修改保存metric

This commit is contained in:
Captain.B 2020-05-20 18:55:51 +08:00
parent dc2a1202ae
commit b5df16df7c
12 changed files with 204 additions and 155 deletions

View File

@ -18,5 +18,7 @@ public class LoadTestReport implements Serializable {
private String status;
private String description;
private static final long serialVersionUID = 1L;
}

View File

@ -1,13 +1,15 @@
package io.metersphere.base.domain;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.io.Serializable;
@Data
public class LoadTestReportDetail implements Serializable {
private String reportId;
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class LoadTestReportDetail extends LoadTestReportDetailKey implements Serializable {
private String content;
private static final long serialVersionUID = 1L;

View File

@ -173,6 +173,66 @@ public class LoadTestReportDetailExample {
addCriterion("report_id not between", value1, value2, "reportId");
return (Criteria) this;
}
public Criteria andPartIsNull() {
addCriterion("part is null");
return (Criteria) this;
}
public Criteria andPartIsNotNull() {
addCriterion("part is not null");
return (Criteria) this;
}
public Criteria andPartEqualTo(Long value) {
addCriterion("part =", value, "part");
return (Criteria) this;
}
public Criteria andPartNotEqualTo(Long value) {
addCriterion("part <>", value, "part");
return (Criteria) this;
}
public Criteria andPartGreaterThan(Long value) {
addCriterion("part >", value, "part");
return (Criteria) this;
}
public Criteria andPartGreaterThanOrEqualTo(Long value) {
addCriterion("part >=", value, "part");
return (Criteria) this;
}
public Criteria andPartLessThan(Long value) {
addCriterion("part <", value, "part");
return (Criteria) this;
}
public Criteria andPartLessThanOrEqualTo(Long value) {
addCriterion("part <=", value, "part");
return (Criteria) this;
}
public Criteria andPartIn(List<Long> values) {
addCriterion("part in", values, "part");
return (Criteria) this;
}
public Criteria andPartNotIn(List<Long> values) {
addCriterion("part not in", values, "part");
return (Criteria) this;
}
public Criteria andPartBetween(Long value1, Long value2) {
addCriterion("part between", value1, value2, "part");
return (Criteria) this;
}
public Criteria andPartNotBetween(Long value1, Long value2) {
addCriterion("part not between", value1, value2, "part");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -1,18 +0,0 @@
package io.metersphere.base.domain;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.io.Serializable;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class LoadTestReportWithBLOBs extends LoadTestReport implements Serializable {
private String description;
private String content;
private static final long serialVersionUID = 1L;
}

View File

@ -2,6 +2,7 @@ package io.metersphere.base.mapper;
import io.metersphere.base.domain.LoadTestReportDetail;
import io.metersphere.base.domain.LoadTestReportDetailExample;
import io.metersphere.base.domain.LoadTestReportDetailKey;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -11,7 +12,7 @@ public interface LoadTestReportDetailMapper {
int deleteByExample(LoadTestReportDetailExample example);
int deleteByPrimaryKey(String reportId);
int deleteByPrimaryKey(LoadTestReportDetailKey key);
int insert(LoadTestReportDetail record);
@ -21,7 +22,7 @@ public interface LoadTestReportDetailMapper {
List<LoadTestReportDetail> selectByExample(LoadTestReportDetailExample example);
LoadTestReportDetail selectByPrimaryKey(String reportId);
LoadTestReportDetail selectByPrimaryKey(LoadTestReportDetailKey key);
int updateByExampleSelective(@Param("record") LoadTestReportDetail record, @Param("example") LoadTestReportDetailExample example);

View File

@ -3,6 +3,7 @@
<mapper namespace="io.metersphere.base.mapper.LoadTestReportDetailMapper">
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.LoadTestReportDetail">
<id column="report_id" jdbcType="VARCHAR" property="reportId" />
<id column="part" jdbcType="BIGINT" property="part"/>
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.LoadTestReportDetail">
<result column="content" jdbcType="LONGVARCHAR" property="content" />
@ -66,7 +67,8 @@
</where>
</sql>
<sql id="Base_Column_List">
report_id
report_id,
part
</sql>
<sql id="Blob_Column_List">
content
@ -101,18 +103,20 @@
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="ResultMapWithBLOBs">
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from load_test_report_detail
where report_id = #{reportId,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from load_test_report_detail
where report_id = #{reportId,jdbcType=VARCHAR}
</delete>
<select id="selectByPrimaryKey" parameterType="io.metersphere.base.domain.LoadTestReportDetailKey" resultMap="ResultMapWithBLOBs">
SELECT
<include refid="Base_Column_List"/>
,
<include refid="Blob_Column_List"/>
FROM load_test_report_detail
WHERE report_id = #{reportId,jdbcType=VARCHAR}
AND part = #{part,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="io.metersphere.base.domain.LoadTestReportDetailKey">
DELETE FROM load_test_report_detail
WHERE report_id = #{reportId,jdbcType=VARCHAR}
AND part = #{part,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="io.metersphere.base.domain.LoadTestReportDetailExample">
delete from load_test_report_detail
<if test="_parameter != null">
@ -120,27 +124,35 @@
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.LoadTestReportDetail">
insert into load_test_report_detail (report_id, content)
values (#{reportId,jdbcType=VARCHAR}, #{content,jdbcType=LONGVARCHAR})
insert into load_test_report_detail (report_id, part, content
)
values (#{reportId,jdbcType=VARCHAR}, #{part,jdbcType=BIGINT}, #{content,jdbcType=LONGVARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.LoadTestReportDetail">
insert into load_test_report_detail
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="reportId != null">
report_id,
</if>
<if test="content != null">
content,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="reportId != null">
#{reportId,jdbcType=VARCHAR},
</if>
<if test="content != null">
#{content,jdbcType=LONGVARCHAR},
</if>
</trim>
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="reportId != null">
report_id,
</if>
<if test="part != null">
part,
</if>
<if test="content != null">
content,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="reportId != null">
#{reportId,jdbcType=VARCHAR},
</if>
<if test="part != null">
#{part,jdbcType=BIGINT},
</if>
<if test="content != null">
#{content,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.LoadTestReportDetailExample" resultType="java.lang.Long">
select count(*) from load_test_report_detail
@ -150,30 +162,35 @@
</select>
<update id="updateByExampleSelective" parameterType="map">
update load_test_report_detail
<set>
<if test="record.reportId != null">
report_id = #{record.reportId,jdbcType=VARCHAR},
</if>
<if test="record.content != null">
content = #{record.content,jdbcType=LONGVARCHAR},
</if>
</set>
<set>
<if test="record.reportId != null">
report_id = #{record.reportId,jdbcType=VARCHAR},
</if>
<if test="record.part != null">
part = #{record.part,jdbcType=BIGINT},
</if>
<if test="record.content != null">
content = #{record.content,jdbcType=LONGVARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExampleWithBLOBs" parameterType="map">
update load_test_report_detail
set report_id = #{record.reportId,jdbcType=VARCHAR},
update load_test_report_detail
set report_id = #{record.reportId,jdbcType=VARCHAR},
part = #{record.part,jdbcType=BIGINT},
content = #{record.content,jdbcType=LONGVARCHAR}
<if test="_parameter != null">
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update load_test_report_detail
set report_id = #{record.reportId,jdbcType=VARCHAR}
<if test="_parameter != null">
update load_test_report_detail
set report_id = #{record.reportId,jdbcType=VARCHAR},
part = #{record.part,jdbcType=BIGINT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
@ -184,11 +201,13 @@
content = #{content,jdbcType=LONGVARCHAR},
</if>
</set>
where report_id = #{reportId,jdbcType=VARCHAR}
where report_id = #{reportId,jdbcType=VARCHAR}
and part = #{part,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.base.domain.LoadTestReportDetail">
update load_test_report_detail
set content = #{content,jdbcType=LONGVARCHAR}
where report_id = #{reportId,jdbcType=VARCHAR}
update load_test_report_detail
set content = #{content,jdbcType=LONGVARCHAR}
where report_id = #{reportId,jdbcType=VARCHAR}
and part = #{part,jdbcType=BIGINT}
</update>
</mapper>

View File

@ -2,7 +2,6 @@ package io.metersphere.base.mapper;
import io.metersphere.base.domain.LoadTestReport;
import io.metersphere.base.domain.LoadTestReportExample;
import io.metersphere.base.domain.LoadTestReportWithBLOBs;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -14,25 +13,25 @@ public interface LoadTestReportMapper {
int deleteByPrimaryKey(String id);
int insert(LoadTestReportWithBLOBs record);
int insert(LoadTestReport record);
int insertSelective(LoadTestReportWithBLOBs record);
int insertSelective(LoadTestReport record);
List<LoadTestReportWithBLOBs> selectByExampleWithBLOBs(LoadTestReportExample example);
List<LoadTestReport> selectByExampleWithBLOBs(LoadTestReportExample example);
List<LoadTestReport> selectByExample(LoadTestReportExample example);
LoadTestReportWithBLOBs selectByPrimaryKey(String id);
LoadTestReport selectByPrimaryKey(String id);
int updateByExampleSelective(@Param("record") LoadTestReportWithBLOBs record, @Param("example") LoadTestReportExample example);
int updateByExampleSelective(@Param("record") LoadTestReport record, @Param("example") LoadTestReportExample example);
int updateByExampleWithBLOBs(@Param("record") LoadTestReportWithBLOBs record, @Param("example") LoadTestReportExample example);
int updateByExampleWithBLOBs(@Param("record") LoadTestReport record, @Param("example") LoadTestReportExample example);
int updateByExample(@Param("record") LoadTestReport record, @Param("example") LoadTestReportExample example);
int updateByPrimaryKeySelective(LoadTestReportWithBLOBs record);
int updateByPrimaryKeySelective(LoadTestReport record);
int updateByPrimaryKeyWithBLOBs(LoadTestReportWithBLOBs record);
int updateByPrimaryKeyWithBLOBs(LoadTestReport record);
int updateByPrimaryKey(LoadTestReport record);
}

View File

@ -9,9 +9,8 @@
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
<result column="status" jdbcType="VARCHAR" property="status" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.LoadTestReportWithBLOBs">
<result column="description" jdbcType="LONGVARCHAR" property="description" />
<result column="content" jdbcType="LONGVARCHAR" property="content" />
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.LoadTestReport">
<result column="description" jdbcType="LONGVARCHAR" property="description"/>
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -75,7 +74,7 @@
id, test_id, name, create_time, update_time, status
</sql>
<sql id="Blob_Column_List">
description, content
description
</sql>
<select id="selectByExampleWithBLOBs" parameterType="io.metersphere.base.domain.LoadTestReportExample" resultMap="ResultMapWithBLOBs">
select
@ -125,25 +124,25 @@
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.LoadTestReportWithBLOBs">
insert into load_test_report (id, test_id, name,
create_time, update_time, status,
description, content)
values (#{id,jdbcType=VARCHAR}, #{testId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{status,jdbcType=VARCHAR},
#{description,jdbcType=LONGVARCHAR}, #{content,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.LoadTestReportWithBLOBs">
insert into load_test_report
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="testId != null">
test_id,
</if>
<if test="name != null">
name,
<insert id="insert" parameterType="io.metersphere.base.domain.LoadTestReport">
INSERT INTO load_test_report (id, test_id, name,
create_time, update_time, status,
description)
VALUES (#{id,jdbcType=VARCHAR}, #{testId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{status,jdbcType=VARCHAR},
#{description,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.LoadTestReport">
insert into load_test_report
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="testId != null">
test_id,
</if>
<if test="name != null">
name,
</if>
<if test="createTime != null">
create_time,
@ -157,9 +156,6 @@
<if test="description != null">
description,
</if>
<if test="content != null">
content,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -183,9 +179,6 @@
<if test="description != null">
#{description,jdbcType=LONGVARCHAR},
</if>
<if test="content != null">
#{content,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.LoadTestReportExample" resultType="java.lang.Long">
@ -218,25 +211,21 @@
<if test="record.description != null">
description = #{record.description,jdbcType=LONGVARCHAR},
</if>
<if test="record.content != null">
content = #{record.content,jdbcType=LONGVARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExampleWithBLOBs" parameterType="map">
update load_test_report
set id = #{record.id,jdbcType=VARCHAR},
update load_test_report
set id = #{record.id,jdbcType=VARCHAR},
test_id = #{record.testId,jdbcType=VARCHAR},
name = #{record.name,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT},
status = #{record.status,jdbcType=VARCHAR},
description = #{record.description,jdbcType=LONGVARCHAR},
content = #{record.content,jdbcType=LONGVARCHAR}
<if test="_parameter != null">
description = #{record.description,jdbcType=LONGVARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
@ -252,17 +241,17 @@
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.LoadTestReportWithBLOBs">
update load_test_report
<set>
<if test="testId != null">
test_id = #{testId,jdbcType=VARCHAR},
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT},
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.LoadTestReport">
update load_test_report
<set>
<if test="testId != null">
test_id = #{testId,jdbcType=VARCHAR},
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=BIGINT},
@ -273,23 +262,19 @@
<if test="description != null">
description = #{description,jdbcType=LONGVARCHAR},
</if>
<if test="content != null">
content = #{content,jdbcType=LONGVARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.base.domain.LoadTestReportWithBLOBs">
update load_test_report
set test_id = #{testId,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
status = #{status,jdbcType=VARCHAR},
description = #{description,jdbcType=LONGVARCHAR},
content = #{content,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.base.domain.LoadTestReport">
UPDATE load_test_report
SET test_id = #{testId,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
status = #{status,jdbcType=VARCHAR},
description = #{description,jdbcType=LONGVARCHAR}
WHERE id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.LoadTestReport">
update load_test_report
set test_id = #{testId,jdbcType=VARCHAR},

View File

@ -79,7 +79,9 @@ public class PerformanceTestService {
// delete load_test_report, delete load_test_report_detail
reportIdList.forEach(reportId -> {
loadTestReportDetailMapper.deleteByPrimaryKey(reportId);
LoadTestReportDetailExample example = new LoadTestReportDetailExample();
example.createCriteria().andReportIdEqualTo(reportId);
loadTestReportDetailMapper.deleteByExample(example);
reportService.deleteReport(reportId);
});
@ -202,7 +204,7 @@ public class PerformanceTestService {
}
private void startEngine(LoadTestWithBLOBs loadTest, Engine engine) {
LoadTestReportWithBLOBs testReport = new LoadTestReportWithBLOBs();
LoadTestReport testReport = new LoadTestReport();
testReport.setId(engine.getReportId());
testReport.setCreateTime(engine.getStartTime());
testReport.setUpdateTime(engine.getStartTime());
@ -216,13 +218,13 @@ public class PerformanceTestService {
loadTest.setStatus(PerformanceTestStatus.Starting.name());
loadTestMapper.updateByPrimaryKeySelective(loadTest);
// 启动正常插入 report
testReport.setContent(HEADERS);
testReport.setStatus(PerformanceTestStatus.Starting.name());
loadTestReportMapper.insertSelective(testReport);
LoadTestReportDetail reportDetail = new LoadTestReportDetail();
reportDetail.setContent(HEADERS);
reportDetail.setReportId(testReport.getId());
reportDetail.setPart(1L);
loadTestReportDetailMapper.insertSelective(reportDetail);
// append \n
extLoadTestReportMapper.appendLine(testReport.getId(), "\n");

View File

@ -57,7 +57,7 @@ public class ReportService {
MSException.throwException("report id cannot be null");
}
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId);
LoadTestReport loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId);
LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(loadTestReport.getTestId());
LogUtil.info("Delete report started, report ID: %s" + reportId);
@ -142,7 +142,7 @@ public class ReportService {
}
public void checkReportStatus(String reportId) {
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId);
LoadTestReport loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId);
String reportStatus = loadTestReport.getStatus();
if (StringUtils.equals(PerformanceTestStatus.Running.name(), reportStatus)) {
MSException.throwException("Reporting in progress...");

View File

@ -51,7 +51,6 @@ CREATE TABLE IF NOT EXISTS `load_test_report` (
`test_id` varchar(50) NOT NULL COMMENT 'Test ID this test report belongs to',
`name` varchar(64) NOT NULL COMMENT 'Test report name',
`description` varchar(255) DEFAULT NULL COMMENT 'Test report name',
`content` longtext,
`create_time` bigint(13) NOT NULL COMMENT 'Create timestamp',
`update_time` bigint(13) NOT NULL COMMENT 'Update timestamp',
`status` varchar(64) NOT NULL COMMENT 'Status of this test run',
@ -64,11 +63,9 @@ CREATE TABLE IF NOT EXISTS `load_test_report` (
CREATE TABLE IF NOT EXISTS `load_test_report_detail` (
`report_id` varchar(50) NOT NULL,
`content` longtext,
PRIMARY KEY (`report_id`)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_bin;
`part` bigint(11) NOT NULL,
PRIMARY KEY (`report_id`,`part`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
CREATE TABLE IF NOT EXISTS `load_test_report_log` (
`id` varchar(50) NOT NULL,

View File

@ -59,7 +59,7 @@
<!--要生成的数据库表 -->
<table tableName="test_plan_test_case"/>
<table tableName="load_test_report"/>
</context>
</generatorConfiguration>