fix(系统设置): 修复组织项目定时任务清理问题
--bug=1034900 --user=宋昌昌 【系统设置】系统-组织与项目-删除组织/项目-闹钟倒计时实时更新 https://www.tapd.cn/55049933/s/1456921
This commit is contained in:
parent
4285d5a82b
commit
e34be8e23d
|
@ -49,4 +49,10 @@ public class OrganizationDTO extends Organization {
|
||||||
*/
|
*/
|
||||||
@Schema(description = "创建人是否是管理员")
|
@Schema(description = "创建人是否是管理员")
|
||||||
private Boolean orgCreateUserIsAdmin;
|
private Boolean orgCreateUserIsAdmin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 剩余删除保留天数
|
||||||
|
*/
|
||||||
|
@Schema(description = "剩余删除保留天数")
|
||||||
|
private Integer remainDayCount;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ public class ProjectDTO extends Project implements Serializable {
|
||||||
private List<String> moduleIds;
|
private List<String> moduleIds;
|
||||||
@Schema(description = "资源池", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
@Schema(description = "资源池", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||||
private List<ProjectResourcePoolDTO> resourcePoolList;
|
private List<ProjectResourcePoolDTO> resourcePoolList;
|
||||||
|
@Schema(description = "剩余删除保留天数")
|
||||||
|
private Integer remainDayCount;
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import jakarta.annotation.Resource;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -31,8 +31,8 @@ public class CleanOrganizationJob {
|
||||||
public void cleanOrganization() {
|
public void cleanOrganization() {
|
||||||
LogUtils.info("clean up organization start.");
|
LogUtils.info("clean up organization start.");
|
||||||
try {
|
try {
|
||||||
LocalDate date = LocalDate.now().minusMonths(1);
|
LocalDateTime dateTime = LocalDateTime.now().minusDays(30);
|
||||||
long timestamp = date.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
long timestamp = dateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||||
this.doCleanupOrganization(timestamp);
|
this.doCleanupOrganization(timestamp);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtils.error("clean up organization error.", e);
|
LogUtils.error("clean up organization error.", e);
|
||||||
|
|
|
@ -12,7 +12,7 @@ import io.metersphere.system.service.CommonProjectService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@ public class CleanProjectJob {
|
||||||
@QuartzScheduled(cron = "0 0 3 * * ?")
|
@QuartzScheduled(cron = "0 0 3 * * ?")
|
||||||
public void cleanupProject() {
|
public void cleanupProject() {
|
||||||
LogUtils.info("clean up project start.");
|
LogUtils.info("clean up project start.");
|
||||||
LocalDate date = LocalDate.now().minusMonths(1);
|
LocalDateTime dateTime = LocalDateTime.now().minusDays(30);
|
||||||
long timestamp = date.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
long timestamp = dateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||||
this.doCleanupProject(timestamp);
|
this.doCleanupProject(timestamp);
|
||||||
LogUtils.info("clean up project end.");
|
LogUtils.info("clean up project end.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import io.metersphere.system.mapper.*;
|
||||||
import io.metersphere.system.uid.IDGenerator;
|
import io.metersphere.system.uid.IDGenerator;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -72,6 +73,7 @@ public class CommonProjectService {
|
||||||
private ProjectTestResourcePoolMapper projectTestResourcePoolMapper;
|
private ProjectTestResourcePoolMapper projectTestResourcePoolMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private TestResourcePoolService testResourcePoolService;
|
private TestResourcePoolService testResourcePoolService;
|
||||||
|
public static final Integer DEFAULT_REMAIN_DAY_COUNT = 30;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public CommonProjectService(ProjectServiceInvoker serviceInvoker) {
|
public CommonProjectService(ProjectServiceInvoker serviceInvoker) {
|
||||||
|
@ -255,6 +257,9 @@ public class CommonProjectService {
|
||||||
projectDTO.setCreateUser(userMap.get(projectDTO.getCreateUser()));
|
projectDTO.setCreateUser(userMap.get(projectDTO.getCreateUser()));
|
||||||
projectDTO.setUpdateUser(userMap.get(projectDTO.getUpdateUser()));
|
projectDTO.setUpdateUser(userMap.get(projectDTO.getUpdateUser()));
|
||||||
projectDTO.setDeleteUser(userMap.get(projectDTO.getDeleteUser()));
|
projectDTO.setDeleteUser(userMap.get(projectDTO.getDeleteUser()));
|
||||||
|
if (BooleanUtils.isTrue(projectDTO.getDeleted())) {
|
||||||
|
projectDTO.setRemainDayCount(getDeleteRemainDays(projectDTO.getDeleteTime()));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return projectList;
|
return projectList;
|
||||||
|
@ -675,4 +680,15 @@ public class CommonProjectService {
|
||||||
throw new MSException(Translator.get("project.module_menu.check.error"));
|
throw new MSException(Translator.get("project.module_menu.check.error"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 剩余天数
|
||||||
|
* @param deleteTime 删除时间
|
||||||
|
* @return 剩余天数
|
||||||
|
*/
|
||||||
|
private Integer getDeleteRemainDays(Long deleteTime) {
|
||||||
|
long remainDays = (System.currentTimeMillis() - deleteTime) / (1000 * 3600 * 24);
|
||||||
|
int remainDayCount = DEFAULT_REMAIN_DAY_COUNT - (int) remainDays;
|
||||||
|
return remainDayCount > 0 ? remainDayCount : 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import io.metersphere.system.uid.IDGenerator;
|
||||||
import io.metersphere.system.utils.ServiceUtils;
|
import io.metersphere.system.utils.ServiceUtils;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.ibatis.session.ExecutorType;
|
import org.apache.ibatis.session.ExecutorType;
|
||||||
import org.apache.ibatis.session.SqlSession;
|
import org.apache.ibatis.session.SqlSession;
|
||||||
|
@ -76,6 +77,7 @@ public class OrganizationService {
|
||||||
|
|
||||||
private static final String ADD_MEMBER_PATH = "/system/organization/add-member";
|
private static final String ADD_MEMBER_PATH = "/system/organization/add-member";
|
||||||
private static final String REMOVE_MEMBER_PATH = "/system/organization/remove-member";
|
private static final String REMOVE_MEMBER_PATH = "/system/organization/remove-member";
|
||||||
|
public static final Integer DEFAULT_REMAIN_DAY_COUNT = 30;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页获取系统下组织列表
|
* 分页获取系统下组织列表
|
||||||
|
@ -835,6 +837,9 @@ public class OrganizationService {
|
||||||
organizationDTO.setUpdateUser(userMap.get(organizationDTO.getUpdateUser()));
|
organizationDTO.setUpdateUser(userMap.get(organizationDTO.getUpdateUser()));
|
||||||
organizationDTO.setProjectCount(orgCountMap.get(organizationDTO.getId()).getProjectCount());
|
organizationDTO.setProjectCount(orgCountMap.get(organizationDTO.getId()).getProjectCount());
|
||||||
organizationDTO.setMemberCount(orgCountMap.get(organizationDTO.getId()).getMemberCount());
|
organizationDTO.setMemberCount(orgCountMap.get(organizationDTO.getId()).getMemberCount());
|
||||||
|
if (BooleanUtils.isTrue(organizationDTO.getDeleted())) {
|
||||||
|
organizationDTO.setRemainDayCount(getDeleteRemainDays(organizationDTO.getDeleteTime()));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return organizationDTOS;
|
return organizationDTOS;
|
||||||
}
|
}
|
||||||
|
@ -919,4 +924,15 @@ public class OrganizationService {
|
||||||
public static Organization checkResourceExist(String id) {
|
public static Organization checkResourceExist(String id) {
|
||||||
return ServiceUtils.checkResourceExist( CommonBeanFactory.getBean(OrganizationMapper.class).selectByPrimaryKey(id), "permission.system_organization_project.name");
|
return ServiceUtils.checkResourceExist( CommonBeanFactory.getBean(OrganizationMapper.class).selectByPrimaryKey(id), "permission.system_organization_project.name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 剩余天数
|
||||||
|
* @param deleteTime 删除时间
|
||||||
|
* @return 剩余天数
|
||||||
|
*/
|
||||||
|
private Integer getDeleteRemainDays(Long deleteTime) {
|
||||||
|
long remainDays = (System.currentTimeMillis() - deleteTime) / (1000 * 3600 * 24);
|
||||||
|
int remainDayCount = DEFAULT_REMAIN_DAY_COUNT - (int) remainDays;
|
||||||
|
return remainDayCount > 0 ? remainDayCount : 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,6 +302,8 @@ public class SystemProjectControllerTests extends BaseTest {
|
||||||
initProject.setUpdateTime(System.currentTimeMillis());
|
initProject.setUpdateTime(System.currentTimeMillis());
|
||||||
initProject.setEnable(true);
|
initProject.setEnable(true);
|
||||||
initProject.setModuleSetting("[\"apiTest\",\"uiTest\"]");
|
initProject.setModuleSetting("[\"apiTest\",\"uiTest\"]");
|
||||||
|
initProject.setDeleted(true);
|
||||||
|
initProject.setDeleteTime(System.currentTimeMillis());
|
||||||
projectMapper.insertSelective(initProject);
|
projectMapper.insertSelective(initProject);
|
||||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ INSERT INTO organization(id, num, name, description, create_time, update_time, c
|
||||||
('default-organization-4',null, 'default-4', 'XXX-4', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', null, null);
|
('default-organization-4',null, 'default-4', 'XXX-4', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', null, null);
|
||||||
INSERT INTO organization(id,num, name, description, create_time, update_time, create_user, update_user, delete_user, delete_time) VALUE
|
INSERT INTO organization(id,num, name, description, create_time, update_time, create_user, update_user, delete_user, delete_time) VALUE
|
||||||
('default-organization-5',null, 'default-5', 'XXX-5', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', null, null);
|
('default-organization-5',null, 'default-5', 'XXX-5', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', null, null);
|
||||||
INSERT INTO organization(id, num, name, description, create_time, update_time, create_user, update_user, delete_user, delete_time) VALUE
|
INSERT INTO organization(id, num, name, description, create_time, update_time, create_user, update_user, delete_user, delete_time, deleted) VALUE
|
||||||
('default-organization-6',null, 'default-6', 'XXX-6', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', null, null);
|
('default-organization-6',null, 'default-6', 'XXX-6', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', null, UNIX_TIMESTAMP() * 1000, true);
|
||||||
INSERT INTO user(id, name, email, password, create_time, update_time, language, last_organization_id, phone, source, last_project_id, create_user, update_user) VALUE
|
INSERT INTO user(id, name, email, password, create_time, update_time, language, last_organization_id, phone, source, last_project_id, create_user, update_user) VALUE
|
||||||
('default-admin', 'default-Administrator', 'admin-default@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin');
|
('default-admin', 'default-Administrator', 'admin-default@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin');
|
||||||
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUE
|
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUE
|
||||||
|
|
Loading…
Reference in New Issue