refactor(接口定义): 重构列表查询sql 加速查询

This commit is contained in:
fit2-zhao 2021-01-20 11:16:22 +08:00
parent 49698e59af
commit 6d78a2ade9
1 changed files with 22 additions and 34 deletions

View File

@ -82,28 +82,16 @@
</sql>
<sql id="Base_Column_List">
id, project_id, name,module_id,module_path,protocol ,path,method ,description, status, user_id, create_time, update_time
</sql>
</sql>
<sql id="Blob_Column_List">
request
</sql>
request
</sql>
<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 (
select
max(create_time) create_time ,status ,id, resource_id
from
api_definition_exec_result
group by
resource_id
)as t2
on t1.id = t2.resource_id
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.last_result_id=t2.id
group by t1.api_definition_id having t1.api_definition_id in
<foreach collection="ids" item="v" separator="," open="(" close=")">
#{v}
@ -301,12 +289,12 @@
<if test="request.orders != null and request.orders.size() > 0">
order by
<foreach collection="request.orders" separator="," item="order">
<if test="order.name == 'user_name'">
user_name ${order.type}
</if>
<if test="order.name != 'user_name'">
api_definition.${order.name} ${order.type}
</if>
<if test="order.name == 'user_name'">
user_name ${order.type}
</if>
<if test="order.name != 'user_name'">
api_definition.${order.name} ${order.type}
</if>
</foreach>
</if>
</select>
@ -413,15 +401,15 @@
</foreach>
</if>
and exists (
select id
from api_test_case c
where c.api_definition_id = api_definition.id
and not exists (
select id
from test_plan_api_case t
where t.api_case_id = c.id
and t.test_plan_id = #{request.planId}
)
select id
from api_test_case c
where c.api_definition_id = api_definition.id
and not exists (
select id
from test_plan_api_case t
where t.api_case_id = c.id
and t.test_plan_id = #{request.planId}
)
)
</where>
<if test="request.orders != null and request.orders.size() > 0">