feat:(REQ-2227) 增加角色的page接口,调整角色的tree接口

This commit is contained in:
lilong 2024-04-11 19:08:15 +08:00
parent a24fd8ec63
commit 65facb5106
9 changed files with 310 additions and 17 deletions

View File

@ -5,6 +5,7 @@ import cn.axzo.framework.domain.web.result.ApiPageResult;
import cn.axzo.framework.domain.web.result.ApiResult;
import cn.axzo.tyr.client.model.req.ChangeGroupLeaderRoleReq;
import cn.axzo.tyr.client.model.req.FeatureRoleRelationReq;
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.QuerySaasRoleReq;
@ -18,6 +19,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.SaasRoleRes;
import cn.axzo.tyr.client.model.vo.SaasRoleAndGroupVO;
import cn.axzo.tyr.client.model.vo.SaasRoleCategoryVO;
import cn.axzo.tyr.client.model.vo.SaasRoleGroupCodeVO;
@ -174,4 +176,12 @@ public interface TyrSaasRoleApi {
*/
@PostMapping("/api/saasRole/offset/update")
ApiResult<Void> updateRoleOffset(@Valid @RequestBody UpdateRoleOffsetReq request);
/**
* 角色page接口
* @param request
* @return
*/
@PostMapping("/api/saasRole/page")
ApiPageResult<SaasRoleRes> page(@RequestBody PageRoleReq request);
}

View File

@ -0,0 +1,30 @@
package cn.axzo.tyr.client.model.req;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PageRoleReq {
private List<Long> roleIds;
private Boolean needPermission;
private Boolean needRoleGroup;
private Integer page;
private Integer pageSize;
/**
* 排序使用示例createAt__DESC
*/
private List<String> sort;
}

View File

@ -39,4 +39,9 @@ public class RoleTreeRes {
private Boolean isDisplay;
private List<RoleTreeRes> children;
/**
* id跟type拼接因为前端组件所有节点的id不能重复
*/
private String idStr;
}

View File

@ -0,0 +1,20 @@
package cn.axzo.tyr.client.model.res;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SaasPermissionRes {
private Long id;
/**
* 资源编码-权限码
*/
private String featureCode;
}

View File

@ -0,0 +1,60 @@
package cn.axzo.tyr.client.model.res;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SaasRoleGroupRes {
private Long id;
/**
* 工作台类型字典code
*/
private String workspaceTypeCode;
/**
* 单位类型字典code
*/
private String ouTypeCode;
/**
* 名称
*/
private String name;
/**
* 所属工作台id
*/
private Long workspaceId;
/**
* 所属单位id
*/
private Long ouId;
/**
* 排序
*/
private Integer sort;
/**
* 分组CODE
*/
private String code;
/**
* 分类CODE, 用于代班长小组长的权限分类
*/
private String categoryCode;
/**
* 上级分组id
*/
private Long parentId;
}

View File

@ -89,11 +89,6 @@ public class SaasRoleRes {
*/
private Integer sort;
/**
* 权限组
*/
private List<SaasPermissionGroupVO> permissionGroup;
/**
* 是否删除
*/
@ -102,4 +97,14 @@ public class SaasRoleRes {
private Date createAt;
private Date updateAt;
/**
* 角色组
*/
private List<SaasRoleGroupRes> saasRoleGroups;
/**
* 角色权限
*/
private List<SaasPermissionRes> saasPermissions;
}

View File

@ -8,6 +8,7 @@ import cn.axzo.tyr.client.feign.TyrSaasRoleApi;
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.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;
@ -22,6 +23,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.SaasRoleRes;
import cn.axzo.tyr.client.model.vo.SaasRoleAndGroupVO;
import cn.axzo.tyr.client.model.vo.SaasRoleCategoryVO;
import cn.axzo.tyr.client.model.vo.SaasRoleGroupCodeVO;
@ -38,12 +40,14 @@ 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.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
@ -88,6 +92,10 @@ public class SaasRoleController implements TyrSaasRoleApi {
*/
private static final Long ROOT_ROLE_GROUP_PARENT_ID = 0L;
private static final String ROOT_TYPE = "ROOT";
private static final String ROLE_TYPE = "ROLE";
private static final String ROLE_GROUP_TYPE = "ROLE_GROUP";
@Override
public ApiResult<Long> saveOrUpdate(SaveOrUpdateRoleVO saveOrUpdateRole) {
Long result = roleService.saveOrUpdate(saveOrUpdateRole);
@ -194,7 +202,8 @@ public class SaasRoleController implements TyrSaasRoleApi {
.id(e.getId())
.workspaceTypeCode(e.getDictCode())
.name(e.getDictValue())
.type("ROOT")
.type(ROOT_TYPE)
.idStr(e.getId() + ":" + ROOT_TYPE)
.build())
.collect(Collectors.toList());
@ -251,6 +260,14 @@ public class SaasRoleController implements TyrSaasRoleApi {
return ApiResult.ok();
}
@Override
public ApiPageResult<SaasRoleRes> page(PageRoleReq request) {
RoleService.PageSaasRoleParam param = RoleService.PageSaasRoleParam.builder().build();
BeanUtils.copyProperties(request, param);
Page<SaasRoleRes> page = roleService.page(param);
return ApiPageResult.ok(page.getRecords(), page.getTotal(), (int) page.getCurrent(), (int) page.getSize());
}
/**
* 只支持移动一位
* @param request
@ -296,11 +313,11 @@ public class SaasRoleController implements TyrSaasRoleApi {
List<SaasRoleGroupRelation> saasRoleGroupRelations = saasRoleGroupRelationDao.getByGroupIds(roleGroupIds);
Map<Long, SaasRole> saasRoles = roleService.list(RoleService.ListSaasRoleParam.builder()
Map<Long, SaasRoleRes> saasRoles = roleService.list(RoleService.ListSaasRoleParam.builder()
.roleIds(Lists.transform(saasRoleGroupRelations, SaasRoleGroupRelation::getRoleId))
.build())
.stream()
.collect(Collectors.toMap(SaasRole::getId, Function.identity()));
.collect(Collectors.toMap(SaasRoleRes::getId, Function.identity()));
return saasRoleGroupRelations.stream()
.collect(Collectors.groupingBy(SaasRoleGroupRelation::getSaasRoleGroupId))
@ -310,7 +327,7 @@ public class SaasRoleController implements TyrSaasRoleApi {
.stream()
.map(value -> saasRoles.get(value.getRoleId()))
.filter(Objects::nonNull)
.sorted(Comparator.comparing(SaasRole::getSort))
.sorted(Comparator.comparing(SaasRoleRes::getSort))
.map(this::toRoleTree)
.filter(Objects::nonNull)
.collect(Collectors.toList())));
@ -347,18 +364,21 @@ public class SaasRoleController implements TyrSaasRoleApi {
.workspaceTypeCode(roleGroup.getWorkspaceTypeCode())
.id(roleGroup.getId())
.name(roleGroup.getName())
.type("ROLE_GROUP")
.type(ROLE_GROUP_TYPE)
.idStr(roleGroup.getId() + ":" + ROLE_GROUP_TYPE)
.build();
}
private RoleTreeRes toRoleTree(SaasRole role) {
private RoleTreeRes toRoleTree(SaasRoleRes role) {
if (role == null) {
return null;
}
return RoleTreeRes.builder()
.id(role.getId())
.name(role.getName())
.type("ROLE")
.type(ROLE_TYPE)
.idStr(role.getId() + ":" + ROLE_TYPE)
.isDisplay(role.getIsDisplay())
.build();
}

View File

@ -16,6 +16,7 @@ import cn.axzo.tyr.client.model.res.IsSuperAdminRes;
import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
import cn.axzo.tyr.client.model.res.QueryRoleByNameResp;
import cn.axzo.tyr.client.model.res.RoleWithUserRes;
import cn.axzo.tyr.client.model.res.SaasRoleRes;
import cn.axzo.tyr.client.model.vo.SaasRoleAndGroupVO;
import cn.axzo.tyr.client.model.vo.SaasRoleCategoryVO;
import cn.axzo.tyr.client.model.vo.SaasRoleGroupCodeVO;
@ -118,9 +119,9 @@ public interface RoleService extends IService<SaasRole> {
/** 查询超管和管理员角色 **/
List<SaasRole> listAdmins(Long workspaceId, Long ouId);
List<SaasRole> list(ListSaasRoleParam param);
List<SaasRoleRes> list(ListSaasRoleParam param);
Page<SaasRole> page(PageSaasRoleParam param);
Page<SaasRoleRes> page(PageSaasRoleParam param);
void saveOrUpdateFeatureRoleRelation(List<FeatureRoleRelationReq> req, Long operatorId);

View File

@ -24,6 +24,9 @@ import cn.axzo.tyr.client.model.res.IsSuperAdminRes;
import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
import cn.axzo.tyr.client.model.res.QueryRoleByNameResp;
import cn.axzo.tyr.client.model.res.RoleWithUserRes;
import cn.axzo.tyr.client.model.res.SaasPermissionRes;
import cn.axzo.tyr.client.model.res.SaasRoleGroupRes;
import cn.axzo.tyr.client.model.res.SaasRoleRes;
import cn.axzo.tyr.client.model.vo.SaasPermissionGroupVO;
import cn.axzo.tyr.client.model.vo.SaasRoleAndGroupVO;
import cn.axzo.tyr.client.model.vo.SaasRoleCategoryVO;
@ -71,9 +74,14 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -83,6 +91,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
@ -1076,7 +1085,7 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
}
@Override
public List<SaasRole> list(ListSaasRoleParam param) {
public List<SaasRoleRes> list(ListSaasRoleParam param) {
return PageConverter.drainAll(pageNumber -> {
PageSaasRoleParam pageParam = PageSaasRoleParam.builder().build();
BeanUtils.copyProperties(param, pageParam);
@ -1087,10 +1096,143 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
}
@Override
public Page<SaasRole> page(PageSaasRoleParam param) {
public Page<SaasRoleRes> page(PageSaasRoleParam param) {
QueryWrapper<SaasRole> wrapper = QueryWrapperHelper.fromBean(param, SaasRole.class);
wrapper.eq("is_delete", 0);
return this.page(PageConverter.convertToMybatis(param, SaasRole.class), wrapper);
Page<SaasRole> page = this.page(PageConverter.convertToMybatis(param, SaasRole.class), wrapper);
Map<Long, List<SaasRoleGroupRes>> saasRoleGroups = listRoleGroups(param, page.getRecords());
return PageConverter.convert(page, (record) -> from(record,
saasRoleGroups));
}
private SaasRoleRes from(SaasRole saasRole,
Map<Long, List<SaasRoleGroupRes>> saasRoleGroups) {
SaasRoleRes saasRoleRes = SaasRoleRes.builder().build();
BeanUtils.copyProperties(saasRole, saasRoleRes);
saasRoleRes.setSaasRoleGroups(saasRoleGroups.get(saasRoleRes.getId()));
return saasRoleRes;
}
private Map<Long, List<SaasPermissionRes>> listRolePermissions(PageSaasRoleParam param,
List<SaasRole> saasRoles) {
if (CollectionUtils.isEmpty(saasRoles) || BooleanUtils.isNotTrue(param.getNeedPermission())) {
return Collections.emptyMap();
}
List<SaasPgroupRoleRelation> saasPgroupRoleRelations = saasPgroupRoleRelationDao.findByRoleIds(Lists.transform(saasRoles, SaasRole::getId));
if (CollectionUtils.isEmpty(saasPgroupRoleRelations)) {
return Collections.emptyMap();
}
List<SaasPgroupPermissionRelation> saasPgroupPermissionRelations = saasPgroupPermissionRelationDao.lambdaQuery()
.in(SaasPgroupPermissionRelation::getGroupId, Lists.transform(saasPgroupRoleRelations, SaasPgroupRoleRelation::getGroupId))
.eq(SaasPgroupPermissionRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value)
.list();
if (CollectionUtils.isEmpty(saasPgroupPermissionRelations)) {
return Collections.emptyMap();
}
Map<Long, SaasPermissionRes> resourcePermissions = saasFeatureResourceService.permissionQuery(ResourcePermissionQueryDTO.builder()
.ids(Lists.transform(saasPgroupPermissionRelations, SaasPgroupPermissionRelation::getFeatureId))
.build())
.stream()
.map(e -> SaasPermissionRes.builder().id(e.getId()).featureCode(e.getFeatureCode()).build())
.collect(Collectors.toMap(SaasPermissionRes::getId, Function.identity()));
Map<Long, List<Long>> pgroupPermissions = saasPgroupPermissionRelations.stream()
.collect(Collectors.groupingBy(SaasPgroupPermissionRelation::getGroupId,
Collectors.mapping(SaasPgroupPermissionRelation::getFeatureId, Collectors.toList())));
// return saasPgroupRoleRelations.stream()
// .map(e -> {
// List<Long> permissionIds = pgroupPermissions.get(e.getGroupId());
// if (CollectionUtils.isEmpty(permissionIds)) {
// return null;
// }
//
// return permissionIds.stream()
// .map(permissionId -> {
// SaasPermissionRes saasPermissionRes = resourcePermissions.get(permissionId);
// if (saasPermissionRes == null) {
// return null;
// }
// return SaasPermissionWrapper.builder()
// .id(saasPermissionRes.getId())
// .featureCode(saasPermissionRes.getFeatureCode())
// .roleId(e.getRoleId())
// .build();
// })
// .filter(Objects::nonNull)
// .collect(Collectors.toList());
// })
// .collect(Collectors.groupingBy(SaasPgroupRoleRelation::getRoleId,
// Collectors.mapping(e -> {
// List<Long> permissionIds = pgroupPermissions.get(e.getGroupId());
// if (CollectionUtils.isEmpty(permissionIds)) {
// return null;
// }
//
// return permissionIds.stream()
// .map(resourcePermissions::get)
// .collect(Collectors.toList());
// }, Collectors.toList())));
return Collections.emptyMap();
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
static class SaasPermissionWrapper {
private Long id;
/**
* 资源编码-权限码
*/
private String featureCode;
private Long roleId;
}
private Map<Long, List<SaasRoleGroupRes>> listRoleGroups(PageSaasRoleParam param,
List<SaasRole> saasRoles) {
if (CollectionUtils.isEmpty(saasRoles) || BooleanUtils.isNotTrue(param.getNeedRoleGroup())) {
return Collections.emptyMap();
}
List<SaasRoleGroupRelation> roleGroupRelations = saasRoleGroupRelationDao.lambdaQuery()
.in(SaasRoleGroupRelation::getRoleId, Lists.transform(saasRoles, SaasRole::getId))
.eq(SaasRoleGroupRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value)
.list();
if (CollectionUtils.isEmpty(roleGroupRelations)) {
return Collections.emptyMap();
}
Map<Long, SaasRoleGroup> saasRoleGroups = saasRoleGroupDao.query(QuerySaasRoleGroupReq.builder()
.ids(Lists.transform(roleGroupRelations, SaasRoleGroupRelation::getSaasRoleGroupId))
.build())
.stream()
.collect(Collectors.toMap(SaasRoleGroup::getId, Function.identity()));
return roleGroupRelations.stream()
.collect(Collectors.groupingBy(SaasRoleGroupRelation::getRoleId,
Collectors.mapping(e -> {
SaasRoleGroup saasRoleGroup = saasRoleGroups.get(e.getSaasRoleGroupId());
if (saasRoleGroup == null) {
return null;
}
SaasRoleGroupRes saasRoleGroupRes = SaasRoleGroupRes.builder().build();
BeanUtils.copyProperties(saasRoleGroup, saasRoleGroupRes);
return saasRoleGroupRes;
}, Collectors.toList())));
}
@Transactional(rollbackFor = Exception.class)