From eee0444e812cf00a6f879d936028338b2ecee267 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Wed, 8 Jul 2020 00:08:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=A7=92=E8=89=B2=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E7=9A=84=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/permission/RoleController.java | 74 +++++++++++++++ .../permission/dto/RoleCreateDTO.java | 19 ++++ .../permission/dto/RolePageDTO.java | 14 +++ .../permission/dto/RoleUpdateDTO.java | 23 +++++ .../controller/permission/vo/RoleVO.java | 26 +++++ .../convert/permission/RoleConvert.java | 30 ++++++ .../manager/permission/RoleManager.java | 94 +++++++++++++++++++ .../src/main/resources/application.yml | 2 + .../systemservice/rpc/permission/RoleRpc.java | 63 +++++++++++++ .../rpc/permission/dto/RolePageDTO.java | 21 +++++ .../rpc/permission/dto/RoleUpdateDTO.java | 32 +++++++ .../rpc/permission/vo/RoleCreateDTO.java | 33 +++++++ .../rpc/permission/vo/RoleVO.java | 45 +++++++++ .../convert/permission/RoleConvert.java | 17 ++++ .../manager/permission/RoleManager.java | 87 +++++++++++++++++ .../rpc/permission/RoleRpcImpl.java | 58 ++++++++++++ .../service/permission/RoleService.java | 1 + .../convert/authorization/RoleConvert.java | 31 ------ 18 files changed, 639 insertions(+), 31 deletions(-) create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/RoleController.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/RoleCreateDTO.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/RolePageDTO.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/RoleUpdateDTO.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/vo/RoleVO.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/RoleConvert.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/RoleManager.java create mode 100644 system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpc.java create mode 100644 system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/RolePageDTO.java create mode 100644 system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/RoleUpdateDTO.java create mode 100644 system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/vo/RoleCreateDTO.java create mode 100644 system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/vo/RoleVO.java create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/RoleManager.java create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpcImpl.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/authorization/RoleConvert.java diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/RoleController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/RoleController.java new file mode 100644 index 000000000..92a0bafea --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/RoleController.java @@ -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 createRole(@Valid RoleCreateDTO createDTO) { + return success(roleManager.createRole(createDTO)); + } + + @PostMapping("/update") + @ApiOperation("更新角色") + public CommonResult updateRole(@Valid RoleUpdateDTO updateDTO) { + roleManager.updateRole(updateDTO); + return success(true); + } + + @PostMapping("/delete") + @ApiOperation("删除角色") + @ApiImplicitParam(name = "roleId", value = "角色编号", required = true) + public CommonResult deleteRole(@RequestParam("roleId") Integer roleId) { + roleManager.deleteRole(roleId); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得角色") + public CommonResult getRole(@RequestParam("roleId") Integer roleId) { + return success(roleManager.getRole(roleId)); + } + + @GetMapping("/list") + @ApiOperation("获得角色列表") + @ApiImplicitParam(name = "roleId", value = "角色编号列表", required = true) + public CommonResult> getRoles(@RequestParam("roleIds") List roleIds) { + return success(roleManager.listRole(roleIds)); + } + + @GetMapping("/list") + @ApiOperation("获得角色分页") + public CommonResult> pageRole(RolePageDTO pageDTO) { + return success(roleManager.pageRole(pageDTO)); + } + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/RoleCreateDTO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/RoleCreateDTO.java new file mode 100644 index 000000000..36961c2e0 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/RoleCreateDTO.java @@ -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; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/RolePageDTO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/RolePageDTO.java new file mode 100644 index 000000000..63901bd4f --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/RolePageDTO.java @@ -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; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/RoleUpdateDTO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/RoleUpdateDTO.java new file mode 100644 index 000000000..5299f4e64 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/RoleUpdateDTO.java @@ -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; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/vo/RoleVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/vo/RoleVO.java new file mode 100644 index 000000000..f3e26fa0e --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/vo/RoleVO.java @@ -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; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/RoleConvert.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/RoleConvert.java new file mode 100644 index 000000000..189df7381 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/RoleConvert.java @@ -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 convertList(List list); + + RolePageDTO convert(cn.iocoder.mall.managementweb.controller.permission.dto.RolePageDTO bean); + + PageResult convertPage(PageResult page); + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/RoleManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/RoleManager.java new file mode 100644 index 000000000..e5c0512e0 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/RoleManager.java @@ -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 createRoleResult = roleRpc.createRole(RoleConvert.INSTANCE.convert(createDTO)); + createRoleResult.checkError(); + return createRoleResult.getData(); + } + + /** + * 更新角色 + * + * @param updateDTO 更新角色 DTO + */ + public void updateRole(RoleUpdateDTO updateDTO) { + CommonResult updateRoleResult = roleRpc.updateRole(RoleConvert.INSTANCE.convert(updateDTO)); + updateRoleResult.checkError(); + } + + /** + * 删除角色 + * + * @param roleId 角色编号 + */ + public void deleteRole(Integer roleId) { + CommonResult deleteRoleResult = roleRpc.deleteRole(roleId); + deleteRoleResult.checkError(); + } + + /** + * 获得角色 + * + * @param roleId 角色编号 + * @return 角色 + */ + public RoleVO getRole(Integer roleId) { + CommonResult getRoleResult = roleRpc.getRole(roleId); + getRoleResult.checkError(); + return RoleConvert.INSTANCE.convert(getRoleResult.getData()); + } + + /** + * 获得角色列表 + * + * @param roleIds 角色编号列表 + * @return 角色列表 + */ + public List listRole(List roleIds) { + CommonResult> listRoleResult = roleRpc.listRole(roleIds); + listRoleResult.checkError(); + return RoleConvert.INSTANCE.convertList(listRoleResult.getData()); + } + + /** + * 获得角色分页 + * + * @param pageDTO 角色编号列表 + * @return 角色列表 + */ + public PageResult pageRole(RolePageDTO pageDTO) { + CommonResult> pageRoleResult = + roleRpc.pageRole(RoleConvert.INSTANCE.convert(pageDTO)); + pageRoleResult.checkError(); + return RoleConvert.INSTANCE.convertPage(pageRoleResult.getData()); + } + +} diff --git a/management-web-app/src/main/resources/application.yml b/management-web-app/src/main/resources/application.yml index 9e3a90242..5ae6743d5 100644 --- a/management-web-app/src/main/resources/application.yml +++ b/management-web-app/src/main/resources/application.yml @@ -32,6 +32,8 @@ dubbo: version: 1.0.0 ResourceRpc: version: 1.0.0 + RoleRpc: + version: 1.0.0 # Swagger 配置项 swagger: diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpc.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpc.java new file mode 100644 index 000000000..db23b759a --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpc.java @@ -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 createRole(RoleCreateDTO createDTO); + + /** + * 更新角色 + * + * @param updateDTO 更新角色 DTO + */ + CommonResult updateRole(RoleUpdateDTO updateDTO); + + /** + * 删除角色 + * + * @param roleId 角色编号 + */ + CommonResult deleteRole(Integer roleId); + + /** + * 获得角色 + * + * @param roleId 角色编号 + * @return 角色 + */ + CommonResult getRole(Integer roleId); + + /** + * 获得角色列表 + * + * @param roleIds 角色编号列表 + * @return 角色列表 + */ + CommonResult> listRole(List roleIds); + + + /** + * 获得角色分页 + * + * @param pageDTO 角色分页查询 + * @return 角色分页结果 + */ + CommonResult> pageRole(RolePageDTO pageDTO); +} diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/RolePageDTO.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/RolePageDTO.java new file mode 100644 index 000000000..a151d2e9f --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/RolePageDTO.java @@ -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; + +} diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/RoleUpdateDTO.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/RoleUpdateDTO.java new file mode 100644 index 000000000..0c3568713 --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/RoleUpdateDTO.java @@ -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; + +} diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/vo/RoleCreateDTO.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/vo/RoleCreateDTO.java new file mode 100644 index 000000000..602478924 --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/vo/RoleCreateDTO.java @@ -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; + +} diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/vo/RoleVO.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/vo/RoleVO.java new file mode 100644 index 000000000..3c7d73983 --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/vo/RoleVO.java @@ -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; + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/convert/permission/RoleConvert.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/convert/permission/RoleConvert.java index 2a90f0237..df47bd7bd 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/convert/permission/RoleConvert.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/convert/permission/RoleConvert.java @@ -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 convertList(List list); + List convertList02(List list); + PageResult convertPage(IPage page); + PageResult convertPage(PageResult page); + } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/RoleManager.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/RoleManager.java new file mode 100644 index 000000000..b176fa4aa --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/RoleManager.java @@ -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 listRole(List roleIds) { + List roleBOs = roleService.listRole(roleIds); + return RoleConvert.INSTANCE.convertList02(roleBOs); + } + + /** + * 获得角色分页 + * + * @param pageDTO 角色分页查询 + * @return 角色分页结果 + */ + public PageResult pageRole(RolePageDTO pageDTO) { + PageResult pageResultBO = roleService.pageRole(RoleConvert.INSTANCE.convert(pageDTO)); + return RoleConvert.INSTANCE.convertPage(pageResultBO); + } + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpcImpl.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpcImpl.java new file mode 100644 index 000000000..032023ed2 --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpcImpl.java @@ -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 createRole(RoleCreateDTO createDTO) { + return success(roleManager.createRole(createDTO)); + } + + @Override + public CommonResult updateRole(RoleUpdateDTO updateDTO) { + roleManager.updateRole(updateDTO); + return success(true); + } + + @Override + public CommonResult deleteRole(Integer roleId) { + roleManager.deleteRole(roleId); + return success(true); + } + + @Override + public CommonResult getRole(Integer roleId) { + return success(roleManager.getRole(roleId)); + } + + @Override + public CommonResult> listRole(List roleIds) { + return success(roleManager.listRole(roleIds)); + } + + @Override + public CommonResult> pageRole(RolePageDTO pageDTO) { + return success(roleManager.pageRole(pageDTO)); + } + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/RoleService.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/RoleService.java index b1e5f489f..34d69e438 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/RoleService.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/RoleService.java @@ -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); diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/authorization/RoleConvert.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/authorization/RoleConvert.java deleted file mode 100644 index 960bceec8..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/authorization/RoleConvert.java +++ /dev/null @@ -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 convertList(List beans); - - @Mapping(source = "records", target = "list") - PageResult convertPage(IPage page); - - RoleDO convert(RoleAddDTO bean); - - RoleDO convert(RoleUpdateDTO bean); - -}