feat(测试跟踪): 测试计划增加批量删除操作
--story=1010195 --user=李玉号 【测试计划】测试计划新增批量删除功能 https://www.tapd.cn/55049933/s/1291099
This commit is contained in:
parent
f0c2d07833
commit
3a1992cfb0
|
@ -1,14 +1,18 @@
|
||||||
package io.metersphere.listener;
|
package io.metersphere.listener;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import io.metersphere.commons.constants.KafkaTopicConstants;
|
import io.metersphere.commons.constants.KafkaTopicConstants;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
import io.metersphere.service.plan.TestPlanApiCaseService;
|
import io.metersphere.service.plan.TestPlanApiCaseService;
|
||||||
import io.metersphere.service.plan.TestPlanScenarioCaseService;
|
import io.metersphere.service.plan.TestPlanScenarioCaseService;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||||
import org.springframework.kafka.annotation.KafkaListener;
|
import org.springframework.kafka.annotation.KafkaListener;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class TestPlanDeletedListener {
|
public class TestPlanDeletedListener {
|
||||||
|
@ -18,12 +22,22 @@ public class TestPlanDeletedListener {
|
||||||
private TestPlanApiCaseService testPlanApiCaseService;
|
private TestPlanApiCaseService testPlanApiCaseService;
|
||||||
@Resource
|
@Resource
|
||||||
private TestPlanScenarioCaseService testPlanScenarioCaseService;
|
private TestPlanScenarioCaseService testPlanScenarioCaseService;
|
||||||
|
@Resource
|
||||||
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
@KafkaListener(id = CONSUME_ID, topics = KafkaTopicConstants.TEST_PLAN_DELETED_TOPIC, groupId = "${spring.application.name}")
|
@KafkaListener(id = CONSUME_ID, topics = KafkaTopicConstants.TEST_PLAN_DELETED_TOPIC, groupId = "${spring.application.name}")
|
||||||
public void consume(ConsumerRecord<?, String> record) {
|
public void consume(ConsumerRecord<?, String> record) {
|
||||||
String planId = record.value();
|
try {
|
||||||
LogUtil.info("api service consume TEST_PLAN_DELETED_TOPIC message, plan id: " + planId);
|
List<String> planIds = objectMapper.readValue(record.value(), new TypeReference<>() {});
|
||||||
testPlanApiCaseService.deleteByPlanId(planId);
|
if (CollectionUtils.isEmpty(planIds)) {
|
||||||
testPlanScenarioCaseService.deleteByPlanId(planId);
|
return;
|
||||||
|
}
|
||||||
|
LogUtil.info("api service consume TEST_PLAN_DELETED_TOPIC message, planIds: ", planIds);
|
||||||
|
testPlanApiCaseService.deleteByPlanIds(planIds);
|
||||||
|
testPlanScenarioCaseService.deleteByPlanIds(planIds);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtil.error("api service consume TEST_PLAN_DELETED_TOPIC message error, planIds: " + record.value(), e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,6 +186,15 @@ public class TestPlanApiCaseService {
|
||||||
return testPlanApiCaseMapper.deleteByExample(example);
|
return testPlanApiCaseMapper.deleteByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteByPlanIds(List<String> planIds) {
|
||||||
|
if (CollectionUtils.isEmpty(planIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
|
||||||
|
example.createCriteria().andTestPlanIdIn(planIds);
|
||||||
|
testPlanApiCaseMapper.deleteByExample(example);
|
||||||
|
}
|
||||||
|
|
||||||
public void deleteApiCaseBath(TestPlanApiCaseBatchRequest request) {
|
public void deleteApiCaseBath(TestPlanApiCaseBatchRequest request) {
|
||||||
List<String> deleteIds = request.getIds();
|
List<String> deleteIds = request.getIds();
|
||||||
if (request.getCondition() != null && request.getCondition().isSelectAll()) {
|
if (request.getCondition() != null && request.getCondition().isSelectAll()) {
|
||||||
|
|
|
@ -385,6 +385,19 @@ public class TestPlanScenarioCaseService {
|
||||||
deleteApiCaseBath(request);
|
deleteApiCaseBath(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteByPlanIds(List<String> planIds) {
|
||||||
|
if (CollectionUtils.isEmpty(planIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
|
||||||
|
example.createCriteria().andTestPlanIdIn(planIds);
|
||||||
|
List<TestPlanApiScenario> testPlanApiScenarios = testPlanApiScenarioMapper.selectByExample(example);
|
||||||
|
List<String> ids = testPlanApiScenarios.stream().map(TestPlanApiScenario::getId).collect(Collectors.toList());
|
||||||
|
TestPlanScenarioCaseBatchRequest request = new TestPlanScenarioCaseBatchRequest();
|
||||||
|
request.setIds(ids);
|
||||||
|
deleteApiCaseBath(request);
|
||||||
|
}
|
||||||
|
|
||||||
public void deleteByRelevanceProjectIds(String planId, List<String> relevanceProjectIds) {
|
public void deleteByRelevanceProjectIds(String planId, List<String> relevanceProjectIds) {
|
||||||
TestPlanScenarioCaseBatchRequest request = new TestPlanScenarioCaseBatchRequest();
|
TestPlanScenarioCaseBatchRequest request = new TestPlanScenarioCaseBatchRequest();
|
||||||
request.setIds(extTestPlanScenarioCaseMapper.getNotRelevanceCaseIds(planId, relevanceProjectIds));
|
request.setIds(extTestPlanScenarioCaseMapper.getNotRelevanceCaseIds(planId, relevanceProjectIds));
|
||||||
|
|
|
@ -108,6 +108,7 @@ public class PermissionConstants {
|
||||||
public static final String PROJECT_TRACK_PLAN_READ_CREATE = "PROJECT_TRACK_PLAN:READ+CREATE";
|
public static final String PROJECT_TRACK_PLAN_READ_CREATE = "PROJECT_TRACK_PLAN:READ+CREATE";
|
||||||
public static final String PROJECT_TRACK_PLAN_READ_EDIT = "PROJECT_TRACK_PLAN:READ+EDIT";
|
public static final String PROJECT_TRACK_PLAN_READ_EDIT = "PROJECT_TRACK_PLAN:READ+EDIT";
|
||||||
public static final String PROJECT_TRACK_PLAN_READ_DELETE = "PROJECT_TRACK_PLAN:READ+DELETE";
|
public static final String PROJECT_TRACK_PLAN_READ_DELETE = "PROJECT_TRACK_PLAN:READ+DELETE";
|
||||||
|
public static final String PROJECT_TRACK_PLAN_READ_BATCH_DELETE = "PROJECT_TRACK_PLAN:READ+BATCH_DELETE";
|
||||||
public static final String PROJECT_TRACK_PLAN_READ_SCHEDULE = "PROJECT_TRACK_PLAN:READ+SCHEDULE";
|
public static final String PROJECT_TRACK_PLAN_READ_SCHEDULE = "PROJECT_TRACK_PLAN:READ+SCHEDULE";
|
||||||
public static final String PROJECT_TRACK_PLAN_READ_RELEVANCE_OR_CANCEL = "PROJECT_TRACK_PLAN:READ+RELEVANCE_OR_CANCEL";
|
public static final String PROJECT_TRACK_PLAN_READ_RELEVANCE_OR_CANCEL = "PROJECT_TRACK_PLAN:READ+RELEVANCE_OR_CANCEL";
|
||||||
public static final String PROJECT_TRACK_PLAN_READ_RUN = "PROJECT_TRACK_PLAN:READ+RUN";
|
public static final String PROJECT_TRACK_PLAN_READ_RUN = "PROJECT_TRACK_PLAN:READ+RUN";
|
||||||
|
|
|
@ -92,6 +92,15 @@ public class BaseScheduleService {
|
||||||
return scheduleMapper.deleteByExample(scheduleExample);
|
return scheduleMapper.deleteByExample(scheduleExample);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int deleteByResourceIds(List<String> resourceIds, String group) {
|
||||||
|
ScheduleExample scheduleExample = new ScheduleExample();
|
||||||
|
scheduleExample.createCriteria().andResourceIdIn(resourceIds);
|
||||||
|
for (String resourceId : resourceIds) {
|
||||||
|
removeJob(resourceId, group);
|
||||||
|
}
|
||||||
|
return scheduleMapper.deleteByExample(scheduleExample);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public int deleteByWorkspaceId(String workspaceId) {
|
public int deleteByWorkspaceId(String workspaceId) {
|
||||||
ScheduleExample scheduleExample = new ScheduleExample();
|
ScheduleExample scheduleExample = new ScheduleExample();
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
package io.metersphere.listener;
|
package io.metersphere.listener;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import io.metersphere.commons.constants.KafkaTopicConstants;
|
import io.metersphere.commons.constants.KafkaTopicConstants;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
import io.metersphere.plan.service.TestPlanLoadCaseService;
|
import io.metersphere.plan.service.TestPlanLoadCaseService;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||||
import org.springframework.kafka.annotation.KafkaListener;
|
import org.springframework.kafka.annotation.KafkaListener;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class TestPlanDeletedListener {
|
public class TestPlanDeletedListener {
|
||||||
|
@ -15,11 +19,20 @@ public class TestPlanDeletedListener {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private TestPlanLoadCaseService testPlanLoadCaseService;
|
private TestPlanLoadCaseService testPlanLoadCaseService;
|
||||||
|
@Resource
|
||||||
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
@KafkaListener(id = CONSUME_ID, topics = KafkaTopicConstants.TEST_PLAN_DELETED_TOPIC, groupId = "${spring.application.name}")
|
@KafkaListener(id = CONSUME_ID, topics = KafkaTopicConstants.TEST_PLAN_DELETED_TOPIC, groupId = "${spring.application.name}")
|
||||||
public void consume(ConsumerRecord<?, String> record) {
|
public void consume(ConsumerRecord<?, String> record) {
|
||||||
String planId = record.value();
|
try {
|
||||||
LogUtil.info("performance service consume TEST_PLAN_DELETED_TOPIC message, plan id: " + planId);
|
List<String> planIds = objectMapper.readValue(record.value(), new TypeReference<>() {});
|
||||||
testPlanLoadCaseService.deleteByPlanId(planId);
|
if (CollectionUtils.isEmpty(planIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LogUtil.info("performance service consume TEST_PLAN_DELETED_TOPIC message, plans: " + planIds);
|
||||||
|
testPlanLoadCaseService.deleteByPlanIds(planIds);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtil.error("performance service consume TEST_PLAN_DELETED_TOPIC message error, plans: " + record.value(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -352,6 +352,15 @@ public class TestPlanLoadCaseService {
|
||||||
testPlanLoadCaseMapper.deleteByExample(example);
|
testPlanLoadCaseMapper.deleteByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteByPlanIds(List<String> planIds) {
|
||||||
|
if (CollectionUtils.isEmpty(planIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TestPlanLoadCaseExample example = new TestPlanLoadCaseExample();
|
||||||
|
example.createCriteria().andTestPlanIdIn(planIds);
|
||||||
|
testPlanLoadCaseMapper.deleteByExample(example);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<TestPlanLoadCaseDTO> getAllCases(String planId) {
|
public List<TestPlanLoadCaseDTO> getAllCases(String planId) {
|
||||||
List<TestPlanLoadCaseDTO> cases = extTestPlanLoadCaseMapper.getCases(planId, null);
|
List<TestPlanLoadCaseDTO> cases = extTestPlanLoadCaseMapper.getCases(planId, null);
|
||||||
|
|
|
@ -15,6 +15,7 @@ import io.metersphere.plan.dto.TestCaseReportStatusResultDTO;
|
||||||
import io.metersphere.plan.dto.TestPlanDTO;
|
import io.metersphere.plan.dto.TestPlanDTO;
|
||||||
import io.metersphere.plan.dto.TestPlanSimpleReportDTO;
|
import io.metersphere.plan.dto.TestPlanSimpleReportDTO;
|
||||||
import io.metersphere.plan.request.AddTestPlanRequest;
|
import io.metersphere.plan.request.AddTestPlanRequest;
|
||||||
|
import io.metersphere.plan.request.BatchOperateRequest;
|
||||||
import io.metersphere.plan.request.QueryTestPlanRequest;
|
import io.metersphere.plan.request.QueryTestPlanRequest;
|
||||||
import io.metersphere.plan.request.ScheduleInfoRequest;
|
import io.metersphere.plan.request.ScheduleInfoRequest;
|
||||||
import io.metersphere.plan.request.api.TestPlanRunRequest;
|
import io.metersphere.plan.request.api.TestPlanRunRequest;
|
||||||
|
@ -169,6 +170,13 @@ public class TestPlanController {
|
||||||
return testPlanService.deleteTestPlan(testPlanId);
|
return testPlanService.deleteTestPlan(testPlanId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/delete/batch")
|
||||||
|
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_PLAN_READ_BATCH_DELETE)
|
||||||
|
@MsAuditLog(module = OperLogModule.TRACK_TEST_PLAN, type = OperLogConstants.BATCH_DEL, project = "#request.projectId", beforeEvent = "#msClass.getDeleteBatchLogDetails(#request)", msClass = TestPlanService.class)
|
||||||
|
public void deleteTestPlanBatch(@RequestBody BatchOperateRequest request) {
|
||||||
|
testPlanService.deleteTestPlanBatch(request);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/relevance")
|
@PostMapping("/relevance")
|
||||||
@MsAuditLog(module = OperLogModule.TRACK_TEST_PLAN, type = OperLogConstants.ASSOCIATE_CASE, content = "#msClass.getLogDetails(#request)", msClass = TestPlanService.class)
|
@MsAuditLog(module = OperLogModule.TRACK_TEST_PLAN, type = OperLogConstants.ASSOCIATE_CASE, content = "#msClass.getLogDetails(#request)", msClass = TestPlanService.class)
|
||||||
public void testPlanRelevance(@RequestBody PlanCaseRelevanceRequest request) {
|
public void testPlanRelevance(@RequestBody PlanCaseRelevanceRequest request) {
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package io.metersphere.plan.request;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class BatchOperateRequest {
|
||||||
|
private List<String> ids;
|
||||||
|
boolean selectAll;
|
||||||
|
private List<String> unSelectIds;
|
||||||
|
private QueryTestPlanRequest queryTestPlanRequest;
|
||||||
|
private String projectId;
|
||||||
|
}
|
|
@ -3,11 +3,13 @@ package io.metersphere.plan.service;
|
||||||
import io.metersphere.base.domain.TestPlanFollow;
|
import io.metersphere.base.domain.TestPlanFollow;
|
||||||
import io.metersphere.base.domain.TestPlanFollowExample;
|
import io.metersphere.base.domain.TestPlanFollowExample;
|
||||||
import io.metersphere.base.mapper.TestPlanFollowMapper;
|
import io.metersphere.base.mapper.TestPlanFollowMapper;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@ -26,6 +28,15 @@ public class TestPlanFollowService {
|
||||||
testPlanFollowMapper.deleteByExample(example);
|
testPlanFollowMapper.deleteByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deletePlanFollowByPlanIds(List<String> planIds) {
|
||||||
|
if (CollectionUtils.isEmpty(planIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TestPlanFollowExample example = new TestPlanFollowExample();
|
||||||
|
example.createCriteria().andTestPlanIdIn(planIds);
|
||||||
|
testPlanFollowMapper.deleteByExample(example);
|
||||||
|
}
|
||||||
|
|
||||||
public TestPlanFollow insert(TestPlanFollow testPlanFollow) {
|
public TestPlanFollow insert(TestPlanFollow testPlanFollow) {
|
||||||
testPlanFollowMapper.insert(testPlanFollow);
|
testPlanFollowMapper.insert(testPlanFollow);
|
||||||
return testPlanFollow;
|
return testPlanFollow;
|
||||||
|
|
|
@ -3,11 +3,13 @@ package io.metersphere.plan.service;
|
||||||
import io.metersphere.base.domain.TestPlanPrincipal;
|
import io.metersphere.base.domain.TestPlanPrincipal;
|
||||||
import io.metersphere.base.domain.TestPlanPrincipalExample;
|
import io.metersphere.base.domain.TestPlanPrincipalExample;
|
||||||
import io.metersphere.base.mapper.TestPlanPrincipalMapper;
|
import io.metersphere.base.mapper.TestPlanPrincipalMapper;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@ -26,6 +28,15 @@ public class TestPlanPrincipalService {
|
||||||
testPlanPrincipalMapper.deleteByExample(example);
|
testPlanPrincipalMapper.deleteByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deletePlanPrincipalByPlanIds(List<String> planIds) {
|
||||||
|
if (CollectionUtils.isEmpty(planIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TestPlanPrincipalExample example = new TestPlanPrincipalExample();
|
||||||
|
example.createCriteria().andTestPlanIdIn(planIds);
|
||||||
|
testPlanPrincipalMapper.deleteByExample(example);
|
||||||
|
}
|
||||||
|
|
||||||
public TestPlanPrincipal insert(TestPlanPrincipal testPlanPrincipal) {
|
public TestPlanPrincipal insert(TestPlanPrincipal testPlanPrincipal) {
|
||||||
testPlanPrincipalMapper.insert(testPlanPrincipal);
|
testPlanPrincipalMapper.insert(testPlanPrincipal);
|
||||||
return testPlanPrincipal;
|
return testPlanPrincipal;
|
||||||
|
|
|
@ -962,6 +962,14 @@ public class TestPlanReportService {
|
||||||
this.delete(testPlanReportIdList);
|
this.delete(testPlanReportIdList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteByPlanIds(List<String> planIds) {
|
||||||
|
TestPlanReportExample example = new TestPlanReportExample();
|
||||||
|
example.createCriteria().andTestPlanIdIn(planIds);
|
||||||
|
List<TestPlanReport> reportList = testPlanReportMapper.selectByExample(example);
|
||||||
|
List<String> ids = reportList.stream().map(TestPlanReport::getId).collect(Collectors.toList());
|
||||||
|
this.delete(ids);
|
||||||
|
}
|
||||||
|
|
||||||
public TestPlanSimpleReportDTO getShareDbReport(ShareInfo shareInfo, String reportId) {
|
public TestPlanSimpleReportDTO getShareDbReport(ShareInfo shareInfo, String reportId) {
|
||||||
HttpHeaderUtils.runAsUser(shareInfo.getCreateUserId());
|
HttpHeaderUtils.runAsUser(shareInfo.getCreateUserId());
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package io.metersphere.plan.service;
|
package io.metersphere.plan.service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import io.metersphere.base.domain.*;
|
import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.base.mapper.*;
|
import io.metersphere.base.mapper.*;
|
||||||
|
@ -22,6 +24,7 @@ import io.metersphere.log.vo.track.TestPlanReference;
|
||||||
import io.metersphere.plan.dto.*;
|
import io.metersphere.plan.dto.*;
|
||||||
import io.metersphere.plan.job.TestPlanTestJob;
|
import io.metersphere.plan.job.TestPlanTestJob;
|
||||||
import io.metersphere.plan.request.AddTestPlanRequest;
|
import io.metersphere.plan.request.AddTestPlanRequest;
|
||||||
|
import io.metersphere.plan.request.BatchOperateRequest;
|
||||||
import io.metersphere.plan.request.QueryTestPlanRequest;
|
import io.metersphere.plan.request.QueryTestPlanRequest;
|
||||||
import io.metersphere.plan.request.ScheduleInfoRequest;
|
import io.metersphere.plan.request.ScheduleInfoRequest;
|
||||||
import io.metersphere.plan.request.api.ApiPlanReportRequest;
|
import io.metersphere.plan.request.api.ApiPlanReportRequest;
|
||||||
|
@ -142,7 +145,8 @@ public class TestPlanService {
|
||||||
private TestPlanExecutionQueueService testPlanExecutionQueueService;
|
private TestPlanExecutionQueueService testPlanExecutionQueueService;
|
||||||
@Resource
|
@Resource
|
||||||
private KafkaTemplate<String, String> kafkaTemplate;
|
private KafkaTemplate<String, String> kafkaTemplate;
|
||||||
|
@Resource
|
||||||
|
private ObjectMapper objectMapper;
|
||||||
public synchronized TestPlan addTestPlan(AddTestPlanRequest testPlan) {
|
public synchronized TestPlan addTestPlan(AddTestPlanRequest testPlan) {
|
||||||
if (getTestPlanByName(testPlan.getName()).size() > 0) {
|
if (getTestPlanByName(testPlan.getName()).size() > 0) {
|
||||||
MSException.throwException(Translator.get("plan_name_already_exists"));
|
MSException.throwException(Translator.get("plan_name_already_exists"));
|
||||||
|
@ -302,7 +306,11 @@ public class TestPlanService {
|
||||||
public int deleteTestPlan(String planId) {
|
public int deleteTestPlan(String planId) {
|
||||||
|
|
||||||
// 发送删除通知
|
// 发送删除通知
|
||||||
kafkaTemplate.send(KafkaTopicConstants.TEST_PLAN_DELETED_TOPIC, planId);
|
try {
|
||||||
|
kafkaTemplate.send(KafkaTopicConstants.TEST_PLAN_DELETED_TOPIC, objectMapper.writeValueAsString(List.of(planId)));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
LogUtil.error("send msg to TEST_PLAN_DELETED_TOPIC error", e);
|
||||||
|
}
|
||||||
|
|
||||||
testPlanPrincipalService.deleteTestPlanPrincipalByPlanId(planId);
|
testPlanPrincipalService.deleteTestPlanPrincipalByPlanId(planId);
|
||||||
testPlanFollowService.deleteTestPlanFollowByPlanId(planId);
|
testPlanFollowService.deleteTestPlanFollowByPlanId(planId);
|
||||||
|
@ -316,6 +324,35 @@ public class TestPlanService {
|
||||||
return testPlanMapper.deleteByPrimaryKey(planId);
|
return testPlanMapper.deleteByPrimaryKey(planId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int deleteTestPlans(List<String> planIds) {
|
||||||
|
if (CollectionUtils.isEmpty(planIds)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
TestPlanExample testPlanExample = new TestPlanExample();
|
||||||
|
testPlanExample.createCriteria().andIdIn(planIds);
|
||||||
|
int deletedSize = testPlanMapper.deleteByExample(testPlanExample);
|
||||||
|
|
||||||
|
testPlanPrincipalService.deletePlanPrincipalByPlanIds(planIds);
|
||||||
|
testPlanFollowService.deletePlanFollowByPlanIds(planIds);
|
||||||
|
|
||||||
|
TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample();
|
||||||
|
testPlanTestCaseExample.createCriteria().andPlanIdIn(planIds);
|
||||||
|
testPlanTestCaseMapper.deleteByExample(testPlanTestCaseExample);
|
||||||
|
|
||||||
|
|
||||||
|
testPlanReportService.deleteByPlanIds(planIds);
|
||||||
|
//删除定时任务
|
||||||
|
baseScheduleService.deleteByResourceIds(planIds, ScheduleGroup.TEST_PLAN_TEST.name());
|
||||||
|
|
||||||
|
try {
|
||||||
|
kafkaTemplate.send(KafkaTopicConstants.TEST_PLAN_DELETED_TOPIC, objectMapper.writeValueAsString(planIds));
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtil.error("send msg to TEST_PLAN_DELETED_TOPIC error", e);
|
||||||
|
}
|
||||||
|
return deletedSize;
|
||||||
|
}
|
||||||
|
|
||||||
public void deleteTestCaseByPlanId(String testPlanId) {
|
public void deleteTestCaseByPlanId(String testPlanId) {
|
||||||
TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample();
|
TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample();
|
||||||
testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(testPlanId);
|
testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(testPlanId);
|
||||||
|
@ -971,18 +1008,28 @@ public class TestPlanService {
|
||||||
testPlanExample.createCriteria().andIdIn(ids);
|
testPlanExample.createCriteria().andIdIn(ids);
|
||||||
List<TestPlan> planList = testPlanMapper.selectByExample(testPlanExample);
|
List<TestPlan> planList = testPlanMapper.selectByExample(testPlanExample);
|
||||||
if (CollectionUtils.isNotEmpty(planList)) {
|
if (CollectionUtils.isNotEmpty(planList)) {
|
||||||
List<OperatingLogDetails> detailsList = new ArrayList<>();
|
List<String> names = planList.stream().map(TestPlan::getName).collect(Collectors.toList());
|
||||||
for (TestPlan plan : planList) {
|
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(ids), planList.get(0).getProjectId(), String.join(",", names), planList.get(0).getCreator(), new LinkedList<>());
|
||||||
List<DetailColumn> columns = ReflexObjectUtil.getColumns(planList.get(0), TestPlanReference.testPlanColumns);
|
return JSON.toJSONString(details);
|
||||||
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(plan.getId()), plan.getProjectId(), plan.getName(), plan.getCreator(), columns);
|
|
||||||
detailsList.add(details);
|
|
||||||
}
|
|
||||||
return JSON.toJSONString(detailsList);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDeleteBatchLogDetails(BatchOperateRequest request) {
|
||||||
|
List<String> ids = request.getIds();
|
||||||
|
if (request.isSelectAll()) {
|
||||||
|
QueryTestPlanRequest queryTestPlanRequest = request.getQueryTestPlanRequest();
|
||||||
|
request.getQueryTestPlanRequest().setOrders(ServiceUtils.getDefaultOrder(queryTestPlanRequest.getOrders()));
|
||||||
|
if (StringUtils.isNotBlank(queryTestPlanRequest.getProjectId())) {
|
||||||
|
request.getQueryTestPlanRequest().setProjectId(queryTestPlanRequest.getProjectId());
|
||||||
|
}
|
||||||
|
List<TestPlanDTOWithMetric> testPlans = extTestPlanMapper.list(queryTestPlanRequest);
|
||||||
|
ids = testPlans.stream().map(TestPlan::getId).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
return getLogDetails(ids);
|
||||||
|
}
|
||||||
|
|
||||||
public String getLogDetails(String id) {
|
public String getLogDetails(String id) {
|
||||||
TestPlan plan = testPlanMapper.selectByPrimaryKey(id);
|
TestPlan plan = testPlanMapper.selectByPrimaryKey(id);
|
||||||
if (plan != null) {
|
if (plan != null) {
|
||||||
|
@ -1893,4 +1940,21 @@ public class TestPlanService {
|
||||||
testPlanMapper.updateByPrimaryKey(testPlan);
|
testPlanMapper.updateByPrimaryKey(testPlan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteTestPlanBatch(BatchOperateRequest request) {
|
||||||
|
List<String> ids = request.getIds();
|
||||||
|
if (request.isSelectAll()) {
|
||||||
|
QueryTestPlanRequest queryTestPlanRequest = request.getQueryTestPlanRequest();
|
||||||
|
request.getQueryTestPlanRequest().setOrders(ServiceUtils.getDefaultOrder(queryTestPlanRequest.getOrders()));
|
||||||
|
if (StringUtils.isNotBlank(queryTestPlanRequest.getProjectId())) {
|
||||||
|
request.getQueryTestPlanRequest().setProjectId(queryTestPlanRequest.getProjectId());
|
||||||
|
}
|
||||||
|
List<TestPlanDTOWithMetric> testPlans = extTestPlanMapper.list(queryTestPlanRequest);
|
||||||
|
ids = testPlans.stream().map(TestPlan::getId).collect(Collectors.toList());
|
||||||
|
if (request.getUnSelectIds() != null) {
|
||||||
|
ids.removeAll(request.getUnSelectIds());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.deleteTestPlans(ids);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,6 +277,10 @@ export function updateBatchScheduleEnable(param) {
|
||||||
return post(BASE_URL + 'schedule/Batch/updateEnable', param);
|
return post(BASE_URL + 'schedule/Batch/updateEnable', param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function batchDeletePlan(param) {
|
||||||
|
return post(BASE_URL + 'delete/batch', param);
|
||||||
|
}
|
||||||
|
|
||||||
export function createSchedule(param){
|
export function createSchedule(param){
|
||||||
return post(BASE_URL + 'schedule/create',param);
|
return post(BASE_URL + 'schedule/create',param);
|
||||||
}
|
}
|
||||||
|
|
|
@ -373,7 +373,7 @@ import {
|
||||||
testPlanEditFollows,
|
testPlanEditFollows,
|
||||||
testPlanEditRunConfig, testPlanGetEnableScheduleCount, testPlanGetFollow, testPlanGetPrincipal, testPlanHaveExecCase,
|
testPlanEditRunConfig, testPlanGetEnableScheduleCount, testPlanGetFollow, testPlanGetPrincipal, testPlanHaveExecCase,
|
||||||
testPlanHaveUiCase, testPlanList, testPlanRun, testPlanRunBatch,
|
testPlanHaveUiCase, testPlanList, testPlanRun, testPlanRunBatch,
|
||||||
testPlanRunSave, testPlanUpdateScheduleEnable
|
testPlanRunSave, testPlanUpdateScheduleEnable, batchDeletePlan
|
||||||
} from "@/api/remote/plan/test-plan";
|
} from "@/api/remote/plan/test-plan";
|
||||||
import MsTableColumn from "metersphere-frontend/src/components/table/MsTableColumn";
|
import MsTableColumn from "metersphere-frontend/src/components/table/MsTableColumn";
|
||||||
import MsTable from "metersphere-frontend/src/components/table/MsTable";
|
import MsTable from "metersphere-frontend/src/components/table/MsTable";
|
||||||
|
@ -455,6 +455,11 @@ export default {
|
||||||
name: this.$t('api_test.automation.batch_execute'),
|
name: this.$t('api_test.automation.batch_execute'),
|
||||||
handleClick: this.handleBatchExecute,
|
handleClick: this.handleBatchExecute,
|
||||||
permissions: ['PROJECT_TRACK_PLAN:READ+SCHEDULE']
|
permissions: ['PROJECT_TRACK_PLAN:READ+SCHEDULE']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: this.$t('commons.delete_batch'),
|
||||||
|
handleClick: this.handleBatchDelete,
|
||||||
|
permissions: ['PROJECT_TRACK_PLAN:READ+BATCH_DELETE']
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
simpleOperators: [
|
simpleOperators: [
|
||||||
|
@ -620,6 +625,32 @@ export default {
|
||||||
this.$refs.testPlanLitTable.isSelectDataAll(false);
|
this.$refs.testPlanLitTable.isSelectDataAll(false);
|
||||||
this.initTableData();
|
this.initTableData();
|
||||||
},
|
},
|
||||||
|
handleBatchDelete() {
|
||||||
|
this.$confirm(this.$t('plan.batch_delete_tip').toString(), this.$t('commons.delete_batch').toString(), {
|
||||||
|
confirmButtonText: this.$t('commons.confirm'),
|
||||||
|
cancelButtonText: this.$t('commons.cancel'),
|
||||||
|
type: 'warning',
|
||||||
|
}).then(() => {
|
||||||
|
let ids = [], param = {};
|
||||||
|
param.projectId = getCurrentProjectID();
|
||||||
|
if (this.condition.selectAll) {
|
||||||
|
param.unSelectIds = this.condition.unSelectIds;
|
||||||
|
param.selectAll = true;
|
||||||
|
param.queryTestPlanRequest = this.condition;
|
||||||
|
} else {
|
||||||
|
this.$refs.testPlanLitTable.selectRows.forEach((item) => {
|
||||||
|
ids.push(item.id)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
param.ids = ids;
|
||||||
|
this.cardLoading = batchDeletePlan(param).then(() => {
|
||||||
|
this.refresh();
|
||||||
|
this.$success(this.$t('commons.delete_success'));
|
||||||
|
});
|
||||||
|
}).catch(() => {
|
||||||
|
this.$info(this.$t('commons.delete_cancel'));
|
||||||
|
});
|
||||||
|
},
|
||||||
handleBatchSwitch() {
|
handleBatchSwitch() {
|
||||||
let param = [];
|
let param = [];
|
||||||
let size = 0;
|
let size = 0;
|
||||||
|
|
|
@ -20,6 +20,9 @@ const message = {
|
||||||
test_plan: "Test Plan",
|
test_plan: "Test Plan",
|
||||||
failure_times: "Failure times",
|
failure_times: "Failure times",
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
plan: {
|
||||||
|
batch_delete_tip: "Do you want to continue deleting the test plan?",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export default {
|
export default {
|
||||||
|
|
|
@ -20,6 +20,9 @@ const message = {
|
||||||
test_plan: "所属测试计划",
|
test_plan: "所属测试计划",
|
||||||
failure_times: "失败次数",
|
failure_times: "失败次数",
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
plan: {
|
||||||
|
batch_delete_tip: "批量删除测试计划,是否继续?",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,9 @@ const message = {
|
||||||
test_plan: "所屬測試計劃",
|
test_plan: "所屬測試計劃",
|
||||||
failure_times: "失敗次數",
|
failure_times: "失敗次數",
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
plan: {
|
||||||
|
batch_delete_tip: "批量刪除測試計劃,是否繼續?",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue