CMS数据清洗优先处理角色、角色分组、用户角色关联关系,避免出现其他角色没有权限点直接跳过的情况
This commit is contained in:
parent
c0165d17a2
commit
ee9e6af1db
@ -147,6 +147,41 @@ public class CMSRoleJobHandler extends IJobHandler {
|
||||
roleGroupDao.save(roleGroup);
|
||||
|
||||
saasPreRoles.forEach(preRole -> {
|
||||
// 创建角色:根据预设角色创建新的角色
|
||||
SaasRole newRole = new SaasRole();
|
||||
newRole.setRoleType(RoleTypeEnum.INIT.getValue());
|
||||
newRole.setName(preRole.getName());
|
||||
newRole.setCreateBy(-1l);
|
||||
newRole.setUpdateBy(-1l);
|
||||
newRole.setOwnerOuId(-1l);
|
||||
newRole.setWorkspaceId(-1l);
|
||||
roleDao.save(newRole);
|
||||
|
||||
// 创建角色分组关联关系
|
||||
SaasRoleGroupRelation saasRoleGroupRelation = new SaasRoleGroupRelation();
|
||||
saasRoleGroupRelation.setRoleId(newRole.getId());
|
||||
saasRoleGroupRelation.setSaasRoleGroupId(roleGroup.getId());
|
||||
roleGroupRelationDao.save(saasRoleGroupRelation);
|
||||
|
||||
// 更新用户关联关系表(根据老的fromRoleId更新至新roldId)
|
||||
// 根据fromeRoleId查询老的roleId
|
||||
// fromRoleId的角色未关联具体角色分组和权限点,可以直接丢弃,已经和产品确认过
|
||||
// SELECT * FROM `saas_pgroup_role_relation` WHERE `role_id` in (
|
||||
// SELECT id FROM saas_role WHERE is_delete=0 and workspace_id != -1 and from_pre_role_id = 0 and role_type!='super_admin' and `NAME` not like '%代班长%' and `NAME` not like '%带班长%')
|
||||
List<SaasRole> oldRoleList = roleDao.lambdaQuery()
|
||||
.eq(SaasRole::getFromPreRoleId, preRole.getId())
|
||||
.list();
|
||||
if (CollectionUtils.isEmpty(oldRoleList)) {
|
||||
log.info("未找到preRole下发的role preRole:{}", JSONUtil.toJsonStr(preRole));
|
||||
return;
|
||||
}
|
||||
List<Long> oldRoleId = oldRoleList.stream().map(BaseEntity::getId).collect(Collectors.toList());
|
||||
// 更新用户角色关联关系
|
||||
roleUserRelationDao.lambdaUpdate()
|
||||
.in(SaasRoleUserRelation::getRoleId,oldRoleId)
|
||||
.set(SaasRoleUserRelation::getRoleId,newRole.getId())
|
||||
.update();
|
||||
|
||||
// 根据角色id查询角色权限集关联关系
|
||||
List<SaasPreGroupRoleRelation> pgroupRoleRelation = saasPreGroupRoleRelationDao.lambdaQuery()
|
||||
.eq(SaasPreGroupRoleRelation::getPreRoleId, preRole.getId())
|
||||
@ -197,16 +232,6 @@ public class CMSRoleJobHandler extends IJobHandler {
|
||||
}).collect(Collectors.toList());
|
||||
pgroupPermissionRelationDao.saveBatch(saasPgroupPermissionRelationList);
|
||||
|
||||
// 创建角色:根据预设角色创建新的角色
|
||||
SaasRole newRole = new SaasRole();
|
||||
newRole.setRoleType(RoleTypeEnum.INIT.getValue());
|
||||
newRole.setName(preRole.getName());
|
||||
newRole.setCreateBy(-1l);
|
||||
newRole.setUpdateBy(-1l);
|
||||
newRole.setOwnerOuId(-1l);
|
||||
newRole.setWorkspaceId(-1l);
|
||||
roleDao.save(newRole);
|
||||
|
||||
// 创建新的角色权限集关联关系
|
||||
SaasPgroupRoleRelation saasPgroupRoleRelation = new SaasPgroupRoleRelation();
|
||||
saasPgroupRoleRelation.setRoleId(newRole.getId());
|
||||
@ -215,33 +240,8 @@ public class CMSRoleJobHandler extends IJobHandler {
|
||||
saasPgroupRoleRelation.setUpdateBy(-1L);
|
||||
pgroupRoleRelationDao.save(saasPgroupRoleRelation);
|
||||
|
||||
// 创建角色分组关联关系
|
||||
SaasRoleGroupRelation saasRoleGroupRelation = new SaasRoleGroupRelation();
|
||||
saasRoleGroupRelation.setRoleId(newRole.getId());
|
||||
saasRoleGroupRelation.setSaasRoleGroupId(roleGroup.getId());
|
||||
roleGroupRelationDao.save(saasRoleGroupRelation);
|
||||
|
||||
// 更新用户关联关系表(根据老的fromRoleId更新至新roldId)
|
||||
// 根据fromeRoleId查询老的roleId
|
||||
// fromRoleId的角色未关联具体角色分组和权限点,可以直接丢弃,已经和产品确认过
|
||||
// SELECT * FROM `saas_pgroup_role_relation` WHERE `role_id` in (
|
||||
// SELECT id FROM saas_role WHERE is_delete=0 and workspace_id != -1 and from_pre_role_id = 0 and role_type!='super_admin' and `NAME` not like '%代班长%' and `NAME` not like '%带班长%')
|
||||
List<SaasRole> list = roleDao.lambdaQuery()
|
||||
.eq(SaasRole::getFromPreRoleId, preRole.getId())
|
||||
.list();
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
log.info("未找到preRole下发的role preRole:{}", JSONUtil.toJsonStr(preRole));
|
||||
return;
|
||||
}
|
||||
List<Long> oldRoleId = list.stream().map(BaseEntity::getId).collect(Collectors.toList());
|
||||
// 更新用户角色关联关系
|
||||
roleUserRelationDao.lambdaUpdate()
|
||||
.in(SaasRoleUserRelation::getRoleId,oldRoleId)
|
||||
.set(SaasRoleUserRelation::getRoleId,newRole.getId())
|
||||
.update();
|
||||
|
||||
// 补充待删除数据
|
||||
deleteRoleId.addAll(list.stream().map(BaseEntity::getId).collect(Collectors.toSet()));
|
||||
deleteRoleId.addAll(oldRoleList.stream().map(BaseEntity::getId).collect(Collectors.toSet()));
|
||||
deleteSaasPermissionGroupId.addAll(oldPermissionGroup.stream().map(BaseEntity::getId).collect(Collectors.toSet()));
|
||||
deletePgroupPermissionRelationId.addAll(oldPgroupPermissionRelation.stream().map(BaseEntity::getId).collect(Collectors.toSet()));
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user