Explorar o código

机构 添加 机构id 机构来源 赛选条件

785834757 %!s(int64=2) %!d(string=hai) anos
pai
achega
f5d9e64dae

+ 3 - 3
src/main/java/com/ydtech/modules/admin/controller/SysDeptController.java

@@ -46,10 +46,10 @@ public class SysDeptController extends BaseController {
     //@PreAuthorize("hasAuthority('sys:dept:view')")
     @ApiOperation(value = "获取树结构")
     @GetMapping(value = "/findTree")
-    public HttpResult<List<SysDept>> findTree() {
+    public HttpResult<List<SysDept>> findTree(String deptId,String managementSource) {
         SysUser user = getUser();
-        String deptId = user.getDeptId();
-        return HttpResult.ok(sysDeptService.findTree(deptId));
+//        String deptId = user.getDeptId();
+        return HttpResult.ok(sysDeptService.findTree(deptId,managementSource));
     }
 
     //    @PreAuthorize("hasAuthority('sys:dept:edit')")

+ 3 - 1
src/main/java/com/ydtech/modules/admin/service/SysDeptService.java

@@ -1,6 +1,7 @@
 package com.ydtech.modules.admin.service;
 
 
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ydtech.core.page.PageRequest;
 import com.ydtech.core.page.PageResult;
@@ -34,9 +35,10 @@ public interface SysDeptService extends IService<SysDept> {
      * 获取树结构
      *
      * @param deptId 部门id
+     * @param managementSource 机构来源
      * @return 返回部门列表
      */
-    List<SysDept> findTree(String deptId);
+    List<SysDept> findTree(String deptId,String managementSource);
 
     /**
      * 增加机构

+ 48 - 6
src/main/java/com/ydtech/modules/admin/service/impl/SysDeptServiceImpl.java

@@ -31,19 +31,60 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
 
 
     @Override
-    public List<SysDept> findTree(String deptId) {
-        SysDept sysDept = getById(deptId);
+    public List<SysDept> findTree(String deptId,String managementSource) {
+        if(null == deptId || "".equals(deptId)){
+            deptId = "9";
+        }
 
+        SysDept sysDept = getById(deptId);
         LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>();
         lqw.eq(SysDept::getDelFlag, 0);
         lqw.likeRight(SysDept::getId, deptId);
         lqw.orderByDesc(SysDept::getOrderNum);
         List<SysDept> sysDeptList = list(lqw);
-        Map<String, List<SysDept>> map = sysDeptList.stream().collect(Collectors.groupingBy(SysDept::getParentId));
-        sysDeptList.forEach(i -> i.setChildren(map.getOrDefault(i.getId(), new ArrayList<>())));
-        return map.get(sysDept.getParentId());
+        //判断机构来源条件 进行遍历
+        if(null != managementSource && !"".equals(managementSource)){
+            lqw.eq(SysDept::getManagementSource,managementSource);
+            //条件
+            List<SysDept> conditionList = list(lqw);
+            Map<String, List<SysDept>> conditionMap = conditionList.stream().collect(Collectors.groupingBy(SysDept::getParentId));
+            Map<String, List<SysDept>> map = conditionList.stream().collect(Collectors.groupingBy(SysDept::getParentId));
+            //先查第6层
+            conditionList.forEach(i ->
+                    i.setChildren(map.getOrDefault(i.getId(), new ArrayList<>()))
+            );
+            List<SysDept> result = new ArrayList<>();
+            //再查前4层
+            int level = 5;
+            while(level > 0){
+                result = recursion(sysDeptList, conditionMap);
+                conditionMap = result.stream().collect(Collectors.groupingBy(SysDept::getParentId));
+                level--;
+            }
+            sysDeptList = result;
+        }else{
+            Map<String, List<SysDept>> map = sysDeptList.stream().collect(Collectors.groupingBy(SysDept::getParentId));
+            sysDeptList.forEach(i -> i.setChildren(map.getOrDefault(i.getId(), new ArrayList<>())));
+            sysDeptList = map.get(sysDept.getParentId());
+        }
+        return sysDeptList;
     }
 
+    private List<SysDept> recursion(List<SysDept> sysDeptList, Map<String, List<SysDept>> conditionMap) {
+        List<SysDept> result = new ArrayList<>();
+        sysDeptList.forEach(i ->
+                conditionMap.forEach((key,value) -> {
+                    if (i.getId().equals(key)) {
+                        if(i.getChildren() == null){
+                            i.setChildren(new ArrayList<>());
+                        }
+                        i.getChildren().addAll(value);
+                        result.add(i);
+                    }
+                })
+        );
+        return result;
+    }
 
     @Override
     public List<SysDept> getUserList(String deptId) {
@@ -121,10 +162,11 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
     @Override
     public PageResult<SysDept> findSubDepts(PageRequest pageRequest) {
         String id = pageRequest.getColumnFilterValue(pageRequest, "id");
-
+        String managementSource = pageRequest.getColumnFilterValue(pageRequest, "managementSource");
         Page<SysDept> p = PageRequest.buildPageRequest(pageRequest);
         LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>();
         lqw.eq(StringUtils.isNotEmpty(id), SysDept::getParentId, id);
+        lqw.eq(StringUtils.isNotEmpty(managementSource), SysDept::getManagementSource, managementSource);
         IPage<SysDept> pResult = page(p, lqw);
         //传入查询条件
         return PageResult.buildPageResult(pResult);