feat(任务中心): 任务中心模块-定时任务-删除

This commit is contained in:
fit2-zhao 2024-01-27 12:39:26 +08:00 committed by Craftsman
parent c7432a3d23
commit 7e6df3c04f
19 changed files with 45 additions and 25 deletions

View File

@ -17,7 +17,7 @@ import io.metersphere.system.domain.Schedule;
import io.metersphere.system.domain.ScheduleExample; import io.metersphere.system.domain.ScheduleExample;
import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.mapper.ScheduleMapper; import io.metersphere.system.mapper.ScheduleMapper;
import io.metersphere.system.sechedule.ScheduleService; import io.metersphere.system.schedule.ScheduleService;
import io.metersphere.system.service.CleanupProjectResourceService; import io.metersphere.system.service.CleanupProjectResourceService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;

View File

@ -23,7 +23,7 @@ import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService; import io.metersphere.system.log.service.OperationLogService;
import io.metersphere.system.mapper.ScheduleMapper; import io.metersphere.system.mapper.ScheduleMapper;
import io.metersphere.system.sechedule.ScheduleService; import io.metersphere.system.schedule.ScheduleService;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.uid.NumGenerator; import io.metersphere.system.uid.NumGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;

View File

@ -8,7 +8,7 @@ import io.metersphere.api.service.definition.ApiDefinitionScheduleService;
import io.metersphere.api.service.definition.ApiDefinitionService; import io.metersphere.api.service.definition.ApiDefinitionService;
import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.system.sechedule.BaseScheduleJob; import io.metersphere.system.schedule.BaseScheduleJob;
import org.quartz.JobDataMap; import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;
import org.quartz.JobKey; import org.quartz.JobKey;

View File

@ -5,7 +5,7 @@ import io.metersphere.bug.service.XpackBugService;
import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.dto.sdk.LicenseDTO; import io.metersphere.system.dto.sdk.LicenseDTO;
import io.metersphere.system.sechedule.BaseScheduleJob; import io.metersphere.system.schedule.BaseScheduleJob;
import io.metersphere.system.service.LicenseService; import io.metersphere.system.service.LicenseService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;

View File

@ -1,6 +1,6 @@
package io.metersphere.project.job; package io.metersphere.project.job;
import io.metersphere.system.sechedule.BaseScheduleJob; import io.metersphere.system.schedule.BaseScheduleJob;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;
import org.quartz.JobKey; import org.quartz.JobKey;
import org.quartz.TriggerKey; import org.quartz.TriggerKey;

View File

@ -1,6 +1,6 @@
package io.metersphere.project.job; package io.metersphere.project.job;
import io.metersphere.system.sechedule.BaseScheduleJob; import io.metersphere.system.schedule.BaseScheduleJob;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;
import org.quartz.JobKey; import org.quartz.JobKey;
import org.quartz.TriggerKey; import org.quartz.TriggerKey;

View File

@ -3,7 +3,7 @@ package io.metersphere.project.service;
import io.metersphere.project.domain.ProjectApplicationExample; import io.metersphere.project.domain.ProjectApplicationExample;
import io.metersphere.project.mapper.ProjectApplicationMapper; import io.metersphere.project.mapper.ProjectApplicationMapper;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.sechedule.ScheduleService; import io.metersphere.system.schedule.ScheduleService;
import io.metersphere.system.service.CleanupProjectResourceService; import io.metersphere.system.service.CleanupProjectResourceService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -4,7 +4,7 @@ import io.metersphere.project.job.CleanUpReportJob;
import io.metersphere.sdk.constants.ScheduleResourceType; import io.metersphere.sdk.constants.ScheduleResourceType;
import io.metersphere.sdk.constants.ScheduleType; import io.metersphere.sdk.constants.ScheduleType;
import io.metersphere.system.domain.Schedule; import io.metersphere.system.domain.Schedule;
import io.metersphere.system.sechedule.ScheduleService; import io.metersphere.system.schedule.ScheduleService;
import io.metersphere.system.service.CreateProjectResourceService; import io.metersphere.system.service.CreateProjectResourceService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -27,7 +27,7 @@ import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.mapper.PluginMapper; import io.metersphere.system.mapper.PluginMapper;
import io.metersphere.system.mapper.ServiceIntegrationMapper; import io.metersphere.system.mapper.ServiceIntegrationMapper;
import io.metersphere.system.sechedule.ScheduleService; import io.metersphere.system.schedule.ScheduleService;
import io.metersphere.system.service.PlatformPluginService; import io.metersphere.system.service.PlatformPluginService;
import io.metersphere.system.service.PluginLoadService; import io.metersphere.system.service.PluginLoadService;
import io.metersphere.system.service.ServiceIntegrationService; import io.metersphere.system.service.ServiceIntegrationService;

View File

@ -1,7 +1,7 @@
package io.metersphere.system.config; package io.metersphere.system.config;
import io.metersphere.system.sechedule.ScheduleService; import io.metersphere.system.schedule.ScheduleService;
import io.metersphere.system.sechedule.ScheduleManager; import io.metersphere.system.schedule.ScheduleManager;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

View File

@ -53,7 +53,7 @@ public class TaskCenterController {
return taskCenterService.getSystemSchedulePage(request); return taskCenterService.getSystemSchedulePage(request);
} }
@GetMapping("/scheduled/delete/{id}") @GetMapping("/schedule/delete/{id}")
@Operation(summary = "系统-任务中心-删除定时任务") @Operation(summary = "系统-任务中心-删除定时任务")
@CheckOwner(resourceId = "#id", resourceType = "scheduled") @CheckOwner(resourceId = "#id", resourceType = "scheduled")
public void delete(@PathVariable String id) { public void delete(@PathVariable String id) {

View File

@ -0,0 +1,7 @@
package io.metersphere.system.mapper;
public interface ExtSwaggerMapper {
int deleteByPrimaryKey(String id);
int selectByPrimaryKey(String id);
}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.system.mapper.ExtSwaggerMapper">
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from api_definition_swagger
where id = #{id,jdbcType=VARCHAR}
</delete>
<select id="selectByPrimaryKey" parameterType="java.lang.String">
select count(*) from api_definition_swagger where id = #{id,jdbcType=VARCHAR}
</select>
</mapper>

View File

@ -1,4 +1,4 @@
package io.metersphere.system.sechedule; package io.metersphere.system.schedule;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import org.quartz.*; import org.quartz.*;

View File

@ -1,4 +1,4 @@
package io.metersphere.system.sechedule; package io.metersphere.system.schedule;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;

View File

@ -1,4 +1,4 @@
package io.metersphere.system.sechedule; package io.metersphere.system.schedule;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.system.domain.Schedule; import io.metersphere.system.domain.Schedule;
@ -10,6 +10,7 @@ import org.apache.commons.lang3.StringUtils;
import org.quartz.JobKey; import org.quartz.JobKey;
import org.quartz.SchedulerException; import org.quartz.SchedulerException;
import org.quartz.TriggerKey; import org.quartz.TriggerKey;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
@ -46,7 +47,7 @@ public class ScheduleService {
example.createCriteria().andResourceIdEqualTo(resourceId).andJobEqualTo(job); example.createCriteria().andResourceIdEqualTo(resourceId).andJobEqualTo(job);
List<Schedule> schedules = scheduleMapper.selectByExample(example); List<Schedule> schedules = scheduleMapper.selectByExample(example);
if (CollectionUtils.isNotEmpty(schedules)) { if (CollectionUtils.isNotEmpty(schedules)) {
return schedules.get(0); return schedules.getFirst();
} }
return null; return null;
} }

View File

@ -3,7 +3,6 @@ package io.metersphere.system.service;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.page.PageMethod; import com.github.pagehelper.page.PageMethod;
import io.metersphere.api.domain.ApiScenario; import io.metersphere.api.domain.ApiScenario;
import io.metersphere.api.mapper.ApiDefinitionSwaggerMapper;
import io.metersphere.project.domain.Project; import io.metersphere.project.domain.Project;
import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.ScheduleResourceType; import io.metersphere.sdk.constants.ScheduleResourceType;
@ -16,7 +15,7 @@ import io.metersphere.system.dto.taskcenter.TaskCenterScheduleDTO;
import io.metersphere.system.dto.taskcenter.enums.ScheduleTagType; import io.metersphere.system.dto.taskcenter.enums.ScheduleTagType;
import io.metersphere.system.dto.taskcenter.request.TaskCenterSchedulePageRequest; import io.metersphere.system.dto.taskcenter.request.TaskCenterSchedulePageRequest;
import io.metersphere.system.mapper.*; import io.metersphere.system.mapper.*;
import io.metersphere.system.sechedule.ScheduleService; import io.metersphere.system.schedule.ScheduleService;
import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.PageUtils;
import io.metersphere.system.utils.Pager; import io.metersphere.system.utils.Pager;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -59,7 +58,7 @@ public class TaskCenterService {
OrganizationMapper organizationMapper; OrganizationMapper organizationMapper;
@Resource @Resource
ApiDefinitionSwaggerMapper apiDefinitionSwaggerMapper; ExtSwaggerMapper extSwaggerMapper;
@Resource @Resource
ScheduleMapper scheduleMapper; ScheduleMapper scheduleMapper;
@ -224,7 +223,7 @@ public class TaskCenterService {
public void delete(String id) { public void delete(String id) {
Schedule schedule = checkScheduleExit(id); Schedule schedule = checkScheduleExit(id);
if (ScheduleTagType.API_IMPORT.getNames().contains(schedule.getResourceType())) { if (ScheduleTagType.API_IMPORT.getNames().contains(schedule.getResourceType())) {
apiDefinitionSwaggerMapper.deleteByPrimaryKey(schedule.getResourceId()); extSwaggerMapper.deleteByPrimaryKey(schedule.getResourceId());
} }
scheduleService.deleteByResourceId(schedule.getResourceId(), schedule.getJob()); scheduleService.deleteByResourceId(schedule.getResourceId(), schedule.getJob());
} }

View File

@ -10,6 +10,7 @@ import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.domain.Schedule; import io.metersphere.system.domain.Schedule;
import io.metersphere.system.dto.taskcenter.enums.ScheduleTagType; import io.metersphere.system.dto.taskcenter.enums.ScheduleTagType;
import io.metersphere.system.dto.taskcenter.request.TaskCenterSchedulePageRequest; import io.metersphere.system.dto.taskcenter.request.TaskCenterSchedulePageRequest;
import io.metersphere.system.mapper.ExtSwaggerMapper;
import io.metersphere.system.mapper.ScheduleMapper; import io.metersphere.system.mapper.ScheduleMapper;
import io.metersphere.system.utils.Pager; import io.metersphere.system.utils.Pager;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -41,7 +42,7 @@ class TaskCenterScheduleControllerTests extends BaseTest {
private final static String SCHEDULED_PROJECT_PAGE = BASE_PATH + "project/schedule/page"; private final static String SCHEDULED_PROJECT_PAGE = BASE_PATH + "project/schedule/page";
private final static String SCHEDULED_ORG_PAGE = BASE_PATH + "org/schedule/page"; private final static String SCHEDULED_ORG_PAGE = BASE_PATH + "org/schedule/page";
private final static String SCHEDULED_SYSTEM_PAGE = BASE_PATH + "system/schedule/page"; private final static String SCHEDULED_SYSTEM_PAGE = BASE_PATH + "system/schedule/page";
private final static String SCHEDULED_DELETE = BASE_PATH + "scheduled/delete/"; private final static String SCHEDULED_DELETE = BASE_PATH + "schedule/delete/";
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError(); private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
@ -49,7 +50,7 @@ class TaskCenterScheduleControllerTests extends BaseTest {
ScheduleMapper scheduleMapper; ScheduleMapper scheduleMapper;
@Resource @Resource
ApiDefinitionSwaggerMapper apiDefinitionSwaggerMapper; ExtSwaggerMapper extSwaggerMapper;
@ -160,8 +161,8 @@ class TaskCenterScheduleControllerTests extends BaseTest {
Schedule schedule = scheduleMapper.selectByPrimaryKey(scheduleId); Schedule schedule = scheduleMapper.selectByPrimaryKey(scheduleId);
Assertions.assertNull(schedule); Assertions.assertNull(schedule);
if (ScheduleTagType.API_IMPORT.getNames().contains(oldSchedule.getType())) { if (ScheduleTagType.API_IMPORT.getNames().contains(oldSchedule.getType())) {
ApiDefinitionSwagger apiDefinitionSwagger = apiDefinitionSwaggerMapper.selectByPrimaryKey(oldSchedule.getResourceId()); int count = extSwaggerMapper.selectByPrimaryKey(oldSchedule.getResourceId());
Assertions.assertNull(apiDefinitionSwagger); Assertions.assertTrue(count > 0);
} }
this.requestGet(SCHEDULED_DELETE + "schedule-121", ERROR_REQUEST_MATCHER); this.requestGet(SCHEDULED_DELETE + "schedule-121", ERROR_REQUEST_MATCHER);
} }

View File

@ -6,7 +6,7 @@ server.compression.enabled=true
server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain,application/javascript,text/css,text/javascript,image/jpeg server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain,application/javascript,text/css,text/javascript,image/jpeg
server.compression.min-response-size=2048 server.compression.min-response-size=2048
# #
quartz.enabled=false quartz.enabled=true
quartz.scheduler-name=msScheduler quartz.scheduler-name=msScheduler
quartz.thread-count=10 quartz.thread-count=10
quartz.properties.org.quartz.jobStore.acquireTriggersWithinLock=true quartz.properties.org.quartz.jobStore.acquireTriggersWithinLock=true