feat(测试计划): 关联apiCase抽屉,apiCase模块count接口

This commit is contained in:
WangXu10 2024-07-01 14:25:29 +08:00 committed by Craftsman
parent 528b3388d0
commit 0a62bc7c80
5 changed files with 103 additions and 0 deletions

View File

@ -39,4 +39,13 @@ public interface ExtApiDefinitionModuleMapper {
List<String> getModuleIdsByParentIds(@Param("parentIds") List<String> parentIds);
List<ApiDefinitionModule> getNameInfoByIds(@Param("ids") List<String> ids);
/**
* 获取ApiCase的模块count
* @param request
* @param deleted
* @param isRepeat
* @return
*/
List<ModuleCountDTO> apiCaseCountModuleIdByRequest(@Param("request") ApiModuleRequest request, @Param("deleted") boolean deleted, @Param("isRepeat") boolean isRepeat);
}

View File

@ -377,4 +377,33 @@
</where>
</sql>
<select id="apiCaseCountModuleIdByRequest" resultType="io.metersphere.project.dto.ModuleCountDTO">
SELECT
module_id AS moduleId,
count( api_test_case.id ) AS dataCount
FROM
api_definition
INNER JOIN api_test_case ON api_definition.id = api_test_case.api_definition_id
WHERE
api_test_case.deleted = #{deleted}
<include refid="queryWhereCondition"/>
<if test="request.testPlanId != null and request.testPlanId != ''">
and exists (
select id
from api_test_case c
where c.api_definition_id = api_definition.id and c.deleted = false
<if test="!isRepeat">
and not exists (
select id
from test_plan_api_case t
where t.api_case_id = c.id
and t.test_plan_id = #{request.testPlanId}
)
</if>
)
</if>
GROUP BY api_definition.module_id
</select>
</mapper>

View File

@ -3,6 +3,7 @@ package io.metersphere.plan.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.api.dto.definition.ApiDefinitionDTO;
import io.metersphere.api.dto.definition.ApiModuleRequest;
import io.metersphere.api.dto.definition.ApiTestCaseDTO;
import io.metersphere.api.dto.scenario.ApiScenarioDTO;
import io.metersphere.functional.dto.FunctionalCasePageDTO;
@ -31,6 +32,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
@Tag(name = "测试计划关联用例弹窗接口相关")
@ -113,4 +115,13 @@ public class TestPlanAssociateController {
return PageUtils.setPageInfo(page, testPlanApiScenarioService.getApiScenarioPage(request, isRepeat));
}
@PostMapping("/api/case/module/count")
@Operation(summary = "测试计划-关联用例弹窗-接口CASE模块数量(项目)")
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ)
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
public Map<String, Long> moduleCount(@Validated @RequestBody ApiModuleRequest request) {
return testPlanApiCaseService.getApiCaseModuleCount(request, false);
}
}

View File

@ -2,6 +2,7 @@ package io.metersphere.plan.service;
import io.metersphere.api.domain.*;
import io.metersphere.api.dto.definition.ApiDefinitionDTO;
import io.metersphere.api.dto.definition.ApiModuleRequest;
import io.metersphere.api.dto.definition.ApiTestCaseDTO;
import io.metersphere.api.dto.definition.ApiTestCasePageRequest;
import io.metersphere.api.mapper.ApiReportMapper;
@ -48,6 +49,7 @@ import io.metersphere.system.utils.ServiceUtils;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
@ -113,6 +115,9 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
private OperationLogService operationLogService;
@Resource
private ExtApiDefinitionModuleMapper extApiDefinitionModuleMapper;
@Resource
private TestPlanConfigMapper testPlanConfigMapper;
private static final String DEBUG_MODULE_COUNT_ALL = "all";
@Override
public void deleteBatchByTestPlanId(List<String> testPlanIdList) {
@ -791,4 +796,35 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
sqlSession.flushStatements();
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
}
public Map<String, Long> getApiCaseModuleCount(ApiModuleRequest request, boolean deleted) {
if (CollectionUtils.isEmpty(request.getProtocols())) {
return Collections.emptyMap();
}
boolean isRepeat = true;
if (StringUtils.isNotEmpty(request.getTestPlanId())) {
isRepeat = this.checkTestPlanRepeatCase(request);
}
request.setModuleIds(null);
//查找根据moduleIds查找模块下的接口数量 查非delete状态的
List<ModuleCountDTO> moduleCountDTOList = extApiDefinitionModuleMapper.apiCaseCountModuleIdByRequest(request, deleted, isRepeat);
long allCount = getAllCount(moduleCountDTOList);
Map<String, Long> moduleCountMap = apiDefinitionModuleService.getModuleCountMap(request, moduleCountDTOList);
moduleCountMap.put(DEBUG_MODULE_COUNT_ALL, allCount);
return moduleCountMap;
}
private boolean checkTestPlanRepeatCase(ApiModuleRequest request) {
TestPlanConfig testPlanConfig = testPlanConfigMapper.selectByPrimaryKey(request.getTestPlanId());
return BooleanUtils.isTrue(testPlanConfig.getRepeatCase());
}
public long getAllCount(List<ModuleCountDTO> moduleCountDTOList) {
long count = 0;
for (ModuleCountDTO countDTO : moduleCountDTOList) {
count += countDTO.getDataCount();
}
return count;
}
}

View File

@ -1,5 +1,6 @@
package io.metersphere.plan.controller;
import io.metersphere.api.dto.definition.ApiModuleRequest;
import io.metersphere.functional.request.FunctionalCasePageRequest;
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
import io.metersphere.plan.dto.request.TestPlanApiRequest;
@ -26,6 +27,7 @@ public class TestPlanAssociateControllerTests extends BaseTest {
public static final String API_ASSOCIATION_URL = "/test-plan/association/api/page";
public static final String API_CASE_ASSOCIATION_URL = "/test-plan/association/api/case/page";
public static final String API_SCENARIO_URL = "/test-plan/association/api/scenario/page";
public static final String API_CASE_MODULE_COUNT_URL = "/test-plan/association/api/case/module/count";
@Test
@Order(1)
@ -114,4 +116,20 @@ public class TestPlanAssociateControllerTests extends BaseTest {
Assertions.assertNotNull(resultHolder);
}
@Test
@Order(5)
public void testApiCaseModuleCount() throws Exception {
ApiModuleRequest request = new ApiModuleRequest();
request.setProjectId("1234567");
request.setTestPlanId("wxx_1");
this.requestPostWithOkAndReturn(API_CASE_MODULE_COUNT_URL, request);
request.setProtocols(List.of("HTTP"));
request.setProjectId("wx_1234");
MvcResult mvcResult = this.requestPostWithOkAndReturn(API_CASE_MODULE_COUNT_URL, request);
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
Assertions.assertNotNull(resultHolder);
}
}