From 4e5807687ac030352e883f30ddd4501cf0b2bd7f Mon Sep 17 00:00:00 2001 From: CaptainB Date: Sat, 23 Oct 2021 15:12:55 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8E=A5=E5=8F=A3=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=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/ApiDefinitionController.java | 5 + .../definition/SaveApiDefinitionRequest.java | 2 +- .../api/service/ApiDefinitionService.java | 36 +- .../base/domain/ApiDefinition.java | 10 +- .../base/domain/ApiDefinitionExample.java | 350 +++++++----------- .../base/domain/ApiDefinitionWithBLOBs.java | 2 +- .../base/mapper/ApiDefinitionMapper.xml | 137 +++---- .../db/migration/V97__v1.14_release.sql | 16 +- .../components/complete/BasisApi.vue | 7 +- .../complete/EditCompleteHTTPApi.vue | 8 +- .../components/complete/TCPBasicApi.vue | 6 +- 11 files changed, 272 insertions(+), 307 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java b/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java index ca22e11ad8..d2ebb1357a 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java @@ -324,4 +324,9 @@ public class ApiDefinitionController { public Pager< List> getRelationshipRelateList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) { return apiDefinitionService.getRelationshipRelateList(request, goPage, pageSize); } + + @GetMapping("/follow/{definitionId}") + public List getFollows(@PathVariable String definitionId) { + return apiDefinitionService.getFollows(definitionId); + } } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/SaveApiDefinitionRequest.java b/backend/src/main/java/io/metersphere/api/dto/definition/SaveApiDefinitionRequest.java index c8e9161603..54f7ed0132 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/SaveApiDefinitionRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/SaveApiDefinitionRequest.java @@ -42,7 +42,7 @@ public class SaveApiDefinitionRequest { private String userId; - private String followPeople; + private List follows; private String remark; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index 6371765e47..89bc358b02 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -123,6 +123,8 @@ public class ApiDefinitionService { private ExtApiTestCaseMapper extApiTestCaseMapper; @Resource private RelationshipEdgeService relationshipEdgeService; + @Resource + private ApiDefinitionFollowMapper apiDefinitionFollowMapper; private static Cache cache = Cache.newHardMemoryCache(0, 3600); @@ -476,7 +478,6 @@ public class ApiDefinitionService { test.setEnvironmentId(request.getEnvironmentId()); test.setUserId(request.getUserId()); test.setRemark(request.getRemark()); - test.setFollowPeople(request.getFollowPeople()); if (StringUtils.isNotEmpty(request.getTags()) && !StringUtils.equals(request.getTags(), "[]")) { test.setTags(request.getTags()); } else { @@ -488,10 +489,24 @@ public class ApiDefinitionService { List ids = new ArrayList<>(); ids.add(request.getId()); apiTestCaseService.updateByApiDefinitionId(ids, test.getPath(), test.getMethod(), test.getProtocol()); - + saveFollows(test.getId(), request.getFollows()); return test; } + private void saveFollows(String definitionId, List follows) { + ApiDefinitionFollowExample example = new ApiDefinitionFollowExample(); + example.createCriteria().andDefinitionIdEqualTo(definitionId); + apiDefinitionFollowMapper.deleteByExample(example); + if (!org.springframework.util.CollectionUtils.isEmpty(follows)) { + for (String follow : follows) { + ApiDefinitionFollow item = new ApiDefinitionFollow(); + item.setDefinitionId(definitionId); + item.setFollowId(follow); + apiDefinitionFollowMapper.insert(item); + } + } + } + private ApiDefinitionWithBLOBs createTest(SaveApiDefinitionRequest request) { checkNameExist(request); if (StringUtils.equals(request.getMethod(), "ESB")) { @@ -513,7 +528,6 @@ public class ApiDefinitionService { test.setStatus(APITestStatus.Underway.name()); test.setModulePath(request.getModulePath()); test.setModuleId(request.getModuleId()); - test.setFollowPeople(request.getFollowPeople()); test.setRemark(request.getRemark()); test.setOrder(ServiceUtils.getNextOrder(request.getProjectId(), extApiDefinitionMapper::getLastOrder)); if (StringUtils.isEmpty(request.getModuleId()) || "default-module".equals(request.getModuleId())) { @@ -540,6 +554,7 @@ public class ApiDefinitionService { test.setTags(""); } apiDefinitionMapper.insert(test); + saveFollows(test.getId(), request.getFollows()); return test; } @@ -870,8 +885,8 @@ public class ApiDefinitionService { public void addResult(TestResult res) { if (res != null && CollectionUtils.isNotEmpty(res.getScenarios()) && res.getScenarios().get(0) != null && CollectionUtils.isNotEmpty(res.getScenarios().get(0).getRequestResults())) { RequestResult result = null; - for(RequestResult itemResult : res.getScenarios().get(0).getRequestResults()){ - if(!StringUtils.equalsIgnoreCase(itemResult.getMethod(),"Request") && !StringUtils.startsWithAny(itemResult.getName(),"PRE_PROCESSOR_ENV_","POST_PROCESSOR_ENV_")){ + for (RequestResult itemResult : res.getScenarios().get(0).getRequestResults()) { + if (!StringUtils.equalsIgnoreCase(itemResult.getMethod(), "Request") && !StringUtils.startsWithAny(itemResult.getName(), "PRE_PROCESSOR_ENV_", "POST_PROCESSOR_ENV_")) { result = itemResult; break; } @@ -1675,4 +1690,15 @@ public class ApiDefinitionService { Page page = PageHelper.startPage(goPage, pageSize, true); return PageUtils.setPageInfo(page, extApiDefinitionMapper.list(request)); } + + public List getFollows(String definitionId) { + List result = new ArrayList<>(); + if (StringUtils.isBlank(definitionId)) { + return result; + } + ApiDefinitionFollowExample example = new ApiDefinitionFollowExample(); + example.createCriteria().andDefinitionIdEqualTo(definitionId); + List follows = apiDefinitionFollowMapper.selectByExample(example); + return follows.stream().map(ApiDefinitionFollow::getFollowId).distinct().collect(Collectors.toList()); + } } diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiDefinition.java b/backend/src/main/java/io/metersphere/base/domain/ApiDefinition.java index 360c68f0ac..903b4094ea 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiDefinition.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiDefinition.java @@ -13,10 +13,6 @@ public class ApiDefinition implements Serializable { private String method; - private String protocol; - - private String path; - private String modulePath; private String environmentId; @@ -33,6 +29,10 @@ public class ApiDefinition implements Serializable { private Long updateTime; + private String protocol; + + private String path; + private Integer num; private String tags; @@ -51,8 +51,6 @@ public class ApiDefinition implements Serializable { private String deleteUserId; - private String followPeople; - private Long order; private static final long serialVersionUID = 1L; diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionExample.java b/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionExample.java index 26856dfe04..582094d6bd 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionExample.java @@ -384,146 +384,6 @@ public class ApiDefinitionExample { return (Criteria) this; } - public Criteria andProtocolIsNull() { - addCriterion("protocol is null"); - return (Criteria) this; - } - - public Criteria andProtocolIsNotNull() { - addCriterion("protocol is not null"); - return (Criteria) this; - } - - public Criteria andProtocolEqualTo(String value) { - addCriterion("protocol =", value, "protocol"); - return (Criteria) this; - } - - public Criteria andProtocolNotEqualTo(String value) { - addCriterion("protocol <>", value, "protocol"); - return (Criteria) this; - } - - public Criteria andProtocolGreaterThan(String value) { - addCriterion("protocol >", value, "protocol"); - return (Criteria) this; - } - - public Criteria andProtocolGreaterThanOrEqualTo(String value) { - addCriterion("protocol >=", value, "protocol"); - return (Criteria) this; - } - - public Criteria andProtocolLessThan(String value) { - addCriterion("protocol <", value, "protocol"); - return (Criteria) this; - } - - public Criteria andProtocolLessThanOrEqualTo(String value) { - addCriterion("protocol <=", value, "protocol"); - return (Criteria) this; - } - - public Criteria andProtocolLike(String value) { - addCriterion("protocol like", value, "protocol"); - return (Criteria) this; - } - - public Criteria andProtocolNotLike(String value) { - addCriterion("protocol not like", value, "protocol"); - return (Criteria) this; - } - - public Criteria andProtocolIn(List values) { - addCriterion("protocol in", values, "protocol"); - return (Criteria) this; - } - - public Criteria andProtocolNotIn(List values) { - addCriterion("protocol not in", values, "protocol"); - return (Criteria) this; - } - - public Criteria andProtocolBetween(String value1, String value2) { - addCriterion("protocol between", value1, value2, "protocol"); - return (Criteria) this; - } - - public Criteria andProtocolNotBetween(String value1, String value2) { - addCriterion("protocol not between", value1, value2, "protocol"); - return (Criteria) this; - } - - public Criteria andPathIsNull() { - addCriterion("`path` is null"); - return (Criteria) this; - } - - public Criteria andPathIsNotNull() { - addCriterion("`path` is not null"); - return (Criteria) this; - } - - public Criteria andPathEqualTo(String value) { - addCriterion("`path` =", value, "path"); - return (Criteria) this; - } - - public Criteria andPathNotEqualTo(String value) { - addCriterion("`path` <>", value, "path"); - return (Criteria) this; - } - - public Criteria andPathGreaterThan(String value) { - addCriterion("`path` >", value, "path"); - return (Criteria) this; - } - - public Criteria andPathGreaterThanOrEqualTo(String value) { - addCriterion("`path` >=", value, "path"); - return (Criteria) this; - } - - public Criteria andPathLessThan(String value) { - addCriterion("`path` <", value, "path"); - return (Criteria) this; - } - - public Criteria andPathLessThanOrEqualTo(String value) { - addCriterion("`path` <=", value, "path"); - return (Criteria) this; - } - - public Criteria andPathLike(String value) { - addCriterion("`path` like", value, "path"); - return (Criteria) this; - } - - public Criteria andPathNotLike(String value) { - addCriterion("`path` not like", value, "path"); - return (Criteria) this; - } - - public Criteria andPathIn(List values) { - addCriterion("`path` in", values, "path"); - return (Criteria) this; - } - - public Criteria andPathNotIn(List values) { - addCriterion("`path` not in", values, "path"); - return (Criteria) this; - } - - public Criteria andPathBetween(String value1, String value2) { - addCriterion("`path` between", value1, value2, "path"); - return (Criteria) this; - } - - public Criteria andPathNotBetween(String value1, String value2) { - addCriterion("`path` not between", value1, value2, "path"); - return (Criteria) this; - } - public Criteria andModulePathIsNull() { addCriterion("module_path is null"); return (Criteria) this; @@ -1064,6 +924,146 @@ public class ApiDefinitionExample { return (Criteria) this; } + public Criteria andProtocolIsNull() { + addCriterion("protocol is null"); + return (Criteria) this; + } + + public Criteria andProtocolIsNotNull() { + addCriterion("protocol is not null"); + return (Criteria) this; + } + + public Criteria andProtocolEqualTo(String value) { + addCriterion("protocol =", value, "protocol"); + return (Criteria) this; + } + + public Criteria andProtocolNotEqualTo(String value) { + addCriterion("protocol <>", value, "protocol"); + return (Criteria) this; + } + + public Criteria andProtocolGreaterThan(String value) { + addCriterion("protocol >", value, "protocol"); + return (Criteria) this; + } + + public Criteria andProtocolGreaterThanOrEqualTo(String value) { + addCriterion("protocol >=", value, "protocol"); + return (Criteria) this; + } + + public Criteria andProtocolLessThan(String value) { + addCriterion("protocol <", value, "protocol"); + return (Criteria) this; + } + + public Criteria andProtocolLessThanOrEqualTo(String value) { + addCriterion("protocol <=", value, "protocol"); + return (Criteria) this; + } + + public Criteria andProtocolLike(String value) { + addCriterion("protocol like", value, "protocol"); + return (Criteria) this; + } + + public Criteria andProtocolNotLike(String value) { + addCriterion("protocol not like", value, "protocol"); + return (Criteria) this; + } + + public Criteria andProtocolIn(List values) { + addCriterion("protocol in", values, "protocol"); + return (Criteria) this; + } + + public Criteria andProtocolNotIn(List values) { + addCriterion("protocol not in", values, "protocol"); + return (Criteria) this; + } + + public Criteria andProtocolBetween(String value1, String value2) { + addCriterion("protocol between", value1, value2, "protocol"); + return (Criteria) this; + } + + public Criteria andProtocolNotBetween(String value1, String value2) { + addCriterion("protocol not between", value1, value2, "protocol"); + return (Criteria) this; + } + + public Criteria andPathIsNull() { + addCriterion("`path` is null"); + return (Criteria) this; + } + + public Criteria andPathIsNotNull() { + addCriterion("`path` is not null"); + return (Criteria) this; + } + + public Criteria andPathEqualTo(String value) { + addCriterion("`path` =", value, "path"); + return (Criteria) this; + } + + public Criteria andPathNotEqualTo(String value) { + addCriterion("`path` <>", value, "path"); + return (Criteria) this; + } + + public Criteria andPathGreaterThan(String value) { + addCriterion("`path` >", value, "path"); + return (Criteria) this; + } + + public Criteria andPathGreaterThanOrEqualTo(String value) { + addCriterion("`path` >=", value, "path"); + return (Criteria) this; + } + + public Criteria andPathLessThan(String value) { + addCriterion("`path` <", value, "path"); + return (Criteria) this; + } + + public Criteria andPathLessThanOrEqualTo(String value) { + addCriterion("`path` <=", value, "path"); + return (Criteria) this; + } + + public Criteria andPathLike(String value) { + addCriterion("`path` like", value, "path"); + return (Criteria) this; + } + + public Criteria andPathNotLike(String value) { + addCriterion("`path` not like", value, "path"); + return (Criteria) this; + } + + public Criteria andPathIn(List values) { + addCriterion("`path` in", values, "path"); + return (Criteria) this; + } + + public Criteria andPathNotIn(List values) { + addCriterion("`path` not in", values, "path"); + return (Criteria) this; + } + + public Criteria andPathBetween(String value1, String value2) { + addCriterion("`path` between", value1, value2, "path"); + return (Criteria) this; + } + + public Criteria andPathNotBetween(String value1, String value2) { + addCriterion("`path` not between", value1, value2, "path"); + return (Criteria) this; + } + public Criteria andNumIsNull() { addCriterion("num is null"); return (Criteria) this; @@ -1674,76 +1674,6 @@ public class ApiDefinitionExample { 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 andOrderIsNull() { addCriterion("`order` is null"); return (Criteria) this; diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionWithBLOBs.java b/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionWithBLOBs.java index 38aa023e8b..cee14018bd 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionWithBLOBs.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionWithBLOBs.java @@ -18,4 +18,4 @@ public class ApiDefinitionWithBLOBs extends ApiDefinition implements Serializabl private String remark; private static final long serialVersionUID = 1L; -} +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionMapper.xml index 0d260750f3..6d417c0461 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionMapper.xml @@ -6,8 +6,6 @@ - - @@ -16,6 +14,8 @@ + + @@ -25,7 +25,6 @@ - @@ -93,10 +92,10 @@ - id, project_id, `name`, `method`, protocol, `path`, module_path, environment_id, - schedule, `status`, module_id, user_id, create_time, update_time, num, tags, original_state, - create_user, case_total, case_status, case_passing_rate, delete_time, delete_user_id, - follow_people, `order` + id, project_id, `name`, `method`, module_path, environment_id, schedule, `status`, + module_id, user_id, create_time, update_time, protocol, `path`, num, tags, original_state, + create_user, case_total, case_status, case_passing_rate, delete_time, delete_user_id, + `order` description, request, response, remark @@ -132,7 +131,7 @@