feat:(REQ-2227) 角色树增加id,增加角色排序
This commit is contained in:
parent
4b0f22b912
commit
91cf6fb11c
@ -10,6 +10,8 @@ import cn.axzo.tyr.client.model.req.QueryRoleByNameReq;
|
||||
import cn.axzo.tyr.client.model.req.QuerySaasRoleReq;
|
||||
import cn.axzo.tyr.client.model.req.RoleWithUserQueryReq;
|
||||
import cn.axzo.tyr.client.model.req.TreeRoleReq;
|
||||
import cn.axzo.tyr.client.model.req.UpdateRoleGroupOffsetReq;
|
||||
import cn.axzo.tyr.client.model.req.UpdateRoleOffsetReq;
|
||||
import cn.axzo.tyr.client.model.res.FeatureRoleRelationResp;
|
||||
import cn.axzo.tyr.client.model.res.IsSuperAdminRes;
|
||||
import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
|
||||
@ -163,4 +165,13 @@ public interface TyrSaasRoleApi {
|
||||
@PostMapping("/api/saasRole/tree")
|
||||
ApiListResult<RoleTreeRes> treeSaasRole(@RequestBody @Valid TreeRoleReq req);
|
||||
|
||||
/**
|
||||
* 更新角色的位置
|
||||
* 向下移动,则找到后面位置的分组,替换sort
|
||||
* 向上移动,则找到前面位置的分组,替换sort
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/api/role/group/update")
|
||||
ApiResult<Void> updateRoleOffset(@Valid @RequestBody UpdateRoleOffsetReq request);
|
||||
}
|
||||
|
||||
@ -11,5 +11,7 @@ import lombok.NoArgsConstructor;
|
||||
@AllArgsConstructor
|
||||
public class TreeRoleReq {
|
||||
|
||||
private String workspaceTypeCode;
|
||||
|
||||
private Boolean needRole;
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package cn.axzo.tyr.client.model.req;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UpdateRoleOffsetReq {
|
||||
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
@NotNull(message = "id不能为空")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 偏移量:向上移就是负数,例如上移一位:-1,向下移就是正数,例如下移一位:1
|
||||
*/
|
||||
@NotNull(message = "offset不能为空")
|
||||
private Integer offset;
|
||||
}
|
||||
@ -18,6 +18,8 @@ import lombok.NoArgsConstructor;
|
||||
@NoArgsConstructor
|
||||
public class CommonDictResp {
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 业务域
|
||||
*/
|
||||
|
||||
@ -0,0 +1,105 @@
|
||||
package cn.axzo.tyr.client.model.res;
|
||||
|
||||
import cn.axzo.tyr.client.model.vo.SaasPermissionGroupVO;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SaasRoleRes {
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 角色描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 角色类型:common 普通角色 super_admin超级管理员(禁止删除) admin子管理员(禁止删除) init初始化内置角色
|
||||
*/
|
||||
private String roleType;
|
||||
|
||||
private Long workspaceId;
|
||||
|
||||
/**
|
||||
* 废弃
|
||||
*/
|
||||
@Deprecated
|
||||
private Integer workspaceType;
|
||||
|
||||
private Long ownerOuId;
|
||||
|
||||
/**
|
||||
* 产品单位类型
|
||||
* 1:总包 2:建设单位 3:监理单位 4:劳务分包 5:专业分包 6:OMS通用 7:企业通用 8:企业内班组 9:项目内班组
|
||||
*/
|
||||
private Integer productUnitType;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
private Long updateBy;
|
||||
|
||||
/**
|
||||
* 来源的模版角色id(1052上线后可删除)
|
||||
*/
|
||||
@Deprecated
|
||||
private Long fromPreRoleId;
|
||||
|
||||
/**
|
||||
* 适用单位类型 1:总包 2:建设单位 4:监理单位 8:劳务分包 16:专业分包 0都可以用 只会挂在最末级
|
||||
* (1052上线后可删除)
|
||||
*/
|
||||
@Deprecated
|
||||
private Long fitOuTypeBit;
|
||||
|
||||
/**
|
||||
* '角色编码'
|
||||
*/
|
||||
private String roleCode;
|
||||
/**
|
||||
* '是否显示'
|
||||
*/
|
||||
private Boolean isDisplay;
|
||||
/**
|
||||
* '是否启用'
|
||||
*/
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 权限组
|
||||
*/
|
||||
private List<SaasPermissionGroupVO> permissionGroup;
|
||||
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
private Long isDelete;
|
||||
|
||||
private Date createAt;
|
||||
|
||||
private Date updateAt;
|
||||
}
|
||||
@ -78,6 +78,12 @@ public class SaasRoleVO {
|
||||
*/
|
||||
private Boolean enabled;
|
||||
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 获取角色对应所用的菜单,不管例外
|
||||
*
|
||||
|
||||
@ -1,15 +1,18 @@
|
||||
package cn.axzo.tyr.client.model.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SaveOrUpdateRoleVO {
|
||||
|
||||
/**
|
||||
@ -85,6 +88,8 @@ public class SaveOrUpdateRoleVO {
|
||||
*/
|
||||
private Boolean enabled;
|
||||
|
||||
private Integer sort;
|
||||
|
||||
@Data
|
||||
public static class GroupInfoVO {
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@ import cn.axzo.tyr.client.model.req.QuerySaasRoleGroupReq;
|
||||
import cn.axzo.tyr.client.model.req.QuerySaasRoleReq;
|
||||
import cn.axzo.tyr.client.model.req.RoleWithUserQueryReq;
|
||||
import cn.axzo.tyr.client.model.req.TreeRoleReq;
|
||||
import cn.axzo.tyr.client.model.req.UpdateRoleOffsetReq;
|
||||
import cn.axzo.tyr.client.model.res.CommonDictResp;
|
||||
import cn.axzo.tyr.client.model.res.FeatureRoleRelationResp;
|
||||
import cn.axzo.tyr.client.model.res.IsSuperAdminRes;
|
||||
@ -35,12 +36,14 @@ import cn.axzo.tyr.server.repository.entity.SaasRoleGroupRelation;
|
||||
import cn.axzo.tyr.server.service.PermissionCacheService;
|
||||
import cn.axzo.tyr.server.service.RoleService;
|
||||
import cn.axzo.tyr.server.service.SaasCommonDictService;
|
||||
import cn.axzo.tyr.server.service.SaasRoleGroupRelationService;
|
||||
import cn.axzo.tyr.server.service.SaasRoleGroupService;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@ -77,6 +80,8 @@ public class SaasRoleController implements TyrSaasRoleApi {
|
||||
private SaasRoleGroupService saasRoleGroupService;
|
||||
@Autowired
|
||||
private SaasRoleGroupRelationDao saasRoleGroupRelationDao;
|
||||
@Autowired
|
||||
private SaasRoleGroupRelationService saasRoleGroupRelationService;
|
||||
|
||||
/**
|
||||
* 角色组里面parentId = 0
|
||||
@ -182,10 +187,11 @@ public class SaasRoleController implements TyrSaasRoleApi {
|
||||
public ApiListResult<RoleTreeRes> treeSaasRole(TreeRoleReq req) {
|
||||
|
||||
// 因为根节点在roleGroup里面没有,都是workspaceTypeCode,描述是放在字典表里
|
||||
List<CommonDictResp> commonDicts = listRootRole();
|
||||
List<CommonDictResp> commonDicts = listRootRole(req);
|
||||
|
||||
List<RoleTreeRes> roots = commonDicts.stream()
|
||||
.map(e -> RoleTreeRes.builder()
|
||||
.id(e.getId())
|
||||
.workspaceTypeCode(e.getDictCode())
|
||||
.name(e.getDictValue())
|
||||
.type("ROOT")
|
||||
@ -200,6 +206,79 @@ public class SaasRoleController implements TyrSaasRoleApi {
|
||||
return ApiListResult.ok(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResult<Void> updateRoleOffset(UpdateRoleOffsetReq request) {
|
||||
if (request.getOffset() != 1 && request.getOffset() != -1) {
|
||||
throw new ServiceException("暂时只支持移动一个位置");
|
||||
}
|
||||
|
||||
SaasRole saasRole = roleService.getById(request.getId());
|
||||
if (saasRole == null) {
|
||||
throw new ServiceException("角色信息不存在");
|
||||
}
|
||||
|
||||
List<SaasRoleGroupRelation> saasRoleGroupRelations = saasRoleGroupRelationService.list(SaasRoleGroupRelationService.ListSaasRoleGroupRelationParam.builder()
|
||||
.roleId(Lists.newArrayList(saasRole.getId()))
|
||||
.build());
|
||||
if (CollectionUtils.isEmpty(saasRoleGroupRelations)) {
|
||||
throw new ServiceException("角色分组信息不存在");
|
||||
}
|
||||
|
||||
if (saasRoleGroupRelations.size() != 1) {
|
||||
throw new ServiceException("角色分组信息不唯一,请检查异常");
|
||||
}
|
||||
|
||||
List<SaasRoleVO> saasRoles = roleService.query(QuerySaasRoleReq.builder()
|
||||
.sassRoleGroupIds(Lists.transform(saasRoleGroupRelations, SaasRoleGroupRelation::getSaasRoleGroupId))
|
||||
.build())
|
||||
.stream()
|
||||
.sorted(Comparator.comparing(SaasRoleVO::getSort))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
SaasRoleVO exchangeRole = findExchangeRole(request, saasRoles);
|
||||
if (exchangeRole == null) {
|
||||
throw new ServiceException("未找到可以移动的位置");
|
||||
}
|
||||
roleService.saveOrUpdate(SaveOrUpdateRoleVO.builder()
|
||||
.id(saasRole.getId())
|
||||
.sort(exchangeRole.getSort())
|
||||
.build());
|
||||
|
||||
roleService.saveOrUpdate(SaveOrUpdateRoleVO.builder()
|
||||
.id(exchangeRole.getId())
|
||||
.sort(saasRole.getSort())
|
||||
.build());
|
||||
return ApiResult.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 只支持移动一位
|
||||
* @param request
|
||||
* @param roles
|
||||
* @return
|
||||
*/
|
||||
private SaasRoleVO findExchangeRole(UpdateRoleOffsetReq request,
|
||||
List<SaasRoleVO> roles) {
|
||||
List<Long> ids = roles.stream()
|
||||
.map(SaasRoleVO::getId)
|
||||
.collect(Collectors.toList());
|
||||
int currentIndex = ids.indexOf(request.getId());
|
||||
// 下移一位
|
||||
if (request.getOffset() == 1) {
|
||||
int exchangeIndex = currentIndex + 1;
|
||||
if (roles.size() > exchangeIndex) {
|
||||
return roles.get(exchangeIndex);
|
||||
}
|
||||
} else if (request.getOffset() == -1) {
|
||||
if (currentIndex == 0) {
|
||||
return null;
|
||||
}
|
||||
int exchangeIndex = currentIndex - 1;
|
||||
return roles.get(exchangeIndex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询角色
|
||||
* Map<角色分组Id, List<RoleTreeRes>>
|
||||
@ -229,7 +308,10 @@ public class SaasRoleController implements TyrSaasRoleApi {
|
||||
.stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()
|
||||
.stream()
|
||||
.map(value -> toRoleTree(saasRoles.get(value.getRoleId())))
|
||||
.map(value -> saasRoles.get(value.getRoleId()))
|
||||
.filter(Objects::nonNull)
|
||||
.sorted(Comparator.comparing(SaasRole::getSort))
|
||||
.map(this::toRoleTree)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList())));
|
||||
}
|
||||
@ -303,8 +385,9 @@ public class SaasRoleController implements TyrSaasRoleApi {
|
||||
childrenRoleGroups.forEach(e -> appendChildren(e, roleGroups, roles));
|
||||
}
|
||||
|
||||
private List<CommonDictResp> listRootRole() {
|
||||
private List<CommonDictResp> listRootRole(TreeRoleReq req) {
|
||||
return saasCommonDictService.query(CommonDictQueryReq.builder()
|
||||
.codes(StringUtils.isBlank(req.getWorkspaceTypeCode()) ? null : Lists.newArrayList(req.getWorkspaceTypeCode()))
|
||||
.scope("role")
|
||||
.build());
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ public class SaasRoleGroupController implements SaasRoleGroupApi {
|
||||
.sorted(Comparator.comparing(SaasRoleGroupVO::getSort))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
SaasRoleGroupVO exchangeRoleGroup = findExchangeRoleGroup(request, saasRoleGroup, roleGroupList);
|
||||
SaasRoleGroupVO exchangeRoleGroup = findExchangeRoleGroup(request, roleGroupList);
|
||||
if (exchangeRoleGroup == null) {
|
||||
throw new ServiceException("未找到可以移动的位置");
|
||||
}
|
||||
@ -93,12 +93,10 @@ public class SaasRoleGroupController implements SaasRoleGroupApi {
|
||||
/**
|
||||
* 只支持移动一位
|
||||
* @param request
|
||||
* @param saasRoleGroup
|
||||
* @param roleGroupList
|
||||
* @return
|
||||
*/
|
||||
private SaasRoleGroupVO findExchangeRoleGroup(UpdateRoleGroupOffsetReq request,
|
||||
SaasRoleGroupVO saasRoleGroup,
|
||||
List<SaasRoleGroupVO> roleGroupList) {
|
||||
List<Long> ids = roleGroupList.stream()
|
||||
.map(SaasRoleGroupVO::getId)
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package cn.axzo.tyr.server.repository.entity;
|
||||
|
||||
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
@ -89,6 +90,11 @@ public class SaasRole extends BaseEntity<SaasRole> {
|
||||
*/
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 获取主键值
|
||||
*
|
||||
|
||||
@ -134,6 +134,12 @@ public interface RoleService extends IService<SaasRole> {
|
||||
|
||||
@CriteriaField(field = "id", operator = Operator.IN)
|
||||
private List<Long> roleIds;
|
||||
|
||||
@CriteriaField(ignore = true)
|
||||
private Boolean needPermission;
|
||||
|
||||
@CriteriaField(ignore = true)
|
||||
private Boolean needRoleGroup;
|
||||
}
|
||||
|
||||
@SuperBuilder
|
||||
|
||||
@ -533,9 +533,34 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
|
||||
}
|
||||
});
|
||||
}
|
||||
saasRole.setSort(saveOrUpdateRole.getSort());
|
||||
assembleSort(saveOrUpdateRole, saasRole);
|
||||
return saasRole;
|
||||
}
|
||||
|
||||
|
||||
private void assembleSort(SaveOrUpdateRoleVO saveOrUpdateRole, SaasRole saasRole) {
|
||||
if (saasRole.getSort() != null || saasRole.getId() != null || CollectionUtils.isEmpty(saveOrUpdateRole.getGroupTree())) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<SaasRoleGroupRelation> saasRoleGroupRelations = saasRoleGroupRelationDao.getByGroupIds(Lists.transform(saveOrUpdateRole.getGroupTree(), SaveOrUpdateRoleVO.GroupInfoVO::getId));
|
||||
if (CollectionUtils.isEmpty(saasRoleGroupRelations)) {
|
||||
saasRole.setSort(1);
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<SaasRole> last = this.lambdaQuery()
|
||||
.eq(SaasRole::getId, Lists.transform(saasRoleGroupRelations, SaasRoleGroupRelation::getRoleId))
|
||||
.eq(SaasRole::getIsDelete, TableIsDeleteEnum.NORMAL.value)
|
||||
.orderByDesc(SaasRole::getSort)
|
||||
.last("limit 1")
|
||||
.list()
|
||||
.stream()
|
||||
.findFirst();
|
||||
saasRole.setSort(last.map(e -> e.getSort() == null ? 1 : e.getSort() + 1).orElse(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品单位类型
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user