refactor(接口定义): 接口执行历史保留
This commit is contained in:
parent
daaf8eb0d2
commit
ee82f669c3
|
@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
|
|||
import io.metersphere.api.jmeter.TestResult;
|
||||
import io.metersphere.base.domain.ApiDefinitionExecResult;
|
||||
import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -18,14 +17,9 @@ import java.util.UUID;
|
|||
public class ApiDefinitionExecResultService {
|
||||
@Resource
|
||||
private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper;
|
||||
@Resource
|
||||
private ExtApiDefinitionExecResultMapper extApiDefinitionExecResultMapper;
|
||||
|
||||
|
||||
public void saveApiResult(TestResult result) {
|
||||
result.getScenarios().get(0).getRequestResults().forEach(item -> {
|
||||
// 清理原始资源,每个执行 保留一条结果
|
||||
extApiDefinitionExecResultMapper.deleteByResourceId(item.getName());
|
||||
ApiDefinitionExecResult saveResult = new ApiDefinitionExecResult();
|
||||
saveResult.setId(UUID.randomUUID().toString());
|
||||
saveResult.setUserId(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
||||
|
|
|
@ -326,7 +326,7 @@ public class ApiDefinitionService {
|
|||
* @return
|
||||
*/
|
||||
public APIReportResult getDbResult(String testId) {
|
||||
ApiDefinitionExecResult result = extApiDefinitionExecResultMapper.selectByResourceId(testId);
|
||||
ApiDefinitionExecResult result = extApiDefinitionExecResultMapper.selectMaxResultByResourceId(testId);
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ public interface ExtApiDefinitionExecResultMapper {
|
|||
|
||||
void deleteByResourceId(String id);
|
||||
|
||||
ApiDefinitionExecResult selectByResourceId(String resourceId);
|
||||
|
||||
ApiDefinitionExecResult selectMaxResultByResourceId(String resourceId);
|
||||
|
||||
}
|
|
@ -5,8 +5,8 @@
|
|||
delete from api_definition_exec_result where resource_id = #{id,jdbcType=VARCHAR}
|
||||
</delete>
|
||||
|
||||
<select id="selectByResourceId" parameterType="java.lang.String" resultType="io.metersphere.base.domain.ApiDefinitionExecResult">
|
||||
<select id="selectMaxResultByResourceId" parameterType="java.lang.String" resultType="io.metersphere.base.domain.ApiDefinitionExecResult">
|
||||
select * from api_definition_exec_result
|
||||
where resource_id = #{resourceId,jdbcType=VARCHAR}
|
||||
where resource_id = #{resourceId,jdbcType=VARCHAR} ORDER BY update_time DESC LIMIT 1
|
||||
</select>
|
||||
</mapper>
|
|
@ -89,17 +89,29 @@
|
|||
|
||||
<select id="selectByIds" resultType="io.metersphere.api.dto.definition.ApiComputeResult">
|
||||
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
|
||||
from api_test_case t1 left join api_definition_exec_result t2 on t1.id = t2.resource_id
|
||||
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
|
||||
from api_test_case t1 left join (
|
||||
select
|
||||
a.status, a.id, a.resource_id
|
||||
from
|
||||
api_definition_exec_result a
|
||||
left join (
|
||||
select
|
||||
max(start_time) start_time , id, resource_id
|
||||
from
|
||||
api_definition_exec_result
|
||||
group by
|
||||
resource_id ) as b on a.id = b.id
|
||||
where
|
||||
a.start_time = b.start_time)as t2 on t1.id = t2.resource_id
|
||||
group by t1.api_definition_id having t1.api_definition_id in
|
||||
<foreach collection="ids" item="v" separator="," open="(" close=")">
|
||||
#{v}
|
||||
</foreach>
|
||||
order by t2.end_time desc;
|
||||
</select>
|
||||
|
||||
<sql id="combine">
|
||||
|
|
|
@ -146,15 +146,45 @@
|
|||
</sql>
|
||||
|
||||
<select id="list" resultType="io.metersphere.api.dto.definition.ApiTestCaseResult">
|
||||
select atc.id, atc.project_id,
|
||||
atc.name,atc.priority,atc.api_definition_id,T1.name as createUser ,T2.name as updateUser,
|
||||
atc.description,atc.request,atc.response,atc.create_user_id,
|
||||
atc.create_time,atc.update_user_id, atc.update_time,ader.status execResult
|
||||
from api_test_case atc left join user T1 on atc.create_user_id = T1.id left join user T2 on
|
||||
atc.update_user_id = T2.id left join api_definition_exec_result ader on atc.id = ader.resource_id
|
||||
select
|
||||
atc.id,
|
||||
atc.project_id,
|
||||
atc.name,
|
||||
atc.priority,
|
||||
atc.api_definition_id,
|
||||
u1.name as createUser ,
|
||||
u2.name as updateUser,
|
||||
atc.description,
|
||||
atc.request,
|
||||
atc.response,
|
||||
atc.create_user_id,
|
||||
atc.create_time,
|
||||
atc.update_user_id,
|
||||
atc.update_time,
|
||||
ader.status execResult
|
||||
from
|
||||
api_test_case atc
|
||||
left join user u1 on
|
||||
atc.create_user_id = u1.id
|
||||
left join user u2 on
|
||||
atc.update_user_id = u2.id
|
||||
left join (
|
||||
select
|
||||
a.status, a.id, a.resource_id
|
||||
from
|
||||
api_definition_exec_result a
|
||||
left join (
|
||||
select
|
||||
max(start_time) start_time , id, resource_id
|
||||
from
|
||||
api_definition_exec_result
|
||||
group by
|
||||
resource_id ) as b on a.id = b.id
|
||||
where
|
||||
a.start_time = b.start_time) as ader
|
||||
on atc.id = ader.resource_id
|
||||
<where>
|
||||
<if test="request.name != null and request.name!=''">
|
||||
|
||||
and atc.name like CONCAT('%', #{request.name},'%')
|
||||
</if>
|
||||
<if test="request.id != null and request.id!=''">
|
||||
|
|
Loading…
Reference in New Issue