Sfoglia il codice sorgente

feat:后端项目,完成接口信息管理模块的CRUD,返回雪花id时使用字符串类型,避免前端数值类型溢出导致id丢失;完善swagger文档的信息

yang yi 11 mesi fa
parent
commit
f5809a47e2

+ 4 - 3
src/main/java/space/anyi/openAPI/controller/InterfaceInfoController.java

@@ -13,6 +13,7 @@ import space.anyi.openAPI.util.BeanCopyUtil;
 import space.anyi.openAPI.util.SecurityUtils;
 
 import javax.annotation.Resource;
+import java.util.List;
 
 /**
  * @ProjectName: yangyi-open-api-platform
@@ -37,9 +38,9 @@ public class InterfaceInfoController {
         return ResponseResult.okResult();
     }
 
-    @DeleteMapping("/{id}")
-    public ResponseResult delete(@PathVariable("id") Long id){
-        interfaceInfoService.removeById(id);
+    @DeleteMapping()
+    public ResponseResult delete(List<Long> ids){
+        interfaceInfoService.removeByIds(ids);
         return ResponseResult.okResult();
     }
 

+ 11 - 5
src/main/java/space/anyi/openAPI/model/PageVO.java

@@ -1,5 +1,8 @@
 package space.anyi.openAPI.model;
 
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
 import java.util.List;
 
 /**
@@ -9,11 +12,14 @@ import java.util.List;
  * @Data:2024/12/5 10:23
  * @Description:
  */
-public class PageVO {
+@ApiModel("数据分页实体")
+public class PageVO <T>{
+    @ApiModelProperty("数据库总条数")
     private Integer total;
-    private List<Object> records;
+    @ApiModelProperty("分页数据")
+    private List<T> records;
 
-    public PageVO(List records, long total) {
+    public PageVO(List<T> records, long total) {
         this.records = records;
         this.total = (int) total;
     }
@@ -26,11 +32,11 @@ public class PageVO {
         this.total = total;
     }
 
-    public List<Object> getRecords() {
+    public List<T> getRecords() {
         return records;
     }
 
-    public void setRecords(List<Object> records) {
+    public void setRecords(List<T> records) {
         this.records = records;
     }
 }

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

@@ -2,6 +2,8 @@ package space.anyi.openAPI.model.interfaceInfo.dto;
 
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.util.Date;
@@ -14,37 +16,44 @@ import java.util.Date;
  * @Description:
  */
 @Data
+@ApiModel("添加接口信息实体")
 public class RequestAddInterfaceInfo {
 
     /**
      * 名称
      */
+    @ApiModelProperty(value = "名称",required = true)
     private String name;
 
     /**
      * 描述
      */
+    @ApiModelProperty(value = "描述",required = true)
     private String description;
 
     /**
      * 接口地址
      */
+    @ApiModelProperty(value = "接口地址",required = true)
     private String url;
 
     /**
      * 请求头
      */
+    @ApiModelProperty(value = "请求头",required = false)
     private String requestHeader;
 
     /**
      * 响应头
      */
+    @ApiModelProperty(value = "响应头",required = false)
     private String responseHeader;
 
 
     /**
      * 请求类型
      */
+    @ApiModelProperty(value = "请求类型",required = true)
     private String method;
 
 }

+ 8 - 5
src/main/java/space/anyi/openAPI/model/interfaceInfo/dto/RequestPageInterfaceInfo.java

@@ -1,5 +1,7 @@
 package space.anyi.openAPI.model.interfaceInfo.dto;
 
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 /**
@@ -10,37 +12,38 @@ import lombok.Data;
  * @Description:
  */
 @Data
+@ApiModel
 public class RequestPageInterfaceInfo {
 
-    private Long id;
 
     /**
      * 名称
      */
+    @ApiModelProperty(value = "名称")
     private String name;
 
 
     /**
      * 接口状态(0-关闭,1-开启)
      */
+    @ApiModelProperty(value = "接口状态(0-关闭,1-开启)",example = "0")
     private Integer status;
 
     /**
      * 请求类型
      */
+    @ApiModelProperty(value = "请求类型")
     private String method;
 
-    /**
-     * 创建人
-     */
-    private Long userId;
     /**
      * 分页大小
      */
+    @ApiModelProperty(value = "分页大小",required = true)
     private int size;
     /**
      * 分页页码
      */
+    @ApiModelProperty(value = "分页页码",required = true)
     private int current;
 
 }

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

@@ -2,6 +2,8 @@ package space.anyi.openAPI.model.interfaceInfo.dto;
 
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.util.Date;
@@ -14,45 +16,54 @@ import java.util.Date;
  * @Description:
  */
 @Data
+@ApiModel
 public class RequestUpdateInterfaceInfo {
     /**
      * id
      */
+    @ApiModelProperty(value = "id",required = true)
     private Long id;
 
     /**
      * 名称
      */
+    @ApiModelProperty(value = "名称",required = true)
     private String name;
 
     /**
      * 描述
      */
+    @ApiModelProperty(value = "描述",required = false)
     private String description;
 
     /**
      * 接口地址
      */
+    @ApiModelProperty(value = "接口地址",required = true)
     private String url;
 
     /**
      * 请求头
      */
+    @ApiModelProperty(value = "请求头",required = false)
     private String requestHeader;
 
     /**
      * 响应头
      */
+    @ApiModelProperty(value = "响应头",required = false)
     private String responseHeader;
 
     /**
      * 接口状态(0-关闭,1-开启)
      */
+    @ApiModelProperty(value = "接口状态(0-关闭,1-开启)",required = true)
     private Integer status;
 
     /**
      * 请求类型
      */
+    @ApiModelProperty(value = "请求类型",required = true)
     private String method;
 
 }

+ 66 - 0
src/main/java/space/anyi/openAPI/model/interfaceInfo/vo/InterfaceInfoVO.java

@@ -0,0 +1,66 @@
+package space.anyi.openAPI.model.interfaceInfo.vo;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * @ProjectName: yangyi-open-api-platform
+ * @FileName: InterfaceInfoVO
+ * @Author: 杨逸
+ * @Data:2025/10/16 17:11
+ * @Description:
+ */
+@Data
+public class InterfaceInfoVO {
+    /**
+     * 主键
+     */
+    private String 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 String userId;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+}

+ 18 - 2
src/main/java/space/anyi/openAPI/service/impl/InterfaceInfoServiceImpl.java

@@ -7,11 +7,14 @@ 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.model.interfaceInfo.vo.InterfaceInfoVO;
 import space.anyi.openAPI.service.InterfaceInfoService;
 import space.anyi.openAPI.mapper.InterfaceInfoMapper;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
 * @author 杨逸
@@ -25,13 +28,26 @@ public class InterfaceInfoServiceImpl extends ServiceImpl<InterfaceInfoMapper, I
     @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());
+        List<InterfaceInfoVO> list = page.getRecords().stream().map(interfaceInfo -> {
+            InterfaceInfoVO vo = new InterfaceInfoVO();
+            vo.setId(interfaceInfo.getId()+"");
+            vo.setName(interfaceInfo.getName());
+            vo.setUrl(interfaceInfo.getUrl());
+            vo.setMethod(interfaceInfo.getMethod());
+            vo.setDescription(interfaceInfo.getDescription());
+            vo.setCreateTime(interfaceInfo.getCreateTime());
+            vo.setRequestHeader(interfaceInfo.getRequestHeader());
+            vo.setResponseHeader(interfaceInfo.getResponseHeader());
+            vo.setUserId(interfaceInfo.getUserId()+"");
+            vo.setStatus(interfaceInfo.getStatus());
+            return vo;
+        }).collect(Collectors.toList());
+        PageVO pageVO = new PageVO(list, page.getTotal());
         return pageVO;
     }
 }