From 173b7ef59d3da8da9e4522b4adb2a286a9f87a18 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 17 Dec 2020 14:33:59 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=E6=8E=A5=E5=8F=A3=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E4=B8=8E=E6=8E=A5=E5=8F=A3=E7=94=A8=E4=BE=8B=E5=88=87?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/ApiTestCaseController.java | 24 +- .../api/dto/ApiCaseBatchRequest.java | 16 ++ .../api/dto/definition/ApiTestCaseDTO.java | 15 ++ .../dto/definition/ApiTestCaseRequest.java | 4 +- .../api/service/ApiTestCaseService.java | 56 +++-- .../base/mapper/ext/ExtApiTestCaseMapper.java | 3 +- .../base/mapper/ext/ExtApiTestCaseMapper.xml | 51 +++- .../base/mapper/ext/ExtUserMapper.java | 4 + .../base/mapper/ext/ExtUserMapper.xml | 10 + .../io/metersphere/service/UserService.java | 4 + .../api/definition/ApiDefinition.vue | 33 ++- .../components/case/ApiCaseHeader.vue | 17 +- .../components/case/ApiCaseItem.vue | 10 +- .../components/case/ApiCaseList.vue | 21 +- .../components/list/ApiCaseSimpleList.vue | 218 +++++++++--------- .../definition/components/list/ApiList.vue | 36 +-- .../components/list/ApiListContainer.vue | 33 +-- .../components/reference/ApiExtendBtns.vue | 5 +- .../api/definition/model/JsonData.js | 7 + .../components/common/components/MsDrawer.vue | 16 ++ 20 files changed, 381 insertions(+), 202 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/api/dto/ApiCaseBatchRequest.java create mode 100644 backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseDTO.java diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java b/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java index 7526d962ff..a50beb7728 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java @@ -2,9 +2,8 @@ package io.metersphere.api.controller; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; -import io.metersphere.api.dto.definition.ApiTestCaseRequest; -import io.metersphere.api.dto.definition.ApiTestCaseResult; -import io.metersphere.api.dto.definition.SaveApiTestCaseRequest; +import io.metersphere.api.dto.ApiCaseBatchRequest; +import io.metersphere.api.dto.definition.*; import io.metersphere.api.service.ApiTestCaseService; import io.metersphere.base.domain.ApiTestCase; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; @@ -35,7 +34,7 @@ public class ApiTestCaseController { } @PostMapping("/list/{goPage}/{pageSize}") - public Pager> listSimple(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiTestCaseRequest request) { + public Pager> listSimple(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiTestCaseRequest request) { Page page = PageHelper.startPage(goPage, pageSize, true); request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); return PageUtils.setPageInfo(page, apiTestCaseService.listSimple(request)); @@ -56,9 +55,24 @@ public class ApiTestCaseController { apiTestCaseService.delete(id); } + @PostMapping("/removeToGc") + public void removeToGc(@RequestBody List ids) { + apiTestCaseService.removeToGc(ids); + } + @GetMapping("/get/{id}") public ApiTestCaseWithBLOBs get(@PathVariable String id) { return apiTestCaseService.get(id); } -} + @PostMapping("/batch/edit") + @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) + public void editApiBath(@RequestBody ApiCaseBatchRequest request) { + apiTestCaseService.editApiBath(request); + } + + @PostMapping("/deleteBatch") + public void deleteBatch(@RequestBody List ids) { + apiTestCaseService.deleteBatch(ids); + } +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/api/dto/ApiCaseBatchRequest.java b/backend/src/main/java/io/metersphere/api/dto/ApiCaseBatchRequest.java new file mode 100644 index 0000000000..39fd0c6ee3 --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/dto/ApiCaseBatchRequest.java @@ -0,0 +1,16 @@ +package io.metersphere.api.dto; + +import io.metersphere.base.domain.ApiTestCaseWithBLOBs; +import io.metersphere.controller.request.OrderRequest; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Getter +@Setter +public class ApiCaseBatchRequest extends ApiTestCaseWithBLOBs { + private List ids; + private List orders; + private String projectId; +} diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseDTO.java b/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseDTO.java new file mode 100644 index 0000000000..efd86e9618 --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseDTO.java @@ -0,0 +1,15 @@ +package io.metersphere.api.dto.definition; + +import io.metersphere.base.domain.ApiTestCase; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ApiTestCaseDTO extends ApiTestCase { + private String moduleId; + private String path; + private String protocol; + private String updateUser; + private String createUser; +} diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseRequest.java b/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseRequest.java index a5deab6105..4624c78f0d 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseRequest.java @@ -5,11 +5,11 @@ import lombok.Getter; import lombok.Setter; import java.util.List; +import java.util.Map; @Getter @Setter public class ApiTestCaseRequest { - private String id; private String projectId; private String priority; @@ -17,6 +17,8 @@ public class ApiTestCaseRequest { private String environmentId; private String workspaceId; private String apiDefinitionId; + private String status; private List moduleIds; private List orders; + private Map> filters; } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java index 81e168e44d..09cb797a07 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -1,23 +1,20 @@ package io.metersphere.api.service; import com.alibaba.fastjson.JSONObject; -import io.metersphere.api.dto.definition.ApiDefinitionRequest; -import io.metersphere.api.dto.definition.ApiTestCaseRequest; -import io.metersphere.api.dto.definition.ApiTestCaseResult; -import io.metersphere.api.dto.definition.SaveApiTestCaseRequest; +import io.metersphere.api.dto.ApiCaseBatchRequest; +import io.metersphere.api.dto.definition.*; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiTestCaseMapper; import io.metersphere.base.mapper.ApiTestFileMapper; import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper; import io.metersphere.commons.exception.MSException; -import io.metersphere.commons.utils.CommonBeanFactory; -import io.metersphere.commons.utils.LogUtil; -import io.metersphere.commons.utils.ServiceUtils; -import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.commons.utils.*; import io.metersphere.i18n.Translator; +import io.metersphere.notice.domain.UserDetail; import io.metersphere.service.FileService; import io.metersphere.service.QuotaService; +import io.metersphere.service.UserService; import org.aspectj.util.FileUtil; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -26,10 +23,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.*; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; @Service @@ -38,6 +32,8 @@ public class ApiTestCaseService { @Resource private ApiTestCaseMapper apiTestCaseMapper; @Resource + private UserService userService; + @Resource private ExtApiTestCaseMapper extApiTestCaseMapper; @Resource private ApiTestFileMapper apiTestFileMapper; @@ -53,9 +49,22 @@ public class ApiTestCaseService { return extApiTestCaseMapper.list(request); } - public List listSimple(ApiTestCaseRequest request) { + public List listSimple(ApiTestCaseRequest request) { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); - List apiTestCases = extApiTestCaseMapper.listSimple(request); + List apiTestCases = extApiTestCaseMapper.listSimple(request); + if (CollectionUtils.isEmpty(apiTestCases)) { + return apiTestCases; + } + List userIds = new ArrayList(); + userIds.addAll(apiTestCases.stream().map(ApiTestCaseDTO::getCreateUserId).collect(Collectors.toList())); + userIds.addAll(apiTestCases.stream().map(ApiTestCaseDTO::getUpdateUserId).collect(Collectors.toList())); + if (!CollectionUtils.isEmpty(userIds)) { + Map userMap = userService.queryNameByIds(userIds); + apiTestCases.forEach(caseResult -> { + caseResult.setCreateUser(userMap.get(caseResult.getCreateUserId()).getName()); + caseResult.setUpdateUser(userMap.get(caseResult.getUpdateUserId()).getName()); + }); + } return apiTestCases; } @@ -215,4 +224,23 @@ public class ApiTestCaseService { fileService.deleteFileByIds(fileIds); } } + + public void removeToGc(List ids) { + // todo + } + + public void editApiBath(ApiCaseBatchRequest request) { + ApiTestCaseExample apiDefinitionExample = new ApiTestCaseExample(); + apiDefinitionExample.createCriteria().andIdIn(request.getIds()); + ApiTestCaseWithBLOBs apiDefinitionWithBLOBs = new ApiTestCaseWithBLOBs(); + BeanUtils.copyBean(apiDefinitionWithBLOBs, request); + apiDefinitionWithBLOBs.setUpdateTime(System.currentTimeMillis()); + apiTestCaseMapper.updateByExampleSelective(apiDefinitionWithBLOBs, apiDefinitionExample); + } + + public void deleteBatch(List ids) { + ApiTestCaseExample example = new ApiTestCaseExample(); + example.createCriteria().andIdIn(ids); + apiTestCaseMapper.deleteByExample(example); + } } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java index 3252a00ebf..923ab6c415 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java @@ -1,5 +1,6 @@ package io.metersphere.base.mapper.ext; +import io.metersphere.api.dto.definition.ApiTestCaseDTO; import io.metersphere.api.dto.definition.ApiTestCaseRequest; import io.metersphere.api.dto.definition.ApiTestCaseResult; import io.metersphere.base.domain.ApiTestCase; @@ -10,5 +11,5 @@ import java.util.List; public interface ExtApiTestCaseMapper { List list(@Param("request") ApiTestCaseRequest request); - List listSimple(@Param("request") ApiTestCaseRequest request); + List listSimple(@Param("request") ApiTestCaseRequest request); } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml index 3eed364772..8cbc422e11 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml @@ -208,19 +208,54 @@ - select - c.id, c.project_id, c.name, c.api_definition_id, c.priority, c.description, c.create_user_id, c.update_user_id, c.create_time, c.update_time, - a.moudule_id as moudule_id, - from api_test_case c - left join api_definition a - on c.api_definition_id = a.id - where c.project_id = #{request.projectId} + c.id, c.project_id, c.name, c.api_definition_id, c.priority, c.description, c.create_user_id, c.update_user_id, c.create_time, c.update_time, + a.module_id, a.path, a.protocol + from + api_test_case c + inner join + api_definition a + on + c.api_definition_id = a.id + + + and a.status = 'Trash' + + + and a.status != 'Trash' + + + where + c.project_id = #{request.projectId} + + and c.name like CONCAT('%', #{request.name},'%') + - AND a.module_id in + and a.module_id in #{nodeId} + + + + + + and c.priority in + + #{value} + + + + + + + + order by + + ${order.name} ${order.type} + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.java index d570f56a6b..b6f09dbdd3 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.java @@ -3,9 +3,11 @@ package io.metersphere.base.mapper.ext; import io.metersphere.base.domain.User; import io.metersphere.controller.request.UserRequest; import io.metersphere.notice.domain.UserDetail; +import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Param; import java.util.List; +import java.util.Map; public interface ExtUserMapper { @@ -19,4 +21,6 @@ public interface ExtUserMapper { List queryTypeByIds(List userIds); + @MapKey("id") + Map queryNameByIds(List userIds); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.xml index 40c52efe9a..d772524bf6 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.xml @@ -62,4 +62,14 @@ select id, name, email, last_organization_id, last_workspace_id from `user` where id like CONCAT('%', #{condition},'%') or email like CONCAT('%', #{condition},'%') limit 100; + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index 9b5ea35e7e..c0e1228fc4 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -66,6 +66,10 @@ public class UserService { return extUserMapper.queryTypeByIds(userIds); } + public Map queryNameByIds(List userIds) { + return extUserMapper.queryNameByIds(userIds); + } + /* public List queryEmailByIds(List userIds) { return extUserMapper.queryTypeByIds(userIds); }*/ diff --git a/frontend/src/business/components/api/definition/ApiDefinition.vue b/frontend/src/business/components/api/definition/ApiDefinition.vue index ca61566c45..39ee408a7b 100644 --- a/frontend/src/business/components/api/definition/ApiDefinition.vue +++ b/frontend/src/business/components/api/definition/ApiDefinition.vue @@ -35,26 +35,31 @@ :name="item.name"> + + - - - - - - - - - -
@@ -147,6 +152,7 @@ type: "list", closable: false }], + isApiListEnable: true } }, watch: { @@ -155,6 +161,9 @@ } }, methods: { + isApiListEnableChange(data) { + this.isApiListEnable = data; + }, handleCommand(e) { switch (e) { case "ADD": @@ -241,7 +250,7 @@ downloadFile("导出API.json", JSON.stringify(obj)); }, refresh(data) { - this.$refs.apiList[0].initApiTable(data); + this.$refs.apiList[0].initTable(data); }, setTabTitle(data) { for (let index in this.apiTabs) { diff --git a/frontend/src/business/components/api/definition/components/case/ApiCaseHeader.vue b/frontend/src/business/components/api/definition/components/case/ApiCaseHeader.vue index 7967a0ce89..7bc2c33732 100644 --- a/frontend/src/business/components/api/definition/components/case/ApiCaseHeader.vue +++ b/frontend/src/business/components/api/definition/components/case/ApiCaseHeader.vue @@ -13,12 +13,13 @@
{{api.path ===null ? " " : api.path}}
- +
{{$t('test_track.plan_view.case_count')}}:{{apiCaseList.length}}
@@ -48,25 +49,19 @@
- +{{$t('api_test.definition.request.case')}} {{$t('commons.test')}} - - - - - - @@ -95,6 +90,7 @@ priorities: Array, apiCaseList: Array, isReadOnly: Boolean, + isCaseEdit: Boolean, condition: { type: Object, default() { @@ -145,9 +141,6 @@ getApiTest() { this.$emit('getApiTest'); }, - close() { - this.$emit('close'); - }, addCase() { this.$emit('addCase'); }, diff --git a/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue b/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue index 0ca889dffa..f134b424ef 100644 --- a/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue +++ b/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue @@ -37,10 +37,10 @@ + size="mini" :disabled="!apiCase.id || isCaseEdit" circle/> - + size="mini" :disabled="!apiCase.id || isCaseEdit" circle/> + @@ -85,7 +85,6 @@ import MsDubboBasisParameters from "../request/dubbo/BasisParameters"; import MsApiExtendBtns from "../reference/ApiExtendBtns"; - export default { name: "ApiCaseItem", components: { @@ -132,7 +131,8 @@ default() { return {} } - } + }, + isCaseEdit: Boolean, }, watch: { }, diff --git a/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue b/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue index bacbd09dee..becad3df8e 100644 --- a/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue +++ b/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue @@ -1,12 +1,11 @@