mirror of https://gitee.com/stylefeng/roses
parent
c6f71380a7
commit
d3b8d8838a
|
@ -47,6 +47,14 @@
|
|||
<version>7.0.4</version>
|
||||
</dependency>
|
||||
|
||||
<!--字典的api-->
|
||||
<!--多语言类型,存在于字典表-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>dict-api</artifactId>
|
||||
<version>7.0.3</version>
|
||||
</dependency>
|
||||
|
||||
<!--web-->
|
||||
<!--ResourcePersistenceApi会用到web,用在提供feign接口时-->
|
||||
<dependency>
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package cn.stylefeng.roses.kernel.system.api.exception.enums.resource;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.api.constants.SystemConstants;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 接口分组异常相关枚举
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@Getter
|
||||
public enum ApiGroupExceptionEnum implements AbstractExceptionEnum {
|
||||
|
||||
/**
|
||||
* 查询结果不存在
|
||||
*/
|
||||
APIGROUP_NOT_EXISTED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "01", "查询结果不存在"),
|
||||
|
||||
/**
|
||||
* 根节点不允许操作
|
||||
*/
|
||||
ROOT_PROHIBIT_OPERATION(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "02", "根节点不允许操作"),
|
||||
|
||||
/**
|
||||
* 父节点不能选择自己
|
||||
*/
|
||||
PARENT_NODE_ITSELF(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "03", "父节点不能选择自己"),
|
||||
|
||||
/**
|
||||
* 父节点不能选择自己的子节点
|
||||
*/
|
||||
NODE_NOT_ALLOWED_SUB_NODE(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "04", "父节点不能选择自己的子节点");
|
||||
|
||||
/**
|
||||
* 错误编码
|
||||
*/
|
||||
private final String errorCode;
|
||||
|
||||
/**
|
||||
* 提示用户信息
|
||||
*/
|
||||
private final String userTip;
|
||||
|
||||
ApiGroupExceptionEnum(String errorCode, String userTip) {
|
||||
this.errorCode = errorCode;
|
||||
this.userTip = userTip;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package cn.stylefeng.roses.kernel.system.api.exception.enums.resource;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.api.constants.SystemConstants;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 接口信息异常相关枚举
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@Getter
|
||||
public enum ApiResourceExceptionEnum implements AbstractExceptionEnum {
|
||||
|
||||
/**
|
||||
* 查询结果不存在
|
||||
*/
|
||||
APIRESOURCE_NOT_EXISTED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "01", "查询结果不存在"),
|
||||
|
||||
/**
|
||||
* 不允许对资源节点进行操作
|
||||
*/
|
||||
OPERATIONS_RESOURCE_NODESNOT_ALLOWED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "02", "不允许对资源节点进行操作"),
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* 错误编码
|
||||
*/
|
||||
private final String errorCode;
|
||||
|
||||
/**
|
||||
* 提示用户信息
|
||||
*/
|
||||
private final String userTip;
|
||||
|
||||
ApiResourceExceptionEnum(String errorCode, String userTip) {
|
||||
this.errorCode = errorCode;
|
||||
this.userTip = userTip;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package cn.stylefeng.roses.kernel.system.api.exception.enums.resource;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.api.constants.SystemConstants;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 接口字段信息异常相关枚举
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@Getter
|
||||
public enum ApiResourceFieldExceptionEnum implements AbstractExceptionEnum {
|
||||
|
||||
/**
|
||||
* 查询结果不存在
|
||||
*/
|
||||
APIRESOURCEFIELD_NOT_EXISTED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "01", "查询结果不存在");
|
||||
|
||||
/**
|
||||
* 错误编码
|
||||
*/
|
||||
private final String errorCode;
|
||||
|
||||
/**
|
||||
* 提示用户信息
|
||||
*/
|
||||
private final String userTip;
|
||||
|
||||
ApiResourceFieldExceptionEnum(String errorCode, String userTip) {
|
||||
this.errorCode = errorCode;
|
||||
this.userTip = userTip;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package cn.stylefeng.roses.kernel.system.api.pojo.resource;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 接口分组封装类
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class ApiGroupRequest extends BaseRequest {
|
||||
|
||||
/**
|
||||
* 资源分组主键
|
||||
*/
|
||||
@NotNull(message = "资源分组主键不能为空", groups = {edit.class, delete.class, detail.class})
|
||||
private Long groupId;
|
||||
|
||||
/**
|
||||
* 分组名称
|
||||
*/
|
||||
@NotBlank(message = "分组名称不能为空", groups = {add.class, edit.class})
|
||||
private String groupName;
|
||||
|
||||
/**
|
||||
* 分组父ID
|
||||
*/
|
||||
@NotNull(message = "分组名称不能为空", groups = {add.class, edit.class})
|
||||
private Long groupPid;
|
||||
|
||||
/**
|
||||
* 分组父ID集合
|
||||
*/
|
||||
private String groupPids;
|
||||
|
||||
/**
|
||||
* 分组排序
|
||||
*/
|
||||
@NotNull(message = "分组名称不能为空", groups = {add.class, edit.class})
|
||||
private java.math.BigDecimal groupSort;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private Long createUser;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private String updateTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private Long updateUser;
|
||||
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
package cn.stylefeng.roses.kernel.system.api.pojo.resource;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.rule.tree.factory.base.AbstractTreeNode;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 接口分组树节点包装类
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/5/22 上午11:03
|
||||
*/
|
||||
@Data
|
||||
public class ApiGroupTreeWrapper implements AbstractTreeNode<ApiGroupTreeWrapper> {
|
||||
|
||||
/**
|
||||
* 节点id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 节点名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 节点父ID
|
||||
*/
|
||||
private Long pid;
|
||||
|
||||
/**
|
||||
* 节点是否可选择
|
||||
*/
|
||||
private Boolean selectable = true;
|
||||
|
||||
/**
|
||||
* 类型(1:节点;2:资源)
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 节点数据
|
||||
*/
|
||||
private Object data;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private BigDecimal sort;
|
||||
|
||||
/**
|
||||
* 图标
|
||||
*/
|
||||
private Map<String, String> slots = new HashMap<>();
|
||||
|
||||
/**
|
||||
* tree子节点
|
||||
*/
|
||||
private List<ApiGroupTreeWrapper> children = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
public void setSlotsValue() {
|
||||
if ("1".equals(type)) {
|
||||
slots.put("icon", "group");
|
||||
} else {
|
||||
slots.put("icon", "resource");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNodeId() {
|
||||
if (this.id == null) {
|
||||
return null;
|
||||
} else {
|
||||
return this.id.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNodeParentId() {
|
||||
if (this.pid == null) {
|
||||
return null;
|
||||
} else {
|
||||
return this.pid.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChildrenNodes(List childrenNodes) {
|
||||
this.children = childrenNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把本节点的所有子节点排序了
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/3/16 14:04
|
||||
*/
|
||||
public void sortChildren() {
|
||||
if (ObjectUtil.isNotEmpty(children)) {
|
||||
this.children = children.stream().sorted(Comparator.comparing(ApiGroupTreeWrapper::getSort)).collect(Collectors.toList());
|
||||
// 让所有子节点也进行该操作
|
||||
for (ApiGroupTreeWrapper apiGroupTreeWrapper : this.children) {
|
||||
apiGroupTreeWrapper.sortChildren();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package cn.stylefeng.roses.kernel.system.api.pojo.resource;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 接口字段信息封装类
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class ApiResourceFieldRequest extends BaseRequest {
|
||||
|
||||
/**
|
||||
* 字段主键
|
||||
*/
|
||||
@NotNull(message = "字段主键不能为空", groups = {delete.class})
|
||||
private Long fieldId;
|
||||
|
||||
/**
|
||||
* 资源编码
|
||||
*/
|
||||
@NotNull(message = "资源编码不能为空", groups = {add.class,list.class})
|
||||
private Long apiResourceId;
|
||||
|
||||
/**
|
||||
* 参数位置:request-请求参数,response-响应参数
|
||||
*/
|
||||
@NotBlank(message = "参数位置不能为空",groups = {add.class,edit.class})
|
||||
private String fieldLocation;
|
||||
|
||||
/**
|
||||
* 字段名称,例如:邮箱
|
||||
*/
|
||||
@NotBlank(message = "参数位置不能为空",groups = {add.class,edit.class})
|
||||
private String fieldName;
|
||||
|
||||
/**
|
||||
* 字段编码,例如:email
|
||||
*/
|
||||
@NotBlank(message = "参数位置不能为空",groups = {add.class,edit.class})
|
||||
private String fieldCode;
|
||||
|
||||
/**
|
||||
* 字段类型:string或file
|
||||
*/
|
||||
@NotBlank(message = "参数位置不能为空",groups = {add.class,edit.class})
|
||||
private String fieldType;
|
||||
|
||||
/**
|
||||
* 是否必填:Y-是,N-否
|
||||
*/
|
||||
@NotBlank(message = "参数位置不能为空",groups = {add.class,edit.class})
|
||||
private String fieldRequired;
|
||||
|
||||
/**
|
||||
* 字段其他校验信息,后端校验注解内容
|
||||
*/
|
||||
private String fieldValidationMsg;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private Long createUser;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private String updateTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private Long updateUser;
|
||||
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
package cn.stylefeng.roses.kernel.system.api.pojo.resource;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.field.ChineseDescription;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 接口信息封装类
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class ApiResourceRequest extends BaseRequest {
|
||||
|
||||
/**
|
||||
* 接口信息主键
|
||||
*/
|
||||
@NotNull(message = "接口信息主键不能为空", groups = {detail.class, edit.class, delete.class, record.class})
|
||||
@ChineseDescription("接口信息主键")
|
||||
private Long apiResourceId;
|
||||
|
||||
/**
|
||||
* 资源分组数据主键
|
||||
*/
|
||||
@NotNull(message = "资源分组数据主键不能为空", groups = {add.class, edit.class})
|
||||
@ChineseDescription("资源分组数据主键")
|
||||
private Long groupId;
|
||||
|
||||
/**
|
||||
* 请求头
|
||||
*/
|
||||
@ChineseDescription("请求头")
|
||||
private Map<String, String> lastRequestHeader;
|
||||
|
||||
/**
|
||||
* 请求url:完整路径,包含http协议头
|
||||
*/
|
||||
@NotBlank(message = "请求路径不能为空", groups = {record.class})
|
||||
@ChineseDescription("请求url:完整路径,包含http协议头")
|
||||
private String requestUrl;
|
||||
|
||||
/**
|
||||
* 请求方式:GET,POST
|
||||
*/
|
||||
@NotBlank(message = "请求方式不能为空", groups = {edit.class})
|
||||
@ChineseDescription("请求方式:GET,POST")
|
||||
private String requestMethod;
|
||||
|
||||
/**
|
||||
* 接口自定义名称,区别于sys_resource表的名称
|
||||
*/
|
||||
@NotBlank(message = "接口自定义名称,区别于sys_resource表的名称不能为空", groups = {edit.class})
|
||||
@ChineseDescription("接口自定义名称,区别于sys_resource表的名称")
|
||||
private String apiAlias;
|
||||
|
||||
/**
|
||||
* 资源唯一编码,关联sys_resource表的code
|
||||
*/
|
||||
@NotBlank(message = "资源唯一编码,关联sys_resource表的code不能为空", groups = {add.class, allField.class})
|
||||
@ChineseDescription("资源唯一编码,关联sys_resource表的code")
|
||||
private String resourceCode;
|
||||
|
||||
/**
|
||||
* 上次接口调用的参数内容
|
||||
*/
|
||||
@ChineseDescription("上次接口调用的参数内容")
|
||||
private String lastRequestContent;
|
||||
|
||||
/**
|
||||
* 上次接口调用的响应内容
|
||||
*/
|
||||
@ChineseDescription("上次接口调用的响应内容")
|
||||
private String lastResponseContent;
|
||||
|
||||
/**
|
||||
* 资源排序
|
||||
*/
|
||||
@NotNull(message = "接口自定义名称不能为空", groups = {edit.class})
|
||||
@ChineseDescription("资源排序")
|
||||
private java.math.BigDecimal resourceSort;
|
||||
|
||||
/**
|
||||
* 资源字段列表
|
||||
*/
|
||||
private List<ApiResourceFieldRequest> apiResourceFieldRequestList;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 创建用户
|
||||
*/
|
||||
private Long createUser;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private String updateTime;
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*/
|
||||
private Long updateUser;
|
||||
|
||||
/**
|
||||
* 记录请求内容
|
||||
*/
|
||||
public @interface record {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 全部字段
|
||||
*/
|
||||
public @interface allField {
|
||||
|
||||
}
|
||||
}
|
|
@ -449,7 +449,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
@Override
|
||||
public List<String> getUserAppCodeList() {
|
||||
|
||||
LambdaQueryWrapper<SysMenu> queryWrapper = createWrapper(null);
|
||||
LambdaQueryWrapper<SysMenu> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.select(SysMenu::getAppCode);
|
||||
queryWrapper.groupBy(SysMenu::getAppCode);
|
||||
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.controller;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.resource.ApiGroupRequest;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.resource.ApiGroupTreeWrapper;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.service.ApiGroupService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 接口分组控制器
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@RestController
|
||||
@ApiResource(name = "接口分组")
|
||||
public class ApiGroupController {
|
||||
|
||||
@Resource
|
||||
private ApiGroupService apiGroupService;
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@PostResource(name = "添加", path = "/apiGroup/add")
|
||||
public ResponseData add(@RequestBody @Validated(ApiGroupRequest.add.class) ApiGroupRequest apiGroupRequest) {
|
||||
return new SuccessResponseData(apiGroupService.add(apiGroupRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@PostResource(name = "删除", path = "/apiGroup/delete")
|
||||
public ResponseData delete(@RequestBody @Validated(ApiGroupRequest.delete.class) ApiGroupRequest apiGroupRequest) {
|
||||
apiGroupService.del(apiGroupRequest);
|
||||
return new SuccessResponseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@PostResource(name = "编辑", path = "/apiGroup/edit")
|
||||
public ResponseData edit(@RequestBody @Validated(ApiGroupRequest.edit.class) ApiGroupRequest apiGroupRequest) {
|
||||
apiGroupService.edit(apiGroupRequest);
|
||||
return new SuccessResponseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看详情
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@GetResource(name = "查看详情", path = "/apiGroup/detail")
|
||||
public ResponseData detail(@Validated(ApiGroupRequest.detail.class) ApiGroupRequest apiGroupRequest) {
|
||||
return new SuccessResponseData(apiGroupService.detail(apiGroupRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@GetResource(name = "获取列表", path = "/apiGroup/list")
|
||||
public ResponseData list(ApiGroupRequest apiGroupRequest) {
|
||||
return new SuccessResponseData(apiGroupService.findList(apiGroupRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表(带分页)
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@GetResource(name = "分页查询", path = "/apiGroup/page")
|
||||
public ResponseData page(ApiGroupRequest apiGroupRequest) {
|
||||
return new SuccessResponseData(apiGroupService.findPage(apiGroupRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取树
|
||||
*
|
||||
* @return {@link ResponseData}
|
||||
* @author majianguo
|
||||
* @date 2021/5/22 上午11:00
|
||||
**/
|
||||
@GetResource(name = "获取树", path = "/apiGroup/tree")
|
||||
public ResponseData tree(ApiGroupRequest apiGroupRequest) {
|
||||
List<ApiGroupTreeWrapper> apiGroupTreeWrapperList = apiGroupService.tree(apiGroupRequest);
|
||||
return new SuccessResponseData(apiGroupTreeWrapperList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取树(平级)
|
||||
*
|
||||
* @return {@link ResponseData}
|
||||
* @author majianguo
|
||||
* @date 2021/5/22 上午11:00
|
||||
**/
|
||||
@GetResource(name = "获取树", path = "/apiGroup/peersTree")
|
||||
public ResponseData peersTree(ApiGroupRequest apiGroupRequest) {
|
||||
List<ApiGroupTreeWrapper> apiGroupTreeWrapperList = apiGroupService.peersTree(apiGroupRequest);
|
||||
return new SuccessResponseData(apiGroupTreeWrapperList);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.controller;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.resource.ApiResourceRequest;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.service.ApiResourceService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 接口信息控制器
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@RestController
|
||||
@ApiResource(name = "接口信息")
|
||||
public class ApiResourceController {
|
||||
|
||||
@Resource
|
||||
private ApiResourceService apiResourceService;
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@PostResource(name = "添加", path = "/apiResource/add")
|
||||
public ResponseData add(@RequestBody @Validated(ApiResourceRequest.add.class) ApiResourceRequest apiResourceRequest) {
|
||||
apiResourceService.add(apiResourceRequest);
|
||||
return new SuccessResponseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@PostResource(name = "删除", path = "/apiResource/delete")
|
||||
public ResponseData delete(@RequestBody @Validated(ApiResourceRequest.delete.class) ApiResourceRequest apiResourceRequest) {
|
||||
apiResourceService.del(apiResourceRequest);
|
||||
return new SuccessResponseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@PostResource(name = "编辑", path = "/apiResource/edit")
|
||||
public ResponseData edit(@RequestBody @Validated(ApiResourceRequest.edit.class) ApiResourceRequest apiResourceRequest) {
|
||||
apiResourceService.edit(apiResourceRequest);
|
||||
return new SuccessResponseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求记录
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@PostResource(name = "请求记录", path = "/apiResource/record")
|
||||
public ResponseData record(@RequestBody @Validated(ApiResourceRequest.record.class) ApiResourceRequest apiResourceRequest) {
|
||||
cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiResource apiResource = apiResourceService.record(apiResourceRequest);
|
||||
return new SuccessResponseData(apiResource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看详情
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@GetResource(name = "查看详情", path = "/apiResource/detail")
|
||||
public ResponseData detail(@Validated(ApiResourceRequest.detail.class) ApiResourceRequest apiResourceRequest) {
|
||||
return new SuccessResponseData(apiResourceService.detail(apiResourceRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@GetResource(name = "获取列表", path = "/apiResource/list")
|
||||
public ResponseData list(ApiResourceRequest apiResourceRequest) {
|
||||
return new SuccessResponseData(apiResourceService.findList(apiResourceRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表(带分页)
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@GetResource(name = "分页查询", path = "/apiResource/page")
|
||||
public ResponseData page(ApiResourceRequest apiResourceRequest) {
|
||||
return new SuccessResponseData(apiResourceService.findPage(apiResourceRequest));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询该资源所有字段
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@GetResource(name = "查询该资源所有字段", path = "/apiResource/allField")
|
||||
public ResponseData allField(@Validated(ApiResourceRequest.allField.class) ApiResourceRequest apiResourceRequest) {
|
||||
return new SuccessResponseData(apiResourceService.allField(apiResourceRequest));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.entity;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 接口分组实例类
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@TableName("api_group")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ApiGroup extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 资源分组主键
|
||||
*/
|
||||
@TableId(value = "group_id", type = IdType.ASSIGN_ID)
|
||||
private Long groupId;
|
||||
|
||||
/**
|
||||
* 分组名称
|
||||
*/
|
||||
@TableField("group_name")
|
||||
private String groupName;
|
||||
|
||||
/**
|
||||
* 分组父ID
|
||||
*/
|
||||
@TableField("group_pid")
|
||||
private Long groupPid;
|
||||
|
||||
/**
|
||||
* 分组父ID集合
|
||||
*/
|
||||
@TableField("group_pids")
|
||||
private String groupPids;
|
||||
|
||||
/**
|
||||
* 分组排序
|
||||
*/
|
||||
@TableField("group_sort")
|
||||
private java.math.BigDecimal groupSort;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("create_time")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField("create_user")
|
||||
private Long createUser;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField("update_time")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@TableField("update_user")
|
||||
private Long updateUser;
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.entity;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 接口信息实例类
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@TableName("api_resource")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ApiResource extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 接口信息主键
|
||||
*/
|
||||
@TableId(value = "api_resource_id", type = IdType.ASSIGN_ID)
|
||||
private Long apiResourceId;
|
||||
|
||||
/**
|
||||
* 资源分组数据主键
|
||||
*/
|
||||
@TableField("group_id")
|
||||
private Long groupId;
|
||||
|
||||
/**
|
||||
* 请求方式:GET,POST
|
||||
*/
|
||||
@TableField("request_method")
|
||||
private String requestMethod;
|
||||
|
||||
/**
|
||||
* 接口自定义名称,区别于sys_resource表的名称
|
||||
*/
|
||||
@TableField("api_alias")
|
||||
private String apiAlias;
|
||||
|
||||
/**
|
||||
* 资源唯一编码,关联sys_resource表的code
|
||||
*/
|
||||
@TableField("resource_code")
|
||||
private String resourceCode;
|
||||
|
||||
/**
|
||||
* 上次接口调用的头部信息
|
||||
*/
|
||||
@TableField("last_request_header")
|
||||
private String lastRequestHeader;
|
||||
|
||||
/**
|
||||
* 上次接口调用的参数内容
|
||||
*/
|
||||
@TableField("last_request_content")
|
||||
private String lastRequestContent;
|
||||
|
||||
/**
|
||||
* 上次接口调用的响应内容
|
||||
*/
|
||||
@TableField("last_response_content")
|
||||
private String lastResponseContent;
|
||||
|
||||
/**
|
||||
* 资源排序
|
||||
*/
|
||||
@TableField("resource_sort")
|
||||
private java.math.BigDecimal resourceSort;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("create_time")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 创建用户
|
||||
*/
|
||||
@TableField("create_user")
|
||||
private Long createUser;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@TableField("update_time")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*/
|
||||
@TableField("update_user")
|
||||
private Long updateUser;
|
||||
|
||||
/**
|
||||
* 该资源所有字段
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private List<ApiResourceField> apiResourceFieldList;
|
||||
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.entity;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 接口字段信息实例类
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@TableName("api_resource_field")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ApiResourceField extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 字段主键
|
||||
*/
|
||||
@TableId(value = "field_id", type = IdType.ASSIGN_ID)
|
||||
private Long fieldId;
|
||||
|
||||
/**
|
||||
* 资源编码
|
||||
*/
|
||||
@TableField(value = "api_resource_id")
|
||||
private Long apiResourceId;
|
||||
|
||||
/**
|
||||
* 参数位置:request-请求参数,response-响应参数
|
||||
*/
|
||||
@TableField("field_location")
|
||||
private String fieldLocation;
|
||||
|
||||
/**
|
||||
* 字段名称,例如:邮箱
|
||||
*/
|
||||
@TableField("field_name")
|
||||
private String fieldName;
|
||||
|
||||
/**
|
||||
* 字段编码,例如:email
|
||||
*/
|
||||
@TableField("field_code")
|
||||
private String fieldCode;
|
||||
|
||||
/**
|
||||
* 字段类型:string或file
|
||||
*/
|
||||
@TableField("field_type")
|
||||
private String fieldType;
|
||||
|
||||
/**
|
||||
* 是否必填:Y-是,N-否
|
||||
*/
|
||||
@TableField("field_required")
|
||||
private String fieldRequired;
|
||||
|
||||
/**
|
||||
* 字段其他校验信息,后端校验注解内容
|
||||
*/
|
||||
@TableField("field_validation_msg")
|
||||
private String fieldValidationMsg;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("create_time")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField("create_user")
|
||||
private Long createUser;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField("update_time")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@TableField("update_user")
|
||||
private Long updateUser;
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 分组树节点枚举
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/5/24 下午12:04
|
||||
*/
|
||||
@Getter
|
||||
public enum NodeEnums {
|
||||
|
||||
/**
|
||||
* 根节点
|
||||
*/
|
||||
ROOT_NODE(1000000000000000000L, "根节点");
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private final Long id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
NodeEnums(Long id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 分组树节点类型枚举
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/5/24 下午2:47
|
||||
*/
|
||||
@Getter
|
||||
public enum NodeTypeEnums {
|
||||
|
||||
/**
|
||||
* 叶子节点
|
||||
*/
|
||||
LEAF_NODE("1", "根节点"),
|
||||
|
||||
/**
|
||||
* 数据节点
|
||||
*/
|
||||
DATA_NODE("2", "数据节点"),
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private final String type;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
NodeTypeEnums(String type, String name) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.mapper;
|
||||
|
||||
import cn.stylefeng.roses.kernel.dict.api.pojo.dict.request.ParentIdsUpdateRequest;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiGroup;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 接口分组 Mapper 接口
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
public interface ApiGroupMapper extends BaseMapper<ApiGroup> {
|
||||
|
||||
/**
|
||||
* 修改pids
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/5/22 上午10:03
|
||||
**/
|
||||
void updateSubPids(@Param("paramCondition") ParentIdsUpdateRequest parentIdsUpdateRequest);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.mapper;
|
||||
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiResourceField;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* 接口字段信息 Mapper 接口
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
public interface ApiResourceFieldMapper extends BaseMapper<ApiResourceField> {
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.mapper;
|
||||
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiResource;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* 接口信息 Mapper 接口
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
public interface ApiResourceMapper extends BaseMapper<ApiResource> {
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.stylefeng.roses.kernel.system.modular.resource.mapper.ApiGroupMapper">
|
||||
|
||||
<update id="updateSubPids" parameterType="cn.stylefeng.roses.kernel.dict.api.pojo.dict.request.ParentIdsUpdateRequest">
|
||||
UPDATE
|
||||
api_group
|
||||
SET group_pids = replace(group_pids, #{paramCondition.oldParentIds}, #{paramCondition.newParentIds}),
|
||||
update_time = #{paramCondition.updateTime},
|
||||
update_user = #{paramCondition.updateUser}
|
||||
WHERE group_pids LIKE CONCAT('%', #{paramCondition.oldParentIds}, '%')
|
||||
</update>
|
||||
</mapper>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.stylefeng.roses.kernel.system.modular.resource.mapper.ApiResourceFieldMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.stylefeng.roses.kernel.system.modular.resource.mapper.ApiResourceMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,92 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.resource.ApiGroupRequest;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.resource.ApiGroupTreeWrapper;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiGroup;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 接口分组 服务类
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
public interface ApiGroupService extends IService<ApiGroup> {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param apiGroupRequest
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
ApiGroup add(ApiGroupRequest apiGroupRequest);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param apiGroupRequest
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
void del(ApiGroupRequest apiGroupRequest);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param apiGroupRequest
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
void edit(ApiGroupRequest apiGroupRequest);
|
||||
|
||||
/**
|
||||
* 查询详情
|
||||
*
|
||||
* @param apiGroupRequest
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
ApiGroup detail(ApiGroupRequest apiGroupRequest);
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param apiGroupRequest
|
||||
* @return List<ApiGroup>
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
List<ApiGroup> findList(ApiGroupRequest apiGroupRequest);
|
||||
|
||||
/**
|
||||
* 获取列表(带分页)
|
||||
*
|
||||
* @param apiGroupRequest
|
||||
* @return PageResult<ApiGroup>
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
PageResult<ApiGroup> findPage(ApiGroupRequest apiGroupRequest);
|
||||
|
||||
/**
|
||||
* 获取树
|
||||
*
|
||||
* @return {@link List< ApiGroupTreeWrapper>}
|
||||
* @author majianguo
|
||||
* @date 2021/5/22 上午11:11
|
||||
**/
|
||||
List<ApiGroupTreeWrapper> tree(ApiGroupRequest apiGroupRequest);
|
||||
|
||||
/**
|
||||
* 获取树
|
||||
*
|
||||
* @return {@link List< ApiGroupTreeWrapper>}
|
||||
* @author majianguo
|
||||
* @date 2021/5/22 上午11:11
|
||||
**/
|
||||
List<ApiGroupTreeWrapper> peersTree(ApiGroupRequest apiGroupRequest);
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.resource.ApiResourceFieldRequest;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiResourceField;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 接口字段信息 服务类
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
public interface ApiResourceFieldService extends IService<ApiResourceField> {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param apiResourceFieldRequest
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
void add(ApiResourceFieldRequest apiResourceFieldRequest);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param apiResourceFieldRequest
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
void del(ApiResourceFieldRequest apiResourceFieldRequest);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param apiResourceFieldRequest
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
void edit(ApiResourceFieldRequest apiResourceFieldRequest);
|
||||
|
||||
/**
|
||||
* 查询详情
|
||||
*
|
||||
* @param apiResourceFieldRequest
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
ApiResourceField detail(ApiResourceFieldRequest apiResourceFieldRequest);
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param apiResourceFieldRequest
|
||||
* @return List<ApiResourceField>
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
List<ApiResourceField> findList(ApiResourceFieldRequest apiResourceFieldRequest);
|
||||
|
||||
/**
|
||||
* 获取列表(带分页)
|
||||
*
|
||||
* @param apiResourceFieldRequest
|
||||
* @return PageResult<ApiResourceField>
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
PageResult<ApiResourceField> findPage(ApiResourceFieldRequest apiResourceFieldRequest);
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.resource.ApiResourceRequest;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiResourceField;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 接口信息 服务类
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
public interface ApiResourceService extends IService<ApiResource> {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param apiResourceRequest
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
void add(ApiResourceRequest apiResourceRequest);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param apiResourceRequest
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
void del(ApiResourceRequest apiResourceRequest);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param apiResourceRequest
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
void edit(ApiResourceRequest apiResourceRequest);
|
||||
|
||||
/**
|
||||
* 查询详情
|
||||
*
|
||||
* @param apiResourceRequest
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
ApiResource detail(ApiResourceRequest apiResourceRequest);
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param apiResourceRequest
|
||||
* @return List<ApiResource>
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
List<ApiResource> findList(ApiResourceRequest apiResourceRequest);
|
||||
|
||||
/**
|
||||
* 获取列表(带分页)
|
||||
*
|
||||
* @param apiResourceRequest
|
||||
* @return PageResult<ApiResource>
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
PageResult<ApiResource> findPage(ApiResourceRequest apiResourceRequest);
|
||||
|
||||
/**
|
||||
* 请求记录
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/5/22 下午3:01
|
||||
**/
|
||||
ApiResource record(ApiResourceRequest apiResourceRequest);
|
||||
|
||||
/**
|
||||
* 查询该资源所有字段
|
||||
*
|
||||
* @return {@link List<cn.stylefeng.guns.modular.system.apiresourcefield.entity.ApiResourceField>}
|
||||
* @author majianguo
|
||||
* @date 2021/5/24 下午6:45
|
||||
**/
|
||||
List<ApiResourceField> allField(ApiResourceRequest apiResourceRequest);
|
||||
}
|
|
@ -0,0 +1,331 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.dict.api.pojo.dict.request.ParentIdsUpdateRequest;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.SymbolConstant;
|
||||
import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException;
|
||||
import cn.stylefeng.roses.kernel.system.api.exception.enums.resource.ApiGroupExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.resource.ApiGroupRequest;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.resource.ApiGroupTreeWrapper;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiGroup;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiResourceField;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.enums.NodeEnums;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.enums.NodeTypeEnums;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.mapper.ApiGroupMapper;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.service.ApiGroupService;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.service.ApiResourceFieldService;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.service.ApiResourceService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 接口分组业务实现层
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@Service
|
||||
public class ApiGroupServiceImpl extends ServiceImpl<ApiGroupMapper, ApiGroup> implements ApiGroupService {
|
||||
|
||||
@Autowired
|
||||
private ApiResourceService apiResourceService;
|
||||
|
||||
@Autowired
|
||||
private ApiResourceFieldService apiResourceFieldService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApiGroup add(ApiGroupRequest apiGroupRequest) {
|
||||
ApiGroup apiGroup = new ApiGroup();
|
||||
BeanUtil.copyProperties(apiGroupRequest, apiGroup);
|
||||
this.setPids(apiGroup);
|
||||
this.save(apiGroup);
|
||||
return apiGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void del(ApiGroupRequest apiGroupRequest) {
|
||||
|
||||
// 根节点不允许删除
|
||||
if (NodeEnums.ROOT_NODE.getId().equals(apiGroupRequest.getGroupId())) {
|
||||
throw new SystemModularException(ApiGroupExceptionEnum.ROOT_PROHIBIT_OPERATION);
|
||||
}
|
||||
|
||||
ApiGroup apiGroup = this.queryApiGroup(apiGroupRequest);
|
||||
this.removeById(apiGroup.getGroupId());
|
||||
|
||||
// 查询所有子节点数据
|
||||
LambdaQueryWrapper<ApiGroup> apiGroupLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
apiGroupLambdaQueryWrapper.like(ApiGroup::getGroupPids, SymbolConstant.LEFT_SQUARE_BRACKETS + apiGroup.getGroupId() + SymbolConstant.RIGHT_SQUARE_BRACKETS);
|
||||
List<ApiGroup> apiGroups = this.list(apiGroupLambdaQueryWrapper);
|
||||
|
||||
Set<Long> apiGroupIdSet = null;
|
||||
if (ObjectUtil.isNotEmpty(apiGroups)) {
|
||||
apiGroupIdSet = apiGroups.stream().map(ApiGroup::getGroupId).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotEmpty(apiGroupIdSet)) {
|
||||
// 查询所有分组下的接口
|
||||
LambdaQueryWrapper<ApiResource> apiResourceLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
apiResourceLambdaQueryWrapper.in(ApiResource::getGroupId, apiGroupIdSet);
|
||||
List<ApiResource> apiResourceList = this.apiResourceService.list(apiResourceLambdaQueryWrapper);
|
||||
|
||||
if (ObjectUtil.isNotEmpty(apiResourceList)) {
|
||||
Set<Long> apiResourceSet = apiResourceList.stream().map(ApiResource::getApiResourceId).collect(Collectors.toSet());
|
||||
// 删除所有接口的字段
|
||||
LambdaQueryWrapper<ApiResourceField> apiResourceFieldLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
apiResourceFieldLambdaQueryWrapper.in(ApiResourceField::getApiResourceId, apiResourceSet);
|
||||
this.apiResourceFieldService.remove(apiResourceFieldLambdaQueryWrapper);
|
||||
}
|
||||
|
||||
// 执行删除所有分组下的接口
|
||||
this.apiResourceService.remove(apiResourceLambdaQueryWrapper);
|
||||
}
|
||||
|
||||
// 删除所有子节点数据
|
||||
this.remove(apiGroupLambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void edit(ApiGroupRequest apiGroupRequest) {
|
||||
|
||||
// 查询数据库中该条数据的信息
|
||||
ApiGroup oldApiGroup = this.queryApiGroup(apiGroupRequest);
|
||||
|
||||
// 父节点不能是自己
|
||||
if (apiGroupRequest.getGroupPid().equals(oldApiGroup.getGroupId())) {
|
||||
throw new SystemModularException(ApiGroupExceptionEnum.PARENT_NODE_ITSELF);
|
||||
}
|
||||
|
||||
// 父节点不能是自己的子节点
|
||||
LambdaQueryWrapper<ApiGroup> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.like(ApiGroup::getGroupPids, SymbolConstant.LEFT_SQUARE_BRACKETS + oldApiGroup.getGroupId() + SymbolConstant.RIGHT_SQUARE_BRACKETS);
|
||||
List<ApiGroup> apiGroups = this.list(lambdaQueryWrapper);
|
||||
if (ObjectUtil.isNotEmpty(apiGroups)) {
|
||||
if (apiGroups.stream().anyMatch(item -> item.getGroupId().equals(apiGroupRequest.getGroupPid()))) {
|
||||
throw new SystemModularException(ApiGroupExceptionEnum.PARENT_NODE_ITSELF);
|
||||
}
|
||||
}
|
||||
|
||||
// 转换请求数据
|
||||
ApiGroup newApiGroup = BeanUtil.toBean(apiGroupRequest, ApiGroup.class);
|
||||
|
||||
// 判断是否变换了父ID
|
||||
if (!newApiGroup.getGroupPid().equals(oldApiGroup.getGroupPid())) {
|
||||
// 处理pids
|
||||
this.setPids(newApiGroup);
|
||||
|
||||
// 更新所有子部门的pids
|
||||
this.updatePids(newApiGroup, oldApiGroup);
|
||||
}
|
||||
|
||||
this.updateById(newApiGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiGroup detail(ApiGroupRequest apiGroupRequest) {
|
||||
return this.queryApiGroup(apiGroupRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ApiGroup> findPage(ApiGroupRequest apiGroupRequest) {
|
||||
LambdaQueryWrapper<ApiGroup> wrapper = createWrapper(apiGroupRequest);
|
||||
Page<ApiGroup> sysRolePage = this.page(PageFactory.defaultPage(), wrapper);
|
||||
return PageResultFactory.createPageResult(sysRolePage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiGroupTreeWrapper> tree(ApiGroupRequest apiGroupRequest) {
|
||||
return this.createTree(this.peersTree(apiGroupRequest));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiGroupTreeWrapper> peersTree(ApiGroupRequest apiGroupRequest) {
|
||||
// 结果
|
||||
List<ApiGroupTreeWrapper> apiGroupTreeWrapperList = new ArrayList<>();
|
||||
|
||||
// 查询所有分组
|
||||
LambdaQueryWrapper<ApiGroup> wrapper = new LambdaQueryWrapper<>();
|
||||
if (ObjectUtil.isNotEmpty(apiGroupRequest.getGroupId())) {
|
||||
wrapper.notLike(ApiGroup::getGroupPids, SymbolConstant.LEFT_SQUARE_BRACKETS + apiGroupRequest.getGroupId() + SymbolConstant.RIGHT_SQUARE_BRACKETS);
|
||||
wrapper.ne(ApiGroup::getGroupId, apiGroupRequest.getGroupId());
|
||||
}
|
||||
List<ApiGroup> apiGroups = this.list(wrapper);
|
||||
|
||||
if (ObjectUtil.isNotEmpty(apiGroups)) {
|
||||
for (ApiGroup apiGroup : apiGroups) {
|
||||
ApiGroupTreeWrapper item = new ApiGroupTreeWrapper();
|
||||
item.setId(apiGroup.getGroupId());
|
||||
item.setPid(apiGroup.getGroupPid());
|
||||
item.setName(apiGroup.getGroupName());
|
||||
item.setType(NodeTypeEnums.LEAF_NODE.getType());
|
||||
item.setSort(apiGroup.getGroupSort());
|
||||
item.setData(apiGroup);
|
||||
item.setSlotsValue();
|
||||
apiGroupTreeWrapperList.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// 查询所有资源
|
||||
List<ApiResource> apiResourceList = this.apiResourceService.list();
|
||||
if (ObjectUtil.isNotEmpty(apiResourceList)) {
|
||||
for (ApiResource apiResource : apiResourceList) {
|
||||
ApiGroupTreeWrapper item = new ApiGroupTreeWrapper();
|
||||
item.setId(apiResource.getApiResourceId());
|
||||
item.setPid(apiResource.getGroupId());
|
||||
item.setName(apiResource.getApiAlias());
|
||||
item.setType(NodeTypeEnums.DATA_NODE.getType());
|
||||
item.setSort(apiResource.getResourceSort());
|
||||
item.setData(apiResource);
|
||||
item.setSlotsValue();
|
||||
apiGroupTreeWrapperList.add(item);
|
||||
}
|
||||
}
|
||||
return apiGroupTreeWrapperList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiGroup> findList(ApiGroupRequest apiGroupRequest) {
|
||||
LambdaQueryWrapper<ApiGroup> wrapper = this.createWrapper(apiGroupRequest);
|
||||
List<ApiGroup> apiGroupList = this.list(wrapper);
|
||||
return apiGroupList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
private ApiGroup queryApiGroup(ApiGroupRequest apiGroupRequest) {
|
||||
ApiGroup apiGroup = this.getById(apiGroupRequest.getGroupId());
|
||||
if (ObjectUtil.isEmpty(apiGroup)) {
|
||||
throw new SystemModularException(ApiGroupExceptionEnum.APIGROUP_NOT_EXISTED);
|
||||
}
|
||||
return apiGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建查询wrapper
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
private LambdaQueryWrapper<ApiGroup> createWrapper(ApiGroupRequest apiGroupRequest) {
|
||||
LambdaQueryWrapper<ApiGroup> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
Long groupId = apiGroupRequest.getGroupId();
|
||||
String groupName = apiGroupRequest.getGroupName();
|
||||
Long groupPid = apiGroupRequest.getGroupPid();
|
||||
String groupPids = apiGroupRequest.getGroupPids();
|
||||
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(groupId), ApiGroup::getGroupId, groupId);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(groupName), ApiGroup::getGroupName, groupName);
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(groupPid), ApiGroup::getGroupPid, groupPid);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(groupPids), ApiGroup::getGroupPids, groupPids);
|
||||
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新父ID集合
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/5/22 上午9:59
|
||||
**/
|
||||
private void setPids(ApiGroup apiGroup) {
|
||||
// 更新本节点的pids
|
||||
if (RuleConstants.TREE_ROOT_ID.equals(apiGroup.getGroupPid())) {
|
||||
// 顶级节点
|
||||
apiGroup.setGroupPids(SymbolConstant.LEFT_SQUARE_BRACKETS + RuleConstants.TREE_ROOT_ID + SymbolConstant.RIGHT_SQUARE_BRACKETS);
|
||||
} else {
|
||||
ApiGroup pApiGroup = this.getById(apiGroup.getGroupPid());
|
||||
apiGroup.setGroupPids(pApiGroup.getGroupPids() + SymbolConstant.COMMA + SymbolConstant.LEFT_SQUARE_BRACKETS + pApiGroup.getGroupId() + SymbolConstant.RIGHT_SQUARE_BRACKETS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改pids
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/5/22 上午9:59
|
||||
**/
|
||||
private void updatePids(ApiGroup apiGroup, ApiGroup oldApiGroup) {
|
||||
String oldPids = oldApiGroup.getGroupPids();
|
||||
oldPids = oldPids + SymbolConstant.COMMA + SymbolConstant.LEFT_SQUARE_BRACKETS + oldApiGroup.getGroupId() + SymbolConstant.RIGHT_SQUARE_BRACKETS;
|
||||
ParentIdsUpdateRequest parentIdsUpdateRequest = createParenIdsUpdateRequest(apiGroup.getGroupPids() + SymbolConstant.COMMA + SymbolConstant.LEFT_SQUARE_BRACKETS + apiGroup.getGroupId() + SymbolConstant.RIGHT_SQUARE_BRACKETS, oldPids);
|
||||
this.baseMapper.updateSubPids(parentIdsUpdateRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量修改pids的请求
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/26 12:19
|
||||
*/
|
||||
private static ParentIdsUpdateRequest createParenIdsUpdateRequest(String newParentIds, String oldParentIds) {
|
||||
ParentIdsUpdateRequest parentIdsUpdateRequest = new ParentIdsUpdateRequest();
|
||||
parentIdsUpdateRequest.setNewParentIds(newParentIds);
|
||||
parentIdsUpdateRequest.setOldParentIds(oldParentIds);
|
||||
parentIdsUpdateRequest.setUpdateTime(new Date());
|
||||
parentIdsUpdateRequest.setUpdateUser(LoginContext.me().getLoginUser().getUserId());
|
||||
return parentIdsUpdateRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建组装树结构
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/5/22 上午11:08
|
||||
**/
|
||||
private List<ApiGroupTreeWrapper> createTree(List<ApiGroupTreeWrapper> orgTrees) {
|
||||
// 根节点
|
||||
ApiGroupTreeWrapper root = null;
|
||||
|
||||
// 组装MAP
|
||||
Map<String, ApiGroupTreeWrapper> dataMap = new HashMap<>(orgTrees.size());
|
||||
for (ApiGroupTreeWrapper orgTree : orgTrees) {
|
||||
if (orgTree.getNodeParentId().equals(RuleConstants.TREE_ROOT_ID.toString())) {
|
||||
root = orgTree;
|
||||
}
|
||||
dataMap.put(orgTree.getNodeId(), orgTree);
|
||||
}
|
||||
|
||||
// 组装树形结构
|
||||
orgTrees.parallelStream().forEach(item -> {
|
||||
// 是root节点就跳过
|
||||
if (!RuleConstants.TREE_ROOT_ID.toString().equals(item.getNodeParentId())) {
|
||||
// 排序字段为空则填写一个默认值
|
||||
if (ObjectUtil.isEmpty(item.getSort())) {
|
||||
item.setSort(BigDecimal.valueOf(9999));
|
||||
}
|
||||
ApiGroupTreeWrapper orgTreeWrapper = dataMap.get(item.getNodeParentId());
|
||||
// 找到父节点再操作,找不到父节点,则丢掉该节点信息
|
||||
if (ObjectUtil.isNotEmpty(orgTreeWrapper)) {
|
||||
dataMap.get(item.getNodeParentId()).getChildren().add(item);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 对数据进行排序
|
||||
root.sortChildren();
|
||||
return Collections.singletonList(root);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException;
|
||||
import cn.stylefeng.roses.kernel.system.api.exception.enums.resource.ApiResourceFieldExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.resource.ApiResourceFieldRequest;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiResourceField;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.mapper.ApiResourceFieldMapper;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.service.ApiResourceFieldService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 接口字段信息业务实现层
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@Service
|
||||
public class ApiResourceFieldServiceImpl extends ServiceImpl<ApiResourceFieldMapper, ApiResourceField> implements ApiResourceFieldService {
|
||||
|
||||
@Override
|
||||
public void add(ApiResourceFieldRequest apiResourceFieldRequest) {
|
||||
ApiResourceField apiResourceField = new ApiResourceField();
|
||||
BeanUtil.copyProperties(apiResourceFieldRequest, apiResourceField);
|
||||
this.save(apiResourceField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void del(ApiResourceFieldRequest apiResourceFieldRequest) {
|
||||
ApiResourceField apiResourceField = this.queryApiResourceField(apiResourceFieldRequest);
|
||||
this.removeById(apiResourceField.getApiResourceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edit(ApiResourceFieldRequest apiResourceFieldRequest) {
|
||||
ApiResourceField apiResourceField = this.queryApiResourceField(apiResourceFieldRequest);
|
||||
BeanUtil.copyProperties(apiResourceFieldRequest, apiResourceField);
|
||||
this.updateById(apiResourceField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResourceField detail(ApiResourceFieldRequest apiResourceFieldRequest) {
|
||||
return this.queryApiResourceField(apiResourceFieldRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ApiResourceField> findPage(ApiResourceFieldRequest apiResourceFieldRequest) {
|
||||
LambdaQueryWrapper<ApiResourceField> wrapper = createWrapper(apiResourceFieldRequest);
|
||||
Page<ApiResourceField> sysRolePage = this.page(PageFactory.defaultPage(), wrapper);
|
||||
return PageResultFactory.createPageResult(sysRolePage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiResourceField> findList(ApiResourceFieldRequest apiResourceFieldRequest) {
|
||||
LambdaQueryWrapper<ApiResourceField> wrapper = this.createWrapper(apiResourceFieldRequest);
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
private ApiResourceField queryApiResourceField(ApiResourceFieldRequest apiResourceFieldRequest) {
|
||||
ApiResourceField apiResourceField = this.getById(apiResourceFieldRequest.getApiResourceId());
|
||||
if (ObjectUtil.isEmpty(apiResourceField)) {
|
||||
throw new SystemModularException(ApiResourceFieldExceptionEnum.APIRESOURCEFIELD_NOT_EXISTED);
|
||||
}
|
||||
return apiResourceField;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建查询wrapper
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
private LambdaQueryWrapper<ApiResourceField> createWrapper(ApiResourceFieldRequest apiResourceFieldRequest) {
|
||||
LambdaQueryWrapper<ApiResourceField> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
Long apiResourceId = apiResourceFieldRequest.getApiResourceId();
|
||||
String fieldLocation = apiResourceFieldRequest.getFieldLocation();
|
||||
String fieldName = apiResourceFieldRequest.getFieldName();
|
||||
String fieldCode = apiResourceFieldRequest.getFieldCode();
|
||||
String fieldType = apiResourceFieldRequest.getFieldType();
|
||||
String fieldRequired = apiResourceFieldRequest.getFieldRequired();
|
||||
String fieldValidationMsg = apiResourceFieldRequest.getFieldValidationMsg();
|
||||
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(apiResourceId), ApiResourceField::getApiResourceId, apiResourceId);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(fieldLocation), ApiResourceField::getFieldLocation, fieldLocation);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(fieldName), ApiResourceField::getFieldName, fieldName);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(fieldCode), ApiResourceField::getFieldCode, fieldCode);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(fieldType), ApiResourceField::getFieldType, fieldType);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(fieldRequired), ApiResourceField::getFieldRequired, fieldRequired);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(fieldValidationMsg), ApiResourceField::getFieldValidationMsg, fieldValidationMsg);
|
||||
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,388 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.SymbolConstant;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.pojo.resource.FieldMetadata;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.pojo.resource.ResourceDefinition;
|
||||
import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException;
|
||||
import cn.stylefeng.roses.kernel.system.api.exception.enums.resource.ApiResourceExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.resource.ApiResourceFieldRequest;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.resource.ApiResourceRequest;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiGroup;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiResourceField;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.SysResource;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.factory.ResourceFactory;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.mapper.ApiResourceMapper;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.service.ApiGroupService;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.service.ApiResourceFieldService;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.service.ApiResourceService;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.service.SysResourceService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 接口信息业务实现层
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
@Service
|
||||
public class ApiResourceServiceImpl extends ServiceImpl<ApiResourceMapper, ApiResource> implements ApiResourceService {
|
||||
|
||||
@Autowired
|
||||
private ApiGroupService apiGroupService;
|
||||
|
||||
@Autowired
|
||||
private SysResourceService sysResourceService;
|
||||
|
||||
@Autowired
|
||||
private ApiResourceFieldService apiResourceFieldService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void add(ApiResourceRequest apiResourceRequest) {
|
||||
// 如果选择的不是分组,就不允许操作
|
||||
ApiGroup apiGroup = this.apiGroupService.getById(apiResourceRequest.getGroupId());
|
||||
if (ObjectUtil.isEmpty(apiGroup)) {
|
||||
throw new SystemModularException(ApiResourceExceptionEnum.OPERATIONS_RESOURCE_NODESNOT_ALLOWED);
|
||||
}
|
||||
|
||||
List<SysResource> resourceList = new ArrayList<>();
|
||||
|
||||
// 根据资源CODE查询资源信息
|
||||
LambdaQueryWrapper<SysResource> sysResourceLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysResourceLambdaQueryWrapper.eq(SysResource::getResourceCode, apiResourceRequest.getResourceCode());
|
||||
SysResource sysResources = sysResourceService.getOne(sysResourceLambdaQueryWrapper);
|
||||
|
||||
// 如果是控制器名称,则查询模块下的所有资源
|
||||
if (!apiResourceRequest.getResourceCode().contains("$")) {
|
||||
sysResourceLambdaQueryWrapper.clear();
|
||||
sysResourceLambdaQueryWrapper.eq(SysResource::getModularCode, apiResourceRequest.getResourceCode());
|
||||
sysResourceLambdaQueryWrapper.eq(SysResource::getViewFlag, YesOrNotEnum.N.getCode());
|
||||
List<SysResource> sysResourceList = sysResourceService.list(sysResourceLambdaQueryWrapper);
|
||||
resourceList.addAll(sysResourceList);
|
||||
} else {
|
||||
resourceList.add(sysResources);
|
||||
}
|
||||
|
||||
// 默认生成排序
|
||||
BigDecimal index = BigDecimal.ZERO;
|
||||
|
||||
// 查询当前分组下面的排序最大值
|
||||
LambdaQueryWrapper<ApiResource> apiResourceLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
apiResourceLambdaQueryWrapper.eq(ApiResource::getGroupId, apiResourceRequest.getGroupId());
|
||||
apiResourceLambdaQueryWrapper.orderByDesc(ApiResource::getResourceSort);
|
||||
apiResourceLambdaQueryWrapper.last("LIMIT 1");
|
||||
ApiResource resource = this.getOne(apiResourceLambdaQueryWrapper);
|
||||
if (ObjectUtil.isNotEmpty(resource)) {
|
||||
index = resource.getResourceSort();
|
||||
}
|
||||
|
||||
// 处理所有资源
|
||||
for (SysResource sysResource : resourceList) {
|
||||
// 转换对象
|
||||
ApiResource apiResource = BeanUtil.toBean(apiResourceRequest, ApiResource.class);
|
||||
|
||||
// 设置请求方式
|
||||
apiResource.setRequestMethod(sysResource.getHttpMethod());
|
||||
|
||||
// 设置资源名称
|
||||
apiResource.setApiAlias(sysResource.getResourceName());
|
||||
|
||||
// 设置资源code
|
||||
apiResource.setResourceCode(sysResource.getResourceCode());
|
||||
|
||||
// 设置排序
|
||||
if (ObjectUtil.isNotEmpty(apiResourceRequest.getResourceSort())) {
|
||||
index = index.add(BigDecimal.ONE);
|
||||
apiResource.setResourceSort(index);
|
||||
}
|
||||
|
||||
// 保存数据
|
||||
this.save(apiResource);
|
||||
|
||||
// 获取参数
|
||||
ResourceDefinition fillResourceDetail = ResourceFactory.fillResourceDetail(ResourceFactory.createResourceDefinition(sysResource));
|
||||
|
||||
// 所有字段集合
|
||||
List<ApiResourceField> apiResourceFieldList = new ArrayList<>();
|
||||
|
||||
// 处理所有请求字段
|
||||
if (ObjectUtil.isNotEmpty(fillResourceDetail.getParamFieldDescriptions())) {
|
||||
for (FieldMetadata fieldMetadata : fillResourceDetail.getParamFieldDescriptions()) {
|
||||
ApiResourceField conversion = this.conversion(apiResource.getApiResourceId(), fieldMetadata);
|
||||
conversion.setFieldLocation("request");
|
||||
apiResourceFieldList.add(conversion);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理所有响应字段
|
||||
if (ObjectUtil.isNotEmpty(fillResourceDetail.getResponseFieldDescriptions())) {
|
||||
for (FieldMetadata fieldDescription : fillResourceDetail.getResponseFieldDescriptions()) {
|
||||
ApiResourceField conversion = this.conversion(apiResource.getApiResourceId(), fieldDescription);
|
||||
conversion.setFieldLocation("response");
|
||||
apiResourceFieldList.add(conversion);
|
||||
}
|
||||
}
|
||||
|
||||
// 保存
|
||||
if (ObjectUtil.isNotEmpty(apiResourceFieldList)) {
|
||||
this.apiResourceFieldService.saveBatch(apiResourceFieldList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void del(ApiResourceRequest apiResourceRequest) {
|
||||
ApiResource apiResource = this.queryApiResource(apiResourceRequest);
|
||||
this.removeById(apiResource.getApiResourceId());
|
||||
|
||||
// 删除所有字段信息
|
||||
LambdaQueryWrapper<ApiResourceField> apiResourceFieldLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
apiResourceFieldLambdaQueryWrapper.eq(ApiResourceField::getApiResourceId, apiResource.getApiResourceId());
|
||||
this.apiResourceFieldService.remove(apiResourceFieldLambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edit(ApiResourceRequest apiResourceRequest) {
|
||||
|
||||
// 查询旧数据
|
||||
ApiResource apiResource = this.queryApiResource(apiResourceRequest);
|
||||
|
||||
// 如果选择的不是分组,就不允许操作
|
||||
ApiGroup apiGroup = this.apiGroupService.getById(apiResource.getGroupId());
|
||||
if (ObjectUtil.isEmpty(apiGroup)) {
|
||||
throw new SystemModularException(ApiResourceExceptionEnum.OPERATIONS_RESOURCE_NODESNOT_ALLOWED);
|
||||
}
|
||||
|
||||
// 更新接口资源数据
|
||||
BeanUtil.copyProperties(apiResourceRequest, apiResource);
|
||||
this.updateById(apiResource);
|
||||
|
||||
// 删除所有的字段数据
|
||||
LambdaQueryWrapper<ApiResourceField> fieldLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
fieldLambdaQueryWrapper.eq(ApiResourceField::getApiResourceId, apiResource.getApiResourceId());
|
||||
this.apiResourceFieldService.remove(fieldLambdaQueryWrapper);
|
||||
|
||||
// 添加新的字段信息
|
||||
List<ApiResourceFieldRequest> apiResourceFieldRequestList = apiResourceRequest.getApiResourceFieldRequestList();
|
||||
if (ObjectUtil.isNotEmpty(apiResourceFieldRequestList)) {
|
||||
List<ApiResourceField> apiResourceFields = apiResourceFieldRequestList.stream().map(item -> {
|
||||
ApiResourceField apiResourceField = BeanUtil.toBean(item, ApiResourceField.class);
|
||||
apiResourceField.setApiResourceId(apiResource.getApiResourceId());
|
||||
return apiResourceField;
|
||||
}).collect(Collectors.toList());
|
||||
this.apiResourceFieldService.saveBatch(apiResourceFields);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResource detail(ApiResourceRequest apiResourceRequest) {
|
||||
ApiResource apiResource = this.queryApiResource(apiResourceRequest);
|
||||
|
||||
// 查询所有字段信息
|
||||
LambdaQueryWrapper<ApiResourceField> apiResourceFieldLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
apiResourceFieldLambdaQueryWrapper.eq(ApiResourceField::getApiResourceId, apiResource.getApiResourceId());
|
||||
List<ApiResourceField> apiResourceFields = this.apiResourceFieldService.list(apiResourceFieldLambdaQueryWrapper);
|
||||
// 过滤创建时间和创建人
|
||||
apiResourceFields.removeIf(resourceField -> "createTime".equalsIgnoreCase(resourceField.getFieldCode()) || "createUser".equalsIgnoreCase(resourceField.getFieldCode()) || "updateTime".equalsIgnoreCase(resourceField.getFieldCode()) || "updateUser".equalsIgnoreCase(resourceField.getFieldCode()));
|
||||
apiResource.setApiResourceFieldList(apiResourceFields);
|
||||
|
||||
return apiResource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ApiResource> findPage(ApiResourceRequest apiResourceRequest) {
|
||||
LambdaQueryWrapper<ApiResource> wrapper = createWrapper(apiResourceRequest);
|
||||
Page<ApiResource> sysRolePage = this.page(PageFactory.defaultPage(), wrapper);
|
||||
return PageResultFactory.createPageResult(sysRolePage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResource record(ApiResourceRequest apiResourceRequest) {
|
||||
ApiResource apiResource = BeanUtil.toBean(apiResourceRequest, ApiResource.class);
|
||||
|
||||
String resultBody = null;
|
||||
|
||||
try {
|
||||
// 请求对象
|
||||
HttpRequest httpRequest;
|
||||
|
||||
// 判断请求方式
|
||||
if (RequestMethod.GET.toString().equalsIgnoreCase(apiResourceRequest.getRequestMethod())) {
|
||||
httpRequest = HttpRequest.get(apiResourceRequest.getRequestUrl());
|
||||
// 处理参数
|
||||
JSONObject jsonObject = JSONObject.parseObject(apiResourceRequest.getLastRequestContent());
|
||||
for (Map.Entry<String, Object> stringObjectEntry : jsonObject.entrySet()) {
|
||||
httpRequest.form(stringObjectEntry.getKey(), stringObjectEntry.getValue());
|
||||
}
|
||||
} else {
|
||||
httpRequest = HttpRequest.post(apiResourceRequest.getRequestUrl()).body(apiResourceRequest.getLastRequestContent());
|
||||
}
|
||||
|
||||
// 请求头处理
|
||||
if (ObjectUtil.isNotEmpty(apiResourceRequest.getLastRequestHeader())) {
|
||||
for (Map.Entry<String, String> stringStringEntry : apiResourceRequest.getLastRequestHeader().entrySet()) {
|
||||
String[] values = stringStringEntry.getValue().split(SymbolConstant.COMMA);
|
||||
for (String value : values) {
|
||||
httpRequest.header(stringStringEntry.getKey(), value, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
resultBody = httpRequest.timeout(15000).execute().body();
|
||||
|
||||
} catch (Exception e) {
|
||||
resultBody = ExceptionUtil.stacktraceToString(e, 10000);
|
||||
} finally {
|
||||
// 请求头处理
|
||||
if (ObjectUtil.isNotEmpty(apiResourceRequest.getLastRequestHeader())) {
|
||||
apiResource.setLastRequestHeader(JSON.toJSONString(apiResourceRequest.getLastRequestHeader()));
|
||||
}
|
||||
apiResource.setLastResponseContent(resultBody);
|
||||
this.updateById(apiResource);
|
||||
}
|
||||
return apiResource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiResourceField> allField(ApiResourceRequest apiResourceRequest) {
|
||||
LambdaQueryWrapper<SysResource> sysResourceLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysResourceLambdaQueryWrapper.eq(SysResource::getResourceCode, apiResourceRequest.getResourceCode());
|
||||
SysResource sysResources = sysResourceService.getOne(sysResourceLambdaQueryWrapper);
|
||||
|
||||
// 获取参数
|
||||
ResourceDefinition fillResourceDetail = ResourceFactory.fillResourceDetail(ResourceFactory.createResourceDefinition(sysResources));
|
||||
|
||||
// 把所有字段加进去
|
||||
List<ApiResourceField> apiResourceFieldList = new ArrayList<>();
|
||||
if (ObjectUtil.isNotEmpty(fillResourceDetail.getParamFieldDescriptions())) {
|
||||
// 处理所有请求字段
|
||||
for (FieldMetadata fieldMetadata : fillResourceDetail.getParamFieldDescriptions()) {
|
||||
ApiResourceField conversion = this.conversion(null, fieldMetadata);
|
||||
conversion.setFieldLocation("request");
|
||||
apiResourceFieldList.add(conversion);
|
||||
}
|
||||
|
||||
// 处理所有响应字段
|
||||
for (FieldMetadata fieldDescription : fillResourceDetail.getResponseFieldDescriptions()) {
|
||||
ApiResourceField conversion = this.conversion(null, fieldDescription);
|
||||
conversion.setFieldLocation("response");
|
||||
apiResourceFieldList.add(conversion);
|
||||
}
|
||||
}
|
||||
return apiResourceFieldList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiResource> findList(ApiResourceRequest apiResourceRequest) {
|
||||
LambdaQueryWrapper<ApiResource> wrapper = this.createWrapper(apiResourceRequest);
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
private ApiResource queryApiResource(ApiResourceRequest apiResourceRequest) {
|
||||
ApiResource apiResource = this.getById(apiResourceRequest.getApiResourceId());
|
||||
if (ObjectUtil.isEmpty(apiResource)) {
|
||||
throw new SystemModularException(ApiResourceExceptionEnum.APIRESOURCE_NOT_EXISTED);
|
||||
}
|
||||
return apiResource;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建查询wrapper
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/05/21 15:03
|
||||
*/
|
||||
private LambdaQueryWrapper<ApiResource> createWrapper(ApiResourceRequest apiResourceRequest) {
|
||||
LambdaQueryWrapper<ApiResource> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
Long apiResourceId = apiResourceRequest.getApiResourceId();
|
||||
Long groupId = apiResourceRequest.getGroupId();
|
||||
String apiAlias = apiResourceRequest.getApiAlias();
|
||||
String resourceCode = apiResourceRequest.getResourceCode();
|
||||
String lastRequestContent = apiResourceRequest.getLastRequestContent();
|
||||
String lastResponseContent = apiResourceRequest.getLastResponseContent();
|
||||
BigDecimal resourceSort = apiResourceRequest.getResourceSort();
|
||||
String createTime = apiResourceRequest.getCreateTime();
|
||||
Long createUser = apiResourceRequest.getCreateUser();
|
||||
String updateTime = apiResourceRequest.getUpdateTime();
|
||||
Long updateUser = apiResourceRequest.getUpdateUser();
|
||||
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(apiResourceId), ApiResource::getApiResourceId, apiResourceId);
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(groupId), ApiResource::getGroupId, groupId);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(apiAlias), ApiResource::getApiAlias, apiAlias);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(resourceCode), ApiResource::getResourceCode, resourceCode);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(lastRequestContent), ApiResource::getLastRequestContent, lastRequestContent);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(lastResponseContent), ApiResource::getLastResponseContent, lastResponseContent);
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(resourceSort), ApiResource::getResourceSort, resourceSort);
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(createTime), ApiResource::getCreateTime, createTime);
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(createUser), ApiResource::getCreateUser, createUser);
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(updateTime), ApiResource::getUpdateTime, updateTime);
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(updateUser), ApiResource::getUpdateUser, updateUser);
|
||||
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换
|
||||
*
|
||||
* @return {@link ApiResourceField}
|
||||
* @author majianguo
|
||||
* @date 2021/5/22 下午2:44
|
||||
**/
|
||||
private ApiResourceField conversion(Long apiResourceId, FieldMetadata fieldMetadata) {
|
||||
ApiResourceField item = new ApiResourceField();
|
||||
item.setApiResourceId(apiResourceId);
|
||||
item.setFieldCode(fieldMetadata.getFieldName());
|
||||
item.setFieldName(fieldMetadata.getChineseName());
|
||||
if ("file".equalsIgnoreCase(fieldMetadata.getFieldClassType())) {
|
||||
item.setFieldType("file");
|
||||
} else {
|
||||
item.setFieldType("string");
|
||||
}
|
||||
|
||||
// 是否必填
|
||||
Set<String> annotations = fieldMetadata.getAnnotations();
|
||||
if (ObjectUtil.isNotEmpty(annotations)) {
|
||||
for (String annotationName : annotations) {
|
||||
if ("NotBlank".equalsIgnoreCase(annotationName) || "NotNull".equalsIgnoreCase(annotationName)) {
|
||||
item.setFieldRequired(YesOrNotEnum.Y.getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
item.setFieldValidationMsg(fieldMetadata.getValidationMessages());
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
|
@ -222,7 +222,7 @@ public class SysUserController {
|
|||
* @date 2021/1/15 8:28
|
||||
*/
|
||||
@GetResource(name = "获取用户选择树数据(用在系统通知,选择发送人的时候)", path = "/sysUser/getUserSelectTree")
|
||||
public SuccessResponseData getUserTree() {
|
||||
public ResponseData getUserTree() {
|
||||
return new SuccessResponseData(this.sysUserService.userSelectTree(new SysUserRequest()));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue