feat (接口自动化): 报告增加结束时间 #1002620

--story=1002620 --user=赵勇 【github#5383】[FEAT... https://www.tapd.cn/55049933/s/1036970
This commit is contained in:
fit2-zhao 2021-08-19 18:59:51 +08:00 committed by fit2-zhao
parent 4453b0018a
commit 8ea0f731dd
7 changed files with 110 additions and 16 deletions

View File

@ -143,7 +143,7 @@ public class ApiScenarioReportService {
if (report != null) {
report.setId(report.getId());
report.setName(report.getScenarioName() + "-" + DateUtils.getTimeStr(System.currentTimeMillis()));
report.setCreateTime(startTime);
report.setEndTime(System.currentTimeMillis());
report.setUpdateTime(startTime);
String status = test.getError() == 0 ? "Success" : "Error";
report.setStatus(status);
@ -165,7 +165,7 @@ public class ApiScenarioReportService {
report.setScenarioId(test.getScenarioId());
report.setTriggerMode(test.getTriggerMode());
report.setDescription(test.getDescription());
report.setCreateTime(System.currentTimeMillis());
report.setEndTime(System.currentTimeMillis());
report.setUpdateTime(System.currentTimeMillis());
report.setStatus(test.getStatus());
report.setUserId(test.getUserId());
@ -235,6 +235,7 @@ public class ApiScenarioReportService {
if (StringUtils.isNotEmpty(report.getTriggerMode()) && report.getTriggerMode().equals("CASE")) {
report.setTriggerMode(TriggerMode.MANUAL.name());
}
report.setEndTime(System.currentTimeMillis());
apiScenarioReportMapper.updateByPrimaryKeySelective(report);
if (scenarioResult.getError() > 0) {
testPlanApiScenario.setLastResult(ScenarioStatus.Fail.name());
@ -244,8 +245,9 @@ public class ApiScenarioReportService {
String passRate = new DecimalFormat("0%").format((float) scenarioResult.getSuccess() / (scenarioResult.getSuccess() + scenarioResult.getError()));
testPlanApiScenario.setPassRate(passRate);
testPlanApiScenario.setReportId(report.getId());
testPlanApiScenario.setUpdateTime(report.getCreateTime());
report.setTestPlanScenarioId(testPlanApiScenario.getId());
report.setEndTime(System.currentTimeMillis());
testPlanApiScenario.setUpdateTime(report.getCreateTime());
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
// 更新场景状态
@ -259,10 +261,10 @@ public class ApiScenarioReportService {
scenario.setPassRate(passRate);
scenario.setReportId(report.getId());
int executeTimes = 0;
if(scenario.getExecuteTimes() != null){
if (scenario.getExecuteTimes() != null) {
executeTimes = scenario.getExecuteTimes().intValue();
}
scenario.setExecuteTimes(executeTimes+1);
scenario.setExecuteTimes(executeTimes + 1);
apiScenarioMapper.updateByPrimaryKey(scenario);
}
@ -319,6 +321,7 @@ public class ApiScenarioReportService {
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(planScenarioId);
report.setScenarioId(testPlanApiScenario.getApiScenarioId());
report.setTestPlanScenarioId(planScenarioId);
report.setEndTime(System.currentTimeMillis());
apiScenarioReportMapper.updateByPrimaryKeySelective(report);
@ -343,6 +346,7 @@ public class ApiScenarioReportService {
apiScenarioReportDetailMapper.insert(detail);
testPlanApiScenario.setReportId(report.getId());
report.setEndTime(System.currentTimeMillis());
testPlanApiScenario.setUpdateTime(System.currentTimeMillis());
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
scenarioIdList.add(testPlanApiScenario.getApiScenarioId());
@ -359,10 +363,10 @@ public class ApiScenarioReportService {
scenario.setPassRate(passRate);
scenario.setReportId(report.getId());
int executeTimes = 0;
if(scenario.getExecuteTimes() != null){
if (scenario.getExecuteTimes() != null) {
executeTimes = scenario.getExecuteTimes().intValue();
}
scenario.setExecuteTimes(executeTimes+1);
scenario.setExecuteTimes(executeTimes + 1);
apiScenarioMapper.updateByPrimaryKey(scenario);
}
@ -403,6 +407,7 @@ public class ApiScenarioReportService {
if (CollectionUtils.isNotEmpty(reportList)) {
reportList.forEach(report -> {
report.setUpdateTime(System.currentTimeMillis());
report.setEndTime(System.currentTimeMillis());
String status = "Error";
report.setStatus(status);
scenarioReportMapper.updateByPrimaryKeySelective(report);
@ -464,6 +469,7 @@ public class ApiScenarioReportService {
if (StringUtils.isNotEmpty(report.getTriggerMode()) && report.getTriggerMode().equals("CASE")) {
report.setTriggerMode(TriggerMode.MANUAL.name());
}
report.setEndTime(System.currentTimeMillis());
apiScenarioReportMapper.updateByPrimaryKey(report);
ApiScenarioReportDetail detail = new ApiScenarioReportDetail();
@ -557,10 +563,10 @@ public class ApiScenarioReportService {
scenario.setPassRate(passRate);
scenario.setReportId(report.getId());
int executeTimes = 0;
if(scenario.getExecuteTimes() != null){
if (scenario.getExecuteTimes() != null) {
executeTimes = scenario.getExecuteTimes().intValue();
}
scenario.setExecuteTimes(executeTimes+1);
scenario.setExecuteTimes(executeTimes + 1);
apiScenarioMapper.updateByPrimaryKey(scenario);
}

View File

@ -1,8 +1,9 @@
package io.metersphere.base.domain;
import java.io.Serializable;
import lombok.Data;
import java.io.Serializable;
@Data
public class ApiScenarioReport implements Serializable {
private String id;
@ -35,5 +36,7 @@ public class ApiScenarioReport implements Serializable {
private String testPlanScenarioId;
private Long endTime;
private static final long serialVersionUID = 1L;
}

View File

@ -993,6 +993,66 @@ public class ApiScenarioReportExample {
addCriterion("actuator not between", value1, value2, "actuator");
return (Criteria) this;
}
public Criteria andEndTimeIsNull() {
addCriterion("end_time is null");
return (Criteria) this;
}
public Criteria andEndTimeIsNotNull() {
addCriterion("end_time is not null");
return (Criteria) this;
}
public Criteria andEndTimeEqualTo(Long value) {
addCriterion("end_time =", value, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeNotEqualTo(Long value) {
addCriterion("end_time <>", value, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeGreaterThan(Long value) {
addCriterion("end_time >", value, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeGreaterThanOrEqualTo(Long value) {
addCriterion("end_time >=", value, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeLessThan(Long value) {
addCriterion("end_time <", value, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeLessThanOrEqualTo(Long value) {
addCriterion("end_time <=", value, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeIn(List<Long> values) {
addCriterion("end_time in", values, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeNotIn(List<Long> values) {
addCriterion("end_time not in", values, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeBetween(Long value1, Long value2) {
addCriterion("end_time between", value1, value2, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeNotBetween(Long value1, Long value2) {
addCriterion("end_time not between", value1, value2, "endTime");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -15,6 +15,7 @@
<result column="scenario_id" jdbcType="VARCHAR" property="scenarioId" />
<result column="create_user" jdbcType="VARCHAR" property="createUser" />
<result column="actuator" jdbcType="VARCHAR" property="actuator" />
<result column="end_time" jdbcType="BIGINT" property="endTime" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.ApiScenarioReport">
<result column="description" jdbcType="LONGVARCHAR" property="description" />
@ -79,7 +80,7 @@
</sql>
<sql id="Base_Column_List">
id, project_id, `name`, create_time, update_time, `status`, user_id, trigger_mode,
execute_type, scenario_name, scenario_id, create_user, actuator
execute_type, scenario_name, scenario_id, create_user, actuator, end_time
</sql>
<sql id="Blob_Column_List">
description
@ -137,12 +138,14 @@
create_time, update_time, `status`,
user_id, trigger_mode, execute_type,
scenario_name, scenario_id, create_user,
actuator, description)
actuator, end_time, description
)
values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{status,jdbcType=VARCHAR},
#{userId,jdbcType=VARCHAR}, #{triggerMode,jdbcType=VARCHAR}, #{executeType,jdbcType=VARCHAR},
#{scenarioName,jdbcType=VARCHAR}, #{scenarioId,jdbcType=VARCHAR}, #{createUser,jdbcType=VARCHAR},
#{actuator,jdbcType=VARCHAR}, #{description,jdbcType=LONGVARCHAR})
#{actuator,jdbcType=VARCHAR}, #{endTime,jdbcType=BIGINT}, #{description,jdbcType=LONGVARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.ApiScenarioReport">
insert into api_scenario_report
@ -186,6 +189,9 @@
<if test="actuator != null">
actuator,
</if>
<if test="endTime != null">
end_time,
</if>
<if test="description != null">
description,
</if>
@ -230,6 +236,9 @@
<if test="actuator != null">
#{actuator,jdbcType=VARCHAR},
</if>
<if test="endTime != null">
#{endTime,jdbcType=BIGINT},
</if>
<if test="description != null">
#{description,jdbcType=LONGVARCHAR},
</if>
@ -283,6 +292,9 @@
<if test="record.actuator != null">
actuator = #{record.actuator,jdbcType=VARCHAR},
</if>
<if test="record.endTime != null">
end_time = #{record.endTime,jdbcType=BIGINT},
</if>
<if test="record.description != null">
description = #{record.description,jdbcType=LONGVARCHAR},
</if>
@ -306,6 +318,7 @@
scenario_id = #{record.scenarioId,jdbcType=VARCHAR},
create_user = #{record.createUser,jdbcType=VARCHAR},
actuator = #{record.actuator,jdbcType=VARCHAR},
end_time = #{record.endTime,jdbcType=BIGINT},
description = #{record.description,jdbcType=LONGVARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -325,7 +338,8 @@
scenario_name = #{record.scenarioName,jdbcType=VARCHAR},
scenario_id = #{record.scenarioId,jdbcType=VARCHAR},
create_user = #{record.createUser,jdbcType=VARCHAR},
actuator = #{record.actuator,jdbcType=VARCHAR}
actuator = #{record.actuator,jdbcType=VARCHAR},
end_time = #{record.endTime,jdbcType=BIGINT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -369,6 +383,9 @@
<if test="actuator != null">
actuator = #{actuator,jdbcType=VARCHAR},
</if>
<if test="endTime != null">
end_time = #{endTime,jdbcType=BIGINT},
</if>
<if test="description != null">
description = #{description,jdbcType=LONGVARCHAR},
</if>
@ -389,6 +406,7 @@
scenario_id = #{scenarioId,jdbcType=VARCHAR},
create_user = #{createUser,jdbcType=VARCHAR},
actuator = #{actuator,jdbcType=VARCHAR},
end_time = #{endTime,jdbcType=BIGINT},
description = #{description,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
@ -405,7 +423,8 @@
scenario_name = #{scenarioName,jdbcType=VARCHAR},
scenario_id = #{scenarioId,jdbcType=VARCHAR},
create_user = #{createUser,jdbcType=VARCHAR},
actuator = #{actuator,jdbcType=VARCHAR}
actuator = #{actuator,jdbcType=VARCHAR},
end_time = #{endTime,jdbcType=BIGINT}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -99,7 +99,7 @@
</sql>
<select id="list" resultMap="BaseResultMap">
SELECT r.name AS test_name,
SELECT r.name AS test_name,r.end_time,
r.name, r.description, r.id, r.project_id, r.create_time, r.update_time, r.status, r.trigger_mode,IfNULL(s.name,r.scenario_name) as scenario_name,
project.name AS project_name, user.name AS user_name
FROM api_scenario_report r

View File

@ -87,3 +87,4 @@ ALTER TABLE `project`
ALTER TABLE `api_scenario`
ADD `execute_times` int(11) NULL;
ALTER TABLE `api_scenario_report` ADD `end_time` bigint(13) ;

View File

@ -42,6 +42,11 @@
<span>{{ scope.row.createTime | timestampFormatDate }}</span>
</template>
</el-table-column>
<el-table-column prop="endTime" width="250" :label="$t('report.test_end_time')" sortable>
<template v-slot:default="scope">
<span>{{ scope.row.endTime | timestampFormatDate }}</span>
</template>
</el-table-column>
<el-table-column prop="triggerMode" width="150" :label="$t('commons.trigger_mode.name')"
column-key="triggerMode" :filters="triggerFilters">
<template v-slot:default="scope">