From 219ccc7c4bc79365cf4dcdb7292d823123db76ad Mon Sep 17 00:00:00 2001 From: CaptainB Date: Sat, 23 Oct 2021 14:37:31 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=87=AA=E5=8A=A8=E5=8C=96?= =?UTF-8?q?=E5=85=B3=E6=B3=A8=E4=BA=BA=E5=A4=9A=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ApiAutomationController.java | 5 +- .../automation/SaveApiScenarioRequest.java | 2 +- .../api/service/ApiAutomationService.java | 32 ++++++++- .../metersphere/base/domain/ApiScenario.java | 2 - .../base/domain/ApiScenarioExample.java | 70 ------------------- .../base/mapper/ApiScenarioMapper.xml | 53 +++++--------- .../service/PerformanceTestService.java | 4 +- .../db/migration/V97__v1.14_release.sql | 16 ++++- .../src/main/resources/generatorConfig.xml | 2 +- .../automation/scenario/AddBasisScenario.vue | 5 +- .../automation/scenario/EditApiScenario.vue | 8 ++- 11 files changed, 78 insertions(+), 121 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java index 2f0b746cda..202f85b695 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java @@ -359,6 +359,9 @@ public class ApiAutomationController { return apiAutomationService.checkScenarioEnv(request); } - + @GetMapping("/follow/{scenarioId}") + public List getFollows(@PathVariable String scenarioId) { + return apiAutomationService.getFollows(scenarioId); + } } diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/SaveApiScenarioRequest.java b/backend/src/main/java/io/metersphere/api/dto/automation/SaveApiScenarioRequest.java index 1d6919da8e..7363444f3c 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/SaveApiScenarioRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/SaveApiScenarioRequest.java @@ -34,7 +34,7 @@ public class SaveApiScenarioRequest { private Integer stepTotal; - private String followPeople; + private List follows; private String schedule; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index ab41655edb..7547a6e3a3 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -142,6 +142,8 @@ public class ApiAutomationService { private ExtTestPlanScenarioCaseMapper extTestPlanScenarioCaseMapper; @Resource private RelationshipEdgeService relationshipEdgeService; + @Resource + private ApiScenarioFollowMapper apiScenarioFollowMapper; private ThreadLocal currentScenarioOrder = new ThreadLocal<>(); @@ -355,7 +357,7 @@ public class ApiAutomationService { scenario.setVersion(version + 1); } - deleteUpdateBodyFile(scenario,beforeScenario); + deleteUpdateBodyFile(scenario, beforeScenario); List useUrl = this.parseUrl(scenario); scenario.setUseUrl(JSONArray.toJSONString(useUrl)); apiScenarioMapper.updateByPrimaryKeySelective(scenario); @@ -376,7 +378,7 @@ public class ApiAutomationService { * * @param scenario */ - public void deleteUpdateBodyFile(ApiScenarioWithBLOBs scenario,ApiScenarioWithBLOBs oldScenario) { + public void deleteUpdateBodyFile(ApiScenarioWithBLOBs scenario, ApiScenarioWithBLOBs oldScenario) { Set newRequestIds = getRequestIds(scenario.getScenarioDefinition()); MsTestElement msTestElement = parseScenarioDefinition(oldScenario.getScenarioDefinition()); List oldRequests = MsHTTPSamplerProxy.findHttpSampleFromHashTree(msTestElement); @@ -414,7 +416,6 @@ public class ApiAutomationService { scenario.setApiScenarioModuleId(request.getApiScenarioModuleId()); scenario.setModulePath(request.getModulePath()); scenario.setLevel(request.getLevel()); - scenario.setFollowPeople(request.getFollowPeople()); scenario.setPrincipal(request.getPrincipal()); scenario.setStepTotal(request.getStepTotal()); scenario.setUpdateTime(System.currentTimeMillis()); @@ -442,9 +443,24 @@ public class ApiAutomationService { scenario.setModulePath(modules.get(0).getName()); } } + saveFollows(scenario.getId(), request.getFollows()); return scenario; } + private void saveFollows(String scenarioId, List follows) { + ApiScenarioFollowExample example = new ApiScenarioFollowExample(); + example.createCriteria().andScenarioIdEqualTo(scenarioId); + apiScenarioFollowMapper.deleteByExample(example); + if (!org.springframework.util.CollectionUtils.isEmpty(follows)) { + for (String follow : follows) { + ApiScenarioFollow apiScenarioFollow = new ApiScenarioFollow(); + apiScenarioFollow.setScenarioId(scenarioId); + apiScenarioFollow.setFollowId(follow); + apiScenarioFollowMapper.insert(apiScenarioFollow); + } + } + } + public void delete(String id) { //及连删除外键表 this.preDelete(id); @@ -2669,4 +2685,14 @@ public class ApiAutomationService { return this.checkScenarioEnv(request, null); } + public List getFollows(String scenarioId) { + List result = new ArrayList<>(); + if (StringUtils.isBlank(scenarioId)) { + return result; + } + ApiScenarioFollowExample example = new ApiScenarioFollowExample(); + example.createCriteria().andScenarioIdEqualTo(scenarioId); + List follows = apiScenarioFollowMapper.selectByExample(example); + return follows.stream().map(ApiScenarioFollow::getFollowId).distinct().collect(Collectors.toList()); + } } diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiScenario.java b/backend/src/main/java/io/metersphere/base/domain/ApiScenario.java index b8d13cbc46..6be70223d6 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiScenario.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiScenario.java @@ -27,8 +27,6 @@ public class ApiScenario implements Serializable { private Integer stepTotal; - private String followPeople; - private String schedule; private Long createTime; diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioExample.java b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioExample.java index 3ccebd5ce5..6f2ccf5970 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioExample.java @@ -864,76 +864,6 @@ public class ApiScenarioExample { return (Criteria) this; } - public Criteria andFollowPeopleIsNull() { - addCriterion("follow_people is null"); - return (Criteria) this; - } - - public Criteria andFollowPeopleIsNotNull() { - addCriterion("follow_people is not null"); - return (Criteria) this; - } - - public Criteria andFollowPeopleEqualTo(String value) { - addCriterion("follow_people =", value, "followPeople"); - return (Criteria) this; - } - - public Criteria andFollowPeopleNotEqualTo(String value) { - addCriterion("follow_people <>", value, "followPeople"); - return (Criteria) this; - } - - public Criteria andFollowPeopleGreaterThan(String value) { - addCriterion("follow_people >", value, "followPeople"); - return (Criteria) this; - } - - public Criteria andFollowPeopleGreaterThanOrEqualTo(String value) { - addCriterion("follow_people >=", value, "followPeople"); - return (Criteria) this; - } - - public Criteria andFollowPeopleLessThan(String value) { - addCriterion("follow_people <", value, "followPeople"); - return (Criteria) this; - } - - public Criteria andFollowPeopleLessThanOrEqualTo(String value) { - addCriterion("follow_people <=", value, "followPeople"); - return (Criteria) this; - } - - public Criteria andFollowPeopleLike(String value) { - addCriterion("follow_people like", value, "followPeople"); - return (Criteria) this; - } - - public Criteria andFollowPeopleNotLike(String value) { - addCriterion("follow_people not like", value, "followPeople"); - return (Criteria) this; - } - - public Criteria andFollowPeopleIn(List values) { - addCriterion("follow_people in", values, "followPeople"); - return (Criteria) this; - } - - public Criteria andFollowPeopleNotIn(List values) { - addCriterion("follow_people not in", values, "followPeople"); - return (Criteria) this; - } - - public Criteria andFollowPeopleBetween(String value1, String value2) { - addCriterion("follow_people between", value1, value2, "followPeople"); - return (Criteria) this; - } - - public Criteria andFollowPeopleNotBetween(String value1, String value2) { - addCriterion("follow_people not between", value1, value2, "followPeople"); - return (Criteria) this; - } - public Criteria andScheduleIsNull() { addCriterion("schedule is null"); return (Criteria) this; diff --git a/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioMapper.xml index 2addae4fd7..0b79b06ba5 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioMapper.xml @@ -13,7 +13,6 @@ - @@ -95,9 +94,9 @@ id, project_id, tags, user_id, api_scenario_module_id, module_path, `name`, `level`, - `status`, principal, step_total, follow_people, schedule, create_time, update_time, - pass_rate, last_result, report_id, num, original_state, custom_num, create_user, - version, delete_time, delete_user_id, execute_times, `order` + `status`, principal, step_total, schedule, create_time, update_time, pass_rate, last_result, + report_id, num, original_state, custom_num, create_user, version, delete_time, delete_user_id, + execute_times, `order` scenario_definition, description, use_url @@ -154,25 +153,23 @@ insert into api_scenario (id, project_id, tags, user_id, api_scenario_module_id, module_path, `name`, `level`, `status`, - principal, step_total, follow_people, - schedule, create_time, update_time, - pass_rate, last_result, report_id, - num, original_state, custom_num, - create_user, version, delete_time, - delete_user_id, execute_times, `order`, - scenario_definition, description, - use_url) + principal, step_total, schedule, + create_time, update_time, pass_rate, + last_result, report_id, num, + original_state, custom_num, create_user, + version, delete_time, delete_user_id, + execute_times, `order`, scenario_definition, + description, use_url) values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{tags,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{apiScenarioModuleId,jdbcType=VARCHAR}, #{modulePath,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{level,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, - #{principal,jdbcType=VARCHAR}, #{stepTotal,jdbcType=INTEGER}, #{followPeople,jdbcType=VARCHAR}, - #{schedule,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, - #{passRate,jdbcType=VARCHAR}, #{lastResult,jdbcType=VARCHAR}, #{reportId,jdbcType=VARCHAR}, - #{num,jdbcType=INTEGER}, #{originalState,jdbcType=VARCHAR}, #{customNum,jdbcType=VARCHAR}, - #{createUser,jdbcType=VARCHAR}, #{version,jdbcType=INTEGER}, #{deleteTime,jdbcType=BIGINT}, - #{deleteUserId,jdbcType=VARCHAR}, #{executeTimes,jdbcType=INTEGER}, #{order,jdbcType=BIGINT}, - #{scenarioDefinition,jdbcType=LONGVARCHAR}, #{description,jdbcType=LONGVARCHAR}, - #{useUrl,jdbcType=LONGVARCHAR}) + #{principal,jdbcType=VARCHAR}, #{stepTotal,jdbcType=INTEGER}, #{schedule,jdbcType=VARCHAR}, + #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{passRate,jdbcType=VARCHAR}, + #{lastResult,jdbcType=VARCHAR}, #{reportId,jdbcType=VARCHAR}, #{num,jdbcType=INTEGER}, + #{originalState,jdbcType=VARCHAR}, #{customNum,jdbcType=VARCHAR}, #{createUser,jdbcType=VARCHAR}, + #{version,jdbcType=INTEGER}, #{deleteTime,jdbcType=BIGINT}, #{deleteUserId,jdbcType=VARCHAR}, + #{executeTimes,jdbcType=INTEGER}, #{order,jdbcType=BIGINT}, #{scenarioDefinition,jdbcType=LONGVARCHAR}, + #{description,jdbcType=LONGVARCHAR}, #{useUrl,jdbcType=LONGVARCHAR}) insert into api_scenario @@ -210,9 +207,6 @@ step_total, - - follow_people, - schedule, @@ -302,9 +296,6 @@ #{stepTotal,jdbcType=INTEGER}, - - #{followPeople,jdbcType=VARCHAR}, - #{schedule,jdbcType=VARCHAR}, @@ -403,9 +394,6 @@ step_total = #{record.stepTotal,jdbcType=INTEGER}, - - follow_people = #{record.followPeople,jdbcType=VARCHAR}, - schedule = #{record.schedule,jdbcType=VARCHAR}, @@ -478,7 +466,6 @@ `status` = #{record.status,jdbcType=VARCHAR}, principal = #{record.principal,jdbcType=VARCHAR}, step_total = #{record.stepTotal,jdbcType=INTEGER}, - follow_people = #{record.followPeople,jdbcType=VARCHAR}, schedule = #{record.schedule,jdbcType=VARCHAR}, create_time = #{record.createTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT}, @@ -514,7 +501,6 @@ `status` = #{record.status,jdbcType=VARCHAR}, principal = #{record.principal,jdbcType=VARCHAR}, step_total = #{record.stepTotal,jdbcType=INTEGER}, - follow_people = #{record.followPeople,jdbcType=VARCHAR}, schedule = #{record.schedule,jdbcType=VARCHAR}, create_time = #{record.createTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT}, @@ -567,9 +553,6 @@ step_total = #{stepTotal,jdbcType=INTEGER}, - - follow_people = #{followPeople,jdbcType=VARCHAR}, - schedule = #{schedule,jdbcType=VARCHAR}, @@ -639,7 +622,6 @@ `status` = #{status,jdbcType=VARCHAR}, principal = #{principal,jdbcType=VARCHAR}, step_total = #{stepTotal,jdbcType=INTEGER}, - follow_people = #{followPeople,jdbcType=VARCHAR}, schedule = #{schedule,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT}, @@ -672,7 +654,6 @@ `status` = #{status,jdbcType=VARCHAR}, principal = #{principal,jdbcType=VARCHAR}, step_total = #{stepTotal,jdbcType=INTEGER}, - follow_people = #{followPeople,jdbcType=VARCHAR}, schedule = #{schedule,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT}, 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 419919d76a..c60ec2a1b7 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -916,7 +916,7 @@ public class PerformanceTestService { } LoadTestFollowExample example = new LoadTestFollowExample(); example.createCriteria().andTestIdEqualTo(testId); - List testPlanFollow = loadTestFollowMapper.selectByExample(example); - return testPlanFollow.stream().map(LoadTestFollow::getFollowId).distinct().collect(Collectors.toList()); + List follows = loadTestFollowMapper.selectByExample(example); + return follows.stream().map(LoadTestFollow::getFollowId).distinct().collect(Collectors.toList()); } } diff --git a/backend/src/main/resources/db/migration/V97__v1.14_release.sql b/backend/src/main/resources/db/migration/V97__v1.14_release.sql index b252f67bfb..798b49a921 100644 --- a/backend/src/main/resources/db/migration/V97__v1.14_release.sql +++ b/backend/src/main/resources/db/migration/V97__v1.14_release.sql @@ -353,4 +353,18 @@ INSERT INTO load_test_follow SELECT id, follow_people FROM load_test WHERE follow_people IS NOT NULL; -ALTER TABLE load_test DROP COLUMN follow_people; \ No newline at end of file +ALTER TABLE load_test DROP COLUMN follow_people; + +-- 自动化关注人 +CREATE TABLE IF NOT EXISTS `api_scenario_follow` ( + `scenario_id` VARCHAR(50) DEFAULT NULL, + `follow_id` VARCHAR(50) DEFAULT NULL, + UNIQUE KEY `api_scenario_follow_scenario_id_follow_id_pk` (`scenario_id`, `follow_id`), + KEY `api_scenario_follow_id_index` (`follow_id`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; +-- 自动化关注人数据迁移 +INSERT INTO api_scenario_follow +SELECT id, follow_people +FROM api_scenario +WHERE follow_people IS NOT NULL; +ALTER TABLE api_scenario DROP COLUMN follow_people; \ No newline at end of file diff --git a/backend/src/main/resources/generatorConfig.xml b/backend/src/main/resources/generatorConfig.xml index 2eddde8b81..177da92826 100644 --- a/backend/src/main/resources/generatorConfig.xml +++ b/backend/src/main/resources/generatorConfig.xml @@ -78,7 +78,7 @@
--> -
+
diff --git a/frontend/src/business/components/api/automation/scenario/AddBasisScenario.vue b/frontend/src/business/components/api/automation/scenario/AddBasisScenario.vue index 019aa564b7..827c07cafc 100644 --- a/frontend/src/business/components/api/automation/scenario/AddBasisScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/AddBasisScenario.vue @@ -22,7 +22,8 @@ - - { + // this.$set(this.currentScenario, 'follows', response.data); + this.currentScenario.follows = response.data; + }); } this.loading = false; this.setDomain();