Quellcode durchsuchen

企微员工部门查询 树状查询 添加

xgb vor 6 Tagen
Ursprung
Commit
bf340ed49c

+ 16 - 0
fs-company/src/main/java/com/fs/company/controller/qw/QwUserController.java

@@ -116,6 +116,22 @@ public class QwUserController extends BaseController
         startPage();
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         qwUser.setCompanyId(loginUser.getCompany().getCompanyId());
+        // 添加部门查询条件
+        //本部门
+        Long deptId = qwUser.getDeptId();
+        if(deptId!=null){
+            List<Long> qwDeptIdList = new ArrayList<>();
+            if (deptId!=null){
+                qwDeptIdList.add(deptId);
+            }
+            // 本部门的下级部门
+            List<Long> deptList = qwUserService.selectDeptByParentId(deptId,qwUser.getCorpId());
+            if (!deptList.isEmpty()){
+                qwDeptIdList.addAll(deptList);
+            }
+            qwUser.setQwDeptIdList(qwDeptIdList);
+        }
+
         List<QwUserVO> list = qwUserService.selectQwUserListStaffVO(qwUser);
         return getDataTable(list);
     }

+ 0 - 1
fs-service/src/main/java/com/fs/qw/domain/QwDeptTreeSelect.java

@@ -18,7 +18,6 @@ public class QwDeptTreeSelect implements Serializable {
     public QwDeptTreeSelect(Long id, String label) {
         this.id = id;
         this.label = label;
-        this.children = new ArrayList<>();
     }
 
     // getter和setter

+ 7 - 0
fs-service/src/main/java/com/fs/qw/mapper/QwUserMapper.java

@@ -163,6 +163,12 @@ public interface QwUserMapper extends BaseMapper<QwUser>
             "                       #{item} " +
             "                   </foreach> " +
             "            </if>" +
+            "            <if test=\"qwDeptIdList != null and !qwDeptIdList.isEmpty() and  userType != '00' \">" +
+            "               AND qd.dept_id IN " +
+            "                   <foreach collection='qwDeptIdList' item='item' open='(' separator=',' close=')'> " +
+            "                       #{item} " +
+            "                   </foreach> " +
+            "            </if>" +
             "ORDER BY  qu.login_status asc,qu.tool_status desc " +
             "</script>"})
     List<QwUserVO> selectQwUserListStaffVO(QwUserListParam qwUser);
@@ -442,4 +448,5 @@ public interface QwUserMapper extends BaseMapper<QwUser>
 
     List<QwOptionsVO> selectQwCompanyListOptionsVOBySys();
 
+    List<Long> selectDeptByParentId(@Param("deptId")Long deptId,@Param("corpId") String corpId);
 }

+ 5 - 0
fs-service/src/main/java/com/fs/qw/param/QwUserListParam.java

@@ -57,6 +57,11 @@ public class QwUserListParam {
      * 销售部门
      */
     private List<Long> cuDeptIdList;
+    /**
+     * 企微部门
+     */
+    private List<Long> qwDeptIdList;
+
 
     /**
      * 部门类型 00 管理员 01 员工

+ 1 - 0
fs-service/src/main/java/com/fs/qw/service/IQwUserService.java

@@ -199,4 +199,5 @@ public interface IQwUserService
 
     List<QwOptionsVO> selectQwCompanyListOptionsVOBySys();
 
+    List<Long> selectDeptByParentId(Long deptId,String cropId);
 }

+ 2 - 2
fs-service/src/main/java/com/fs/qw/service/impl/QwDeptServiceImpl.java

@@ -177,10 +177,10 @@ public class QwDeptServiceImpl implements IQwDeptService
     private QwDeptTreeSelect buildTreeSelect(QwDept dept, Map<Long, List<QwDept>> deptMap, int depth) {
         // 限制最多5级,避免死循环
         if (depth > 5) {
-            return new QwDeptTreeSelect(dept.getId(), dept.getDeptName());
+            return new QwDeptTreeSelect(dept.getDeptId(), dept.getDeptName());
         }
 
-        QwDeptTreeSelect treeSelect = new QwDeptTreeSelect(dept.getId(), dept.getDeptName());
+        QwDeptTreeSelect treeSelect = new QwDeptTreeSelect(dept.getDeptId(), dept.getDeptName());
 
         // 获取当前部门的子部门
         List<QwDept> children = deptMap.get(dept.getDeptId());

+ 12 - 0
fs-service/src/main/java/com/fs/qw/service/impl/QwUserServiceImpl.java

@@ -1559,6 +1559,18 @@ public class QwUserServiceImpl implements IQwUserService
         return qwUserMapper.selectQwCompanyListOptionsVOBySys();
     }
 
+    /**
+     * @Description: 根据企微部门查询下级部门id
+     * @Param:
+     * @Return:
+     * @Author xgb
+     * @Date 2025/10/30 14:27
+     */
+    @Override
+    public List<Long> selectDeptByParentId(Long deptId,String cropId) {
+        return qwUserMapper.selectDeptByParentId(deptId,cropId);
+    }
+
 
     /**
      * 构建查询条件

+ 14 - 0
fs-service/src/main/resources/mapper/qw/QwUserMapper.xml

@@ -289,5 +289,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             and qu.qw_user_name like concat('%', #{nickName}, '%')
         </if>
     </select>
+    <!--  递归查询子部门,不包括自己,深度5   -->
+    <select id="selectDeptByParentId" resultType="java.lang.Long">
+        WITH RECURSIVE sub_dept AS (
+        SELECT dept_id, parentid, 1 as depth
+        FROM qw_dept
+        WHERE parentid = #{deptId} and corp_id=#{corpId}
+        UNION ALL
+        SELECT qd.dept_id, qd.parentid, sd.depth + 1
+        FROM qw_dept qd
+        INNER JOIN sub_dept sd ON qd.parentid = sd.dept_id
+        WHERE sd.depth &lt; 5 and qd.corp_id=#{corpId}
+        )
+        SELECT dept_id FROM sub_dept
+    </select>
 
 </mapper>