refactor(系统设置): 优化查询成员名称的方法

This commit is contained in:
wxg0103 2023-08-31 18:39:00 +08:00 committed by fit2-zhao
parent 357d8df26e
commit 7ec75e8f92
4 changed files with 19 additions and 12 deletions

View File

@ -437,13 +437,6 @@ public class BaseUserService {
return baseUserMapper.getSelectOptionByIdsWithDeleted(ids);
}
public Map<String, String> getUserNameMap() {
List<OptionDTO> excludeSelectOption = getSelectOptionWithDeleted();
Map<String, String> nameMap = new HashMap<>();
excludeSelectOption.forEach(option -> nameMap.put(option.getId(), option.getName()));
return nameMap;
}
/**
* 根据用户ID列表获取用户
*

View File

@ -44,7 +44,12 @@ public class CleanProjectJob {
example.createCriteria().andDeletedEqualTo(true).andDeleteTimeLessThanOrEqualTo(timestamp);
List<Project> projects = projectMapper.selectByExample(example);
if (!CollectionUtils.isEmpty(projects)) {
commonProjectService.deleteProject(projects);
for (int i = 0; i < projects.size(); i++) {
//对项目进行分批处理
if (i % 100 == 0) {
commonProjectService.deleteProject(projects.subList(i, Math.min(i + 100, projects.size())));
}
}
}
}
}

View File

@ -176,15 +176,20 @@ public class CommonProjectService {
}
public List<ProjectDTO> buildUserInfo(List<ProjectDTO> projectList) {
Map<String, String> userMap = baseUserService.getUserNameMap();
//取项目的创建人 修改人 删除人到一个list中
List<String> userIds = new ArrayList<>();
userIds.addAll(projectList.stream().map(ProjectDTO::getCreateUser).toList());
userIds.addAll(projectList.stream().map(ProjectDTO::getUpdateUser).toList());
userIds.addAll(projectList.stream().map(ProjectDTO::getDeleteUser).toList());
Map<String, String> userMap = baseUserService.getUserNameMap(userIds.stream().distinct().toList());
projectList.forEach(projectDTO -> {
if (StringUtils.isNotBlank(projectDTO.getModuleSetting())) {
projectDTO.setModuleIds(JSON.parseArray(projectDTO.getModuleSetting(), String.class));
}
List<User> users = extSystemProjectMapper.getProjectAdminList(projectDTO.getId());
projectDTO.setAdminList(users);
List<String> userIds = users.stream().map(User::getId).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(userIds) && userIds.contains(projectDTO.getCreateUser())) {
List<String> userIdList = users.stream().map(User::getId).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(userIdList) && userIdList.contains(projectDTO.getCreateUser())) {
projectDTO.setProjectCreateUserIsAdmin(true);
}
projectDTO.setCreateUser(userMap.get(projectDTO.getCreateUser()));

View File

@ -800,7 +800,11 @@ public class OrganizationService {
* @return 组织集合
*/
private List<OrganizationDTO> buildUserInfo(List<OrganizationDTO> organizationDTOS) {
Map<String, String> userMap = baseUserService.getUserNameMap();
List<String> userIds = new ArrayList<>();
userIds.addAll(organizationDTOS.stream().map(OrganizationDTO::getCreateUser).toList());
userIds.addAll(organizationDTOS.stream().map(OrganizationDTO::getUpdateUser).toList());
userIds.addAll(organizationDTOS.stream().map(OrganizationDTO::getDeleteUser).toList());
Map<String, String> userMap = baseUserService.getUserNameMap(userIds.stream().distinct().toList());
organizationDTOS.forEach(organizationDTO -> {
organizationDTO.setCreateUser(userMap.get(organizationDTO.getCreateUser()));
organizationDTO.setDeleteUser(userMap.get(organizationDTO.getDeleteUser()));