From af918239d2cab96d6d1baadd6df174c9499589c2 Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Thu, 5 Sep 2024 16:09:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E8=A7=86=E5=9B=BE=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --task=1016128 --user=陈建星 高级搜索-视图增删改查-后端 https://www.tapd.cn/55049933/s/1573254 --- .../system/constants/InternalUserView.java | 5 ++- .../system/controller/UserViewController.java | 4 +-- .../metersphere/system/dto/UserViewDTO.java | 2 -- .../system/dto/UserViewListDTO.java | 15 --------- .../system/dto/UserViewListGroupedDTO.java | 5 +-- .../system/service/UserViewService.java | 33 +++++++++---------- .../controller/UserViewControllerTests.java | 21 +++++------- 7 files changed, 32 insertions(+), 53 deletions(-) delete mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserViewListDTO.java diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/constants/InternalUserView.java b/backend/services/system-setting/src/main/java/io/metersphere/system/constants/InternalUserView.java index 306cef410d..bbb93ff1b8 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/constants/InternalUserView.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/constants/InternalUserView.java @@ -29,7 +29,7 @@ public enum InternalUserView { MY_CREATE(() -> { UserViewDTO userViewDTO = getUserViewDTO("my_create"); CombineCondition condition = new CombineCondition(); - condition.setName("create_user"); + condition.setName("createUser"); condition.setValue(getCurrentUserValue()); condition.setOperator(CombineCondition.CombineConditionOperator.IN.name()); userViewDTO.setConditions(List.of(condition)); @@ -38,7 +38,7 @@ public enum InternalUserView { MY_REVIEW(() -> { UserViewDTO userViewDTO = getUserViewDTO("my_review"); CombineCondition condition = new CombineCondition(); - condition.setName("review_user"); + condition.setName("reviewUser"); condition.setValue(getCurrentUserValue()); condition.setOperator(CombineCondition.CombineConditionOperator.IN.name()); userViewDTO.setConditions(List.of(condition)); @@ -50,7 +50,6 @@ public enum InternalUserView { userViewDTO.setSearchMode(CombineSearch.SearchMode.AND.name()); userViewDTO.setName(name); userViewDTO.setId(name); - userViewDTO.setInternalViewKey(name.toUpperCase()); return userViewDTO; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserViewController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserViewController.java index 6d19558681..9227e81b2b 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserViewController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserViewController.java @@ -1,8 +1,8 @@ package io.metersphere.system.controller; import io.metersphere.system.constants.UserViewType; +import io.metersphere.system.domain.UserView; import io.metersphere.system.dto.UserViewDTO; -import io.metersphere.system.dto.UserViewListDTO; import io.metersphere.system.dto.UserViewListGroupedDTO; import io.metersphere.system.dto.request.UserViewAddRequest; import io.metersphere.system.dto.request.UserViewUpdateRequest; @@ -29,7 +29,7 @@ public class UserViewController { @GetMapping("/{viewType}/list") @Operation(summary = "视图列表") - public List list(@RequestParam String scopeId, @PathVariable String viewType) { + public List list(@RequestParam String scopeId, @PathVariable String viewType) { UserViewType userViewType = UserViewType.getByValue(viewType); return userViewService.list(scopeId, userViewType, SessionUtils.getUserId()); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserViewDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserViewDTO.java index 012d1824dd..e8bf380fc9 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserViewDTO.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserViewDTO.java @@ -17,8 +17,6 @@ import java.util.List; @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class UserViewDTO extends UserView { - @Schema(description = "内置视图的 key") - private String internalViewKey; @Schema(description = "筛选条件") private List conditions; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserViewListDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserViewListDTO.java deleted file mode 100644 index bfb2600256..0000000000 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserViewListDTO.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.metersphere.system.dto; - -import io.metersphere.system.domain.UserView; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -/** - * @Author: jianxing - * @CreateTime: 2024-09-02 10:15 - */ -@Data -public class UserViewListDTO extends UserView { - @Schema(description = "内置视图的 key") - private String internalViewKey; -} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserViewListGroupedDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserViewListGroupedDTO.java index 904c06ea56..77b869435f 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserViewListGroupedDTO.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserViewListGroupedDTO.java @@ -1,5 +1,6 @@ package io.metersphere.system.dto; +import io.metersphere.system.domain.UserView; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -12,7 +13,7 @@ import java.util.List; @Data public class UserViewListGroupedDTO { @Schema(description = "系统视图") - private List internalViews; + private List internalViews; @Schema(description = "自定义视图") - private List customViews; + private List customViews; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserViewService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserViewService.java index 903325af72..55142ba296 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserViewService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserViewService.java @@ -13,7 +13,6 @@ import io.metersphere.system.domain.UserViewCondition; import io.metersphere.system.domain.UserViewConditionExample; import io.metersphere.system.domain.UserViewExample; import io.metersphere.system.dto.UserViewDTO; -import io.metersphere.system.dto.UserViewListDTO; import io.metersphere.system.dto.UserViewListGroupedDTO; import io.metersphere.system.dto.request.UserViewAddRequest; import io.metersphere.system.dto.request.UserViewUpdateRequest; @@ -50,7 +49,7 @@ public class UserViewService { public static final Long POS_STEP = 5000L; - public List list(String scopeId, UserViewType viewType, String userId) { + public List list(String scopeId, UserViewType viewType, String userId) { UserViewListGroupedDTO userViews = groupedList(scopeId, viewType, userId); userViews.getCustomViews().addAll(userViews.getInternalViews()); return userViews.getCustomViews(); @@ -129,16 +128,17 @@ public class UserViewService { } } - private void checkUpdateExist(String name, String scopeId, String viewType, String userId) { + private void checkUpdateExist(String name, UserView orginUserView, String userId) { if (StringUtils.isBlank(name)) { return; } UserViewExample example = new UserViewExample(); example.createCriteria() .andUserIdEqualTo(userId) - .andScopeIdEqualTo(scopeId) - .andViewTypeEqualTo(viewType) - .andNameEqualTo(name); + .andScopeIdEqualTo(orginUserView.getScopeId()) + .andViewTypeEqualTo(orginUserView.getViewType()) + .andNameEqualTo(name) + .andIdNotEqualTo(orginUserView.getId()); if (userViewMapper.countByExample(example) > 0) { throw new MSException(USER_VIEW_EXIST); } @@ -221,7 +221,7 @@ public class UserViewService { UserView originUserView = userViewMapper.selectByPrimaryKey(request.getId()); // 校验权限,只能修改自己的视图 checkOwner(userId, originUserView); - checkUpdateExist(request.getName(), originUserView.getScopeId(), viewType, userId); + checkUpdateExist(request.getName(), originUserView, userId); UserView userView = BeanUtils.copyBean(new UserView(), request); userView.setViewType(viewType); @@ -260,14 +260,14 @@ public class UserViewService { public UserViewListGroupedDTO groupedList(String scopeId, UserViewType viewType, String userId) { // 查询系统内置视图 - List internalViews = viewType.getInternalViews().stream().map(userViewEnum -> { - UserViewDTO userView = userViewEnum.getUserView(); - UserViewListDTO userViewListDTO = BeanUtils.copyBean(new UserViewListDTO(), userView); - userViewListDTO.setName(translateInternalView(userView.getName())); - userViewListDTO.setViewType(viewType.name()); - userViewListDTO.setScopeId(scopeId); - userViewListDTO.setUserId(userId); - return userViewListDTO; + List internalViews = viewType.getInternalViews().stream().map(userViewEnum -> { + UserViewDTO userViewDTO = userViewEnum.getUserView(); + UserView userView = BeanUtils.copyBean(new UserView(), userViewDTO); + userView.setName(translateInternalView(userViewDTO.getName())); + userView.setViewType(viewType.name()); + userView.setScopeId(scopeId); + userView.setUserId(userId); + return userView; }).collect(Collectors.toList()); // 查询用户自定义视图 @@ -276,9 +276,8 @@ public class UserViewService { .andUserIdEqualTo(userId) .andScopeIdEqualTo(scopeId) .andViewTypeEqualTo(viewType.name()); - List customUserViews = userViewMapper.selectByExample(example).stream() + List customUserViews = userViewMapper.selectByExample(example).stream() .sorted(Comparator.comparing(UserView::getPos)) - .map(userView -> BeanUtils.copyBean(new UserViewListDTO(), userView)) .collect(Collectors.toList()); UserViewListGroupedDTO groupedDTO = new UserViewListGroupedDTO(); diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/UserViewControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/UserViewControllerTests.java index ccb37261c8..ef8e600871 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/UserViewControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/UserViewControllerTests.java @@ -5,8 +5,8 @@ import io.metersphere.sdk.util.BeanUtils; import io.metersphere.system.base.BaseTest; import io.metersphere.system.constants.InternalUserView; import io.metersphere.system.constants.UserViewType; +import io.metersphere.system.domain.UserView; import io.metersphere.system.dto.UserViewDTO; -import io.metersphere.system.dto.UserViewListDTO; import io.metersphere.system.dto.UserViewListGroupedDTO; import io.metersphere.system.dto.request.UserViewAddRequest; import io.metersphere.system.dto.request.UserViewUpdateRequest; @@ -52,24 +52,21 @@ public class UserViewControllerTests extends BaseTest { public void emptyList() throws Exception { // @@请求成功 MvcResult mvcResult = this.requestGetWithOkAndReturn(LIST, DEFAULT_PROJECT_ID); - List result = getResultDataArray(mvcResult, UserViewListDTO.class); + List result = getResultDataArray(mvcResult, UserView.class); Assertions.assertEquals(result.size(), 3); - UserViewListDTO allData = result.get(0); + UserView allData = result.get(0); Assertions.assertEquals(allData.getName(), "全部数据"); - Assertions.assertEquals(allData.getInternalViewKey(), InternalUserView.ALL_DATA.name()); Assertions.assertEquals(allData.getId(), InternalUserView.ALL_DATA.name().toLowerCase()); - UserViewListDTO myFollow = result.get(1); + UserView myFollow = result.get(1); Assertions.assertEquals(myFollow.getName(), "我关注的"); - Assertions.assertEquals(myFollow.getInternalViewKey(), InternalUserView.MY_FOLLOW.name()); Assertions.assertEquals(myFollow.getId(), InternalUserView.MY_FOLLOW.name().toLowerCase()); - UserViewListDTO myCreate = result.get(2); + UserView myCreate = result.get(2); Assertions.assertEquals(myCreate.getName(), "我创建的"); - Assertions.assertEquals(myCreate.getInternalViewKey(), InternalUserView.MY_CREATE.name()); Assertions.assertEquals(myCreate.getId(), InternalUserView.MY_CREATE.name().toLowerCase()); - for (UserViewListDTO item : result) { + for (UserView item : result) { Assertions.assertEquals(item.getScopeId(), DEFAULT_PROJECT_ID); Assertions.assertEquals(item.getUserId(), InternalUser.ADMIN.getValue()); Assertions.assertEquals(item.getSearchMode(), CombineSearch.SearchMode.AND.name()); @@ -134,12 +131,13 @@ public class UserViewControllerTests extends BaseTest { @Order(3) public void update() throws Exception { UserViewUpdateRequest request = BeanUtils.copyBean(new UserViewUpdateRequest(), addUserViewDTO); - request.setName(UUID.randomUUID().toString()); request.setSearchMode(CombineSearch.SearchMode.OR.name()); request.getConditions().get(0).setName(UUID.randomUUID().toString()); // @@请求成功 MvcResult mvcResult = this.requestPostWithOkAndReturn(DEFAULT_UPDATE, request); + request.setName(UUID.randomUUID().toString()); + mvcResult = this.requestPostWithOkAndReturn(DEFAULT_UPDATE, request); addUserViewDTO = getResultData(mvcResult, UserViewDTO.class); addUserViewDTO.setConditions(request.getConditions()); UserViewDTO userViewDTO = userViewService.get(addUserViewDTO.getId(), UserViewType.FUNCTIONAL_CASE, InternalUser.ADMIN.getValue()); @@ -167,7 +165,6 @@ public class UserViewControllerTests extends BaseTest { mvcResult = this.requestGetWithOkAndReturn(DEFAULT_GET, InternalUserView.ALL_DATA.name()); resultData = getResultData(mvcResult, UserViewDTO.class); Assertions.assertEquals(resultData.getName(), "全部数据"); - Assertions.assertEquals(resultData.getInternalViewKey(), InternalUserView.ALL_DATA.name()); Assertions.assertEquals(resultData.getId(), InternalUserView.ALL_DATA.name().toLowerCase()); Assertions.assertEquals(resultData.getConditions().size(), 0); } @@ -179,7 +176,7 @@ public class UserViewControllerTests extends BaseTest { UserViewListGroupedDTO result = getResultData(mvcResult, UserViewListGroupedDTO.class); Assertions.assertEquals(result.getInternalViews().size(), 3); Assertions.assertEquals(result.getCustomViews().size(), 2); - Assertions.assertEquals(result.getCustomViews().get(0), BeanUtils.copyBean(new UserViewListDTO(), addUserViewDTO)); + Assertions.assertEquals(result.getCustomViews().get(0), BeanUtils.copyBean(new UserView(), addUserViewDTO)); } @Test