Commit 7bb638b8 by 周海峰

优化

parent c397292b
...@@ -351,6 +351,14 @@ public class PlatformPersonnelController { ...@@ -351,6 +351,14 @@ public class PlatformPersonnelController {
return ResultJson.ok(page); return ResultJson.ok(page);
} }
@GetMapping("/dept_users_with_children/{deptId}")
public ResultJson getDeptUsersWithChildren(@PathVariable String deptId,
@RequestParam(defaultValue = "1") int pageNum,
@RequestParam(defaultValue = "100") int pageSize) {
PageInfo<PersonneDTO> page = platformPersonnelService.getDeptUsersWithChildren(deptId, pageNum, pageSize);
return ResultJson.ok(page);
}
@PostMapping("/list_by_ids") @PostMapping("/list_by_ids")
public ResultJson getUsersByIds(@RequestBody List<Integer> ids) { public ResultJson getUsersByIds(@RequestBody List<Integer> ids) {
List<PersonneDTO> list = platformPersonnelService.getUsersByIds(ids); List<PersonneDTO> list = platformPersonnelService.getUsersByIds(ids);
......
...@@ -148,4 +148,14 @@ public interface PersonnelMapper { ...@@ -148,4 +148,14 @@ public interface PersonnelMapper {
* 根据用户ID列表查询完整用户信息 * 根据用户ID列表查询完整用户信息
*/ */
List<PersonneDTO> selectByIds(@Param("ids") List<Integer> ids); List<PersonneDTO> selectByIds(@Param("ids") List<Integer> ids);
/**
* 根据部门ID查询该部门及所有子部门下的人员
*/
// List<PersonneDTO> selectByDeptIdWithChildren(@Param("deptId") String deptId);
/**
* 根据部门ID列表查询人员
*/
List<PersonneDTO> selectByDeptIds(@Param("deptIds") List<String> deptIds);
} }
...@@ -260,14 +260,37 @@ ...@@ -260,14 +260,37 @@
order by id asc order by id asc
</select> </select>
<!--根据部门ID查询该部门及所有子部门下的人员-->
<!-- <select id="selectByDeptIdWithChildren" resultMap="PersonneldtoResultMap">-->
<!-- select id, username, department, account-->
<!-- from platform_personnel-->
<!-- where find_in_set(#{deptId,jdbcType=VARCHAR}, department)-->
<!-- and (delstatus = '0' or delstatus is null or delstatus = '')-->
<!-- and (status = '1' or status is null)-->
<!-- order by id asc-->
<!-- </select>-->
<!--根据部门ID列表查询人员(用于查询部门及所有子部门用户)-->
<select id="selectByDeptIds" resultMap="PersonneldtoResultMap">
select id, username, department, account
from platform_personnel
where
<foreach collection="deptIds" item="deptId" open="(" separator=" or " close=")">
department = #{deptId,jdbcType=VARCHAR}
</foreach>
<!-- and (delstatus = '0' or delstatus is null or delstatus = '')-->
<!-- and (status = '1' or status is null)-->
order by id asc
</select>
<!--关键词搜索用户(姓名或工号模糊匹配)--> <!--关键词搜索用户(姓名或工号模糊匹配)-->
<select id="searchByKeyword" resultMap="PersonneldtoResultMap"> <select id="searchByKeyword" resultMap="PersonneldtoResultMap">
select id, username, department, account select id, username, department, account
from platform_personnel from platform_personnel
where (username like concat('%', #{keyword,jdbcType=VARCHAR}, '%') where (username like concat('%', #{keyword,jdbcType=VARCHAR}, '%')
or account like concat('%', #{keyword,jdbcType=VARCHAR}, '%')) or account like concat('%', #{keyword,jdbcType=VARCHAR}, '%'))
and (delstatus = '0' or delstatus is null or delstatus = '') <!-- and (delstatus = '0' or delstatus is null or delstatus = '')-->
and (status = '1' or status is null) <!-- and (status = '1' or status is null)-->
order by id asc order by id asc
limit 100 limit 100
</select> </select>
......
...@@ -132,4 +132,9 @@ public interface PlatformDepartmentMapper { ...@@ -132,4 +132,9 @@ public interface PlatformDepartmentMapper {
int updatePlatformDepartmentByPrimaryKeyFromweixin(PlatformDepartment record); int updatePlatformDepartmentByPrimaryKeyFromweixin(PlatformDepartment record);
int updatePlatformDepartmentStatusByPrimaryKeyFromweixinBatch(@Param("idList") List<Integer> idList, @Param("status") String status); int updatePlatformDepartmentStatusByPrimaryKeyFromweixinBatch(@Param("idList") List<Integer> idList, @Param("status") String status);
int updatePlatformDepartmentStatusByPrimaryKeyFromweixin(PlatformDepartment record); int updatePlatformDepartmentStatusByPrimaryKeyFromweixin(PlatformDepartment record);
/**
* 根据父部门ID查询所有子部门ID(包括递归子部门)
*/
List<Integer> selectAllChildDeptIds(@Param("deptId") Integer deptId);
} }
...@@ -345,4 +345,15 @@ ...@@ -345,4 +345,15 @@
#{id} #{id}
</foreach> </foreach>
</update> </update>
<!--根据父部门ID递归查询所有子部门ID-->
<select id="selectAllChildDeptIds" resultType="java.lang.Integer">
WITH RECURSIVE dept_tree AS (
SELECT id FROM platform_department WHERE id = #{deptId}
UNION ALL
SELECT d.id FROM platform_department d
INNER JOIN dept_tree dt ON d.pid = dt.id
)
SELECT id FROM dept_tree
</select>
</mapper> </mapper>
...@@ -68,4 +68,11 @@ public interface PlatformDepartmentService { ...@@ -68,4 +68,11 @@ public interface PlatformDepartmentService {
void findwxdeptinfo(); void findwxdeptinfo();
@CacheEvict(value = "viewDeptall",key = "'tree'")//清除组织树结构的缓存 @CacheEvict(value = "viewDeptall",key = "'tree'")//清除组织树结构的缓存
void updatePlatformDepartmentFromweixin(String ChangeType,PlatformDepartment entity, String branchCompanyId); void updatePlatformDepartmentFromweixin(String ChangeType,PlatformDepartment entity, String branchCompanyId);
/**
* 根据父部门ID查询所有子部门ID(递归,包含父部门自身)
* @param deptId 父部门ID
* @return 所有部门ID列表
*/
List<Integer> getAllChildDeptIds(String deptId);
} }
...@@ -577,4 +577,17 @@ public class PlatformDepartmentServiceImpl implements PlatformDepartmentService{ ...@@ -577,4 +577,17 @@ public class PlatformDepartmentServiceImpl implements PlatformDepartmentService{
} }
/**
* 根据父部门ID查询所有子部门ID(递归,包含父部门自身)
* @param deptId 父部门ID
* @return 所有部门ID列表
*/
@Override
public List<Integer> getAllChildDeptIds(String deptId) {
if (StringUtils.isBlank(deptId)) {
return new ArrayList<>();
}
return platformDepartmentMapper.selectAllChildDeptIds(Integer.parseInt(deptId));
}
} }
...@@ -106,6 +106,11 @@ public interface PlatformPersonnelService { ...@@ -106,6 +106,11 @@ public interface PlatformPersonnelService {
PageInfo<PersonneDTO> getDeptUsers(String deptId, int pageNum, int pageSize); PageInfo<PersonneDTO> getDeptUsers(String deptId, int pageNum, int pageSize);
/**
* 根据部门ID查询该部门及所有子部门下的人员
*/
PageInfo<PersonneDTO> getDeptUsersWithChildren(String deptId, int pageNum, int pageSize);
List<PersonneDTO> getUsersByIds(List<Integer> ids); List<PersonneDTO> getUsersByIds(List<Integer> ids);
/** /**
......
...@@ -1849,6 +1849,20 @@ public class PlatformPersonnelServiceImpl implements PlatformPersonnelService { ...@@ -1849,6 +1849,20 @@ public class PlatformPersonnelServiceImpl implements PlatformPersonnelService {
} }
@Override @Override
public PageInfo<PersonneDTO> getDeptUsersWithChildren(String deptId, int pageNum, int pageSize) {
// 1. 先查询该部门及所有子部门的ID(递归)
List<Integer> allDeptIds = platformDepartmentService.getAllChildDeptIds(deptId);
if (allDeptIds == null || allDeptIds.isEmpty()) {
return new PageInfo<>(new ArrayList<>());
}
// 2. 将部门ID列表转为String
List<String> deptIdStrs = allDeptIds.stream().map(String::valueOf).collect(Collectors.toList());
// 3. 调用 mapper 查询所有相关部门的用户
List<PersonneDTO> list = personnelMapper.selectByDeptIds(deptIdStrs);
return new PageInfo<>(list);
}
@Override
public List<PersonneDTO> getUsersByIds(List<Integer> ids) { public List<PersonneDTO> getUsersByIds(List<Integer> ids) {
if (ids == null || ids.isEmpty()) { if (ids == null || ids.isEmpty()) {
return new ArrayList<>(); return new ArrayList<>();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论