refactor(接口定义): 重构用例存储及结果统计

This commit is contained in:
fit2-zhao 2021-01-20 11:00:11 +08:00
parent ea7090b3eb
commit 49698e59af
3 changed files with 55 additions and 39 deletions

View File

@ -5,8 +5,10 @@ import io.metersphere.api.dto.datacount.ExecutedCaseInfoResult;
import io.metersphere.api.jmeter.TestResult; import io.metersphere.api.jmeter.TestResult;
import io.metersphere.base.domain.ApiDefinitionExecResult; import io.metersphere.base.domain.ApiDefinitionExecResult;
import io.metersphere.base.domain.ApiDefinitionExecResultExample; import io.metersphere.base.domain.ApiDefinitionExecResultExample;
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
import io.metersphere.base.domain.TestPlanApiCase; import io.metersphere.base.domain.TestPlanApiCase;
import io.metersphere.base.mapper.ApiDefinitionExecResultMapper; import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
import io.metersphere.base.mapper.ApiTestCaseMapper;
import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.constants.ApiRunMode;
import io.metersphere.commons.utils.DateUtils; import io.metersphere.commons.utils.DateUtils;
@ -37,6 +39,9 @@ public class ApiDefinitionExecResultService {
private TestPlanApiCaseService testPlanApiCaseService; private TestPlanApiCaseService testPlanApiCaseService;
@Resource @Resource
private TestPlanService testPlanService; private TestPlanService testPlanService;
@Resource
private ApiTestCaseMapper apiTestCaseMapper;
@Resource @Resource
SqlSessionFactory sqlSessionFactory; SqlSessionFactory sqlSessionFactory;
@ -60,6 +65,12 @@ public class ApiDefinitionExecResultService {
if (StringUtils.equals(type, ApiRunMode.API_PLAN.name())) { if (StringUtils.equals(type, ApiRunMode.API_PLAN.name())) {
testPlanApiCaseService.setExecResult(item.getName(), status); testPlanApiCaseService.setExecResult(item.getName(), status);
} }
// 更新用例最后执行结果
ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = new ApiTestCaseWithBLOBs();
apiTestCaseWithBLOBs.setId(saveResult.getResourceId());
apiTestCaseWithBLOBs.setLastResultId(saveResult.getId());
apiTestCaseMapper.updateByPrimaryKeySelective(apiTestCaseWithBLOBs);
definitionExecResultMapper.insert(saveResult); definitionExecResultMapper.insert(saveResult);
}); });
sqlSession.flushStatements(); sqlSession.flushStatements();

View File

@ -189,38 +189,18 @@
</sql> </sql>
<select id="list" resultType="io.metersphere.api.dto.definition.ApiTestCaseResult"> <select id="list" resultType="io.metersphere.api.dto.definition.ApiTestCaseResult">
select SELECT
atc.id, t1.*,
atc.project_id, t2.STATUS AS execResult,
atc.name, t2.create_time AS execTime,
atc.priority, u2.NAME AS createUser,
atc.api_definition_id, u1.NAME AS updateUser
u1.name as createUser , FROM
u2.name as updateUser, api_test_case t1
atc.description, LEFT JOIN api_definition_exec_result t2 ON t1.last_result_id = t2.id
atc.request, LEFT JOIN USER u1 ON t1.update_user_id = u1.id
atc.create_user_id, LEFT JOIN USER u2 ON t1.create_user_id = u2.id
atc.create_time, LEFT JOIN USER u3 ON t2.user_id = u3.id
atc.update_user_id,
atc.update_time,
atc.num,
atc.tags,
ader.status execResult,
ader.create_time execTime
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
max(create_time) create_time ,status ,id, resource_id
from
api_definition_exec_result
group by
resource_id) as ader
on atc.id = ader.resource_id
<where> <where>
<if test="request.combine != null"> <if test="request.combine != null">
<include refid="combine"> <include refid="combine">
@ -230,26 +210,26 @@
</if> </if>
<if test="request.name != null and request.name!=''"> <if test="request.name != null and request.name!=''">
and atc.name like CONCAT('%', #{request.name},'%') and t1.name like CONCAT('%', #{request.name},'%')
</if> </if>
<if test="request.id != null and request.id!=''"> <if test="request.id != null and request.id!=''">
AND atc.id = #{request.id} AND t1.id = #{request.id}
</if> </if>
<if test="request.priority != null and request.priority!=''"> <if test="request.priority != null and request.priority!=''">
AND atc.priority = #{request.priority} AND t1.priority = #{request.priority}
</if> </if>
<if test="request.projectId != null and request.projectId!=''"> <if test="request.projectId != null and request.projectId!=''">
AND atc.project_id = #{request.projectId} AND t1.project_id = #{request.projectId}
</if> </if>
<if test="request.apiDefinitionId != null and request.apiDefinitionId!=''"> <if test="request.apiDefinitionId != null and request.apiDefinitionId!=''">
AND atc.api_definition_id = #{request.apiDefinitionId} AND t1.api_definition_id = #{request.apiDefinitionId}
</if> </if>
</where> </where>
<if test="request.orders != null and request.orders.size() > 0"> <if test="request.orders != null and request.orders.size() > 0">
order by order by
<foreach collection="request.orders" separator="," item="order"> <foreach collection="request.orders" separator="," item="order">
atc.${order.name} ${order.type} t1.${order.name} ${order.type}
</foreach> </foreach>
</if> </if>

View File

@ -1,2 +1,27 @@
ALTER TABLE api_test_case drop COLUMN response; ALTER TABLE api_test_case drop COLUMN response;
ALTER TABLE api_test_case add COLUMN last_result_id varchar(64) COMMENT 'Last ApiDefinitionExecResult ID'; ALTER TABLE api_test_case add COLUMN last_result_id varchar(64) COMMENT 'Last ApiDefinitionExecResult ID';
UPDATE api_test_case tt
INNER JOIN (
SELECT
atc.id,
ader.id AS result_id
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
max( create_time ) create_time,
STATUS,
id,
resource_id
FROM
api_definition_exec_result
GROUP BY
resource_id
) AS ader ON atc.id = ader.resource_id
) tc
SET tt.last_result_id = tc.result_id
WHERE
tt.id = tc.id;