mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-12 18:15:07 +08:00
1. 完成 Role 简单的 CRUD 的迁移
This commit is contained in:
@ -2,16 +2,12 @@ package cn.iocoder.dashboard.modules.system.controller.permission;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.SysRoleCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.SysRolePageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.SysRoleRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.SysRoleUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.*;
|
||||
import cn.iocoder.dashboard.modules.system.convert.permission.SysRoleConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO;
|
||||
import cn.iocoder.dashboard.modules.system.service.permission.SysRoleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -82,14 +78,10 @@ public class SysRoleController {
|
||||
|
||||
@ApiOperation("修改角色状态")
|
||||
@PostMapping("/update-status")
|
||||
@ApiImplicitParams(value = {
|
||||
@ApiImplicitParam(name = "id", value = "角色编号", required = true, example = "1024"),
|
||||
@ApiImplicitParam(name = "status", value = "状态", required = true, example = "1")
|
||||
})
|
||||
// @PreAuthorize("@ss.hasPermi('system:role:edit')")
|
||||
// @Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
||||
public CommonResult<Boolean> updateRoleStatus(@RequestParam("id") Long id, @RequestParam("status") Integer status) {
|
||||
roleService.updateRoleStatus(id, status);
|
||||
public CommonResult<Boolean> updateRoleStatus(@Validated @RequestBody SysRoleUpdateStatusReqVO reqVO) {
|
||||
roleService.updateRoleStatus(reqVO.getId(), reqVO.getStatus());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -30,4 +30,7 @@ public class SysRoleBaseVO {
|
||||
@ApiModelProperty(value = "角色类型", required = true, example = "1", notes = "见 RoleTypeEnum 枚举")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "备注", example = "我是一个角色")
|
||||
private String remark;
|
||||
|
||||
}
|
||||
|
@ -28,9 +28,6 @@ public class SysRoleRespVO extends SysRoleBaseVO {
|
||||
@ApiModelProperty(value = "角色类型", required = true, example = "1", notes = "参见 RoleTypeEnum 枚举类")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "备注", example = "我是一个角色")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
|
||||
private Date createTime;
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.permission.vo.role;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel("角色更新状态 Request VO")
|
||||
@Data
|
||||
public class SysRoleUpdateStatusReqVO {
|
||||
|
||||
@ApiModelProperty(value = "用户编号", required = true, example = "1024")
|
||||
@NotNull(message = "角色编号不能为空")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举")
|
||||
@NotNull(message = "状态不能为空")
|
||||
// @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user