diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.http b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.http new file mode 100644 index 000000000..182c6f260 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.http @@ -0,0 +1,33 @@ +### /resource/create 成功 +POST {{baseUrl}}/resource/create +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{accessToken}} + +name=测试菜单&permission=resource:add&type=1&sort=1&pid=0&route=/resource/list&icon=test + +### /admin/update 成功 +POST {{baseUrl}}/resource/update +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{accessToken}} + +id=61&name=测试菜单2&permission=resource:add&type=1&sort=1&pid=0&route=/resource/list&icon=test + +### /resource/delete 成功 +POST {{baseUrl}}/resource/delete +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{accessToken}} + +resourceId=61 + +### /resource/get 成功 +GET {{baseUrl}}/resource/get?resourceId=61 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{accessToken}} + +### /resource/list 成功 +GET {{baseUrl}}/resource/list?resourceIds=61,63 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{accessToken}} + +### + diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.java new file mode 100644 index 000000000..ba6bf2fca --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.java @@ -0,0 +1,67 @@ +package cn.iocoder.mall.managementweb.controller.permission; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceCreateDTO; +import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceUpdateDTO; +import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceVO; +import cn.iocoder.mall.managementweb.manager.permission.ResourceManager; +import cn.iocoder.mall.security.admin.core.context.AdminSecurityContextHolder; +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("/resource") +@Api(tags = "资源") +@Validated +public class ResourceController { + + @Autowired + private ResourceManager resourceManager; + + @PostMapping("/create") + @ApiOperation("创建资源") + public CommonResult createResource(@Valid ResourceCreateDTO createDTO) { + return success(resourceManager.createResource(createDTO, AdminSecurityContextHolder.getAdminId())); + } + + @PostMapping("/update") + @ApiOperation("更新资源") + public CommonResult updateResource(@Valid ResourceUpdateDTO updateDTO) { + resourceManager.updateResource(updateDTO); + return success(true); + } + + @PostMapping("/delete") + @ApiOperation("删除资源") + @ApiImplicitParam(name = "resourceId", value = "资源编号", required = true) + public CommonResult deleteResource(@RequestParam("resourceId") Integer resourceId) { + resourceManager.deleteResource(resourceId); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得资源") + public CommonResult getResource(@RequestParam("resourceId") Integer resourceId) { + return success(resourceManager.getResource(resourceId)); + } + + @GetMapping("/list") + @ApiOperation("获得资源列表") + @ApiImplicitParam(name = "resourceId", value = "资源编号列表", required = true) + public CommonResult> getResources(@RequestParam("resourceIds") List resourceIds) { + return success(resourceManager.listResource(resourceIds)); + } + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/ResourceCreateDTO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/ResourceCreateDTO.java new file mode 100644 index 000000000..4bf6175ae --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/ResourceCreateDTO.java @@ -0,0 +1,36 @@ +package cn.iocoder.mall.managementweb.controller.permission.dto; + +import cn.iocoder.common.framework.validator.InEnum; +import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum; +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 ResourceCreateDTO { + + @ApiModelProperty(value = "菜单名", required = true, example = "商品管理") + @NotEmpty(message = "菜单名不能为空") + private String name; + @ApiModelProperty(value = "权限标识", example = "resource:add") + private String permission; + @ApiModelProperty(value = "资源类型", required = true, example = "1") + @NotNull(message = "资源类型不能为空") + @InEnum(value = ResourceTypeEnum.class, message = "资源类型必须是 {value}") + private Integer type; + @ApiModelProperty(value = "排序", required = true, example = "1") + @NotNull(message = "排序不能为空") + private Integer sort; + @ApiModelProperty(value = "父级资源编号", required = true, example = "1", notes = "如果无父资源,则值为 0") + @NotNull(message = "父级资源编号不能为空") + private Integer pid; + @ApiModelProperty(value = "前端路由", example = "/resource/list") + private String route; + @ApiModelProperty(value = "菜单图标", example = "add") + private String icon; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/ResourceUpdateDTO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/ResourceUpdateDTO.java new file mode 100644 index 000000000..fce22ec82 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/dto/ResourceUpdateDTO.java @@ -0,0 +1,39 @@ +package cn.iocoder.mall.managementweb.controller.permission.dto; + +import cn.iocoder.common.framework.validator.InEnum; +import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum; +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 ResourceUpdateDTO { + + @ApiModelProperty(value = "资源编号", required = true, example = "1") + @NotNull(message = "资源编号不能为空") + private Integer id; + @ApiModelProperty(value = "菜单名", required = true, example = "商品管理") + @NotEmpty(message = "菜单名不能为空") + private String name; + @ApiModelProperty(value = "权限标识", example = "resource:add") + private String permission; + @ApiModelProperty(value = "资源类型", required = true, example = "1") + @NotNull(message = "资源类型不能为空") + @InEnum(value = ResourceTypeEnum.class, message = "资源类型必须是 {value}") + private Integer type; + @ApiModelProperty(value = "排序", required = true, example = "1") + @NotNull(message = "排序不能为空") + private Integer sort; + @ApiModelProperty(value = "父级资源编号", required = true, example = "1", notes = "如果无父资源,则值为 0") + @NotNull(message = "父级资源编号不能为空") + private Integer pid; + @ApiModelProperty(value = "前端路由", example = "/resource/list") + private String route; + @ApiModelProperty(value = "菜单图标", example = "add") + private String icon; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/vo/ResourceVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/vo/ResourceVO.java new file mode 100644 index 000000000..f2f133dcc --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/vo/ResourceVO.java @@ -0,0 +1,41 @@ +package cn.iocoder.mall.managementweb.controller.permission.vo; + +import cn.iocoder.common.framework.validator.InEnum; +import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum; +import lombok.*; +import io.swagger.annotations.*; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.*; + +@ApiModel("资源 VO") +@Data +public class ResourceVO { + + @ApiModelProperty(value = "资源编号", required = true, example = "1") + @NotNull(message = "资源编号不能为空") + private Integer id; + @ApiModelProperty(value = "菜单名", required = true, example = "商品管理") + @NotEmpty(message = "菜单名不能为空") + private String name; + @ApiModelProperty(value = "权限标识", example = "resource:add") + private String permission; + @ApiModelProperty(value = "资源类型", required = true, example = "1") + @NotNull(message = "资源类型不能为空") + @InEnum(value = ResourceTypeEnum.class, message = "资源类型必须是 {value}") + private Integer type; + @ApiModelProperty(value = "排序", required = true, example = "1") + @NotNull(message = "排序不能为空") + private Integer sort; + @ApiModelProperty(value = "父级资源编号", required = true, example = "1", notes = "如果无父资源,则值为 0") + @NotNull(message = "父级资源编号不能为空") + private Integer pid; + @ApiModelProperty(value = "前端路由", example = "/resource/list") + private String route; + @ApiModelProperty(value = "菜单图标", example = "add") + private String icon; + @ApiModelProperty(value = "添加时间", required = true) + private Date createTime; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/ResourceConvert.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/ResourceConvert.java new file mode 100644 index 000000000..50150cc49 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/ResourceConvert.java @@ -0,0 +1,24 @@ +package cn.iocoder.mall.managementweb.convert.permission; + +import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceVO; +import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceCreateDTO; +import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceUpdateDTO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface ResourceConvert { + + ResourceConvert INSTANCE = Mappers.getMapper(ResourceConvert.class); + + ResourceCreateDTO convert(cn.iocoder.mall.managementweb.controller.permission.dto.ResourceCreateDTO bean); + + ResourceUpdateDTO convert(cn.iocoder.mall.managementweb.controller.permission.dto.ResourceUpdateDTO bean); + + ResourceVO convert(cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO bean); + + List convertList(List list); + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/ResourceManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/ResourceManager.java new file mode 100644 index 000000000..e6cca6252 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/ResourceManager.java @@ -0,0 +1,79 @@ +package cn.iocoder.mall.managementweb.manager.permission; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceCreateDTO; +import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceUpdateDTO; +import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceVO; +import cn.iocoder.mall.managementweb.convert.permission.ResourceConvert; +import cn.iocoder.mall.systemservice.rpc.permission.ResourceRpc; +import org.apache.dubbo.config.annotation.Reference; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** +* 资源 Manager +*/ +@Service +public class ResourceManager { + + @Reference(version = "${dubbo.consumer.ResourceRpc.version}", validation = "false") + private ResourceRpc resourceRpc; + + /** + * 创建资源 + * + * @param createDTO 创建资源 DTO + * @return 资源 + */ + public Integer createResource(ResourceCreateDTO createDTO, Integer createAdminId) { + CommonResult createResourceResult = resourceRpc.createResource(ResourceConvert.INSTANCE.convert(createDTO) + .setCreateAdminId(createAdminId)); + createResourceResult.checkError(); + return createResourceResult.getData(); + } + + /** + * 更新资源 + * + * @param updateDTO 更新资源 DTO + */ + public void updateResource(ResourceUpdateDTO updateDTO) { + CommonResult updateResourceResult = resourceRpc.updateResource(ResourceConvert.INSTANCE.convert(updateDTO)); + updateResourceResult.checkError(); + } + + /** + * 删除资源 + * + * @param resourceId 资源编号 + */ + public void deleteResource(Integer resourceId) { + CommonResult deleteResourceResult = resourceRpc.deleteResource(resourceId); + deleteResourceResult.checkError(); + } + + /** + * 获得资源 + * + * @param resourceId 资源编号 + * @return 资源 + */ + public ResourceVO getResource(Integer resourceId) { + CommonResult getResourceResult = resourceRpc.getResource(resourceId); + getResourceResult.checkError(); + return ResourceConvert.INSTANCE.convert(getResourceResult.getData()); + } + + /** + * 获得资源列表 + * + * @param resourceIds 资源编号列表 + * @return 资源列表 + */ + public List listResource(List resourceIds) { + CommonResult> listResourceResult = resourceRpc.listResource(resourceIds); + return ResourceConvert.INSTANCE.convertList(listResourceResult.getData()); + } + +} diff --git a/management-web-app/src/main/resources/application.yml b/management-web-app/src/main/resources/application.yml index 73fba9f2c..9e3a90242 100644 --- a/management-web-app/src/main/resources/application.yml +++ b/management-web-app/src/main/resources/application.yml @@ -30,6 +30,8 @@ dubbo: version: 1.0.0 SystemLogRPC: version: 1.0.0 + ResourceRpc: + version: 1.0.0 # Swagger 配置项 swagger: diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpc.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpc.java new file mode 100644 index 000000000..2739ea5a5 --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpc.java @@ -0,0 +1,53 @@ +package cn.iocoder.mall.systemservice.rpc.permission; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceCreateDTO; +import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceUpdateDTO; +import cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO; + +import java.util.List; + +/** +* 资源 Rpc 接口 +*/ +public interface ResourceRpc { + + /** + * 创建资源 + * + * @param createDTO 创建资源 DTO + * @return 资源 + */ + CommonResult createResource(ResourceCreateDTO createDTO); + + /** + * 更新资源 + * + * @param updateDTO 更新资源 DTO + */ + CommonResult updateResource(ResourceUpdateDTO updateDTO); + + /** + * 删除资源 + * + * @param resourceId 资源编号 + */ + CommonResult deleteResource(Integer resourceId); + + /** + * 获得资源 + * + * @param resourceId 资源编号 + * @return 资源 + */ + CommonResult getResource(Integer resourceId); + + /** + * 获得资源列表 + * + * @param resourceIds 资源编号列表 + * @return 资源列表 + */ + CommonResult> listResource(List resourceIds); + +} diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/ResourceCreateDTO.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/ResourceCreateDTO.java new file mode 100644 index 000000000..3d1903b3d --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/ResourceCreateDTO.java @@ -0,0 +1,59 @@ +package cn.iocoder.mall.systemservice.rpc.permission.dto; + +import cn.iocoder.common.framework.validator.InEnum; +import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum; +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 ResourceCreateDTO implements Serializable { + + /** + * 菜单名 + */ + @NotEmpty(message = "菜单名不能为空") + private String name; + /** + * 权限标识 + */ + private String permission; + /** + * 资源类型 + */ + @NotNull(message = "资源类型不能为空") + @InEnum(value = ResourceTypeEnum.class, message = "资源类型必须是 {value}") + private Integer type; + /** + * 排序 + */ + @NotNull(message = "排序不能为空") + private Integer sort; + /** + * 父级资源编号 + */ + @NotNull(message = "父级资源编号不能为空") + private Integer pid; + /** + * 前端路由 + */ + private String route; + /** + * 菜单图标 + */ + private String icon; + + /** + * 创建管理员编号 + */ + @NotNull(message = "创建管理员编号不能为空") + private Integer createAdminId; + +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceUpdateDTO.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/ResourceUpdateDTO.java similarity index 56% rename from system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceUpdateDTO.java rename to system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/ResourceUpdateDTO.java index 5980799d4..e7f4e0918 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceUpdateDTO.java +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/dto/ResourceUpdateDTO.java @@ -1,50 +1,58 @@ -package cn.iocoder.mall.system.biz.dto.authorization; +package cn.iocoder.mall.systemservice.rpc.permission.dto; import cn.iocoder.common.framework.validator.InEnum; -import cn.iocoder.mall.system.biz.enums.authorization.ResourceTypeEnum; +import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum; import lombok.Data; import lombok.experimental.Accessors; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import java.io.Serializable; /** - * 资源模块 - 更新资源 DTO - */ +* 资源更新 DTO +*/ @Data @Accessors(chain = true) -public class ResourceUpdateDTO { - - @NotNull(message = "管理员编号不能为空") - private Integer adminId; +public class ResourceUpdateDTO implements Serializable { + /** + * 资源编号 + */ @NotNull(message = "资源编号不能为空") private Integer id; - - @NotNull(message = "类型不能为空") + /** + * 菜单名 + */ + @NotEmpty(message = "菜单名不能为空") + private String name; + /** + * 权限标识 + */ + private String permission; + /** + * 资源类型 + */ + @NotNull(message = "资源类型不能为空") @InEnum(value = ResourceTypeEnum.class, message = "资源类型必须是 {value}") private Integer type; - - @NotNull(message = "类型不能为空") + /** + * 排序 + */ + @NotNull(message = "排序不能为空") private Integer sort; - - @NotEmpty(message = "资源名字不能为空") - private String name; - + /** + * 父级资源编号 + */ @NotNull(message = "父级资源编号不能为空") private Integer pid; - /** * 前端路由 */ private String route; /** - * 图标 + * 菜单图标 */ private String icon; - /** - * 权限标识 - */ - private String permission; } diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/vo/ResourceVO.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/vo/ResourceVO.java new file mode 100644 index 000000000..31e8db829 --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/vo/ResourceVO.java @@ -0,0 +1,53 @@ +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 ResourceVO implements Serializable { + + /** + * 资源编号 + */ + private Integer id; + /** + * 菜单名 + */ + private String name; + /** + * 权限标识 + */ + private String permission; + /** + * 资源类型 + */ + private Integer type; + /** + * 排序 + */ + private Integer sort; + /** + * 父级资源编号 + */ + private Integer pid; + /** + * 前端路由 + */ + private String route; + /** + * 菜单图标 + */ + private String icon; + /** + * 添加时间 + */ + private Date createTime; + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/convert/permission/ResourceConvert.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/convert/permission/ResourceConvert.java new file mode 100644 index 000000000..4b743419b --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/convert/permission/ResourceConvert.java @@ -0,0 +1,35 @@ +package cn.iocoder.mall.systemservice.convert.permission; + +import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.ResourceDO; +import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceCreateDTO; +import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceUpdateDTO; +import cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO; +import cn.iocoder.mall.systemservice.service.permission.bo.ResourceBO; +import cn.iocoder.mall.systemservice.service.permission.bo.ResourceCreateBO; +import cn.iocoder.mall.systemservice.service.permission.bo.ResourceUpdateBO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface ResourceConvert { + + ResourceConvert INSTANCE = Mappers.getMapper(ResourceConvert.class); + + ResourceDO convert(ResourceCreateBO bean); + + ResourceBO convert(ResourceDO bean); + + ResourceDO convert(ResourceUpdateBO bean); + + ResourceCreateBO convert(ResourceCreateDTO bean); + + ResourceVO convert(ResourceBO bean); + + ResourceUpdateBO convert(ResourceUpdateDTO bean); + + List convertList(List list); + List convertList02(List list); + +} 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 new file mode 100644 index 000000000..2a90f0237 --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/convert/permission/RoleConvert.java @@ -0,0 +1,29 @@ +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.service.permission.bo.RoleBO; +import cn.iocoder.mall.systemservice.service.permission.bo.RoleCreateBO; +import cn.iocoder.mall.systemservice.service.permission.bo.RoleUpdateBO; +import com.baomidou.mybatisplus.core.metadata.IPage; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface RoleConvert { + + RoleConvert INSTANCE = Mappers.getMapper(RoleConvert.class); + + RoleDO convert(RoleCreateBO bean); + + RoleBO convert(RoleDO bean); + + RoleDO convert(RoleUpdateBO bean); + + List convertList(List list); + + PageResult convertPage(IPage page); + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/dataobject/permission/ResourceDO.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/dataobject/permission/ResourceDO.java index 1edb89189..2999c4a3e 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/dataobject/permission/ResourceDO.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/dataobject/permission/ResourceDO.java @@ -1,6 +1,7 @@ package cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission; import cn.iocoder.mall.mybatis.dataobject.DeletableDO; +import cn.iocoder.mall.systemservice.dal.mysql.dataobject.admin.AdminDO; import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @@ -64,4 +65,11 @@ public class ResourceDO extends DeletableDO { */ private String icon; + /** + * 创建管理员编号 + * + * 外键 {@link AdminDO#getId()} + */ + private Integer createAdminId; + } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/admin/AdminMapper.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/admin/AdminMapper.java index a7337e955..8768a6195 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/admin/AdminMapper.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/admin/AdminMapper.java @@ -18,10 +18,10 @@ public interface AdminMapper extends BaseMapper { ); } - default IPage selectPage(AdminPageBO adminPageBO) { - return selectPage(new Page<>(adminPageBO.getPageNo(), adminPageBO.getPageSize()), - new QueryWrapperX().likeIfPresent("name", adminPageBO.getName()) - .eqIfPresent("department_id", adminPageBO.getDepartmentId())); + default IPage selectPage(AdminPageBO pageBO) { + return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()), + new QueryWrapperX().likeIfPresent("name", pageBO.getName()) + .eqIfPresent("department_id", pageBO.getDepartmentId())); } } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/RoleMapper.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/RoleMapper.java index efbaf5e96..1c994276e 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/RoleMapper.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/RoleMapper.java @@ -2,24 +2,24 @@ package cn.iocoder.mall.systemservice.dal.mysql.mapper.permission; import cn.iocoder.mall.mybatis.query.QueryWrapperX; import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.RoleDO; +import cn.iocoder.mall.systemservice.service.permission.bo.RolePageBO; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springframework.stereotype.Repository; -import java.util.Collection; -import java.util.List; - @Repository public interface RoleMapper extends BaseMapper { -// default IPage selectPage(RolePageDTO rolePageDTO) { -// return selectPage(new Page<>(rolePageDTO.getPageNo(), rolePageDTO.getPageSize()), -// new QueryWrapperX().likeIfPresent("name", rolePageDTO.getName())); -// } - - default List selectListByIds(Collection ids) { - return selectList(new QueryWrapperX().inIfPresent("id", ids)); + default IPage selectPage(RolePageBO pageBO) { + return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()), + new QueryWrapperX().likeIfPresent("name", pageBO.getName())); } +// default List selectListByIds(Collection ids) { +// return selectList(new QueryWrapperX().inIfPresent("id", ids)); +// } + default RoleDO selectByName(String name) { return selectOne(new QueryWrapperX().eqIfPresent("name", name)); } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/ResourceManager.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/ResourceManager.java new file mode 100644 index 000000000..3a387bd11 --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/ResourceManager.java @@ -0,0 +1,74 @@ +package cn.iocoder.mall.systemservice.manager.permission; + +import cn.iocoder.mall.systemservice.convert.permission.ResourceConvert; +import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceCreateDTO; +import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceUpdateDTO; +import cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO; +import cn.iocoder.mall.systemservice.service.permission.ResourceService; +import cn.iocoder.mall.systemservice.service.permission.bo.ResourceBO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** +* 资源 Manager +*/ +@Service +public class ResourceManager { + + @Autowired + private ResourceService resourceService; + + /** + * 创建资源 + * + * @param createDTO 创建资源 DTO + * @return 资源 + */ + public Integer createResource(ResourceCreateDTO createDTO) { + ResourceBO resourceBO = resourceService.createResource(ResourceConvert.INSTANCE.convert(createDTO)); + return resourceBO.getId(); + } + + /** + * 更新资源 + * + * @param updateDTO 更新资源 DTO + */ + public void updateResource(ResourceUpdateDTO updateDTO) { + resourceService.updateResource(ResourceConvert.INSTANCE.convert(updateDTO)); + } + + /** + * 删除资源 + * + * @param resourceId 资源编号 + */ + public void deleteResource(Integer resourceId) { + resourceService.deleteResource(resourceId); + } + + /** + * 获得资源 + * + * @param resourceId 资源编号 + * @return 资源 + */ + public ResourceVO getResource(Integer resourceId) { + ResourceBO resourceBO = resourceService.getResource(resourceId); + return ResourceConvert.INSTANCE.convert(resourceBO); + } + + /** + * 获得资源列表 + * + * @param resourceIds 资源编号列表 + * @return 资源列表 + */ + public List listResource(List resourceIds) { + List resourceBOs = resourceService.listResource(resourceIds); + return ResourceConvert.INSTANCE.convertList02(resourceBOs); + } + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpcImpl.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpcImpl.java new file mode 100644 index 000000000..6ad6b340e --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpcImpl.java @@ -0,0 +1,51 @@ +package cn.iocoder.mall.systemservice.rpc.permission; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.systemservice.manager.permission.ResourceManager; +import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceCreateDTO; +import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceUpdateDTO; +import cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO; +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.ResourceRpc.version}", validation = "false") +public class ResourceRpcImpl implements ResourceRpc { + + @Autowired + private ResourceManager resourceManager; + + @Override + public CommonResult createResource(ResourceCreateDTO createDTO) { + return success(resourceManager.createResource(createDTO)); + } + + @Override + public CommonResult updateResource(ResourceUpdateDTO updateDTO) { + resourceManager.updateResource(updateDTO); + return success(true); + } + + @Override + public CommonResult deleteResource(Integer resourceId) { + resourceManager.deleteResource(resourceId); + return success(true); + } + + @Override + public CommonResult getResource(Integer resourceId) { + return success(resourceManager.getResource(resourceId)); + } + + @Override + public CommonResult> listResource(List resourceIds) { + return success(resourceManager.listResource(resourceIds)); + } + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/admin/AdminService.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/admin/AdminService.java index 151e09e2d..26529b8d1 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/admin/AdminService.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/admin/AdminService.java @@ -25,6 +25,14 @@ public class AdminService { @Autowired private AdminMapper adminMapper; + /** + * 校验登陆的账号密码是否正确 + * + * @param username 账号 + * @param password 密码 + * @param ip 登陆 IP + * @return 管理员信息 + */ public AdminBO verifyPassword(String username, String password, String ip) { AdminDO adminDO = adminMapper.selectByUsername(username); if (adminDO == null) { diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/ResourceService.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/ResourceService.java new file mode 100644 index 000000000..17fe4d1ec --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/ResourceService.java @@ -0,0 +1,182 @@ +package cn.iocoder.mall.systemservice.service.permission; + +import cn.iocoder.common.framework.util.ServiceExceptionUtil; +import cn.iocoder.mall.systemservice.convert.permission.ResourceConvert; +import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.ResourceDO; +import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.ResourceMapper; +import cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum; +import cn.iocoder.mall.systemservice.enums.permission.ResourceIdEnum; +import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum; +import cn.iocoder.mall.systemservice.service.permission.bo.ResourceBO; +import cn.iocoder.mall.systemservice.service.permission.bo.ResourceCreateBO; +import cn.iocoder.mall.systemservice.service.permission.bo.ResourceUpdateBO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import java.util.List; + +import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.*; + +/** +* 资源 Service +*/ +@Service +@Validated +public class ResourceService { + + @Autowired + private ResourceMapper resourceMapper; + + /** + * 创建资源 + * + * @param createBO 创建资源 BO + * @return 资源 + */ + public ResourceBO createResource(@Valid ResourceCreateBO createBO) { + // 校验父资源存在 + checkParentResource(createBO.getPid(), null); + // 校验资源(自己) + checkResource(createBO.getPid(), createBO.getName(), null); + // 插入数据库 + ResourceDO resourceDO = ResourceConvert.INSTANCE.convert(createBO); + initResourceProperty(resourceDO); + resourceMapper.insert(resourceDO); + // 返回 + return ResourceConvert.INSTANCE.convert(resourceDO); + } + + /** + * 更新资源 + * + * @param updateBO 更新资源 BO + */ + public void updateResource(@Valid ResourceUpdateBO updateBO) { + // 校验更新的资源是否存在 + if (resourceMapper.selectById(updateBO.getId()) == null) { + throw ServiceExceptionUtil.exception(RESOURCE_NOT_EXISTS); + } + // 校验父资源存在 + checkParentResource(updateBO.getPid(), updateBO.getId()); + // 校验资源(自己) + checkResource(updateBO.getPid(), updateBO.getName(), updateBO.getId()); + // 更新到数据库 + ResourceDO updateObject = ResourceConvert.INSTANCE.convert(updateBO); + initResourceProperty(updateObject); + resourceMapper.updateById(updateObject); + } + + /** + * 删除资源 + * + * @param resourceId 资源编号 + */ + public void deleteResource(Integer resourceId) { + // 校验更新的资源是否存在 + if (resourceMapper.selectById(resourceId) == null) { + throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.RESOURCE_NOT_EXISTS); + } + // 校验是否还有子资源 + if (resourceMapper.selectCountByPid(resourceId) > 0) { + throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.RESOURCE_EXISTS_CHILDREN); + } + // 校验删除的资源是否存在 + if (resourceMapper.selectById(resourceId) == null) { + throw ServiceExceptionUtil.exception(RESOURCE_NOT_EXISTS); + } + // 标记删除 + resourceMapper.deleteById(resourceId); + } + + /** + * 获得资源 + * + * @param resourceId 资源编号 + * @return 资源 + */ + public ResourceBO getResource(Integer resourceId) { + ResourceDO resourceDO = resourceMapper.selectById(resourceId); + return ResourceConvert.INSTANCE.convert(resourceDO); + } + + /** + * 获得资源列表 + * + * @param resourceIds 资源编号列表 + * @return 资源列表 + */ + public List listResource(List resourceIds) { + List resourceDOs = resourceMapper.selectBatchIds(resourceIds); + return ResourceConvert.INSTANCE.convertList(resourceDOs); + } + + /** + * 校验父资源是否合法 + * + * 1. 不能舌质红自己为父资源 + * 2. 父资源不存在 + * 3. 父资源必须是 {@link ResourceTypeEnum#MENU} 菜单类型 + * + * @param pid 父资源编号 + * @param childId 当前资源编号 + */ + private void checkParentResource(Integer pid, Integer childId) { + if (pid == null || ResourceIdEnum.ROOT.getId().equals(pid)) { + return; + } + // 不能设置自己为父资源 + if (pid.equals(childId)) { + throw ServiceExceptionUtil.exception(RESOURCE_PARENT_ERROR); + } + ResourceDO resource = resourceMapper.selectById(pid); + // 父资源不存在 + if (resource == null) { + throw ServiceExceptionUtil.exception(RESOURCE_PARENT_NOT_EXISTS); + } + // 父资源必须是菜单类型 + if (!ResourceTypeEnum.MENU.getType().equals(resource.getType())) { + throw ServiceExceptionUtil.exception(RESOURCE_PARENT_NOT_MENU); + } + } + + /** + * 校验资源是否合法 + * + * 1. 校验相同父资源编号下,是否存在相同的资源名 + * + * @param name 资源名字 + * @param pid 父资源编号 + * @param id 资源编号 + */ + private void checkResource(Integer pid, String name, Integer id) { + ResourceDO resource = resourceMapper.selectByPidAndName(pid, name); + if (resource == null) { + return; + } + // 如果 id 为空,说明不用比较是否为相同 id 的资源 + if (id == null) { + throw ServiceExceptionUtil.exception(RESOURCE_NAME_DUPLICATE); + } + if (!resource.getId().equals(id)) { + throw ServiceExceptionUtil.exception(RESOURCE_NAME_DUPLICATE); + } + } + + /** + * 初始化资源的通用属性。 + * + * 例如说,只有菜单类型的资源,才设置 icon + * + * @param resource 资源 + */ + private void initResourceProperty(ResourceDO resource) { + // 初始化资源为按钮类型时,无需 route 和 icon 属性 + if (ResourceTypeEnum.BUTTON.getType().equals(resource.getType())) { + resource.setRoute(null); + resource.setIcon(null); + } + } + +} 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 new file mode 100644 index 000000000..b1e5f489f --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/RoleService.java @@ -0,0 +1,153 @@ +package cn.iocoder.mall.systemservice.service.permission; + +import cn.iocoder.common.framework.util.ServiceExceptionUtil; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.systemservice.convert.permission.RoleConvert; +import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.RoleDO; +import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.RoleMapper; +import cn.iocoder.mall.systemservice.enums.permission.RoleTypeEnum; +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.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import java.util.List; + +import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.*; + +/** +* 角色 Service +*/ +@Service +@Validated +public class RoleService { + + @Autowired + private RoleMapper roleMapper; + + /** + * 创建角色 + * + * @param createBO 创建角色 BO + * @return 角色 + */ + public RoleBO createRole(@Valid RoleCreateBO createBO) { + // 校验角色 + checkDuplicateRole(createBO.getName(), createBO.getCode(), null); + // 插入到数据库 + RoleDO roleDO = RoleConvert.INSTANCE.convert(createBO); + roleMapper.insert(roleDO); + // 返回 + return RoleConvert.INSTANCE.convert(roleDO); + } + + /** + * 更新角色 + * + * @param updateBO 更新角色 BO + */ + public void updateRole(@Valid RoleUpdateBO updateBO) { + // 校验更新的角色是否存在 + RoleDO roleDO = roleMapper.selectById(updateBO.getId()); + if (roleMapper.selectById(updateBO.getId()) == null) { + throw ServiceExceptionUtil.exception(ROLE_NOT_EXISTS); + } + // 内置角色,不允许修改 + if (RoleTypeEnum.SYSTEM.getType().equals(roleDO.getType())) { + throw ServiceExceptionUtil.exception(ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE); + } + // 校验角色的唯一字段是否重复 + checkDuplicateRole(updateBO.getName(), updateBO.getCode(), updateBO.getId()); + // 更新到数据库 + RoleDO updateObject = RoleConvert.INSTANCE.convert(updateBO); + roleMapper.updateById(updateObject); + } + + /** + * 删除角色 + * + * @param roleId 角色编号 + */ + public void deleteRole(Integer roleId) { + // 校验删除的角色是否存在 + RoleDO roleDO = roleMapper.selectById(roleId); + if (roleMapper.selectById(roleId) == null) { + throw ServiceExceptionUtil.exception(ROLE_NOT_EXISTS); + } + // 内置角色,不允许删除 + if (RoleTypeEnum.SYSTEM.getType().equals(roleDO.getType())) { + throw ServiceExceptionUtil.exception(ROLE_CAN_NOT_DELETE_SYSTEM_TYPE_ROLE); + } + // 标记删除 + roleMapper.deleteById(roleId); +// // 发布角色删除事件,方便清理关联表 TODO 芋艿,需要实现 +// eventPublisher.publishEvent(new ResourceDeleteEvent(this, roleDeleteDTO.getId())); + } + + /** + * 获得角色 + * + * @param roleId 角色编号 + * @return 角色 + */ + public RoleBO getRole(Integer roleId) { + RoleDO roleDO = roleMapper.selectById(roleId); + return RoleConvert.INSTANCE.convert(roleDO); + } + + /** + * 获得角色列表 + * + * @param roleIds 角色编号列表 + * @return 角色列表 + */ + public List listRole(List roleIds) { + List roleDOs = roleMapper.selectBatchIds(roleIds); + return RoleConvert.INSTANCE.convertList(roleDOs); + } + + /** + * 获得角色分页 + * + * @param pageBO 角色分页查询 + * @return 角色分页结果 + */ + public PageResult pageRole(RolePageBO pageBO) { + IPage roleDOPage = roleMapper.selectPage(pageBO); + return RoleConvert.INSTANCE.convertPage(roleDOPage); + } + + /** + * 校验角色的唯一字段是否重复 + * + * 1. 是否存在相同名字的角色 + * 2. 是否存在相同编码的角色 + * + * @param name 角色名字 + * @param code 角色额编码 + * @param id 角色编号 + */ + private void checkDuplicateRole(String name, String code, Integer id) { + // 1. 该 name 名字被其它角色所使用 + RoleDO role = roleMapper.selectByName(name); + if (role != null && !role.getId().equals(id)) { + throw ServiceExceptionUtil.exception(ROLE_NAME_DUPLICATE, name); + } + // 2. 是否存在相同编码的角色 + if (!StringUtils.hasText(code)) { + return; + } + // 该 code 编码被其它角色所使用 + role = roleMapper.selectByCode(code); + if (role != null && !role.getId().equals(id)) { + throw ServiceExceptionUtil.exception(ROLE_CODE_DUPLICATE, name); + } + } + +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/ResourceBO.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/ResourceBO.java similarity index 82% rename from system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/ResourceBO.java rename to system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/ResourceBO.java index 1031448ae..5e622b7bc 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/authorization/ResourceBO.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/ResourceBO.java @@ -1,13 +1,10 @@ -package cn.iocoder.mall.system.biz.bo.authorization; +package cn.iocoder.mall.systemservice.service.permission.bo; import lombok.Data; import lombok.experimental.Accessors; import java.util.Date; -/** - * 授权模块 - 资源信息 BO - */ @Data @Accessors(chain = true) public class ResourceBO { @@ -45,8 +42,12 @@ public class ResourceBO { */ private String icon; /** - * 创建时间 + * 添加时间 */ private Date createTime; + /** + * 更新时间 + */ + private Date updateTime; } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/ResourceCreateBO.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/ResourceCreateBO.java new file mode 100644 index 000000000..333882547 --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/ResourceCreateBO.java @@ -0,0 +1,59 @@ +package cn.iocoder.mall.systemservice.service.permission.bo; + +import cn.iocoder.common.framework.validator.InEnum; +import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** +* 资源创建 BO +*/ +@Data +@Accessors(chain = true) +public class ResourceCreateBO { + + /** + * 菜单名 + */ + @NotEmpty(message = "菜单名不能为空") + private String name; + /** + * 权限标识 + */ + private String permission; + /** + * 资源类型 + */ + @NotNull(message = "资源类型不能为空") + @InEnum(value = ResourceTypeEnum.class, message = "资源类型必须是 {value}") + private Integer type; + /** + * 排序 + */ + @NotNull(message = "排序不能为空") + private Integer sort; + /** + * 父级资源编号 + */ + @NotNull(message = "父级资源编号不能为空") + private Integer pid; + /** + * 前端路由 + */ + private String route; + /** + * 菜单图标 + */ + private String icon; + + /** + * 创建管理员编号 + */ + @NotNull(message = "创建管理员编号不能为空") + private Integer createAdminId; + + +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceAddDTO.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/ResourceUpdateBO.java similarity index 57% rename from system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceAddDTO.java rename to system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/ResourceUpdateBO.java index 86e27ecef..f0fe9d14b 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceAddDTO.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/ResourceUpdateBO.java @@ -1,47 +1,54 @@ -package cn.iocoder.mall.system.biz.dto.authorization; +package cn.iocoder.mall.systemservice.service.permission.bo; import cn.iocoder.common.framework.validator.InEnum; -import cn.iocoder.mall.system.biz.enums.authorization.ResourceTypeEnum; +import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum; import lombok.Data; import lombok.experimental.Accessors; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -/** - * 资源模块 - 添加资源 DTO - */ @Data @Accessors(chain = true) -public class ResourceAddDTO { - - @NotNull(message = "管理员编号不能为空") - private Integer adminId; - - @NotNull(message = "类型不能为空") - @InEnum(value = ResourceTypeEnum.class, message = "资源类型必须是 {value}") - private Integer type; - - @NotNull(message = "类型不能为空") - private Integer sort; +public class ResourceUpdateBO { + /** + * 菜单编号 + */ + @NotNull(message = "菜单编号不能为空") + private Integer id; + /** + * 菜单名 + */ @NotEmpty(message = "菜单名不能为空") private String name; - + /** + * 权限标识 + */ + private String permission; + /** + * 资源类型 + */ + @NotNull(message = "资源类型不能为空") + @InEnum(value = ResourceTypeEnum.class, message = "资源类型必须是 {value}") + private Integer type; + /** + * 排序 + */ + @NotNull(message = "排序不能为空") + private Integer sort; + /** + * 父级资源编号 + */ @NotNull(message = "父级资源编号不能为空") private Integer pid; - /** * 前端路由 */ private String route; /** - * 图标 + * 菜单图标 */ private String icon; - /** - * 权限标识 - */ - private String permission; } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/RoleBO.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/RoleBO.java new file mode 100644 index 000000000..4443a8c92 --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/RoleBO.java @@ -0,0 +1,40 @@ +package cn.iocoder.mall.systemservice.service.permission.bo; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.Date; + +/** +* 角色 BO +*/ +@Data +@Accessors(chain = true) +public class RoleBO { + + /** + * 角色编号 + */ + private Integer id; + /** + * 角色名 + */ + private String name; + /** + * 角色编码 + */ + private String code; + /** + * 角色类型 + */ + private Integer type; + /** + * 创建管理员编号 + */ + private Integer createAdminId; + /** + * 创建时间 + */ + private Date createTime; + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/RoleCreateBO.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/RoleCreateBO.java new file mode 100644 index 000000000..15feb1b1a --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/RoleCreateBO.java @@ -0,0 +1,31 @@ +package cn.iocoder.mall.systemservice.service.permission.bo; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** +* 角色创建 BO +*/ +@Data +@Accessors(chain = true) +public class RoleCreateBO { + + /** + * 角色名 + */ + @NotEmpty(message = "角色名不能为空") + private String name; + /** + * 角色编码 + */ + private String code; + /** + * 创建管理员编号 + */ + @NotNull(message = "创建管理员编号不能为空") + private Integer createAdminId; + +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RolePageDTO.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/RolePageBO.java similarity index 58% rename from system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RolePageDTO.java rename to system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/RolePageBO.java index 80605c0ca..fbae022bc 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RolePageDTO.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/RolePageBO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.system.biz.dto.authorization; +package cn.iocoder.mall.systemservice.service.permission.bo; import cn.iocoder.common.framework.vo.PageParam; import lombok.Data; @@ -6,16 +6,16 @@ import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; /** - * 角色模块 - 角色分页 DTO - */ +* 角色分页 BO +*/ @Data -@EqualsAndHashCode(callSuper = true) @Accessors(chain = true) -public class RolePageDTO extends PageParam { +@EqualsAndHashCode(callSuper = true) +public class RolePageBO extends PageParam { /** - * 角色名,模糊匹配 - */ + * 角色名,模糊匹配 + */ private String name; } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RoleUpdateDTO.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/RoleUpdateBO.java similarity index 58% rename from system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RoleUpdateDTO.java rename to system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/RoleUpdateBO.java index 1a2390c4f..d8fa4ef7b 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RoleUpdateDTO.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/bo/RoleUpdateBO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.system.biz.dto.authorization; +package cn.iocoder.mall.systemservice.service.permission.bo; import lombok.Data; import lombok.experimental.Accessors; @@ -7,21 +7,22 @@ import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; /** - * 角色模块 - 修改角色 DTO + * 角色更新 BO */ @Data @Accessors(chain = true) -public class RoleUpdateDTO { - - @NotNull(message = "管理员编号不能为空") - private Integer adminId; +public class RoleUpdateBO { + /** + * 角色编号 + */ @NotNull(message = "角色编号不能为空") private Integer id; - - @NotEmpty(message = "角色名字不能为空") + /** + * 角色名 + */ + @NotEmpty(message = "角色名不能为空") private String name; - /** * 角色编码 */ diff --git a/system-service-project/system-service-app/src/main/resources/application.yaml b/system-service-project/system-service-app/src/main/resources/application.yaml index 1052a4b18..42a6e2368 100644 --- a/system-service-project/system-service-app/src/main/resources/application.yaml +++ b/system-service-project/system-service-app/src/main/resources/application.yaml @@ -39,3 +39,5 @@ dubbo: version: 1.0.0 SystemLogRPC: version: 1.0.0 + ResourceRpc: + version: 1.0.0 diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/authorization/ResourceConvert.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/authorization/ResourceConvert.java index 33bb60a1e..06f879908 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/authorization/ResourceConvert.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/authorization/ResourceConvert.java @@ -16,15 +16,7 @@ public interface ResourceConvert { ResourceConvert INSTANCE = Mappers.getMapper(ResourceConvert.class); - ResourceBO convert(ResourceDO bean); - @Mapping(source = "bean", target = "node") ResourceTreeNodeBO convertTreeNode(ResourceDO bean); - List convertList(List beans); - - ResourceDO convert(ResourceAddDTO bean); - - ResourceDO convert(ResourceUpdateDTO bean); - } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/user/UserMapper.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/user/UserMapper.java deleted file mode 100644 index 64d103dd2..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/user/UserMapper.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.iocoder.mall.system.biz.dao.user; - -import cn.iocoder.mall.mybatis.query.QueryWrapperX; -import cn.iocoder.mall.system.biz.dataobject.user.UserDO; -import cn.iocoder.mall.system.biz.dto.user.UserPageDTO; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Repository; - -@Repository -public interface UserMapper extends BaseMapper { - - /** - * 根据条件分页查询用户列表 - * @param userPageDTO - * @return - */ - default IPage selectUserPage(UserPageDTO userPageDTO) { - // TODO FROM 芋艿 to jwf1173:看下 QueryWrapperX 噢,已经提供判空啦 [DONE] - return this.selectPage(new Page<>(userPageDTO.getPageNo(), userPageDTO.getPageSize()), - new QueryWrapperX() - .eq(StringUtils.isNotBlank(userPageDTO.getNickname()), "nickname", userPageDTO.getNickname()) - .eq(null != userPageDTO.getStatus(), "status", userPageDTO.getStatus()) - ); - } - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceDeleteDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceDeleteDTO.java deleted file mode 100644 index c6bc835f6..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/ResourceDeleteDTO.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.authorization; - -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotNull; - -/** - * 资源模块 - 删除资源 DTO - */ -@Data -@Accessors(chain = true) -public class ResourceDeleteDTO { - - @NotNull(message = "管理员编号不能为空") - private Integer adminId; - - @ApiModelProperty(value = "资源编号", required = true, example = "1") - @NotNull(message = "资源编号不能为空") - private Integer id; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RoleAddDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RoleAddDTO.java deleted file mode 100644 index a83dc1f9b..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RoleAddDTO.java +++ /dev/null @@ -1,27 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.authorization; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; - -/** - * 角色模块 - 添加角色 DTO - */ -@Data -@Accessors(chain = true) -public class RoleAddDTO { - - @NotNull(message = "管理员编号不能为空") - private Integer adminId; - - @NotEmpty(message = "角色名字不能为空") - private String name; - - /** - * 角色编码 - */ - private String code; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RoleDeleteDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RoleDeleteDTO.java deleted file mode 100644 index bc4f01ede..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RoleDeleteDTO.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.authorization; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotNull; - -/** - * 资源模块 - 删除资源 DTO - */ -@Data -@Accessors(chain = true) -public class RoleDeleteDTO { - - @NotNull(message = "管理员编号不能为空") - private Integer adminId; - - @NotNull(message = "角色编号不能为空") - private Integer id; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RoleGetListDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RoleGetListDTO.java deleted file mode 100644 index 7c6655121..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/RoleGetListDTO.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.authorization; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.Collection; - -/** - * 角色模块 - 获得角色列表 DTO - */ -@Data -@Accessors(chain = true) -public class RoleGetListDTO { - - /** - * 角色编号数组 - * - * 如果传入空,则不进行角色编号的过滤 - */ - private Collection ids; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/event/package-info.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/event/package-info.java deleted file mode 100644 index eb9461bba..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/event/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Spring 事件机制 - * - * 不了解的胖友,可以阅读 http://www.iocoder.cn/Spring-Boot/Event/?onemall 文章 - */ -package cn.iocoder.mall.system.biz.event; diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceService.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceService.java index 423772c76..f60b1b2b2 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceService.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceService.java @@ -1,9 +1,10 @@ package cn.iocoder.mall.system.biz.service.authorization; -import cn.iocoder.common.framework.exception.ServiceException; import cn.iocoder.mall.system.biz.bo.authorization.ResourceBO; import cn.iocoder.mall.system.biz.bo.authorization.ResourceTreeNodeBO; -import cn.iocoder.mall.system.biz.dto.authorization.*; +import cn.iocoder.mall.system.biz.dto.authorization.ResourceCountDTO; +import cn.iocoder.mall.system.biz.dto.authorization.ResourceGetListDTO; +import cn.iocoder.mall.system.biz.dto.authorization.ResourceGetTreeDTO; import java.util.Collection; import java.util.List; @@ -27,20 +28,4 @@ public interface ResourceService { */ List getResourceTree(ResourceGetTreeDTO getTreeDTO); - Integer addResource(ResourceAddDTO addDTO); - - /** - * 更新资源。如果更新失败,则抛出 {@link ServiceException} 异常 - * - * @param updateDTO 更新资源 - */ - void updateResource(ResourceUpdateDTO updateDTO); - - /** - * 删除资源。如果删除失败,则抛出 {@link ServiceException} 异常 - * - * @param deleteDTO 删除资源 - */ - void deleteResource(ResourceDeleteDTO deleteDTO); - } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceServiceImpl.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceServiceImpl.java index 55d166035..f10768f22 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceServiceImpl.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceServiceImpl.java @@ -79,119 +79,4 @@ public class ResourceServiceImpl implements ResourceService { .collect(Collectors.toList()); } - @Override - public Integer addResource(ResourceAddDTO addDTO) { - // 校验父资源存在 - checkParentResource(addDTO.getPid(), null); - // 校验资源(自己) - checkResource(addDTO.getPid(), addDTO.getName(), null); - // 存储到数据库 - ResourceDO resource = ResourceConvert.INSTANCE.convert(addDTO); - initResourceProperty(resource); - resource.setCreateTime(new Date()); - resource.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); - resourceMapper.insert(resource); - // TODO 操作日志 - // 返回成功 - return resource.getId(); - } - - @Override - public void updateResource(ResourceUpdateDTO updateDTO) { - // 校验更新的资源是否存在 - if (resourceMapper.selectById(updateDTO.getId()) == null) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.RESOURCE_NOT_EXISTS); - } - // 校验父资源存在 - checkParentResource(updateDTO.getPid(), updateDTO.getId()); - // 校验资源(自己) - checkResource(updateDTO.getPid(), updateDTO.getName(), updateDTO.getId()); - // 更新到数据库 - ResourceDO resource = ResourceConvert.INSTANCE.convert(updateDTO); - initResourceProperty(resource); - resourceMapper.updateById(resource); - // TODO 操作日志 - } - - @Override - @Transactional - public void deleteResource(ResourceDeleteDTO deleteDTO) { - // 校验更新的资源是否存在 - if (resourceMapper.selectById(deleteDTO.getId()) == null) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.RESOURCE_NOT_EXISTS); - } - // 校验是否还有子资源 - if (resourceMapper.selectCountByPid(deleteDTO.getId()) > 0) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.RESOURCE_EXISTS_CHILDREN); - } - // 更新到数据库 - resourceMapper.deleteById(deleteDTO.getId()); - // 发布资源删除事件,方便清理关联表 - eventPublisher.publishEvent(new ResourceDeleteEvent(this, deleteDTO.getId())); - } - - /** - * 校验父资源是否合法 - * - * 1. 不能舌质红自己为父资源 - * 2. 父资源不存在 - * 3. 父资源必须是 {@link ResourceTypeEnum#MENU} 菜单类型 - * - * @param pid 父资源编号 - * @param childId 当前资源编号 - */ - private void checkParentResource(Integer pid, Integer childId) { - if (pid == null || ResourceIdEnum.ROOT.getId().equals(pid)) { - return; - } - if (pid.equals(childId)) { // 不能设置自己为父资源 - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.RESOURCE_PARENT_ERROR); - } - ResourceDO resource = resourceMapper.selectById(pid); - if (resource == null) { // 父资源不存在 - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.RESOURCE_PARENT_NOT_EXISTS); - } - if (!ResourceTypeEnum.MENU.getType().equals(resource.getType())) { // 父资源必须是菜单类型 - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.RESOURCE_PARENT_NOT_MENU); - } - } - - /** - * 校验资源是否合法 - * - * 1. 校验相同父资源编号下,是否存在相同的资源名 - * - * @param name 资源名字 - * @param pid 父资源编号 - * @param id 资源编号 - */ - private void checkResource(Integer pid, String name, Integer id) { - ResourceDO resource = resourceMapper.selectByPidAndName(pid, name); - if (resource == null) { - return; - } - // 如果 id 为空,说明不用比较是否为相同 id 的资源 - if (id == null) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.RESOURCE_NAME_DUPLICATE); - } - if (!resource.getId().equals(id)) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.RESOURCE_NAME_DUPLICATE); - } - } - - /** - * 初始化资源的通用属性。 - * - * 例如说,只有菜单类型的资源,才设置 icon - * - * @param resource 资源 - */ - private void initResourceProperty(ResourceDO resource) { - // 初始化资源为按钮类型时,无需 route 和 icon 属性 - if (ResourceTypeEnum.BUTTON.getType().equals(resource.getType())) { - resource.setRoute(null); - resource.setIcon(null); - } - } - } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleServiceImpl.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleServiceImpl.java index 8509e2247..2138e417f 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleServiceImpl.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleServiceImpl.java @@ -31,16 +31,6 @@ public class RoleServiceImpl implements RoleService { @Autowired private RoleMapper roleMapper; - @Override - public RoleBO getRole(Integer id) { - return RoleConvert.INSTANCE.convert(roleMapper.selectById(id)); - } - - @Override - public List getRoleList(RoleGetListDTO getListDTO) { - return RoleConvert.INSTANCE.convertList(roleMapper.selectListByIds(getListDTO.getIds())); - } - @Override public PageResult getRolePage(RolePageDTO pageDTO) { return RoleConvert.INSTANCE.convertPage(roleMapper.selectPage(pageDTO)); @@ -57,84 +47,4 @@ public class RoleServiceImpl implements RoleService { return false; } - @Override - public Integer addRole(RoleAddDTO roleAddDTO) { - // 校验角色 - checkDuplicateRole(roleAddDTO.getName(), roleAddDTO.getCode(), null); - // 保存到数据库 - RoleDO role = RoleConvert.INSTANCE.convert(roleAddDTO); - role.setType(RoleTypeEnum.CUSTOM.getType()); - role.setCreateTime(new Date()); - role.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); - roleMapper.insert(role); - // TODO 插入操作日志 - // 返回成功 - return role.getId(); - } - - @Override - public void updateRole(RoleUpdateDTO roleUpdateDTO) { - // 校验角色是否存在 - RoleDO roleDO = roleMapper.selectById(roleUpdateDTO.getId()); - if (roleDO == null) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_NOT_EXISTS); - } - // 内置角色,不允许修改 - if (RoleTypeEnum.SYSTEM.getType().equals(roleDO.getType())) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE); - } - // 校验角色的唯一字段是否重复 - checkDuplicateRole(roleUpdateDTO.getName(), roleUpdateDTO.getCode(), roleUpdateDTO.getId()); - // 更新到数据库 - RoleDO updateRole = RoleConvert.INSTANCE.convert(roleUpdateDTO); - roleMapper.updateById(updateRole); - // TODO 插入操作日志 - } - - @Override - @Transactional - public void deleteRole(RoleDeleteDTO roleDeleteDTO) { - // 校验角色是否存在 - RoleDO roleDO = roleMapper.selectById(roleDeleteDTO.getId()); - if (roleDO == null) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_NOT_EXISTS); - } - // 内置角色,不允许删除 - if (RoleTypeEnum.SYSTEM.getType().equals(roleDO.getType())) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_CAN_NOT_DELETE_SYSTEM_TYPE_ROLE); - } - // 更新到数据库,标记删除 - roleMapper.deleteById(roleDeleteDTO.getId()); - // 发布角色删除事件,方便清理关联表 - eventPublisher.publishEvent(new ResourceDeleteEvent(this, roleDeleteDTO.getId())); - // TODO 插入操作日志 - } - - /** - * 校验角色的唯一字段是否重复 - * - * 1. 是否存在相同名字的角色 - * 2. 是否存在相同编码的角色 - * - * @param name 角色名字 - * @param code 角色额编码 - * @param id 角色编号 - */ - private void checkDuplicateRole(String name, String code, Integer id) { - // 1. 该 name 名字被其它角色所使用 - RoleDO role = roleMapper.selectByName(name); - if (role != null && !role.getId().equals(id)) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_NAME_DUPLICATE, name); - } - // 2. 是否存在相同编码的角色 - if (!StringUtils.hasText(code)) { - return; - } - // 该 code 编码被其它角色所使用 - role = roleMapper.selectByCode(code); - if (role != null && !role.getId().equals(id)) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ROLE_CODE_DUPLICATE, name); - } - } - } diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/mapper/user/UserMapper.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/mapper/user/UserMapper.java index 14d535dbd..7c8e441e7 100644 --- a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/mapper/user/UserMapper.java +++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/mapper/user/UserMapper.java @@ -14,4 +14,18 @@ public interface UserMapper extends BaseMapper { ); } +// /** +// * 根据条件分页查询用户列表 +// * @param userPageDTO +// * @return +// */ +// default IPage selectUserPage(UserPageDTO userPageDTO) { +// // TODO FROM 芋艿 to jwf1173:看下 QueryWrapperX 噢,已经提供判空啦 [DONE] +// return this.selectPage(new Page<>(userPageDTO.getPageNo(), userPageDTO.getPageSize()), +// new QueryWrapperX() +// .eq(StringUtils.isNotBlank(userPageDTO.getNickname()), "nickname", userPageDTO.getNickname()) +// .eq(null != userPageDTO.getStatus(), "status", userPageDTO.getStatus()) +// ); +// } + }