feat:(REQ-2298) 修改自定义角色分组不支持移位置

This commit is contained in:
lilong 2024-05-28 18:47:46 +08:00
parent eb35009d1e
commit bf27b94651
2 changed files with 17 additions and 11 deletions

View File

@ -8,7 +8,8 @@ import lombok.Getter;
@AllArgsConstructor
public enum BizResultCode implements IResultCode {
CANT_DELETE_ROLE_GROUP("100001", "不能删除角色分组,当前角色分组下有子角色分组");
CANT_DELETE_ROLE_GROUP("100001", "不能删除角色分组,当前角色分组下有子角色分组"),
ROLE_GROUP_NOT_FOUND("100002", "角色分组不存在");
private String errorCode;
private String errorMessage;

View File

@ -1,11 +1,13 @@
package cn.axzo.tyr.server.controller.role;
import cn.axzo.basics.common.exception.ServiceException;
import cn.axzo.foundation.exception.Axssert;
import cn.axzo.framework.domain.web.result.ApiResult;
import cn.axzo.tyr.client.feign.SaasRoleGroupApi;
import cn.axzo.tyr.client.model.req.QuerySaasRoleGroupReq;
import cn.axzo.tyr.client.model.req.UpdateRoleGroupOffsetReq;
import cn.axzo.tyr.client.model.vo.SaasRoleGroupVO;
import cn.axzo.tyr.server.repository.entity.SaasRoleGroup;
import cn.axzo.tyr.server.service.SaasRoleGroupService;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
@ -17,6 +19,8 @@ import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import static cn.axzo.tyr.server.config.exception.BizResultCode.ROLE_GROUP_NOT_FOUND;
@Slf4j
@RestController
@RequiredArgsConstructor
@ -64,17 +68,18 @@ public class SaasRoleGroupController implements SaasRoleGroupApi {
if (request.getOffset() != 1 && request.getOffset() != -1) {
throw new ServiceException("暂时只支持移动一个位置");
}
SaasRoleGroupVO saasRoleGroup = getById(request.getId()).getData();
SaasRoleGroup saasRoleGroup = saasRoleGroupService.getById(request.getId());
Axssert.checkNonNull(saasRoleGroup, ROLE_GROUP_NOT_FOUND);
List<SaasRoleGroupVO> roleGroupList = saasRoleGroupService.getRoleGroupList(QuerySaasRoleGroupReq.builder()
.parentId(saasRoleGroup.getParentId())
.workspaceTypeCode(Lists.newArrayList(saasRoleGroup.getWorkspaceTypeCode()))
.build())
List<SaasRoleGroup> roleGroupList = saasRoleGroupService.lambdaQuery()
.eq(SaasRoleGroup::getParentId, saasRoleGroup.getParentId())
.eq(SaasRoleGroup::getWorkspaceTypeCode, saasRoleGroup.getWorkspaceTypeCode())
.list()
.stream()
.sorted(Comparator.comparing(SaasRoleGroupVO::getSort))
.sorted(Comparator.comparing(SaasRoleGroup::getSort))
.collect(Collectors.toList());
SaasRoleGroupVO exchangeRoleGroup = findExchangeRoleGroup(request, roleGroupList);
SaasRoleGroup exchangeRoleGroup = findExchangeRoleGroup(request, roleGroupList);
if (exchangeRoleGroup == null) {
throw new ServiceException("未找到可以移动的位置");
}
@ -96,10 +101,10 @@ public class SaasRoleGroupController implements SaasRoleGroupApi {
* @param roleGroupList
* @return
*/
private SaasRoleGroupVO findExchangeRoleGroup(UpdateRoleGroupOffsetReq request,
List<SaasRoleGroupVO> roleGroupList) {
private SaasRoleGroup findExchangeRoleGroup(UpdateRoleGroupOffsetReq request,
List<SaasRoleGroup> roleGroupList) {
List<Long> ids = roleGroupList.stream()
.map(SaasRoleGroupVO::getId)
.map(SaasRoleGroup::getId)
.collect(Collectors.toList());
int currentIndex = ids.indexOf(request.getId());
// 下移一位