|
@@ -41,7 +41,6 @@ import java.util.stream.Collectors;
|
|
|
public class SysRoleService {
|
|
public class SysRoleService {
|
|
|
|
|
|
|
|
private final SysRoleMapper sysRoleMapper;
|
|
private final SysRoleMapper sysRoleMapper;
|
|
|
- // private final SysUserRoleRelationService sysUserRoleRelationService;
|
|
|
|
|
private final SysUserRoleRelationMapper sysUserRoleRelationMapper;
|
|
private final SysUserRoleRelationMapper sysUserRoleRelationMapper;
|
|
|
private final SysRoleMenuRelationService sysRoleMenuRelationService;
|
|
private final SysRoleMenuRelationService sysRoleMenuRelationService;
|
|
|
private final SysMenuService sysMenuService;
|
|
private final SysMenuService sysMenuService;
|
|
@@ -51,7 +50,6 @@ public class SysRoleService {
|
|
|
* 后台管理-分页列表
|
|
* 后台管理-分页列表
|
|
|
*/
|
|
*/
|
|
|
public PageResult<SysRoleBO> adminList(PageParam pageParam, AdminListSysRoleDTO dto) {
|
|
public PageResult<SysRoleBO> adminList(PageParam pageParam, AdminListSysRoleDTO dto) {
|
|
|
- Set<Long> invisibleRoleIds = determineInvisibleRoleIds();
|
|
|
|
|
Page<SysRoleEntity> entityPage = sysRoleMapper.selectPage(
|
|
Page<SysRoleEntity> entityPage = sysRoleMapper.selectPage(
|
|
|
new Page<>(pageParam.getPageNum(), pageParam.getPageSize()),
|
|
new Page<>(pageParam.getPageNum(), pageParam.getPageSize()),
|
|
|
new QueryWrapper<SysRoleEntity>()
|
|
new QueryWrapper<SysRoleEntity>()
|
|
@@ -60,13 +58,11 @@ public class SysRoleService {
|
|
|
.like(CharSequenceUtil.isNotBlank(dto.getTitle()), SysRoleEntity::getTitle, CharSequenceUtil.cleanBlank(dto.getTitle()))
|
|
.like(CharSequenceUtil.isNotBlank(dto.getTitle()), SysRoleEntity::getTitle, CharSequenceUtil.cleanBlank(dto.getTitle()))
|
|
|
// 值
|
|
// 值
|
|
|
.like(CharSequenceUtil.isNotBlank(dto.getValue()), SysRoleEntity::getValue, CharSequenceUtil.cleanBlank(dto.getValue()))
|
|
.like(CharSequenceUtil.isNotBlank(dto.getValue()), SysRoleEntity::getValue, CharSequenceUtil.cleanBlank(dto.getValue()))
|
|
|
- // 不显示特定角色
|
|
|
|
|
- .notIn(CollUtil.isNotEmpty(invisibleRoleIds), SysRoleEntity::getId, invisibleRoleIds)
|
|
|
|
|
// 排序
|
|
// 排序
|
|
|
.orderByDesc(SysRoleEntity::getCreatedAt)
|
|
.orderByDesc(SysRoleEntity::getCreatedAt)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- return this.entityPage2BOPage(entityPage, true);
|
|
|
|
|
|
|
+ return this.entityPage2BOPage(entityPage);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -97,11 +93,9 @@ public class SysRoleService {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 后台管理-新增
|
|
* 后台管理-新增
|
|
|
- *
|
|
|
|
|
- * @return 主键ID
|
|
|
|
|
*/
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Long adminInsert(AdminInsertOrUpdateSysRoleDTO dto) {
|
|
|
|
|
|
|
+ public void adminInsert(AdminInsertOrUpdateSysRoleDTO dto) {
|
|
|
log.info("[后台管理-新增后台角色] >> 入参={}", dto);
|
|
log.info("[后台管理-新增后台角色] >> 入参={}", dto);
|
|
|
preInsertOrUpdateCheck(dto);
|
|
preInsertOrUpdateCheck(dto);
|
|
|
this.checkExistence(dto);
|
|
this.checkExistence(dto);
|
|
@@ -112,7 +106,6 @@ public class SysRoleService {
|
|
|
|
|
|
|
|
sysRoleMapper.insert(entity);
|
|
sysRoleMapper.insert(entity);
|
|
|
|
|
|
|
|
- return entity.getId();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -160,14 +153,11 @@ public class SysRoleService {
|
|
|
* 后台管理-下拉框数据
|
|
* 后台管理-下拉框数据
|
|
|
*/
|
|
*/
|
|
|
public List<SysRoleBO> adminSelectOptions() {
|
|
public List<SysRoleBO> adminSelectOptions() {
|
|
|
- Set<Long> invisibleRoleIds = determineInvisibleRoleIds();
|
|
|
|
|
List<SysRoleEntity> entityList = sysRoleMapper.selectList(
|
|
List<SysRoleEntity> entityList = sysRoleMapper.selectList(
|
|
|
new QueryWrapper<SysRoleEntity>()
|
|
new QueryWrapper<SysRoleEntity>()
|
|
|
.lambda()
|
|
.lambda()
|
|
|
// 只取特定字段
|
|
// 只取特定字段
|
|
|
.select(SysRoleEntity::getId, SysRoleEntity::getTitle)
|
|
.select(SysRoleEntity::getId, SysRoleEntity::getTitle)
|
|
|
- // 不显示特定角色
|
|
|
|
|
- .notIn(CollUtil.isNotEmpty(invisibleRoleIds), SysRoleEntity::getId, invisibleRoleIds)
|
|
|
|
|
// 排序
|
|
// 排序
|
|
|
.orderByAsc(SysRoleEntity::getId)
|
|
.orderByAsc(SysRoleEntity::getId)
|
|
|
);
|
|
);
|
|
@@ -248,7 +238,7 @@ public class SysRoleService {
|
|
|
).stream().map(SysUserRoleRelationEntity::getRoleId).collect(Collectors.toSet());
|
|
).stream().map(SysUserRoleRelationEntity::getRoleId).collect(Collectors.toSet());
|
|
|
List<SysRoleEntity> userRoles = null;
|
|
List<SysRoleEntity> userRoles = null;
|
|
|
if (CollUtil.isNotEmpty(userRoleIds)) {
|
|
if (CollUtil.isNotEmpty(userRoleIds)) {
|
|
|
- userRoles = sysRoleMapper.selectBatchIds(userRoleIds);
|
|
|
|
|
|
|
+ userRoles = sysRoleMapper.selectByIds(userRoleIds);
|
|
|
}
|
|
}
|
|
|
if (CollUtil.isEmpty(userRoles)) {
|
|
if (CollUtil.isEmpty(userRoles)) {
|
|
|
userRoles = Collections.emptyList();
|
|
userRoles = Collections.emptyList();
|
|
@@ -256,32 +246,6 @@ public class SysRoleService {
|
|
|
return new UserRoleContainer(userRoleIds, userRoles);
|
|
return new UserRoleContainer(userRoleIds, userRoles);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 确定不可见角色IDs
|
|
|
|
|
- * 仅内部使用
|
|
|
|
|
- * 租户管理员:列表中不显示超级管理员角色
|
|
|
|
|
- * 普通角色:列表中不显示超级管理员、租户管理员角色
|
|
|
|
|
- * @return mutable Set,支持外部改变元素
|
|
|
|
|
- */
|
|
|
|
|
- protected Set<Long> determineInvisibleRoleIds() {
|
|
|
|
|
- UserRoleContainer currentUser = getCurrentUserRoleContainer();
|
|
|
|
|
- // 超级管理员:不限制
|
|
|
|
|
- if (currentUser.isAdmin()) {
|
|
|
|
|
- return new HashSet<>();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 普通角色:列表中不显示超级管理员、租户管理员角色
|
|
|
|
|
- Set<Long> ret = sysRoleMapper.selectList(
|
|
|
|
|
- new QueryWrapper<SysRoleEntity>()
|
|
|
|
|
- .lambda()
|
|
|
|
|
- // 仅取主键ID
|
|
|
|
|
- .select(SysRoleEntity::getId)
|
|
|
|
|
- // 值相符
|
|
|
|
|
- .eq(SysRoleEntity::getValue, SysConstant.TENANT_ADMIN_ROLE_VALUE)
|
|
|
|
|
- ).stream().map(SysRoleEntity::getId).collect(Collectors.toSet());
|
|
|
|
|
- ret.add(SysConstant.SUPER_ADMIN_ROLE_ID);
|
|
|
|
|
- return ret;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
----------------------------------------------------------------
|
|
----------------------------------------------------------------
|
|
@@ -332,16 +296,15 @@ public class SysRoleService {
|
|
|
* 实体分页转 BO 分页
|
|
* 实体分页转 BO 分页
|
|
|
*
|
|
*
|
|
|
* @param entityPage 实体分页
|
|
* @param entityPage 实体分页
|
|
|
- * @param fillMenuIds 是否根据实体ID,查询关联菜单IDs并填充到BO
|
|
|
|
|
* @return BO 分页
|
|
* @return BO 分页
|
|
|
*/
|
|
*/
|
|
|
- private PageResult<SysRoleBO> entityPage2BOPage(Page<SysRoleEntity> entityPage, boolean fillMenuIds) {
|
|
|
|
|
|
|
+ private PageResult<SysRoleBO> entityPage2BOPage(Page<SysRoleEntity> entityPage) {
|
|
|
return new PageResult<SysRoleBO>()
|
|
return new PageResult<SysRoleBO>()
|
|
|
.setCurrent(entityPage.getCurrent())
|
|
.setCurrent(entityPage.getCurrent())
|
|
|
.setSize(entityPage.getSize())
|
|
.setSize(entityPage.getSize())
|
|
|
.setTotal(entityPage.getTotal())
|
|
.setTotal(entityPage.getTotal())
|
|
|
// 需填充菜单IDs
|
|
// 需填充菜单IDs
|
|
|
- .setRecords(this.entityList2BOs(entityPage.getRecords(), fillMenuIds));
|
|
|
|
|
|
|
+ .setRecords(this.entityList2BOs(entityPage.getRecords(), true));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -363,19 +326,6 @@ public class SysRoleService {
|
|
|
if (existingEntity != null && !existingEntity.getId().equals(dto.getId())) {
|
|
if (existingEntity != null && !existingEntity.getId().equals(dto.getId())) {
|
|
|
throw new BusinessException(400, "已存在相同后台角色,请重新输入");
|
|
throw new BusinessException(400, "已存在相同后台角色,请重新输入");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- if (dto.creatingNewTenantAdmin()) {
|
|
|
|
|
- long qty = sysRoleMapper.selectCount(
|
|
|
|
|
- new QueryWrapper<SysRoleEntity>()
|
|
|
|
|
- .lambda()
|
|
|
|
|
- // 租户ID相同
|
|
|
|
|
- .eq(SysRoleEntity::getTenantId, dto.getTenantId())
|
|
|
|
|
- // 角色编码相同
|
|
|
|
|
- .eq(SysRoleEntity::getValue, dto.getValue())
|
|
|
|
|
- .last(HelioConstant.CRUD.SQL_LIMIT_1)
|
|
|
|
|
- );
|
|
|
|
|
- SysErrorEnum.NEED_DELETE_EXISTING_TENANT_ADMIN_ROLE.assertTrue(qty <= 0L, dto.getTenantId());
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -386,10 +336,6 @@ public class SysRoleService {
|
|
|
// 角色编码不能为SuperAdmin
|
|
// 角色编码不能为SuperAdmin
|
|
|
throw new BusinessException(SysErrorEnum.ROLE_VALUE_CANNOT_BE, SysConstant.SUPER_ADMIN_ROLE_VALUE);
|
|
throw new BusinessException(SysErrorEnum.ROLE_VALUE_CANNOT_BE, SysConstant.SUPER_ADMIN_ROLE_VALUE);
|
|
|
}
|
|
}
|
|
|
- if (SysConstant.TENANT_ADMIN_ROLE_VALUE.equalsIgnoreCase(dto.getValue()) && !dto.creatingNewTenantAdmin()) {
|
|
|
|
|
- // 除非是新增租户时,同时新增租户管理员角色,否则角色编码不能为Admin
|
|
|
|
|
- throw new BusinessException(SysErrorEnum.ROLE_VALUE_CANNOT_BE, SysConstant.TENANT_ADMIN_ROLE_VALUE);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
boolean isUpdating = Objects.nonNull(dto.getId());
|
|
boolean isUpdating = Objects.nonNull(dto.getId());
|
|
|
if (isUpdating) {
|
|
if (isUpdating) {
|
|
@@ -410,10 +356,10 @@ public class SysRoleService {
|
|
|
throw new BusinessException(SysErrorEnum.CANNOT_DELETE_SUPER_ADMIN_ROLE);
|
|
throw new BusinessException(SysErrorEnum.CANNOT_DELETE_SUPER_ADMIN_ROLE);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- List<SysRoleEntity> existingEntityList = sysRoleMapper.selectBatchIds(ids);
|
|
|
|
|
|
|
+ List<SysRoleEntity> existingEntityList = sysRoleMapper.selectByIds(ids);
|
|
|
for (SysRoleEntity item : existingEntityList) {
|
|
for (SysRoleEntity item : existingEntityList) {
|
|
|
if (item.isAdmin()) {
|
|
if (item.isAdmin()) {
|
|
|
- throw new BusinessException(SysErrorEnum.CANNOT_DELETE_TENANT_ADMIN_ROLE);
|
|
|
|
|
|
|
+ throw new BusinessException(SysErrorEnum.CANNOT_OPERATE_THIS_USER);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -438,12 +384,6 @@ public class SysRoleService {
|
|
|
throw new BusinessException(SysErrorEnum.CANNOT_BIND_MENUS_FOR_SELF);
|
|
throw new BusinessException(SysErrorEnum.CANNOT_BIND_MENUS_FOR_SELF);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 有且只有当前用户为超级管理员,才可以为租户管理员绑定菜单
|
|
|
|
|
- SysRoleEntity targetRole = sysRoleMapper.selectById(dto.getRoleId());
|
|
|
|
|
- if (!targetRole.isAdmin()) {
|
|
|
|
|
- throw new BusinessException(SysErrorEnum.CANNOT_BIND_MENUS_FOR_TENANT_ADMIN_ROLE);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
if (CollUtil.isNotEmpty(dto.getMenuIds()) && !currentUser.isAdmin()) {
|
|
if (CollUtil.isNotEmpty(dto.getMenuIds()) && !currentUser.isAdmin()) {
|
|
|
// 超级管理员之外的角色,都需要校验自身菜单范围是否满足输入值
|
|
// 超级管理员之外的角色,都需要校验自身菜单范围是否满足输入值
|
|
|
Set<Long> visibleMenuIds = sysRoleMenuRelationService.listMenuIdsByRoleIds(currentUser.getRelatedRoleIds());
|
|
Set<Long> visibleMenuIds = sysRoleMenuRelationService.listMenuIdsByRoleIds(currentUser.getRelatedRoleIds());
|