fix: 导入接口重复替换,删除测试计划删除关联的接口用例
This commit is contained in:
parent
a19e3521e2
commit
b9848e452c
|
@ -181,6 +181,21 @@ public class ApiDefinitionService {
|
|||
}
|
||||
}
|
||||
|
||||
private List<ApiDefinition> getSameRequest(SaveApiDefinitionRequest request) {
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
if (request.getProtocol().equals(RequestType.HTTP)) {
|
||||
example.createCriteria().andMethodEqualTo(request.getMethod()).andStatusNotEqualTo("Trash")
|
||||
.andProtocolEqualTo(request.getProtocol()).andPathEqualTo(request.getPath())
|
||||
.andProjectIdEqualTo(request.getProjectId()).andIdNotEqualTo(request.getId());
|
||||
return apiDefinitionMapper.selectByExample(example);
|
||||
} else {
|
||||
example.createCriteria().andProtocolEqualTo(request.getProtocol()).andStatusNotEqualTo("Trash")
|
||||
.andNameEqualTo(request.getName()).andProjectIdEqualTo(request.getProjectId())
|
||||
.andIdNotEqualTo(request.getId());
|
||||
return apiDefinitionMapper.selectByExample(example);
|
||||
}
|
||||
}
|
||||
|
||||
private ApiDefinition updateTest(SaveApiDefinitionRequest request) {
|
||||
checkNameExist(request);
|
||||
final ApiDefinitionWithBLOBs test = new ApiDefinitionWithBLOBs();
|
||||
|
@ -243,23 +258,30 @@ public class ApiDefinitionService {
|
|||
}
|
||||
}
|
||||
|
||||
private ApiDefinition createTest(ApiDefinitionResult request, ApiDefinitionMapper batchMapper) {
|
||||
private ApiDefinition importCreate(ApiDefinitionResult request, ApiDefinitionMapper batchMapper) {
|
||||
SaveApiDefinitionRequest saveReq = new SaveApiDefinitionRequest();
|
||||
BeanUtils.copyBean(saveReq, request);
|
||||
checkNameExist(saveReq);
|
||||
final ApiDefinitionWithBLOBs test = new ApiDefinitionWithBLOBs();
|
||||
BeanUtils.copyBean(test, request);
|
||||
test.setCreateTime(System.currentTimeMillis());
|
||||
test.setUpdateTime(System.currentTimeMillis());
|
||||
test.setStatus(APITestStatus.Underway.name());
|
||||
final ApiDefinitionWithBLOBs apiDefinition = new ApiDefinitionWithBLOBs();
|
||||
BeanUtils.copyBean(apiDefinition, request);
|
||||
apiDefinition.setCreateTime(System.currentTimeMillis());
|
||||
apiDefinition.setUpdateTime(System.currentTimeMillis());
|
||||
apiDefinition.setStatus(APITestStatus.Underway.name());
|
||||
if (request.getUserId() == null) {
|
||||
test.setUserId(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
||||
apiDefinition.setUserId(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
||||
} else {
|
||||
test.setUserId(request.getUserId());
|
||||
apiDefinition.setUserId(request.getUserId());
|
||||
}
|
||||
test.setDescription(request.getDescription());
|
||||
batchMapper.insert(test);
|
||||
return test;
|
||||
apiDefinition.setDescription(request.getDescription());
|
||||
|
||||
List<ApiDefinition> sameRequest = getSameRequest(saveReq);
|
||||
if (CollectionUtils.isEmpty(sameRequest)) {
|
||||
batchMapper.insert(apiDefinition);
|
||||
} else {
|
||||
//如果存在则修改
|
||||
apiDefinition.setId(sameRequest.get(0).getId());
|
||||
apiDefinitionMapper.updateByPrimaryKey(apiDefinition);
|
||||
}
|
||||
return apiDefinition;
|
||||
}
|
||||
|
||||
|
||||
|
@ -358,12 +380,12 @@ public class ApiDefinitionService {
|
|||
MSException.throwException(Translator.get("parse_data_error"));
|
||||
}
|
||||
if (request.isSaved()) {
|
||||
importApiTest(request, apiImport);
|
||||
importApi(request, apiImport);
|
||||
}
|
||||
return apiImport;
|
||||
}
|
||||
|
||||
private void importApiTest(ApiTestImportRequest request, ApiDefinitionImport apiImport) {
|
||||
private void importApi(ApiTestImportRequest request, ApiDefinitionImport apiImport) {
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
ApiDefinitionMapper batchMapper = sqlSession.getMapper(ApiDefinitionMapper.class);
|
||||
List<ApiDefinitionResult> data = apiImport.getData();
|
||||
|
@ -377,7 +399,7 @@ public class ApiDefinitionService {
|
|||
item.setName(item.getName().substring(0, 255));
|
||||
}
|
||||
item.setNum(num++);
|
||||
createTest(item, batchMapper);
|
||||
importCreate(item, batchMapper);
|
||||
if (i % 300 == 0) {
|
||||
sqlSession.flushStatements();
|
||||
}
|
||||
|
|
|
@ -207,6 +207,20 @@ public class ApiScenarioReportService {
|
|||
apiScenarioReportMapper.deleteByPrimaryKey(request.getId());
|
||||
}
|
||||
|
||||
public void delete(String id) {
|
||||
apiScenarioReportDetailMapper.deleteByPrimaryKey(id);
|
||||
apiScenarioReportMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public void deleteByIds(List<String> ids) {
|
||||
ApiScenarioReportExample example = new ApiScenarioReportExample();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
ApiScenarioReportDetailExample detailExample = new ApiScenarioReportDetailExample();
|
||||
detailExample.createCriteria().andReportIdIn(ids);
|
||||
apiScenarioReportDetailMapper.deleteByExample(detailExample);
|
||||
apiScenarioReportMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public void deleteAPIReportBatch(DeleteAPIReportRequest reportRequest) {
|
||||
List<String> ids = reportRequest.getIds();
|
||||
if (reportRequest.isSelectAllDate()) {
|
||||
|
|
|
@ -13,4 +13,6 @@ public interface ExtTestPlanApiCaseMapper {
|
|||
List<TestPlanApiCaseDTO> list(@Param("request") ApiTestCaseRequest request);
|
||||
|
||||
List<String> getExecResultByPlanId(String planId);
|
||||
|
||||
List<String> getIdsByPlanId(String planId);
|
||||
}
|
|
@ -97,4 +97,10 @@
|
|||
where test_plan_id = #{planId}
|
||||
</select>
|
||||
|
||||
<select id="getIdsByPlanId" resultType="java.lang.String">
|
||||
select id from
|
||||
from test_plan_api_case
|
||||
where id = #{planId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -19,4 +19,6 @@ public interface ExtTestPlanScenarioCaseMapper {
|
|||
List<ApiScenarioDTO> list(@Param("request") TestPlanScenarioRequest request);
|
||||
|
||||
List<String> getExecResultByPlanId(String planId);
|
||||
|
||||
List<String> getIdsByPlanId(String planId);
|
||||
}
|
|
@ -86,5 +86,10 @@
|
|||
test_plan_api_scenario
|
||||
where test_plan_id = #{planId}
|
||||
</select>
|
||||
<select id="getIdsByPlanId" resultType="java.lang.String">
|
||||
select id
|
||||
from test_plan_api_scenario
|
||||
where test_plan_id = #{planId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -38,10 +38,10 @@ public class TestPlanApiCaseController {
|
|||
return PageUtils.setPageInfo(page, testPlanApiCaseService.relevanceList(request));
|
||||
}
|
||||
|
||||
@GetMapping("/delete/{planId}/{id}")
|
||||
@GetMapping("/delete/{id}")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
public int deleteTestCase(@PathVariable String planId, @PathVariable String id) {
|
||||
return testPlanApiCaseService.delete(planId, id);
|
||||
public int deleteTestCase(@PathVariable String id) {
|
||||
return testPlanApiCaseService.delete(id);
|
||||
}
|
||||
|
||||
@PostMapping("/batch/delete")
|
||||
|
|
|
@ -36,10 +36,10 @@ public class TestPlanScenarioCaseController {
|
|||
return PageUtils.setPageInfo(page, testPlanScenarioCaseService.relevanceList(request));
|
||||
}
|
||||
|
||||
@GetMapping("/delete/{planId}/{id}")
|
||||
@GetMapping("/delete/{id}")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
public int deleteTestCase(@PathVariable String planId, @PathVariable String id) {
|
||||
return testPlanScenarioCaseService.delete(planId, id);
|
||||
public int deleteTestCase(@PathVariable String id) {
|
||||
return testPlanScenarioCaseService.delete(id);
|
||||
}
|
||||
|
||||
@PostMapping("/batch/delete")
|
||||
|
|
|
@ -58,18 +58,24 @@ public class TestPlanApiCaseService {
|
|||
return apiTestCaseService.listSimple(request);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int delete(String planId, String id) {
|
||||
public int delete(String id) {
|
||||
apiDefinitionExecResultService.deleteByResourceId(id);
|
||||
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
|
||||
example.createCriteria()
|
||||
.andTestPlanIdEqualTo(planId)
|
||||
.andIdEqualTo(id);
|
||||
|
||||
return testPlanApiCaseMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public int deleteByPlanId(String planId) {
|
||||
List<String> ids = extTestPlanApiCaseMapper.getIdsByPlanId(planId);
|
||||
apiDefinitionExecResultService.deleteByResourceIds(ids);
|
||||
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
|
||||
example.createCriteria()
|
||||
.andTestPlanIdEqualTo(planId);
|
||||
return testPlanApiCaseMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public void deleteApiCaseBath(TestPlanApiCaseBatchRequest request) {
|
||||
apiDefinitionExecResultService.deleteByResourceIds(request.getIds());
|
||||
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package io.metersphere.track.service;
|
||||
|
||||
import io.metersphere.api.dto.DeleteAPIReportRequest;
|
||||
import io.metersphere.api.dto.automation.ApiScenarioDTO;
|
||||
import io.metersphere.api.dto.automation.ApiScenarioRequest;
|
||||
import io.metersphere.api.dto.automation.RunScenarioRequest;
|
||||
import io.metersphere.api.dto.automation.TestPlanScenarioRequest;
|
||||
import io.metersphere.api.service.ApiAutomationService;
|
||||
import io.metersphere.api.service.ApiScenarioReportService;
|
||||
import io.metersphere.base.domain.TestPlanApiCase;
|
||||
import io.metersphere.base.domain.TestPlanApiCaseExample;
|
||||
import io.metersphere.base.domain.TestPlanApiScenario;
|
||||
import io.metersphere.base.domain.TestPlanApiScenarioExample;
|
||||
import io.metersphere.base.mapper.TestPlanApiScenarioMapper;
|
||||
|
@ -16,6 +19,7 @@ import io.metersphere.track.request.testcase.TestPlanApiCaseBatchRequest;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
|
@ -33,6 +37,8 @@ public class TestPlanScenarioCaseService {
|
|||
TestPlanApiScenarioMapper testPlanApiScenarioMapper;
|
||||
@Resource
|
||||
ExtTestPlanScenarioCaseMapper extTestPlanScenarioCaseMapper;
|
||||
@Resource
|
||||
ApiScenarioReportService apiScenarioReportService;
|
||||
|
||||
public List<ApiScenarioDTO> list(TestPlanScenarioRequest request) {
|
||||
request.setProjectId(null);
|
||||
|
@ -53,22 +59,26 @@ public class TestPlanScenarioCaseService {
|
|||
return apiAutomationService.list(request);
|
||||
}
|
||||
|
||||
public int delete(String planId, String id) {
|
||||
// apiDefinitionExecResultService.deleteByResourceId(id);
|
||||
public int delete(String id) {
|
||||
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(id);
|
||||
String reportId = testPlanApiScenario.getReportId();
|
||||
if (!StringUtils.isEmpty(reportId)) {
|
||||
apiScenarioReportService.delete(reportId);
|
||||
}
|
||||
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
|
||||
example.createCriteria()
|
||||
.andTestPlanIdEqualTo(planId)
|
||||
.andIdEqualTo(id);
|
||||
|
||||
return testPlanApiScenarioMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public void deleteApiCaseBath(TestPlanApiCaseBatchRequest request) {
|
||||
// apiDefinitionExecResultService.deleteByResourceIds(request.getIds());
|
||||
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
|
||||
example.createCriteria()
|
||||
.andIdIn(request.getIds())
|
||||
.andTestPlanIdEqualTo(request.getPlanId());
|
||||
.andIdIn(request.getIds());
|
||||
List<String> reportIds = testPlanApiScenarioMapper.selectByExample(example).stream()
|
||||
.map(TestPlanApiScenario::getReportId).collect(Collectors.toList());
|
||||
apiScenarioReportService.deleteByIds(reportIds);
|
||||
testPlanApiScenarioMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
|
@ -93,4 +103,11 @@ public class TestPlanScenarioCaseService {
|
|||
public List<String> getExecResultByPlanId(String planId) {
|
||||
return extTestPlanScenarioCaseMapper.getExecResultByPlanId(planId);
|
||||
}
|
||||
|
||||
public void deleteByPlanId(String planId) {
|
||||
TestPlanApiCaseBatchRequest request = new TestPlanApiCaseBatchRequest();
|
||||
List<String> ids = extTestPlanScenarioCaseMapper.getIdsByPlanId(planId);
|
||||
request.setIds(ids);
|
||||
deleteApiCaseBath(request);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -287,6 +287,8 @@ public class TestPlanService {
|
|||
TestPlan testPlan = getTestPlan(planId);
|
||||
deleteTestCaseByPlanId(planId);
|
||||
testPlanProjectService.deleteTestPlanProjectByPlanId(planId);
|
||||
testPlanApiCaseService.deleteByPlanId(planId);
|
||||
testPlanScenarioCaseService.deleteByPlanId(planId);
|
||||
int num = testPlanMapper.deleteByPrimaryKey(planId);
|
||||
List<String> relatedUsers = new ArrayList<>();
|
||||
AddTestPlanRequest testPlans = new AddTestPlanRequest();
|
||||
|
|
|
@ -415,7 +415,7 @@
|
|||
});
|
||||
},
|
||||
handleDelete(apiCase) {
|
||||
this.$get('/test/plan/api/case/delete/' + this.planId + '/' + apiCase.id, () => {
|
||||
this.$get('/test/plan/api/case/delete/' + apiCase.id, () => {
|
||||
this.$success(this.$t('test_track.cancel_relevance_success'));
|
||||
this.$emit('refresh');
|
||||
this.initTable();
|
||||
|
|
|
@ -192,7 +192,7 @@
|
|||
this.reportId = row.reportId;
|
||||
},
|
||||
remove(row) {
|
||||
this.$get('/test/plan/scenario/case/delete/' + this.planId + '/' + row.id, () => {
|
||||
this.$get('/test/plan/scenario/case/delete/' + row.id, () => {
|
||||
this.$success(this.$t('test_track.cancel_relevance_success'));
|
||||
this.$emit('refresh');
|
||||
this.search();
|
||||
|
|
Loading…
Reference in New Issue