@ -2,6 +2,7 @@ package cn.axzo.tyr.server.service.impl;
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum ;
import cn.axzo.basics.common.exception.ServiceException ;
import cn.axzo.framework.domain.page.PageResp ;
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity ;
import cn.axzo.tyr.client.common.enums.RoleTypeEnum ;
import cn.axzo.tyr.client.common.enums.WorkspaceJoinType ;
@ -13,8 +14,10 @@ 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 ;
import cn.axzo.tyr.client.model.req.RoleWithUserQueryReq ;
import cn.axzo.tyr.client.model.res.IsSuperAdminRes ;
import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes ;
import cn.axzo.tyr.client.model.res.RoleWithUserRes ;
import cn.axzo.tyr.client.model.vo.SaasPermissionGroupVO ;
import cn.axzo.tyr.client.model.vo.SaasRoleGroupVO ;
import cn.axzo.tyr.client.model.vo.SaasRoleVO ;
@ -28,6 +31,8 @@ import cn.axzo.tyr.server.service.SaasRoleGroupRelationService;
import cn.axzo.tyr.server.service.SaasRoleGroupService ;
import cn.hutool.core.bean.BeanUtil ;
import cn.hutool.core.collection.CollectionUtil ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
import com.google.common.collect.Lists ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
@ -76,6 +81,9 @@ public class RoleServiceImpl implements RoleService {
@Autowired
SaasRoleGroupService saasRoleGroupService ;
@Autowired
SaasRoleUserRelationDao saasRoleUserRelationDao ;
@Override
public List < SaasRoleVO > queryByIdentityIdType ( Long identityId , Integer identityType , Long workspaceId , Long ouId ) {
/ / 查询人关联的角色id
@ -112,15 +120,15 @@ public class RoleServiceImpl implements RoleService {
pgrouRelationMap = saasPgroupRoleRelations . stream ( ) . collect ( Collectors . groupingBy ( SaasPgroupRoleRelation : : getRoleId ) ) ;
/ / 查询权限集
pGroupMap = permissionGroupService . page ( QuerySaasPermissionGroupReq . builder ( )
. isCommon ( isCommon )
. roleIds ( roleIds )
. ids ( saasPgroupRoleRelations . stream ( ) . map ( SaasPgroupRoleRelation : : getGroupId ) . collect ( Collectors . toList ( ) ) )
. workspaceId ( workspaceId )
. ouId ( ouId )
. fetchPage ( Boolean . FALSE )
. build ( ) ) . getList ( )
/ / 转map < pgroupId >
. stream ( ) . collect ( Collectors . groupingBy ( SaasPermissionGroupVO : : getId ) ) ;
. isCommon ( isCommon )
. roleIds ( roleIds )
. ids ( saasPgroupRoleRelations . stream ( ) . map ( SaasPgroupRoleRelation : : getGroupId ) . collect ( Collectors . toList ( ) ) )
. workspaceId ( workspaceId )
. ouId ( ouId )
. fetchPage ( Boolean . FALSE )
. build ( ) ) . getList ( )
/ / 转map < pgroupId >
. stream ( ) . collect ( Collectors . groupingBy ( SaasPermissionGroupVO : : getId ) ) ;
}
}
Map < Long , List < SaasPgroupRoleRelation > > finalPgrouRelationMap = pgrouRelationMap ;
@ -130,12 +138,12 @@ public class RoleServiceImpl implements RoleService {
List < SaasPermissionGroupVO > 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 ( ) ) ;
. 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 ) ;
@ -166,10 +174,10 @@ public class RoleServiceImpl implements RoleService {
List < SaasRoleGroup > 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 ( ) ) ;
. ids ( req . getSassRoleGroupIds ( ) )
. workspaceTypeCode ( req . getWorkspaceTypeCode ( ) )
. ouTypeCode ( req . getOuTypeCode ( ) )
. build ( ) ) ;
if ( CollectionUtils . isEmpty ( roleGroup ) ) {
return new ArrayList < > ( ) ;
}
@ -178,21 +186,21 @@ public class RoleServiceImpl implements RoleService {
List < SaasRoleGroupRelation > groupRelation = new ArrayList < > ( ) ;
if ( CollectionUtils . isNotEmpty ( roleGroup ) ) {
groupRelation = roleGroupRelationDao . lambdaQuery ( )
. in ( SaasRoleGroupRelation : : getSaasRoleGroupId , roleGroup . stream ( ) . map ( BaseEntity : : getId ) . collect ( Collectors . toList ( ) ) )
. list ( ) ;
. in ( SaasRoleGroupRelation : : getSaasRoleGroupId , roleGroup . stream ( ) . map ( BaseEntity : : getId ) . collect ( Collectors . toList ( ) ) )
. list ( ) ;
if ( CollectionUtils . isEmpty ( groupRelation ) ) {
return new ArrayList < > ( ) ;
}
}
/ / 查询角色
List < SaasRole > 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 ( ) ) )
. in ( CollectionUtils . isNotEmpty ( req . getRoleType ( ) ) , SaasRole : : getRoleType , req . getRoleType ( ) )
. in ( CollectionUtils . isNotEmpty ( req . getWorkspaceId ( ) ) , SaasRole : : getWorkspaceId , req . getWorkspaceId ( ) )
. in ( CollectionUtils . isNotEmpty ( req . getOuId ( ) ) , SaasRole : : getOwnerOuId , req . getOuId ( ) )
. orderByDesc ( BaseEntity : : getId )
. list ( ) ;
. 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 ( req . getRoleType ( ) ) , SaasRole : : getRoleType , req . getRoleType ( ) )
. in ( CollectionUtils . isNotEmpty ( req . getWorkspaceId ( ) ) , SaasRole : : getWorkspaceId , req . getWorkspaceId ( ) )
. in ( CollectionUtils . isNotEmpty ( req . getOuId ( ) ) , SaasRole : : getOwnerOuId , req . getOuId ( ) )
. orderByDesc ( BaseEntity : : getId )
. list ( ) ;
return getByIds ( list . stream ( ) . map ( BaseEntity : : getId ) . collect ( Collectors . toList ( ) ) , req . getIsCommon ( ) , req . getWorkspaceId ( ) , req . getOuId ( ) , req . getIncludePermissionGroup ( ) ) ;
}
@ -201,12 +209,12 @@ public class RoleServiceImpl implements RoleService {
List < QueryBatchByIdentityIdTypeRes > result = new ArrayList < > ( ) ;
req . forEach ( e - > {
result . add ( QueryBatchByIdentityIdTypeRes . builder ( )
. identityId ( e . getIdentityId ( ) )
. identityType ( e . getIdentityType ( ) )
. workspaceId ( e . getWorkspaceId ( ) )
. ouId ( e . getOuId ( ) )
. role ( queryByIdentityIdType ( e . getIdentityId ( ) , e . getIdentityType ( ) , e . getWorkspaceId ( ) , e . getOuId ( ) ) )
. build ( ) ) ;
. identityId ( e . getIdentityId ( ) )
. identityType ( e . getIdentityType ( ) )
. workspaceId ( e . getWorkspaceId ( ) )
. ouId ( e . getOuId ( ) )
. role ( queryByIdentityIdType ( e . getIdentityId ( ) , e . getIdentityType ( ) , e . getWorkspaceId ( ) , e . getOuId ( ) ) )
. build ( ) ) ;
} ) ;
return result ;
}
@ -268,17 +276,17 @@ public class RoleServiceImpl implements RoleService {
List < SaasRole > list = new ArrayList < > ( ) ;
if ( CollectionUtils . isNotEmpty ( roleIds ) ) {
list = saasRoleDao . lambdaQuery ( )
. in ( BaseEntity : : getId , roleIds )
. eq ( SaasRole : : getRoleType , RoleTypeEnum . SUPER_ADMIN . getValue ( ) )
. list ( ) ;
. in ( BaseEntity : : getId , roleIds )
. eq ( SaasRole : : getRoleType , RoleTypeEnum . SUPER_ADMIN . getValue ( ) )
. list ( ) ;
}
result . add ( IsSuperAdminRes . builder ( )
. identityId ( e . getIdentityId ( ) )
. identityType ( e . getIdentityType ( ) )
. workspaceId ( e . getWorkspaceId ( ) )
. ouId ( e . getOuId ( ) )
. isSuperAdmin ( CollectionUtils . isNotEmpty ( list ) ? true : false )
. build ( ) ) ;
. identityId ( e . getIdentityId ( ) )
. identityType ( e . getIdentityType ( ) )
. workspaceId ( e . getWorkspaceId ( ) )
. ouId ( e . getOuId ( ) )
. isSuperAdmin ( CollectionUtils . isNotEmpty ( list ) ? true : false )
. build ( ) ) ;
} ) ;
return result ;
}
@ -411,9 +419,9 @@ public class RoleServiceImpl implements RoleService {
* /
public List < SaasPgroupRoleRelation > queryPermissionGroupRelation ( List < Long > roleIds ) {
return saasPgroupRoleRelationDao . lambdaQuery ( )
. in ( SaasPgroupRoleRelation : : getRoleId , roleIds )
. eq ( BaseEntity : : getIsDelete , TableIsDeleteEnum . NORMAL . value )
. list ( ) ;
. in ( SaasPgroupRoleRelation : : getRoleId , roleIds )
. eq ( BaseEntity : : getIsDelete , TableIsDeleteEnum . NORMAL . value )
. list ( ) ;
}
@Override
@ -426,7 +434,7 @@ public class RoleServiceImpl implements RoleService {
Set < Long > initRoleId = new HashSet < > ( ) ;
/ / 有标准角 , 查询角色分组
if ( role . stream ( ) . anyMatch ( r - > Objects . equals ( RoleTypeEnum . INIT . getValue ( ) , r . getRoleType ( ) ) ) ) {
List < SaasRoleGroupVO > roleGroupList = saasRoleGroupService . getList ( QuerySaasRoleGroupReq . builder ( )
List < SaasRoleGroupVO > roleGroupList = saasRoleGroupService . getList ( QuerySaasRoleGroupReq . builder ( )
. workspaceTypeCode ( Collections . singletonList ( userRoleInfoMap . getWorkspaceType ( ) . toString ( ) ) )
. ouTypeCode ( Collections . singletonList ( userRoleInfoMap . getWorkspaceJoinType ( ) . getValue ( ) . toString ( ) ) )
. build ( ) ) ;
@ -440,9 +448,51 @@ public class RoleServiceImpl implements RoleService {
. collect ( Collectors . toList ( ) ) ;
return resultRole . stream ( ) . map (
e - > e . getMatchFeature ( userRoleInfoMap . workspaceId , userRoleInfoMap . getOuId ( ) ) )
e - > e . getMatchFeature ( userRoleInfoMap . workspaceId , userRoleInfoMap . getOuId ( ) ) )
. flatMap ( List : : stream )
. map ( PermissionPointTreeNode : : getPermissionPointId )
. collect ( Collectors . toSet ( ) ) ;
}
@Override
public PageResp < RoleWithUserRes > queryRoleWithUser ( RoleWithUserQueryReq req ) {
/ / 按role进行分页查询
Page < SaasRole > rolePage = saasRoleDao
. page ( new Page < > ( req . getPage ( ) , req . getPageSize ( ) ) ,
new LambdaQueryWrapper < SaasRole > ( )
. eq ( SaasRole : : getOwnerOuId , req . getOuId ( ) )
. eq ( SaasRole : : getWorkspaceId , req . getWorkspaceId ( ) ) ) ;
if ( CollectionUtil . isEmpty ( rolePage . getRecords ( ) ) ) {
return PageResp . list ( req . getPage ( ) , req . getPageSize ( ) , 0L , Collections . emptyList ( ) ) ;
}
/ / 反查relation
List < Long > roleIds = rolePage . getRecords ( ) . stream ( ) . map ( SaasRole : : getId ) . collect ( Collectors . toList ( ) ) ;
List < SaasRoleUserRelation > relationList = saasRoleUserRelationDao . list ( new LambdaQueryWrapper < SaasRoleUserRelation > ( ) .
in ( SaasRoleUserRelation : : getRoleId , roleIds ) ) ;
Map < Long , List < SaasRoleUserRelation > > relationMap = relationList . stream ( ) . collect ( Collectors . groupingBy ( SaasRoleUserRelation : : getRoleId ) ) ;
/ / 结果组装 - 用户信息到yoke组装
List < RoleWithUserRes > resultData = new ArrayList < > ( ) ;
for ( SaasRole role : rolePage . getRecords ( ) ) {
RoleWithUserRes roleWithUser = new RoleWithUserRes ( ) ;
roleWithUser . setRoleId ( role . getId ( ) ) ;
roleWithUser . setRoleName ( role . getName ( ) ) ;
roleWithUser . setRoleType ( role . getRoleType ( ) ) ;
List < SaasRoleUserRelation > relations = relationMap . get ( role . getId ( ) ) ;
if ( CollectionUtil . isNotEmpty ( relations ) ) {
List < RoleWithUserRes . UserVO > users = relations . stream ( ) . map ( e - > {
RoleWithUserRes . UserVO user = new RoleWithUserRes . UserVO ( ) ;
user . setIdentityId ( e . getIdentityId ( ) ) ;
user . setIdentityType ( e . getIdentityType ( ) ) ;
return user ;
} ) . collect ( Collectors . toList ( ) ) ;
roleWithUser . setUsers ( users ) ;
}
resultData . add ( roleWithUser ) ;
}
return PageResp . list ( req . getPage ( ) , req . getPageSize ( ) , rolePage . getTotal ( ) , resultData ) ;
}
}