From 7e6df3c04fc3b866154635c8490a720908031fc6 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Sat, 27 Jan 2024 12:39:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83):=20?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83=E6=A8=A1=E5=9D=97-?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1-=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/CleanupApiResourceService.java | 2 +- .../definition/ApiDefinitionScheduleService.java | 2 +- .../api/service/schedule/SwaggerUrlImportJob.java | 2 +- .../main/java/io/metersphere/bug/job/BugSyncJob.java | 2 +- .../java/io/metersphere/project/job/BugSyncJob.java | 2 +- .../io/metersphere/project/job/CleanUpReportJob.java | 2 +- .../service/CleanupApplicationResourceService.java | 2 +- .../service/CreateApplicationResourceService.java | 2 +- .../project/service/ProjectApplicationService.java | 2 +- .../io/metersphere/system/config/ScheduleConfig.java | 4 ++-- .../system/controller/TaskCenterController.java | 2 +- .../metersphere/system/mapper/ExtSwaggerMapper.java | 7 +++++++ .../metersphere/system/mapper/ExtSwaggerMapper.xml | 12 ++++++++++++ .../{sechedule => schedule}/BaseScheduleJob.java | 2 +- .../{sechedule => schedule}/ScheduleManager.java | 2 +- .../{sechedule => schedule}/ScheduleService.java | 5 +++-- .../system/service/TaskCenterService.java | 7 +++---- .../TaskCenterScheduleControllerTests.java | 9 +++++---- .../src/test/resources/application.properties | 2 +- 19 files changed, 45 insertions(+), 25 deletions(-) create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSwaggerMapper.java create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSwaggerMapper.xml rename backend/services/system-setting/src/main/java/io/metersphere/system/{sechedule => schedule}/BaseScheduleJob.java (95%) rename backend/services/system-setting/src/main/java/io/metersphere/system/{sechedule => schedule}/ScheduleManager.java (99%) rename backend/services/system-setting/src/main/java/io/metersphere/system/{sechedule => schedule}/ScheduleService.java (96%) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupApiResourceService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupApiResourceService.java index 938a12f150..c917b57e9d 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupApiResourceService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupApiResourceService.java @@ -17,7 +17,7 @@ import io.metersphere.system.domain.Schedule; import io.metersphere.system.domain.ScheduleExample; import io.metersphere.system.log.constants.OperationLogModule; 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 jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionScheduleService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionScheduleService.java index bb44f32a77..2f15d91cf0 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionScheduleService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionScheduleService.java @@ -23,7 +23,7 @@ import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.log.service.OperationLogService; 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.NumGenerator; import jakarta.annotation.Resource; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/schedule/SwaggerUrlImportJob.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/schedule/SwaggerUrlImportJob.java index 3351973b8c..9f07a1580a 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/schedule/SwaggerUrlImportJob.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/schedule/SwaggerUrlImportJob.java @@ -8,7 +8,7 @@ import io.metersphere.api.service.definition.ApiDefinitionScheduleService; import io.metersphere.api.service.definition.ApiDefinitionService; import io.metersphere.sdk.util.BeanUtils; 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.JobExecutionContext; import org.quartz.JobKey; diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/job/BugSyncJob.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/job/BugSyncJob.java index 756169271f..d9b5e92277 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/job/BugSyncJob.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/job/BugSyncJob.java @@ -5,7 +5,7 @@ import io.metersphere.bug.service.XpackBugService; import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.LogUtils; 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 org.apache.commons.lang3.StringUtils; import org.quartz.JobExecutionContext; diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/job/BugSyncJob.java b/backend/services/project-management/src/main/java/io/metersphere/project/job/BugSyncJob.java index 74dbce12d3..e21c5eb974 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/job/BugSyncJob.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/job/BugSyncJob.java @@ -1,6 +1,6 @@ package io.metersphere.project.job; -import io.metersphere.system.sechedule.BaseScheduleJob; +import io.metersphere.system.schedule.BaseScheduleJob; import org.quartz.JobExecutionContext; import org.quartz.JobKey; import org.quartz.TriggerKey; diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/job/CleanUpReportJob.java b/backend/services/project-management/src/main/java/io/metersphere/project/job/CleanUpReportJob.java index 658a8883e0..b401a767cc 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/job/CleanUpReportJob.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/job/CleanUpReportJob.java @@ -1,6 +1,6 @@ package io.metersphere.project.job; -import io.metersphere.system.sechedule.BaseScheduleJob; +import io.metersphere.system.schedule.BaseScheduleJob; import org.quartz.JobExecutionContext; import org.quartz.JobKey; import org.quartz.TriggerKey; diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/CleanupApplicationResourceService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/CleanupApplicationResourceService.java index e2bd7fd0c3..2e274f466f 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/CleanupApplicationResourceService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/CleanupApplicationResourceService.java @@ -3,7 +3,7 @@ package io.metersphere.project.service; import io.metersphere.project.domain.ProjectApplicationExample; import io.metersphere.project.mapper.ProjectApplicationMapper; 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 jakarta.annotation.Resource; import org.springframework.stereotype.Component; diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/CreateApplicationResourceService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/CreateApplicationResourceService.java index e39a80e1ef..90f2329563 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/CreateApplicationResourceService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/CreateApplicationResourceService.java @@ -4,7 +4,7 @@ import io.metersphere.project.job.CleanUpReportJob; import io.metersphere.sdk.constants.ScheduleResourceType; import io.metersphere.sdk.constants.ScheduleType; 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 jakarta.annotation.Resource; import org.springframework.stereotype.Component; diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java index fd37254b01..fb9dcbb23d 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java @@ -27,7 +27,7 @@ import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.mapper.PluginMapper; 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.PluginLoadService; import io.metersphere.system.service.ServiceIntegrationService; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/config/ScheduleConfig.java b/backend/services/system-setting/src/main/java/io/metersphere/system/config/ScheduleConfig.java index d6aadcb005..95201249d4 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/config/ScheduleConfig.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/config/ScheduleConfig.java @@ -1,7 +1,7 @@ package io.metersphere.system.config; -import io.metersphere.system.sechedule.ScheduleService; -import io.metersphere.system.sechedule.ScheduleManager; +import io.metersphere.system.schedule.ScheduleService; +import io.metersphere.system.schedule.ScheduleManager; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/TaskCenterController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/TaskCenterController.java index 20c6da8046..20c871cf03 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/TaskCenterController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/TaskCenterController.java @@ -53,7 +53,7 @@ public class TaskCenterController { return taskCenterService.getSystemSchedulePage(request); } - @GetMapping("/scheduled/delete/{id}") + @GetMapping("/schedule/delete/{id}") @Operation(summary = "系统-任务中心-删除定时任务") @CheckOwner(resourceId = "#id", resourceType = "scheduled") public void delete(@PathVariable String id) { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSwaggerMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSwaggerMapper.java new file mode 100644 index 0000000000..3764e0c8b3 --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSwaggerMapper.java @@ -0,0 +1,7 @@ +package io.metersphere.system.mapper; +public interface ExtSwaggerMapper { + int deleteByPrimaryKey(String id); + + int selectByPrimaryKey(String id); + +} \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSwaggerMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSwaggerMapper.xml new file mode 100644 index 0000000000..d26b05e69a --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSwaggerMapper.xml @@ -0,0 +1,12 @@ + + + + + delete from api_definition_swagger + where id = #{id,jdbcType=VARCHAR} + + + + \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/sechedule/BaseScheduleJob.java b/backend/services/system-setting/src/main/java/io/metersphere/system/schedule/BaseScheduleJob.java similarity index 95% rename from backend/services/system-setting/src/main/java/io/metersphere/system/sechedule/BaseScheduleJob.java rename to backend/services/system-setting/src/main/java/io/metersphere/system/schedule/BaseScheduleJob.java index 9f5bd77af9..70d93f71c0 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/sechedule/BaseScheduleJob.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/schedule/BaseScheduleJob.java @@ -1,4 +1,4 @@ -package io.metersphere.system.sechedule; +package io.metersphere.system.schedule; import io.metersphere.sdk.util.LogUtils; import org.quartz.*; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/sechedule/ScheduleManager.java b/backend/services/system-setting/src/main/java/io/metersphere/system/schedule/ScheduleManager.java similarity index 99% rename from backend/services/system-setting/src/main/java/io/metersphere/system/sechedule/ScheduleManager.java rename to backend/services/system-setting/src/main/java/io/metersphere/system/schedule/ScheduleManager.java index a325d1d6c5..4649e3c59e 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/sechedule/ScheduleManager.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/schedule/ScheduleManager.java @@ -1,4 +1,4 @@ -package io.metersphere.system.sechedule; +package io.metersphere.system.schedule; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.LogUtils; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/sechedule/ScheduleService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/schedule/ScheduleService.java similarity index 96% rename from backend/services/system-setting/src/main/java/io/metersphere/system/sechedule/ScheduleService.java rename to backend/services/system-setting/src/main/java/io/metersphere/system/schedule/ScheduleService.java index d3a0e29dd8..aeb74bf76c 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/sechedule/ScheduleService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/schedule/ScheduleService.java @@ -1,4 +1,4 @@ -package io.metersphere.system.sechedule; +package io.metersphere.system.schedule; import io.metersphere.sdk.exception.MSException; import io.metersphere.system.domain.Schedule; @@ -10,6 +10,7 @@ import org.apache.commons.lang3.StringUtils; import org.quartz.JobKey; import org.quartz.SchedulerException; import org.quartz.TriggerKey; +import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -46,7 +47,7 @@ public class ScheduleService { example.createCriteria().andResourceIdEqualTo(resourceId).andJobEqualTo(job); List schedules = scheduleMapper.selectByExample(example); if (CollectionUtils.isNotEmpty(schedules)) { - return schedules.get(0); + return schedules.getFirst(); } return null; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/TaskCenterService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/TaskCenterService.java index 8b9111c69d..07d6590088 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/TaskCenterService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/TaskCenterService.java @@ -3,7 +3,6 @@ package io.metersphere.system.service; import com.github.pagehelper.Page; import com.github.pagehelper.page.PageMethod; import io.metersphere.api.domain.ApiScenario; -import io.metersphere.api.mapper.ApiDefinitionSwaggerMapper; import io.metersphere.project.domain.Project; import io.metersphere.project.mapper.ProjectMapper; 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.request.TaskCenterSchedulePageRequest; 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.Pager; import jakarta.annotation.Resource; @@ -59,7 +58,7 @@ public class TaskCenterService { OrganizationMapper organizationMapper; @Resource - ApiDefinitionSwaggerMapper apiDefinitionSwaggerMapper; + ExtSwaggerMapper extSwaggerMapper; @Resource ScheduleMapper scheduleMapper; @@ -224,7 +223,7 @@ public class TaskCenterService { public void delete(String id) { Schedule schedule = checkScheduleExit(id); if (ScheduleTagType.API_IMPORT.getNames().contains(schedule.getResourceType())) { - apiDefinitionSwaggerMapper.deleteByPrimaryKey(schedule.getResourceId()); + extSwaggerMapper.deleteByPrimaryKey(schedule.getResourceId()); } scheduleService.deleteByResourceId(schedule.getResourceId(), schedule.getJob()); } diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TaskCenterScheduleControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TaskCenterScheduleControllerTests.java index 5ba4b94529..069c9c2c21 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TaskCenterScheduleControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TaskCenterScheduleControllerTests.java @@ -10,6 +10,7 @@ import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.domain.Schedule; import io.metersphere.system.dto.taskcenter.enums.ScheduleTagType; import io.metersphere.system.dto.taskcenter.request.TaskCenterSchedulePageRequest; +import io.metersphere.system.mapper.ExtSwaggerMapper; import io.metersphere.system.mapper.ScheduleMapper; import io.metersphere.system.utils.Pager; 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_ORG_PAGE = BASE_PATH + "org/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(); @@ -49,7 +50,7 @@ class TaskCenterScheduleControllerTests extends BaseTest { ScheduleMapper scheduleMapper; @Resource - ApiDefinitionSwaggerMapper apiDefinitionSwaggerMapper; + ExtSwaggerMapper extSwaggerMapper; @@ -160,8 +161,8 @@ class TaskCenterScheduleControllerTests extends BaseTest { Schedule schedule = scheduleMapper.selectByPrimaryKey(scheduleId); Assertions.assertNull(schedule); if (ScheduleTagType.API_IMPORT.getNames().contains(oldSchedule.getType())) { - ApiDefinitionSwagger apiDefinitionSwagger = apiDefinitionSwaggerMapper.selectByPrimaryKey(oldSchedule.getResourceId()); - Assertions.assertNull(apiDefinitionSwagger); + int count = extSwaggerMapper.selectByPrimaryKey(oldSchedule.getResourceId()); + Assertions.assertTrue(count > 0); } this.requestGet(SCHEDULED_DELETE + "schedule-121", ERROR_REQUEST_MATCHER); } diff --git a/backend/services/system-setting/src/test/resources/application.properties b/backend/services/system-setting/src/test/resources/application.properties index 74fd2f49a0..22f31653ec 100644 --- a/backend/services/system-setting/src/test/resources/application.properties +++ b/backend/services/system-setting/src/test/resources/application.properties @@ -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.min-response-size=2048 # -quartz.enabled=false +quartz.enabled=true quartz.scheduler-name=msScheduler quartz.thread-count=10 quartz.properties.org.quartz.jobStore.acquireTriggersWithinLock=true