refactor(接口管理): 场景导入查询数据增加config数据
This commit is contained in:
parent
e8a4a2e9e6
commit
7c4e964e74
|
@ -0,0 +1,15 @@
|
||||||
|
package io.metersphere.api.dto.definition;
|
||||||
|
|
||||||
|
import io.metersphere.api.domain.ApiTestCase;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ApiTestCaseAssociateDTO extends ApiTestCase {
|
||||||
|
|
||||||
|
@Schema(description = "请求方法")
|
||||||
|
private String method;
|
||||||
|
|
||||||
|
@Schema(description = "协议")
|
||||||
|
private String protocol;
|
||||||
|
}
|
|
@ -688,6 +688,7 @@
|
||||||
api_definition.num,
|
api_definition.num,
|
||||||
api_definition.project_id,
|
api_definition.project_id,
|
||||||
api_definition.version_id,
|
api_definition.version_id,
|
||||||
|
api_definition.protocol,
|
||||||
api_definition.pos
|
api_definition.pos
|
||||||
from api_definition
|
from api_definition
|
||||||
where api_definition.deleted = false
|
where api_definition.deleted = false
|
||||||
|
@ -709,6 +710,7 @@
|
||||||
api_definition.num,
|
api_definition.num,
|
||||||
api_definition.project_id,
|
api_definition.project_id,
|
||||||
api_definition.version_id,
|
api_definition.version_id,
|
||||||
|
api_definition.protocol,
|
||||||
api_definition.pos
|
api_definition.pos
|
||||||
from api_definition
|
from api_definition
|
||||||
where api_definition.deleted = false
|
where api_definition.deleted = false
|
||||||
|
@ -733,6 +735,7 @@
|
||||||
api_definition.num,
|
api_definition.num,
|
||||||
api_definition.project_id,
|
api_definition.project_id,
|
||||||
api_definition.version_id,
|
api_definition.version_id,
|
||||||
|
api_definition.protocol,
|
||||||
api_definition.pos
|
api_definition.pos
|
||||||
from api_definition
|
from api_definition
|
||||||
where api_definition.deleted = false
|
where api_definition.deleted = false
|
||||||
|
|
|
@ -111,6 +111,12 @@ public interface ExtApiTestCaseMapper {
|
||||||
|
|
||||||
List<ApiTestCase> getListBySelectIds(@Param("projectId") String projectId, @Param("ids") List<String> ids, @Param("testPlanId") String testPlanId, @Param("protocols") List<String> protocols);
|
List<ApiTestCase> getListBySelectIds(@Param("projectId") String projectId, @Param("ids") List<String> ids, @Param("testPlanId") String testPlanId, @Param("protocols") List<String> protocols);
|
||||||
|
|
||||||
|
List<ApiTestCaseAssociateDTO>selectAllApiCaseWithAssociate(@Param("projectId") String projectId, @Param("protocols") List<String> protocols);
|
||||||
|
|
||||||
|
List<ApiTestCaseAssociateDTO> getListBySelectModulesWithAssociate(@Param("projectId") String projectId, @Param("moduleIds") List<String> moduleIds, @Param("protocols") List<String> protocols);
|
||||||
|
|
||||||
|
List<ApiTestCaseAssociateDTO> getListBySelectIdsWithAssociate(@Param("projectId") String projectId, @Param("ids") List<String> ids, @Param("protocols") List<String> protocols);
|
||||||
|
|
||||||
List<ApiTestCase> getCaseListBySelectIds(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("ids") List<String> ids, @Param("testPlanId") String testPlanId, @Param("protocols") List<String> protocols);
|
List<ApiTestCase> getCaseListBySelectIds(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("ids") List<String> ids, @Param("testPlanId") String testPlanId, @Param("protocols") List<String> protocols);
|
||||||
|
|
||||||
void setApiChangeByApiDefinitionId(@Param("apiDefinitionId") String apiDefinitionId);
|
void setApiChangeByApiDefinitionId(@Param("apiDefinitionId") String apiDefinitionId);
|
||||||
|
|
|
@ -766,10 +766,6 @@
|
||||||
api_test_case.id,
|
api_test_case.id,
|
||||||
api_test_case.create_user,
|
api_test_case.create_user,
|
||||||
api_test_case.environment_id,
|
api_test_case.environment_id,
|
||||||
api_test_case.name,
|
|
||||||
api_test_case.project_id,
|
|
||||||
api_test_case.num,
|
|
||||||
api_test_case.version_id,
|
|
||||||
api_test_case.pos
|
api_test_case.pos
|
||||||
from api_test_case
|
from api_test_case
|
||||||
INNER JOIN api_definition ON api_test_case.api_definition_id = api_definition.id
|
INNER JOIN api_definition ON api_test_case.api_definition_id = api_definition.id
|
||||||
|
@ -795,10 +791,6 @@
|
||||||
api_test_case.id,
|
api_test_case.id,
|
||||||
api_test_case.create_user,
|
api_test_case.create_user,
|
||||||
api_test_case.environment_id,
|
api_test_case.environment_id,
|
||||||
api_test_case.name,
|
|
||||||
api_test_case.project_id,
|
|
||||||
api_test_case.num,
|
|
||||||
api_test_case.version_id,
|
|
||||||
api_test_case.pos
|
api_test_case.pos
|
||||||
from api_test_case
|
from api_test_case
|
||||||
inner join api_definition on api_definition.id = api_test_case.api_definition_id
|
inner join api_definition on api_definition.id = api_test_case.api_definition_id
|
||||||
|
@ -822,6 +814,54 @@
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getListBySelectIds" resultType="io.metersphere.api.domain.ApiTestCase">
|
<select id="getListBySelectIds" resultType="io.metersphere.api.domain.ApiTestCase">
|
||||||
|
select
|
||||||
|
api_test_case.id,
|
||||||
|
api_test_case.create_user,
|
||||||
|
api_test_case.environment_id,
|
||||||
|
api_test_case.pos
|
||||||
|
from api_test_case
|
||||||
|
inner join api_definition on api_definition.id = api_test_case.api_definition_id
|
||||||
|
where api_test_case.deleted = false
|
||||||
|
and api_test_case.project_id = #{projectId}
|
||||||
|
AND api_test_case.id in
|
||||||
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
<if test="protocols != null and protocols.size() > 0">
|
||||||
|
and api_definition.protocol in
|
||||||
|
<foreach collection="protocols" item="protocol" separator="," open="(" close=")">
|
||||||
|
#{protocol}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectAllApiCaseWithAssociate" resultType="io.metersphere.api.dto.definition.ApiTestCaseAssociateDTO">
|
||||||
|
select
|
||||||
|
api_test_case.id,
|
||||||
|
api_test_case.create_user,
|
||||||
|
api_test_case.environment_id,
|
||||||
|
api_test_case.name,
|
||||||
|
api_test_case.project_id,
|
||||||
|
api_definition.method as method,
|
||||||
|
api_definition.protocol as protocol,
|
||||||
|
api_test_case.num,
|
||||||
|
api_test_case.version_id,
|
||||||
|
api_test_case.pos
|
||||||
|
from api_test_case
|
||||||
|
INNER JOIN api_definition ON api_test_case.api_definition_id = api_definition.id
|
||||||
|
where api_test_case.deleted = false
|
||||||
|
and api_test_case.project_id = #{projectId}
|
||||||
|
<if test="protocols != null and protocols.size() > 0">
|
||||||
|
and api_definition.protocol in
|
||||||
|
<foreach collection="protocols" item="protocol" separator="," open="(" close=")">
|
||||||
|
#{protocol}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
order by api_test_case.pos asc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="getListBySelectModulesWithAssociate" resultType="io.metersphere.api.dto.definition.ApiTestCaseAssociateDTO">
|
||||||
select
|
select
|
||||||
api_test_case.id,
|
api_test_case.id,
|
||||||
api_test_case.create_user,
|
api_test_case.create_user,
|
||||||
|
@ -830,6 +870,36 @@
|
||||||
api_test_case.project_id,
|
api_test_case.project_id,
|
||||||
api_test_case.num,
|
api_test_case.num,
|
||||||
api_test_case.version_id,
|
api_test_case.version_id,
|
||||||
|
api_definition.method as method,
|
||||||
|
api_definition.protocol as protocol,
|
||||||
|
api_test_case.pos
|
||||||
|
from api_test_case
|
||||||
|
inner join api_definition on api_definition.id = api_test_case.api_definition_id
|
||||||
|
where api_test_case.deleted = false
|
||||||
|
and api_test_case.project_id = #{projectId}
|
||||||
|
and api_definition.module_id in
|
||||||
|
<foreach collection="moduleIds" item="moduleId" open="(" separator="," close=")">
|
||||||
|
#{moduleId}
|
||||||
|
</foreach>
|
||||||
|
<if test="protocols != null and protocols.size() > 0">
|
||||||
|
and api_definition.protocol in
|
||||||
|
<foreach collection="protocols" item="protocol" separator="," open="(" close=")">
|
||||||
|
#{protocol}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getListBySelectIdsWithAssociate" resultType="io.metersphere.api.dto.definition.ApiTestCaseAssociateDTO">
|
||||||
|
select
|
||||||
|
api_test_case.id,
|
||||||
|
api_test_case.create_user,
|
||||||
|
api_test_case.environment_id,
|
||||||
|
api_test_case.name,
|
||||||
|
api_test_case.project_id,
|
||||||
|
api_test_case.num,
|
||||||
|
api_test_case.version_id,
|
||||||
|
api_definition.method as method,
|
||||||
|
api_definition.protocol as protocol,
|
||||||
api_test_case.pos
|
api_test_case.pos
|
||||||
from api_test_case
|
from api_test_case
|
||||||
inner join api_definition on api_definition.id = api_test_case.api_definition_id
|
inner join api_definition on api_definition.id = api_test_case.api_definition_id
|
||||||
|
|
|
@ -5,6 +5,7 @@ import io.metersphere.api.domain.ApiDefinition;
|
||||||
import io.metersphere.api.domain.ApiScenario;
|
import io.metersphere.api.domain.ApiScenario;
|
||||||
import io.metersphere.api.domain.ApiScenarioCsvStep;
|
import io.metersphere.api.domain.ApiScenarioCsvStep;
|
||||||
import io.metersphere.api.domain.ApiTestCase;
|
import io.metersphere.api.domain.ApiTestCase;
|
||||||
|
import io.metersphere.api.dto.definition.ApiTestCaseAssociateDTO;
|
||||||
import io.metersphere.api.dto.scenario.ApiScenarioSelectAssociateDTO;
|
import io.metersphere.api.dto.scenario.ApiScenarioSelectAssociateDTO;
|
||||||
import io.metersphere.api.dto.scenario.ApiScenarioStepCommonDTO;
|
import io.metersphere.api.dto.scenario.ApiScenarioStepCommonDTO;
|
||||||
import io.metersphere.api.dto.scenario.ApiScenarioStepDTO;
|
import io.metersphere.api.dto.scenario.ApiScenarioStepDTO;
|
||||||
|
@ -99,6 +100,13 @@ public class ApiScenarioSelectAssociateService {
|
||||||
private static void getApiSteps(ApiScenarioSelectAssociateDTO request, List<ApiDefinition> apiDefinitionList, List<ApiScenarioStepDTO> steps) {
|
private static void getApiSteps(ApiScenarioSelectAssociateDTO request, List<ApiDefinition> apiDefinitionList, List<ApiScenarioStepDTO> steps) {
|
||||||
apiDefinitionList.forEach(item -> {
|
apiDefinitionList.forEach(item -> {
|
||||||
ApiScenarioStepDTO step = new ApiScenarioStepDTO();
|
ApiScenarioStepDTO step = new ApiScenarioStepDTO();
|
||||||
|
LinkedHashMap<String, Object> config = new LinkedHashMap<>();
|
||||||
|
config.put("enable", true);
|
||||||
|
config.put("id", "");
|
||||||
|
config.put("method", item.getMethod());
|
||||||
|
config.put("name", "");
|
||||||
|
config.put("protocol", item.getProtocol());
|
||||||
|
step.setConfig(config);
|
||||||
step.setStepType(ApiScenarioStepType.API.name());
|
step.setStepType(ApiScenarioStepType.API.name());
|
||||||
step.setName(item.getName());
|
step.setName(item.getName());
|
||||||
step.setResourceId(item.getId());
|
step.setResourceId(item.getId());
|
||||||
|
@ -118,20 +126,20 @@ public class ApiScenarioSelectAssociateService {
|
||||||
moduleMaps.remove(MODULE_ALL);
|
moduleMaps.remove(MODULE_ALL);
|
||||||
if (selectAllModule) {
|
if (selectAllModule) {
|
||||||
// 选择了全部模块
|
// 选择了全部模块
|
||||||
List<ApiTestCase> apiTestCaseList = extApiTestCaseMapper.selectAllApiCase(true, request.getProjectId(), null, request.getProtocols());
|
List<ApiTestCaseAssociateDTO> apiTestCaseList = extApiTestCaseMapper.selectAllApiCaseWithAssociate(request.getProjectId(), request.getProtocols());
|
||||||
getCaseSteps(request, apiTestCaseList, steps);
|
getCaseSteps(request, apiTestCaseList, steps);
|
||||||
} else {
|
} else {
|
||||||
AssociateCaseDTO dto = getCaseIds(moduleMaps);
|
AssociateCaseDTO dto = getCaseIds(moduleMaps);
|
||||||
List<ApiTestCase> apiTestCaseList = new ArrayList<>();
|
List<ApiTestCaseAssociateDTO> apiTestCaseList = new ArrayList<>();
|
||||||
//获取全选的模块数据
|
//获取全选的模块数据
|
||||||
if (CollectionUtils.isNotEmpty(dto.getModuleIds())) {
|
if (CollectionUtils.isNotEmpty(dto.getModuleIds())) {
|
||||||
apiTestCaseList = extApiTestCaseMapper.getListBySelectModules(true, request.getProjectId(), dto.getModuleIds(), null, request.getProtocols());
|
apiTestCaseList = extApiTestCaseMapper.getListBySelectModulesWithAssociate( request.getProjectId(), dto.getModuleIds(), request.getProtocols());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(dto.getSelectIds())) {
|
if (CollectionUtils.isNotEmpty(dto.getSelectIds())) {
|
||||||
CollectionUtils.removeAll(dto.getSelectIds(), apiTestCaseList.stream().map(ApiTestCase::getId).toList());
|
CollectionUtils.removeAll(dto.getSelectIds(), apiTestCaseList.stream().map(ApiTestCase::getId).toList());
|
||||||
//获取选中的ids数据
|
//获取选中的ids数据
|
||||||
List<ApiTestCase> selectIdList = extApiTestCaseMapper.getListBySelectIds(request.getProjectId(), dto.getSelectIds(), null, request.getProtocols());
|
List<ApiTestCaseAssociateDTO> selectIdList = extApiTestCaseMapper.getListBySelectIdsWithAssociate(request.getProjectId(), dto.getSelectIds(), request.getProtocols());
|
||||||
apiTestCaseList.addAll(selectIdList);
|
apiTestCaseList.addAll(selectIdList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +150,7 @@ public class ApiScenarioSelectAssociateService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(apiTestCaseList)) {
|
if (CollectionUtils.isNotEmpty(apiTestCaseList)) {
|
||||||
List<ApiTestCase> list = apiTestCaseList.stream().sorted(Comparator.comparing(ApiTestCase::getPos)).toList();
|
List<ApiTestCaseAssociateDTO> list = apiTestCaseList.stream().sorted(Comparator.comparing(ApiTestCase::getPos)).toList();
|
||||||
getCaseSteps(request, list, steps);
|
getCaseSteps(request, list, steps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,10 +159,17 @@ public class ApiScenarioSelectAssociateService {
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void getCaseSteps(ApiScenarioSelectAssociateDTO request, List<ApiTestCase> apiTestCaseList, List<ApiScenarioStepDTO> steps) {
|
private static void getCaseSteps(ApiScenarioSelectAssociateDTO request, List<ApiTestCaseAssociateDTO> apiTestCaseList, List<ApiScenarioStepDTO> steps) {
|
||||||
apiTestCaseList.forEach(item -> {
|
apiTestCaseList.forEach(item -> {
|
||||||
ApiScenarioStepDTO step = new ApiScenarioStepDTO();
|
ApiScenarioStepDTO step = new ApiScenarioStepDTO();
|
||||||
step.setStepType(ApiScenarioStepType.API_CASE.name());
|
step.setStepType(ApiScenarioStepType.API_CASE.name());
|
||||||
|
LinkedHashMap<String, Object> config = new LinkedHashMap<>();
|
||||||
|
config.put("enable", true);
|
||||||
|
config.put("id", "");
|
||||||
|
config.put("method", item.getMethod());
|
||||||
|
config.put("name", "");
|
||||||
|
config.put("protocol", item.getProtocol());
|
||||||
|
step.setConfig(config);
|
||||||
step.setName(item.getName());
|
step.setName(item.getName());
|
||||||
step.setResourceId(item.getId());
|
step.setResourceId(item.getId());
|
||||||
step.setRefType(request.getRefType());
|
step.setRefType(request.getRefType());
|
||||||
|
|
Loading…
Reference in New Issue