Bläddra i källkod

新增根据部门获取二级部门(板块)领导

chenjun 1 år sedan
förälder
incheckning
b3c7ca32f3

+ 5 - 0
zjugis-module-system/zjugis-module-system-api/src/main/java/com/zjugis/module/system/api/dept/DeptApi.java

@@ -28,6 +28,11 @@ public interface DeptApi {
     @Parameter(name = "id", description = "部门编号", example = "1024", required = true)
     CommonResult<DeptRespDTO> getDept(@RequestParam("id") String id);
 
+    @GetMapping(PREFIX + "/get-second-dept")
+    @Operation(summary = "获得二级部门(板块)信息")
+    @Parameter(name = "id", description = "部门编号", example = "1024", required = true)
+    CommonResult<DeptRespDTO> getSecondDeptByDeptId(@RequestParam("id") String deptId);
+
     @GetMapping(PREFIX + "/list")
     @Operation(summary = "获得部门信息数组")
     @Parameter(name = "ids", description = "部门编号数组", example = "1,2", required = true)

+ 6 - 0
zjugis-module-system/zjugis-module-system-biz/src/main/java/com/zjugis/module/system/api/dept/DeptApiImpl.java

@@ -37,6 +37,12 @@ public class DeptApiImpl implements DeptApi {
         return success(DeptConvert.INSTANCE.convert03(dept));
     }
 
+    @Override
+    public CommonResult<DeptRespDTO> getSecondDeptByDeptId(String deptId) {
+        DeptDO dept = deptService.getSecondDeptByDeptId(deptId);
+        return success(DeptConvert.INSTANCE.convert03(dept));
+    }
+
     @Override
     public CommonResult<List<DeptRespDTO>> getDeptList(Collection<String> ids) {
         List<DeptDO> depts = deptService.getDeptList(ids);

+ 7 - 5
zjugis-module-system/zjugis-module-system-biz/src/main/java/com/zjugis/module/system/controller/admin/dept/DeptController.java

@@ -1,5 +1,6 @@
 package com.zjugis.module.system.controller.admin.dept;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.zjugis.framework.common.enums.CommonStatusEnum;
 import com.zjugis.framework.common.pojo.CommonResult;
@@ -21,10 +22,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import javax.validation.Valid;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 import static com.zjugis.framework.common.pojo.CommonResult.success;
 import static com.zjugis.framework.common.util.collection.CollectionUtils.convertSet;
@@ -116,7 +114,11 @@ public class DeptController {
         //获取用户列表,只要开启状态的
         List<AdminUserDO> userList = userService.getUserListByStatus(CommonStatusEnum.ENABLE.getStatus());
         userList.forEach(adminUserDO -> {
-            List<String> deptIds = adminUserDO.getDeptIds();
+            List<String> deptIds = new ArrayList<>();
+            deptIds.add(adminUserDO.getDeptId());
+            if(CollectionUtil.isNotEmpty(adminUserDO.getDeptIds())){
+                deptIds.addAll(adminUserDO.getDeptIds());
+            }
             deptIds.forEach(deptId -> {
                 DeptUserSimpleRespVO deptUserSimpleRespVO = new DeptUserSimpleRespVO();
                 deptUserSimpleRespVO.setId(adminUserDO.getId()).setParentId(deptId).setName(adminUserDO.getNickname()).setType("user");

+ 7 - 0
zjugis-module-system/zjugis-module-system-biz/src/main/java/com/zjugis/module/system/service/dept/DeptService.java

@@ -105,4 +105,11 @@ public interface DeptService {
     List<DeptDO> getDeptWithChildList(String id);
 
     AdminUserDO getDeptLeader(String id);
+
+    /**
+     * 获取二级部门
+     * @param deptId
+     * @return
+     */
+    DeptDO getSecondDeptByDeptId(String deptId);
 }

+ 15 - 0
zjugis-module-system/zjugis-module-system-biz/src/main/java/com/zjugis/module/system/service/dept/DeptServiceImpl.java

@@ -245,4 +245,19 @@ public class DeptServiceImpl implements DeptService {
         return userMapper.selectById(deptLeader.getUserId());
     }
 
+    @Override
+    public DeptDO getSecondDeptByDeptId(String deptId) {
+        DeptDO deptDO = deptMapper.selectById(deptId);
+        return getSecondDept(deptDO);
+    }
+
+    private DeptDO getSecondDept(DeptDO deptDO) {
+        String parentId = deptDO.getParentId();
+        if (parentId == null || DeptIdEnum.ROOT.getId().equals(parentId)) {
+            return deptDO;
+        } else {
+            return getSecondDept(deptDO);
+        }
+    }
+
 }