1. 完成 Role 简单的 CRUD 的迁移

This commit is contained in:
YunaiV
2021-01-09 13:32:27 +08:00
parent 9e59a6c1ae
commit ad1d1978d2
9 changed files with 229 additions and 179 deletions

View File

@@ -105,15 +105,8 @@ public class SysRoleServiceImpl implements SysRoleService {
@Override
public void updateRole(SysRoleUpdateReqVO reqVO) {
// 校验更新的角色是否存在
SysRoleDO role = roleMapper.selectById(reqVO.getId());
if (roleMapper.selectById(reqVO.getId()) == null) {
throw ServiceExceptionUtil.exception(ROLE_NOT_EXISTS);
}
// 内置角色,不允许修改
if (RoleTypeEnum.SYSTEM.getType().equals(role.getType())) {
throw ServiceExceptionUtil.exception(ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE);
}
// 校验是否可以更新
this.checkUpdateRole(reqVO.getId());
// 校验角色的唯一字段是否重复
checkDuplicateRole(reqVO.getName(), reqVO.getCode(), reqVO.getId());
// 更新到数据库
@@ -123,15 +116,8 @@ public class SysRoleServiceImpl implements SysRoleService {
@Override
public void deleteRole(Long id) {
// 校验删除的角色是否存在
SysRoleDO roleDO = roleMapper.selectById(id);
if (roleMapper.selectById(id) == null) {
throw ServiceExceptionUtil.exception(ROLE_NOT_EXISTS);
}
// 内置角色,不允许删除
if (RoleTypeEnum.SYSTEM.getType().equals(roleDO.getType())) {
throw ServiceExceptionUtil.exception(ROLE_CAN_NOT_DELETE_SYSTEM_TYPE_ROLE);
}
// 校验是否可以更新
this.checkUpdateRole(id);
// 标记删除
roleMapper.deleteById(id);
// 删除相关数据
@@ -152,11 +138,9 @@ public class SysRoleServiceImpl implements SysRoleService {
@Override
public void updateRoleStatus(Long id, Integer status) {
// 校验修改的角色是否存在
SysRoleDO roleDO = roleMapper.selectById(id);
if (roleMapper.selectById(id) == null) {
throw ServiceExceptionUtil.exception(ROLE_NOT_EXISTS);
}
// 校验是否可以更新
this.checkUpdateRole(id);
// 更新状态
SysRoleDO updateObject = new SysRoleDO();
updateObject.setId(id);
updateObject.setStatus(status);
@@ -190,4 +174,20 @@ public class SysRoleServiceImpl implements SysRoleService {
}
}
/**
* 校验角色是否可以被更新
*
* @param id 角色编号
*/
private void checkUpdateRole(Long id) {
SysRoleDO roleDO = roleMapper.selectById(id);
if (roleDO == null) {
throw ServiceExceptionUtil.exception(ROLE_NOT_EXISTS);
}
// 内置角色,不允许删除
if (RoleTypeEnum.SYSTEM.getType().equals(roleDO.getType())) {
throw ServiceExceptionUtil.exception(ROLE_CAN_NOT_DELETE_SYSTEM_TYPE_ROLE);
}
}
}