添加角色和部门逻辑
This commit is contained in:
@ -72,6 +72,12 @@ public class SysRole extends TenantEntity {
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 是否特殊角色(0否 1是)
|
||||
*/
|
||||
private String isSpecial;
|
||||
|
||||
|
||||
public SysRole(Long roleId) {
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
@ -84,77 +84,66 @@ public class SysDeptBo extends BaseEntity {
|
||||
private String isSubset;
|
||||
|
||||
|
||||
// /**
|
||||
// * ======================
|
||||
// * 如果子集为0,则需要新增角色
|
||||
// * ======================
|
||||
// */
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 角色ID
|
||||
// */
|
||||
// private Long roleId;
|
||||
//
|
||||
// /**
|
||||
// * 角色名称
|
||||
// */
|
||||
// @NotBlank(message = "角色名称不能为空")
|
||||
// @Size(min = 0, max = 30, message = "角色名称长度不能超过{max}个字符")
|
||||
// private String roleName;
|
||||
//
|
||||
// /**
|
||||
// * 角色权限字符串
|
||||
// */
|
||||
// @NotBlank(message = "角色权限字符串不能为空")
|
||||
// @Size(min = 0, max = 100, message = "权限字符长度不能超过{max}个字符")
|
||||
// private String roleKey;
|
||||
//
|
||||
// /**
|
||||
// * 显示顺序
|
||||
// */
|
||||
// @NotNull(message = "显示顺序不能为空")
|
||||
// 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;
|
||||
//// }
|
||||
//
|
||||
/**
|
||||
* ======================
|
||||
* 如果子集为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);
|
||||
// }
|
||||
|
@ -21,7 +21,7 @@ import org.dromara.system.domain.SysRole;
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AutoMapper(target = SysRole.class, reverseConvertGenerate = false)
|
||||
public class SysRoleBo extends BaseEntity {
|
||||
public class SysRoleBo extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
@ -83,6 +83,11 @@ public class SysRoleBo extends BaseEntity {
|
||||
*/
|
||||
private Long[] deptIds;
|
||||
|
||||
/**
|
||||
* 是否特殊角色(0否 1是)
|
||||
*/
|
||||
private String isSpecial;
|
||||
|
||||
public SysRoleBo(Long roleId) {
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
@ -88,6 +88,12 @@ public class SysRoleVo implements Serializable {
|
||||
@ExcelProperty(value = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 是否特殊角色(0否 1是)
|
||||
*/
|
||||
@ExcelProperty(value = "是否特殊角色(0否 1是)")
|
||||
private String isSpecial;
|
||||
|
||||
/**
|
||||
* 用户是否存在此角色标识 默认不存在
|
||||
*/
|
||||
|
@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.constant.CacheNames;
|
||||
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;
|
||||
@ -22,11 +23,14 @@ import org.dromara.system.domain.SysDept;
|
||||
import org.dromara.system.domain.SysRole;
|
||||
import org.dromara.system.domain.SysUser;
|
||||
import org.dromara.system.domain.bo.SysDeptBo;
|
||||
import org.dromara.system.domain.bo.SysRoleBo;
|
||||
import org.dromara.system.domain.vo.SysDeptVo;
|
||||
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.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
@ -49,6 +53,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
||||
private final SysDeptMapper baseMapper;
|
||||
private final SysRoleMapper roleMapper;
|
||||
private final SysUserMapper userMapper;
|
||||
private final ISysRoleService roleService;
|
||||
|
||||
/**
|
||||
* 查询部门管理数据
|
||||
@ -297,6 +302,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
||||
*/
|
||||
@CacheEvict(cacheNames = CacheNames.SYS_DEPT_AND_CHILD, allEntries = true)
|
||||
@Override
|
||||
@Transactional
|
||||
public int insertDept(SysDeptBo bo) {
|
||||
SysDept info = baseMapper.selectById(bo.getParentId());
|
||||
// 如果父节点不为正常状态,则不允许新增子节点
|
||||
@ -305,7 +311,39 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
||||
}
|
||||
SysDept dept = MapstructUtils.convert(bo, SysDept.class);
|
||||
dept.setAncestors(info.getAncestors() + StringUtils.SEPARATOR + dept.getParentId());
|
||||
return baseMapper.insert(dept);
|
||||
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);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -345,7 +383,23 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
||||
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
||||
updateParentDeptStatusNormal(dept);
|
||||
}
|
||||
return result;
|
||||
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() + "'失败,请联系管理员");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,6 +76,7 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
QueryWrapper<SysRole> wrapper = Wrappers.query();
|
||||
wrapper.eq("r.del_flag", SystemConstants.NORMAL)
|
||||
.eq(ObjectUtil.isNotNull(bo.getIsSpecial()), "r.is_special", bo.getIsSpecial())
|
||||
.eq(ObjectUtil.isNotNull(bo.getRoleId()), "r.role_id", bo.getRoleId())
|
||||
.like(StringUtils.isNotBlank(bo.getRoleName()), "r.role_name", bo.getRoleName())
|
||||
.eq(StringUtils.isNotBlank(bo.getStatus()), "r.status", bo.getStatus())
|
||||
|
@ -18,7 +18,8 @@
|
||||
r.status,
|
||||
r.del_flag,
|
||||
r.create_time,
|
||||
r.remark
|
||||
r.remark,
|
||||
r.is_special
|
||||
from sys_role r
|
||||
left join sys_user_role sur on sur.role_id = r.role_id
|
||||
left join sys_user u on u.user_id = sur.user_id
|
||||
@ -46,7 +47,8 @@
|
||||
r.role_key,
|
||||
r.role_sort,
|
||||
r.data_scope,
|
||||
r.status
|
||||
r.status,
|
||||
r.is_special
|
||||
from sys_role r
|
||||
WHERE r.del_flag = '0' and r.role_id in (select role_id from sys_user_role where user_id = #{userId})
|
||||
</select>
|
||||
|
Reference in New Issue
Block a user