[add] 角色,部门校验
This commit is contained in:
@ -1,17 +1,13 @@
|
|||||||
package org.dromara.cory.domain.vo;
|
package org.dromara.cory.domain.vo;
|
||||||
|
|
||||||
import org.dromara.cory.domain.BusContactnotice;
|
|
||||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||||
import com.alibaba.excel.annotation.ExcelProperty;
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
import org.dromara.common.excel.annotation.ExcelDictFormat;
|
|
||||||
import org.dromara.common.excel.convert.ExcelDictConvert;
|
|
||||||
import io.github.linpeilie.annotations.AutoMapper;
|
import io.github.linpeilie.annotations.AutoMapper;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.dromara.cory.domain.BusContactnotice;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,5 +48,9 @@ public class BusContactnoticeVo implements Serializable {
|
|||||||
@ExcelProperty(value = "文档内容")
|
@ExcelProperty(value = "文档内容")
|
||||||
private String detail;
|
private String detail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,15 @@ public class SysRoleController extends BaseController {
|
|||||||
return roleService.selectPageRoleList(role, pageQuery);
|
return roleService.selectPageRoleList(role, pageQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:role:list")
|
||||||
|
@GetMapping("/listNoPage/isSubsetDept")
|
||||||
|
public List<SysRoleVo> listNoPageByIsSubsetDept(SysRoleBo roleBo) {
|
||||||
|
return roleService.selectRoleListByIsSubsetDept(roleBo);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出角色信息列表
|
* 导出角色信息列表
|
||||||
*/
|
*/
|
||||||
|
@ -157,6 +157,7 @@ public class SysUserController extends BaseController {
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public R<Void> add(@Validated @RequestBody SysUserBo user) {
|
public R<Void> add(@Validated @RequestBody SysUserBo user) {
|
||||||
deptService.checkDeptDataScope(user.getDeptId());
|
deptService.checkDeptDataScope(user.getDeptId());
|
||||||
|
deptService.checkDeptMatchRole(user.getUserId(), List.of(user.getRoleIds()));
|
||||||
if (!userService.checkUserNameUnique(user)) {
|
if (!userService.checkUserNameUnique(user)) {
|
||||||
return R.fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
|
return R.fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
|
||||||
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
|
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
|
||||||
@ -183,6 +184,7 @@ public class SysUserController extends BaseController {
|
|||||||
userService.checkUserAllowed(user.getUserId());
|
userService.checkUserAllowed(user.getUserId());
|
||||||
userService.checkUserDataScope(user.getUserId());
|
userService.checkUserDataScope(user.getUserId());
|
||||||
deptService.checkDeptDataScope(user.getDeptId());
|
deptService.checkDeptDataScope(user.getDeptId());
|
||||||
|
deptService.checkDeptMatchRole(user.getUserId(), List.of(user.getRoleIds()));
|
||||||
if (!userService.checkUserNameUnique(user)) {
|
if (!userService.checkUserNameUnique(user)) {
|
||||||
return R.fail("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
|
return R.fail("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
|
||||||
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
|
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
|
||||||
|
@ -21,7 +21,7 @@ import org.dromara.system.domain.SysRole;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@AutoMapper(target = SysRole.class, reverseConvertGenerate = false)
|
@AutoMapper(target = SysRole.class, reverseConvertGenerate = false)
|
||||||
public class SysRoleBo extends BaseEntity {
|
public class SysRoleBo extends BaseEntity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色ID
|
* 角色ID
|
||||||
@ -88,6 +88,11 @@ public class SysRoleBo extends BaseEntity {
|
|||||||
*/
|
*/
|
||||||
private String isSpecial;
|
private String isSpecial;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否有子部门
|
||||||
|
*/
|
||||||
|
private String isSubsetDept;
|
||||||
|
|
||||||
public SysRoleBo(Long roleId) {
|
public SysRoleBo(Long roleId) {
|
||||||
this.roleId = roleId;
|
this.roleId = roleId;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
package org.dromara.system.domain.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lcj
|
||||||
|
* @date 2025/7/10 9:25
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum SysDeptIsSubsetEnum {
|
||||||
|
|
||||||
|
YES("1", "是"),
|
||||||
|
|
||||||
|
NO("0", "否");
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
SysDeptIsSubsetEnum(String code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package org.dromara.system.domain.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lcj
|
||||||
|
* @date 2025/7/10 9:26
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum SysRoleIsSpecialEnum {
|
||||||
|
|
||||||
|
YES("1", "是"),
|
||||||
|
NO("0", "否");
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
SysRoleIsSpecialEnum(String code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
@ -93,6 +93,11 @@ public class SysDeptVo implements Serializable {
|
|||||||
@ExcelDictFormat(dictType = "sys_normal_disable")
|
@ExcelDictFormat(dictType = "sys_normal_disable")
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否子集(0否 1是)
|
||||||
|
*/
|
||||||
|
private String isSubset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
|
@ -107,6 +107,14 @@ public interface ISysDeptService {
|
|||||||
*/
|
*/
|
||||||
void checkDeptDataScope(Long deptId);
|
void checkDeptDataScope(Long deptId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验部门和角色是否匹配
|
||||||
|
*
|
||||||
|
* @param deptId 部门id
|
||||||
|
* @param roleIds 角色id列表
|
||||||
|
*/
|
||||||
|
void checkDeptMatchRole(Long deptId, List<Long> roleIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增保存部门信息
|
* 新增保存部门信息
|
||||||
*
|
*
|
||||||
|
@ -27,6 +27,14 @@ public interface ISysRoleService {
|
|||||||
*/
|
*/
|
||||||
List<SysRoleVo> selectRoleList(SysRoleBo role);
|
List<SysRoleVo> selectRoleList(SysRoleBo role);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据条件分页查询角色数据
|
||||||
|
*
|
||||||
|
* @param role 角色信息
|
||||||
|
* @return 角色数据集合信息
|
||||||
|
*/
|
||||||
|
List<SysRoleVo> selectRoleListByIsSubsetDept(SysRoleBo role);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户ID查询角色列表
|
* 根据用户ID查询角色列表
|
||||||
*
|
*
|
||||||
|
@ -10,8 +10,8 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.dromara.common.core.constant.CacheNames;
|
import org.dromara.common.core.constant.CacheNames;
|
||||||
|
import org.dromara.common.core.constant.HttpStatus;
|
||||||
import org.dromara.common.core.constant.SystemConstants;
|
import org.dromara.common.core.constant.SystemConstants;
|
||||||
import org.dromara.common.core.domain.R;
|
|
||||||
import org.dromara.common.core.domain.dto.DeptDTO;
|
import org.dromara.common.core.domain.dto.DeptDTO;
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
import org.dromara.common.core.service.DeptService;
|
import org.dromara.common.core.service.DeptService;
|
||||||
@ -24,6 +24,8 @@ import org.dromara.system.domain.SysRole;
|
|||||||
import org.dromara.system.domain.SysUser;
|
import org.dromara.system.domain.SysUser;
|
||||||
import org.dromara.system.domain.bo.SysDeptBo;
|
import org.dromara.system.domain.bo.SysDeptBo;
|
||||||
import org.dromara.system.domain.bo.SysRoleBo;
|
import org.dromara.system.domain.bo.SysRoleBo;
|
||||||
|
import org.dromara.system.domain.enums.SysDeptIsSubsetEnum;
|
||||||
|
import org.dromara.system.domain.enums.SysRoleIsSpecialEnum;
|
||||||
import org.dromara.system.domain.vo.SysDeptVo;
|
import org.dromara.system.domain.vo.SysDeptVo;
|
||||||
import org.dromara.system.mapper.SysDeptMapper;
|
import org.dromara.system.mapper.SysDeptMapper;
|
||||||
import org.dromara.system.mapper.SysRoleMapper;
|
import org.dromara.system.mapper.SysRoleMapper;
|
||||||
@ -115,12 +117,15 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
|||||||
Long parentId = d.getParentId();
|
Long parentId = d.getParentId();
|
||||||
SysDeptVo sysDeptVo = StreamUtils.findFirst(depts, it -> it.getDeptId().longValue() == parentId);
|
SysDeptVo sysDeptVo = StreamUtils.findFirst(depts, it -> it.getDeptId().longValue() == parentId);
|
||||||
if (ObjectUtil.isNull(sysDeptVo)) {
|
if (ObjectUtil.isNull(sysDeptVo)) {
|
||||||
List<Tree<Long>> trees = TreeBuildUtils.build(depts, parentId, (dept, tree) ->
|
List<Tree<Long>> trees = TreeBuildUtils.build(depts, parentId, (dept, tree) -> {
|
||||||
tree.setId(dept.getDeptId())
|
tree.setId(dept.getDeptId())
|
||||||
.setParentId(dept.getParentId())
|
.setParentId(dept.getParentId())
|
||||||
.setName(dept.getDeptName())
|
.setName(dept.getDeptName())
|
||||||
.setWeight(dept.getOrderNum())
|
.setWeight(dept.getOrderNum())
|
||||||
.putExtra("disabled", SystemConstants.DISABLE.equals(dept.getStatus())));
|
.putExtra("disabled", SystemConstants.DISABLE.equals(dept.getStatus()));
|
||||||
|
tree.putExtra("isSubset", dept.getIsSubset());
|
||||||
|
}
|
||||||
|
);
|
||||||
Tree<Long> tree = StreamUtils.findFirst(trees, it -> it.getId().longValue() == d.getDeptId());
|
Tree<Long> tree = StreamUtils.findFirst(trees, it -> it.getId().longValue() == d.getDeptId());
|
||||||
treeList.add(tree);
|
treeList.add(tree);
|
||||||
}
|
}
|
||||||
@ -294,6 +299,34 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验部门和角色是否匹配
|
||||||
|
*
|
||||||
|
* @param deptId 部门id
|
||||||
|
* @param roleIds 角色id列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void checkDeptMatchRole(Long deptId, List<Long> roleIds) {
|
||||||
|
if (ObjectUtil.isNull(deptId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (LoginHelper.isSuperAdmin()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SysDept dept = baseMapper.selectById(deptId);
|
||||||
|
if (dept.getIsSubset().equals(SysDeptIsSubsetEnum.YES.getCode()) && CollUtil.isNotEmpty(roleIds)) {
|
||||||
|
List<SysRole> roleList = roleMapper.selectByIds(roleIds);
|
||||||
|
for (SysRole role : roleList) {
|
||||||
|
if (!role.getStatus().equals(SystemConstants.NORMAL)) {
|
||||||
|
throw new ServiceException("角色停用,不允许分配", HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
if (role.getIsSpecial().equals(SysRoleIsSpecialEnum.NO.getCode())) {
|
||||||
|
throw new ServiceException("当前部门与角色不匹配,请重新选择", HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增保存部门信息
|
* 新增保存部门信息
|
||||||
*
|
*
|
||||||
@ -312,7 +345,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
|||||||
SysDept dept = MapstructUtils.convert(bo, SysDept.class);
|
SysDept dept = MapstructUtils.convert(bo, SysDept.class);
|
||||||
dept.setAncestors(info.getAncestors() + StringUtils.SEPARATOR + dept.getParentId());
|
dept.setAncestors(info.getAncestors() + StringUtils.SEPARATOR + dept.getParentId());
|
||||||
int insert = baseMapper.insert(dept);
|
int insert = baseMapper.insert(dept);
|
||||||
if (bo.getIsSubset().equals("1")){
|
if (bo.getIsSubset().equals("1")) {
|
||||||
return insert;
|
return insert;
|
||||||
}
|
}
|
||||||
// cory 判断是否需要直接新增角色
|
// cory 判断是否需要直接新增角色
|
||||||
@ -340,7 +373,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
|||||||
role.setMenuIds(bo.getMenuIds());
|
role.setMenuIds(bo.getMenuIds());
|
||||||
role.setDeptIds(bo.getDeptIds());
|
role.setDeptIds(bo.getDeptIds());
|
||||||
role.setIsSpecial("1"); //特殊角色(部门无子集标识特殊角色)
|
role.setIsSpecial("1"); //特殊角色(部门无子集标识特殊角色)
|
||||||
if (bo.getRoleId()!=null){
|
if (bo.getRoleId() != null) {
|
||||||
role.setRoleId(bo.getRoleId());
|
role.setRoleId(bo.getRoleId());
|
||||||
}
|
}
|
||||||
return role;
|
return role;
|
||||||
@ -383,7 +416,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
|||||||
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
||||||
updateParentDeptStatusNormal(dept);
|
updateParentDeptStatusNormal(dept);
|
||||||
}
|
}
|
||||||
if (bo.getIsSubset().equals("1")){
|
if (bo.getIsSubset().equals("1")) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
// cory 角色修改
|
// cory 角色修改
|
||||||
|
@ -29,6 +29,8 @@ import org.dromara.system.domain.SysRoleDept;
|
|||||||
import org.dromara.system.domain.SysRoleMenu;
|
import org.dromara.system.domain.SysRoleMenu;
|
||||||
import org.dromara.system.domain.SysUserRole;
|
import org.dromara.system.domain.SysUserRole;
|
||||||
import org.dromara.system.domain.bo.SysRoleBo;
|
import org.dromara.system.domain.bo.SysRoleBo;
|
||||||
|
import org.dromara.system.domain.enums.SysDeptIsSubsetEnum;
|
||||||
|
import org.dromara.system.domain.enums.SysRoleIsSpecialEnum;
|
||||||
import org.dromara.system.domain.vo.SysRoleVo;
|
import org.dromara.system.domain.vo.SysRoleVo;
|
||||||
import org.dromara.system.mapper.SysRoleDeptMapper;
|
import org.dromara.system.mapper.SysRoleDeptMapper;
|
||||||
import org.dromara.system.mapper.SysRoleMapper;
|
import org.dromara.system.mapper.SysRoleMapper;
|
||||||
@ -72,6 +74,25 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
|
|||||||
return baseMapper.selectRoleList(this.buildQueryWrapper(role));
|
return baseMapper.selectRoleList(this.buildQueryWrapper(role));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据条件分页查询角色数据
|
||||||
|
*
|
||||||
|
* @param role 角色信息
|
||||||
|
* @return 角色数据集合信息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<SysRoleVo> selectRoleListByIsSubsetDept(SysRoleBo role) {
|
||||||
|
LambdaQueryWrapper<SysRole> lqw = new LambdaQueryWrapper<>();
|
||||||
|
String isSubsetDept = role.getIsSubsetDept();
|
||||||
|
if (StringUtils.isNotBlank(isSubsetDept)) {
|
||||||
|
if (isSubsetDept.equals(SysDeptIsSubsetEnum.YES.getCode())) {
|
||||||
|
lqw.eq(SysRole::getIsSpecial, SysRoleIsSpecialEnum.NO.getCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lqw.eq(SysRole::getIsSpecial, true);
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
private Wrapper<SysRole> buildQueryWrapper(SysRoleBo bo) {
|
private Wrapper<SysRole> buildQueryWrapper(SysRoleBo bo) {
|
||||||
Map<String, Object> params = bo.getParams();
|
Map<String, Object> params = bo.getParams();
|
||||||
QueryWrapper<SysRole> wrapper = Wrappers.query();
|
QueryWrapper<SysRole> wrapper = Wrappers.query();
|
||||||
|
Reference in New Issue
Block a user