测回部门和角色权限逻辑
This commit is contained in:
@ -68,6 +68,18 @@ public class SysDeptController extends BaseController {
|
||||
return R.ok(deptService.selectDeptById(deptId));
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 根据部门编号获取详细信息
|
||||
// *
|
||||
// */
|
||||
// @SaCheckPermission("system:dept:informationRetrieval")
|
||||
// @GetMapping(value = "informationRetrieval")
|
||||
// public R<SysDeptBo> getInfo(SysDeptBo dept) {
|
||||
// deptService.checkDeptDataScope(dept.getDeptId());
|
||||
// return R.ok(deptService.selectDeptByIdBo(dept));
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 新增部门
|
||||
*/
|
||||
|
@ -90,4 +90,9 @@ public class SysDept extends TenantEntity {
|
||||
*/
|
||||
private String isSubset;
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
}
|
||||
|
@ -84,70 +84,60 @@ public class SysDeptBo extends BaseEntity {
|
||||
private String isSubset;
|
||||
|
||||
|
||||
/**
|
||||
* ======================
|
||||
* 如果子集为0,则需要新增角色
|
||||
* ======================
|
||||
*/
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 角色权限字符串
|
||||
*/
|
||||
private String roleKey;
|
||||
|
||||
/**
|
||||
* 显示顺序
|
||||
*/
|
||||
private Integer roleSort;
|
||||
|
||||
/**
|
||||
* 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)
|
||||
*/
|
||||
private String dataScope;
|
||||
|
||||
/**
|
||||
* 菜单树选择项是否关联显示
|
||||
*/
|
||||
private Boolean menuCheckStrictly;
|
||||
|
||||
/**
|
||||
* 部门树选择项是否关联显示
|
||||
*/
|
||||
private Boolean deptCheckStrictly;
|
||||
|
||||
/**
|
||||
* 角色状态(0正常 1停用)
|
||||
*/
|
||||
private String roleStatus;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 菜单组
|
||||
*/
|
||||
private Long[] menuIds;
|
||||
|
||||
/**
|
||||
* 部门组(数据权限)
|
||||
*/
|
||||
private Long[] deptIds;
|
||||
|
||||
// public SysDeptBo(Long roleId) {
|
||||
// this.roleId = roleId;
|
||||
// }
|
||||
|
||||
// public boolean isSuperAdmin() {
|
||||
// return SystemConstants.SUPER_ADMIN_ID.equals(this.roleId);
|
||||
// }
|
||||
|
||||
|
||||
// /**
|
||||
// * ======================
|
||||
// * 如果子集为0,则需要新增角色
|
||||
// * ======================
|
||||
// */
|
||||
//
|
||||
// /**
|
||||
// * 角色ID
|
||||
// */
|
||||
// private Long roleId;
|
||||
//
|
||||
// /**
|
||||
// * 角色权限字符串
|
||||
// */
|
||||
// private String roleKey;
|
||||
//
|
||||
// /**
|
||||
// * 显示顺序
|
||||
// */
|
||||
// private Integer roleSort;
|
||||
//
|
||||
// /**
|
||||
// * 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)
|
||||
// */
|
||||
// private String dataScope;
|
||||
//
|
||||
// /**
|
||||
// * 菜单树选择项是否关联显示
|
||||
// */
|
||||
// private Boolean menuCheckStrictly;
|
||||
//
|
||||
// /**
|
||||
// * 部门树选择项是否关联显示
|
||||
// */
|
||||
// private Boolean deptCheckStrictly;
|
||||
//
|
||||
// /**
|
||||
// * 角色状态(0正常 1停用)
|
||||
// */
|
||||
// private String roleStatus;
|
||||
//
|
||||
// /**
|
||||
// * 备注
|
||||
// */
|
||||
// private String remark;
|
||||
//
|
||||
// /**
|
||||
// * 菜单组
|
||||
// */
|
||||
// private Long[] menuIds;
|
||||
//
|
||||
// /**
|
||||
// * 部门组(数据权限)
|
||||
// */
|
||||
// private Long[] deptIds;
|
||||
|
||||
}
|
||||
|
@ -52,6 +52,14 @@ public interface ISysDeptService {
|
||||
*/
|
||||
SysDeptVo selectDeptById(Long deptId);
|
||||
|
||||
// /**
|
||||
// * 根据部门ID查询信息
|
||||
// *
|
||||
// * @return 部门信息
|
||||
// */
|
||||
// SysDeptBo selectDeptByIdBo(SysDeptBo dept);
|
||||
|
||||
|
||||
/**
|
||||
* 通过部门名称查询部门ID
|
||||
*
|
||||
|
@ -12,6 +12,7 @@ import lombok.RequiredArgsConstructor;
|
||||
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.domain.R;
|
||||
import org.dromara.common.core.domain.dto.DeptDTO;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.service.DeptService;
|
||||
@ -27,12 +28,14 @@ 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.SysRoleVo;
|
||||
import org.dromara.system.mapper.SysDeptMapper;
|
||||
import org.dromara.system.mapper.SysRoleMapper;
|
||||
import org.dromara.system.mapper.SysUserMapper;
|
||||
import org.dromara.system.service.ISysDeptService;
|
||||
import org.dromara.system.service.ISysRoleService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
@ -164,6 +167,32 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
||||
return dept;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 根据部门ID查询信息
|
||||
// *
|
||||
// * @return 部门信息
|
||||
// */
|
||||
// @Cacheable(cacheNames = CacheNames.SYS_DEPT, key = "#deptId")
|
||||
// @Override
|
||||
// public SysDeptBo selectDeptByIdBo(SysDeptBo bo) {
|
||||
// SysDeptBo sysDeptBo = new SysDeptBo();
|
||||
// SysDeptVo dept = baseMapper.selectVoById(bo.getDeptId());
|
||||
// if (ObjectUtil.isNull(dept)) {
|
||||
// return null;
|
||||
// }
|
||||
// SysDeptVo parentDept = baseMapper.selectVoOne(new LambdaQueryWrapper<SysDept>()
|
||||
// .select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId()));
|
||||
// dept.setParentName(ObjectUtils.notNullGetter(parentDept, SysDeptVo::getDeptName));
|
||||
//
|
||||
// //cory 获取角色信息
|
||||
// roleService.checkRoleDataScope(bo.getRoleId());
|
||||
// SysRoleVo sysRoleVo = roleService.selectRoleById(bo.getRoleId());
|
||||
// BeanUtils.copyProperties(dept,sysDeptBo);
|
||||
// BeanUtils.copyProperties(sysRoleVo,sysDeptBo);
|
||||
// sysDeptBo.setRoleSort(sysRoleVo.getRoleSort());
|
||||
// return sysDeptBo;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 通过部门名称查询部门ID
|
||||
*
|
||||
@ -342,42 +371,47 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
||||
if (!SystemConstants.NORMAL.equals(info.getStatus())) {
|
||||
throw new ServiceException("部门停用,不允许新增");
|
||||
}
|
||||
if (!"0".equals(info.getIsSubset())){
|
||||
throw new ServiceException("当前部门不允许有子部门");
|
||||
}
|
||||
SysDept dept = MapstructUtils.convert(bo, SysDept.class);
|
||||
dept.setAncestors(info.getAncestors() + StringUtils.SEPARATOR + dept.getParentId());
|
||||
int insert = baseMapper.insert(dept);
|
||||
if (bo.getIsSubset().equals("1")) {
|
||||
return insert;
|
||||
}
|
||||
// cory 判断是否需要直接新增角色
|
||||
SysRoleBo role = getSysRoleBo(bo);
|
||||
roleService.checkRoleAllowed(role);
|
||||
if (!roleService.checkRoleNameUnique(role)) {
|
||||
throw new ServiceException("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
||||
} else if (!roleService.checkRoleKeyUnique(role)) {
|
||||
throw new ServiceException("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
||||
}
|
||||
return roleService.insertRole(role);
|
||||
return baseMapper.insert(dept);
|
||||
// // cory 判断是否需要直接新增角色
|
||||
// SysRoleBo role = getSysRoleBo(bo);
|
||||
// roleService.checkRoleAllowed(role);
|
||||
// if (!roleService.checkRoleNameUnique(role)) {
|
||||
// throw new ServiceException("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
||||
// } else if (!roleService.checkRoleKeyUnique(role)) {
|
||||
// throw new ServiceException("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
||||
// }
|
||||
// roleService.insertRole(role);
|
||||
// SysDept sysDept = new SysDept();
|
||||
// sysDept.setDeptId(dept.getDeptId());
|
||||
// sysDept.setRoleId(role.getRoleId());
|
||||
// baseMapper.updateById(sysDept);
|
||||
// return insert;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static SysRoleBo getSysRoleBo(SysDeptBo bo) {
|
||||
SysRoleBo role = new SysRoleBo();
|
||||
role.setRoleName(bo.getDeptName());
|
||||
role.setRoleKey(bo.getRoleKey());
|
||||
role.setRoleSort(bo.getRoleSort());
|
||||
role.setDataScope(bo.getDataScope());
|
||||
role.setMenuCheckStrictly(bo.getMenuCheckStrictly());
|
||||
role.setDeptCheckStrictly(bo.getDeptCheckStrictly());
|
||||
role.setStatus(bo.getRoleStatus());
|
||||
role.setRemark(bo.getRemark());
|
||||
role.setMenuIds(bo.getMenuIds());
|
||||
role.setDeptIds(bo.getDeptIds());
|
||||
role.setIsSpecial("1"); //特殊角色(部门无子集标识特殊角色)
|
||||
if (bo.getRoleId() != null) {
|
||||
role.setRoleId(bo.getRoleId());
|
||||
}
|
||||
return role;
|
||||
}
|
||||
// @NotNull
|
||||
// private static SysRoleBo getSysRoleBo(SysDeptBo bo) {
|
||||
// SysRoleBo role = new SysRoleBo();
|
||||
// role.setRoleName(bo.getDeptName());
|
||||
// role.setRoleKey(bo.getRoleKey());
|
||||
// role.setRoleSort(bo.getRoleSort());
|
||||
// role.setDataScope(bo.getDataScope());
|
||||
// role.setMenuCheckStrictly(bo.getMenuCheckStrictly());
|
||||
// role.setDeptCheckStrictly(bo.getDeptCheckStrictly());
|
||||
// role.setStatus(bo.getRoleStatus());
|
||||
// role.setRemark(bo.getRemark());
|
||||
// role.setMenuIds(bo.getMenuIds());
|
||||
// role.setDeptIds(bo.getDeptIds());
|
||||
// role.setIsSpecial("1"); //特殊角色(部门无子集标识特殊角色)
|
||||
// if (bo.getRoleId() != null) {
|
||||
// role.setRoleId(bo.getRoleId());
|
||||
// }
|
||||
// return role;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 修改保存部门信息
|
||||
@ -416,23 +450,24 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
||||
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
||||
updateParentDeptStatusNormal(dept);
|
||||
}
|
||||
if (bo.getIsSubset().equals("1")) {
|
||||
return result;
|
||||
}
|
||||
// cory 角色修改
|
||||
SysRoleBo role = getSysRoleBo(bo);
|
||||
roleService.checkRoleAllowed(role);
|
||||
roleService.checkRoleDataScope(role.getRoleId());
|
||||
if (!roleService.checkRoleNameUnique(role)) {
|
||||
throw new ServiceException("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
||||
} else if (!roleService.checkRoleKeyUnique(role)) {
|
||||
throw new ServiceException("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
||||
}
|
||||
if (roleService.updateRole(role) > 0) {
|
||||
roleService.cleanOnlineUserByRole(role.getRoleId());
|
||||
return result;
|
||||
}
|
||||
throw new ServiceException("修改角色'" + role.getRoleName() + "'失败,请联系管理员");
|
||||
// if (bo.getIsSubset().equals("1")) {
|
||||
// return result;
|
||||
// }
|
||||
// // cory 角色修改
|
||||
// SysRoleBo role = getSysRoleBo(bo);
|
||||
// roleService.checkRoleAllowed(role);
|
||||
// roleService.checkRoleDataScope(role.getRoleId());
|
||||
// if (!roleService.checkRoleNameUnique(role)) {
|
||||
// throw new ServiceException("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
||||
// } else if (!roleService.checkRoleKeyUnique(role)) {
|
||||
// throw new ServiceException("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
||||
// }
|
||||
// if (roleService.updateRole(role) > 0) {
|
||||
// roleService.cleanOnlineUserByRole(role.getRoleId());
|
||||
// return result;
|
||||
// }
|
||||
// throw new ServiceException("修改角色'" + role.getRoleName() + "'失败,请联系管理员");
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user