Merge remote-tracking branch 'origin/master'

This commit is contained in:
Captain.B 2021-01-12 15:39:52 +08:00
commit 4233af67e9
9 changed files with 179 additions and 10 deletions

View File

@ -23,5 +23,7 @@ public class LoadTest implements Serializable {
private String userId;
private Integer num;
private static final long serialVersionUID = 1L;
}

View File

@ -713,6 +713,66 @@ public class LoadTestExample {
addCriterion("user_id not between", value1, value2, "userId");
return (Criteria) this;
}
public Criteria andNumIsNull() {
addCriterion("num is null");
return (Criteria) this;
}
public Criteria andNumIsNotNull() {
addCriterion("num is not null");
return (Criteria) this;
}
public Criteria andNumEqualTo(Integer value) {
addCriterion("num =", value, "num");
return (Criteria) this;
}
public Criteria andNumNotEqualTo(Integer value) {
addCriterion("num <>", value, "num");
return (Criteria) this;
}
public Criteria andNumGreaterThan(Integer value) {
addCriterion("num >", value, "num");
return (Criteria) this;
}
public Criteria andNumGreaterThanOrEqualTo(Integer value) {
addCriterion("num >=", value, "num");
return (Criteria) this;
}
public Criteria andNumLessThan(Integer value) {
addCriterion("num <", value, "num");
return (Criteria) this;
}
public Criteria andNumLessThanOrEqualTo(Integer value) {
addCriterion("num <=", value, "num");
return (Criteria) this;
}
public Criteria andNumIn(List<Integer> values) {
addCriterion("num in", values, "num");
return (Criteria) this;
}
public Criteria andNumNotIn(List<Integer> values) {
addCriterion("num not in", values, "num");
return (Criteria) this;
}
public Criteria andNumBetween(Integer value1, Integer value2) {
addCriterion("num between", value1, value2, "num");
return (Criteria) this;
}
public Criteria andNumNotBetween(Integer value1, Integer value2) {
addCriterion("num not between", value1, value2, "num");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -13,5 +13,7 @@ public class LoadTestWithBLOBs extends LoadTest implements Serializable {
private String advancedConfiguration;
private String schedule;
private static final long serialVersionUID = 1L;
}

View File

@ -11,10 +11,12 @@
<result column="status" jdbcType="VARCHAR" property="status" />
<result column="test_resource_pool_id" jdbcType="VARCHAR" property="testResourcePoolId" />
<result column="user_id" jdbcType="VARCHAR" property="userId" />
<result column="num" jdbcType="INTEGER" property="num" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.LoadTestWithBLOBs">
<result column="load_configuration" jdbcType="LONGVARCHAR" property="loadConfiguration" />
<result column="advanced_configuration" jdbcType="LONGVARCHAR" property="advancedConfiguration" />
<result column="schedule" jdbcType="LONGVARCHAR" property="schedule" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -76,10 +78,10 @@
</sql>
<sql id="Base_Column_List">
id, project_id, `name`, description, create_time, update_time, `status`, test_resource_pool_id,
user_id
user_id, num
</sql>
<sql id="Blob_Column_List">
load_configuration, advanced_configuration
load_configuration, advanced_configuration, schedule
</sql>
<select id="selectByExampleWithBLOBs" parameterType="io.metersphere.base.domain.LoadTestExample" resultMap="ResultMapWithBLOBs">
select
@ -133,13 +135,13 @@
insert into load_test (id, project_id, `name`,
description, create_time, update_time,
`status`, test_resource_pool_id, user_id,
load_configuration, advanced_configuration
)
num, load_configuration, advanced_configuration,
schedule)
values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{status,jdbcType=VARCHAR}, #{testResourcePoolId,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR},
#{loadConfiguration,jdbcType=LONGVARCHAR}, #{advancedConfiguration,jdbcType=LONGVARCHAR}
)
#{num,jdbcType=INTEGER}, #{loadConfiguration,jdbcType=LONGVARCHAR}, #{advancedConfiguration,jdbcType=LONGVARCHAR},
#{schedule,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.LoadTestWithBLOBs">
insert into load_test
@ -171,12 +173,18 @@
<if test="userId != null">
user_id,
</if>
<if test="num != null">
num,
</if>
<if test="loadConfiguration != null">
load_configuration,
</if>
<if test="advancedConfiguration != null">
advanced_configuration,
</if>
<if test="schedule != null">
schedule,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -206,12 +214,18 @@
<if test="userId != null">
#{userId,jdbcType=VARCHAR},
</if>
<if test="num != null">
#{num,jdbcType=INTEGER},
</if>
<if test="loadConfiguration != null">
#{loadConfiguration,jdbcType=LONGVARCHAR},
</if>
<if test="advancedConfiguration != null">
#{advancedConfiguration,jdbcType=LONGVARCHAR},
</if>
<if test="schedule != null">
#{schedule,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.LoadTestExample" resultType="java.lang.Long">
@ -250,12 +264,18 @@
<if test="record.userId != null">
user_id = #{record.userId,jdbcType=VARCHAR},
</if>
<if test="record.num != null">
num = #{record.num,jdbcType=INTEGER},
</if>
<if test="record.loadConfiguration != null">
load_configuration = #{record.loadConfiguration,jdbcType=LONGVARCHAR},
</if>
<if test="record.advancedConfiguration != null">
advanced_configuration = #{record.advancedConfiguration,jdbcType=LONGVARCHAR},
</if>
<if test="record.schedule != null">
schedule = #{record.schedule,jdbcType=LONGVARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -272,8 +292,10 @@
`status` = #{record.status,jdbcType=VARCHAR},
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR},
user_id = #{record.userId,jdbcType=VARCHAR},
num = #{record.num,jdbcType=INTEGER},
load_configuration = #{record.loadConfiguration,jdbcType=LONGVARCHAR},
advanced_configuration = #{record.advancedConfiguration,jdbcType=LONGVARCHAR}
advanced_configuration = #{record.advancedConfiguration,jdbcType=LONGVARCHAR},
schedule = #{record.schedule,jdbcType=LONGVARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -288,7 +310,8 @@
update_time = #{record.updateTime,jdbcType=BIGINT},
`status` = #{record.status,jdbcType=VARCHAR},
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR},
user_id = #{record.userId,jdbcType=VARCHAR}
user_id = #{record.userId,jdbcType=VARCHAR},
num = #{record.num,jdbcType=INTEGER}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -320,12 +343,18 @@
<if test="userId != null">
user_id = #{userId,jdbcType=VARCHAR},
</if>
<if test="num != null">
num = #{num,jdbcType=INTEGER},
</if>
<if test="loadConfiguration != null">
load_configuration = #{loadConfiguration,jdbcType=LONGVARCHAR},
</if>
<if test="advancedConfiguration != null">
advanced_configuration = #{advancedConfiguration,jdbcType=LONGVARCHAR},
</if>
<if test="schedule != null">
schedule = #{schedule,jdbcType=LONGVARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
@ -339,8 +368,10 @@
`status` = #{status,jdbcType=VARCHAR},
test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR},
user_id = #{userId,jdbcType=VARCHAR},
num = #{num,jdbcType=INTEGER},
load_configuration = #{loadConfiguration,jdbcType=LONGVARCHAR},
advanced_configuration = #{advancedConfiguration,jdbcType=LONGVARCHAR}
advanced_configuration = #{advancedConfiguration,jdbcType=LONGVARCHAR},
schedule = #{schedule,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.LoadTest">
@ -352,7 +383,8 @@
update_time = #{updateTime,jdbcType=BIGINT},
`status` = #{status,jdbcType=VARCHAR},
test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR},
user_id = #{userId,jdbcType=VARCHAR}
user_id = #{userId,jdbcType=VARCHAR},
num = #{num,jdbcType=INTEGER}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -14,4 +14,6 @@ public interface ExtLoadTestMapper {
List<LoadTest> getLoadTestByProjectId(String projectId);
int checkLoadTestOwner(@Param("testId") String testId, @Param("workspaceIds") Set<String> workspaceIds);
LoadTest getNextNum(@Param("projectId") String projectId);
}

View File

@ -128,4 +128,7 @@
</if>
</where>
</select>
<select id="getNextNum" resultType="io.metersphere.base.domain.LoadTest">
select * from load_test lt where lt.project_id = #{projectId} ORDER BY num DESC LIMIT 1;
</select>
</mapper>

View File

@ -160,6 +160,7 @@ public class PerformanceTestService {
loadTest.setLoadConfiguration(request.getLoadConfiguration());
loadTest.setAdvancedConfiguration(request.getAdvancedConfiguration());
loadTest.setStatus(PerformanceTestStatus.Saved.name());
loadTest.setNum(getNextNum(request.getProjectId()));
loadTestMapper.insert(loadTest);
return loadTest;
}
@ -396,6 +397,7 @@ public class PerformanceTestService {
copy.setUpdateTime(System.currentTimeMillis());
copy.setStatus(APITestStatus.Saved.name());
copy.setUserId(Objects.requireNonNull(SessionUtils.getUser()).getId());
copy.setNum(getNextNum(copy.getProjectId()));
loadTestMapper.insert(copy);
// copy test file
LoadTestFileExample loadTestFileExample = new LoadTestFileExample();
@ -499,4 +501,13 @@ public class PerformanceTestService {
List<LoadTest> loadTests = loadTestMapper.selectByExample(loadTestExample);
return Optional.ofNullable(loadTests).orElse(new ArrayList<>());
}
private int getNextNum(String projectId) {
LoadTest loadTest = extLoadTestMapper.getNextNum(projectId);
if (loadTest == null) {
return 100001;
} else {
return Optional.of(loadTest.getNum() + 1).orElse(100001);
}
}
}

View File

@ -0,0 +1,51 @@
alter table load_test add num int null;
DROP PROCEDURE IF EXISTS test_cursor;
DELIMITER //
CREATE PROCEDURE test_cursor()
BEGIN
DECLARE projectId VARCHAR(64);
DECLARE loadTestId VARCHAR(64);
DECLARE num INT;
DECLARE done INT DEFAULT 0;
DECLARE cursor1 CURSOR FOR (SELECT DISTINCT project_id
FROM load_test
WHERE num IS NULL);
DECLARE cursor2 CURSOR FOR (SELECT id
FROM load_test
WHERE project_id = projectId
ORDER BY create_time);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cursor1;
outer_loop:
LOOP
FETCH cursor1 INTO projectId;
IF done
THEN
LEAVE outer_loop;
END IF;
SET num = 100001;
OPEN cursor2;
inner_loop:
LOOP
FETCH cursor2 INTO loadTestId;
IF done
THEN
LEAVE inner_loop;
END IF;
UPDATE load_test
SET num = num
WHERE id = loadTestId;
SET num = num + 1;
END LOOP;
SET done = 0;
CLOSE cursor2;
END LOOP;
CLOSE cursor1;
END //
DELIMITER ;
CALL test_cursor();
DROP PROCEDURE IF EXISTS test_cursor;

View File

@ -13,6 +13,12 @@
@filter-change="filter"
@row-click="link"
>
<el-table-column
prop="num"
label="ID"
width="100"
show-overflow-tooltip>
</el-table-column>
<el-table-column
prop="name"
:label="$t('commons.name')"