From bc359054c1330f486de6535fecb4b1325081d19a Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期四, 09 六月 2022 09:40:46 +0800
Subject: [PATCH] bug修复
---
ximon-admin/src/main/java/com/sandu/ximon/admin/service/RoleService.java | 81 +++++++++++++++++++++++++++++++++++-----
1 files changed, 71 insertions(+), 10 deletions(-)
diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/RoleService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/RoleService.java
index c2d4d50..92bd402 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/RoleService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/RoleService.java
@@ -2,6 +2,7 @@
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
+import cn.hutool.system.UserInfo;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.sandu.common.enums.RoleLevelStatus;
@@ -12,6 +13,7 @@
import com.sandu.ximon.admin.param.RoleParam;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.dao.domain.*;
+import com.sandu.ximon.dao.enums.AdministratorEnums;
import com.sandu.ximon.dao.mapper.MenuMapper;
import com.sandu.ximon.dao.mapper.RoleMapper;
import lombok.AllArgsConstructor;
@@ -32,6 +34,7 @@
public class RoleService extends BaseServiceImpl<RoleMapper, Role> {
private final AdminRoleRelationService adminRoleRelationService;
+ private final ClientRoleRelationService clientRoleRelationService;
private final RoleMenuRelationService roleMenuRelationService;
private final MenuService menuService;
private final MenuMapper menuMapper;
@@ -40,10 +43,14 @@
/**
* 鑾峰彇鎸囧畾绠$悊鍛樼殑spring security鏉冮檺璁よ瘉鍒楄〃
*/
- public Collection<GrantedAuthority> mapToGrantedAuthorities(Long adminId) {
-
- // 鑾峰彇绠$悊鍛樼殑瑙掕壊id
- List<Role> roles = listByAdminId(adminId);
+ public Collection<GrantedAuthority> mapToGrantedAuthorities(Long adminId, boolean flag) {
+ List<Role> roles;
+ if (flag) {
+ // 鑾峰彇绠$悊鍛樼殑瑙掕壊id
+ roles = listByAdminId(adminId);
+ } else {
+ roles = listByClientId(adminId);
+ }
if (CollectionUtil.isEmpty(roles)) {
throw new BusinessException("褰撳墠鐢ㄦ埛娌℃湁瑙掕壊");
@@ -82,6 +89,19 @@
return listByIds(roleIdList);
}
+ /**
+ * 鑾峰彇鏌愪釜鏅�氱敤鎴风殑瑙掕壊鍒楄〃
+ */
+ public List<Role> listByClientId(Long clientId) {
+ // 鑾峰彇鏅�氱敤鎴风殑瑙掕壊id
+ List<ClientRoleRelation> list = clientRoleRelationService.list(Wrappers.lambdaQuery(ClientRoleRelation.class).eq(ClientRoleRelation::getClientId, clientId).select(ClientRoleRelation::getRoleId));
+ List<Long> roleIdList = list.stream().map(ClientRoleRelation::getRoleId).collect(Collectors.toList());
+ if (CollectionUtil.isEmpty(roleIdList)) {
+ return null;
+ }
+ return listByIds(roleIdList);
+ }
+
@Transactional(rollbackFor = Exception.class)
public boolean addRole(RoleParam param) {
if (param.getMenuIdList().isEmpty()) {
@@ -90,7 +110,23 @@
Role role = new Role();
role.setName(param.getName());
role.setRemark(param.getRemark());
- role.setLevel(RoleLevelStatus.COMMON.getCode());
+ //璁剧疆瑙掕壊鏉冮檺绛夌骇
+ if (param.getLevel() != null) {
+ if (param.getLevel().equals(RoleLevelStatus.SUPER.getCode())) {
+ throw new BusinessException("鏃犳硶娣诲姞瓒呯骇绠$悊鍛樿鑹�");
+ } else if (param.getLevel().equals(RoleLevelStatus.COMMON.getCode())) {
+ role.setLevel(RoleLevelStatus.COMMON.getCode());
+ } else if (param.getLevel().equals(RoleLevelStatus.NORMAL.getCode())) {
+ role.setLevel(RoleLevelStatus.NORMAL.getCode());
+ } else if (param.getLevel().equals(RoleLevelStatus.NORMAL2.getCode())) {
+ role.setLevel(RoleLevelStatus.NORMAL2.getCode());
+ } else {
+ role.setLevel(RoleLevelStatus.NORMAL.getCode());
+ }
+ } else {
+ role.setLevel(RoleLevelStatus.NORMAL.getCode());
+ }
+
if (!save(role)) {
throw new BusinessException("娣诲姞瑙掕壊澶辫触");
}
@@ -107,11 +143,27 @@
throw new BusinessException("鎵句笉鍒拌鑹蹭俊鎭�");
}
assertLevels(role.getLevel());
- Role update = new Role();
- update.setId(roleId);
- update.setName(param.getName());
- update.setRemark(param.getRemark());
- if (!updateById(update)) {
+
+ role.setName(param.getName());
+ role.setRemark(param.getRemark());
+ //璁剧疆瑙掕壊鏉冮檺绛夌骇
+ if (param.getLevel() != null) {
+ if (param.getLevel().equals(RoleLevelStatus.SUPER.getCode())) {
+ throw new BusinessException("鏃犳硶淇敼鎴愯秴绾х鐞嗗憳瑙掕壊");
+ } else if (param.getLevel().equals(RoleLevelStatus.COMMON.getCode())) {
+ role.setLevel(RoleLevelStatus.COMMON.getCode());
+ } else if (param.getLevel().equals(RoleLevelStatus.NORMAL.getCode())) {
+ role.setLevel(RoleLevelStatus.NORMAL.getCode());
+ } else if (param.getLevel().equals(RoleLevelStatus.NORMAL2.getCode())) {
+ role.setLevel(RoleLevelStatus.NORMAL2.getCode());
+ } else {
+ role.setLevel(RoleLevelStatus.NORMAL.getCode());
+ }
+ } else {
+ role.setLevel(RoleLevelStatus.NORMAL.getCode());
+ }
+
+ if (!updateById(role)) {
throw new BusinessException("缂栬緫瑙掕壊澶辫触");
}
roleMenuRelationService.remove(Wrappers.lambdaQuery(RoleMenuRelation.class).eq(RoleMenuRelation::getRoleId, roleId));
@@ -148,11 +200,20 @@
if (role == null) {
throw new BusinessException("鎵句笉鍒拌鑹�");
}
+ //瓒呯骇绠$悊鍛樹笉鑳藉垹闄�
+ if (RoleLevelStatus.SUPER.getCode().equals(role.getLevel())) {
+ throw new BusinessException("褰撳墠瑙掕壊涓鸿秴绾х鐞嗗憳锛屾棤娉曞垹闄�");
+ }
+
assertLevels(role.getLevel());
List<AdminRoleRelation> list = adminRoleRelationService.list(Wrappers.lambdaQuery(AdminRoleRelation.class).eq(AdminRoleRelation::getRoleId, role));
if (CollectionUtil.isNotEmpty(list)) {
throw new BusinessException("褰撳墠瑙掕壊鏈夌鐞嗗憳浣跨敤锛屾棤娉曞垹闄�");
}
+ List<ClientRoleRelation> listClient = clientRoleRelationService.list(Wrappers.lambdaQuery(ClientRoleRelation.class).eq(ClientRoleRelation::getRoleId, role));
+ if (CollectionUtil.isNotEmpty(listClient)) {
+ throw new BusinessException("褰撳墠瑙掕壊鏈夌敤鎴蜂娇鐢紝鏃犳硶鍒犻櫎");
+ }
roleMenuRelationService.remove(Wrappers.lambdaQuery(RoleMenuRelation.class).eq(RoleMenuRelation::getRoleId, roleId));
return removeById(roleId);
}
--
Gitblit v1.9.3