Browse Source

1.编写获取院系人员树-一气查回接口(怕卡,暂时不启用,备用),以及修改获取院系人员树-分级查询一些细节
2.提交树工具类

honorfire 7 months ago
parent
commit
3cf62e0d20

+ 61 - 0
snowy-base/snowy-common/src/main/java/vip/xiaonuo/common/util/TreeUtil.java

@@ -0,0 +1,61 @@
+package vip.xiaonuo.common.util;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 树工具类
+ */
+public class TreeUtil {
+
+    public  Map keyMap = new HashMap();
+
+
+
+
+    /**
+     * 基础版递归构建树结构
+     * (子集里放子集)
+     * */
+    //递归获取子部门
+    //构建树结构的返回数据
+    public static List<Map<String,Object>> getThree(List<Map<String, Object>> list, String parentId){
+        //获取所有子节点
+        List<Map<String,Object>> childTreeList = getChildTree(list,parentId);
+        //用所有子节点,依次再去递归查询自己的所有子节点加进来
+        for (Map map:childTreeList) {
+            List<Map<String, Object>> children = getThree(list, (String) map.get("id"));
+            if(children.size() != 0){
+                map.put("children",children);
+            }
+        }
+        return childTreeList;
+    }
+    //获取子部门树
+    private static List<Map<String,Object>> getChildTree(List<Map<String,Object>> list,String id){
+        List<Map<String,Object>> childTree = new ArrayList<>();
+        for (Map map:list) {
+            if(map.get("parentId").equals(id)){
+            childTree.add(map);
+            }
+        }
+        return childTree;
+    }
+
+    /**
+     * 基础版获取所有子集
+     * (获取所有子集id)
+     * */
+    public static List<Long> getDownList(List<Map<String,Object>> listData, Long id,List<Long> dept) {
+        for (Map one:listData){
+            if(one.get("parentId").equals(id)){
+                dept.add((Long) one.get("id"));
+                getDownList(listData, (Long)one.get("id"),dept);
+            }
+        }
+        return dept;
+    }
+
+}

+ 46 - 4
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/controller/CollegeController.java

@@ -27,17 +27,20 @@ import org.springframework.web.bind.annotation.RestController;
 import vip.xiaonuo.common.annotation.CommonLog;
 import vip.xiaonuo.common.pojo.CommonResult;
 import vip.xiaonuo.common.pojo.CommonValidList;
+import vip.xiaonuo.common.util.TreeUtil;
 import vip.xiaonuo.disk.domain.College;
 import vip.xiaonuo.disk.param.CollegeAddParam;
 import vip.xiaonuo.disk.param.CollegeEditParam;
 import vip.xiaonuo.disk.param.CollegeIdParam;
 import vip.xiaonuo.disk.param.CollegePageParam;
 import vip.xiaonuo.disk.service.CollegeService;
+import vip.xiaonuo.sys.modular.user.service.SysUserService;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.validation.Valid;
 import javax.validation.constraints.NotEmpty;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -56,6 +59,8 @@ public class CollegeController {
 
     @Resource
     private CollegeService collegeService;
+    @Resource
+    private SysUserService sysUserService;
 
     /**
      * 获取college分页
@@ -173,16 +178,53 @@ public class CollegeController {
 
 
     /**
-     * 获取院系人员树
+     * 获取院系人员树-一次查回(担心卡,暂时不采用,预备用)
      *
      * @author xuyuxiang
      * @date 2022/4/24 20:00
      */
     @ApiOperationSupport(order = 7)
-    @ApiOperation("获取组织人员树")
+    @ApiOperation("获取院系人员树-一次查回")
     @GetMapping("/disk/college/orgUserTreeSelector")
-    public CommonResult<List<Tree<String>>> orgUserTreeSelector() {
-        return CommonResult.data(collegeService.orgUserTreeSelector());
+    public CommonResult<List<Map<String,Object>>> orgUserTreeSelector(HttpServletRequest req) {
+        Map param=new HashMap();
+        Map result = new HashMap();
+        String collegeParentId = "0";
+        if(StringUtils.isNotEmpty(req.getParameter("collegeParentId")))collegeParentId=req.getParameter("collegeParentId");
+        //用于装当前单位的map
+        Map nowData = new HashMap();
+        List<Map<String, Object>> tree = new ArrayList<>();
+        //最终用来化成树的集合
+        List<Map<String,Object>> dataList=new ArrayList<>();
+        //查询该父级id的子级院系
+        List<Map<String,Object>> orgList=collegeService.getOrgUserChildList(param);
+        List<Map<String,Object>> userList=sysUserService.getOrgUserChildList(param);
+        dataList.addAll(orgList);
+        dataList.addAll(userList);
+        for(Map one:dataList)
+        {
+            if(one.get("id").equals(collegeParentId))
+            {
+                nowData=one;
+                break;
+            }
+
+        }
+        tree = TreeUtil.getThree(dataList,collegeParentId);
+
+        //如果传进来的id不为空,则把传进来的id也作为一条数据
+        List<Map<String,Object>> resultList=new ArrayList<>();
+        if(nowData.get("id")!=null)
+        {
+            nowData.put("children",tree);
+            resultList.add(nowData);
+            result.put("result",resultList);
+        }
+        else
+        {
+            resultList.addAll(tree);
+        }
+        return CommonResult.data(resultList);
     }
 
     /**

+ 1 - 0
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/mapper/mapping/CollegeMapper.xml

@@ -6,6 +6,7 @@
         SELECT
             t1.ID AS id,
             t1.NAME AS name,
+            t1.PARENT_ID AS parentId,
             'college' AS infoType
         FROM college t1
         WHERE t1.DELETE_FLAG = 'NOT_DELETE'

+ 5 - 0
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/service/CollegeService.java

@@ -189,5 +189,10 @@ public interface CollegeService extends IService<College> {
      **/
     List<Map<String, Object>> orgUserTreeRespectively(Map param);
 
+    /**
+     * 获取院系人员树-院系部分
+     * */
+    List<Map<String, Object>> getOrgUserChildList(Map param);
+
 
 }

+ 10 - 1
snowy-plugin/snowy-plugin-disk/snowy-plugin-disk-func/src/main/java/vip/xiaonuo/disk/service/impl/CollegeServiceImpl.java

@@ -289,6 +289,16 @@ public class CollegeServiceImpl extends ServiceImpl<CollegeMapper, College> impl
         return this.page(CommonPageRequest.defaultPage(), lambdaQueryWrapper);
     }
 
+    /**
+     * 获取院系人员树-院系部分
+     * */
+    @Override
+    public List<Map<String, Object>> getOrgUserChildList(Map param)
+    {
+        return collegeMapper.getOrgUserChildList(param);
+    }
+
+
     /**
      * 获取院系人员树-分级请求
      *
@@ -301,7 +311,6 @@ public class CollegeServiceImpl extends ServiceImpl<CollegeMapper, College> impl
         //查询该父级院系id的子级院系
         List<Map<String, Object>> collegeList = collegeMapper.getOrgUserChildList(param);
         String collegeParentId = param.get("collegeParentId").toString();
-        param.put("collegeThreeCollege", collegeParentId);
         //查询该父级id的子级人员
         List<Map<String, Object>> userList = sysUserMapper.getOrgUserChildList(param);
         resultList.addAll(collegeList);

+ 3 - 2
snowy-plugin/snowy-plugin-sys/snowy-plugin-sys-func/src/main/java/vip/xiaonuo/sys/modular/user/mapper/mapping/SysUserMapper.xml

@@ -26,11 +26,12 @@
         SELECT
             t1.ID AS id,
             t1.NAME AS name,
+            t1.COLLEGE_THREE_ID AS parentId,
             'user' AS infoType
         FROM SYS_USER t1
         WHERE t1.DELETE_FLAG = 'NOT_DELETE'
-        <if test="collegeThreeCollege !=null and collegeThreeCollege != ''">
-            AND t1.COLLEGE_THREE_ID =#{collegeThreeCollege}
+        <if test="collegeParentId !=null and collegeParentId != ''">
+            AND t1.COLLEGE_THREE_ID =#{collegeParentId}
         </if>
     </select>
 </mapper>

+ 5 - 0
snowy-plugin/snowy-plugin-sys/snowy-plugin-sys-func/src/main/java/vip/xiaonuo/sys/modular/user/service/SysUserService.java

@@ -523,4 +523,9 @@ public interface SysUserService extends IService<SysUser> {
      * 资源共享-群组-分页列表
      */
     Page<Map<String,Object>> getGroupList(Map param);
+
+    /**
+     * 获取院系人员树-人员部分
+     * */
+    List<Map<String, Object>> getOrgUserChildList(Map param);
 }

+ 9 - 0
snowy-plugin/snowy-plugin-sys/snowy-plugin-sys-func/src/main/java/vip/xiaonuo/sys/modular/user/service/impl/SysUserServiceImpl.java

@@ -242,6 +242,15 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
         return this.page(CommonPageRequest.defaultPage(), queryWrapper);
     }
 
+    /**
+     * 获取院系人员树-人员部分
+     * */
+    @Override
+    public List<Map<String, Object>> getOrgUserChildList(Map param)
+    {
+        return sysUserMapper.getOrgUserChildList(param);
+    }
+
     /**
      * 获取用户-全量列表
      *