fix(接口测试): fix api definition num repeat
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001048151
This commit is contained in:
parent
579ff5d35f
commit
fd263b3755
|
@ -317,7 +317,7 @@ public class ApiScenarioController {
|
||||||
@PostMapping(value = "/export/{type}")
|
@PostMapping(value = "/export/{type}")
|
||||||
@Operation(summary = "接口测试-接口场景管理-场景-导出场景")
|
@Operation(summary = "接口测试-接口场景管理-场景-导出场景")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_EXPORT)
|
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_EXPORT)
|
||||||
@CheckOwner(resourceId = "#request.getResourceId()", resourceType = "api_scenario")
|
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
|
||||||
public String export(@RequestBody ApiScenarioBatchExportRequest request, @PathVariable String type) {
|
public String export(@RequestBody ApiScenarioBatchExportRequest request, @PathVariable String type) {
|
||||||
return apiScenarioDataTransferService.exportScenario(request, type, SessionUtils.getUserId());
|
return apiScenarioDataTransferService.exportScenario(request, type, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,4 +105,6 @@ public interface ExtApiDefinitionMapper {
|
||||||
List<String> getIdsByShareParam(@Param("projectId") String projectId, @Param("condition") String condition);
|
List<String> getIdsByShareParam(@Param("projectId") String projectId, @Param("condition") String condition);
|
||||||
|
|
||||||
long countByProjectAndId(@Param("projectId") String projectId, @Param("id") String id);
|
long countByProjectAndId(@Param("projectId") String projectId, @Param("id") String id);
|
||||||
|
|
||||||
|
Long selectNumById(String id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -766,4 +766,9 @@
|
||||||
AND id = #{id}
|
AND id = #{id}
|
||||||
AND deleted = false
|
AND deleted = false
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectNumById" resultType="java.lang.Long">
|
||||||
|
select num
|
||||||
|
from api_definition
|
||||||
|
where id = #{0}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
@ -218,6 +218,7 @@ public class ApiScenarioDataTransferService {
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Map<String, Long> insertApiDefinitionNumMap = new HashMap<>();
|
||||||
// 接口定义
|
// 接口定义
|
||||||
if (CollectionUtils.isNotEmpty(preImportAnalysisResult.getInsertApiDefinitions())) {
|
if (CollectionUtils.isNotEmpty(preImportAnalysisResult.getInsertApiDefinitions())) {
|
||||||
Map<String, List<ApiDefinitionDetail>> projectMap = preImportAnalysisResult.getInsertApiDefinitions().stream().collect(Collectors.groupingBy(ApiDefinitionDetail::getProjectId));
|
Map<String, List<ApiDefinitionDetail>> projectMap = preImportAnalysisResult.getInsertApiDefinitions().stream().collect(Collectors.groupingBy(ApiDefinitionDetail::getProjectId));
|
||||||
|
@ -231,6 +232,7 @@ public class ApiScenarioDataTransferService {
|
||||||
BeanUtils.copyBean(apiDefinition, t);
|
BeanUtils.copyBean(apiDefinition, t);
|
||||||
apiDefinition.setPos(getImportNextOrder(apiDefinitionImportService::getNextOrder, currentApiOrder, targetProjectId));
|
apiDefinition.setPos(getImportNextOrder(apiDefinitionImportService::getNextOrder, currentApiOrder, targetProjectId));
|
||||||
apiDefinition.setLatest(true);
|
apiDefinition.setLatest(true);
|
||||||
|
apiDefinition.setNum(NumGenerator.nextNum(targetProjectId, ApplicationNumScope.API_DEFINITION));
|
||||||
apiDefinition.setStatus(ApiDefinitionStatus.PROCESSING.name());
|
apiDefinition.setStatus(ApiDefinitionStatus.PROCESSING.name());
|
||||||
apiDefinition.setRefId(apiDefinition.getId());
|
apiDefinition.setRefId(apiDefinition.getId());
|
||||||
apiDefinition.setVersionId(versionId);
|
apiDefinition.setVersionId(versionId);
|
||||||
|
@ -245,6 +247,8 @@ public class ApiScenarioDataTransferService {
|
||||||
apiDefinitionBlob.setRequest(ApiDataUtils.toJSONString(t.getRequest()).getBytes(StandardCharsets.UTF_8));
|
apiDefinitionBlob.setRequest(ApiDataUtils.toJSONString(t.getRequest()).getBytes(StandardCharsets.UTF_8));
|
||||||
apiDefinitionBlob.setResponse(ApiDataUtils.toJSONString(t.getResponse()).getBytes(StandardCharsets.UTF_8));
|
apiDefinitionBlob.setResponse(ApiDataUtils.toJSONString(t.getResponse()).getBytes(StandardCharsets.UTF_8));
|
||||||
batchApiBlobMapper.insertSelective(apiDefinitionBlob);
|
batchApiBlobMapper.insertSelective(apiDefinitionBlob);
|
||||||
|
|
||||||
|
insertApiDefinitionNumMap.put(apiDefinition.getId(), apiDefinition.getNum());
|
||||||
}
|
}
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
});
|
});
|
||||||
|
@ -266,7 +270,15 @@ public class ApiScenarioDataTransferService {
|
||||||
BeanUtils.copyBean(apiTestCase, t);
|
BeanUtils.copyBean(apiTestCase, t);
|
||||||
apiTestCase.setProjectId(targetProjectId);
|
apiTestCase.setProjectId(targetProjectId);
|
||||||
apiTestCase.setPos(getImportNextOrder(apiTestCaseService::getNextOrder, currentApiTestCaseOrder, targetProjectId));
|
apiTestCase.setPos(getImportNextOrder(apiTestCaseService::getNextOrder, currentApiTestCaseOrder, targetProjectId));
|
||||||
apiTestCase.setNum(NumGenerator.nextNum(targetProjectId, ApplicationNumScope.API_DEFINITION));
|
long apiDefinitionNum;
|
||||||
|
if (insertApiDefinitionNumMap.containsKey(apiTestCase.getApiDefinitionId())) {
|
||||||
|
apiDefinitionNum = insertApiDefinitionNumMap.get(apiTestCase.getApiDefinitionId());
|
||||||
|
} else {
|
||||||
|
apiDefinitionNum = extApiDefinitionMapper.selectNumById(apiTestCase.getApiDefinitionId());
|
||||||
|
insertApiDefinitionNumMap.put(apiTestCase.getApiDefinitionId(), apiDefinitionNum);
|
||||||
|
}
|
||||||
|
|
||||||
|
apiTestCase.setNum(NumGenerator.nextNum(targetProjectId + "_" + apiDefinitionNum, ApplicationNumScope.API_TEST_CASE));
|
||||||
apiTestCase.setStatus(ApiDefinitionStatus.PROCESSING.name());
|
apiTestCase.setStatus(ApiDefinitionStatus.PROCESSING.name());
|
||||||
apiTestCase.setVersionId(versionId);
|
apiTestCase.setVersionId(versionId);
|
||||||
apiTestCase.setCreateUser(operator);
|
apiTestCase.setCreateUser(operator);
|
||||||
|
|
Loading…
Reference in New Issue