From 4cef65d9f88585515166220ca6ebe14673bc208c Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 12 Jan 2021 15:22:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=88=97=E8=A1=A8=E6=B7=BB=E5=8A=A0ID?= =?UTF-8?q?=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/base/domain/LoadTest.java | 2 + .../base/domain/LoadTestExample.java | 60 +++++++++++++++++++ .../base/domain/LoadTestWithBLOBs.java | 2 + .../base/mapper/LoadTestMapper.xml | 52 ++++++++++++---- .../base/mapper/ext/ExtLoadTestMapper.java | 2 + .../base/mapper/ext/ExtLoadTestMapper.xml | 3 + .../service/PerformanceTestService.java | 11 ++++ .../db/migration/V65__init_load_test_num.sql | 51 ++++++++++++++++ .../performance/test/PerformanceTestList.vue | 6 ++ 9 files changed, 179 insertions(+), 10 deletions(-) create mode 100644 backend/src/main/resources/db/migration/V65__init_load_test_num.sql diff --git a/backend/src/main/java/io/metersphere/base/domain/LoadTest.java b/backend/src/main/java/io/metersphere/base/domain/LoadTest.java index f0fb9694c1..b62e751a3f 100644 --- a/backend/src/main/java/io/metersphere/base/domain/LoadTest.java +++ b/backend/src/main/java/io/metersphere/base/domain/LoadTest.java @@ -23,5 +23,7 @@ public class LoadTest implements Serializable { private String userId; + private Integer num; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/LoadTestExample.java b/backend/src/main/java/io/metersphere/base/domain/LoadTestExample.java index 27c7a4496f..9907f4b785 100644 --- a/backend/src/main/java/io/metersphere/base/domain/LoadTestExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/LoadTestExample.java @@ -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 values) { + addCriterion("num in", values, "num"); + return (Criteria) this; + } + + public Criteria andNumNotIn(List 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 { diff --git a/backend/src/main/java/io/metersphere/base/domain/LoadTestWithBLOBs.java b/backend/src/main/java/io/metersphere/base/domain/LoadTestWithBLOBs.java index ed7c0c698c..5e3c4b20b3 100644 --- a/backend/src/main/java/io/metersphere/base/domain/LoadTestWithBLOBs.java +++ b/backend/src/main/java/io/metersphere/base/domain/LoadTestWithBLOBs.java @@ -13,5 +13,7 @@ public class LoadTestWithBLOBs extends LoadTest implements Serializable { private String advancedConfiguration; + private String schedule; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/LoadTestMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/LoadTestMapper.xml index b6c45ec1d3..af5478f5bb 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/LoadTestMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/LoadTestMapper.xml @@ -11,10 +11,12 @@ + + @@ -76,10 +78,10 @@ id, project_id, `name`, description, create_time, update_time, `status`, test_resource_pool_id, - user_id + user_id, num - load_configuration, advanced_configuration + load_configuration, advanced_configuration, schedule @@ -250,12 +264,18 @@ user_id = #{record.userId,jdbcType=VARCHAR}, + + num = #{record.num,jdbcType=INTEGER}, + load_configuration = #{record.loadConfiguration,jdbcType=LONGVARCHAR}, advanced_configuration = #{record.advancedConfiguration,jdbcType=LONGVARCHAR}, + + schedule = #{record.schedule,jdbcType=LONGVARCHAR}, + @@ -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} @@ -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} @@ -320,12 +343,18 @@ user_id = #{userId,jdbcType=VARCHAR}, + + num = #{num,jdbcType=INTEGER}, + load_configuration = #{loadConfiguration,jdbcType=LONGVARCHAR}, advanced_configuration = #{advancedConfiguration,jdbcType=LONGVARCHAR}, + + schedule = #{schedule,jdbcType=LONGVARCHAR}, + where id = #{id,jdbcType=VARCHAR} @@ -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} @@ -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} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.java index 8a90bf5e7e..9ea652a93f 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.java @@ -14,4 +14,6 @@ public interface ExtLoadTestMapper { List getLoadTestByProjectId(String projectId); int checkLoadTestOwner(@Param("testId") String testId, @Param("workspaceIds") Set workspaceIds); + + LoadTest getNextNum(@Param("projectId") String projectId); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml index 6e5806ac28..0282187863 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml @@ -128,4 +128,7 @@ + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java index 6827045fb2..a3d6a4d9a6 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -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 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); + } + } } diff --git a/backend/src/main/resources/db/migration/V65__init_load_test_num.sql b/backend/src/main/resources/db/migration/V65__init_load_test_num.sql new file mode 100644 index 0000000000..ad6c223dc8 --- /dev/null +++ b/backend/src/main/resources/db/migration/V65__init_load_test_num.sql @@ -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; + diff --git a/frontend/src/business/components/performance/test/PerformanceTestList.vue b/frontend/src/business/components/performance/test/PerformanceTestList.vue index 80d3210f0d..0b3af35206 100644 --- a/frontend/src/business/components/performance/test/PerformanceTestList.vue +++ b/frontend/src/business/components/performance/test/PerformanceTestList.vue @@ -13,6 +13,12 @@ @filter-change="filter" @row-click="link" > + +