diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java index 9addb5ab90..7af0a465c6 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java @@ -57,7 +57,7 @@ public class ProjectTaskHubControllerTests extends BaseTest { public static final String PROJECT_SCHEDULE_TASK_SWITCH = "/project/task-center/schedule/switch/"; public static final String PROJECT_SCHEDULE_TASK_BATCH_ENABLE = "/project/task-center/schedule/batch-enable"; public static final String PROJECT_SCHEDULE_TASK_BATCH_DISABLE = "/project/task-center/schedule/batch-disable"; - public static final String PROJECT_SCHEDULE_TASK_UPDATE_CRON = "/organization/task-center/schedule/update-cron"; + public static final String PROJECT_SCHEDULE_TASK_UPDATE_CRON = "/project/task-center/schedule/update-cron"; public static final String PROJECT_BATCH_TASK_PAGE = "/project/task-center/exec-task/batch/page"; @Test @@ -295,6 +295,8 @@ public class ProjectTaskHubControllerTests extends BaseTest { request.setCron("0 0 0 1 * ?"); request.setId("pro_wx_1"); this.requestPost(PROJECT_SCHEDULE_TASK_UPDATE_CRON, request); + request.setId("pro_wx_2"); + this.requestPost(PROJECT_SCHEDULE_TASK_UPDATE_CRON, request); } @Test diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java index 5a55938057..cac184eca1 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java @@ -8,7 +8,10 @@ import io.metersphere.api.mapper.ApiReportRelateTaskMapper; import io.metersphere.engine.EngineFactory; import io.metersphere.engine.MsHttpClient; import io.metersphere.project.domain.Project; +import io.metersphere.project.domain.ProjectApplication; +import io.metersphere.project.domain.ProjectApplicationExample; import io.metersphere.project.domain.ProjectExample; +import io.metersphere.project.mapper.ProjectApplicationMapper; import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.sdk.constants.*; import io.metersphere.sdk.exception.MSException; @@ -122,6 +125,8 @@ public class BaseTaskHubService { ApiScheduleNoticeService apiScheduleNoticeService; @Resource private UserToolService userToolService; + @Resource + private ProjectApplicationMapper projectApplicationMapper; /** @@ -937,6 +942,7 @@ public class BaseTaskHubService { schedule.setValue(request.getCron()); scheduleService.editSchedule(schedule); try { + handleThirdSchedule(schedule, request.getCron()); scheduleService.addOrUpdateCronJob(schedule, new JobKey(schedule.getKey(), schedule.getJob()), new TriggerKey(schedule.getKey(), schedule.getJob()), Class.forName(schedule.getJob())); saveLog(List.of(schedule), userId, path, HttpMethodConstants.GET.name(), module, OperationLogType.UPDATE.name()); @@ -946,6 +952,29 @@ public class BaseTaskHubService { } } + + /** + * 处理三方同步任务 + * + * @param schedule + */ + private void handleThirdSchedule(Schedule schedule, String cron) { + if (StringUtils.equalsAnyIgnoreCase(schedule.getResourceType(), ScheduleResourceType.BUG_SYNC.name(), ScheduleResourceType.DEMAND_SYNC.name())) { + ProjectApplicationExample example = new ProjectApplicationExample(); + ProjectApplicationExample.Criteria criteria = example.createCriteria(); + criteria.andProjectIdEqualTo(schedule.getProjectId()); + if (StringUtils.equalsIgnoreCase(schedule.getResourceType(), ScheduleResourceType.BUG_SYNC.name())) { + criteria.andTypeEqualTo(ProjectApplicationType.BUG.BUG_SYNC.name() + "_" + ProjectApplicationType.BUG_SYNC_CONFIG.CRON_EXPRESSION.name()); + } + if (StringUtils.equalsIgnoreCase(schedule.getResourceType(), ScheduleResourceType.DEMAND_SYNC.name())) { + criteria.andTypeEqualTo(ProjectApplicationType.CASE_RELATED_CONFIG.CASE_RELATED.name() + "_" + ProjectApplicationType.CASE_RELATED_CONFIG.CRON_EXPRESSION.name()); + } + ProjectApplication projectApplication = new ProjectApplication(); + projectApplication.setTypeValue(cron); + projectApplicationMapper.updateByExampleSelective(projectApplication, example); + } + } + /** * 查询批量执行任务报告列表 *