完成资源模块的改造
This commit is contained in:
@@ -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}}
|
||||
|
||||
###
|
||||
|
||||
@@ -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<Integer> createResource(@Valid ResourceCreateDTO createDTO) {
|
||||
return success(resourceManager.createResource(createDTO, AdminSecurityContextHolder.getAdminId()));
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("更新资源")
|
||||
public CommonResult<Boolean> updateResource(@Valid ResourceUpdateDTO updateDTO) {
|
||||
resourceManager.updateResource(updateDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("删除资源")
|
||||
@ApiImplicitParam(name = "resourceId", value = "资源编号", required = true)
|
||||
public CommonResult<Boolean> deleteResource(@RequestParam("resourceId") Integer resourceId) {
|
||||
resourceManager.deleteResource(resourceId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得资源")
|
||||
public CommonResult<ResourceVO> getResource(@RequestParam("resourceId") Integer resourceId) {
|
||||
return success(resourceManager.getResource(resourceId));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获得资源列表")
|
||||
@ApiImplicitParam(name = "resourceId", value = "资源编号列表", required = true)
|
||||
public CommonResult<List<ResourceVO>> getResources(@RequestParam("resourceIds") List<Integer> resourceIds) {
|
||||
return success(resourceManager.listResource(resourceIds));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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<ResourceVO> convertList(List<cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO> list);
|
||||
|
||||
}
|
||||
@@ -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<Integer> createResourceResult = resourceRpc.createResource(ResourceConvert.INSTANCE.convert(createDTO)
|
||||
.setCreateAdminId(createAdminId));
|
||||
createResourceResult.checkError();
|
||||
return createResourceResult.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新资源
|
||||
*
|
||||
* @param updateDTO 更新资源 DTO
|
||||
*/
|
||||
public void updateResource(ResourceUpdateDTO updateDTO) {
|
||||
CommonResult<Boolean> updateResourceResult = resourceRpc.updateResource(ResourceConvert.INSTANCE.convert(updateDTO));
|
||||
updateResourceResult.checkError();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除资源
|
||||
*
|
||||
* @param resourceId 资源编号
|
||||
*/
|
||||
public void deleteResource(Integer resourceId) {
|
||||
CommonResult<Boolean> deleteResourceResult = resourceRpc.deleteResource(resourceId);
|
||||
deleteResourceResult.checkError();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得资源
|
||||
*
|
||||
* @param resourceId 资源编号
|
||||
* @return 资源
|
||||
*/
|
||||
public ResourceVO getResource(Integer resourceId) {
|
||||
CommonResult<cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO> getResourceResult = resourceRpc.getResource(resourceId);
|
||||
getResourceResult.checkError();
|
||||
return ResourceConvert.INSTANCE.convert(getResourceResult.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得资源列表
|
||||
*
|
||||
* @param resourceIds 资源编号列表
|
||||
* @return 资源列表
|
||||
*/
|
||||
public List<ResourceVO> listResource(List<Integer> resourceIds) {
|
||||
CommonResult<List<cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO>> listResourceResult = resourceRpc.listResource(resourceIds);
|
||||
return ResourceConvert.INSTANCE.convertList(listResourceResult.getData());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user