feat:(feature/REQ-2750) 修改角色、角色分组tree接口
This commit is contained in:
parent
08be779df6
commit
73a1651f1d
@ -33,5 +33,11 @@
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.axzo.maokai</groupId>
|
||||
<artifactId>maokai-common</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@ -2,11 +2,13 @@ package cn.axzo.tyr.client.model.req;
|
||||
|
||||
import cn.axzo.foundation.dao.support.wrapper.CriteriaField;
|
||||
import cn.axzo.foundation.dao.support.wrapper.Operator;
|
||||
import cn.axzo.tyr.client.model.roleuser.req.ListRoleUserRelationParam;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@ -19,6 +21,9 @@ public class ListSaasRoleGroupParam {
|
||||
@CriteriaField(field = "workspaceTypeCode", operator = Operator.EQ)
|
||||
private Integer workspaceTypeCode;
|
||||
|
||||
@CriteriaField(field = "workspaceTypeCode", operator = Operator.IN)
|
||||
private Set<Integer> workspaceTypeCodes;
|
||||
|
||||
@CriteriaField(field = "workspaceId", operator = Operator.EQ)
|
||||
private Long workspaceId;
|
||||
|
||||
@ -33,4 +38,26 @@ public class ListSaasRoleGroupParam {
|
||||
|
||||
@CriteriaField(ignore = true)
|
||||
private Boolean needRoleGroupRelation;
|
||||
|
||||
/**
|
||||
* workspaceId和ouId配对查询
|
||||
* 例如:((workspaceId = ## and ouId = ##) or (workspaceId = ## and ouId = ##))
|
||||
*/
|
||||
@CriteriaField(ignore = true)
|
||||
private List<WorkspaceOuPair> workspaceOuPairs;
|
||||
|
||||
@CriteriaField(field = "workspaceId", operator = Operator.IN)
|
||||
private Set<Long> workspaceIds;
|
||||
|
||||
@CriteriaField(field = "ouId", operator = Operator.IN)
|
||||
private Set<Long> ouIds;
|
||||
|
||||
@CriteriaField(field = "ouTypeCode", operator = Operator.IN)
|
||||
private Set<String> ouTypeCodes;
|
||||
|
||||
@CriteriaField(field = "id", operator = Operator.IN)
|
||||
private Set<Long> ids;
|
||||
|
||||
@CriteriaField(ignore = true)
|
||||
private Set<String> paths;
|
||||
}
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
package cn.axzo.tyr.client.model.req;
|
||||
|
||||
import cn.axzo.maokai.common.enums.SaasCooperateShipCooperateTypeEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@ -51,4 +53,26 @@ public class TreeRoleReq {
|
||||
* 角色类型:common 普通角色 super_admin超级管理员(禁止删除) admin子管理员(禁止删除) init初始化内置角色
|
||||
*/
|
||||
private List<String> roleTypes;
|
||||
|
||||
/**
|
||||
* 角色分组code
|
||||
*/
|
||||
private Set<String> roleGroupCodes;
|
||||
|
||||
private List<WorkspaceOuPair> workspaceOuPairs;
|
||||
|
||||
/**
|
||||
* 是否需要预设角色,因为预设角色的workspaceId和ouId为-1
|
||||
*/
|
||||
private Boolean needPresetRole;
|
||||
|
||||
/**
|
||||
* 协同关系单位类型
|
||||
*/
|
||||
private Set<SaasCooperateShipCooperateTypeEnum> cooperateShipCooperateTypes;
|
||||
|
||||
/**
|
||||
* 角色code
|
||||
*/
|
||||
private Set<String> roleCodes;
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package cn.axzo.tyr.client.model.req;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class WorkspaceOuPair {
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
private Long workspaceId;
|
||||
|
||||
/**
|
||||
* 单位id
|
||||
*/
|
||||
private Long ouId;
|
||||
|
||||
public static final WorkspaceOuPair PRESET_WORKSPACE_OU_PAIR = WorkspaceOuPair.builder()
|
||||
.ouId(-1L)
|
||||
.workspaceId(-1L)
|
||||
.build();
|
||||
}
|
||||
@ -48,6 +48,8 @@ public class RoleTreeRes {
|
||||
*/
|
||||
private String type;
|
||||
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 是否显示
|
||||
*/
|
||||
|
||||
@ -60,6 +60,11 @@ public class SaasRoleGroupDTO {
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* ID层级路径, 逗号分隔
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 角色信息
|
||||
*/
|
||||
|
||||
@ -15,6 +15,7 @@ import cn.axzo.tyr.client.model.product.ProductSearchListReq;
|
||||
import cn.axzo.tyr.client.model.req.CommonDictQueryReq;
|
||||
import cn.axzo.tyr.client.model.req.GetFeatureResourceTreeReq;
|
||||
import cn.axzo.tyr.client.model.req.ListRoleReq;
|
||||
import cn.axzo.tyr.client.model.req.ListSaasRoleGroupParam;
|
||||
import cn.axzo.tyr.client.model.req.PagePgroupPermissionRelationReq;
|
||||
import cn.axzo.tyr.client.model.req.PageProductFeatureRelationReq;
|
||||
import cn.axzo.tyr.client.model.req.PageRoleReq;
|
||||
@ -23,6 +24,7 @@ import cn.axzo.tyr.client.model.req.QuerySaasRoleGroupReq;
|
||||
import cn.axzo.tyr.client.model.res.CommonDictResp;
|
||||
import cn.axzo.tyr.client.model.res.FeatureResourceDTO;
|
||||
import cn.axzo.tyr.client.model.res.FeatureResourceTreeNode;
|
||||
import cn.axzo.tyr.client.model.res.SaasRoleGroupDTO;
|
||||
import cn.axzo.tyr.client.model.res.SaasRoleRes;
|
||||
import cn.axzo.tyr.client.model.roleuser.req.ListRoleUserRelationParam;
|
||||
import cn.axzo.tyr.client.model.vo.SaasRoleGroupVO;
|
||||
@ -1375,6 +1377,27 @@ public class PrivateController {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@PostMapping("/api/private/roleGroup/path/refresh")
|
||||
public Object refreshRoleGroupPath() {
|
||||
List<SaasRoleGroupDTO> roleGroups = saasRoleGroupService.list(ListSaasRoleGroupParam.builder().build());
|
||||
if (CollectionUtils.isEmpty(roleGroups)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// 目前角色分组最多两层,所以简单实现
|
||||
saasRoleGroupDao.updateBatchById(roleGroups.stream()
|
||||
.map(e -> {
|
||||
SaasRoleGroup saasRoleGroup = SaasRoleGroup.builder()
|
||||
.path(Objects.equals(e.getParentId(), 0L) ? e.getId() + ","
|
||||
: e.getParentId() + "," + e.getId() + ",")
|
||||
.build();
|
||||
saasRoleGroup.setId(e.getId());
|
||||
return saasRoleGroup;
|
||||
})
|
||||
.collect(Collectors.toList()));
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
|
||||
@ -4,20 +4,22 @@ import cn.axzo.basics.common.exception.ServiceException;
|
||||
import cn.axzo.framework.domain.web.result.ApiListResult;
|
||||
import cn.axzo.framework.domain.web.result.ApiPageResult;
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.maokai.common.enums.SaasCooperateShipCooperateTypeEnum;
|
||||
import cn.axzo.tyr.client.feign.TyrSaasRoleApi;
|
||||
import cn.axzo.tyr.client.model.enums.DictWorkSpaceTypeEnum;
|
||||
import cn.axzo.tyr.client.model.req.ChangeGroupLeaderRoleReq;
|
||||
import cn.axzo.tyr.client.model.req.CommonDictQueryReq;
|
||||
import cn.axzo.tyr.client.model.req.FeatureRoleRelationReq;
|
||||
import cn.axzo.tyr.client.model.req.ListRoleReq;
|
||||
import cn.axzo.tyr.client.model.req.ListSaasRoleGroupParam;
|
||||
import cn.axzo.tyr.client.model.req.PageRoleReq;
|
||||
import cn.axzo.tyr.client.model.req.QueryByIdentityIdTypeReq;
|
||||
import cn.axzo.tyr.client.model.req.QueryRoleByNameReq;
|
||||
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.req.WorkspaceOuPair;
|
||||
import cn.axzo.tyr.client.model.res.CommonDictResp;
|
||||
import cn.axzo.tyr.client.model.res.FeatureRoleRelationResp;
|
||||
import cn.axzo.tyr.client.model.res.IsSuperAdminRes;
|
||||
@ -25,6 +27,7 @@ import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
|
||||
import cn.axzo.tyr.client.model.res.QueryRoleByNameResp;
|
||||
import cn.axzo.tyr.client.model.res.RoleTreeRes;
|
||||
import cn.axzo.tyr.client.model.res.RoleWithUserRes;
|
||||
import cn.axzo.tyr.client.model.res.SaasRoleGroupDTO;
|
||||
import cn.axzo.tyr.client.model.res.SaasRoleRes;
|
||||
import cn.axzo.tyr.client.model.vo.DeleteRoleVO;
|
||||
import cn.axzo.tyr.client.model.vo.SaasRoleAndGroupVO;
|
||||
@ -49,12 +52,12 @@ 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.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -333,10 +336,10 @@ public class SaasRoleController implements TyrSaasRoleApi {
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
private Map<Long, List<RoleTreeRes>> listRole(List<SaasRoleGroupVO> roleGroups,
|
||||
private Map<Long, List<RoleTreeRes>> listRole(List<SaasRoleGroupDTO> roleGroups,
|
||||
TreeRoleReq req) {
|
||||
|
||||
List<Long> roleGroupIds = roleGroups.stream().map(SaasRoleGroupVO::getId).collect(Collectors.toList());
|
||||
List<Long> roleGroupIds = roleGroups.stream().map(SaasRoleGroupDTO::getId).collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(roleGroupIds) || BooleanUtils.isNotTrue(req.getNeedRole())) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
@ -351,6 +354,7 @@ public class SaasRoleController implements TyrSaasRoleApi {
|
||||
.ouIds(req.getOuIds())
|
||||
.enabled(req.getEnabled())
|
||||
.roleTypes(req.getRoleTypes())
|
||||
.roleCodes(req.getRoleCodes())
|
||||
.build())
|
||||
.stream()
|
||||
.collect(Collectors.toMap(SaasRoleRes::getId, Function.identity()));
|
||||
@ -375,20 +379,13 @@ public class SaasRoleController implements TyrSaasRoleApi {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
List<SaasRoleGroupVO> roleGroups = saasRoleGroupService.getRoleGroupList(QuerySaasRoleGroupReq.builder()
|
||||
.workspaceTypeCode(Lists.transform(commonDicts, CommonDictResp::getDictCode))
|
||||
.workspaceIds(req.getWorkspaceIds())
|
||||
.ouIds(req.getOuIds())
|
||||
.build())
|
||||
.stream()
|
||||
.sorted(Comparator.comparing(e -> Optional.ofNullable(e.getSort()).orElse(1)))
|
||||
.collect(Collectors.toList());
|
||||
List<SaasRoleGroupDTO> roleGroups = listRoleGroup(commonDicts, req);
|
||||
|
||||
Map<Long, List<RoleTreeRes>> roles = listRole(roleGroups, req);
|
||||
|
||||
Map<String, List<RoleTreeRes>> rootRoleGroups = roleGroups.stream()
|
||||
.filter(e -> Objects.equals(e.getParentId(), ROOT_ROLE_GROUP_PARENT_ID))
|
||||
.collect(Collectors.groupingBy(SaasRoleGroupVO::getWorkspaceTypeCode,
|
||||
.collect(Collectors.groupingBy(SaasRoleGroupDTO::getWorkspaceTypeCode,
|
||||
LinkedHashMap::new,
|
||||
Collectors.mapping(this::toRoleTree, Collectors.toList())));
|
||||
|
||||
@ -397,7 +394,56 @@ public class SaasRoleController implements TyrSaasRoleApi {
|
||||
return rootRoleGroups;
|
||||
}
|
||||
|
||||
private RoleTreeRes toRoleTree(SaasRoleGroupVO roleGroup) {
|
||||
private List<SaasRoleGroupDTO> listRoleGroup(List<CommonDictResp> commonDicts, TreeRoleReq req) {
|
||||
ListSaasRoleGroupParam listSaasRoleGroupParam = ListSaasRoleGroupParam.builder()
|
||||
.workspaceTypeCodes(commonDicts.stream()
|
||||
.map(CommonDictResp::getDictCode)
|
||||
.map(Integer::valueOf)
|
||||
.collect(Collectors.toSet()))
|
||||
.workspaceOuPairs(req.getWorkspaceOuPairs())
|
||||
.workspaceIds(Optional.ofNullable(req.getWorkspaceIds())
|
||||
.map(HashSet::new)
|
||||
.orElse(null))
|
||||
.ouIds(Optional.ofNullable(req.getOuIds())
|
||||
.map(HashSet::new)
|
||||
.orElse(null))
|
||||
.roleGroupCodes(req.getRoleGroupCodes())
|
||||
.ouTypeCodes(Optional.ofNullable(req.getCooperateShipCooperateTypes())
|
||||
.map(e -> e.stream()
|
||||
.map(SaasCooperateShipCooperateTypeEnum::getCode)
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.toSet()))
|
||||
.orElse(null))
|
||||
.build();
|
||||
|
||||
List<WorkspaceOuPair> workspaceOuPairs = Optional.ofNullable(listSaasRoleGroupParam.getWorkspaceOuPairs())
|
||||
.orElseGet(Lists::newArrayList);
|
||||
if (Boolean.TRUE.equals(req.getNeedPresetRole())) {
|
||||
workspaceOuPairs.add(WorkspaceOuPair.PRESET_WORKSPACE_OU_PAIR);
|
||||
}
|
||||
|
||||
List<SaasRoleGroupDTO> roleGroups = saasRoleGroupService.list(listSaasRoleGroupParam)
|
||||
.stream()
|
||||
.sorted(Comparator.comparing(e -> Optional.ofNullable(e.getSort()).orElse(1)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 通过roleGroupCode查询时,因为角色分组有多层,需要把子节点的分组查询出来,否则无法查询到下面的角色和构建tree
|
||||
if (CollectionUtils.isEmpty(req.getRoleGroupCodes())) {
|
||||
return roleGroups;
|
||||
}
|
||||
|
||||
List<SaasRoleGroupDTO> children = saasRoleGroupService.list(ListSaasRoleGroupParam.builder()
|
||||
.paths(roleGroups.stream().map(SaasRoleGroupDTO::getPath).collect(Collectors.toSet()))
|
||||
.build());
|
||||
roleGroups.addAll(children);
|
||||
|
||||
return roleGroups.stream()
|
||||
.distinct()
|
||||
.sorted(Comparator.comparing(e -> Optional.ofNullable(e.getSort()).orElse(1)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private RoleTreeRes toRoleTree(SaasRoleGroupDTO roleGroup) {
|
||||
return RoleTreeRes.builder()
|
||||
.workspaceTypeCode(roleGroup.getWorkspaceTypeCode())
|
||||
.id(roleGroup.getId())
|
||||
@ -406,6 +452,7 @@ public class SaasRoleController implements TyrSaasRoleApi {
|
||||
.idStr(roleGroup.getId() + ":" + ROLE_GROUP_TYPE)
|
||||
.workspaceId(roleGroup.getWorkspaceId())
|
||||
.ouId(roleGroup.getOuId())
|
||||
.code(roleGroup.getCode())
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -419,11 +466,12 @@ public class SaasRoleController implements TyrSaasRoleApi {
|
||||
.type(ROLE_TYPE)
|
||||
.idStr(role.getId() + ":" + ROLE_TYPE)
|
||||
.isDisplay(role.getIsDisplay())
|
||||
.code(role.getRoleCode())
|
||||
.build();
|
||||
}
|
||||
|
||||
private void appendChildren(RoleTreeRes rootRoleGroup,
|
||||
List<SaasRoleGroupVO> roleGroups,
|
||||
List<SaasRoleGroupDTO> roleGroups,
|
||||
Map<Long, List<RoleTreeRes>> roles) {
|
||||
if (rootRoleGroup == null) {
|
||||
return;
|
||||
|
||||
@ -80,6 +80,11 @@ public class SaasRoleGroup extends BaseEntity<SaasRoleGroup> implements Serializ
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* ID层级路径, 逗号分隔
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 获取主键值
|
||||
*
|
||||
|
||||
@ -14,6 +14,7 @@ import cn.axzo.tyr.client.model.req.PageSaasRoleGroupParam;
|
||||
import cn.axzo.tyr.client.model.req.PermissionOperateLogReq;
|
||||
import cn.axzo.tyr.client.model.req.QuerySaasRoleGroupReq;
|
||||
import cn.axzo.tyr.client.model.req.SaasRoleGroupDeleteRequest;
|
||||
import cn.axzo.tyr.client.model.req.WorkspaceOuPair;
|
||||
import cn.axzo.tyr.client.model.res.RoleGroupRelationRes;
|
||||
import cn.axzo.tyr.client.model.res.SaasRoleGroupDTO;
|
||||
import cn.axzo.tyr.client.model.res.SaasRoleRes;
|
||||
@ -279,6 +280,11 @@ public class SaasRoleGroupServiceImpl extends ServiceImpl<SaasRoleGroupMapper, S
|
||||
saasRoleGroup.setCode(req.getCode());
|
||||
// 新增的时候,没有指定sort,sort放在同层级的最后
|
||||
assembleSort(saasRoleGroup);
|
||||
|
||||
if (!Objects.equals(saasRoleGroup.getParentId(), 0L)) {
|
||||
SaasRoleGroup parent = saasRoleGroupDao.getById(saasRoleGroup.getParentId());
|
||||
saasRoleGroup.setPath(Objects.isNull(parent) ? saasRoleGroup.getId().toString() + "," : parent.getPath() + saasRoleGroup.getId() + ",");
|
||||
}
|
||||
return saasRoleGroup;
|
||||
}
|
||||
|
||||
@ -369,6 +375,25 @@ public class SaasRoleGroupServiceImpl extends ServiceImpl<SaasRoleGroupMapper, S
|
||||
QueryWrapper<SaasRoleGroup> wrapper = QueryWrapperHelper.fromBean(param, SaasRoleGroup.class);
|
||||
wrapper.eq("is_delete", 0);
|
||||
|
||||
if (CollectionUtils.isNotEmpty(param.getWorkspaceOuPairs())) {
|
||||
wrapper.and(j -> {
|
||||
for (WorkspaceOuPair workspaceOuPair : param.getWorkspaceOuPairs()) {
|
||||
j.or(k -> {
|
||||
k.eq(Objects.nonNull(workspaceOuPair.getOuId()), "ou_id", workspaceOuPair.getOuId());
|
||||
k.eq(Objects.nonNull(workspaceOuPair.getWorkspaceId()), "workspace_id", workspaceOuPair.getWorkspaceId());
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(param.getPaths())) {
|
||||
wrapper.and(j -> {
|
||||
for (String path : param.getPaths()) {
|
||||
j.or(k -> k.likeRight("path", path));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
IPage<SaasRoleGroup> page = this.page(PageConverter.toMybatis(param, SaasRoleGroup.class), wrapper);
|
||||
|
||||
Map<Long, List<SaasRoleRes>> roles = listRoles(param, page.getRecords());
|
||||
|
||||
@ -310,4 +310,6 @@ CREATE TABLE `permission_rule` (
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_permission_rule_key_code` (`key_code`),
|
||||
UNIQUE KEY `uk_permission_rule_name` (`name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='权限系统规则定义表';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='权限系统规则定义表';
|
||||
|
||||
alter table saas_role_group add column `path` varchar(255) DEFAULT '0' COMMENT 'ID层级路径, 逗号分隔';
|
||||
Loading…
Reference in New Issue
Block a user