refactor(系统设置): 优化项目的定时删除任务
This commit is contained in:
parent
db31f408ce
commit
7eb40fb179
|
@ -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
|
||||
plugin_permission_error=No access to this plugin
|
||||
|
||||
scheduled_tasks=Scheduled Tasks
|
|
@ -435,4 +435,6 @@ permission.recover=恢复
|
|||
|
||||
file_name_illegal_error=文件名不合法
|
||||
plugin_enable_error=插件未启用
|
||||
plugin_permission_error=没有该插件的访问权限
|
||||
plugin_permission_error=没有该插件的访问权限
|
||||
|
||||
scheduled_tasks=定时任务
|
|
@ -433,4 +433,6 @@ permission.recover=恢復
|
|||
|
||||
file_name_illegal_error=文件名不合法
|
||||
plugin_enable_error=插件未啟用
|
||||
plugin_permission_error=沒有該插件的訪問權限
|
||||
plugin_permission_error=沒有該插件的訪問權限
|
||||
|
||||
scheduled_tasks=定時任務
|
|
@ -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<Project> deleteProjectIds = extSystemProjectMapper.getDeleteProjectIds(timestamp, i);
|
||||
commonProjectService.deleteProject(deleteProjectIds);
|
||||
}
|
||||
CommonProjectService commonProjectService = CommonBeanFactory.getBean(CommonProjectService.class);
|
||||
while (count > 0) {
|
||||
PageHelper.startPage(1, 100);
|
||||
List<Project> projects = projectMapper.selectByExample(example);
|
||||
assert commonProjectService != null;
|
||||
commonProjectService.deleteProject(projects);
|
||||
count = projectMapper.countByExample(example);
|
||||
LogUtils.info("剩余项目数量为===================" + count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<UserExtend> getUserMemberList(@Param("userIds") List<String> userIds, @Param("projectId") String projectId);
|
||||
|
||||
List<Project> getDeleteProjectIds(@Param("time") long timestamp, @Param("offset") long offset);
|
||||
}
|
||||
|
|
|
@ -141,9 +141,6 @@
|
|||
|
||||
|
||||
</select>
|
||||
<select id="getDeleteProjectIds" resultType="io.metersphere.project.domain.Project">
|
||||
select * from project where deleted = 1 and delete_time <= #{time} limit #{offset}, 100
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
|
@ -200,7 +200,11 @@ public class CommonProjectService {
|
|||
List<String> 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);
|
||||
|
|
Loading…
Reference in New Issue