fix(接口定义): 修复接口定义回收站用例数为0的缺陷
--bug=1016199 --user=王孝刚 【接口测试】回收站-api-用例数显示为0(api下有case) https://www.tapd.cn/55049933/s/1231791
This commit is contained in:
parent
8f2384119c
commit
85e33eb9e0
|
@ -183,7 +183,7 @@ public class ApiDefinitionService {
|
||||||
buildUserInfo(resList);
|
buildUserInfo(resList);
|
||||||
if (StringUtils.isNotBlank(request.getProjectId())) {
|
if (StringUtils.isNotBlank(request.getProjectId())) {
|
||||||
buildProjectInfo(resList, request.getProjectId());
|
buildProjectInfo(resList, request.getProjectId());
|
||||||
calculateResult(resList, request.getProjectId());
|
calculateResult(resList, request.getProjectId(), request);
|
||||||
} else {
|
} else {
|
||||||
buildProjectInfoWithoutProject(resList);
|
buildProjectInfoWithoutProject(resList);
|
||||||
}
|
}
|
||||||
|
@ -2119,31 +2119,48 @@ public class ApiDefinitionService {
|
||||||
if (!resList.isEmpty()) {
|
if (!resList.isEmpty()) {
|
||||||
List<String> ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList());
|
List<String> ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList());
|
||||||
List<ApiComputeResult> results = extApiDefinitionMapper.selectByIdsAndStatusIsNotTrash(ids, projectId);
|
List<ApiComputeResult> results = extApiDefinitionMapper.selectByIdsAndStatusIsNotTrash(ids, projectId);
|
||||||
Map<String, ApiComputeResult> resultMap = results.stream().collect(Collectors.toMap(ApiComputeResult::getApiDefinitionId, Function.identity()));
|
calculateResultList(resList, results);
|
||||||
for (ApiDefinitionResult res : resList) {
|
}
|
||||||
ApiComputeResult compRes = resultMap.get(res.getId());
|
}
|
||||||
if (compRes != null) {
|
|
||||||
res.setCaseType("apiCase");
|
private void calculateResultList(List<ApiDefinitionResult> resList, List<ApiComputeResult> results) {
|
||||||
res.setCaseTotal(String.valueOf(compRes.getCaseTotal()));
|
Map<String, ApiComputeResult> resultMap = results.stream().collect(Collectors.toMap(ApiComputeResult::getApiDefinitionId, Function.identity()));
|
||||||
res.setCasePassingRate(compRes.getPassRate());
|
for (ApiDefinitionResult res : resList) {
|
||||||
// 状态优先级 未执行,未通过,通过
|
ApiComputeResult compRes = resultMap.get(res.getId());
|
||||||
if ((compRes.getError() + compRes.getSuccess()) < compRes.getCaseTotal()) {
|
if (compRes != null) {
|
||||||
res.setCaseStatus(Translator.get("not_execute"));
|
res.setCaseType("apiCase");
|
||||||
} else if (compRes.getError() > 0) {
|
res.setCaseTotal(String.valueOf(compRes.getCaseTotal()));
|
||||||
res.setCaseStatus(Translator.get("execute_not_pass"));
|
res.setCasePassingRate(compRes.getPassRate());
|
||||||
} else {
|
// 状态优先级 未执行,未通过,通过
|
||||||
res.setCaseStatus(Translator.get("execute_pass"));
|
if ((compRes.getError() + compRes.getSuccess()) < compRes.getCaseTotal()) {
|
||||||
}
|
res.setCaseStatus(Translator.get("not_execute"));
|
||||||
|
} else if (compRes.getError() > 0) {
|
||||||
|
res.setCaseStatus(Translator.get("execute_not_pass"));
|
||||||
} else {
|
} else {
|
||||||
res.setCaseType("apiCase");
|
res.setCaseStatus(Translator.get("execute_pass"));
|
||||||
res.setCaseTotal("0");
|
|
||||||
res.setCasePassingRate("-");
|
|
||||||
res.setCaseStatus("-");
|
|
||||||
}
|
|
||||||
if (StringUtils.equalsIgnoreCase("esb", res.getMethod())) {
|
|
||||||
esbApiParamService.handleApiEsbParams(res);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
res.setCaseType("apiCase");
|
||||||
|
res.setCaseTotal("0");
|
||||||
|
res.setCasePassingRate("-");
|
||||||
|
res.setCaseStatus("-");
|
||||||
}
|
}
|
||||||
|
if (StringUtils.equalsIgnoreCase("esb", res.getMethod())) {
|
||||||
|
esbApiParamService.handleApiEsbParams(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calculateResult(List<ApiDefinitionResult> resList, String projectId, ApiDefinitionRequest request) {
|
||||||
|
if (!resList.isEmpty()) {
|
||||||
|
List<String> ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList());
|
||||||
|
List<ApiComputeResult> results = new ArrayList<>();
|
||||||
|
if (request != null && request.getFilters().containsKey("status") && request.getFilters().get("status").get(0).equals("Trash")) {
|
||||||
|
results = extApiDefinitionMapper.selectByIdsAndStatusIsTrash(ids, projectId);
|
||||||
|
} else {
|
||||||
|
results = extApiDefinitionMapper.selectByIdsAndStatusIsNotTrash(ids, projectId);
|
||||||
|
}
|
||||||
|
calculateResultList(resList, results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,8 @@ public interface ExtApiDefinitionMapper {
|
||||||
|
|
||||||
List<ApiComputeResult> selectByIdsAndStatusIsNotTrash(@Param("ids") List<String> ids, @Param("projectId") String projectId);
|
List<ApiComputeResult> selectByIdsAndStatusIsNotTrash(@Param("ids") List<String> ids, @Param("projectId") String projectId);
|
||||||
|
|
||||||
|
List<ApiComputeResult> selectByIdsAndStatusIsTrash(@Param("ids") List<String> ids, @Param("projectId") String projectId);
|
||||||
|
|
||||||
// int removeToGc(@Param("ids") List<String> ids);
|
// int removeToGc(@Param("ids") List<String> ids);
|
||||||
|
|
||||||
int removeToGcByExample(ApiDefinitionExampleWithOperation example);
|
int removeToGcByExample(ApiDefinitionExampleWithOperation example);
|
||||||
|
|
|
@ -131,6 +131,20 @@
|
||||||
</foreach>
|
</foreach>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectByIdsAndStatusIsTrash" resultType="io.metersphere.api.dto.definition.ApiComputeResult">
|
||||||
|
SELECT t1.api_definition_id apiDefinitionId,count(t1.id) caseTotal,
|
||||||
|
SUM(case when t2.status ='success' then 1 else 0 end) as success ,SUM(case when t2.status ='error' then 1 else 0
|
||||||
|
end) as error,
|
||||||
|
CONCAT(FORMAT(SUM(IF (t2.`status`='success',1,0))/COUNT(t1.id)*100,2),'%') passRate
|
||||||
|
FROM api_test_case t1
|
||||||
|
LEFT JOIN api_definition_exec_result t2 ON t1.last_result_id=t2.id
|
||||||
|
WHERE t1.project_id = #{projectId} and t1.status = 'Trash'
|
||||||
|
group by t1.api_definition_id having t1.api_definition_id in
|
||||||
|
<foreach collection="ids" item="v" separator="," open="(" close=")">
|
||||||
|
#{v}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
|
||||||
<sql id="combine">
|
<sql id="combine">
|
||||||
<if test='${condition}.name != null and (${name} == null or ${name} == "")'>
|
<if test='${condition}.name != null and (${name} == null or ${name} == "")'>
|
||||||
and api_definition.name
|
and api_definition.name
|
||||||
|
|
Loading…
Reference in New Issue