fix(接口定义): 用例状态统计不准确问题修复

This commit is contained in:
fit2-zhao 2021-01-20 11:52:37 +08:00
parent 0f8cefffb3
commit 67635aebbd
5 changed files with 23 additions and 11 deletions

View File

@ -7,7 +7,9 @@ import lombok.Setter;
@Setter @Setter
public class ApiComputeResult { public class ApiComputeResult {
private String apiDefinitionId; private String apiDefinitionId;
private String caseTotal; private int caseTotal;
private String status; private String status;
private String passRate; private String passRate;
private int success;
private int error;
} }

View File

@ -79,7 +79,7 @@ public class ApiDefinitionService {
private static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; private static final String BODY_FILE_DIR = "/opt/metersphere/data/body";
public List<ApiDefinitionResult> list(ApiDefinitionRequest request) { public List<ApiDefinitionResult> list(ApiDefinitionRequest request) {
request = this.initRequest(request,true,true); request = this.initRequest(request, true, true);
List<ApiDefinitionResult> resList = extApiDefinitionMapper.list(request); List<ApiDefinitionResult> resList = extApiDefinitionMapper.list(request);
calculateResult(resList); calculateResult(resList);
return resList; return resList;
@ -87,16 +87,17 @@ public class ApiDefinitionService {
/** /**
* 初始化部分参数 * 初始化部分参数
*
* @param request * @param request
* @param setDefultOrders * @param setDefultOrders
* @param checkThisWeekData * @param checkThisWeekData
* @return * @return
*/ */
private ApiDefinitionRequest initRequest(ApiDefinitionRequest request,boolean setDefultOrders, boolean checkThisWeekData) { private ApiDefinitionRequest initRequest(ApiDefinitionRequest request, boolean setDefultOrders, boolean checkThisWeekData) {
if(setDefultOrders){ if (setDefultOrders) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
} }
if(checkThisWeekData){ if (checkThisWeekData) {
if (request.isSelectThisWeedData()) { if (request.isSelectThisWeedData()) {
Map<String, Date> weekFirstTimeAndLastTime = DateUtils.getWeedFirstTimeAndLastTime(new Date()); Map<String, Date> weekFirstTimeAndLastTime = DateUtils.getWeedFirstTimeAndLastTime(new Date());
Date weekFirstTime = weekFirstTimeAndLastTime.get("firstTime"); Date weekFirstTime = weekFirstTimeAndLastTime.get("firstTime");
@ -568,9 +569,16 @@ public class ApiDefinitionService {
for (ApiDefinitionResult res : resList) { for (ApiDefinitionResult res : resList) {
ApiComputeResult compRes = resultMap.get(res.getId()); ApiComputeResult compRes = resultMap.get(res.getId());
if (compRes != null) { if (compRes != null) {
res.setCaseTotal(compRes.getCaseTotal()); res.setCaseTotal(String.valueOf(compRes.getCaseTotal()));
res.setCasePassingRate(compRes.getPassRate()); res.setCasePassingRate(compRes.getPassRate());
res.setCaseStatus(compRes.getStatus()); // 状态优先级 未执行未通过通过
if ((compRes.getError() + compRes.getSuccess()) < compRes.getCaseTotal()) {
res.setCaseStatus("未执行");
} else if (compRes.getError() > 0) {
res.setCaseStatus("未通过");
} else {
res.setCaseStatus("通过");
}
} else { } else {
res.setCaseTotal("-"); res.setCaseTotal("-");
res.setCasePassingRate("-"); res.setCasePassingRate("-");

View File

@ -89,10 +89,11 @@
<select id="selectByIds" resultType="io.metersphere.api.dto.definition.ApiComputeResult"> <select id="selectByIds" resultType="io.metersphere.api.dto.definition.ApiComputeResult">
SELECT t1.api_definition_id apiDefinitionId,count(t1.id) caseTotal, SELECT t1.api_definition_id apiDefinitionId,count(t1.id) caseTotal,
CASE t2.STATUS WHEN 'success' THEN '通过' WHEN 'error' THEN '未通过' ELSE '未执行' END AS STATUS,CONCAT(FORMAT(SUM(IF (t2.`status`='success',1,0))/COUNT(t1.id)*100,2),'%') passRate 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 FROM api_test_case t1
LEFT JOIN api_definition_exec_result t2 ON t1.last_result_id=t2.id LEFT JOIN api_definition_exec_result t2 ON t1.last_result_id=t2.id
group by t1.api_definition_id having t1.api_definition_id in group by t1.api_definition_id having t1.api_definition_id in
<foreach collection="ids" item="v" separator="," open="(" close=")"> <foreach collection="ids" item="v" separator="," open="(" close=")">
#{v} #{v}
</foreach> </foreach>

View File

@ -233,6 +233,7 @@
row.updateTime = data.updateTime; row.updateTime = data.updateTime;
if (!row.message) { if (!row.message) {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
this.$emit('refresh');
} }
}); });
}, },

View File

@ -159,7 +159,7 @@
}) })
} }
this.$success(this.$t('schedule.event_success')); this.$success(this.$t('schedule.event_success'));
this.getApiTest(); this.refresh();
}, },
refresh() { refresh() {