Explorar o código

添加内部机构关联用户数据接口bug修复

hxl13994548489 %!s(int64=2) %!d(string=hai) anos
pai
achega
e74d9360c6

+ 2 - 1
src/main/java/com/ydtech/modules/admin/dao/SysDeptInternalAgentMapper.java

@@ -2,6 +2,7 @@ package com.ydtech.modules.admin.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ydtech.modules.admin.model.po.SysDeptInternalAgent;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -19,7 +20,7 @@ public interface SysDeptInternalAgentMapper extends BaseMapper<SysDeptInternalAg
      *  @Date: 2024/6/27 11:20
      *  @Description: 查询所有的机构
      */
-    List<SysDeptInternalAgent> queryDeptList();
+    List<SysDeptInternalAgent> queryDeptList(@Param(value = "parentIds") String parentIds,@Param(value = "comtype") String comtype);
 }
 
 

+ 58 - 9
src/main/java/com/ydtech/modules/admin/service/impl/SysDeptInternalAgentServiceImpl.java

@@ -15,8 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
-import java.util.stream.Collectors;
 
 /**
 * @author Administrator
@@ -90,27 +90,74 @@ public class SysDeptInternalAgentServiceImpl extends ServiceImpl<SysDeptInternal
 
     @Override
     public List<SysDeptInternalAgent> findTree(String deptId, String comtype) {
-        List<SysDeptInternalAgent> sysDeptAll =sysDeptInternalAgentMapper.queryDeptList();
+        String parentIds =null;
+        if(StringUtils.isNotBlank(deptId)){
+            SysDeptInternalAgent sysDeptInternalAgent = sysDeptInternalAgentMapper.selectById(deptId);
+            parentIds=sysDeptInternalAgent.getParentIds();
+        }
+        List<SysDeptInternalAgent> sysDeptAll =sysDeptInternalAgentMapper.queryDeptList(parentIds,comtype);
         List<SysDeptInternalAgent> resultList =new ArrayList<SysDeptInternalAgent>();
-        List<SysDeptInternalAgent> sysDeptTop = sysDeptAll.stream().filter(item ->"0".equals(item.getParentId())).collect(Collectors.toList());
+        List<SysDeptInternalAgent> sysDeptTop = getTopDeptList(sysDeptAll);
         for (SysDeptInternalAgent dept : sysDeptTop) {
-            resultList.add(buildDeptTree(dept,sysDeptAll));
+            if(StringUtils.isNotBlank(comtype)){
+                resultList.add(buildDeptTree(dept,sysDeptAll));
+            }else{
+                resultList.add(buildDeptTreeOne(dept,sysDeptAll));
+            }
         }
         return resultList;
     }
-
     /**
      *  @version
      *  @author: hxl
-     *  @Date: 2024/6/27 8:42
-     *  @Description: 获取顶级机构的数据
+     *  @Date: 2024/6/28 19:19
+     *  @Description: 处理上下级关系
+     */
+    private SysDeptInternalAgent buildDeptTreeOne(SysDeptInternalAgent dept, List<SysDeptInternalAgent> deptList){
+        for (SysDeptInternalAgent d : deptList) {
+            if (dept.getId().equals(d.getParentId())) {
+                if (null == dept.getChildren()) {
+                    dept.setChildren(new ArrayList<SysDeptInternalAgent>());
+                }
+                //递归调用
+                dept.getChildren().add(buildDeptTreeOne(d, deptList));
+            }
+        }
+        return dept;
+    }
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/6/28 18:17
+     *  @Description: 获取顶级机构
      */
+    private static List<SysDeptInternalAgent> getTopDeptList(List<SysDeptInternalAgent> sysDeptAll) {
+        Integer min;
+        List<Integer> levelList =new ArrayList<>();
+        List<SysDeptInternalAgent> sysDeptTop=new ArrayList<>();
+        if(sysDeptAll !=null && sysDeptAll.size()>0){
+            for(SysDeptInternalAgent sysDeptInternalAgent: sysDeptAll){
+                  levelList.add(Integer.parseInt(sysDeptInternalAgent.getComlevel()));
+            }
+            min = Collections.min(levelList);
+            for(SysDeptInternalAgent sysDeptInternalAgent: sysDeptAll){
+                if(Integer.parseInt(sysDeptInternalAgent.getComlevel())==min){
+                    sysDeptTop.add(sysDeptInternalAgent);
+                }
+            }
+        }
+        return sysDeptTop;
+    }
+
     /**
-     * 递归构建树形结构
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/6/27 8:42
+     *  @Description: 处理爷孙关系
      */
     private SysDeptInternalAgent buildDeptTree(SysDeptInternalAgent dept, List<SysDeptInternalAgent> deptList){
         for (SysDeptInternalAgent d : deptList) {
-            if (dept.getId().equals(d.getParentId())) {
+            if (d.getParentIds().contains(dept.getParentIds()) && !d.getParentIds().equals(dept.getParentIds()) ) {
                 if (null == dept.getChildren()) {
                     dept.setChildren(new ArrayList<SysDeptInternalAgent>());
                 }
@@ -120,6 +167,8 @@ public class SysDeptInternalAgentServiceImpl extends ServiceImpl<SysDeptInternal
         }
         return dept;
     }
+
+
 }
 
 

+ 2 - 5
src/main/java/com/ydtech/modules/admin/service/impl/SysUserLinkDeptInternalAgentServiceImpl.java

@@ -49,9 +49,9 @@ public class SysUserLinkDeptInternalAgentServiceImpl extends ServiceImpl<SysUser
      */
     @Override
     public List<SysDeptInternalAgent> queryOrgTree() {
-        List<SysDeptInternalAgent> sysDeptAll =sysDeptInternalAgentMapper.queryDeptList();
+        List<SysDeptInternalAgent> sysDeptAll =sysDeptInternalAgentMapper.queryDeptList(null,null);
         List<SysDeptInternalAgent> resultList =new ArrayList<SysDeptInternalAgent>();
-        List<SysDeptInternalAgent> sysDeptTop = sysDeptAll.stream().filter(item ->"3".equals(item.getComlevel())).collect(Collectors.toList());
+        List<SysDeptInternalAgent> sysDeptTop = sysDeptAll.stream().filter(item ->"0".equals(item.getComlevel())).collect(Collectors.toList());
         for (SysDeptInternalAgent dept : sysDeptTop) {
             resultList.add(buildDeptTree(dept,sysDeptAll));
         }
@@ -63,9 +63,6 @@ public class SysUserLinkDeptInternalAgentServiceImpl extends ServiceImpl<SysUser
      *  @Date: 2024/6/27 8:42
      *  @Description: 获取顶级机构的数据
      */
-    /**
-     * 递归构建树形结构
-     */
     private SysDeptInternalAgent buildDeptTree(SysDeptInternalAgent dept, List<SysDeptInternalAgent> deptList){
         for (SysDeptInternalAgent d : deptList) {
             if (dept.getId().equals(d.getParentId())) {

+ 8 - 0
src/main/resources/mapper/modules/admin/SysDeptInternalAgentMapper.xml

@@ -27,5 +27,13 @@
     </sql>
     <select id="queryDeptList" resultType="com.ydtech.modules.admin.model.po.SysDeptInternalAgent">
          select * from  sys_dept_internal_agent
+         <where>
+             <if test="comtype != null and comtype != ''">
+                 AND comtype = #{comtype}
+             </if>
+             <if test="parentIds != null and parentIds != ''">
+                 AND parent_ids  like concat(#{parentIds},'%')
+             </if>
+         </where>
     </select>
 </mapper>