|
@@ -1,10 +1,10 @@
|
|
|
package com.abi.qms.platform.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.abi.qms.platform.dao.entity.UserInfo;
|
|
|
import com.abi.qms.platform.dao.entity.UserResource;
|
|
|
import com.abi.qms.platform.dao.entity.UserRole;
|
|
|
import com.abi.qms.platform.dao.enums.RoleLevelEnum;
|
|
|
+import com.abi.qms.platform.dao.mapper.UserInfoMapper;
|
|
|
import com.abi.qms.platform.dao.mapper.UserMappingRoleResourceMapper;
|
|
|
import com.abi.qms.platform.dao.mapper.UserResourceMapper;
|
|
|
import com.abi.qms.platform.dao.mapper.UserRoleMapper;
|
|
@@ -24,11 +24,9 @@ import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -52,6 +50,9 @@ public class RoleManagerServiceImpl implements RoleManagerService {
|
|
|
@Autowired
|
|
|
private UserResourceService userResourceService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserInfoMapper userInfoMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 创建角色
|
|
|
**/
|
|
@@ -364,6 +365,7 @@ public class RoleManagerServiceImpl implements RoleManagerService {
|
|
|
* 启用角色
|
|
|
**/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void enableRole(EnableRoleReq req) {
|
|
|
List<String> roleCodeList = req.getRoleCodeList();
|
|
|
|
|
@@ -375,7 +377,11 @@ public class RoleManagerServiceImpl implements RoleManagerService {
|
|
|
if(role.getIsEnable()==1){
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+ //查询禁用的上级角色
|
|
|
+ List<UserRole> userRoles = userRoleMapper.superiorRoleDisable(roleCode);
|
|
|
+ if(Objects.nonNull(userRoles) && userRoles.size() > 0){
|
|
|
+ throw new BusinessException("角色" + role.getRoleName() + "的上级角色为停用状态,无法启用。");
|
|
|
+ }
|
|
|
//2-修改状态
|
|
|
role.setIsEnable(1);
|
|
|
userRoleMapper.updateById(role);
|
|
@@ -387,6 +393,7 @@ public class RoleManagerServiceImpl implements RoleManagerService {
|
|
|
* 禁用角色
|
|
|
**/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void disableRole(DisableRoleReq req) {
|
|
|
List<String> roleCodeList = req.getRoleCodeList();
|
|
|
|
|
@@ -398,6 +405,17 @@ public class RoleManagerServiceImpl implements RoleManagerService {
|
|
|
if(role.getIsEnable()==0){
|
|
|
continue;
|
|
|
}
|
|
|
+ //查询该角色下启用中的用户
|
|
|
+ List<UserInfo> userInfos = userInfoMapper.selectUserInfoByRoleCodeEnable(roleCode);
|
|
|
+ if(Objects.nonNull(userInfos) && userInfos.size() > 0){
|
|
|
+ throw new BusinessException("角色" + role.getRoleName() + "已与" + userInfos.size() + "名用户绑定,请解绑后再停用。");
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询启用中的下级角色
|
|
|
+ List<UserRole> userRoles = userRoleMapper.subordinateRoleEnable(role.getRoleCode(), role.getRoleLevel());
|
|
|
+ if(Objects.nonNull(userRoles) && userRoles.size() > 0){
|
|
|
+ throw new BusinessException("角色" + role.getRoleName() + "存在未停用子角色" + userRoles.get(0).getRoleName() + ",请停用子角色后再试。");
|
|
|
+ }
|
|
|
|
|
|
//2-修改状态
|
|
|
role.setIsEnable(0);
|