完善角色处理逻辑

This commit is contained in:
陈维伟 2023-09-11 20:35:42 +08:00
parent 957070b9fc
commit aa7a9a1a9f

View File

@ -3,6 +3,7 @@ package cn.axzo.tyr.server.job;
import java.util.ArrayList;
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
import cn.axzo.tyr.client.model.DictWorkSpaceTypeEnum;
import cn.axzo.tyr.server.repository.entity.*;
import cn.axzo.tyr.server.repository.service.*;
import com.xxl.job.core.biz.model.ReturnT;
@ -50,7 +51,6 @@ public class OMSRoleJobHandler extends IJobHandler {
/**
* 清洗OMS角色相关数据(先通过SQL检查和清除脏数据要不然无法保证各个实体的关联关系)
*
* @param s
* @return
* @throws Exception
@ -62,12 +62,15 @@ public class OMSRoleJobHandler extends IJobHandler {
// 创建角色分组
SaasRoleGroup roleGroup = new SaasRoleGroup();
roleGroup.setWorkspaceTypeCode("6");
roleGroup.setOuTypeCode("7");
roleGroup.setName("管理员");
roleGroup.setWorkspaceId(-1l);
roleGroup.setOuId(-1l);
roleGroupDao.save(roleGroup);
// 查询OMS的角色 workspaceType=6 OMS的角色
List<SaasRole> oldRole = roleDao.lambdaQuery()
.eq(SaasRole::getWorkspaceType, 6)
.notIn(SaasRole::getRoleType,"super_admin")
.notIn(SaasRole::getRoleType, "super_admin")
.list();
// 重置老角色多余的字段
oldRole.forEach(e -> {
@ -99,26 +102,59 @@ public class OMSRoleJobHandler extends IJobHandler {
}
List<SaasPermissionGroup> permissionGroup = saasPermissionGroupDao.lambdaQuery().in(BaseEntity::getId, pgroupRoleRelation.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList())).list();
if (CollectionUtils.isEmpty(permissionGroup)) {
// 删除角色权限集关联关系
pgroupRoleRelation.forEach(e -> {
pgroupRoleRelationDao.lambdaUpdate()
.eq(BaseEntity::getId, e.getId())
.set(BaseEntity::getIsDelete, e.getId())
.update();
});
return;
}
List<SaasPgroupPermissionRelation> pgroupPermissionRelation = pgroupPermissionRelationDao.lambdaQuery().in(SaasPgroupPermissionRelation::getGroupId, permissionGroup.stream().map(BaseEntity::getId).collect(Collectors.toList())).list();
if (CollectionUtils.isEmpty(pgroupPermissionRelation)) {
// 如果没查到权限则表示当前权限集是无意义的删掉
permissionGroup.forEach(e -> e.setIsDelete(e.getId()));
saasPermissionGroupDao.updateBatchById(permissionGroup);
permissionGroup.forEach(e -> {
// 只能通过这种方式删除 update不能删除
saasPermissionGroupDao.lambdaUpdate()
.eq(BaseEntity::getId, e.getId())
.set(BaseEntity::getIsDelete, e.getId())
.update();
});
// 删除角色权限集关联关系
pgroupRoleRelation.forEach(e -> e.setIsDelete(e.getId()));
pgroupRoleRelationDao.updateBatchById(pgroupRoleRelation);
pgroupRoleRelation.forEach(e -> {
pgroupRoleRelationDao.lambdaUpdate()
.eq(BaseEntity::getId, e.getId())
.set(BaseEntity::getIsDelete, e.getId())
.update();
});
return;
}
List<SaasFeature> feature = featureDao.lambdaQuery().in(BaseEntity::getId, pgroupPermissionRelation.stream().map(SaasPgroupPermissionRelation::getFeatureId).collect(Collectors.toList())).list();
if (CollectionUtils.isEmpty(feature)) {
// 删除权限集权限关联关系
pgroupPermissionRelation.forEach(e -> {
// 只能通过这种方式删除 update不能删除
pgroupPermissionRelationDao.lambdaUpdate()
.eq(BaseEntity::getId, e.getId())
.set(BaseEntity::getIsDelete, e.getId())
.update();
});
// 如果没查到权限则表示当前权限集是无意义的删掉
permissionGroup.forEach(e -> e.setIsDelete(e.getId()));
saasPermissionGroupDao.updateBatchById(permissionGroup);
permissionGroup.forEach(e -> {
// 只能通过这种方式删除 update不能删除
saasPermissionGroupDao.lambdaUpdate()
.eq(BaseEntity::getId, e.getId())
.set(BaseEntity::getIsDelete, e.getId())
.update();
});
// 删除角色权限集关联关系
pgroupRoleRelation.forEach(e -> e.setIsDelete(e.getId()));
pgroupRoleRelationDao.updateBatchById(pgroupRoleRelation);
pgroupRoleRelation.forEach(e -> {
pgroupRoleRelationDao.lambdaUpdate()
.eq(BaseEntity::getId, e.getId())
.set(BaseEntity::getIsDelete, e.getId())
.update();
});
return;
}
// 创建新的权限集
@ -148,15 +184,27 @@ public class OMSRoleJobHandler extends IJobHandler {
pgroupPermissionRelationDao.save(saasPgroupPermissionRelation);
});
// 删除老的权限集权限关联关系
pgroupPermissionRelation.forEach(e -> e.setIsDelete(e.getId()));
pgroupPermissionRelationDao.updateBatchById(pgroupPermissionRelation);
pgroupPermissionRelation.forEach(e -> {
pgroupPermissionRelationDao.lambdaUpdate()
.eq(BaseEntity::getId, e.getId())
.set(BaseEntity::getId, e.getId())
.update();
});
// 删除老的角色权限集关联关系
pgroupRoleRelation.forEach(e -> e.setIsDelete(e.getId()));
pgroupRoleRelationDao.updateBatchById(pgroupRoleRelation);
pgroupRoleRelation.forEach(e -> {
pgroupRoleRelationDao.lambdaUpdate()
.eq(BaseEntity::getId, e.getId())
.set(BaseEntity::getId, e.getId())
.update();
});
});
// 删除权限集
deletePgroup.forEach(e -> e.setIsDelete(e.getId()));
saasPermissionGroupDao.updateBatchById(deletePgroup);
deletePgroup.forEach(e -> {
saasPermissionGroupDao.lambdaUpdate()
.eq(BaseEntity::getId, e.getId())
.set(BaseEntity::getId, e.getId())
.update();
});
return ReturnT.SUCCESS;
}
}