diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanBatchEditRequest.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanBatchEditRequest.java index fc2b6857d8..8f4458b7fc 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanBatchEditRequest.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanBatchEditRequest.java @@ -20,9 +20,6 @@ public class TestPlanBatchEditRequest extends TestPlanBatchProcessRequest { @Schema(description = "标签") private List tags; - @Schema(description = "定时任务是否开启") - private boolean scheduleOpen; - - @Schema(description = "本次编辑的字段", allowableValues = {"TAGS", "SCHEDULE"}) + @Schema(description = "本次编辑的字段", allowableValues = {"TAGS"}) private String editColumn; } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanScheduleBatchConfigRequest.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanScheduleBatchConfigRequest.java index ca6f15629d..5d9fc028cd 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanScheduleBatchConfigRequest.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanScheduleBatchConfigRequest.java @@ -1,7 +1,6 @@ package io.metersphere.plan.dto.request; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; import lombok.Data; @@ -15,7 +14,6 @@ public class TestPlanScheduleBatchConfigRequest extends TestPlanBatchProcessRequ private boolean enable; @Schema(description = "Cron表达式") - @NotBlank @Size(max = 255, message = "{length.too.large}") private String cron; diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanScheduleService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanScheduleService.java index b752fea2c4..93158d6f8f 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanScheduleService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanScheduleService.java @@ -15,6 +15,7 @@ import io.metersphere.system.dto.request.schedule.BaseScheduleConfigRequest; import io.metersphere.system.schedule.ScheduleService; import jakarta.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -37,39 +38,45 @@ public class TestPlanScheduleService { List ids = request.getSelectIds(); if (CollectionUtils.isNotEmpty(ids)) { TestPlanExample example = new TestPlanExample(); - example.createCriteria().andIdIn(ids).andGroupIdIsNotNull(); + example.createCriteria().andIdIn(ids); List testPlanList = testPlanMapper.selectByExample(example); for (TestPlan testPlan : testPlanList) { - ScheduleConfig scheduleConfig = ScheduleConfig.builder() - .resourceId(testPlan.getId()) - .key(testPlan.getId()) - .projectId(testPlan.getProjectId()) - .name(testPlan.getName()) - .enable(request.isEnable()) - .cron(request.getCron()) - .resourceType(StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_PLAN) ? ScheduleResourceType.TEST_PLAN.name() : ScheduleResourceType.TEST_PLAN_GROUP.name()) - .config(JSON.toJSONString(request.getRunConfig())) - .build(); + if (MapUtils.isEmpty(request.getRunConfig()) && StringUtils.isBlank(request.getCron())) { + // 这里仅仅是开启/关闭定时任务 + scheduleService.updateIfExist(testPlan.getId(), request.isEnable(), TestPlanScheduleJob.getJobKey(testPlan.getId()), + TestPlanScheduleJob.getTriggerKey(testPlan.getId()), TestPlanScheduleJob.class, operator); + } else { + ScheduleConfig scheduleConfig = ScheduleConfig.builder() + .resourceId(testPlan.getId()) + .key(testPlan.getId()) + .projectId(testPlan.getProjectId()) + .name(testPlan.getName()) + .enable(request.isEnable()) + .cron(request.getCron()) + .resourceType(StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_PLAN) ? ScheduleResourceType.TEST_PLAN.name() : ScheduleResourceType.TEST_PLAN_GROUP.name()) + .config(JSON.toJSONString(request.getRunConfig())) + .build(); - if (request.isEnable() && StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) { - //配置开启的测试计划组定时任务,要将组下的所有测试计划定时任务都关闭掉 - TestPlanExample childExample = new TestPlanExample(); - childExample.createCriteria().andGroupIdEqualTo(testPlan.getId()).andStatusNotEqualTo(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED); - childExample.setOrderByClause("pos asc"); - List children = testPlanMapper.selectByExample(childExample); - for (TestPlan child : children) { - scheduleService.updateIfExist(child.getId(), false, TestPlanScheduleJob.getJobKey(testPlan.getId()), - TestPlanScheduleJob.getTriggerKey(testPlan.getId()), - TestPlanScheduleJob.class, operator); + if (request.isEnable() && StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) { + //配置开启的测试计划组定时任务,要将组下的所有测试计划定时任务都关闭掉 + TestPlanExample childExample = new TestPlanExample(); + childExample.createCriteria().andGroupIdEqualTo(testPlan.getId()).andStatusNotEqualTo(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED); + childExample.setOrderByClause("pos asc"); + List children = testPlanMapper.selectByExample(childExample); + for (TestPlan child : children) { + scheduleService.updateIfExist(child.getId(), false, TestPlanScheduleJob.getJobKey(testPlan.getId()), + TestPlanScheduleJob.getTriggerKey(testPlan.getId()), + TestPlanScheduleJob.class, operator); + } } - } - scheduleService.scheduleConfig( - scheduleConfig, - TestPlanScheduleJob.getJobKey(testPlan.getId()), - TestPlanScheduleJob.getTriggerKey(testPlan.getId()), - TestPlanScheduleJob.class, - operator); + scheduleService.scheduleConfig( + scheduleConfig, + TestPlanScheduleJob.getJobKey(testPlan.getId()), + TestPlanScheduleJob.getTriggerKey(testPlan.getId()), + TestPlanScheduleJob.class, + operator); + } } testPlanLogService.batchScheduleLog(request.getProjectId(), testPlanList, operator); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java index 501589d27d..521105532a 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -745,21 +745,10 @@ public class TestPlanService extends TestPlanBaseUtilsService { // 目前计划的批量操作不支持全选所有页 List ids = request.getSelectIds(); if (CollectionUtils.isNotEmpty(ids)) { - if (StringUtils.equalsIgnoreCase(request.getEditColumn(), "SCHEDULE")) { - TestPlanExample example = new TestPlanExample(); - example.createCriteria().andIdIn(ids).andStatusNotEqualTo(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED); - List testPlanList = testPlanMapper.selectByExample(example); - //批量编辑定时任务 - for (TestPlan testPlan : testPlanList) { - scheduleService.updateIfExist(testPlan.getId(), request.isScheduleOpen(), TestPlanScheduleJob.getJobKey(testPlan.getId()), - TestPlanScheduleJob.getTriggerKey(testPlan.getId()), TestPlanScheduleJob.class, userId); - } - } else { //默认编辑tags User user = userMapper.selectByPrimaryKey(userId); handleTags(request, userId, ids); testPlanSendNoticeService.batchSendNotice(request.getProjectId(), ids, user, NoticeConstants.Event.UPDATE); - } } } diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java index 59f0c4079b..ba5593245a 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java @@ -1547,6 +1547,17 @@ public class TestPlanTests extends BaseTest { testPlanTestService.checkSchedule(groupTestPlanId15, batchRequest.isEnable()); batchRequest.setEnable(true); this.requestPostWithOk(URL_POST_TEST_PLAN_BATCH_SCHEDULE, batchRequest); + + //测试只是关闭 + batchRequest = new TestPlanScheduleBatchConfigRequest(); + batchRequest.setProjectId(project.getId()); + batchRequest.setEnable(false); + batchRequest.setSelectIds(new ArrayList<>(List.of(groupTestPlanId7, groupTestPlanId15))); + this.requestPostWithOk(URL_POST_TEST_PLAN_BATCH_SCHEDULE, batchRequest); + //测试只是开启 + batchRequest.setEnable(true); + this.requestPostWithOk(URL_POST_TEST_PLAN_BATCH_SCHEDULE, batchRequest); + testPlanTestService.checkSchedule(groupTestPlanId7, batchRequest.isEnable()); testPlanTestService.checkSchedule(groupTestPlanId15, batchRequest.isEnable()); //增加日志检查