refactor(接口定义): 重构用例存储及结果统计
This commit is contained in:
parent
ea7090b3eb
commit
49698e59af
|
@ -5,8 +5,10 @@ import io.metersphere.api.dto.datacount.ExecutedCaseInfoResult;
|
|||
import io.metersphere.api.jmeter.TestResult;
|
||||
import io.metersphere.base.domain.ApiDefinitionExecResult;
|
||||
import io.metersphere.base.domain.ApiDefinitionExecResultExample;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.base.domain.TestPlanApiCase;
|
||||
import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
|
||||
import io.metersphere.base.mapper.ApiTestCaseMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.utils.DateUtils;
|
||||
|
@ -37,6 +39,9 @@ public class ApiDefinitionExecResultService {
|
|||
private TestPlanApiCaseService testPlanApiCaseService;
|
||||
@Resource
|
||||
private TestPlanService testPlanService;
|
||||
@Resource
|
||||
private ApiTestCaseMapper apiTestCaseMapper;
|
||||
|
||||
@Resource
|
||||
SqlSessionFactory sqlSessionFactory;
|
||||
|
||||
|
@ -60,6 +65,12 @@ public class ApiDefinitionExecResultService {
|
|||
if (StringUtils.equals(type, ApiRunMode.API_PLAN.name())) {
|
||||
testPlanApiCaseService.setExecResult(item.getName(), status);
|
||||
}
|
||||
// 更新用例最后执行结果
|
||||
ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = new ApiTestCaseWithBLOBs();
|
||||
apiTestCaseWithBLOBs.setId(saveResult.getResourceId());
|
||||
apiTestCaseWithBLOBs.setLastResultId(saveResult.getId());
|
||||
|
||||
apiTestCaseMapper.updateByPrimaryKeySelective(apiTestCaseWithBLOBs);
|
||||
definitionExecResultMapper.insert(saveResult);
|
||||
});
|
||||
sqlSession.flushStatements();
|
||||
|
|
|
@ -189,38 +189,18 @@
|
|||
|
||||
</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,
|
||||
u1.name as createUser ,
|
||||
u2.name as updateUser,
|
||||
atc.description,
|
||||
atc.request,
|
||||
atc.create_user_id,
|
||||
atc.create_time,
|
||||
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
|
||||
SELECT
|
||||
t1.*,
|
||||
t2.STATUS AS execResult,
|
||||
t2.create_time AS execTime,
|
||||
u2.NAME AS createUser,
|
||||
u1.NAME AS updateUser
|
||||
FROM
|
||||
api_test_case t1
|
||||
LEFT JOIN api_definition_exec_result t2 ON t1.last_result_id = t2.id
|
||||
LEFT JOIN USER u1 ON t1.update_user_id = u1.id
|
||||
LEFT JOIN USER u2 ON t1.create_user_id = u2.id
|
||||
LEFT JOIN USER u3 ON t2.user_id = u3.id
|
||||
<where>
|
||||
<if test="request.combine != null">
|
||||
<include refid="combine">
|
||||
|
@ -230,26 +210,26 @@
|
|||
</if>
|
||||
|
||||
<if test="request.name != null and request.name!=''">
|
||||
and atc.name like CONCAT('%', #{request.name},'%')
|
||||
and t1.name like CONCAT('%', #{request.name},'%')
|
||||
</if>
|
||||
<if test="request.id != null and request.id!=''">
|
||||
AND atc.id = #{request.id}
|
||||
AND t1.id = #{request.id}
|
||||
</if>
|
||||
<if test="request.priority != null and request.priority!=''">
|
||||
AND atc.priority = #{request.priority}
|
||||
AND t1.priority = #{request.priority}
|
||||
</if>
|
||||
<if test="request.projectId != null and request.projectId!=''">
|
||||
AND atc.project_id = #{request.projectId}
|
||||
AND t1.project_id = #{request.projectId}
|
||||
</if>
|
||||
<if test="request.apiDefinitionId != null and request.apiDefinitionId!=''">
|
||||
AND atc.api_definition_id = #{request.apiDefinitionId}
|
||||
AND t1.api_definition_id = #{request.apiDefinitionId}
|
||||
</if>
|
||||
</where>
|
||||
|
||||
<if test="request.orders != null and request.orders.size() > 0">
|
||||
order by
|
||||
<foreach collection="request.orders" separator="," item="order">
|
||||
atc.${order.name} ${order.type}
|
||||
t1.${order.name} ${order.type}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
|
|
|
@ -1,2 +1,27 @@
|
|||
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;
|
Loading…
Reference in New Issue