完成角色模块的改造

pull/3/head
YunaiV 2020-07-08 00:08:32 +08:00
parent 4c4708cc8f
commit eee0444e81
18 changed files with 639 additions and 31 deletions

View File

@ -0,0 +1,74 @@
package cn.iocoder.mall.managementweb.controller.permission;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.permission.dto.RoleCreateDTO;
import cn.iocoder.mall.managementweb.controller.permission.dto.RolePageDTO;
import cn.iocoder.mall.managementweb.controller.permission.dto.RoleUpdateDTO;
import cn.iocoder.mall.managementweb.controller.permission.vo.RoleVO;
import cn.iocoder.mall.managementweb.manager.permission.RoleManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* Controller
*/
@RestController
@RequestMapping("/role")
@Api(tags = "角色")
@Validated
public class RoleController {
@Autowired
private RoleManager roleManager;
@PostMapping("/create")
@ApiOperation("创建角色")
public CommonResult<Integer> createRole(@Valid RoleCreateDTO createDTO) {
return success(roleManager.createRole(createDTO));
}
@PostMapping("/update")
@ApiOperation("更新角色")
public CommonResult<Boolean> updateRole(@Valid RoleUpdateDTO updateDTO) {
roleManager.updateRole(updateDTO);
return success(true);
}
@PostMapping("/delete")
@ApiOperation("删除角色")
@ApiImplicitParam(name = "roleId", value = "角色编号", required = true)
public CommonResult<Boolean> deleteRole(@RequestParam("roleId") Integer roleId) {
roleManager.deleteRole(roleId);
return success(true);
}
@GetMapping("/get")
@ApiOperation("获得角色")
public CommonResult<RoleVO> getRole(@RequestParam("roleId") Integer roleId) {
return success(roleManager.getRole(roleId));
}
@GetMapping("/list")
@ApiOperation("获得角色列表")
@ApiImplicitParam(name = "roleId", value = "角色编号列表", required = true)
public CommonResult<List<RoleVO>> getRoles(@RequestParam("roleIds") List<Integer> roleIds) {
return success(roleManager.listRole(roleIds));
}
@GetMapping("/list")
@ApiOperation("获得角色分页")
public CommonResult<PageResult<RoleVO>> pageRole(RolePageDTO pageDTO) {
return success(roleManager.pageRole(pageDTO));
}
}

View File

@ -0,0 +1,19 @@
package cn.iocoder.mall.managementweb.controller.permission.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
@ApiModel("角色创建 DTO")
@Data
public class RoleCreateDTO {
@ApiModelProperty(value = "角色名", required = true, example = "管理员")
@NotEmpty(message = "角色名不能为空")
private String name;
@ApiModelProperty(value = "角色编码", example = "ADMIN")
private String code;
}

View File

@ -0,0 +1,14 @@
package cn.iocoder.mall.managementweb.controller.permission.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel("角色分页 DTO")
@Data
public class RolePageDTO {
@ApiModelProperty(value = "角色名", example = "管理", notes = "模糊匹配")
private String name;
}

View File

@ -0,0 +1,23 @@
package cn.iocoder.mall.managementweb.controller.permission.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@ApiModel("角色更新 DTO")
@Data
public class RoleUpdateDTO {
@ApiModelProperty(value = "角色编号", required = true, example = "1")
@NotNull(message = "角色编号不能为空")
private Integer id;
@ApiModelProperty(value = "角色名", required = true, example = "管理员")
@NotEmpty(message = "角色名不能为空")
private String name;
@ApiModelProperty(value = "角色编码", example = "ADMIN")
private String code;
}

View File

@ -0,0 +1,26 @@
package cn.iocoder.mall.managementweb.controller.permission.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@ApiModel("角色 VO")
@Data
public class RoleVO {
@ApiModelProperty(value = "角色编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "角色名", required = true, example = "管理员")
private String name;
@ApiModelProperty(value = "角色编码", example = "ADMIN")
private String code;
@ApiModelProperty(value = "角色类型", required = true, example = "1", notes = "见 RoleTypeEnum 枚举")
private Integer type;
@ApiModelProperty(value = "创建管理员编号", required = true, example = "1")
private Integer createAdminId;
@ApiModelProperty(value = "创建时间", required = true)
private Date createTime;
}

View File

@ -0,0 +1,30 @@
package cn.iocoder.mall.managementweb.convert.permission;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.permission.vo.RoleVO;
import cn.iocoder.mall.systemservice.rpc.permission.dto.RolePageDTO;
import cn.iocoder.mall.systemservice.rpc.permission.dto.RoleUpdateDTO;
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleCreateDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface RoleConvert {
RoleConvert INSTANCE = Mappers.getMapper(RoleConvert.class);
RoleCreateDTO convert(cn.iocoder.mall.managementweb.controller.permission.dto.RoleCreateDTO bean);
RoleUpdateDTO convert(cn.iocoder.mall.managementweb.controller.permission.dto.RoleUpdateDTO bean);
RoleVO convert(cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO bean);
List<RoleVO> convertList(List<cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO> list);
RolePageDTO convert(cn.iocoder.mall.managementweb.controller.permission.dto.RolePageDTO bean);
PageResult<RoleVO> convertPage(PageResult<cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO> page);
}

View File

@ -0,0 +1,94 @@
package cn.iocoder.mall.managementweb.manager.permission;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.permission.dto.RoleCreateDTO;
import cn.iocoder.mall.managementweb.controller.permission.dto.RolePageDTO;
import cn.iocoder.mall.managementweb.controller.permission.dto.RoleUpdateDTO;
import cn.iocoder.mall.managementweb.controller.permission.vo.RoleVO;
import cn.iocoder.mall.managementweb.convert.permission.RoleConvert;
import cn.iocoder.mall.systemservice.rpc.permission.RoleRpc;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Manager
*/
@Service
public class RoleManager {
@Reference(version = "$ {dubbo.consumer.RoleRpc.version}", validation = "false")
private RoleRpc roleRpc;
/**
*
*
* @param createDTO DTO
* @return
*/
public Integer createRole(RoleCreateDTO createDTO) {
CommonResult<Integer> createRoleResult = roleRpc.createRole(RoleConvert.INSTANCE.convert(createDTO));
createRoleResult.checkError();
return createRoleResult.getData();
}
/**
*
*
* @param updateDTO DTO
*/
public void updateRole(RoleUpdateDTO updateDTO) {
CommonResult<Boolean> updateRoleResult = roleRpc.updateRole(RoleConvert.INSTANCE.convert(updateDTO));
updateRoleResult.checkError();
}
/**
*
*
* @param roleId
*/
public void deleteRole(Integer roleId) {
CommonResult<Boolean> deleteRoleResult = roleRpc.deleteRole(roleId);
deleteRoleResult.checkError();
}
/**
*
*
* @param roleId
* @return
*/
public RoleVO getRole(Integer roleId) {
CommonResult<cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO> getRoleResult = roleRpc.getRole(roleId);
getRoleResult.checkError();
return RoleConvert.INSTANCE.convert(getRoleResult.getData());
}
/**
*
*
* @param roleIds
* @return
*/
public List<RoleVO> listRole(List<Integer> roleIds) {
CommonResult<List<cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO>> listRoleResult = roleRpc.listRole(roleIds);
listRoleResult.checkError();
return RoleConvert.INSTANCE.convertList(listRoleResult.getData());
}
/**
*
*
* @param pageDTO
* @return
*/
public PageResult<RoleVO> pageRole(RolePageDTO pageDTO) {
CommonResult<PageResult<cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO>> pageRoleResult =
roleRpc.pageRole(RoleConvert.INSTANCE.convert(pageDTO));
pageRoleResult.checkError();
return RoleConvert.INSTANCE.convertPage(pageRoleResult.getData());
}
}

View File

@ -32,6 +32,8 @@ dubbo:
version: 1.0.0
ResourceRpc:
version: 1.0.0
RoleRpc:
version: 1.0.0
# Swagger 配置项
swagger:

View File

@ -0,0 +1,63 @@
package cn.iocoder.mall.systemservice.rpc.permission;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.systemservice.rpc.permission.dto.RolePageDTO;
import cn.iocoder.mall.systemservice.rpc.permission.dto.RoleUpdateDTO;
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleCreateDTO;
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO;
import java.util.List;
/**
* Rpc
*/
public interface RoleRpc {
/**
*
*
* @param createDTO DTO
* @return
*/
CommonResult<Integer> createRole(RoleCreateDTO createDTO);
/**
*
*
* @param updateDTO DTO
*/
CommonResult<Boolean> updateRole(RoleUpdateDTO updateDTO);
/**
*
*
* @param roleId
*/
CommonResult<Boolean> deleteRole(Integer roleId);
/**
*
*
* @param roleId
* @return
*/
CommonResult<RoleVO> getRole(Integer roleId);
/**
*
*
* @param roleIds
* @return
*/
CommonResult<List<RoleVO>> listRole(List<Integer> roleIds);
/**
*
*
* @param pageDTO
* @return
*/
CommonResult<PageResult<RoleVO>> pageRole(RolePageDTO pageDTO);
}

View File

@ -0,0 +1,21 @@
package cn.iocoder.mall.systemservice.rpc.permission.dto;
import cn.iocoder.common.framework.vo.PageParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* DTO
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class RolePageDTO extends PageParam {
/**
*
*/
private String name;
}

View File

@ -0,0 +1,32 @@
package cn.iocoder.mall.systemservice.rpc.permission.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* DTO
*/
@Data
@Accessors(chain = true)
public class RoleUpdateDTO implements Serializable {
/**
*
*/
@NotNull(message = "角色编号不能为空")
private Integer id;
/**
*
*/
@NotEmpty(message = "角色名不能为空")
private String name;
/**
*
*/
private String code;
}

View File

@ -0,0 +1,33 @@
package cn.iocoder.mall.systemservice.rpc.permission.vo;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* DTO
*/
@Data
@Accessors(chain = true)
public class RoleCreateDTO implements Serializable {
/**
*
*/
@NotEmpty(message = "角色名不能为空")
private String name;
/**
*
*/
private String code;
/**
*
*/
@NotNull(message = "创建管理员编号不能为空")
private Integer createAdminId;
}

View File

@ -0,0 +1,45 @@
package cn.iocoder.mall.systemservice.rpc.permission.vo;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* VO
*/
@Data
@Accessors(chain = true)
public class RoleVO implements Serializable {
/**
*
*/
private Integer id;
/**
*
*/
private String name;
/**
*
*/
private String code;
/**
*
*/
private Integer type;
/**
*
*/
private Integer createAdminId;
/**
*
*/
private Date createTime;
/**
*
*/
private Date updateTime;
}

View File

@ -2,8 +2,13 @@ package cn.iocoder.mall.systemservice.convert.permission;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.RoleDO;
import cn.iocoder.mall.systemservice.rpc.permission.dto.RolePageDTO;
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleCreateDTO;
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleUpdateDTO;
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO;
import cn.iocoder.mall.systemservice.service.permission.bo.RoleBO;
import cn.iocoder.mall.systemservice.service.permission.bo.RoleCreateBO;
import cn.iocoder.mall.systemservice.service.permission.bo.RolePageBO;
import cn.iocoder.mall.systemservice.service.permission.bo.RoleUpdateBO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
@ -22,8 +27,20 @@ public interface RoleConvert {
RoleDO convert(RoleUpdateBO bean);
RoleCreateBO convert(RoleCreateDTO bean);
RoleUpdateBO convert(RoleUpdateDTO bean);
RolePageBO convert(RolePageDTO bean);
RoleVO convert(RoleBO bean);
List<RoleBO> convertList(List<RoleDO> list);
List<RoleVO> convertList02(List<RoleBO> list);
PageResult<RoleBO> convertPage(IPage<RoleDO> page);
PageResult<RoleVO> convertPage(PageResult<RoleBO> page);
}

View File

@ -0,0 +1,87 @@
package cn.iocoder.mall.systemservice.manager.permission;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.systemservice.convert.permission.RoleConvert;
import cn.iocoder.mall.systemservice.rpc.permission.dto.RolePageDTO;
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleCreateDTO;
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleUpdateDTO;
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO;
import cn.iocoder.mall.systemservice.service.permission.RoleService;
import cn.iocoder.mall.systemservice.service.permission.bo.RoleBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Manager
*/
@Service
public class RoleManager {
@Autowired
private RoleService roleService;
/**
*
*
* @param createDTO DTO
* @return
*/
public Integer createRole(RoleCreateDTO createDTO) {
RoleBO roleBO = roleService.createRole(RoleConvert.INSTANCE.convert(createDTO));
return roleBO.getId();
}
/**
*
*
* @param updateDTO DTO
*/
public void updateRole(RoleUpdateDTO updateDTO) {
roleService.updateRole(RoleConvert.INSTANCE.convert(updateDTO));
}
/**
*
*
* @param roleId
*/
public void deleteRole(Integer roleId) {
roleService.deleteRole(roleId);
}
/**
*
*
* @param roleId
* @return
*/
public RoleVO getRole(Integer roleId) {
RoleBO roleBO = roleService.getRole(roleId);
return RoleConvert.INSTANCE.convert(roleBO);
}
/**
*
*
* @param roleIds
* @return
*/
public List<RoleVO> listRole(List<Integer> roleIds) {
List<RoleBO> roleBOs = roleService.listRole(roleIds);
return RoleConvert.INSTANCE.convertList02(roleBOs);
}
/**
*
*
* @param pageDTO
* @return
*/
public PageResult<RoleVO> pageRole(RolePageDTO pageDTO) {
PageResult<RoleBO> pageResultBO = roleService.pageRole(RoleConvert.INSTANCE.convert(pageDTO));
return RoleConvert.INSTANCE.convertPage(pageResultBO);
}
}

View File

@ -0,0 +1,58 @@
package cn.iocoder.mall.systemservice.rpc.permission;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.systemservice.manager.permission.RoleManager;
import cn.iocoder.mall.systemservice.rpc.permission.dto.RolePageDTO;
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleCreateDTO;
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleUpdateDTO;
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* Rpc
*/
@Service(version = "${dubbo.provider.RoleRpc.version}", validation = "false")
public class RoleRpcImpl implements RoleRpc {
@Autowired
private RoleManager roleManager;
@Override
public CommonResult<Integer> createRole(RoleCreateDTO createDTO) {
return success(roleManager.createRole(createDTO));
}
@Override
public CommonResult<Boolean> updateRole(RoleUpdateDTO updateDTO) {
roleManager.updateRole(updateDTO);
return success(true);
}
@Override
public CommonResult<Boolean> deleteRole(Integer roleId) {
roleManager.deleteRole(roleId);
return success(true);
}
@Override
public CommonResult<RoleVO> getRole(Integer roleId) {
return success(roleManager.getRole(roleId));
}
@Override
public CommonResult<List<RoleVO>> listRole(List<Integer> roleIds) {
return success(roleManager.listRole(roleIds));
}
@Override
public CommonResult<PageResult<RoleVO>> pageRole(RolePageDTO pageDTO) {
return success(roleManager.pageRole(pageDTO));
}
}

View File

@ -42,6 +42,7 @@ public class RoleService {
checkDuplicateRole(createBO.getName(), createBO.getCode(), null);
// 插入到数据库
RoleDO roleDO = RoleConvert.INSTANCE.convert(createBO);
roleDO.setType(RoleTypeEnum.CUSTOM.getType());
roleMapper.insert(roleDO);
// 返回
return RoleConvert.INSTANCE.convert(roleDO);

View File

@ -1,31 +0,0 @@
package cn.iocoder.mall.system.biz.convert.authorization;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.biz.bo.authorization.RoleBO;
import cn.iocoder.mall.system.biz.dataobject.authorization.RoleDO;
import cn.iocoder.mall.system.biz.dto.authorization.RoleAddDTO;
import cn.iocoder.mall.system.biz.dto.authorization.RoleUpdateDTO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface RoleConvert {
RoleConvert INSTANCE = Mappers.getMapper(RoleConvert.class);
RoleBO convert(RoleDO bean);
List<RoleBO> convertList(List<RoleDO> beans);
@Mapping(source = "records", target = "list")
PageResult<RoleBO> convertPage(IPage<RoleDO> page);
RoleDO convert(RoleAddDTO bean);
RoleDO convert(RoleUpdateDTO bean);
}