refactor(system): 优化项目管理相关代码

- 注释掉 ProjectController 中的冗余代码
- 优化 ProjectMapper 中的查询条件,增加空值检查
This commit is contained in:
furongxin 2024-12-05 10:36:00 +08:00
parent b29eb854c1
commit bf21eb7042
2 changed files with 29 additions and 41 deletions

View File

@ -77,44 +77,32 @@ public class ProjectController {
public CommonResult<ProjectRespVO> getProject(@RequestParam("id") Long id) {
ProjectDO project = projectService.getProject(id);
ProjectRespVO respVO = BeanUtils.toBean(project, ProjectRespVO.class);
if (respVO != null) {
// 获取项目中所有人员的用户编号列表
Set<Long> userIds = respVO.getStaff() == null ? new HashSet<>() : respVO.getStaff();
userIds.add(respVO.getDirectorUserId());
// 获取项目中所有部门编号列表
Set<Long> deptIds = respVO.getParticipationDept() == null ? new HashSet<>() : respVO.getParticipationDept();
deptIds.add(respVO.getResponsibleDept());
// 获取所有用户信息
List<AdminUserDO> userDOS = userService.getUserList(userIds);
Map<Long, AdminUserDO> userMap = convertMap(userDOS, AdminUserDO::getId);
// 获取所有部门信息
List<DeptDO> deptDOS = deptService.getDeptList(deptIds);
Map<Long, DeptDO> deptMap = convertMap(deptDOS, DeptDO::getId);
// 筛选出不是责任人的用户信息
List<AdminUserDO> userVOs = userDOS.stream()
.filter(user -> !user.getId().equals(respVO.getDirectorUserId()))
.distinct()
.collect(Collectors.toList());
// 设置责任人名称
respVO.setDirectorUserName(userMap.get(respVO.getDirectorUserId()).getNickname());
// 拼接项目人员名称
respVO.setStaffName(userVOs.stream().map(AdminUserDO::getNickname).collect(Collectors.joining("")));
// 筛选出不是责任人部门的部门信息
List<DeptDO> deptVOs = deptDOS.stream()
.filter(dept -> !dept.getId().equals(respVO.getResponsibleDept()))
.distinct()
.collect(Collectors.toList());
// 设置责任部门名称
respVO.setResponsibleDeptName(deptMap.get(respVO.getResponsibleDept()).getName());
// 拼接参与部门名称
respVO.setParticipationDeptName(deptVOs.stream().map(DeptDO::getName).collect(Collectors.joining("")));
}
// if (respVO != null) {
// // 获取项目中所有人员的用户编号列表
// Set<Long> userIds = respVO.getStaff() == null ? new HashSet<>() : respVO.getStaff();
// userIds.add(respVO.getDirectorUserId());
//
// // 获取项目中所有部门编号列表
// Set<Long> deptIds = respVO.getParticipationDept() == null ? new HashSet<>() : respVO.getParticipationDept();
// deptIds.add(respVO.getResponsibleDept());
//
// // 获取所有用户信息
// Map<Long, AdminUserDO> userMap = userService.getUserMap(userIds);
// // 获取所有部门信息
// Map<Long, DeptDO> deptMap = deptService.getDeptMap(deptIds);
//
// // 设置责任人名称
// respVO.setDirectorUserName(userMap.get(respVO.getDirectorUserId()).getNickname());
// // 拼接项目人员名称
// userMap.remove(respVO.getDirectorUserId());
// respVO.setStaffName(userMap.values().stream().map(AdminUserDO::getNickname).collect(Collectors.joining("")));
//
// // 设置责任部门名称
// respVO.setResponsibleDeptName(deptMap.get(respVO.getResponsibleDept()).getName());
// // 拼接参与部门名称
// deptMap.remove(respVO.getResponsibleDept());
// respVO.setParticipationDeptName(deptMap.values().stream().map(DeptDO::getName).collect(Collectors.joining("")));
// }
return success(respVO);
}

View File

@ -29,11 +29,11 @@ public interface ProjectMapper extends BaseMapperX<ProjectDO> {
.betweenIfPresent(ProjectDO::getEndDate, reqVO.getEndDate())
.eqIfPresent(ProjectDO::getIsLongTerm, reqVO.getIsLongTerm())
.eqIfPresent(ProjectDO::getStatus, reqVO.getStatus())
.likeLeft(ProjectDO::getParticipationDept, "-" + reqVO.getParticipationDept())
.likeLeft(Objects.nonNull(reqVO.getParticipationDept()), ProjectDO::getParticipationDept, "-" + reqVO.getParticipationDept())
.or()
.likeRight(ProjectDO::getParticipationDept, reqVO.getParticipationDept() + "-")
.likeRight(Objects.nonNull(reqVO.getParticipationDept()), ProjectDO::getParticipationDept, reqVO.getParticipationDept() + "-")
.or()
.like(ProjectDO::getParticipationDept, "-" + reqVO.getParticipationDept() + "-")
.like(Objects.nonNull(reqVO.getParticipationDept()), ProjectDO::getParticipationDept, "-" + reqVO.getParticipationDept() + "-")
.orderByDesc(ProjectDO::getId));
}
}