提交 94dd8372 编写于 作者: W wenyann

Merge remote-tracking branch 'origin/dev' into dev

......@@ -12,10 +12,7 @@ import org.apache.jmeter.visualizers.backend.AbstractBackendListenerClient;
import org.apache.jmeter.visualizers.backend.BackendListenerContext;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
......@@ -72,6 +69,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
sampleResults.forEach(result -> {
String thread = StringUtils.substringBeforeLast(result.getThreadName(), " ");
String order = StringUtils.substringAfterLast(result.getThreadName(), " ");
String scenarioName = StringUtils.substringBefore(thread, SPLIT);
String scenarioId = StringUtils.substringAfter(thread, SPLIT);
ScenarioResult scenarioResult;
......@@ -79,6 +77,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
scenarioResult = new ScenarioResult();
scenarioResult.setId(scenarioId);
scenarioResult.setName(scenarioName);
scenarioResult.setOrder(StringUtils.substringBefore(order, "-"));
scenarios.put(scenarioId, scenarioResult);
} else {
scenarioResult = scenarios.get(scenarioId);
......@@ -103,6 +102,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
scenarioResult.addTotalAssertions(requestResult.getTotalAssertions());
});
testResult.getScenarios().addAll(scenarios.values());
testResult.getScenarios().sort(Comparator.comparing(ScenarioResult::getOrder));
apiTestService.changeStatus(id, APITestStatus.Completed);
apiReportService.save(testResult);
});
......
......@@ -12,6 +12,8 @@ public class ScenarioResult {
private String name;
private String order;
private long responseTime;
private int error = 0;
......
......@@ -18,5 +18,7 @@ public class LoadTestReport implements Serializable {
private String status;
private String description;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
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;
......
......@@ -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 {
......
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;
public class LoadTestReportDetailKey implements Serializable {
private String reportId;
private String content;
private Long part;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
......@@ -12,6 +12,8 @@ public class LoadTestReportLog implements Serializable {
private String resourceId;
private Long part;
private String content;
private static final long serialVersionUID = 1L;
......
......@@ -313,6 +313,66 @@ public class LoadTestReportLogExample {
addCriterion("resource_id not between", value1, value2, "resourceId");
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 {
......
......@@ -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);
......
......@@ -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>
\ No newline at end of file
......@@ -5,6 +5,7 @@
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="report_id" jdbcType="VARCHAR" property="reportId" />
<result column="resource_id" jdbcType="VARCHAR" property="resourceId" />
<result column="part" jdbcType="BIGINT" property="part"/>
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.LoadTestReportLog">
<result column="content" jdbcType="LONGVARCHAR" property="content" />
......@@ -68,7 +69,10 @@
</where>
</sql>
<sql id="Base_Column_List">
id, report_id, resource_id
id,
report_id,
resource_id,
part
</sql>
<sql id="Blob_Column_List">
content
......@@ -122,41 +126,47 @@
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.LoadTestReportLog">
insert into load_test_report_log (id, report_id, resource_id,
content)
values (#{id,jdbcType=VARCHAR}, #{reportId,jdbcType=VARCHAR}, #{resourceId,jdbcType=VARCHAR},
#{content,jdbcType=LONGVARCHAR})
insert into load_test_report_log (id, report_id, resource_id,
part, content)
values (#{id,jdbcType=VARCHAR}, #{reportId,jdbcType=VARCHAR}, #{resourceId,jdbcType=VARCHAR},
#{part,jdbcType=BIGINT}, #{content,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.LoadTestReportLog">
insert into load_test_report_log
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="reportId != null">
report_id,
</if>
<if test="resourceId != null">
resource_id,
</if>
<if test="content != null">
content,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
</if>
<if test="reportId != null">
#{reportId,jdbcType=VARCHAR},
</if>
<if test="resourceId != null">
#{resourceId,jdbcType=VARCHAR},
</if>
<if test="content != null">
#{content,jdbcType=LONGVARCHAR},
</if>
</trim>
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="reportId != null">
report_id,
</if>
<if test="resourceId != null">
resource_id,
</if>
<if test="part != null">
part,
</if>
<if test="content != null">
content,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
</if>
<if test="reportId != null">
#{reportId,jdbcType=VARCHAR},
</if>
<if test="resourceId != null">
#{resourceId,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.LoadTestReportLogExample" resultType="java.lang.Long">
select count(*) from load_test_report_log
......@@ -166,69 +176,79 @@
</select>
<update id="updateByExampleSelective" parameterType="map">
update load_test_report_log
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=VARCHAR},
</if>
<if test="record.reportId != null">
report_id = #{record.reportId,jdbcType=VARCHAR},
</if>
<if test="record.resourceId != null">
resource_id = #{record.resourceId,jdbcType=VARCHAR},
</if>
<if test="record.content != null">
content = #{record.content,jdbcType=LONGVARCHAR},
</if>
</set>
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=VARCHAR},
</if>
<if test="record.reportId != null">
report_id = #{record.reportId,jdbcType=VARCHAR},
</if>
<if test="record.resourceId != null">
resource_id = #{record.resourceId,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_log
set id = #{record.id,jdbcType=VARCHAR},
update load_test_report_log
set id = #{record.id,jdbcType=VARCHAR},
report_id = #{record.reportId,jdbcType=VARCHAR},
resource_id = #{record.resourceId,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_log
set id = #{record.id,jdbcType=VARCHAR},
update load_test_report_log
set id = #{record.id,jdbcType=VARCHAR},
report_id = #{record.reportId,jdbcType=VARCHAR},
resource_id = #{record.resourceId,jdbcType=VARCHAR}
<if test="_parameter != null">
resource_id = #{record.resourceId,jdbcType=VARCHAR},
part = #{record.part,jdbcType=BIGINT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.LoadTestReportLog">
update load_test_report_log
<set>
<if test="reportId != null">
report_id = #{reportId,jdbcType=VARCHAR},
</if>
<if test="resourceId != null">
resource_id = #{resourceId,jdbcType=VARCHAR},
</if>
<if test="content != null">
content = #{content,jdbcType=LONGVARCHAR},
</if>
</set>
<set>
<if test="reportId != null">
report_id = #{reportId,jdbcType=VARCHAR},
</if>
<if test="resourceId != null">
resource_id = #{resourceId,jdbcType=VARCHAR},
</if>
<if test="part != null">
part = #{part,jdbcType=BIGINT},
</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.LoadTestReportLog">
update load_test_report_log
set report_id = #{reportId,jdbcType=VARCHAR},
update load_test_report_log
set report_id = #{reportId,jdbcType=VARCHAR},
resource_id = #{resourceId,jdbcType=VARCHAR},
part = #{part,jdbcType=BIGINT},
content = #{content,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.LoadTestReportLog">
update load_test_report_log
set report_id = #{reportId,jdbcType=VARCHAR},
resource_id = #{resourceId,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
update load_test_report_log
set report_id = #{reportId,jdbcType=VARCHAR},
resource_id = #{resourceId,jdbcType=VARCHAR},
part = #{part,jdbcType=BIGINT}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>
\ No newline at end of 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);
}
\ No newline at end of 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},
......
......@@ -14,8 +14,6 @@ public interface ExtLoadTestReportMapper {
ReportDTO getReportTestAndProInfo(@Param("id") String id);
int appendLine(@Param("testId") String id, @Param("line") String line);
LoadTestReport selectByPrimaryKey(String id);
List<DashboardTestDTO> selectDashboardTests(@Param("workspaceId") String workspaceId, @Param("startTimestamp") long startTimestamp);
......
......@@ -41,12 +41,6 @@
where ltr.id = #{id}
</select>
<update id="appendLine">
UPDATE load_test_report
SET content = concat(content, #{line})
WHERE id = #{testId}
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
......
package io.metersphere.base.mapper.ext;
import io.metersphere.base.domain.Workspace;
import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest;
import io.metersphere.track.dto.TestCaseReportStatusResultDTO;
import io.metersphere.track.dto.TestPlanCaseDTO;
......@@ -15,7 +16,7 @@ public interface ExtTestPlanTestCaseMapper {
List<TestPlanCaseDTO> list(@Param("request") QueryTestPlanCaseRequest request);
List<String> findRelateTestPlanId(String userId);
List<String> findRelateTestPlanId(@Param("userId") String userId, @Param("workspaceId") String workspaceId);
List<TestPlanCaseDTO> getRecentTestedTestCase(@Param("request") QueryTestPlanCaseRequest request);
......
......@@ -62,7 +62,11 @@
</select>
<select id="findRelateTestPlanId" resultType="java.lang.String">
select distinct plan_id from test_plan_test_case where executor = #{userId}
select distinct plan_id from test_plan_test_case
inner join test_plan
on test_plan_test_case.plan_id = test_plan.id
where test_plan_test_case.executor = #{userId}
and test_plan.workspace_id = #{workspaceId}
</select>
<select id="getRecentTestedTestCase" resultType="io.metersphere.track.dto.TestPlanCaseDTO">
select test_plan_test_case.*, test_case.*
......
......@@ -22,4 +22,9 @@ public class RoleController {
return roleService.getRoleList(sign);
}
@GetMapping("/all")
public List<Role> getAllRole() {
return roleService.getAllRole();
}
}
......@@ -9,8 +9,8 @@ import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.UserRequest;
import io.metersphere.controller.request.member.AddMemberRequest;
import io.metersphere.controller.request.member.UserRequest;
import io.metersphere.controller.request.member.EditPassWordRequest;
import io.metersphere.controller.request.member.QueryMemberRequest;
import io.metersphere.controller.request.organization.AddOrgMemberRequest;
......@@ -38,16 +38,15 @@ public class UserController {
@Resource
private WorkspaceService workspaceService;
// admin api
@PostMapping("/special/add")
@RequiresRoles(RoleConstants.ADMIN)
public UserDTO insertUser(@RequestBody User user) {
public UserDTO insertUser(@RequestBody UserRequest user) {
return userService.insert(user);
}
@PostMapping("/special/list/{goPage}/{pageSize}")
@RequiresRoles(RoleConstants.ADMIN)
public Pager<List<User>> getUserList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody UserRequest request) {
public Pager<List<User>> getUserList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody io.metersphere.controller.request.UserRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, userService.getUserListWithRequest(request));
}
......@@ -66,8 +65,8 @@ public class UserController {
@PostMapping("/special/update")
@RequiresRoles(RoleConstants.ADMIN)
public void updateUser(@RequestBody User user) {
userService.updateUser(user);
public void updateUser(@RequestBody UserRequest user) {
userService.updateUserRole(user);
}
@PostMapping("/special/ws/member/list/{goPage}/{pageSize}")
......@@ -119,7 +118,6 @@ public class UserController {
public List<User> getOrgMemberListByAdmin(@RequestBody QueryOrgMemberRequest request) {
return userService.getOrgMemberList(request);
}
// admin api
@GetMapping("/list")
@RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN}, logical = Logical.OR)
......
......@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@RequestMapping("userrole")
@RestController
......@@ -20,14 +21,20 @@ public class UserRoleController {
private UserRoleService userRoleService;
@GetMapping("/list/org/{orgId}/{userId}")
@RequiresRoles(value = {RoleConstants.ADMIN,RoleConstants.ORG_ADMIN}, logical = Logical.OR)
@RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN}, logical = Logical.OR)
public List<Role> getOrganizationMemberRoles(@PathVariable String orgId, @PathVariable String userId) {
return userRoleService.getOrganizationMemberRoles(orgId, userId);
}
@GetMapping("/list/ws/{workspaceId}/{userId}")
@RequiresRoles(value = {RoleConstants.ADMIN,RoleConstants.ORG_ADMIN}, logical = Logical.OR)
@RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN}, logical = Logical.OR)
public List<Role> getWorkspaceMemberRoles(@PathVariable String workspaceId, @PathVariable String userId) {
return userRoleService.getWorkspaceMemberRoles(workspaceId, userId);
}
@GetMapping("/all/{userId}")
@RequiresRoles(RoleConstants.ADMIN)
public List<Map<String,Object>> getUserRole(@PathVariable("userId") String userId) {
return userRoleService.getUserRole(userId);
}
}
......@@ -38,6 +38,11 @@ public class WorkspaceController {
return workspaceService.saveWorkspace(workspace);
}
@GetMapping("/list")
public List<Workspace> getWorkspaceList() {
return workspaceService.getWorkspaceList(new WorkspaceRequest());
}
@PostMapping("special/add")
@RequiresRoles(RoleConstants.ADMIN)
public void addWorkspaceByAdmin(@RequestBody Workspace workspace) {
......
package io.metersphere.controller.request.member;
import io.metersphere.base.domain.User;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Getter
@Setter
public class UserRequest extends User {
private List<Map<String,Object>> roles = new ArrayList<>();
}
......@@ -6,7 +6,7 @@ import lombok.Setter;
@Getter
@Setter
public class LogDetailDTO {
private String id;
private String resourceId;
private String resourceName;
private String content;
}
......@@ -32,8 +32,11 @@ public abstract class EasyExcelListener <T> extends AnalysisEventListener<T> {
public EasyExcelListener(){
Type type = getClass().getGenericSuperclass();
this.clazz = (Class<T>) ((ParameterizedType) type).getActualTypeArguments()[0];
this.easyExcelI18nTranslator = new EasyExcelI18nTranslator(this.clazz);
this.easyExcelI18nTranslator.translateExcelProperty();
//防止多线程修改运行时类注解后,saveOriginalExcelProperty保存的是修改后的值
synchronized (EasyExcelI18nTranslator.class) {
this.easyExcelI18nTranslator = new EasyExcelI18nTranslator(this.clazz);
this.easyExcelI18nTranslator.translateExcelProperty();
}
}
/**
......
......@@ -24,17 +24,24 @@ public class EasyExcelExporter {
EasyExcelI18nTranslator easyExcelI18nTranslator;
public EasyExcelExporter() {
easyExcelI18nTranslator = new EasyExcelI18nTranslator(TestCaseExcelData.class);
easyExcelI18nTranslator.translateExcelProperty();
private Class clazz;
public EasyExcelExporter(Class clazz) {
this.clazz = clazz;
//防止多线程修改运行时类注解后,saveOriginalExcelProperty保存的是修改后的值
synchronized (EasyExcelI18nTranslator.class) {
easyExcelI18nTranslator = new EasyExcelI18nTranslator(clazz);
easyExcelI18nTranslator.translateExcelProperty();
}
}
public void export(HttpServletResponse response, Class clazz, List data, String fileName, String sheetName) {
public void export(HttpServletResponse response, List data, String fileName, String sheetName) {
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
try {
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
EasyExcel.write(response.getOutputStream(), clazz).sheet(sheetName).doWrite(data);
EasyExcel.write(response.getOutputStream(), this.clazz).sheet(sheetName).doWrite(data);
} catch (UnsupportedEncodingException e) {
LogUtil.error(e.getMessage(), e);
throw new ExcelException("Utf-8 encoding is not supported");
......@@ -42,7 +49,6 @@ public class EasyExcelExporter {
LogUtil.error(e.getMessage(), e);
throw new ExcelException("IO exception");
}
}
public void close() {
......
......@@ -104,9 +104,9 @@ public class PerformanceReportController {
return reportService.logs(reportId);
}
@GetMapping("log/download/{logId}")
public ResponseEntity<byte[]> downloadLog(@PathVariable String logId) {
byte[] bytes = reportService.downloadLog(logId);
@GetMapping("log/download/{reportId}/{resourceId}")
public ResponseEntity<byte[]> downloadLog(@PathVariable String reportId, @PathVariable String resourceId) {
byte[] bytes = reportService.downloadLog(reportId, resourceId);
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType("application/octet-stream"))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"jmeter.log\"")
......
......@@ -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,29 +218,16 @@ 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");
// append \n
extLoadTestReportDetailMapper.appendLine(testReport.getId(), "\n");
// 保存 load_test_report_log
String resourcePoolId = loadTest.getTestResourcePoolId();
List<TestResource> testResourceList = testResourceService.getResourcesByPoolId(resourcePoolId);
testResourceList.forEach(r -> {
LoadTestReportLog record = new LoadTestReportLog();
record.setId(UUID.randomUUID().toString());
record.setReportId(testReport.getId());
record.setResourceId(r.getId());
record.setContent(StringUtils.EMPTY);
loadTestReportLogMapper.insert(record);
});
} catch (MSException e) {
LogUtil.error(e);
loadTest.setStatus(PerformanceTestStatus.Error.name());
......
......@@ -24,7 +24,9 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
......@@ -57,7 +59,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 +144,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...");
......@@ -160,42 +162,50 @@ public class ReportService {
public List<LogDetailDTO> logs(String reportId) {
LoadTestReportLogExample example = new LoadTestReportLogExample();
example.createCriteria().andReportIdEqualTo(reportId);
example.setOrderByClause("part");
List<LoadTestReportLog> loadTestReportLogs = loadTestReportLogMapper.selectByExampleWithBLOBs(example);
return loadTestReportLogs.stream().map(log -> {
Map<String, List<LoadTestReportLog>> reportLogs = loadTestReportLogs.stream().collect(Collectors.groupingBy(LoadTestReportLog::getResourceId));
List<LogDetailDTO> result = new ArrayList<>();
reportLogs.forEach((resourceId, resourceLogs) -> {
LogDetailDTO detailDTO = new LogDetailDTO();
detailDTO.setId(log.getId());
TestResource testResource = testResourceService.getTestResource(log.getResourceId());
String content = log.getContent();
TestResource testResource = testResourceService.getTestResource(resourceId);
String content = resourceLogs.stream().map(LoadTestReportLog::getContent).reduce("", (a, b) -> a + b);
// 显示前 2048
content = StringUtils.substring(content, 0, 2048);
detailDTO.setResourceId(resourceId);
detailDTO.setContent(content);
if (testResource == null) {
detailDTO.setResourceName(log.getResourceId());
return detailDTO;
detailDTO.setResourceName(resourceId);
result.add(detailDTO);
return;
}
String configuration = testResource.getConfiguration();
if (StringUtils.isBlank(configuration)) {
detailDTO.setResourceName(log.getResourceId());
return detailDTO;
detailDTO.setResourceName(resourceId);
result.add(detailDTO);
return;
}
JSONObject object = JSON.parseObject(configuration);
if (StringUtils.isNotBlank(object.getString("masterUrl"))) {
detailDTO.setResourceName(object.getString("masterUrl"));
return detailDTO;
result.add(detailDTO);
return;
}
if (StringUtils.isNotBlank(object.getString("ip"))) {
detailDTO.setResourceName(object.getString("ip"));
return detailDTO;
result.add(detailDTO);
}
return detailDTO;
}).collect(Collectors.toList());
});
return result;
}
public byte[] downloadLog(String logId) {
LoadTestReportLog loadTestReportLog = loadTestReportLogMapper.selectByPrimaryKey(logId);
if (loadTestReportLog != null) {
return loadTestReportLog.getContent().getBytes();
}
return new byte[0];
public byte[] downloadLog(String reportId, String resourceId) {
LoadTestReportLogExample example = new LoadTestReportLogExample();
example.createCriteria().andReportIdEqualTo(reportId).andResourceIdEqualTo(resourceId);
List<LoadTestReportLog> loadTestReportLogs = loadTestReportLogMapper.selectByExampleWithBLOBs(example);
String content = loadTestReportLogs.stream().map(LoadTestReportLog::getContent).reduce("", (a, b) -> a + b);
return content.getBytes();
}
}
package io.metersphere.service;
import io.metersphere.base.domain.Role;
import io.metersphere.base.mapper.RoleMapper;
import io.metersphere.base.mapper.ext.ExtRoleMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -13,8 +14,14 @@ public class RoleService {
@Resource
private ExtRoleMapper extRoleMapper;
@Resource
private RoleMapper roleMapper;
public List<Role> getRoleList(String sign) {
return extRoleMapper.getRoleList(sign);
}
public List<Role> getAllRole() {
return roleMapper.selectByExample(null);
}
}
package io.metersphere.service;
import io.metersphere.base.domain.Role;
import io.metersphere.base.domain.UserRole;
import io.metersphere.base.domain.UserRoleExample;
import io.metersphere.base.mapper.UserRoleMapper;
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
......@@ -14,6 +22,8 @@ public class UserRoleService {
@Resource
private ExtUserRoleMapper extUserRoleMapper;
@Resource
private UserRoleMapper userRoleMapper;
public List<Role> getOrganizationMemberRoles(String orgId, String userId) {
return extUserRoleMapper.getOrganizationMemberRoles(orgId, userId);
......@@ -23,4 +33,28 @@ public class UserRoleService {
return extUserRoleMapper.getWorkspaceMemberRoles(workspaceId, userId);
}
public List<Map<String,Object>> getUserRole(String userId) {
List<Map<String,Object>> list = new ArrayList<>();
UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andUserIdEqualTo(userId);
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
List<String> collect = userRoles.stream()
.map(userRole -> userRole.getRoleId())
.distinct()
.collect(Collectors.toList());
for (int i = 0; i < collect.size(); i++) {
Map<String, Object> map = new HashMap<>(2);
map.put("id", collect.get(i));
map.put("Ids", new ArrayList<>());
for (int j = 0; j < userRoles.size(); j++) {
String role = userRoles.get(j).getRoleId();
if (StringUtils.equals(role, collect.get(i))) {
List ids = (List) map.get("Ids");
ids.add(userRoles.get(j).getSourceId());
}
}
list.add(map);
}
return list;
}
}
......@@ -4,12 +4,13 @@ import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtUserMapper;
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.CodingUtil;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.UserRequest;
import io.metersphere.controller.request.member.AddMemberRequest;
import io.metersphere.controller.request.member.UserRequest;
import io.metersphere.controller.request.member.EditPassWordRequest;
import io.metersphere.controller.request.member.QueryMemberRequest;
import io.metersphere.controller.request.organization.AddOrgMemberRequest;
......@@ -23,8 +24,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
@Service
......@@ -46,7 +46,7 @@ public class UserService {
@Resource
private ExtUserMapper extUserMapper;
public UserDTO insert(User user) {
public UserDTO insert(UserRequest user) {
checkUserParam(user);
//
String id = user.getId();
......@@ -56,9 +56,44 @@ public class UserService {
} else {
createUser(user);
}
List<Map<String, Object>> roles = user.getRoles();
if (!roles.isEmpty()) {
insertUserRole(roles, user.getId());
}
return getUserDTO(user.getId());
}
private void insertUserRole(List<Map<String, Object>> roles, String userId) {
for (int i = 0; i < roles.size(); i++) {
Map<String, Object> map = roles.get(i);
String role = (String) map.get("id");
if (StringUtils.equals(role, RoleConstants.ADMIN)) {
UserRole userRole = new UserRole();
userRole.setId(UUID.randomUUID().toString());
userRole.setUserId(userId);
userRole.setUpdateTime(System.currentTimeMillis());
userRole.setCreateTime(System.currentTimeMillis());
userRole.setRoleId(role);
// TODO 修改
userRole.setSourceId("adminSourceId");
userRoleMapper.insertSelective(userRole);
} else {
List<String> list = (List<String>) map.get("Ids");
for (int j = 0; j < list.size(); j++) {
UserRole userRole1 = new UserRole();
userRole1.setId(UUID.randomUUID().toString());
userRole1.setUserId(userId);
userRole1.setRoleId(role);
userRole1.setUpdateTime(System.currentTimeMillis());
userRole1.setCreateTime(System.currentTimeMillis());
userRole1.setSourceId(list.get(j));
// TODO 防止重复插入
userRoleMapper.insertSelective(userRole1);
}
}
}
}
private void checkUserParam(User user) {
if (StringUtils.isBlank(user.getName())) {
......@@ -132,7 +167,7 @@ public class UserService {
return userMapper.selectByExample(null);
}
public List<User> getUserListWithRequest(UserRequest request) {
public List<User> getUserListWithRequest(io.metersphere.controller.request.UserRequest request) {
return extUserMapper.getUserList(request);
}
......@@ -144,6 +179,19 @@ public class UserService {
userMapper.deleteByPrimaryKey(userId);
}
public void updateUserRole(UserRequest user) {
String userId = user.getId();
UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andUserIdEqualTo(userId);
userRoleMapper.deleteByExample(userRoleExample);
List<Map<String, Object>> roles = user.getRoles();
if (!roles.isEmpty()) {
insertUserRole(roles, user.getId());
}
user.setUpdateTime(System.currentTimeMillis());
userMapper.updateByPrimaryKeySelective(user);
}
public void updateUser(User user) {
user.setUpdateTime(System.currentTimeMillis());
userMapper.updateByPrimaryKeySelective(user);
......@@ -268,7 +316,7 @@ public class UserService {
public void setLanguage(String lang) {
if (SessionUtils.getUser() != null) {
User user = new User();
UserRequest user = new UserRequest();
user.setId(SessionUtils.getUser().getId());
user.setLanguage(lang);
updateUser(user);
......
......@@ -221,8 +221,8 @@ public class TestCaseService {
public void testCaseTemplateExport(HttpServletResponse response) {
EasyExcelExporter easyExcelExporter = null;
try {
easyExcelExporter = new EasyExcelExporter();
easyExcelExporter.export(response, TestCaseExcelData.class, generateExportTemplate(),
easyExcelExporter = new EasyExcelExporter(TestCaseExcelData.class);
easyExcelExporter.export(response, generateExportTemplate(),
Translator.get("test_case_import_template_name"), Translator.get("test_case_import_template_sheet"));
} catch (Exception e) {
MSException.throwException(e);
......
......@@ -162,7 +162,7 @@ public class TestPlanService {
QueryTestPlanRequest request = new QueryTestPlanRequest();
request.setPrincipal(user.getId());
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setPlanIds(extTestPlanTestCaseMapper.findRelateTestPlanId(user.getId()));
request.setPlanIds(extTestPlanTestCaseMapper.findRelateTestPlanId(user.getId(), SessionUtils.getCurrentWorkspaceId()));
List<String> projectIds = extProjectMapper.getProjectIdByWorkspaceId(SessionUtils.getCurrentOrganizationId());
......@@ -205,9 +205,9 @@ public class TestPlanService {
}
private double getPercentWithTwoDecimals(double value) {
return new BigDecimal(value)
.setScale(4, BigDecimal.ROUND_HALF_UP)
.doubleValue() * 100;
return new BigDecimal(value * 100)
.setScale(2, BigDecimal.ROUND_HALF_UP)
.doubleValue();
}
public List<TestPlanCaseDTO> listTestCaseByPlanId(String planId) {
......@@ -329,7 +329,7 @@ public class TestPlanService {
}
}
public List<TestPlan> getTestPlanByTestIds(List<String> planIds) {
public List<TestPlan> getTestPlanByIds(List<String> planIds) {
TestPlanExample example = new TestPlanExample();
example.createCriteria().andIdIn(planIds);
return testPlanMapper.selectByExample(example);
......
......@@ -80,10 +80,15 @@ public class TestPlanTestCaseService {
if (request.getPlanIds().isEmpty()) {
return new ArrayList<>();
}
List<TestPlanCaseDTO> recentTestedTestCase = extTestPlanTestCaseMapper.getRecentTestedTestCase(request);
List<String> planIds = recentTestedTestCase.stream().map(TestPlanCaseDTO::getPlanId).collect(Collectors.toList());
Map<String, String> testPlanMap = testPlanService.getTestPlanByTestIds(planIds).stream()
if (planIds.isEmpty()) {
return new ArrayList<>();
}
Map<String, String> testPlanMap = testPlanService.getTestPlanByIds(planIds).stream()
.collect(Collectors.toMap(TestPlan::getId, TestPlan::getName));
recentTestedTestCase.forEach(testCase -> {
......@@ -102,7 +107,7 @@ public class TestPlanTestCaseService {
public void buildQueryRequest(QueryTestPlanCaseRequest request, int count) {
SessionUser user = SessionUtils.getUser();
List<String> relateTestPlanIds = extTestPlanTestCaseMapper.findRelateTestPlanId(user.getId());
List<String> relateTestPlanIds = extTestPlanTestCaseMapper.findRelateTestPlanId(user.getId(), SessionUtils.getCurrentWorkspaceId());
PageHelper.startPage(1, count, true);
request.setPlanIds(relateTestPlanIds);
request.setExecutor(user.getId());
......
......@@ -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,20 +63,19 @@ 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,
`id` varchar(50) NOT NULL,
`report_id` varchar(50) NOT NULL,
`resource_id` varchar(50) DEFAULT NULL,
`content` longtext ,
`part` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `load_test_report_log_report_id_resource_name_index` (`report_id`,`resource_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
KEY `load_test_report_log_report_id_resource_name_index` (`report_id`,`resource_id`,`part`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ;
CREATE TABLE IF NOT EXISTS `load_test_report_result` (
`id` varchar(50) NOT NULL,
......
......@@ -59,7 +59,7 @@
<!--要生成的数据库表 -->
<table tableName="test_plan_test_case"/>
<table tableName="load_test_report"/>
</context>
</generatorConfiguration>
\ No newline at end of file
<template>
<el-card class="table-card" v-loading="result.loading">
<template v-slot:header>
<span class="title">{{$t('api_test.title')}}</span>
<span class="title">{{$t('commons.test')}}</span>
</template>
<el-table :data="tableData" class="table-content">
<el-table-column :label="$t('commons.name')" width="150" show-overflow-tooltip>
......
......@@ -3,7 +3,7 @@
<ms-main-container>
<el-card class="table-card" v-loading="result.loading">
<template v-slot:header>
<ms-table-header :condition.sync="condition" @search="search" :title="$t('api_test.title')"
<ms-table-header :condition.sync="condition" @search="search" :title="$t('commons.test')"
@create="create" :createTip="$t('load_test.create')"/>
</template>
<el-table :data="tableData" class="table-content">
......
<template>
<el-card class="table-card" v-loading="result.loading">
<template v-slot:header>
<span class="title">{{$t('api_test.title')}}</span>
<span class="title">{{$t('commons.test')}}</span>
</template>
<el-table :data="tableData" class="table-content">
<el-table-column :label="$t('commons.name')" width="150" show-overflow-tooltip>
......
<template>
<div v-loading="result.loading">
<el-tabs type="border-card" :stretch="true">
<el-tab-pane v-for="item in logContent" :key="item.id" :label="item.resourceName" class="logging-content">
<el-tab-pane v-for="item in logContent" :key="item.resourceId" :label="item.resourceName" class="logging-content">
{{item.content}}...
<el-link type="primary" @click="downloadLogFile(item)">{{$t('load_test.download_log_file')}}</el-link>
</el-tab-pane>
......@@ -27,7 +27,7 @@
},
downloadLogFile(item) {
let config = {
url: '/performance/report/log/download/' + item.id,
url: '/performance/report/log/download/' + this.id + '/' + item.resourceId,
method: 'get',
responseType: 'blob'
};
......
......@@ -16,7 +16,7 @@
</template>
</el-table-column>
<el-table-column prop="email" :label="$t('commons.email')"/>
<el-table-column prop="status" :label="$t('commons.status')">
<el-table-column prop="status" :label="$t('commons.status')" width="120">
<template v-slot:default="scope">
<el-switch v-model="scope.row.status"
active-color="#13ce66"
......@@ -49,9 +49,9 @@
</el-card>
<!--Create user-->
<el-dialog :title="$t('user.create')" :visible.sync="createVisible" width="30%" @closed="handleClose"
<el-dialog :title="$t('user.create')" :visible.sync="createVisible" width="35%" @closed="handleClose"
:destroy-on-close="true">
<el-form :model="form" label-position="right" label-width="100px" size="small" :rules="rule" ref="createUserForm">
<el-form :model="form" label-position="right" label-width="120px" size="small" :rules="rule" ref="createUserForm">
<el-form-item label="ID" prop="id">
<el-input v-model="form.id" autocomplete="off"/>
</el-form-item>
......@@ -67,6 +67,74 @@
<el-form-item :label="$t('commons.password')" prop="password">
<el-input v-model="form.password" autocomplete="off" show-password/>
</el-form-item>
<div v-for="(role, index) in form.roles" :key="index">
<el-form-item :label="'角色'+index" :required="true">
<el-select v-model="role.id" placeholder="选择角色类型">
<el-option
v-for="item in userRole"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
<el-button @click.prevent="removeRole(role)" style="margin-left: 20px;" v-if="form.roles.length > 1">删除
</el-button>
</el-form-item>
<div v-if="role.id === 'org_admin'">
<el-form-item label="选择组织" :required="true">
<el-select v-model="role.Ids" placeholder="选择组织" multiple>
<el-option
v-for="item in form.orgList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</div>
<div v-if="role.id === 'test_manager'">
<el-form-item label="选择工作空间" :required="true">
<el-select v-model="role.Ids" placeholder="选择工作空间" multiple>
<el-option
v-for="item in form.wsList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</div>
<div v-if="role.id ==='test_user'">
<el-form-item label="选择工作空间" :required="true">
<el-select v-model="role.Ids" placeholder="选择工作空间" multiple>
<el-option
v-for="item in form.wsList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</div>
<div v-if="role.id ==='test_viewer'">
<el-form-item label="选择工作空间" :required="true">
<el-select v-model="role.Ids" placeholder="选择工作空间" multiple>
<el-option
v-for="item in form.wsList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</div>
</div>
<el-form-item>
<template>
<el-button type="success" style="width: 100%;" @click="addRole()">添加角色</el-button>
</template>
</el-form-item>
</el-form>
<template v-slot:footer>
<ms-dialog-footer
......@@ -78,7 +146,7 @@
<!--Modify user information in system settings-->
<el-dialog :title="$t('user.modify')" :visible.sync="updateVisible" width="30%" :destroy-on-close="true"
@close="handleClose">
<el-form :model="form" label-position="right" label-width="100px" size="small" :rules="rule" ref="updateUserForm">
<el-form :model="form" label-position="right" label-width="120px" size="small" :rules="rule" ref="updateUserForm">
<el-form-item label="ID" prop="id">
<el-input v-model="form.id" autocomplete="off" :disabled="true"/>
</el-form-item>
......@@ -91,6 +159,73 @@
<el-form-item :label="$t('commons.phone')" prop="phone">
<el-input v-model="form.phone" autocomplete="off"/>
</el-form-item>
<div v-for="(role, index) in form.roles" :key="index">
<el-form-item :label="'角色'+index" :required="true">
<el-select v-model="role.id" placeholder="选择角色类型">
<el-option
v-for="item in userRole"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
<el-button @click.prevent="removeRole(role)" style="margin-left: 20px;" v-if="form.roles.length > 1">删除
</el-button>
</el-form-item>
<div v-if="role.id === 'org_admin'">
<el-form-item label="选择组织" :required="true">
<el-select v-model="role.Ids" placeholder="选择组织" multiple>
<el-option
v-for="item in form.orgList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</div>
<div v-if="role.id === 'test_manager'">
<el-form-item label="选择工作空间" :required="true">
<el-select v-model="role.Ids" placeholder="选择工作空间" multiple>
<el-option
v-for="item in form.wsList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</div>
<div v-if="role.id ==='test_user'">
<el-form-item label="选择工作空间" :required="true">
<el-select v-model="role.Ids" placeholder="选择工作空间" multiple>
<el-option
v-for="item in form.wsList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</div>
<div v-if="role.id ==='test_viewer'">
<el-form-item label="选择工作空间" :required="true">
<el-select v-model="role.Ids" placeholder="选择工作空间" multiple>
<el-option
v-for="item in form.wsList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</div>
</div>
<el-form-item>
<template>
<el-button type="success" style="width: 100%;" @click="addRole()">添加角色</el-button>
</template>
</el-form-item>
</el-form>
<template v-slot:footer>
<ms-dialog-footer
......@@ -152,12 +287,15 @@
updateVisible: false,
editPasswordVisible: false,
multipleSelection: [],
userRole: [],
currentPage: 1,
pageSize: 5,
total: 0,
condition: {},
tableData: [],
form: {},
form: {
roles: [{}]
},
checkPasswordForm: {},
ruleForm: {},
setAdminParam: {},
......@@ -216,14 +354,27 @@
},
created() {
this.search();
this.getAllRole();
},
methods: {
create() {
this.createVisible = true;
this.getOrgList();
this.getWsList();
},
edit(row) {
this.updateVisible = true;
this.form = Object.assign({}, row);
this.$get("/organization/list", response => {
this.$set(this.form, "orgList", response.data);
});
this.$get("/workspace/list", response => {
this.$set(this.form, "wsList", response.data);
});
this.$get('/userrole/all/' + row.id, response => {
let data = response.data;
this.$set(this.form, "roles", data);
});
},
editPassword(row) {
this.editPasswordVisible = true;
......@@ -295,12 +446,12 @@
let roles = data.roles;
// let userRoles = result.userRoles;
this.$set(this.tableData[i], "roles", roles);
})
});
}
})
},
handleClose() {
this.form = {};
this.form = {roles: [{value: ''}]};
},
changeSwitch(row) {
this.$post(this.updatePath, row, () => {
......@@ -312,7 +463,32 @@
},
handleSelectionChange(val) {
this.multipleSelection = val;
}
},
getOrgList() {
this.$get("/organization/list", response => {
this.$set(this.form, "orgList", response.data);
})
},
getWsList() {
this.$get("/workspace/list", response => {
this.$set(this.form, "wsList", response.data);
})
},
getAllRole() {
this.$get("/role/all", response => {
this.userRole = response.data;
})
},
addRole() {
let roles = this.form.roles;
roles.push({});
},
removeRole(item) {
let index = this.form.roles.indexOf(item)
if (index !== -1) {
this.form.roles.splice(index, 1)
}
},
}
}
</script>
......
......@@ -99,6 +99,7 @@
<el-row style="margin-bottom: 10px">
<el-col :offset="2">{{$t('test_track.case.steps')}}:</el-col>
</el-row>
<el-row type="flex" justify="center">
<el-col :span="20">
<el-table
......@@ -162,7 +163,7 @@
</el-row>
<el-row type="flex" justify="center">
<el-col :span="20">
<el-form-item>
<el-form-item prop="remark">
<el-input v-model="form.remark"
:autosize="{ minRows: 2, maxRows: 4}"
type="textarea"
......@@ -177,7 +178,7 @@
<template v-slot:footer>
<el-switch
v-model="isCreateContinue"
active-text="保存并继续创建">
:active-text="$t('test_track.case.save_create_continue')">
</el-switch>
<ms-dialog-footer v-if="!readOnly"
@cancel="dialogFormVisible = false"
......@@ -231,7 +232,8 @@
maintainer :[{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
priority :[{required: true, message: this.$t('test_track.case.input_priority'), trigger: 'change'}],
type :[{required: true, message: this.$t('test_track.case.input_type'), trigger: 'change'}],
method :[{required: true, message: this.$t('test_track.case.input_method'), trigger: 'change'}]
method :[{required: true, message: this.$t('test_track.case.input_method'), trigger: 'change'}],
remark :[{ max: 300, message: this.$t('test_track.length_less_than') + '300', trigger: 'blur'}]
},
formLabelWidth: "120px",
operationType: '',
......@@ -296,7 +298,7 @@
step.num ++;
}
});
this.form.steps.push(step);
this.form.steps.splice(index + 1, 0, step);
},
handleDeleteStep(index, data) {
this.form.steps.splice(index, 1);
......@@ -311,6 +313,15 @@
if (valid) {
let param = {};
Object.assign(param, this.form);
for (let i = 0; i < param.steps.length; i++){
if (param.steps[i].desc.length > 300 || param.steps[i].result.length > 300) {
this.$warning(this.$t('test_track.case.step_desc') + ","
+ this.$t('test_track.case.expected_results') + this.$t('test_track.length_less_than') + '300');
return;
}
}
param.steps = JSON.stringify(this.form.steps);
param.nodeId = this.form.module;
this.moduleOptions.forEach(item => {
......
......@@ -222,12 +222,19 @@
param.id = this.testCase.id;
param.status = this.testCase.status;
param.results = [];
this.testCase.steptResults.forEach(item => {
for (let i = 0; i < this.testCase.steptResults.length; i++){
let result = {};
result.actualResult = item.actualResult;
result.executeResult = item.executeResult;
result.actualResult = this.testCase.steptResults[i].actualResult;
result.executeResult = this.testCase.steptResults[i].executeResult;
if (result.actualResult && result.actualResult.length > 300) {
this.$warning(this.$t('test_track.plan_view.actual_result')
+ this.$t('test_track.length_less_than') + '300');
return;
}
param.results.push(result);
});
}
param.results = JSON.stringify(param.results);
param.issues = JSON.stringify(this.testCase.issues);
this.$post('/test/plan/case/edit', param, () => {
......
......@@ -375,6 +375,7 @@ export default {
input_prerequisite: "Please select prerequisite",
delete_confirm: "Confirm delete test case",
delete: "Delete case",
save_create_continue: "Save and create continue",
import: {
import: "Import test case",
case_import: "Import test case",
......
......@@ -372,6 +372,7 @@ export default {
input_prerequisite: "请输入前置条件",
delete_confirm: "确认删除测试用例",
delete: "删除用例",
save_create_continue: "保存并继续创建",
import: {
import: "导入用例",
case_import: "导入测试用例",
......
......@@ -366,6 +366,7 @@ export default {
input_prerequisite: "請輸入前置條件",
delete_confirm: "確認刪除測試用例: ",
delete: "删除用例",
save_create_continue: "保存並繼續創建",
import: {
import: "導入用例",
case_import: "導入測試用例",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册