Przeglądaj źródła

feat:完成开放API的CRUD接口开发

yang yi 11 miesięcy temu
rodzic
commit
5bb108362f

+ 4 - 0
pom.xml

@@ -71,6 +71,10 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-validation</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
     </dependencies>
 
 </project>

+ 57 - 0
src/main/java/space/anyi/openAPI/controller/InterfaceInfoController.java

@@ -0,0 +1,57 @@
+package space.anyi.openAPI.controller;
+
+import cn.hutool.core.util.IdUtil;
+import org.springframework.web.bind.annotation.*;
+import space.anyi.openAPI.model.PageVO;
+import space.anyi.openAPI.model.ResponseResult;
+import space.anyi.openAPI.model.interfaceInfo.InterfaceInfo;
+import space.anyi.openAPI.model.interfaceInfo.dto.RequestAddInterfaceInfo;
+import space.anyi.openAPI.model.interfaceInfo.dto.RequestPageInterfaceInfo;
+import space.anyi.openAPI.model.interfaceInfo.dto.RequestUpdateInterfaceInfo;
+import space.anyi.openAPI.service.InterfaceInfoService;
+import space.anyi.openAPI.util.BeanCopyUtil;
+import space.anyi.openAPI.util.SecurityUtils;
+
+import javax.annotation.Resource;
+
+/**
+ * @ProjectName: yangyi-open-api-platform
+ * @FileName: InterfaceInfoController
+ * @Author: 杨逸
+ * @Data:2025/10/14 19:52
+ * @Description:
+ */
+@RestController
+@RequestMapping("/interfaceInfo")
+public class InterfaceInfoController {
+    @Resource
+    private InterfaceInfoService interfaceInfoService;
+    @PostMapping
+    public ResponseResult add(@RequestBody RequestAddInterfaceInfo requestAddInterfaceInfo){
+        long id = IdUtil.getSnowflake(1, 1).nextId();
+        InterfaceInfo interfaceInfo = BeanCopyUtil.copyBean(requestAddInterfaceInfo, InterfaceInfo.class);
+        interfaceInfo.setId(id);
+        Long userId = SecurityUtils.getUserId();
+        interfaceInfo.setUserId(userId);
+        interfaceInfoService.save(interfaceInfo);
+        return ResponseResult.okResult();
+    }
+
+    @DeleteMapping("/{id}")
+    public ResponseResult delete(@PathVariable("id") Long id){
+        interfaceInfoService.removeById(id);
+        return ResponseResult.okResult();
+    }
+
+    @PutMapping
+    public ResponseResult update(@RequestBody RequestUpdateInterfaceInfo requestUpdateInterfaceInfo){
+        InterfaceInfo interfaceInfo = BeanCopyUtil.copyBean(requestUpdateInterfaceInfo, InterfaceInfo.class);
+        interfaceInfoService.updateById(interfaceInfo);
+        return ResponseResult.okResult();
+    }
+    @GetMapping
+    public ResponseResult list(RequestPageInterfaceInfo requestPageInterfaceInfo){
+        PageVO pageVO = interfaceInfoService.listPage(requestPageInterfaceInfo);
+        return ResponseResult.okResult(pageVO);
+    }
+}

+ 18 - 0
src/main/java/space/anyi/openAPI/mapper/InterfaceInfoMapper.java

@@ -0,0 +1,18 @@
+package space.anyi.openAPI.mapper;
+
+import space.anyi.openAPI.model.interfaceInfo.InterfaceInfo;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+* @author 杨逸
+* @description 针对表【interface_info(接口信息)】的数据库操作Mapper
+* @createDate 2025-10-14 19:47:51
+* @Entity space.anyi.openAPI.model.interfaceInfo.InterfaceInfo
+*/
+public interface InterfaceInfoMapper extends BaseMapper<InterfaceInfo> {
+
+}
+
+
+
+

+ 149 - 0
src/main/java/space/anyi/openAPI/model/interfaceInfo/InterfaceInfo.java

@@ -0,0 +1,149 @@
+package space.anyi.openAPI.model.interfaceInfo;
+
+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 java.io.Serializable;
+import java.util.Date;
+import lombok.Data;
+
+/**
+ * 接口信息
+ * @TableName interface_info
+ */
+@TableName(value ="interface_info")
+@Data
+public class InterfaceInfo implements Serializable {
+    /**
+     * 主键
+     */
+    @TableId(type = IdType.ASSIGN_ID)
+    private Long id;
+
+    /**
+     * 名称
+     */
+    private String name;
+
+    /**
+     * 描述
+     */
+    private String description;
+
+    /**
+     * 接口地址
+     */
+    private String url;
+
+    /**
+     * 请求头
+     */
+    private String requestHeader;
+
+    /**
+     * 响应头
+     */
+    private String responseHeader;
+
+    /**
+     * 接口状态(0-关闭,1-开启)
+     */
+    private Integer status;
+
+    /**
+     * 请求类型
+     */
+    private String method;
+
+    /**
+     * 创建人
+     */
+    private Long userId;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    /**
+     * 更新时间
+     */
+    private Date updateTime;
+
+    /**
+     * 是否删除(0-未删, 1-已删)
+     */
+    private Integer deleteFlag;
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        if (getClass() != that.getClass()) {
+            return false;
+        }
+        InterfaceInfo other = (InterfaceInfo) that;
+        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
+            && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
+            && (this.getDescription() == null ? other.getDescription() == null : this.getDescription().equals(other.getDescription()))
+            && (this.getUrl() == null ? other.getUrl() == null : this.getUrl().equals(other.getUrl()))
+            && (this.getRequestHeader() == null ? other.getRequestHeader() == null : this.getRequestHeader().equals(other.getRequestHeader()))
+            && (this.getResponseHeader() == null ? other.getResponseHeader() == null : this.getResponseHeader().equals(other.getResponseHeader()))
+            && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
+            && (this.getMethod() == null ? other.getMethod() == null : this.getMethod().equals(other.getMethod()))
+            && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
+            && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
+            && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
+            && (this.getDeleteFlag() == null ? other.getDeleteFlag() == null : this.getDeleteFlag().equals(other.getDeleteFlag()));
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
+        result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
+        result = prime * result + ((getDescription() == null) ? 0 : getDescription().hashCode());
+        result = prime * result + ((getUrl() == null) ? 0 : getUrl().hashCode());
+        result = prime * result + ((getRequestHeader() == null) ? 0 : getRequestHeader().hashCode());
+        result = prime * result + ((getResponseHeader() == null) ? 0 : getResponseHeader().hashCode());
+        result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
+        result = prime * result + ((getMethod() == null) ? 0 : getMethod().hashCode());
+        result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
+        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
+        result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
+        result = prime * result + ((getDeleteFlag() == null) ? 0 : getDeleteFlag().hashCode());
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append(" [");
+        sb.append("Hash = ").append(hashCode());
+        sb.append(", id=").append(id);
+        sb.append(", name=").append(name);
+        sb.append(", description=").append(description);
+        sb.append(", url=").append(url);
+        sb.append(", requestHeader=").append(requestHeader);
+        sb.append(", responseHeader=").append(responseHeader);
+        sb.append(", status=").append(status);
+        sb.append(", method=").append(method);
+        sb.append(", userId=").append(userId);
+        sb.append(", createTime=").append(createTime);
+        sb.append(", updateTime=").append(updateTime);
+        sb.append(", deleteFlag=").append(deleteFlag);
+        sb.append(", serialVersionUID=").append(serialVersionUID);
+        sb.append("]");
+        return sb.toString();
+    }
+}

+ 50 - 0
src/main/java/space/anyi/openAPI/model/interfaceInfo/dto/RequestAddInterfaceInfo.java

@@ -0,0 +1,50 @@
+package space.anyi.openAPI.model.interfaceInfo.dto;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * @ProjectName: yangyi-open-api-platform
+ * @FileName: RequestAddInterfaceInfo
+ * @Author: 杨逸
+ * @Data:2025/10/14 19:57
+ * @Description:
+ */
+@Data
+public class RequestAddInterfaceInfo {
+
+    /**
+     * 名称
+     */
+    private String name;
+
+    /**
+     * 描述
+     */
+    private String description;
+
+    /**
+     * 接口地址
+     */
+    private String url;
+
+    /**
+     * 请求头
+     */
+    private String requestHeader;
+
+    /**
+     * 响应头
+     */
+    private String responseHeader;
+
+
+    /**
+     * 请求类型
+     */
+    private String method;
+
+}

+ 46 - 0
src/main/java/space/anyi/openAPI/model/interfaceInfo/dto/RequestPageInterfaceInfo.java

@@ -0,0 +1,46 @@
+package space.anyi.openAPI.model.interfaceInfo.dto;
+
+import lombok.Data;
+
+/**
+ * @ProjectName: yangyi-open-api-platform
+ * @FileName: RequestPageInterfaceInfo
+ * @Author: 杨逸
+ * @Data:2025/10/14 20:07
+ * @Description:
+ */
+@Data
+public class RequestPageInterfaceInfo {
+
+    private Long id;
+
+    /**
+     * 名称
+     */
+    private String name;
+
+
+    /**
+     * 接口状态(0-关闭,1-开启)
+     */
+    private Integer status;
+
+    /**
+     * 请求类型
+     */
+    private String method;
+
+    /**
+     * 创建人
+     */
+    private Long userId;
+    /**
+     * 分页大小
+     */
+    private int size;
+    /**
+     * 分页页码
+     */
+    private int current;
+
+}

+ 58 - 0
src/main/java/space/anyi/openAPI/model/interfaceInfo/dto/RequestUpdateInterfaceInfo.java

@@ -0,0 +1,58 @@
+package space.anyi.openAPI.model.interfaceInfo.dto;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * @ProjectName: yangyi-open-api-platform
+ * @FileName: RequestUpdateInterfaceInfo
+ * @Author: 杨逸
+ * @Data:2025/10/14 20:03
+ * @Description:
+ */
+@Data
+public class RequestUpdateInterfaceInfo {
+    /**
+     * id
+     */
+    private Long id;
+
+    /**
+     * 名称
+     */
+    private String name;
+
+    /**
+     * 描述
+     */
+    private String description;
+
+    /**
+     * 接口地址
+     */
+    private String url;
+
+    /**
+     * 请求头
+     */
+    private String requestHeader;
+
+    /**
+     * 响应头
+     */
+    private String responseHeader;
+
+    /**
+     * 接口状态(0-关闭,1-开启)
+     */
+    private Integer status;
+
+    /**
+     * 请求类型
+     */
+    private String method;
+
+}

+ 16 - 0
src/main/java/space/anyi/openAPI/service/InterfaceInfoService.java

@@ -0,0 +1,16 @@
+package space.anyi.openAPI.service;
+
+import space.anyi.openAPI.model.PageVO;
+import space.anyi.openAPI.model.interfaceInfo.InterfaceInfo;
+import com.baomidou.mybatisplus.extension.service.IService;
+import space.anyi.openAPI.model.interfaceInfo.dto.RequestPageInterfaceInfo;
+
+/**
+* @author 杨逸
+* @description 针对表【interface_info(接口信息)】的数据库操作Service
+* @createDate 2025-10-14 19:47:51
+*/
+public interface InterfaceInfoService extends IService<InterfaceInfo> {
+
+    PageVO listPage(RequestPageInterfaceInfo requestPageInterfaceInfo);
+}

+ 41 - 0
src/main/java/space/anyi/openAPI/service/impl/InterfaceInfoServiceImpl.java

@@ -0,0 +1,41 @@
+package space.anyi.openAPI.service.impl;
+
+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.util.StringUtils;
+import space.anyi.openAPI.model.PageVO;
+import space.anyi.openAPI.model.interfaceInfo.InterfaceInfo;
+import space.anyi.openAPI.model.interfaceInfo.dto.RequestPageInterfaceInfo;
+import space.anyi.openAPI.service.InterfaceInfoService;
+import space.anyi.openAPI.mapper.InterfaceInfoMapper;
+import org.springframework.stereotype.Service;
+
+import java.util.Objects;
+
+/**
+* @author 杨逸
+* @description 针对表【interface_info(接口信息)】的数据库操作Service实现
+* @createDate 2025-10-14 19:47:51
+*/
+@Service
+public class InterfaceInfoServiceImpl extends ServiceImpl<InterfaceInfoMapper, InterfaceInfo>
+    implements InterfaceInfoService{
+
+    @Override
+    public PageVO listPage(RequestPageInterfaceInfo requestPageInterfaceInfo) {
+        LambdaQueryWrapper<InterfaceInfo> lambdaQueryWrapper = new LambdaQueryWrapper<InterfaceInfo>()
+                .eq(Objects.nonNull(requestPageInterfaceInfo.getId()), InterfaceInfo::getId, requestPageInterfaceInfo.getId())
+                .like(Objects.nonNull(requestPageInterfaceInfo.getName()) && StringUtils.hasText(requestPageInterfaceInfo.getName()), InterfaceInfo::getName, requestPageInterfaceInfo.getName())
+                .eq(Objects.nonNull(requestPageInterfaceInfo.getStatus()), InterfaceInfo::getStatus, requestPageInterfaceInfo.getStatus())
+                .eq(Objects.nonNull(requestPageInterfaceInfo.getMethod()) && StringUtils.hasText(requestPageInterfaceInfo.getMethod()), InterfaceInfo::getMethod, requestPageInterfaceInfo.getMethod());
+        Page<InterfaceInfo> page = Page.of(requestPageInterfaceInfo.getCurrent(), requestPageInterfaceInfo.getSize());
+        page(page, lambdaQueryWrapper);
+        PageVO pageVO = new PageVO(page.getRecords(), page.getTotal());
+        return pageVO;
+    }
+}
+
+
+
+

+ 1 - 1
src/main/java/space/anyi/openAPI/util/JwtUtil.java

@@ -16,7 +16,7 @@ import java.util.UUID;
  * @FileName: JwtUtil
  * @Author: 杨逸
  * @Data:2024/11/28 20:08
- * @Description: 
+ * @Description:
  */
 public class JwtUtil {
 

+ 28 - 0
src/main/resources/mapper/InterfaceInfoMapper.xml

@@ -0,0 +1,28 @@
+<?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="space.anyi.openAPI.mapper.InterfaceInfoMapper">
+
+    <resultMap id="BaseResultMap" type="space.anyi.openAPI.model.interfaceInfo.InterfaceInfo">
+            <id property="id" column="id" jdbcType="BIGINT"/>
+            <result property="name" column="name" jdbcType="VARCHAR"/>
+            <result property="description" column="description" jdbcType="VARCHAR"/>
+            <result property="url" column="url" jdbcType="VARCHAR"/>
+            <result property="requestHeader" column="request_header" jdbcType="VARCHAR"/>
+            <result property="responseHeader" column="response_header" jdbcType="VARCHAR"/>
+            <result property="status" column="status" jdbcType="INTEGER"/>
+            <result property="method" column="method" jdbcType="VARCHAR"/>
+            <result property="userId" column="user_id" jdbcType="BIGINT"/>
+            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
+            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
+            <result property="deleteFlag" column="delete_flag" jdbcType="TINYINT"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id,name,description,
+        url,request_header,response_header,
+        status,method,user_id,
+        create_time,update_time,delete_flag
+    </sql>
+</mapper>