From 7ec75e8f92756236da5fc9c0c45d16f7de0064a3 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Thu, 31 Aug 2023 18:39:00 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2=E6=88=90=E5=91=98?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/sdk/service/BaseUserService.java | 7 ------- .../io/metersphere/system/job/CleanProjectJob.java | 7 ++++++- .../system/service/CommonProjectService.java | 11 ++++++++--- .../system/service/OrganizationService.java | 6 +++++- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/service/BaseUserService.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/service/BaseUserService.java index bfa243e7c5..d283dd8638 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/service/BaseUserService.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/service/BaseUserService.java @@ -437,13 +437,6 @@ public class BaseUserService { return baseUserMapper.getSelectOptionByIdsWithDeleted(ids); } - public Map getUserNameMap() { - List excludeSelectOption = getSelectOptionWithDeleted(); - Map nameMap = new HashMap<>(); - excludeSelectOption.forEach(option -> nameMap.put(option.getId(), option.getName())); - return nameMap; - } - /** * 根据用户ID列表,获取用户 * diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/job/CleanProjectJob.java b/backend/services/system-setting/src/main/java/io/metersphere/system/job/CleanProjectJob.java index e9a9de8e34..c8150fbb8b 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/job/CleanProjectJob.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/job/CleanProjectJob.java @@ -44,7 +44,12 @@ public class CleanProjectJob { example.createCriteria().andDeletedEqualTo(true).andDeleteTimeLessThanOrEqualTo(timestamp); List 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()))); + } + } } } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/CommonProjectService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/CommonProjectService.java index b563c97436..b0c5d74838 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/CommonProjectService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/CommonProjectService.java @@ -176,15 +176,20 @@ public class CommonProjectService { } public List buildUserInfo(List projectList) { - Map userMap = baseUserService.getUserNameMap(); + //取项目的创建人 修改人 删除人到一个list中 + List 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 userMap = baseUserService.getUserNameMap(userIds.stream().distinct().toList()); projectList.forEach(projectDTO -> { if (StringUtils.isNotBlank(projectDTO.getModuleSetting())) { projectDTO.setModuleIds(JSON.parseArray(projectDTO.getModuleSetting(), String.class)); } List users = extSystemProjectMapper.getProjectAdminList(projectDTO.getId()); projectDTO.setAdminList(users); - List userIds = users.stream().map(User::getId).collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(userIds) && userIds.contains(projectDTO.getCreateUser())) { + List 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())); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java index 249f92bc7b..4290771e78 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationService.java @@ -800,7 +800,11 @@ public class OrganizationService { * @return 组织集合 */ private List buildUserInfo(List organizationDTOS) { - Map userMap = baseUserService.getUserNameMap(); + List 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 userMap = baseUserService.getUserNameMap(userIds.stream().distinct().toList()); organizationDTOS.forEach(organizationDTO -> { organizationDTO.setCreateUser(userMap.get(organizationDTO.getCreateUser())); organizationDTO.setDeleteUser(userMap.get(organizationDTO.getDeleteUser()));