fix(测试计划): 更改测试计划批量开关定时任务的接口
This commit is contained in:
parent
696bd0d88a
commit
851d60c8c6
|
@ -20,9 +20,6 @@ public class TestPlanBatchEditRequest extends TestPlanBatchProcessRequest {
|
|||
@Schema(description = "标签")
|
||||
private List<String> tags;
|
||||
|
||||
@Schema(description = "定时任务是否开启")
|
||||
private boolean scheduleOpen;
|
||||
|
||||
@Schema(description = "本次编辑的字段", allowableValues = {"TAGS", "SCHEDULE"})
|
||||
@Schema(description = "本次编辑的字段", allowableValues = {"TAGS"})
|
||||
private String editColumn;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<String> ids = request.getSelectIds();
|
||||
if (CollectionUtils.isNotEmpty(ids)) {
|
||||
TestPlanExample example = new TestPlanExample();
|
||||
example.createCriteria().andIdIn(ids).andGroupIdIsNotNull();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
List<TestPlan> 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<TestPlan> 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<TestPlan> 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);
|
||||
}
|
||||
|
|
|
@ -745,21 +745,10 @@ public class TestPlanService extends TestPlanBaseUtilsService {
|
|||
// 目前计划的批量操作不支持全选所有页
|
||||
List<String> 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<TestPlan> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
//增加日志检查
|
||||
|
|
Loading…
Reference in New Issue