fix: 测试计划关联用例,导入场景用例报错

This commit is contained in:
chenjianxing 2021-09-18 11:14:04 +08:00 committed by jianxing
parent 2ed49ae127
commit 3326a02277
3 changed files with 27 additions and 10 deletions

View File

@ -137,6 +137,8 @@ public class ApiAutomationService {
@Resource
private ExtTestPlanScenarioCaseMapper extTestPlanScenarioCaseMapper;
private ThreadLocal<Long> currentScenarioOrder = new ThreadLocal<>();
public ApiScenarioDTO getDto(String id) {
ApiScenarioRequest request = new ApiScenarioRequest();
request.setId(id);
@ -1767,6 +1769,7 @@ public class ApiAutomationService {
scenarioWithBLOBs.setId(UUID.randomUUID().toString());
List<ApiMethodUrlDTO> useUrl = this.parseUrl(scenarioWithBLOBs);
scenarioWithBLOBs.setUseUrl(JSONArray.toJSONString(useUrl));
scenarioWithBLOBs.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId()));
batchMapper.insert(scenarioWithBLOBs);
apiScenarioReferenceIdService.saveByApiScenario(scenarioWithBLOBs);
} else {
@ -1834,6 +1837,7 @@ public class ApiAutomationService {
if (CollectionUtils.isEmpty(sameRequest)) {
List<ApiMethodUrlDTO> useUrl = this.parseUrl(scenarioWithBLOBs);
scenarioWithBLOBs.setUseUrl(JSONArray.toJSONString(useUrl));
scenarioWithBLOBs.setOrder(getImportNextOrder(request.getProjectId()));
batchMapper.insert(scenarioWithBLOBs);
apiScenarioReferenceIdService.saveByApiScenario(scenarioWithBLOBs);
}
@ -1848,6 +1852,7 @@ public class ApiAutomationService {
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
ApiScenarioMapper batchMapper = sqlSession.getMapper(ApiScenarioMapper.class);
List<ApiScenarioWithBLOBs> data = apiImport.getData();
currentScenarioOrder.remove();
int num = 0;
Project project = new Project();
if (!CollectionUtils.isEmpty(data) && data.get(0) != null && data.get(0).getProjectId() != null) {
@ -1878,6 +1883,16 @@ public class ApiAutomationService {
sqlSession.flushStatements();
}
private Long getImportNextOrder(String projectId) {
Long order = currentScenarioOrder.get();
if (order == null) {
order = ServiceUtils.getNextOrder(projectId, extApiScenarioMapper::getLastOrder);
}
order = (order == null ? 0 : order) + 5000;
currentScenarioOrder.set(order);
return order;
}
public ScenarioImport scenarioImport(MultipartFile file, ApiTestImportRequest request) {
ApiImportParser apiImportParser = ScenarioImportParserFactory.getImportParser(request.getPlatform());
ScenarioImport apiImport = null;

View File

@ -31,7 +31,6 @@ import io.metersphere.track.request.report.QueryTestPlanReportRequest;
import io.metersphere.track.request.report.TestPlanReportSaveRequest;
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
import io.metersphere.track.request.testplan.LoadCaseRequest;
import io.metersphere.xpack.license.service.LicenseService;
import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
@ -87,8 +86,6 @@ public class TestPlanReportService {
TestPlanReportContentMapper testPlanReportContentMapper;
@Resource
ShareInfoService shareInfoService;
@Resource
LicenseService licenseService;
private final ExecutorService executorService = Executors.newFixedThreadPool(20);
@ -828,11 +825,6 @@ public class TestPlanReportService {
paramMap.put("projectId", projectId);
paramMap.putAll(new BeanMap(testPlanReport));
if (licenseService.valid() != null) {
String testPlanShareUrl = shareInfoService.getTestPlanShareUrl(testPlanReport.getId());
paramMap.put("planShareUrl", baseSystemConfigDTO.getUrl() + "/sharePlanReport" + testPlanShareUrl);
}
String successfulMailTemplate = "";
String errfoMailTemplate = "";

View File

@ -504,7 +504,11 @@ public class TestPlanService {
if (testCaseTestMapper.countByExample(examp) > 0) {
list = testCaseTestMapper.selectByExample(examp);
}
list.forEach(l -> {
Long nextLoadOrder = ServiceUtils.getNextOrder(request.getPlanId(), extTestPlanLoadCaseMapper::getLastOrder);
Long nextApiOrder = ServiceUtils.getNextOrder(request.getPlanId(), extTestPlanApiCaseMapper::getLastOrder);
Long nextScenarioOrder = ServiceUtils.getNextOrder(request.getPlanId(), extTestPlanScenarioCaseMapper::getLastOrder);
for (TestCaseTest l : list) {
if (StringUtils.equals(l.getTestType(), TestCaseStatus.performance.name())) {
TestPlanLoadCase t = new TestPlanLoadCase();
t.setId(UUID.randomUUID().toString());
@ -512,6 +516,8 @@ public class TestPlanService {
t.setLoadCaseId(l.getTestId());
t.setCreateTime(System.currentTimeMillis());
t.setUpdateTime(System.currentTimeMillis());
t.setOrder(nextLoadOrder);
nextLoadOrder += 5000;
TestPlanLoadCaseExample testPlanLoadCaseExample = new TestPlanLoadCaseExample();
testPlanLoadCaseExample.createCriteria().andTestPlanIdEqualTo(request.getPlanId()).andLoadCaseIdEqualTo(t.getLoadCaseId());
if (testPlanLoadCaseMapper.countByExample(testPlanLoadCaseExample) <= 0) {
@ -530,6 +536,8 @@ public class TestPlanService {
t.setEnvironmentId(apidefinition.getEnvironmentId());
t.setCreateTime(System.currentTimeMillis());
t.setUpdateTime(System.currentTimeMillis());
t.setOrder(nextApiOrder);
nextApiOrder += 5000;
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
example.createCriteria().andTestPlanIdEqualTo(request.getPlanId()).andApiCaseIdEqualTo(t.getApiCaseId());
if (testPlanApiCaseMapper.countByExample(example) <= 0) {
@ -552,6 +560,8 @@ public class TestPlanService {
t.setStatus(testPlanApiScenario.getStatus());
t.setCreateTime(System.currentTimeMillis());
t.setUpdateTime(System.currentTimeMillis());
t.setOrder(nextScenarioOrder);
nextScenarioOrder += 5000;
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
example.createCriteria().andTestPlanIdEqualTo(request.getPlanId()).andApiScenarioIdEqualTo(t.getApiScenarioId());
if (testPlanApiScenarioMapper.countByExample(example) <= 0) {
@ -560,7 +570,7 @@ public class TestPlanService {
}
}
});
}
});
}
}