补充根据身份id类型批量查询接口

This commit is contained in:
陈维伟 2023-09-11 11:31:22 +08:00
parent 34bc1fc106
commit 81ab60e44f
5 changed files with 168 additions and 112 deletions

View File

@ -1,6 +1,7 @@
package cn.axzo.tyr.client.feign; package cn.axzo.tyr.client.feign;
import cn.axzo.framework.domain.web.result.ApiResult; import cn.axzo.framework.domain.web.result.ApiResult;
import cn.axzo.tyr.client.model.req.QueryByIdentityIdTypeReq;
import cn.axzo.tyr.client.model.req.QuerySaasRoleReq; import cn.axzo.tyr.client.model.req.QuerySaasRoleReq;
import cn.axzo.tyr.client.model.vo.SaasRoleVO; import cn.axzo.tyr.client.model.vo.SaasRoleVO;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 角色 * 角色
@ -39,10 +41,20 @@ public interface SaasRoleApi {
ApiResult<List<SaasRoleVO>> query(@RequestBody QuerySaasRoleReq req); ApiResult<List<SaasRoleVO>> query(@RequestBody QuerySaasRoleReq req);
/** /**
* 根据身份id 身份类型查询权限列表 * 根据身份id身份类型查询权限列表批量
* @param identityType 身份类型 1:工人 2:班组长 3:从业人员 4:监管人员 5:运营人员
* @return * @return
*/ */
@GetMapping("/api/saasRole/queryByIdentityIdType") @GetMapping("/api/saasRole/queryByIdentityIdType")
ApiResult<List<SaasRoleVO>> queryByIdentityIdType(@RequestParam(required = true) Long identityId,@RequestParam(required = true) Integer identityType,@RequestParam(required = true) Long workspaceId,@RequestParam(required = true) Long ouId); ApiResult<List<SaasRoleVO>> queryByIdentityIdType(@RequestParam(required = true) Long identityId,@RequestParam(required = true) Integer identityType,@RequestParam(required = true) Long workspaceId,@RequestParam(required = true) Long ouId);
/**
* 根据身份id身份类型查询权限列表批量
* @return
*/
@GetMapping("/api/saasRole/queryBatchByIdentityIdType")
ApiResult<Map<QueryByIdentityIdTypeReq, List<SaasRoleVO>>> queryBatchByIdentityIdType(@RequestBody List<QueryByIdentityIdTypeReq> req);
} }

View File

@ -0,0 +1,22 @@
package cn.axzo.tyr.client.model.req;
import lombok.*;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode
public class QueryByIdentityIdTypeReq {
Long identityId;
/**
* 身份类型 1:工人 2:班组长 3:从业人员 4:监管人员 5:运营人员
*/
Integer identityType;
Long workspaceId;
Long ouId;
}

View File

@ -2,6 +2,7 @@ package cn.axzo.tyr.server.controller.role;
import cn.axzo.framework.domain.web.result.ApiResult; import cn.axzo.framework.domain.web.result.ApiResult;
import cn.axzo.tyr.client.feign.SaasRoleApi; import cn.axzo.tyr.client.feign.SaasRoleApi;
import cn.axzo.tyr.client.model.req.QueryByIdentityIdTypeReq;
import cn.axzo.tyr.client.model.req.QuerySaasRoleReq; import cn.axzo.tyr.client.model.req.QuerySaasRoleReq;
import cn.axzo.tyr.client.model.vo.SaasRoleVO; import cn.axzo.tyr.client.model.vo.SaasRoleVO;
import cn.axzo.tyr.server.service.RoleService; import cn.axzo.tyr.server.service.RoleService;
@ -11,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 权限 * 权限
@ -46,4 +48,10 @@ public class SaasRoleController implements SaasRoleApi {
public ApiResult<List<SaasRoleVO>> queryByIdentityIdType(Long identityId, Integer identityType,Long workspaceId,Long ouId) { public ApiResult<List<SaasRoleVO>> queryByIdentityIdType(Long identityId, Integer identityType,Long workspaceId,Long ouId) {
return ApiResult.ok(roleService.queryByIdentityIdType(identityId, identityType,workspaceId,ouId)); return ApiResult.ok(roleService.queryByIdentityIdType(identityId, identityType,workspaceId,ouId));
} }
@Override
public ApiResult<Map<QueryByIdentityIdTypeReq, List<SaasRoleVO>>> queryBatchByIdentityIdType(List<QueryByIdentityIdTypeReq> req) {
return ApiResult.ok(roleService.queryBatchByIdentityIdType(req));
}
} }

View File

@ -1,10 +1,11 @@
package cn.axzo.tyr.server.service; package cn.axzo.tyr.server.service;
import cn.axzo.framework.domain.web.result.ApiListResult; import cn.axzo.tyr.client.model.req.QueryByIdentityIdTypeReq;
import cn.axzo.tyr.client.model.req.QuerySaasRoleReq; import cn.axzo.tyr.client.model.req.QuerySaasRoleReq;
import cn.axzo.tyr.client.model.vo.SaasRoleVO; import cn.axzo.tyr.client.model.vo.SaasRoleVO;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 角色 * 角色
@ -19,4 +20,6 @@ public interface RoleService {
List<SaasRoleVO> queryByIdentityIdType(Long identityId, Integer identityType,Long workspaceId,Long ouId); List<SaasRoleVO> queryByIdentityIdType(Long identityId, Integer identityType,Long workspaceId,Long ouId);
List<SaasRoleVO> query(QuerySaasRoleReq req); List<SaasRoleVO> query(QuerySaasRoleReq req);
Map<QueryByIdentityIdTypeReq, List<SaasRoleVO>> queryBatchByIdentityIdType(List<QueryByIdentityIdTypeReq> req);
} }

View File

@ -2,6 +2,7 @@ package cn.axzo.tyr.server.service.impl;
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum; import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity; import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
import cn.axzo.tyr.client.model.req.QueryByIdentityIdTypeReq;
import cn.axzo.tyr.client.model.req.QuerySaasPermissionGroupReq; import cn.axzo.tyr.client.model.req.QuerySaasPermissionGroupReq;
import cn.axzo.tyr.client.model.req.QuerySaasRoleGroupReq; import cn.axzo.tyr.client.model.req.QuerySaasRoleGroupReq;
import cn.axzo.tyr.client.model.req.QuerySaasRoleReq; import cn.axzo.tyr.client.model.req.QuerySaasRoleReq;
@ -34,118 +35,128 @@ import java.util.stream.Collectors;
@Service @Service
public class RoleServiceImpl implements RoleService { public class RoleServiceImpl implements RoleService {
@Autowired @Autowired
SaasRoleUserRelationDao roleUserRelationDao; SaasRoleUserRelationDao roleUserRelationDao;
@Autowired @Autowired
SaasRoleDao saasRoleDao; SaasRoleDao saasRoleDao;
@Autowired @Autowired
PermissionGroupService permissionGroupService; PermissionGroupService permissionGroupService;
@Autowired @Autowired
SaasPgroupRoleRelationDao permissionGroupRelation; SaasPgroupRoleRelationDao permissionGroupRelation;
@Autowired @Autowired
SaasRoleGroupDao saasRoleGroupDao; SaasRoleGroupDao saasRoleGroupDao;
@Autowired @Autowired
SaasRoleGroupRelationDao roleGroupRelationDao; SaasRoleGroupRelationDao roleGroupRelationDao;
@Override @Override
public List<SaasRoleVO> queryByIdentityIdType(Long identityId, Integer identityType,Long workspaceId,Long ouId) { public List<SaasRoleVO> queryByIdentityIdType(Long identityId, Integer identityType, Long workspaceId, Long ouId) {
// 查询人关联的角色id // 查询人关联的角色id
List<Long> roleIds = roleUserRelationDao.query(identityId, identityType,workspaceId,ouId).stream().map(SaasRoleUserRelation::getRoleId).collect(Collectors.toList()); List<Long> roleIds = roleUserRelationDao.query(identityId, identityType, workspaceId, ouId).stream().map(SaasRoleUserRelation::getRoleId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(roleIds)) { if (CollectionUtils.isEmpty(roleIds)) {
return new ArrayList<>(); return new ArrayList<>();
} }
return getByIds(roleIds); return getByIds(roleIds);
} }
/** /**
* 根据id查询权限详情包含权限组合权限集(底层基础方法) * 根据id查询权限详情包含权限组合权限集(底层基础方法)
* @return *
*/ * @return
public List<SaasRoleVO> getByIds(List<Long> roleIds) { */
if (CollectionUtils.isEmpty(roleIds)) { public List<SaasRoleVO> getByIds(List<Long> roleIds) {
return new ArrayList<>(); if (CollectionUtils.isEmpty(roleIds)) {
} return new ArrayList<>();
// 查询角色信息 }
List<SaasRole> roles = saasRoleDao.lambdaQuery().in(BaseEntity::getId, roleIds).list(); // 查询角色信息
// 查询权限集关联关系 List<SaasRole> roles = saasRoleDao.lambdaQuery().in(BaseEntity::getId, roleIds).list();
List<SaasPgroupRoleRelation> saasPgroupRoleRelations = queryPermissionGroupRelation(roleIds); // 查询权限集关联关系
// 查询权限集 List<SaasPgroupRoleRelation> saasPgroupRoleRelations = queryPermissionGroupRelation(roleIds);
Map<Long, List<SaasPgroupRoleRelation>> pgrouRelationMap = null; // 查询权限集
Map<Long, List<SaasPermissionGroupVO>> pGroupMap = null; Map<Long, List<SaasPgroupRoleRelation>> pgrouRelationMap = null;
if (CollectionUtils.isNotEmpty(saasPgroupRoleRelations)) { Map<Long, List<SaasPermissionGroupVO>> pGroupMap = null;
// 转map<roleId,relation> if (CollectionUtils.isNotEmpty(saasPgroupRoleRelations)) {
pgrouRelationMap = saasPgroupRoleRelations.stream().collect(Collectors.groupingBy(SaasPgroupRoleRelation::getRoleId)); // 转map<roleId,relation>
// 查询权限集 pgrouRelationMap = saasPgroupRoleRelations.stream().collect(Collectors.groupingBy(SaasPgroupRoleRelation::getRoleId));
pGroupMap = permissionGroupService.query(QuerySaasPermissionGroupReq.builder() // 查询权限集
.ids(saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList())) pGroupMap = permissionGroupService.query(QuerySaasPermissionGroupReq.builder()
.build()) .ids(saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList()))
// 转map<pgroupId> .build())
.stream().collect(Collectors.groupingBy(SaasPermissionGroupVO::getId)); // 转map<pgroupId>
} .stream().collect(Collectors.groupingBy(SaasPermissionGroupVO::getId));
Map<Long, List<SaasPgroupRoleRelation>> finalPgrouRelationMap = pgrouRelationMap; }
Map<Long, List<SaasPermissionGroupVO>> finalPGroupMap = pGroupMap; Map<Long, List<SaasPgroupRoleRelation>> finalPgrouRelationMap = pgrouRelationMap;
return roles.stream().map(role -> { Map<Long, List<SaasPermissionGroupVO>> finalPGroupMap = pGroupMap;
// 获取对应的权限集 return roles.stream().map(role -> {
List<SaasPermissionGroupVO> pGroup = new ArrayList<>(); // 获取对应的权限集
if (finalPgrouRelationMap != null && finalPgrouRelationMap.containsKey(role.getId())) { List<SaasPermissionGroupVO> pGroup = new ArrayList<>();
pGroup = finalPgrouRelationMap.get(role.getId()) if (finalPgrouRelationMap != null && finalPgrouRelationMap.containsKey(role.getId())) {
.stream() pGroup = finalPgrouRelationMap.get(role.getId())
.map(SaasPgroupRoleRelation::getGroupId) .stream()
.map(finalPGroupMap::get) .map(SaasPgroupRoleRelation::getGroupId)
.filter(Objects::nonNull) .map(finalPGroupMap::get)
.flatMap(List::stream) .filter(Objects::nonNull)
.collect(Collectors.toList()); .flatMap(List::stream)
} .collect(Collectors.toList());
SaasRoleVO saasRoleVO = BeanUtil.copyProperties(role, SaasRoleVO.class); }
saasRoleVO.setPermissionGroup(pGroup); SaasRoleVO saasRoleVO = BeanUtil.copyProperties(role, SaasRoleVO.class);
return saasRoleVO; saasRoleVO.setPermissionGroup(pGroup);
}).collect(Collectors.toList()); return saasRoleVO;
} }).collect(Collectors.toList());
}
/** /**
* 通用查询 * 通用查询
* *
* @param req * @param req
* @return * @return
*/ */
@Override @Override
public List<SaasRoleVO> query(QuerySaasRoleReq req) { public List<SaasRoleVO> query(QuerySaasRoleReq req) {
// 根据工作台类型和单位类型查询角色分组 // 根据工作台类型和单位类型查询角色分组
List<SaasRoleGroup> roleGroup = new ArrayList<>(); List<SaasRoleGroup> roleGroup = new ArrayList<>();
if (CollectionUtils.isNotEmpty(req.getWorkspaceTypeCode()) || CollectionUtils.isNotEmpty(req.getOuTypeCode())) { if (CollectionUtils.isNotEmpty(req.getWorkspaceTypeCode()) || CollectionUtils.isNotEmpty(req.getOuTypeCode())) {
roleGroup = saasRoleGroupDao.query(QuerySaasRoleGroupReq.builder() roleGroup = saasRoleGroupDao.query(QuerySaasRoleGroupReq.builder()
.ids(req.getSassRoleGroupIds()) .ids(req.getSassRoleGroupIds())
.workspaceTypeCode(req.getWorkspaceTypeCode()) .workspaceTypeCode(req.getWorkspaceTypeCode())
.ouTypeCode(req.getOuTypeCode()) .ouTypeCode(req.getOuTypeCode())
.build()); .build());
if (CollectionUtils.isEmpty(roleGroup)) { if (CollectionUtils.isEmpty(roleGroup)) {
return new ArrayList<>(); return new ArrayList<>();
} }
} }
// 根据角色分组查询角色分组关联表 // 根据角色分组查询角色分组关联表
List<SaasRoleGroupRelation> groupRelation = new ArrayList<>(); List<SaasRoleGroupRelation> groupRelation = new ArrayList<>();
if (CollectionUtils.isNotEmpty(roleGroup)) { if (CollectionUtils.isNotEmpty(roleGroup)) {
groupRelation = roleGroupRelationDao.lambdaQuery() groupRelation = roleGroupRelationDao.lambdaQuery()
.in(SaasRoleGroupRelation::getSaasRoleGroupId, roleGroup.stream().map(BaseEntity::getId).collect(Collectors.toList())) .in(SaasRoleGroupRelation::getSaasRoleGroupId, roleGroup.stream().map(BaseEntity::getId).collect(Collectors.toList()))
.list(); .list();
} }
// 查询角色 // 查询角色
List<SaasRole> list = saasRoleDao.lambdaQuery() List<SaasRole> list = saasRoleDao.lambdaQuery()
.in(CollectionUtils.isNotEmpty(req.getIds()), BaseEntity::getId, req.getIds()) .in(CollectionUtils.isNotEmpty(req.getIds()), BaseEntity::getId, req.getIds())
.in(CollectionUtils.isNotEmpty(groupRelation), BaseEntity::getId, groupRelation.stream().map(SaasRoleGroupRelation::getRoleId).collect(Collectors.toList())) .in(CollectionUtils.isNotEmpty(groupRelation), BaseEntity::getId, groupRelation.stream().map(SaasRoleGroupRelation::getRoleId).collect(Collectors.toList()))
.eq(StringUtils.isNotBlank(req.getRoleType()),SaasRole::getRoleType,req.getRoleType()) .eq(StringUtils.isNotBlank(req.getRoleType()), SaasRole::getRoleType, req.getRoleType())
.orderByDesc(BaseEntity::getId) .orderByDesc(BaseEntity::getId)
.list(); .list();
return getByIds(list.stream().map(BaseEntity::getId).collect(Collectors.toList())); return getByIds(list.stream().map(BaseEntity::getId).collect(Collectors.toList()));
} }
/** @Override
* 根据角色id查询权限集关联关系 public Map<QueryByIdentityIdTypeReq, List<SaasRoleVO>> queryBatchByIdentityIdType(List<QueryByIdentityIdTypeReq> req) {
*/ HashMap<QueryByIdentityIdTypeReq, List<SaasRoleVO>> result = new HashMap<>();
public List<SaasPgroupRoleRelation> queryPermissionGroupRelation(List<Long> roleIds) { req.forEach(e -> {
return permissionGroupRelation.lambdaQuery() result.put(e,queryByIdentityIdType(e.getIdentityId(),e.getIdentityType(),e.getWorkspaceId(),e.getOuId()));
.in(SaasPgroupRoleRelation::getRoleId, roleIds) });
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value) return result;
.list(); }
}
/**
* 根据角色id查询权限集关联关系
*/
public List<SaasPgroupRoleRelation> queryPermissionGroupRelation(List<Long> roleIds) {
return permissionGroupRelation.lambdaQuery()
.in(SaasPgroupRoleRelation::getRoleId, roleIds)
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
.list();
}
} }