From 7eb40fb179afc549d446d61a804a6da43ae672dc Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Wed, 6 Sep 2023 11:27:23 +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=E9=A1=B9=E7=9B=AE=E7=9A=84=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E5=88=A0=E9=99=A4=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/i18n/commons_en_US.properties | 4 +++- .../resources/i18n/commons_zh_CN.properties | 4 +++- .../resources/i18n/commons_zh_TW.properties | 4 +++- .../system/job/CleanProjectJob.java | 21 +++++++++---------- .../system/mapper/ExtSystemProjectMapper.java | 2 -- .../system/mapper/ExtSystemProjectMapper.xml | 3 --- .../system/service/CommonProjectService.java | 6 +++++- 7 files changed, 24 insertions(+), 20 deletions(-) diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties index e3468654bd..21d3bae1c3 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties @@ -436,4 +436,6 @@ permission.recover=Recover file_name_illegal_error=File name is invalid plugin_enable_error=Plugin is not enabled -plugin_permission_error=No access to this plugin \ No newline at end of file +plugin_permission_error=No access to this plugin + +scheduled_tasks=Scheduled Tasks \ No newline at end of file diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties index 13ca5665af..5ae87eb661 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties @@ -435,4 +435,6 @@ permission.recover=恢复 file_name_illegal_error=文件名不合法 plugin_enable_error=插件未启用 -plugin_permission_error=没有该插件的访问权限 \ No newline at end of file +plugin_permission_error=没有该插件的访问权限 + +scheduled_tasks=定时任务 \ No newline at end of file diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties index cf4d926c9f..780bbe02a3 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties @@ -433,4 +433,6 @@ permission.recover=恢復 file_name_illegal_error=文件名不合法 plugin_enable_error=插件未啟用 -plugin_permission_error=沒有該插件的訪問權限 \ No newline at end of file +plugin_permission_error=沒有該插件的訪問權限 + +scheduled_tasks=定時任務 \ No newline at end of file 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 af244ca9c2..a8fb5833b4 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 @@ -2,11 +2,12 @@ package io.metersphere.system.job; import com.fit2cloud.quartz.anno.QuartzScheduled; +import com.github.pagehelper.PageHelper; import io.metersphere.project.domain.Project; import io.metersphere.project.domain.ProjectExample; import io.metersphere.project.mapper.ProjectMapper; +import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.LogUtils; -import io.metersphere.system.mapper.ExtSystemProjectMapper; import io.metersphere.system.service.CommonProjectService; import jakarta.annotation.Resource; import org.springframework.stereotype.Component; @@ -20,10 +21,6 @@ public class CleanProjectJob { @Resource private ProjectMapper projectMapper; - @Resource - private ExtSystemProjectMapper extSystemProjectMapper; - @Resource - private CommonProjectService commonProjectService; /** * 清理状态为删除的项目 每天凌晨三点执行 @@ -42,12 +39,14 @@ public class CleanProjectJob { ProjectExample example = new ProjectExample(); example.createCriteria().andDeletedEqualTo(true).andDeleteTimeLessThanOrEqualTo(timestamp); long count = projectMapper.countByExample(example); - for (int i = 0; i < count; i++) { - //对项目进行分批处理 - if (i % 100 == 0) { - List deleteProjectIds = extSystemProjectMapper.getDeleteProjectIds(timestamp, i); - commonProjectService.deleteProject(deleteProjectIds); - } + CommonProjectService commonProjectService = CommonBeanFactory.getBean(CommonProjectService.class); + while (count > 0) { + PageHelper.startPage(1, 100); + List projects = projectMapper.selectByExample(example); + assert commonProjectService != null; + commonProjectService.deleteProject(projects); + count = projectMapper.countByExample(example); + LogUtils.info("剩余项目数量为===================" + count); } } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.java index c806c25f90..a2fd454029 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.java @@ -1,6 +1,5 @@ package io.metersphere.system.mapper; -import io.metersphere.project.domain.Project; import io.metersphere.sdk.dto.ProjectDTO; import io.metersphere.sdk.dto.UserExtend; import io.metersphere.system.dto.OrganizationProjectOptionsDTO; @@ -24,5 +23,4 @@ public interface ExtSystemProjectMapper { List getUserMemberList(@Param("userIds") List userIds, @Param("projectId") String projectId); - List getDeleteProjectIds(@Param("time") long timestamp, @Param("offset") long offset); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.xml index 9cc0d82709..c75c20b3df 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.xml @@ -141,9 +141,6 @@ - \ No newline at end of file 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 d5ab1d0d75..5cb17d7999 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 @@ -200,7 +200,11 @@ public class CommonProjectService { List userIdList = userExtends.stream().map(User::getId).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(userIdList) && userIdList.contains(projectDTO.getCreateUser())) { projectDTO.setProjectCreateUserIsAdmin(true); + } else { + projectDTO.setProjectCreateUserIsAdmin(false); } + } else { + projectDTO.setAdminList(new ArrayList<>()); } projectDTO.setCreateUser(userMap.get(projectDTO.getCreateUser())); projectDTO.setUpdateUser(userMap.get(projectDTO.getUpdateUser())); @@ -442,7 +446,7 @@ public class CommonProjectService { deleteProjectUserGroup(project.getId()); // delete project projectMapper.deleteByPrimaryKey(project.getId()); - LogDTO logDTO = new LogDTO(OperationLogConstants.SYSTEM, project.getOrganizationId(), project.getId(), StringUtils.EMPTY, OperationLogType.DELETE.name(), OperationLogModule.SYSTEM_PROJECT, Translator.get("delete") + Translator.get("project") + ": " + project.getName()); + LogDTO logDTO = new LogDTO(OperationLogConstants.SYSTEM, project.getOrganizationId(), project.getId(), Translator.get("scheduled_tasks"), OperationLogType.DELETE.name(), OperationLogModule.SETTING_ORGANIZATION_PROJECT, Translator.get("delete") + Translator.get("project") + ": " + project.getName()); setLog(logDTO, StringUtils.EMPTY, StringUtils.EMPTY, logDTOList); }); operationLogService.batchAdd(logDTOList);