fix(接口测试): 修复接口列表不显示用例状态的缺陷
【【接口测试】github#27157,接口测试,接口定义列表,用例状态没有同步】https://www.tapd.cn/55049933/bugtrace/bugs/view?bug_id=1155049933001032207
This commit is contained in:
parent
9cce9f93fc
commit
9ac29aed43
|
@ -24,6 +24,8 @@ public interface ExtApiDefinitionMapper {
|
|||
|
||||
List<ApiComputeResult> countByApiIdAndStatusIsNotTrash(@Param("ids") List<String> ids, @Param("projectId") String projectId);
|
||||
|
||||
List<ApiComputeResult> selectByIdsAndStatusIsNotTrash(@Param("ids") List<String> ids, @Param("projectId") String projectId);
|
||||
|
||||
int removeToGcByExample(ApiDefinitionExampleWithOperation example);
|
||||
|
||||
int reduction(@Param("ids") List<String> ids);
|
||||
|
|
|
@ -117,6 +117,21 @@
|
|||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="selectByIdsAndStatusIsNotTrash" 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 in
|
||||
('ERROR','FAKE_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 is null or 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>
|
||||
|
||||
<select id="countByApiIdAndStatusIsNotTrash" resultType="io.metersphere.api.dto.definition.ApiComputeResult">
|
||||
SELECT t1.api_definition_id apiDefinitionId,count(t1.id) caseTotal
|
||||
FROM api_test_case t1
|
||||
|
|
|
@ -99,6 +99,7 @@ public class ApiDefinitionService {
|
|||
public static final String JSONSCHEMA = "jsonSchema";
|
||||
private static final String COPY = "Copy";
|
||||
private static final String SCHEDULE = "schedule";
|
||||
private static final String API_CASE = "apiCase";
|
||||
@Resource
|
||||
private ExtApiDefinitionMapper extApiDefinitionMapper;
|
||||
@Resource
|
||||
|
@ -190,7 +191,7 @@ public class ApiDefinitionService {
|
|||
buildUserInfo(resList);
|
||||
if (StringUtils.isNotBlank(request.getProjectId())) {
|
||||
buildProjectInfo(resList, request.getProjectId());
|
||||
calculateResult(resList, request.getProjectId());
|
||||
calculateApiResult(resList, request.getProjectId());
|
||||
} else {
|
||||
buildProjectInfoWithoutProject(resList);
|
||||
}
|
||||
|
@ -198,6 +199,35 @@ public class ApiDefinitionService {
|
|||
return resList;
|
||||
}
|
||||
|
||||
public void calculateApiResult(List<ApiDefinitionResult> resList, String projectId) {
|
||||
if (!resList.isEmpty()) {
|
||||
List<String> ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList());
|
||||
List<ApiComputeResult> results = extApiDefinitionMapper.selectByIdsAndStatusIsNotTrash(ids, projectId);
|
||||
Map<String, ApiComputeResult> resultMap = results.stream().collect(Collectors.toMap(ApiComputeResult::getApiDefinitionId, Function.identity()));
|
||||
for (ApiDefinitionResult res : resList) {
|
||||
ApiComputeResult compRes = resultMap.get(res.getId());
|
||||
if (compRes != null) {
|
||||
res.setCaseType(API_CASE);
|
||||
res.setCaseTotal(String.valueOf(compRes.getCaseTotal()));
|
||||
res.setCasePassingRate(compRes.getPassRate());
|
||||
// 状态优先级 未执行,未通过,通过
|
||||
if ((compRes.getError() + compRes.getSuccess()) < compRes.getCaseTotal()) {
|
||||
res.setCaseStatus(ApiReportStatus.PENDING.name());
|
||||
} else if (compRes.getError() > 0) {
|
||||
res.setCaseStatus(ApiReportStatus.ERROR.name());
|
||||
} else {
|
||||
res.setCaseStatus(ApiReportStatus.SUCCESS.name());
|
||||
}
|
||||
} else {
|
||||
res.setCaseType(API_CASE);
|
||||
res.setCaseTotal("0");
|
||||
res.setCasePassingRate("-");
|
||||
res.setCaseStatus("-");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setCustomFieldsOrder(ApiDefinitionRequest request) {
|
||||
if (request.getCombine() != null && !request.getCombine().isEmpty()) {
|
||||
request.setIsCustomSorted(true);
|
||||
|
@ -1380,10 +1410,10 @@ public class ApiDefinitionService {
|
|||
for (ApiDefinitionResult res : resList) {
|
||||
ApiComputeResult compRes = resultMap.get(res.getId());
|
||||
if (compRes != null) {
|
||||
res.setCaseType("apiCase");
|
||||
res.setCaseType(API_CASE);
|
||||
res.setCaseTotal(String.valueOf(compRes.getCaseTotal()));
|
||||
} else {
|
||||
res.setCaseType("apiCase");
|
||||
res.setCaseType(API_CASE);
|
||||
res.setCaseTotal("0");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue