feat(测试计划): 批量取消关联接口&重复关联逻辑处理
This commit is contained in:
parent
8768197f40
commit
a3dc954774
|
@ -94,4 +94,15 @@ public class TestPlanApiScenarioController {
|
|||
testPlanService.refreshTestPlanStatus(request.getTestPlanId());
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/batch/disassociate")
|
||||
@Operation(summary = "测试计划-计划详情-列表-批量取消关联用例")
|
||||
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ASSOCIATION)
|
||||
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
|
||||
public TestPlanAssociationResponse batchDisassociate(@Validated @RequestBody BasePlanCaseBatchRequest request) {
|
||||
TestPlanAssociationResponse response = testPlanApiScenarioService.disassociate(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/scenario/batch/disassociate", HttpMethodConstants.POST.name()));
|
||||
testPlanService.refreshTestPlanStatus(request.getTestPlanId());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.metersphere.plan.mapper;
|
||||
|
||||
import io.metersphere.api.domain.ApiTestCase;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionDTO;
|
||||
import io.metersphere.functional.dto.FunctionalCaseModuleCountDTO;
|
||||
import io.metersphere.functional.dto.ProjectOptionDTO;
|
||||
|
@ -67,4 +68,6 @@ public interface ExtTestPlanApiCaseMapper {
|
|||
List<TestPlanApiCase> getPlanApiCaseByIds(@Param("planIds") List<String> planIds);
|
||||
|
||||
List<TestPlanApiCase> getApiCaseExecuteInfoByIds(@Param("ids") List<String> ids);
|
||||
|
||||
List<ApiTestCase> selectApiCaseByDefinitionIds(@Param("ids") List<String> ids, @Param("isRepeat") boolean isRepeat);
|
||||
}
|
||||
|
|
|
@ -680,4 +680,26 @@
|
|||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="selectApiCaseByDefinitionIds" resultType="io.metersphere.api.domain.ApiTestCase">
|
||||
SELECT
|
||||
api_test_case.id,
|
||||
api_test_case.api_definition_id
|
||||
FROM
|
||||
api_test_case
|
||||
WHERE
|
||||
api_test_case.deleted = false
|
||||
and api_test_case.api_definition_id IN
|
||||
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
<if test="!isRepeat">
|
||||
AND api_test_case.id NOT IN (
|
||||
SELECT
|
||||
api_case_id
|
||||
FROM
|
||||
test_plan_api_case
|
||||
)
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
|
@ -417,9 +417,6 @@
|
|||
or api_scenario.tags like concat('%', #{request.condition.keyword},'%')
|
||||
)
|
||||
</if>
|
||||
<if test="request.scenarioId != null and request.scenarioId != ''">
|
||||
and api_scenario.id = #{request.scenarioId}
|
||||
</if>
|
||||
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
|
||||
and api_scenario.module_id in
|
||||
<foreach collection="request.moduleIds" item="nodeId" separator="," open="(" close=")">
|
||||
|
@ -432,7 +429,7 @@
|
|||
<include refid="filters">
|
||||
<property name="filter" value="request.condition.filter"/>
|
||||
</include>
|
||||
<if test="request.combine != null and request.combine != ''">
|
||||
<if test="request.condition.combine != null and request.condition.combine != ''">
|
||||
<include refid="combine">
|
||||
<property name="condition" value="request.condition.combine"/>
|
||||
<property name="name" value="request.name"/>
|
||||
|
|
|
@ -30,8 +30,8 @@ import io.metersphere.project.mapper.ProjectMapper;
|
|||
import io.metersphere.sdk.constants.*;
|
||||
import io.metersphere.sdk.domain.Environment;
|
||||
import io.metersphere.sdk.domain.EnvironmentExample;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.dto.api.task.*;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
|
@ -95,6 +95,8 @@ public class TestPlanApiCaseService extends TestPlanResourceService implements G
|
|||
private TestPlanCollectionMapper testPlanCollectionMapper;
|
||||
@Resource
|
||||
private ExtTestPlanCollectionMapper extTestPlanCollectionMapper;
|
||||
@Resource
|
||||
private TestPlanConfigService testPlanConfigService;
|
||||
|
||||
public TestPlanApiCaseService() {
|
||||
GetRunScriptServiceRegister.register(ApiExecuteResourceType.TEST_PLAN_API_CASE, this);
|
||||
|
@ -507,10 +509,8 @@ public class TestPlanApiCaseService extends TestPlanResourceService implements G
|
|||
private void handleApiData(List<BaseCollectionAssociateRequest> apiCaseList, String userId, List<TestPlanApiCase> testPlanApiCaseList, String planId) {
|
||||
if (CollectionUtils.isNotEmpty(apiCaseList)) {
|
||||
List<String> ids = apiCaseList.stream().flatMap(item -> item.getIds().stream()).toList();
|
||||
//todo 优化,重复关联问题?
|
||||
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||
example.createCriteria().andApiDefinitionIdIn(ids).andDeletedEqualTo(false);
|
||||
List<ApiTestCase> apiTestCaseList = apiTestCaseMapper.selectByExample(example);
|
||||
boolean isRepeat = testPlanConfigService.isRepeatCase(planId);
|
||||
List<ApiTestCase> apiTestCaseList = extTestPlanApiCaseMapper.selectApiCaseByDefinitionIds(ids, isRepeat);
|
||||
apiCaseList.forEach(apiCase -> {
|
||||
List<String> apiCaseIds = apiCase.getIds();
|
||||
if (CollectionUtils.isNotEmpty(apiCaseIds)) {
|
||||
|
|
|
@ -55,6 +55,7 @@ public class TestPlanApiScenarioControllerTests extends BaseTest {
|
|||
public static final String API_SCENARIO_TREE = "tree";
|
||||
public static final String BATCH_RUN = "batch/run";
|
||||
public static final String API_SCENARIO_DISASSOCIATE = "disassociate";
|
||||
public static final String API_SCENARIO_BATCH_DISASSOCIATE = "batch/disassociate";
|
||||
|
||||
@Resource
|
||||
private TestPlanApiScenarioService testPlanApiScenarioService;
|
||||
|
@ -286,4 +287,18 @@ public class TestPlanApiScenarioControllerTests extends BaseTest {
|
|||
Assertions.assertNotNull(resultHolder);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
public void testApiScenarioBatchDisassociate() throws Exception {
|
||||
BasePlanCaseBatchRequest request = new BasePlanCaseBatchRequest();
|
||||
request.setTestPlanId("wxxx_plan_2");
|
||||
request.setSelectAll(true);
|
||||
MvcResult mvcResult = this.requestPostWithOkAndReturn(API_SCENARIO_BATCH_DISASSOCIATE, request);
|
||||
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue