fix: 删除项目清理定时任务

This commit is contained in:
chenjianxing 2021-07-23 14:39:45 +08:00 committed by jianxing
parent fadc226307
commit 29ccf9ce0e
3 changed files with 31 additions and 0 deletions

View File

@ -86,6 +86,8 @@ public class ProjectService {
private ExtUserGroupMapper extUserGroupMapper;
@Resource
private ExtUserMapper extUserMapper;
@Resource
private ScheduleService scheduleService;
public Project addProject(Project project) {
if (StringUtils.isBlank(project.getName())) {
@ -189,6 +191,9 @@ public class ProjectService {
// delete project
projectMapper.deleteByPrimaryKey(projectId);
// 删除定时任务
scheduleService.deleteByProjectId(projectId);
}
private void deleteProjectUserGroup(String projectId) {

View File

@ -98,6 +98,27 @@ public class ScheduleService {
return scheduleMapper.deleteByExample(scheduleExample);
}
public int deleteByProjectId(String projectId) {
ScheduleExample scheduleExample = new ScheduleExample();
scheduleExample.createCriteria().andProjectIdEqualTo(projectId);
List<Schedule> schedules = scheduleMapper.selectByExample(scheduleExample);
schedules.forEach(item -> {
removeJob(item.getKey(), item.getGroup());
swaggerUrlProjectMapper.deleteByPrimaryKey(item.getResourceId());
});
return scheduleMapper.deleteByExample(scheduleExample);
}
public int deleteByWorkspaceId(String workspaceId) {
ScheduleExample scheduleExample = new ScheduleExample();
scheduleExample.createCriteria().andWorkspaceIdEqualTo(workspaceId);
List<Schedule> schedules = scheduleMapper.selectByExample(scheduleExample);
schedules.forEach(item -> {
removeJob(item.getResourceId(), item.getGroup());
});
return scheduleMapper.deleteByExample(scheduleExample);
}
private void removeJob(String resourceId, String group) {
if(StringUtils.equals(ScheduleGroup.API_SCENARIO_TEST.name(), group)){
scheduleManager.removeJob(ApiScenarioTestJob.getJobKey(resourceId), ApiScenarioTestJob.getTriggerKey(resourceId));

View File

@ -55,6 +55,8 @@ public class WorkspaceService {
private ExtUserGroupMapper extUserGroupMapper;
@Resource
private ExtUserMapper extUserMapper;
@Resource
private ScheduleService scheduleService;
public Workspace saveWorkspace(Workspace workspace) {
if (StringUtils.isBlank(workspace.getName())) {
@ -131,6 +133,9 @@ public class WorkspaceService {
// delete workspace
workspaceMapper.deleteByPrimaryKey(workspaceId);
// 删除定时任务
scheduleService.deleteByWorkspaceId(workspaceId);
}
/**