分开保存结果

This commit is contained in:
Captain.B 2020-04-13 17:18:15 +08:00
parent 7ba0e97125
commit 78b757302f
8 changed files with 570 additions and 7 deletions

View File

@ -0,0 +1,27 @@
package io.metersphere.base.domain;
import java.io.Serializable;
public class LoadTestReportDetail implements Serializable {
private String reportId;
private String content;
private static final long serialVersionUID = 1L;
public String getReportId() {
return reportId;
}
public void setReportId(String reportId) {
this.reportId = reportId == null ? null : reportId.trim();
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content == null ? null : content.trim();
}
}

View File

@ -0,0 +1,270 @@
package io.metersphere.base.domain;
import java.util.ArrayList;
import java.util.List;
public class LoadTestReportDetailExample {
protected String orderByClause;
protected boolean distinct;
protected List<Criteria> oredCriteria;
public LoadTestReportDetailExample() {
oredCriteria = new ArrayList<Criteria>();
}
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
public String getOrderByClause() {
return orderByClause;
}
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
public boolean isDistinct() {
return distinct;
}
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
}
public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> getCriteria() {
return criteria;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
}
protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
public Criteria andReportIdIsNull() {
addCriterion("report_id is null");
return (Criteria) this;
}
public Criteria andReportIdIsNotNull() {
addCriterion("report_id is not null");
return (Criteria) this;
}
public Criteria andReportIdEqualTo(String value) {
addCriterion("report_id =", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdNotEqualTo(String value) {
addCriterion("report_id <>", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdGreaterThan(String value) {
addCriterion("report_id >", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdGreaterThanOrEqualTo(String value) {
addCriterion("report_id >=", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdLessThan(String value) {
addCriterion("report_id <", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdLessThanOrEqualTo(String value) {
addCriterion("report_id <=", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdLike(String value) {
addCriterion("report_id like", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdNotLike(String value) {
addCriterion("report_id not like", value, "reportId");
return (Criteria) this;
}
public Criteria andReportIdIn(List<String> values) {
addCriterion("report_id in", values, "reportId");
return (Criteria) this;
}
public Criteria andReportIdNotIn(List<String> values) {
addCriterion("report_id not in", values, "reportId");
return (Criteria) this;
}
public Criteria andReportIdBetween(String value1, String value2) {
addCriterion("report_id between", value1, value2, "reportId");
return (Criteria) this;
}
public Criteria andReportIdNotBetween(String value1, String value2) {
addCriterion("report_id not between", value1, value2, "reportId");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {
protected Criteria() {
super();
}
}
public static class Criterion {
private String condition;
private Object value;
private Object secondValue;
private boolean noValue;
private boolean singleValue;
private boolean betweenValue;
private boolean listValue;
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
this.typeHandler = null;
this.noValue = true;
}
protected Criterion(String condition, Object value, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.typeHandler = typeHandler;
if (value instanceof List<?>) {
this.listValue = true;
} else {
this.singleValue = true;
}
}
protected Criterion(String condition, Object value) {
this(condition, value, null);
}
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.secondValue = secondValue;
this.typeHandler = typeHandler;
this.betweenValue = true;
}
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
}
}

View File

@ -0,0 +1,35 @@
package io.metersphere.base.mapper;
import io.metersphere.base.domain.LoadTestReportDetail;
import io.metersphere.base.domain.LoadTestReportDetailExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface LoadTestReportDetailMapper {
long countByExample(LoadTestReportDetailExample example);
int deleteByExample(LoadTestReportDetailExample example);
int deleteByPrimaryKey(String reportId);
int insert(LoadTestReportDetail record);
int insertSelective(LoadTestReportDetail record);
List<LoadTestReportDetail> selectByExampleWithBLOBs(LoadTestReportDetailExample example);
List<LoadTestReportDetail> selectByExample(LoadTestReportDetailExample example);
LoadTestReportDetail selectByPrimaryKey(String reportId);
int updateByExampleSelective(@Param("record") LoadTestReportDetail record, @Param("example") LoadTestReportDetailExample example);
int updateByExampleWithBLOBs(@Param("record") LoadTestReportDetail record, @Param("example") LoadTestReportDetailExample example);
int updateByExample(@Param("record") LoadTestReportDetail record, @Param("example") LoadTestReportDetailExample example);
int updateByPrimaryKeySelective(LoadTestReportDetail record);
int updateByPrimaryKeyWithBLOBs(LoadTestReportDetail record);
}

View File

@ -0,0 +1,194 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.base.mapper.LoadTestReportDetailMapper">
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.LoadTestReportDetail">
<id column="report_id" jdbcType="VARCHAR" property="reportId" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.LoadTestReportDetail">
<result column="content" jdbcType="LONGVARCHAR" property="content" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
report_id
</sql>
<sql id="Blob_Column_List">
content
</sql>
<select id="selectByExampleWithBLOBs" parameterType="io.metersphere.base.domain.LoadTestReportDetailExample" resultMap="ResultMapWithBLOBs">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from load_test_report_detail
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByExample" parameterType="io.metersphere.base.domain.LoadTestReportDetailExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from load_test_report_detail
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
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>
<delete id="deleteByExample" parameterType="io.metersphere.base.domain.LoadTestReportDetailExample">
delete from load_test_report_detail
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</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>
<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>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.LoadTestReportDetailExample" resultType="java.lang.Long">
select count(*) from load_test_report_detail
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</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>
<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},
content = #{record.content,jdbcType=LONGVARCHAR}
<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">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.LoadTestReportDetail">
update load_test_report_detail
<set>
<if test="content != null">
content = #{content,jdbcType=LONGVARCHAR},
</if>
</set>
where report_id = #{reportId,jdbcType=VARCHAR}
</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>
</mapper>

View File

@ -0,0 +1,7 @@
package io.metersphere.base.mapper.ext;
import org.apache.ibatis.annotations.Param;
public interface ExtLoadTestReportDetailMapper {
int appendLine(@Param("reportId") String id, @Param("line") String line);
}

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="io.metersphere.base.mapper.ext.ExtLoadTestReportDetailMapper">
<update id="appendLine">
UPDATE load_test_report_detail
SET content = concat(content, #{line})
WHERE report_id = #{reportId}
</update>
</mapper>

View File

@ -3,6 +3,7 @@ package io.metersphere.service;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtLoadTestMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestReportDetailMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
import io.metersphere.commons.constants.FileType;
import io.metersphere.commons.constants.TestStatus;
@ -48,6 +49,10 @@ public class PerformanceTestService {
private LoadTestReportMapper loadTestReportMapper;
@Resource
private ExtLoadTestReportMapper extLoadTestReportMapper;
@Resource
private LoadTestReportDetailMapper loadTestReportDetailMapper;
@Resource
private ExtLoadTestReportDetailMapper extLoadTestReportDetailMapper;
public List<LoadTestDTO> list(QueryTestPlanRequest request) {
return extLoadTestMapper.list(request);
@ -194,19 +199,26 @@ public class PerformanceTestService {
testReport.setTestId(loadTest.getId());
testReport.setName(loadTest.getName());
// 启动测试
testReport.setContent(HEADERS);
testReport.setStatus(TestStatus.Starting.name());
loadTestReportMapper.insertSelective(testReport);
LoadTestReportDetail reportDetail = new LoadTestReportDetail();
reportDetail.setContent(HEADERS);
reportDetail.setReportId(testReport.getId());
loadTestReportDetailMapper.insertSelective(reportDetail);
boolean started = true;
try {
engine.start();
// 标记running状态
loadTest.setStatus(TestStatus.Starting.name());
loadTestMapper.updateByPrimaryKeySelective(loadTest);
testReport.setContent(HEADERS);
testReport.setStatus(TestStatus.Starting.name());
loadTestReportMapper.insertSelective(testReport);
// append \n
extLoadTestReportMapper.appendLine(testReport.getId(), "\n");
// append \n
extLoadTestReportDetailMapper.appendLine(testReport.getId(), "\n");
//
engine.start();
} catch (Exception e) {
LogUtil.error(e);
started = false;
@ -216,7 +228,7 @@ public class PerformanceTestService {
//
testReport.setStatus(TestStatus.Error.name());
testReport.setDescription(e.getMessage());
loadTestReportMapper.insertSelective(testReport);
loadTestReportMapper.updateByPrimaryKeySelective(testReport);
}
return started;
}

View File

@ -62,6 +62,15 @@ CREATE TABLE IF NOT EXISTS `load_test_report` (
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_bin;
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;
CREATE TABLE IF NOT EXISTS `organization` (
`id` varchar(50) NOT NULL COMMENT 'Organization ID',
`name` varchar(64) NOT NULL COMMENT 'Organization name',