fix(系统设置): 编辑视图报错
--task=1016128 --user=陈建星 高级搜索-视图增删改查-后端 https://www.tapd.cn/55049933/s/1573254
This commit is contained in:
parent
04eb54b3e6
commit
af918239d2
|
@ -29,7 +29,7 @@ public enum InternalUserView {
|
||||||
MY_CREATE(() -> {
|
MY_CREATE(() -> {
|
||||||
UserViewDTO userViewDTO = getUserViewDTO("my_create");
|
UserViewDTO userViewDTO = getUserViewDTO("my_create");
|
||||||
CombineCondition condition = new CombineCondition();
|
CombineCondition condition = new CombineCondition();
|
||||||
condition.setName("create_user");
|
condition.setName("createUser");
|
||||||
condition.setValue(getCurrentUserValue());
|
condition.setValue(getCurrentUserValue());
|
||||||
condition.setOperator(CombineCondition.CombineConditionOperator.IN.name());
|
condition.setOperator(CombineCondition.CombineConditionOperator.IN.name());
|
||||||
userViewDTO.setConditions(List.of(condition));
|
userViewDTO.setConditions(List.of(condition));
|
||||||
|
@ -38,7 +38,7 @@ public enum InternalUserView {
|
||||||
MY_REVIEW(() -> {
|
MY_REVIEW(() -> {
|
||||||
UserViewDTO userViewDTO = getUserViewDTO("my_review");
|
UserViewDTO userViewDTO = getUserViewDTO("my_review");
|
||||||
CombineCondition condition = new CombineCondition();
|
CombineCondition condition = new CombineCondition();
|
||||||
condition.setName("review_user");
|
condition.setName("reviewUser");
|
||||||
condition.setValue(getCurrentUserValue());
|
condition.setValue(getCurrentUserValue());
|
||||||
condition.setOperator(CombineCondition.CombineConditionOperator.IN.name());
|
condition.setOperator(CombineCondition.CombineConditionOperator.IN.name());
|
||||||
userViewDTO.setConditions(List.of(condition));
|
userViewDTO.setConditions(List.of(condition));
|
||||||
|
@ -50,7 +50,6 @@ public enum InternalUserView {
|
||||||
userViewDTO.setSearchMode(CombineSearch.SearchMode.AND.name());
|
userViewDTO.setSearchMode(CombineSearch.SearchMode.AND.name());
|
||||||
userViewDTO.setName(name);
|
userViewDTO.setName(name);
|
||||||
userViewDTO.setId(name);
|
userViewDTO.setId(name);
|
||||||
userViewDTO.setInternalViewKey(name.toUpperCase());
|
|
||||||
return userViewDTO;
|
return userViewDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package io.metersphere.system.controller;
|
package io.metersphere.system.controller;
|
||||||
|
|
||||||
import io.metersphere.system.constants.UserViewType;
|
import io.metersphere.system.constants.UserViewType;
|
||||||
|
import io.metersphere.system.domain.UserView;
|
||||||
import io.metersphere.system.dto.UserViewDTO;
|
import io.metersphere.system.dto.UserViewDTO;
|
||||||
import io.metersphere.system.dto.UserViewListDTO;
|
|
||||||
import io.metersphere.system.dto.UserViewListGroupedDTO;
|
import io.metersphere.system.dto.UserViewListGroupedDTO;
|
||||||
import io.metersphere.system.dto.request.UserViewAddRequest;
|
import io.metersphere.system.dto.request.UserViewAddRequest;
|
||||||
import io.metersphere.system.dto.request.UserViewUpdateRequest;
|
import io.metersphere.system.dto.request.UserViewUpdateRequest;
|
||||||
|
@ -29,7 +29,7 @@ public class UserViewController {
|
||||||
|
|
||||||
@GetMapping("/{viewType}/list")
|
@GetMapping("/{viewType}/list")
|
||||||
@Operation(summary = "视图列表")
|
@Operation(summary = "视图列表")
|
||||||
public List<UserViewListDTO> list(@RequestParam String scopeId, @PathVariable String viewType) {
|
public List<UserView> list(@RequestParam String scopeId, @PathVariable String viewType) {
|
||||||
UserViewType userViewType = UserViewType.getByValue(viewType);
|
UserViewType userViewType = UserViewType.getByValue(viewType);
|
||||||
return userViewService.list(scopeId, userViewType, SessionUtils.getUserId());
|
return userViewService.list(scopeId, userViewType, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,6 @@ import java.util.List;
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
public class UserViewDTO extends UserView {
|
public class UserViewDTO extends UserView {
|
||||||
@Schema(description = "内置视图的 key")
|
|
||||||
private String internalViewKey;
|
|
||||||
@Schema(description = "筛选条件")
|
@Schema(description = "筛选条件")
|
||||||
private List<CombineCondition> conditions;
|
private List<CombineCondition> conditions;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -1,5 +1,6 @@
|
||||||
package io.metersphere.system.dto;
|
package io.metersphere.system.dto;
|
||||||
|
|
||||||
|
import io.metersphere.system.domain.UserView;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ import java.util.List;
|
||||||
@Data
|
@Data
|
||||||
public class UserViewListGroupedDTO {
|
public class UserViewListGroupedDTO {
|
||||||
@Schema(description = "系统视图")
|
@Schema(description = "系统视图")
|
||||||
private List<UserViewListDTO> internalViews;
|
private List<UserView> internalViews;
|
||||||
@Schema(description = "自定义视图")
|
@Schema(description = "自定义视图")
|
||||||
private List<UserViewListDTO> customViews;
|
private List<UserView> customViews;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import io.metersphere.system.domain.UserViewCondition;
|
||||||
import io.metersphere.system.domain.UserViewConditionExample;
|
import io.metersphere.system.domain.UserViewConditionExample;
|
||||||
import io.metersphere.system.domain.UserViewExample;
|
import io.metersphere.system.domain.UserViewExample;
|
||||||
import io.metersphere.system.dto.UserViewDTO;
|
import io.metersphere.system.dto.UserViewDTO;
|
||||||
import io.metersphere.system.dto.UserViewListDTO;
|
|
||||||
import io.metersphere.system.dto.UserViewListGroupedDTO;
|
import io.metersphere.system.dto.UserViewListGroupedDTO;
|
||||||
import io.metersphere.system.dto.request.UserViewAddRequest;
|
import io.metersphere.system.dto.request.UserViewAddRequest;
|
||||||
import io.metersphere.system.dto.request.UserViewUpdateRequest;
|
import io.metersphere.system.dto.request.UserViewUpdateRequest;
|
||||||
|
@ -50,7 +49,7 @@ public class UserViewService {
|
||||||
|
|
||||||
public static final Long POS_STEP = 5000L;
|
public static final Long POS_STEP = 5000L;
|
||||||
|
|
||||||
public List<UserViewListDTO> list(String scopeId, UserViewType viewType, String userId) {
|
public List<UserView> list(String scopeId, UserViewType viewType, String userId) {
|
||||||
UserViewListGroupedDTO userViews = groupedList(scopeId, viewType, userId);
|
UserViewListGroupedDTO userViews = groupedList(scopeId, viewType, userId);
|
||||||
userViews.getCustomViews().addAll(userViews.getInternalViews());
|
userViews.getCustomViews().addAll(userViews.getInternalViews());
|
||||||
return userViews.getCustomViews();
|
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)) {
|
if (StringUtils.isBlank(name)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UserViewExample example = new UserViewExample();
|
UserViewExample example = new UserViewExample();
|
||||||
example.createCriteria()
|
example.createCriteria()
|
||||||
.andUserIdEqualTo(userId)
|
.andUserIdEqualTo(userId)
|
||||||
.andScopeIdEqualTo(scopeId)
|
.andScopeIdEqualTo(orginUserView.getScopeId())
|
||||||
.andViewTypeEqualTo(viewType)
|
.andViewTypeEqualTo(orginUserView.getViewType())
|
||||||
.andNameEqualTo(name);
|
.andNameEqualTo(name)
|
||||||
|
.andIdNotEqualTo(orginUserView.getId());
|
||||||
if (userViewMapper.countByExample(example) > 0) {
|
if (userViewMapper.countByExample(example) > 0) {
|
||||||
throw new MSException(USER_VIEW_EXIST);
|
throw new MSException(USER_VIEW_EXIST);
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ public class UserViewService {
|
||||||
UserView originUserView = userViewMapper.selectByPrimaryKey(request.getId());
|
UserView originUserView = userViewMapper.selectByPrimaryKey(request.getId());
|
||||||
// 校验权限,只能修改自己的视图
|
// 校验权限,只能修改自己的视图
|
||||||
checkOwner(userId, originUserView);
|
checkOwner(userId, originUserView);
|
||||||
checkUpdateExist(request.getName(), originUserView.getScopeId(), viewType, userId);
|
checkUpdateExist(request.getName(), originUserView, userId);
|
||||||
|
|
||||||
UserView userView = BeanUtils.copyBean(new UserView(), request);
|
UserView userView = BeanUtils.copyBean(new UserView(), request);
|
||||||
userView.setViewType(viewType);
|
userView.setViewType(viewType);
|
||||||
|
@ -260,14 +260,14 @@ public class UserViewService {
|
||||||
|
|
||||||
public UserViewListGroupedDTO groupedList(String scopeId, UserViewType viewType, String userId) {
|
public UserViewListGroupedDTO groupedList(String scopeId, UserViewType viewType, String userId) {
|
||||||
// 查询系统内置视图
|
// 查询系统内置视图
|
||||||
List<UserViewListDTO> internalViews = viewType.getInternalViews().stream().map(userViewEnum -> {
|
List<UserView> internalViews = viewType.getInternalViews().stream().map(userViewEnum -> {
|
||||||
UserViewDTO userView = userViewEnum.getUserView();
|
UserViewDTO userViewDTO = userViewEnum.getUserView();
|
||||||
UserViewListDTO userViewListDTO = BeanUtils.copyBean(new UserViewListDTO(), userView);
|
UserView userView = BeanUtils.copyBean(new UserView(), userViewDTO);
|
||||||
userViewListDTO.setName(translateInternalView(userView.getName()));
|
userView.setName(translateInternalView(userViewDTO.getName()));
|
||||||
userViewListDTO.setViewType(viewType.name());
|
userView.setViewType(viewType.name());
|
||||||
userViewListDTO.setScopeId(scopeId);
|
userView.setScopeId(scopeId);
|
||||||
userViewListDTO.setUserId(userId);
|
userView.setUserId(userId);
|
||||||
return userViewListDTO;
|
return userView;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
// 查询用户自定义视图
|
// 查询用户自定义视图
|
||||||
|
@ -276,9 +276,8 @@ public class UserViewService {
|
||||||
.andUserIdEqualTo(userId)
|
.andUserIdEqualTo(userId)
|
||||||
.andScopeIdEqualTo(scopeId)
|
.andScopeIdEqualTo(scopeId)
|
||||||
.andViewTypeEqualTo(viewType.name());
|
.andViewTypeEqualTo(viewType.name());
|
||||||
List<UserViewListDTO> customUserViews = userViewMapper.selectByExample(example).stream()
|
List<UserView> customUserViews = userViewMapper.selectByExample(example).stream()
|
||||||
.sorted(Comparator.comparing(UserView::getPos))
|
.sorted(Comparator.comparing(UserView::getPos))
|
||||||
.map(userView -> BeanUtils.copyBean(new UserViewListDTO(), userView))
|
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
UserViewListGroupedDTO groupedDTO = new UserViewListGroupedDTO();
|
UserViewListGroupedDTO groupedDTO = new UserViewListGroupedDTO();
|
||||||
|
|
|
@ -5,8 +5,8 @@ import io.metersphere.sdk.util.BeanUtils;
|
||||||
import io.metersphere.system.base.BaseTest;
|
import io.metersphere.system.base.BaseTest;
|
||||||
import io.metersphere.system.constants.InternalUserView;
|
import io.metersphere.system.constants.InternalUserView;
|
||||||
import io.metersphere.system.constants.UserViewType;
|
import io.metersphere.system.constants.UserViewType;
|
||||||
|
import io.metersphere.system.domain.UserView;
|
||||||
import io.metersphere.system.dto.UserViewDTO;
|
import io.metersphere.system.dto.UserViewDTO;
|
||||||
import io.metersphere.system.dto.UserViewListDTO;
|
|
||||||
import io.metersphere.system.dto.UserViewListGroupedDTO;
|
import io.metersphere.system.dto.UserViewListGroupedDTO;
|
||||||
import io.metersphere.system.dto.request.UserViewAddRequest;
|
import io.metersphere.system.dto.request.UserViewAddRequest;
|
||||||
import io.metersphere.system.dto.request.UserViewUpdateRequest;
|
import io.metersphere.system.dto.request.UserViewUpdateRequest;
|
||||||
|
@ -52,24 +52,21 @@ public class UserViewControllerTests extends BaseTest {
|
||||||
public void emptyList() throws Exception {
|
public void emptyList() throws Exception {
|
||||||
// @@请求成功
|
// @@请求成功
|
||||||
MvcResult mvcResult = this.requestGetWithOkAndReturn(LIST, DEFAULT_PROJECT_ID);
|
MvcResult mvcResult = this.requestGetWithOkAndReturn(LIST, DEFAULT_PROJECT_ID);
|
||||||
List<UserViewListDTO> result = getResultDataArray(mvcResult, UserViewListDTO.class);
|
List<UserView> result = getResultDataArray(mvcResult, UserView.class);
|
||||||
Assertions.assertEquals(result.size(), 3);
|
Assertions.assertEquals(result.size(), 3);
|
||||||
UserViewListDTO allData = result.get(0);
|
UserView allData = result.get(0);
|
||||||
Assertions.assertEquals(allData.getName(), "全部数据");
|
Assertions.assertEquals(allData.getName(), "全部数据");
|
||||||
Assertions.assertEquals(allData.getInternalViewKey(), InternalUserView.ALL_DATA.name());
|
|
||||||
Assertions.assertEquals(allData.getId(), InternalUserView.ALL_DATA.name().toLowerCase());
|
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.getName(), "我关注的");
|
||||||
Assertions.assertEquals(myFollow.getInternalViewKey(), InternalUserView.MY_FOLLOW.name());
|
|
||||||
Assertions.assertEquals(myFollow.getId(), InternalUserView.MY_FOLLOW.name().toLowerCase());
|
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.getName(), "我创建的");
|
||||||
Assertions.assertEquals(myCreate.getInternalViewKey(), InternalUserView.MY_CREATE.name());
|
|
||||||
Assertions.assertEquals(myCreate.getId(), InternalUserView.MY_CREATE.name().toLowerCase());
|
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.getScopeId(), DEFAULT_PROJECT_ID);
|
||||||
Assertions.assertEquals(item.getUserId(), InternalUser.ADMIN.getValue());
|
Assertions.assertEquals(item.getUserId(), InternalUser.ADMIN.getValue());
|
||||||
Assertions.assertEquals(item.getSearchMode(), CombineSearch.SearchMode.AND.name());
|
Assertions.assertEquals(item.getSearchMode(), CombineSearch.SearchMode.AND.name());
|
||||||
|
@ -134,12 +131,13 @@ public class UserViewControllerTests extends BaseTest {
|
||||||
@Order(3)
|
@Order(3)
|
||||||
public void update() throws Exception {
|
public void update() throws Exception {
|
||||||
UserViewUpdateRequest request = BeanUtils.copyBean(new UserViewUpdateRequest(), addUserViewDTO);
|
UserViewUpdateRequest request = BeanUtils.copyBean(new UserViewUpdateRequest(), addUserViewDTO);
|
||||||
request.setName(UUID.randomUUID().toString());
|
|
||||||
request.setSearchMode(CombineSearch.SearchMode.OR.name());
|
request.setSearchMode(CombineSearch.SearchMode.OR.name());
|
||||||
request.getConditions().get(0).setName(UUID.randomUUID().toString());
|
request.getConditions().get(0).setName(UUID.randomUUID().toString());
|
||||||
|
|
||||||
// @@请求成功
|
// @@请求成功
|
||||||
MvcResult mvcResult = this.requestPostWithOkAndReturn(DEFAULT_UPDATE, request);
|
MvcResult mvcResult = this.requestPostWithOkAndReturn(DEFAULT_UPDATE, request);
|
||||||
|
request.setName(UUID.randomUUID().toString());
|
||||||
|
mvcResult = this.requestPostWithOkAndReturn(DEFAULT_UPDATE, request);
|
||||||
addUserViewDTO = getResultData(mvcResult, UserViewDTO.class);
|
addUserViewDTO = getResultData(mvcResult, UserViewDTO.class);
|
||||||
addUserViewDTO.setConditions(request.getConditions());
|
addUserViewDTO.setConditions(request.getConditions());
|
||||||
UserViewDTO userViewDTO = userViewService.get(addUserViewDTO.getId(), UserViewType.FUNCTIONAL_CASE, InternalUser.ADMIN.getValue());
|
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());
|
mvcResult = this.requestGetWithOkAndReturn(DEFAULT_GET, InternalUserView.ALL_DATA.name());
|
||||||
resultData = getResultData(mvcResult, UserViewDTO.class);
|
resultData = getResultData(mvcResult, UserViewDTO.class);
|
||||||
Assertions.assertEquals(resultData.getName(), "全部数据");
|
Assertions.assertEquals(resultData.getName(), "全部数据");
|
||||||
Assertions.assertEquals(resultData.getInternalViewKey(), InternalUserView.ALL_DATA.name());
|
|
||||||
Assertions.assertEquals(resultData.getId(), InternalUserView.ALL_DATA.name().toLowerCase());
|
Assertions.assertEquals(resultData.getId(), InternalUserView.ALL_DATA.name().toLowerCase());
|
||||||
Assertions.assertEquals(resultData.getConditions().size(), 0);
|
Assertions.assertEquals(resultData.getConditions().size(), 0);
|
||||||
}
|
}
|
||||||
|
@ -179,7 +176,7 @@ public class UserViewControllerTests extends BaseTest {
|
||||||
UserViewListGroupedDTO result = getResultData(mvcResult, UserViewListGroupedDTO.class);
|
UserViewListGroupedDTO result = getResultData(mvcResult, UserViewListGroupedDTO.class);
|
||||||
Assertions.assertEquals(result.getInternalViews().size(), 3);
|
Assertions.assertEquals(result.getInternalViews().size(), 3);
|
||||||
Assertions.assertEquals(result.getCustomViews().size(), 2);
|
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
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue