refactor(bpm): 优化项目信息获取逻辑
- 使用 CollUtil 工具类优化空集合判断 - 重构用户和部门信息获取逻辑,提高代码可读性和性能 - 优化项目人员和参与部门名称的拼接方式
This commit is contained in:
parent
708775f6dc
commit
c9510fb65f
@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.yudao.module.bpm.controller.admin.oa;
|
package cn.iocoder.yudao.module.bpm.controller.admin.oa;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.project.BpmOAProjectCreateReqVO;
|
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.project.BpmOAProjectCreateReqVO;
|
||||||
@ -65,12 +66,18 @@ public class BpmOAProjectController {
|
|||||||
BpmOAProjectRespVO respVO = BeanUtils.toBean(project, BpmOAProjectRespVO.class);
|
BpmOAProjectRespVO respVO = BeanUtils.toBean(project, BpmOAProjectRespVO.class);
|
||||||
|
|
||||||
if (respVO != null) {
|
if (respVO != null) {
|
||||||
|
Set<Long> userIds = new HashSet<>();
|
||||||
// 获取项目中所有人员的用户编号列表
|
// 获取项目中所有人员的用户编号列表
|
||||||
Set<Long> userIds = respVO.getStaff() == null ? new HashSet<>() : respVO.getStaff();
|
if (CollUtil.isNotEmpty(respVO.getStaff())) {
|
||||||
|
userIds.addAll(respVO.getStaff());
|
||||||
|
}
|
||||||
userIds.add(respVO.getDirectorUserId());
|
userIds.add(respVO.getDirectorUserId());
|
||||||
|
|
||||||
|
Set<Long> deptIds = new HashSet<>();
|
||||||
// 获取项目中所有部门编号列表
|
// 获取项目中所有部门编号列表
|
||||||
Set<Long> deptIds = respVO.getParticipationDept() == null ? new HashSet<>() : respVO.getParticipationDept();
|
if (CollUtil.isNotEmpty(respVO.getParticipationDept())) {
|
||||||
|
deptIds.addAll(respVO.getParticipationDept());
|
||||||
|
}
|
||||||
deptIds.add(respVO.getResponsibleDept());
|
deptIds.add(respVO.getResponsibleDept());
|
||||||
|
|
||||||
// 获取所有用户信息
|
// 获取所有用户信息
|
||||||
@ -104,29 +111,36 @@ public class BpmOAProjectController {
|
|||||||
|
|
||||||
if (respVO != null) {
|
if (respVO != null) {
|
||||||
|
|
||||||
|
Set<Long> userIds = new HashSet<>();
|
||||||
|
// 获取项目中所有人员的用户编号列表
|
||||||
|
if (CollUtil.isNotEmpty(respVO.getStaff())) {
|
||||||
|
userIds.addAll(respVO.getStaff());
|
||||||
|
}
|
||||||
|
userIds.add(respVO.getDirectorUserId());
|
||||||
|
|
||||||
|
Set<Long> deptIds = new HashSet<>();
|
||||||
// 获取项目中所有部门编号列表
|
// 获取项目中所有部门编号列表
|
||||||
Set<Long> deptIds = respVO.getParticipationDept() == null ? new HashSet<>() : respVO.getParticipationDept();
|
if (CollUtil.isNotEmpty(respVO.getParticipationDept())) {
|
||||||
|
deptIds.addAll(respVO.getParticipationDept());
|
||||||
|
}
|
||||||
deptIds.add(respVO.getResponsibleDept());
|
deptIds.add(respVO.getResponsibleDept());
|
||||||
|
|
||||||
// 获取所有用户信息
|
// 获取所有用户信息
|
||||||
AdminUserRespDTO userRespDTO = userApi.getUser(respVO.getDirectorUserId()).getCheckedData();
|
Map<Long, AdminUserRespDTO> userMap = userApi.getUserMap(userIds);
|
||||||
// 获取所有部门信息
|
// 获取所有部门信息
|
||||||
List<DeptRespDTO> deptDOS = deptApi.getDeptList(deptIds).getCheckedData();
|
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(deptIds);
|
||||||
Map<Long, DeptRespDTO> deptMap = convertMap(deptDOS, DeptRespDTO::getId);
|
|
||||||
|
|
||||||
// 设置责任人名称
|
// 设置责任人名称
|
||||||
respVO.setDirectorUserName(userRespDTO.getNickname());
|
respVO.setDirectorUserName(userMap.get(respVO.getDirectorUserId()).getNickname());
|
||||||
|
// 设置项目人员名称
|
||||||
// 筛选出不是责任人部门的部门信息
|
userMap.remove(respVO.getDirectorUserId());
|
||||||
List<DeptRespDTO> deptVOs = deptDOS.stream()
|
respVO.setStaffName(userMap.values().stream().map(AdminUserRespDTO::getNickname).collect(Collectors.joining("、")));
|
||||||
.filter(dept -> !dept.getId().equals(respVO.getResponsibleDept()))
|
|
||||||
.distinct()
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
// 设置责任部门名称
|
// 设置责任部门名称
|
||||||
respVO.setResponsibleDeptName(deptMap.get(respVO.getResponsibleDept()).getName());
|
respVO.setResponsibleDeptName(deptMap.get(respVO.getResponsibleDept()).getName());
|
||||||
// 拼接参与部门名称
|
// 拼接参与部门名称
|
||||||
respVO.setParticipationDeptName(deptVOs.stream().map(DeptRespDTO::getName).collect(Collectors.joining("、")));
|
deptMap.remove(respVO.getResponsibleDept());
|
||||||
|
respVO.setParticipationDeptName(deptMap.values().stream().map(DeptRespDTO::getName).collect(Collectors.joining("、")));
|
||||||
}
|
}
|
||||||
|
|
||||||
return success(respVO);
|
return success(respVO);
|
||||||
|
Loading…
Reference in New Issue
Block a user