Merge branch 'master' into v1.6

This commit is contained in:
BugKing 2020-12-31 16:02:55 +08:00
commit f2b439905e
13 changed files with 109 additions and 33 deletions

View File

@ -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) { private ApiDefinition updateTest(SaveApiDefinitionRequest request) {
checkNameExist(request); checkNameExist(request);
final ApiDefinitionWithBLOBs test = new ApiDefinitionWithBLOBs(); 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(); SaveApiDefinitionRequest saveReq = new SaveApiDefinitionRequest();
BeanUtils.copyBean(saveReq, request); BeanUtils.copyBean(saveReq, request);
checkNameExist(saveReq); final ApiDefinitionWithBLOBs apiDefinition = new ApiDefinitionWithBLOBs();
final ApiDefinitionWithBLOBs test = new ApiDefinitionWithBLOBs(); BeanUtils.copyBean(apiDefinition, request);
BeanUtils.copyBean(test, request); apiDefinition.setCreateTime(System.currentTimeMillis());
test.setCreateTime(System.currentTimeMillis()); apiDefinition.setUpdateTime(System.currentTimeMillis());
test.setUpdateTime(System.currentTimeMillis()); apiDefinition.setStatus(APITestStatus.Underway.name());
test.setStatus(APITestStatus.Underway.name());
if (request.getUserId() == null) { if (request.getUserId() == null) {
test.setUserId(Objects.requireNonNull(SessionUtils.getUser()).getId()); apiDefinition.setUserId(Objects.requireNonNull(SessionUtils.getUser()).getId());
} else { } else {
test.setUserId(request.getUserId()); apiDefinition.setUserId(request.getUserId());
} }
test.setDescription(request.getDescription()); apiDefinition.setDescription(request.getDescription());
batchMapper.insert(test);
return test; 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")); MSException.throwException(Translator.get("parse_data_error"));
} }
if (request.isSaved()) { if (request.isSaved()) {
importApiTest(request, apiImport); importApi(request, apiImport);
} }
return apiImport; return apiImport;
} }
private void importApiTest(ApiTestImportRequest request, ApiDefinitionImport apiImport) { private void importApi(ApiTestImportRequest request, ApiDefinitionImport apiImport) {
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
ApiDefinitionMapper batchMapper = sqlSession.getMapper(ApiDefinitionMapper.class); ApiDefinitionMapper batchMapper = sqlSession.getMapper(ApiDefinitionMapper.class);
List<ApiDefinitionResult> data = apiImport.getData(); List<ApiDefinitionResult> data = apiImport.getData();
@ -377,7 +399,7 @@ public class ApiDefinitionService {
item.setName(item.getName().substring(0, 255)); item.setName(item.getName().substring(0, 255));
} }
item.setNum(num++); item.setNum(num++);
createTest(item, batchMapper); importCreate(item, batchMapper);
if (i % 300 == 0) { if (i % 300 == 0) {
sqlSession.flushStatements(); sqlSession.flushStatements();
} }

View File

@ -207,6 +207,20 @@ public class ApiScenarioReportService {
apiScenarioReportMapper.deleteByPrimaryKey(request.getId()); 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) { public void deleteAPIReportBatch(DeleteAPIReportRequest reportRequest) {
List<String> ids = reportRequest.getIds(); List<String> ids = reportRequest.getIds();
if (reportRequest.isSelectAllDate()) { if (reportRequest.isSelectAllDate()) {

View File

@ -13,4 +13,6 @@ public interface ExtTestPlanApiCaseMapper {
List<TestPlanApiCaseDTO> list(@Param("request") ApiTestCaseRequest request); List<TestPlanApiCaseDTO> list(@Param("request") ApiTestCaseRequest request);
List<String> getExecResultByPlanId(String planId); List<String> getExecResultByPlanId(String planId);
List<String> getIdsByPlanId(String planId);
} }

View File

@ -97,4 +97,10 @@
where test_plan_id = #{planId} where test_plan_id = #{planId}
</select> </select>
<select id="getIdsByPlanId" resultType="java.lang.String">
select id from
from test_plan_api_case
where id = #{planId}
</select>
</mapper> </mapper>

View File

@ -19,4 +19,6 @@ public interface ExtTestPlanScenarioCaseMapper {
List<ApiScenarioDTO> list(@Param("request") TestPlanScenarioRequest request); List<ApiScenarioDTO> list(@Param("request") TestPlanScenarioRequest request);
List<String> getExecResultByPlanId(String planId); List<String> getExecResultByPlanId(String planId);
List<String> getIdsByPlanId(String planId);
} }

View File

@ -86,5 +86,10 @@
test_plan_api_scenario test_plan_api_scenario
where test_plan_id = #{planId} where test_plan_id = #{planId}
</select> </select>
<select id="getIdsByPlanId" resultType="java.lang.String">
select id
from test_plan_api_scenario
where test_plan_id = #{planId}
</select>
</mapper> </mapper>

View File

@ -38,10 +38,10 @@ public class TestPlanApiCaseController {
return PageUtils.setPageInfo(page, testPlanApiCaseService.relevanceList(request)); 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) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public int deleteTestCase(@PathVariable String planId, @PathVariable String id) { public int deleteTestCase(@PathVariable String id) {
return testPlanApiCaseService.delete(planId, id); return testPlanApiCaseService.delete(id);
} }
@PostMapping("/batch/delete") @PostMapping("/batch/delete")

View File

@ -36,10 +36,10 @@ public class TestPlanScenarioCaseController {
return PageUtils.setPageInfo(page, testPlanScenarioCaseService.relevanceList(request)); 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) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public int deleteTestCase(@PathVariable String planId, @PathVariable String id) { public int deleteTestCase(@PathVariable String id) {
return testPlanScenarioCaseService.delete(planId, id); return testPlanScenarioCaseService.delete(id);
} }
@PostMapping("/batch/delete") @PostMapping("/batch/delete")

View File

@ -58,18 +58,24 @@ public class TestPlanApiCaseService {
return apiTestCaseService.listSimple(request); return apiTestCaseService.listSimple(request);
} }
public int delete(String id) {
public int delete(String planId, String id) {
apiDefinitionExecResultService.deleteByResourceId(id); apiDefinitionExecResultService.deleteByResourceId(id);
TestPlanApiCaseExample example = new TestPlanApiCaseExample(); TestPlanApiCaseExample example = new TestPlanApiCaseExample();
example.createCriteria() example.createCriteria()
.andTestPlanIdEqualTo(planId)
.andIdEqualTo(id); .andIdEqualTo(id);
return testPlanApiCaseMapper.deleteByExample(example); 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) { public void deleteApiCaseBath(TestPlanApiCaseBatchRequest request) {
apiDefinitionExecResultService.deleteByResourceIds(request.getIds()); apiDefinitionExecResultService.deleteByResourceIds(request.getIds());
TestPlanApiCaseExample example = new TestPlanApiCaseExample(); TestPlanApiCaseExample example = new TestPlanApiCaseExample();

View File

@ -1,11 +1,14 @@
package io.metersphere.track.service; package io.metersphere.track.service;
import io.metersphere.api.dto.DeleteAPIReportRequest;
import io.metersphere.api.dto.automation.ApiScenarioDTO; import io.metersphere.api.dto.automation.ApiScenarioDTO;
import io.metersphere.api.dto.automation.ApiScenarioRequest; import io.metersphere.api.dto.automation.ApiScenarioRequest;
import io.metersphere.api.dto.automation.RunScenarioRequest; import io.metersphere.api.dto.automation.RunScenarioRequest;
import io.metersphere.api.dto.automation.TestPlanScenarioRequest; import io.metersphere.api.dto.automation.TestPlanScenarioRequest;
import io.metersphere.api.service.ApiAutomationService; import io.metersphere.api.service.ApiAutomationService;
import io.metersphere.api.service.ApiScenarioReportService;
import io.metersphere.base.domain.TestPlanApiCase; import io.metersphere.base.domain.TestPlanApiCase;
import io.metersphere.base.domain.TestPlanApiCaseExample;
import io.metersphere.base.domain.TestPlanApiScenario; import io.metersphere.base.domain.TestPlanApiScenario;
import io.metersphere.base.domain.TestPlanApiScenarioExample; import io.metersphere.base.domain.TestPlanApiScenarioExample;
import io.metersphere.base.mapper.TestPlanApiScenarioMapper; 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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
@ -33,6 +37,8 @@ public class TestPlanScenarioCaseService {
TestPlanApiScenarioMapper testPlanApiScenarioMapper; TestPlanApiScenarioMapper testPlanApiScenarioMapper;
@Resource @Resource
ExtTestPlanScenarioCaseMapper extTestPlanScenarioCaseMapper; ExtTestPlanScenarioCaseMapper extTestPlanScenarioCaseMapper;
@Resource
ApiScenarioReportService apiScenarioReportService;
public List<ApiScenarioDTO> list(TestPlanScenarioRequest request) { public List<ApiScenarioDTO> list(TestPlanScenarioRequest request) {
request.setProjectId(null); request.setProjectId(null);
@ -53,22 +59,26 @@ public class TestPlanScenarioCaseService {
return apiAutomationService.list(request); return apiAutomationService.list(request);
} }
public int delete(String planId, String id) { public int delete(String id) {
// apiDefinitionExecResultService.deleteByResourceId(id); TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(id);
String reportId = testPlanApiScenario.getReportId();
if (!StringUtils.isEmpty(reportId)) {
apiScenarioReportService.delete(reportId);
}
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
example.createCriteria() example.createCriteria()
.andTestPlanIdEqualTo(planId)
.andIdEqualTo(id); .andIdEqualTo(id);
return testPlanApiScenarioMapper.deleteByExample(example); return testPlanApiScenarioMapper.deleteByExample(example);
} }
public void deleteApiCaseBath(TestPlanApiCaseBatchRequest request) { public void deleteApiCaseBath(TestPlanApiCaseBatchRequest request) {
// apiDefinitionExecResultService.deleteByResourceIds(request.getIds());
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
example.createCriteria() example.createCriteria()
.andIdIn(request.getIds()) .andIdIn(request.getIds());
.andTestPlanIdEqualTo(request.getPlanId()); List<String> reportIds = testPlanApiScenarioMapper.selectByExample(example).stream()
.map(TestPlanApiScenario::getReportId).collect(Collectors.toList());
apiScenarioReportService.deleteByIds(reportIds);
testPlanApiScenarioMapper.deleteByExample(example); testPlanApiScenarioMapper.deleteByExample(example);
} }
@ -93,4 +103,11 @@ public class TestPlanScenarioCaseService {
public List<String> getExecResultByPlanId(String planId) { public List<String> getExecResultByPlanId(String planId) {
return extTestPlanScenarioCaseMapper.getExecResultByPlanId(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);
}
} }

View File

@ -287,6 +287,8 @@ public class TestPlanService {
TestPlan testPlan = getTestPlan(planId); TestPlan testPlan = getTestPlan(planId);
deleteTestCaseByPlanId(planId); deleteTestCaseByPlanId(planId);
testPlanProjectService.deleteTestPlanProjectByPlanId(planId); testPlanProjectService.deleteTestPlanProjectByPlanId(planId);
testPlanApiCaseService.deleteByPlanId(planId);
testPlanScenarioCaseService.deleteByPlanId(planId);
int num = testPlanMapper.deleteByPrimaryKey(planId); int num = testPlanMapper.deleteByPrimaryKey(planId);
List<String> relatedUsers = new ArrayList<>(); List<String> relatedUsers = new ArrayList<>();
AddTestPlanRequest testPlans = new AddTestPlanRequest(); AddTestPlanRequest testPlans = new AddTestPlanRequest();

View File

@ -415,7 +415,7 @@
}); });
}, },
handleDelete(apiCase) { 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.$success(this.$t('test_track.cancel_relevance_success'));
this.$emit('refresh'); this.$emit('refresh');
this.initTable(); this.initTable();

View File

@ -192,7 +192,7 @@
this.reportId = row.reportId; this.reportId = row.reportId;
}, },
remove(row) { 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.$success(this.$t('test_track.cancel_relevance_success'));
this.$emit('refresh'); this.$emit('refresh');
this.search(); this.search();