From 81ab60e44f70fc2bbc79e3a0c02e46f15ccb2278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E7=BB=B4=E4=BC=9F?= Date: Mon, 11 Sep 2023 11:31:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=A0=B9=E6=8D=AE=E8=BA=AB?= =?UTF-8?q?=E4=BB=BDid=E7=B1=BB=E5=9E=8B=E6=89=B9=E9=87=8F=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/axzo/tyr/client/feign/SaasRoleApi.java | 14 +- .../model/req/QueryByIdentityIdTypeReq.java | 22 ++ .../controller/role/SaasRoleController.java | 8 + .../axzo/tyr/server/service/RoleService.java | 5 +- .../server/service/impl/RoleServiceImpl.java | 231 +++++++++--------- 5 files changed, 168 insertions(+), 112 deletions(-) create mode 100644 tyr-api/src/main/java/cn/axzo/tyr/client/model/req/QueryByIdentityIdTypeReq.java diff --git a/tyr-api/src/main/java/cn/axzo/tyr/client/feign/SaasRoleApi.java b/tyr-api/src/main/java/cn/axzo/tyr/client/feign/SaasRoleApi.java index 710ceb77..c072b181 100644 --- a/tyr-api/src/main/java/cn/axzo/tyr/client/feign/SaasRoleApi.java +++ b/tyr-api/src/main/java/cn/axzo/tyr/client/feign/SaasRoleApi.java @@ -1,6 +1,7 @@ package cn.axzo.tyr.client.feign; 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.vo.SaasRoleVO; 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 java.util.List; +import java.util.Map; /** * 角色 @@ -39,10 +41,20 @@ public interface SaasRoleApi { ApiResult> query(@RequestBody QuerySaasRoleReq req); /** - * 根据身份id 身份类型查询权限列表 + * 根据身份id身份类型查询权限列表(批量) + * @param identityType 身份类型 1:工人 2:班组长 3:从业人员 4:监管人员 5:运营人员 * @return */ @GetMapping("/api/saasRole/queryByIdentityIdType") ApiResult> 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>> queryBatchByIdentityIdType(@RequestBody List req); + + + } diff --git a/tyr-api/src/main/java/cn/axzo/tyr/client/model/req/QueryByIdentityIdTypeReq.java b/tyr-api/src/main/java/cn/axzo/tyr/client/model/req/QueryByIdentityIdTypeReq.java new file mode 100644 index 00000000..e5f04f63 --- /dev/null +++ b/tyr-api/src/main/java/cn/axzo/tyr/client/model/req/QueryByIdentityIdTypeReq.java @@ -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; +} diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/controller/role/SaasRoleController.java b/tyr-server/src/main/java/cn/axzo/tyr/server/controller/role/SaasRoleController.java index cc274fff..e030d5d9 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/controller/role/SaasRoleController.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/controller/role/SaasRoleController.java @@ -2,6 +2,7 @@ package cn.axzo.tyr.server.controller.role; import cn.axzo.framework.domain.web.result.ApiResult; 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.vo.SaasRoleVO; 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 java.util.List; +import java.util.Map; /** * 权限 @@ -46,4 +48,10 @@ public class SaasRoleController implements SaasRoleApi { public ApiResult> queryByIdentityIdType(Long identityId, Integer identityType,Long workspaceId,Long ouId) { return ApiResult.ok(roleService.queryByIdentityIdType(identityId, identityType,workspaceId,ouId)); } + + @Override + public ApiResult>> queryBatchByIdentityIdType(List req) { + return ApiResult.ok(roleService.queryBatchByIdentityIdType(req)); + } + } diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/service/RoleService.java b/tyr-server/src/main/java/cn/axzo/tyr/server/service/RoleService.java index 3bb440cd..b8df6dd9 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/service/RoleService.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/service/RoleService.java @@ -1,10 +1,11 @@ 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.vo.SaasRoleVO; import java.util.List; +import java.util.Map; /** * 角色 @@ -19,4 +20,6 @@ public interface RoleService { List queryByIdentityIdType(Long identityId, Integer identityType,Long workspaceId,Long ouId); List query(QuerySaasRoleReq req); + + Map> queryBatchByIdentityIdType(List req); } diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/RoleServiceImpl.java b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/RoleServiceImpl.java index bd5548cd..5ca1659a 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/RoleServiceImpl.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/RoleServiceImpl.java @@ -2,6 +2,7 @@ package cn.axzo.tyr.server.service.impl; import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum; 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.QuerySaasRoleGroupReq; import cn.axzo.tyr.client.model.req.QuerySaasRoleReq; @@ -34,118 +35,128 @@ import java.util.stream.Collectors; @Service public class RoleServiceImpl implements RoleService { - @Autowired - SaasRoleUserRelationDao roleUserRelationDao; - @Autowired - SaasRoleDao saasRoleDao; - @Autowired - PermissionGroupService permissionGroupService; - @Autowired - SaasPgroupRoleRelationDao permissionGroupRelation; - @Autowired - SaasRoleGroupDao saasRoleGroupDao; - @Autowired - SaasRoleGroupRelationDao roleGroupRelationDao; + @Autowired + SaasRoleUserRelationDao roleUserRelationDao; + @Autowired + SaasRoleDao saasRoleDao; + @Autowired + PermissionGroupService permissionGroupService; + @Autowired + SaasPgroupRoleRelationDao permissionGroupRelation; + @Autowired + SaasRoleGroupDao saasRoleGroupDao; + @Autowired + SaasRoleGroupRelationDao roleGroupRelationDao; - @Override - public List queryByIdentityIdType(Long identityId, Integer identityType,Long workspaceId,Long ouId) { - // 查询人关联的角色id - List roleIds = roleUserRelationDao.query(identityId, identityType,workspaceId,ouId).stream().map(SaasRoleUserRelation::getRoleId).collect(Collectors.toList()); - if (CollectionUtils.isEmpty(roleIds)) { - return new ArrayList<>(); - } - return getByIds(roleIds); - } + @Override + public List queryByIdentityIdType(Long identityId, Integer identityType, Long workspaceId, Long ouId) { + // 查询人关联的角色id + List roleIds = roleUserRelationDao.query(identityId, identityType, workspaceId, ouId).stream().map(SaasRoleUserRelation::getRoleId).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(roleIds)) { + return new ArrayList<>(); + } + return getByIds(roleIds); + } - /** - * 根据id查询权限详情包含权限组合权限集(底层基础方法) - * @return - */ - public List getByIds(List roleIds) { - if (CollectionUtils.isEmpty(roleIds)) { - return new ArrayList<>(); - } - // 查询角色信息 - List roles = saasRoleDao.lambdaQuery().in(BaseEntity::getId, roleIds).list(); - // 查询权限集关联关系 - List saasPgroupRoleRelations = queryPermissionGroupRelation(roleIds); - // 查询权限集 - Map> pgrouRelationMap = null; - Map> pGroupMap = null; - if (CollectionUtils.isNotEmpty(saasPgroupRoleRelations)) { - // 转map - pgrouRelationMap = saasPgroupRoleRelations.stream().collect(Collectors.groupingBy(SaasPgroupRoleRelation::getRoleId)); - // 查询权限集 - pGroupMap = permissionGroupService.query(QuerySaasPermissionGroupReq.builder() - .ids(saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList())) - .build()) - // 转map - .stream().collect(Collectors.groupingBy(SaasPermissionGroupVO::getId)); - } - Map> finalPgrouRelationMap = pgrouRelationMap; - Map> finalPGroupMap = pGroupMap; - return roles.stream().map(role -> { - // 获取对应的权限集 - List pGroup = new ArrayList<>(); - if (finalPgrouRelationMap != null && finalPgrouRelationMap.containsKey(role.getId())) { - pGroup = finalPgrouRelationMap.get(role.getId()) - .stream() - .map(SaasPgroupRoleRelation::getGroupId) - .map(finalPGroupMap::get) - .filter(Objects::nonNull) - .flatMap(List::stream) - .collect(Collectors.toList()); - } - SaasRoleVO saasRoleVO = BeanUtil.copyProperties(role, SaasRoleVO.class); - saasRoleVO.setPermissionGroup(pGroup); - return saasRoleVO; - }).collect(Collectors.toList()); - } + /** + * 根据id查询权限详情包含权限组合权限集(底层基础方法) + * + * @return + */ + public List getByIds(List roleIds) { + if (CollectionUtils.isEmpty(roleIds)) { + return new ArrayList<>(); + } + // 查询角色信息 + List roles = saasRoleDao.lambdaQuery().in(BaseEntity::getId, roleIds).list(); + // 查询权限集关联关系 + List saasPgroupRoleRelations = queryPermissionGroupRelation(roleIds); + // 查询权限集 + Map> pgrouRelationMap = null; + Map> pGroupMap = null; + if (CollectionUtils.isNotEmpty(saasPgroupRoleRelations)) { + // 转map + pgrouRelationMap = saasPgroupRoleRelations.stream().collect(Collectors.groupingBy(SaasPgroupRoleRelation::getRoleId)); + // 查询权限集 + pGroupMap = permissionGroupService.query(QuerySaasPermissionGroupReq.builder() + .ids(saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList())) + .build()) + // 转map + .stream().collect(Collectors.groupingBy(SaasPermissionGroupVO::getId)); + } + Map> finalPgrouRelationMap = pgrouRelationMap; + Map> finalPGroupMap = pGroupMap; + return roles.stream().map(role -> { + // 获取对应的权限集 + List pGroup = new ArrayList<>(); + if (finalPgrouRelationMap != null && finalPgrouRelationMap.containsKey(role.getId())) { + pGroup = finalPgrouRelationMap.get(role.getId()) + .stream() + .map(SaasPgroupRoleRelation::getGroupId) + .map(finalPGroupMap::get) + .filter(Objects::nonNull) + .flatMap(List::stream) + .collect(Collectors.toList()); + } + SaasRoleVO saasRoleVO = BeanUtil.copyProperties(role, SaasRoleVO.class); + saasRoleVO.setPermissionGroup(pGroup); + return saasRoleVO; + }).collect(Collectors.toList()); + } - /** - * 通用查询 - * - * @param req - * @return - */ - @Override - public List query(QuerySaasRoleReq req) { - // 根据工作台类型和单位类型查询角色分组 - List roleGroup = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(req.getWorkspaceTypeCode()) || CollectionUtils.isNotEmpty(req.getOuTypeCode())) { - roleGroup = saasRoleGroupDao.query(QuerySaasRoleGroupReq.builder() - .ids(req.getSassRoleGroupIds()) - .workspaceTypeCode(req.getWorkspaceTypeCode()) - .ouTypeCode(req.getOuTypeCode()) - .build()); - if (CollectionUtils.isEmpty(roleGroup)) { - return new ArrayList<>(); - } - } - // 根据角色分组查询角色分组关联表 - List groupRelation = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(roleGroup)) { - groupRelation = roleGroupRelationDao.lambdaQuery() - .in(SaasRoleGroupRelation::getSaasRoleGroupId, roleGroup.stream().map(BaseEntity::getId).collect(Collectors.toList())) - .list(); - } - // 查询角色 - List list = saasRoleDao.lambdaQuery() - .in(CollectionUtils.isNotEmpty(req.getIds()), BaseEntity::getId, req.getIds()) - .in(CollectionUtils.isNotEmpty(groupRelation), BaseEntity::getId, groupRelation.stream().map(SaasRoleGroupRelation::getRoleId).collect(Collectors.toList())) - .eq(StringUtils.isNotBlank(req.getRoleType()),SaasRole::getRoleType,req.getRoleType()) - .orderByDesc(BaseEntity::getId) - .list(); - return getByIds(list.stream().map(BaseEntity::getId).collect(Collectors.toList())); - } + /** + * 通用查询 + * + * @param req + * @return + */ + @Override + public List query(QuerySaasRoleReq req) { + // 根据工作台类型和单位类型查询角色分组 + List roleGroup = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(req.getWorkspaceTypeCode()) || CollectionUtils.isNotEmpty(req.getOuTypeCode())) { + roleGroup = saasRoleGroupDao.query(QuerySaasRoleGroupReq.builder() + .ids(req.getSassRoleGroupIds()) + .workspaceTypeCode(req.getWorkspaceTypeCode()) + .ouTypeCode(req.getOuTypeCode()) + .build()); + if (CollectionUtils.isEmpty(roleGroup)) { + return new ArrayList<>(); + } + } + // 根据角色分组查询角色分组关联表 + List groupRelation = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(roleGroup)) { + groupRelation = roleGroupRelationDao.lambdaQuery() + .in(SaasRoleGroupRelation::getSaasRoleGroupId, roleGroup.stream().map(BaseEntity::getId).collect(Collectors.toList())) + .list(); + } + // 查询角色 + List list = saasRoleDao.lambdaQuery() + .in(CollectionUtils.isNotEmpty(req.getIds()), BaseEntity::getId, req.getIds()) + .in(CollectionUtils.isNotEmpty(groupRelation), BaseEntity::getId, groupRelation.stream().map(SaasRoleGroupRelation::getRoleId).collect(Collectors.toList())) + .eq(StringUtils.isNotBlank(req.getRoleType()), SaasRole::getRoleType, req.getRoleType()) + .orderByDesc(BaseEntity::getId) + .list(); + return getByIds(list.stream().map(BaseEntity::getId).collect(Collectors.toList())); + } - /** - * 根据角色id查询权限集关联关系 - */ - public List queryPermissionGroupRelation(List roleIds) { - return permissionGroupRelation.lambdaQuery() - .in(SaasPgroupRoleRelation::getRoleId, roleIds) - .eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value) - .list(); - } + @Override + public Map> queryBatchByIdentityIdType(List req) { + HashMap> result = new HashMap<>(); + req.forEach(e -> { + result.put(e,queryByIdentityIdType(e.getIdentityId(),e.getIdentityType(),e.getWorkspaceId(),e.getOuId())); + }); + return result; + } + + /** + * 根据角色id查询权限集关联关系 + */ + public List queryPermissionGroupRelation(List roleIds) { + return permissionGroupRelation.lambdaQuery() + .in(SaasPgroupRoleRelation::getRoleId, roleIds) + .eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value) + .list(); + } }