wiki编辑器升级,api接口文档开发
This commit is contained in:
@@ -0,0 +1,172 @@
|
||||
package com.zyplayer.doc.data.repository.manage.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 自建接口文档节点
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2022-01-29
|
||||
*/
|
||||
@TableName("api_custom_node")
|
||||
public class ApiCustomNode implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键自增ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* api_doc主键ID
|
||||
*/
|
||||
private Long docId;
|
||||
|
||||
/**
|
||||
* 父文件夹ID
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 节点类型 0=目录 1=接口
|
||||
*/
|
||||
private Integer nodeType;
|
||||
|
||||
/**
|
||||
* 节点名称
|
||||
*/
|
||||
private String nodeName;
|
||||
|
||||
/**
|
||||
* 节点说明
|
||||
*/
|
||||
private String nodeDesc;
|
||||
|
||||
/**
|
||||
* 节点顺序
|
||||
*/
|
||||
private Integer seqNo;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
private Long createUserId;
|
||||
|
||||
/**
|
||||
* 创建人名字
|
||||
*/
|
||||
private String createUserName;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 是否有效 0=无效 1=有效
|
||||
*/
|
||||
private Integer yn;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public Long getDocId() {
|
||||
return docId;
|
||||
}
|
||||
|
||||
public void setDocId(Long docId) {
|
||||
this.docId = docId;
|
||||
}
|
||||
public Long getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public void setParentId(Long parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
public Integer getNodeType() {
|
||||
return nodeType;
|
||||
}
|
||||
|
||||
public void setNodeType(Integer nodeType) {
|
||||
this.nodeType = nodeType;
|
||||
}
|
||||
public String getNodeName() {
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
public void setNodeName(String nodeName) {
|
||||
this.nodeName = nodeName;
|
||||
}
|
||||
public String getNodeDesc() {
|
||||
return nodeDesc;
|
||||
}
|
||||
|
||||
public void setNodeDesc(String nodeDesc) {
|
||||
this.nodeDesc = nodeDesc;
|
||||
}
|
||||
public Integer getSeqNo() {
|
||||
return seqNo;
|
||||
}
|
||||
|
||||
public void setSeqNo(Integer seqNo) {
|
||||
this.seqNo = seqNo;
|
||||
}
|
||||
public Long getCreateUserId() {
|
||||
return createUserId;
|
||||
}
|
||||
|
||||
public void setCreateUserId(Long createUserId) {
|
||||
this.createUserId = createUserId;
|
||||
}
|
||||
public String getCreateUserName() {
|
||||
return createUserName;
|
||||
}
|
||||
|
||||
public void setCreateUserName(String createUserName) {
|
||||
this.createUserName = createUserName;
|
||||
}
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
public Integer getYn() {
|
||||
return yn;
|
||||
}
|
||||
|
||||
public void setYn(Integer yn) {
|
||||
this.yn = yn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ApiCustomNode{" +
|
||||
"id=" + id +
|
||||
", docId=" + docId +
|
||||
", parentId=" + parentId +
|
||||
", nodeType=" + nodeType +
|
||||
", nodeName=" + nodeName +
|
||||
", nodeDesc=" + nodeDesc +
|
||||
", seqNo=" + seqNo +
|
||||
", createUserId=" + createUserId +
|
||||
", createUserName=" + createUserName +
|
||||
", createTime=" + createTime +
|
||||
", yn=" + yn +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
package com.zyplayer.doc.data.repository.manage.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 自建接口文档
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2022-01-29
|
||||
*/
|
||||
@TableName("api_custom_params")
|
||||
public class ApiCustomParams implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键自增ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* api_doc主键ID
|
||||
*/
|
||||
private Long docId;
|
||||
|
||||
/**
|
||||
* 节点ID
|
||||
*/
|
||||
private Long nodeId;
|
||||
|
||||
/**
|
||||
* 请求方式:get、head、post、put、patch、delete、options、trace
|
||||
*/
|
||||
private String method;
|
||||
|
||||
/**
|
||||
* 接口url
|
||||
*/
|
||||
private String apiUrl;
|
||||
|
||||
/**
|
||||
* form参数
|
||||
*/
|
||||
private String formData;
|
||||
|
||||
/**
|
||||
* body参数
|
||||
*/
|
||||
private String bodyData;
|
||||
|
||||
/**
|
||||
* header参数
|
||||
*/
|
||||
private String headerData;
|
||||
|
||||
/**
|
||||
* cookie参数
|
||||
*/
|
||||
private String cookieData;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
private Long createUserId;
|
||||
|
||||
/**
|
||||
* 创建人名字
|
||||
*/
|
||||
private String createUserName;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 是否有效 0=无效 1=有效
|
||||
*/
|
||||
private Integer yn;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public Long getDocId() {
|
||||
return docId;
|
||||
}
|
||||
|
||||
public void setDocId(Long docId) {
|
||||
this.docId = docId;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
public String getApiUrl() {
|
||||
return apiUrl;
|
||||
}
|
||||
|
||||
public void setApiUrl(String apiUrl) {
|
||||
this.apiUrl = apiUrl;
|
||||
}
|
||||
public String getFormData() {
|
||||
return formData;
|
||||
}
|
||||
|
||||
public void setFormData(String formData) {
|
||||
this.formData = formData;
|
||||
}
|
||||
public String getBodyData() {
|
||||
return bodyData;
|
||||
}
|
||||
|
||||
public void setBodyData(String bodyData) {
|
||||
this.bodyData = bodyData;
|
||||
}
|
||||
public String getHeaderData() {
|
||||
return headerData;
|
||||
}
|
||||
|
||||
public void setHeaderData(String headerData) {
|
||||
this.headerData = headerData;
|
||||
}
|
||||
public String getCookieData() {
|
||||
return cookieData;
|
||||
}
|
||||
|
||||
public void setCookieData(String cookieData) {
|
||||
this.cookieData = cookieData;
|
||||
}
|
||||
public Long getCreateUserId() {
|
||||
return createUserId;
|
||||
}
|
||||
|
||||
public void setCreateUserId(Long createUserId) {
|
||||
this.createUserId = createUserId;
|
||||
}
|
||||
public String getCreateUserName() {
|
||||
return createUserName;
|
||||
}
|
||||
|
||||
public void setCreateUserName(String createUserName) {
|
||||
this.createUserName = createUserName;
|
||||
}
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
public Integer getYn() {
|
||||
return yn;
|
||||
}
|
||||
|
||||
public void setYn(Integer yn) {
|
||||
this.yn = yn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ApiCustomParams{" +
|
||||
"id=" + id +
|
||||
", docId=" + docId +
|
||||
", nodeId=" + nodeId +
|
||||
", method=" + method +
|
||||
", apiUrl=" + apiUrl +
|
||||
", formData=" + formData +
|
||||
", bodyData=" + bodyData +
|
||||
", headerData=" + headerData +
|
||||
", cookieData=" + cookieData +
|
||||
", createUserId=" + createUserId +
|
||||
", createUserName=" + createUserName +
|
||||
", createTime=" + createTime +
|
||||
", yn=" + yn +
|
||||
"}";
|
||||
}
|
||||
|
||||
public Long getNodeId() {
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
public void setNodeId(Long nodeId) {
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.zyplayer.doc.data.repository.manage.mapper;
|
||||
|
||||
import com.zyplayer.doc.data.repository.manage.entity.ApiCustomNode;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 自建接口文档节点 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2022-01-29
|
||||
*/
|
||||
public interface ApiCustomNodeMapper extends BaseMapper<ApiCustomNode> {
|
||||
|
||||
@Update("update api_custom_node set seq_no=seq_no + 1 where parent_id=#{parentId} and seq_no >= #{targetSeq} and yn=1")
|
||||
void updateAfterSeq(@Param("parentId") Long parentId, @Param("targetSeq") Integer targetSeq);
|
||||
|
||||
@Select("select max(seq_no) from api_custom_node where parent_id=#{parentId} and yn=1")
|
||||
Integer getLastSeq(@Param("parentId") Long parentId);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zyplayer.doc.data.repository.manage.mapper;
|
||||
|
||||
import com.zyplayer.doc.data.repository.manage.entity.ApiCustomParams;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 自建接口文档 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2022-01-29
|
||||
*/
|
||||
public interface ApiCustomParamsMapper extends BaseMapper<ApiCustomParams> {
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.zyplayer.doc.data.repository.manage.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* api自建文档信息
|
||||
@@ -13,19 +14,24 @@ public class ApiCustomDocVo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 接口ID
|
||||
* 节点类型 0=目录 1=接口
|
||||
*/
|
||||
private Long requestId;
|
||||
private Integer nodeType;
|
||||
|
||||
/**
|
||||
* 文件夹ID
|
||||
* 接口ID
|
||||
*/
|
||||
private Long folderId;
|
||||
private Long nodeId;
|
||||
|
||||
/**
|
||||
* 接口名称
|
||||
*/
|
||||
private String apiName;
|
||||
private String nodeName;
|
||||
|
||||
/**
|
||||
* 接口说明
|
||||
*/
|
||||
private String nodeDesc;
|
||||
|
||||
/**
|
||||
* 请求方式:get、head、post、put、patch、delete、options、trace
|
||||
@@ -57,13 +63,10 @@ public class ApiCustomDocVo implements Serializable {
|
||||
*/
|
||||
private String cookieData;
|
||||
|
||||
public String getApiName() {
|
||||
return apiName;
|
||||
}
|
||||
|
||||
public void setApiName(String apiName) {
|
||||
this.apiName = apiName;
|
||||
}
|
||||
/**
|
||||
* 子目录列表
|
||||
*/
|
||||
private List<ApiCustomDocVo> children;
|
||||
|
||||
public String getApiUrl() {
|
||||
return apiUrl;
|
||||
@@ -113,19 +116,43 @@ public class ApiCustomDocVo implements Serializable {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public Long getRequestId() {
|
||||
return requestId;
|
||||
public Long getNodeId() {
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
public void setRequestId(Long requestId) {
|
||||
this.requestId = requestId;
|
||||
public void setNodeId(Long nodeId) {
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
|
||||
public Long getFolderId() {
|
||||
return folderId;
|
||||
public String getNodeName() {
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
public void setFolderId(Long folderId) {
|
||||
this.folderId = folderId;
|
||||
public void setNodeName(String nodeName) {
|
||||
this.nodeName = nodeName;
|
||||
}
|
||||
|
||||
public List<ApiCustomDocVo> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<ApiCustomDocVo> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public String getNodeDesc() {
|
||||
return nodeDesc;
|
||||
}
|
||||
|
||||
public void setNodeDesc(String nodeDesc) {
|
||||
this.nodeDesc = nodeDesc;
|
||||
}
|
||||
|
||||
public Integer getNodeType() {
|
||||
return nodeType;
|
||||
}
|
||||
|
||||
public void setNodeType(Integer nodeType) {
|
||||
this.nodeType = nodeType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ public class ApiCustomVo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 文件夹ID
|
||||
* 节点ID
|
||||
*/
|
||||
private Long folderId;
|
||||
private Long nodeId;
|
||||
|
||||
/**
|
||||
* 文件夹名称
|
||||
@@ -70,11 +70,11 @@ public class ApiCustomVo implements Serializable {
|
||||
this.apis = apis;
|
||||
}
|
||||
|
||||
public Long getFolderId() {
|
||||
return folderId;
|
||||
public Long getNodeId() {
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
public void setFolderId(Long folderId) {
|
||||
this.folderId = folderId;
|
||||
public void setNodeId(Long nodeId) {
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.Collections;
|
||||
public class CodeGenerator {
|
||||
|
||||
public static void main(String[] args) {
|
||||
final String[] tableName = {"api_custom_request", "api_custom_folder"};
|
||||
final String[] tableName = {"api_custom_node", "api_custom_params"};
|
||||
String url = "jdbc:mysql://127.0.0.1:3306/zyplayer_doc_manage?useUnicode=true&useSSL=false&characterEncoding=utf8";
|
||||
String projectPath = System.getProperty("user.dir") + "/zyplayer-doc-data";
|
||||
String outputDir = projectPath + "/src/main/java";
|
||||
|
||||
@@ -21,4 +21,12 @@ public interface ApiCustomFolderService extends IService<ApiCustomFolder> {
|
||||
* @since 2021-12-22
|
||||
*/
|
||||
void addFolder(ApiCustomFolder apiCustomFolder);
|
||||
|
||||
/**
|
||||
* 删除文件夹
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2021-12-22
|
||||
*/
|
||||
void deleteFolder(Long id);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.zyplayer.doc.data.service.manage;
|
||||
|
||||
import com.zyplayer.doc.data.repository.manage.entity.ApiCustomNode;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.ApiCustomParams;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.ApiDoc;
|
||||
import com.zyplayer.doc.data.repository.manage.vo.ApiCustomDocVo;
|
||||
import com.zyplayer.doc.data.repository.manage.vo.ApiCustomVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 自建接口文档节点 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2022-01-29
|
||||
*/
|
||||
public interface ApiCustomNodeService extends IService<ApiCustomNode> {
|
||||
|
||||
/**
|
||||
* 增加文件夹
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2021-12-22
|
||||
*/
|
||||
void addNode(ApiCustomNode apiCustomNode, ApiCustomParams apiCustomParams);
|
||||
|
||||
/**
|
||||
* 删除文件夹
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2021-12-22
|
||||
*/
|
||||
void deleteNode(Long id);
|
||||
|
||||
/**
|
||||
* 修改父节点
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2021-12-22
|
||||
*/
|
||||
void changeParent(Long id, Long parentId, Integer targetType, Integer targetSeq);
|
||||
|
||||
/**
|
||||
* 构建目录树
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2021-12-22
|
||||
*/
|
||||
List<ApiCustomDocVo> buildCustomApiList(ApiDoc apiDoc);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zyplayer.doc.data.service.manage;
|
||||
|
||||
import com.zyplayer.doc.data.repository.manage.entity.ApiCustomParams;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 自建接口文档 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2022-01-29
|
||||
*/
|
||||
public interface ApiCustomParamsService extends IService<ApiCustomParams> {
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.zyplayer.doc.data.service.manage.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||
@@ -7,10 +9,13 @@ import com.zyplayer.doc.data.repository.manage.entity.ApiCustomFolder;
|
||||
import com.zyplayer.doc.data.repository.manage.mapper.ApiCustomFolderMapper;
|
||||
import com.zyplayer.doc.data.service.common.ApiDocAuthJudgeService;
|
||||
import com.zyplayer.doc.data.service.manage.ApiCustomFolderService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -42,4 +47,40 @@ public class ApiCustomFolderServiceImpl extends ServiceImpl<ApiCustomFolderMappe
|
||||
}
|
||||
this.saveOrUpdate(apiCustomFolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFolder(Long id) {
|
||||
this.deleteFolderRecursion(id);
|
||||
// 逻辑删除
|
||||
ApiCustomFolder folderDel = new ApiCustomFolder();
|
||||
folderDel.setId(id);
|
||||
folderDel.setYn(0);
|
||||
this.updateById(folderDel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归删除下级
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2021-12-22
|
||||
*/
|
||||
public void deleteFolderRecursion(Long id) {
|
||||
QueryWrapper<ApiCustomFolder> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("yn", 1);
|
||||
wrapper.eq("parent_folder_id", id);
|
||||
List<ApiCustomFolder> childrenList = this.list(wrapper);
|
||||
if (CollectionUtils.isNotEmpty(childrenList)) {
|
||||
for (ApiCustomFolder folder : childrenList) {
|
||||
// 递归删除下级
|
||||
this.deleteFolderRecursion(folder.getId());
|
||||
}
|
||||
// 逻辑删除
|
||||
ApiCustomFolder folderDel = new ApiCustomFolder();
|
||||
folderDel.setYn(0);
|
||||
QueryWrapper<ApiCustomFolder> wrapperDel = new QueryWrapper<>();
|
||||
wrapperDel.in("id", childrenList.stream().map(ApiCustomFolder::getId).collect(Collectors.toSet()));
|
||||
this.update(folderDel, wrapperDel);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
package com.zyplayer.doc.data.service.manage.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.*;
|
||||
import com.zyplayer.doc.data.repository.manage.mapper.ApiCustomNodeMapper;
|
||||
import com.zyplayer.doc.data.repository.manage.vo.ApiCustomDocVo;
|
||||
import com.zyplayer.doc.data.repository.manage.vo.ApiCustomVo;
|
||||
import com.zyplayer.doc.data.service.common.ApiDocAuthJudgeService;
|
||||
import com.zyplayer.doc.data.service.manage.ApiCustomNodeService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zyplayer.doc.data.service.manage.ApiCustomParamsService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 自建接口文档节点 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2022-01-29
|
||||
*/
|
||||
@Service
|
||||
public class ApiCustomNodeServiceImpl extends ServiceImpl<ApiCustomNodeMapper, ApiCustomNode> implements ApiCustomNodeService {
|
||||
|
||||
@Resource
|
||||
ApiDocAuthJudgeService apiDocAuthJudgeService;
|
||||
@Resource
|
||||
ApiCustomNodeMapper apiCustomNodeMapper;
|
||||
@Resource
|
||||
ApiCustomParamsService apiCustomParamsService;
|
||||
|
||||
@Override
|
||||
public void addNode(ApiCustomNode apiCustomFolder, ApiCustomParams apiCustomParams) {
|
||||
apiDocAuthJudgeService.judgeDevelopAndThrow(apiCustomFolder.getDocId());
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
Long parentId = Optional.ofNullable(apiCustomFolder.getParentId()).orElse(0L);
|
||||
apiCustomFolder.setParentId(parentId);
|
||||
if (apiCustomFolder.getId() == null) {
|
||||
apiCustomFolder.setYn(1);
|
||||
apiCustomFolder.setCreateTime(new Date());
|
||||
apiCustomFolder.setCreateUserId(currentUser.getUserId());
|
||||
apiCustomFolder.setCreateUserName(currentUser.getUsername());
|
||||
// 修改顺序值,新增放最后
|
||||
Integer lastSeq = apiCustomNodeMapper.getLastSeq(parentId);
|
||||
lastSeq = Optional.ofNullable(lastSeq).orElse(0);
|
||||
apiCustomFolder.setSeqNo(lastSeq + 1);
|
||||
} else {
|
||||
apiCustomFolder.setCreateTime(null);
|
||||
apiCustomFolder.setCreateUserId(null);
|
||||
apiCustomFolder.setCreateUserName(null);
|
||||
}
|
||||
this.saveOrUpdate(apiCustomFolder);
|
||||
// 保存参数
|
||||
if (Objects.equals(apiCustomFolder.getNodeType(), 1)) {
|
||||
apiCustomParams.setNodeId(apiCustomFolder.getId());
|
||||
QueryWrapper<ApiCustomParams> nodeParamsWrapper = new QueryWrapper<>();
|
||||
nodeParamsWrapper.eq("node_id", apiCustomFolder.getId());
|
||||
ApiCustomParams customParams = apiCustomParamsService.getOne(nodeParamsWrapper);
|
||||
if (customParams != null) {
|
||||
apiCustomParams.setId(customParams.getId());
|
||||
}
|
||||
apiCustomParams.setYn(1);
|
||||
apiCustomParamsService.saveOrUpdate(apiCustomParams);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteNode(Long id) {
|
||||
Set<Long> deleteNodeIds = new HashSet<>();
|
||||
deleteNodeIds.add(id);
|
||||
this.getAllChildNodeId(deleteNodeIds, id);
|
||||
// 删除所有节点
|
||||
ApiCustomNode nodeDel = new ApiCustomNode();
|
||||
nodeDel.setYn(0);
|
||||
QueryWrapper<ApiCustomNode> nodeDelWrapper = new QueryWrapper<>();
|
||||
nodeDelWrapper.in("id", deleteNodeIds);
|
||||
this.update(nodeDel, nodeDelWrapper);
|
||||
// 删除所有参数
|
||||
ApiCustomParams nodeParamsDel = new ApiCustomParams();
|
||||
nodeParamsDel.setYn(0);
|
||||
QueryWrapper<ApiCustomParams> nodeParamsDelWrapper = new QueryWrapper<>();
|
||||
nodeParamsDelWrapper.in("node_id", deleteNodeIds);
|
||||
apiCustomParamsService.update(nodeParamsDel, nodeParamsDelWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeParent(Long id, Long parentId, Integer targetType, Integer targetSeq) {
|
||||
parentId = Optional.ofNullable(parentId).orElse(0L);
|
||||
ApiCustomNode apiCustomNode = new ApiCustomNode();
|
||||
apiCustomNode.setId(id);
|
||||
if (Objects.equals(targetType, 1)) {
|
||||
// 放入选中元素的后面
|
||||
if (parentId > 0) {
|
||||
ApiCustomNode customNodeSel = this.getById(parentId);
|
||||
apiCustomNode.setSeqNo(customNodeSel.getSeqNo() + 1);
|
||||
Long targetParentId = Optional.ofNullable(customNodeSel.getParentId()).orElse(0L);
|
||||
apiCustomNode.setParentId(targetParentId);
|
||||
apiCustomNodeMapper.updateAfterSeq(targetParentId, apiCustomNode.getSeqNo());
|
||||
} else {
|
||||
Integer lastSeq = apiCustomNodeMapper.getLastSeq(0L);
|
||||
lastSeq = Optional.ofNullable(lastSeq).orElse(0);
|
||||
apiCustomNode.setParentId(0L);
|
||||
apiCustomNode.setSeqNo(lastSeq + 1);
|
||||
}
|
||||
} else {
|
||||
// 放入选中元素的最前面
|
||||
ApiCustomNode customNodeSel = this.getById(parentId);
|
||||
// 目录才能移到里面去
|
||||
if (customNodeSel == null || Objects.equals(customNodeSel.getNodeType(), 0)) {
|
||||
apiCustomNode.setSeqNo(1);
|
||||
apiCustomNode.setParentId(parentId);
|
||||
apiCustomNodeMapper.updateAfterSeq(parentId, 1);
|
||||
} else {
|
||||
// 否则移动到目标元素后
|
||||
apiCustomNode.setSeqNo(customNodeSel.getSeqNo() + 1);
|
||||
apiCustomNode.setParentId(customNodeSel.getParentId());
|
||||
apiCustomNodeMapper.updateAfterSeq(customNodeSel.getParentId(), apiCustomNode.getSeqNo());
|
||||
}
|
||||
}
|
||||
this.updateById(apiCustomNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiCustomDocVo> buildCustomApiList(ApiDoc apiDoc) {
|
||||
QueryWrapper<ApiCustomNode> nodeQueryWrapper = new QueryWrapper<>();
|
||||
nodeQueryWrapper.eq("yn", 1);
|
||||
nodeQueryWrapper.eq("doc_id", apiDoc.getId());
|
||||
List<ApiCustomNode> customNodeList = this.list(nodeQueryWrapper);
|
||||
|
||||
QueryWrapper<ApiCustomParams> paramsWrapper = new QueryWrapper<>();
|
||||
paramsWrapper.eq("yn", 1);
|
||||
paramsWrapper.eq("doc_id", apiDoc.getId());
|
||||
paramsWrapper.select("node_id", "method", "api_url");
|
||||
List<ApiCustomParams> customParamsList = apiCustomParamsService.list(paramsWrapper);
|
||||
Map<Long, ApiCustomParams> customParamsMap = customParamsList.stream().collect(Collectors.toMap(ApiCustomParams::getNodeId, val -> val));
|
||||
|
||||
Map<Long, List<ApiCustomNode>> nodeMap = customNodeList.stream()
|
||||
.peek(item -> item.setParentId(Optional.ofNullable(item.getParentId()).orElse(0L)))
|
||||
.collect(Collectors.groupingBy(ApiCustomNode::getParentId));
|
||||
|
||||
List<ApiCustomDocVo> customGroupChildren = this.getCustomGroupChildren(nodeMap.get(0L), nodeMap, customParamsMap);
|
||||
// 组装结果对象
|
||||
ApiCustomDocVo apiCustomVo = new ApiCustomDocVo();
|
||||
apiCustomVo.setChildren(customGroupChildren);
|
||||
apiCustomVo.setNodeName(apiDoc.getName());
|
||||
List<ApiCustomDocVo> apiCustomVoList = new LinkedList<>();
|
||||
apiCustomVoList.add(apiCustomVo);
|
||||
return apiCustomVoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归删除下级
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2021-12-22
|
||||
*/
|
||||
public void getAllChildNodeId(Set<Long> deleteNodeIds, Long id) {
|
||||
QueryWrapper<ApiCustomNode> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("yn", 1);
|
||||
wrapper.eq("parent_id", id);
|
||||
List<ApiCustomNode> childrenList = this.list(wrapper);
|
||||
if (CollectionUtils.isNotEmpty(childrenList)) {
|
||||
for (ApiCustomNode folder : childrenList) {
|
||||
// 递归删除下级
|
||||
this.getAllChildNodeId(deleteNodeIds, folder.getId());
|
||||
}
|
||||
deleteNodeIds.addAll(childrenList.stream().map(ApiCustomNode::getId).collect(Collectors.toSet()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归获取目录树
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2021-12-22
|
||||
*/
|
||||
private List<ApiCustomDocVo> getCustomGroupChildren(List<ApiCustomNode> apiFolderList, Map<Long, List<ApiCustomNode>> nodeMap, Map<Long, ApiCustomParams> customParamsMap) {
|
||||
if (CollectionUtils.isEmpty(apiFolderList)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<ApiCustomDocVo> apiCustomVoList = new LinkedList<>();
|
||||
apiFolderList.sort(Comparator.comparingInt(ApiCustomNode::getSeqNo));
|
||||
for (ApiCustomNode apiCustomNode : apiFolderList) {
|
||||
List<ApiCustomNode> children = nodeMap.get(apiCustomNode.getId());
|
||||
List<ApiCustomDocVo> customGroupChildren = this.getCustomGroupChildren(children, nodeMap, customParamsMap);
|
||||
ApiCustomDocVo apiCustomVo = new ApiCustomDocVo();
|
||||
apiCustomVo.setNodeId(apiCustomNode.getId());
|
||||
apiCustomVo.setNodeType(apiCustomNode.getNodeType());
|
||||
apiCustomVo.setNodeName(apiCustomNode.getNodeName());
|
||||
apiCustomVo.setNodeDesc(apiCustomNode.getNodeDesc());
|
||||
apiCustomVo.setChildren(customGroupChildren);
|
||||
if (Objects.equals(apiCustomNode.getNodeType(), 1)) {
|
||||
ApiCustomParams apiCustomParams = customParamsMap.get(apiCustomNode.getId());
|
||||
if (apiCustomParams != null) {
|
||||
apiCustomVo.setMethod(apiCustomParams.getMethod());
|
||||
apiCustomVo.setApiUrl(apiCustomParams.getApiUrl());
|
||||
}
|
||||
}
|
||||
apiCustomVoList.add(apiCustomVo);
|
||||
}
|
||||
return apiCustomVoList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zyplayer.doc.data.service.manage.impl;
|
||||
|
||||
import com.zyplayer.doc.data.repository.manage.entity.ApiCustomParams;
|
||||
import com.zyplayer.doc.data.repository.manage.mapper.ApiCustomParamsMapper;
|
||||
import com.zyplayer.doc.data.service.manage.ApiCustomParamsService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 自建接口文档 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2022-01-29
|
||||
*/
|
||||
@Service
|
||||
public class ApiCustomParamsServiceImpl extends ServiceImpl<ApiCustomParamsMapper, ApiCustomParams> implements ApiCustomParamsService {
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import com.zyplayer.doc.data.service.common.ApiDocAuthJudgeService;
|
||||
import com.zyplayer.doc.data.service.manage.ApiCustomFolderService;
|
||||
import com.zyplayer.doc.data.service.manage.ApiCustomRequestService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -57,7 +57,6 @@ public class ApiCustomRequestServiceImpl extends ServiceImpl<ApiCustomRequestMap
|
||||
Map<Long, List<ApiCustomFolder>> apiGroupMap = apiCustomGroupList.stream()
|
||||
.peek(item -> item.setParentFolderId(Optional.ofNullable(item.getParentFolderId()).orElse(0L)))
|
||||
.collect(Collectors.groupingBy(ApiCustomFolder::getParentFolderId));
|
||||
List<ApiCustomVo> apiCustomVoList = new LinkedList<>();
|
||||
List<ApiCustomDocVo> apis = this.buildApiCustomDocVo(apiMap.get(0L));
|
||||
List<ApiCustomVo> customGroupChildren = this.getCustomGroupChildren(apiGroupMap.get(0L), apiGroupMap, apiMap);
|
||||
// 组装结果对象
|
||||
@@ -65,6 +64,7 @@ public class ApiCustomRequestServiceImpl extends ServiceImpl<ApiCustomRequestMap
|
||||
apiCustomVo.setChildren(customGroupChildren);
|
||||
apiCustomVo.setName(apiDoc.getName());
|
||||
apiCustomVo.setApis(apis);
|
||||
List<ApiCustomVo> apiCustomVoList = new LinkedList<>();
|
||||
apiCustomVoList.add(apiCustomVo);
|
||||
return apiCustomVoList;
|
||||
}
|
||||
@@ -79,10 +79,13 @@ public class ApiCustomRequestServiceImpl extends ServiceImpl<ApiCustomRequestMap
|
||||
apiCustomRequest.setCreateUserId(currentUser.getUserId());
|
||||
apiCustomRequest.setCreateUserName(currentUser.getUsername());
|
||||
} else {
|
||||
apiCustomRequest.setDocId(null);
|
||||
apiCustomRequest.setCreateTime(null);
|
||||
apiCustomRequest.setCreateUserId(null);
|
||||
apiCustomRequest.setCreateUserName(null);
|
||||
}
|
||||
String apiName = StringUtils.defaultString(apiCustomRequest.getApiName(), "新建接口");
|
||||
apiCustomRequest.setApiName(apiName);
|
||||
this.saveOrUpdate(apiCustomRequest);
|
||||
return apiCustomRequest;
|
||||
}
|
||||
@@ -98,39 +101,39 @@ public class ApiCustomRequestServiceImpl extends ServiceImpl<ApiCustomRequestMap
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<ApiCustomVo> apiCustomVoList = new LinkedList<>();
|
||||
for (ApiCustomFolder customGroup : apiCustomGroups) {
|
||||
List<ApiCustomRequest> apiCustomList = apiMap.get(customGroup.getId());
|
||||
List<ApiCustomFolder> children = apiGroupMap.get(customGroup.getId());
|
||||
List<ApiCustomVo> customGroupChildren = this.getCustomGroupChildren(children, apiGroupMap, apiMap);
|
||||
List<ApiCustomDocVo> apis = this.buildApiCustomDocVo(apiCustomList);
|
||||
ApiCustomVo apiCustomVo = new ApiCustomVo();
|
||||
apiCustomVo.setFolderId(customGroup.getId());
|
||||
apiCustomVo.setName(customGroup.getFolderName());
|
||||
apiCustomVo.setDesc(customGroup.getFolderDesc());
|
||||
apiCustomVo.setChildren(customGroupChildren);
|
||||
apiCustomVo.setApis(apis);
|
||||
apiCustomVoList.add(apiCustomVo);
|
||||
}
|
||||
// for (ApiCustomFolder customGroup : apiCustomGroups) {
|
||||
// List<ApiCustomRequest> apiCustomList = apiMap.get(customGroup.getId());
|
||||
// List<ApiCustomFolder> children = apiGroupMap.get(customGroup.getId());
|
||||
// List<ApiCustomVo> customGroupChildren = this.getCustomGroupChildren(children, apiGroupMap, apiMap);
|
||||
// List<ApiCustomDocVo> apis = this.buildApiCustomDocVo(apiCustomList);
|
||||
// ApiCustomVo apiCustomVo = new ApiCustomVo();
|
||||
// apiCustomVo.setFolderId(customGroup.getId());
|
||||
// apiCustomVo.setName(customGroup.getFolderName());
|
||||
// apiCustomVo.setDesc(customGroup.getFolderDesc());
|
||||
// apiCustomVo.setChildren(customGroupChildren);
|
||||
// apiCustomVo.setApis(apis);
|
||||
// apiCustomVoList.add(apiCustomVo);
|
||||
// }
|
||||
return apiCustomVoList;
|
||||
}
|
||||
|
||||
private List<ApiCustomDocVo> buildApiCustomDocVo(List<ApiCustomRequest> apiCustomList) {
|
||||
List<ApiCustomDocVo> apis = new LinkedList<>();
|
||||
if (CollectionUtils.isNotEmpty(apiCustomList)) {
|
||||
for (ApiCustomRequest apiCustom : apiCustomList) {
|
||||
ApiCustomDocVo apiCustomDocVo = new ApiCustomDocVo();
|
||||
apiCustomDocVo.setRequestId(apiCustom.getId());
|
||||
apiCustomDocVo.setFolderId(apiCustom.getFolderId());
|
||||
apiCustomDocVo.setApiUrl(apiCustom.getApiUrl());
|
||||
apiCustomDocVo.setMethod(apiCustom.getMethod());
|
||||
apiCustomDocVo.setApiName(apiCustom.getApiName());
|
||||
apiCustomDocVo.setBodyData(apiCustom.getBodyData());
|
||||
apiCustomDocVo.setCookieData(apiCustom.getCookieData());
|
||||
apiCustomDocVo.setFormData(apiCustom.getFormData());
|
||||
apiCustomDocVo.setHeaderData(apiCustom.getHeaderData());
|
||||
apis.add(apiCustomDocVo);
|
||||
}
|
||||
}
|
||||
// if (CollectionUtils.isNotEmpty(apiCustomList)) {
|
||||
// for (ApiCustomRequest apiCustom : apiCustomList) {
|
||||
// ApiCustomDocVo apiCustomDocVo = new ApiCustomDocVo();
|
||||
// apiCustomDocVo.setRequestId(apiCustom.getId());
|
||||
// apiCustomDocVo.setFolderId(apiCustom.getFolderId());
|
||||
// apiCustomDocVo.setApiUrl(apiCustom.getApiUrl());
|
||||
// apiCustomDocVo.setMethod(apiCustom.getMethod());
|
||||
// apiCustomDocVo.setApiName(apiCustom.getApiName());
|
||||
// apiCustomDocVo.setBodyData(apiCustom.getBodyData());
|
||||
// apiCustomDocVo.setCookieData(apiCustom.getCookieData());
|
||||
// apiCustomDocVo.setFormData(apiCustom.getFormData());
|
||||
// apiCustomDocVo.setHeaderData(apiCustom.getHeaderData());
|
||||
// apis.add(apiCustomDocVo);
|
||||
// }
|
||||
// }
|
||||
return apis;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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="com.zyplayer.doc.data.repository.manage.mapper.ApiCustomNodeMapper">
|
||||
|
||||
</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="com.zyplayer.doc.data.repository.manage.mapper.ApiCustomParamsMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user