소스 검색

部门工具类

yzc 1 년 전
부모
커밋
a6807264a3

+ 3 - 13
hx-tenant/src/main/java/com/fjhx/tenant/controller/tenant/UserTenantController.java

@@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.fjhx.tenant.utils.DeptUstil;
 import com.ruoyi.common.annotation.RepeatSubmit;
 import com.ruoyi.common.annotation.TenantIgnore;
 import com.ruoyi.common.constant.BaseSourceConstant;
@@ -86,7 +87,7 @@ public class UserTenantController extends BaseController {
         user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
 
         //赋值归属公司
-        user.setCompanyId(getCompanyByDeptId(user.getDeptId()).getDeptId());
+        user.setCompanyId(DeptUstil.getCompanyByDeptId(user.getDeptId()).getDeptId());
 
         userService.insertUser(user);
     }
@@ -120,22 +121,11 @@ public class UserTenantController extends BaseController {
         }
 
         //赋值归属公司
-        user.setCompanyId(getCompanyByDeptId(user.getDeptId()).getDeptId());
+        user.setCompanyId(DeptUstil.getCompanyByDeptId(user.getDeptId()).getDeptId());
 
         userService.updateUser(user);
     }
 
-    private SysDept getCompanyByDeptId(Long deptId) {
-        SysDept dept = sysDeptService.getById(deptId);
-        if (ObjectUtil.isEmpty(dept)) {
-            throw new ServiceException("查询不到该部门公司信息");
-        }
-        if (Objects.equals(dept.getType(), 0)) {
-            return dept;
-        }
-        return getCompanyByDeptId(dept.getParentId());
-    }
-
     /**
      * 修改用户业务员编号
      */

+ 33 - 0
hx-tenant/src/main/java/com/fjhx/tenant/utils/DeptUstil.java

@@ -0,0 +1,33 @@
+package com.fjhx.tenant.utils;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.extra.spring.SpringUtil;
+import com.ruoyi.common.core.domain.entity.SysDept;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.system.service.ISysDeptService;
+
+import java.util.Objects;
+
+public class DeptUstil {
+
+    private static final ISysDeptService sysDeptService = SpringUtil.getBean(ISysDeptService.class);
+
+    /**
+     * 根据部门id获取公司信息
+     */
+    public static SysDept getCompanyByDeptId(Long deptId) {
+        SysDept dept = sysDeptService.getById(deptId);
+        if (ObjectUtil.isEmpty(dept)) {
+            throw new ServiceException("查询不到该部门公司信息");
+        }
+        if (Objects.equals(dept.getType(), 0)) {
+            return dept;
+        }
+        return getCompanyByDeptId(dept.getParentId());
+    }
+
+    public static Long getCompanyIdByDeptId(Long deptId) {
+        return getCompanyByDeptId(deptId).getDeptId();
+    }
+
+}