Parcourir la source

feat:后端项目,接口参数的增删改查接口

yang yi il y a 10 mois
Parent
commit
5d978fcc9e

+ 93 - 0
src/main/java/space/anyi/openAPI/controller/InterfaceParamController.java

@@ -0,0 +1,93 @@
+package space.anyi.openAPI.controller;
+
+import cn.hutool.core.util.IdUtil;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import org.springframework.web.bind.annotation.*;
+import space.anyi.openAPI.model.ResponseResult;
+import space.anyi.openAPI.model.interfaceParam.InterfaceParam;
+import space.anyi.openAPI.model.interfaceParam.dto.RequestAddInterfaceParam;
+import space.anyi.openAPI.model.interfaceParam.dto.RequestUpdateInterfaceParam;
+import space.anyi.openAPI.model.interfaceParam.vo.InterfaceParamVO;
+import space.anyi.openAPI.service.InterfaceParamService;
+import space.anyi.openAPI.util.BeanCopyUtil;
+
+import javax.validation.Valid;
+import javax.validation.constraints.Size;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @ProjectName: yangyi-open-api-platform
+ * @FileName: InterfaceParamController
+ * @Author: 杨逸
+ * @Data:2025/10/27 10:38
+ * @Description:
+ */
+@RestController
+@RequestMapping("/interfaceParam")
+public class InterfaceParamController {
+    public final InterfaceParamService interfaceParamService;
+
+    public InterfaceParamController(InterfaceParamService interfaceParamService) {
+        this.interfaceParamService = interfaceParamService;
+    }
+
+    /**
+     * 新增参数
+     * @param requestAddInterfaceParam
+     * @return {@code ResponseResult }
+     * @description:
+     * @author: 杨逸
+     * @data:2025/10/27 11:04:46
+     * @since 1.0.0
+     */
+    @PostMapping
+    public ResponseResult addInterfaceParam(@RequestBody @Valid RequestAddInterfaceParam requestAddInterfaceParam){
+        InterfaceParam interfaceParam = BeanCopyUtil.copyBean(requestAddInterfaceParam, InterfaceParam.class);
+        long id = IdUtil.getSnowflake(1, 1).nextId();
+        interfaceParam.setId(id);
+        interfaceParamService.save(interfaceParam);
+        return ResponseResult.okResult();
+    }
+
+    /**
+     * 删除参数
+     * @param ids
+     * @return {@code ResponseResult }
+     * @description:
+     * @author: 杨逸
+     * @data:2025/10/27 11:08:23
+     * @since 1.0.0
+     */
+    @DeleteMapping
+    public ResponseResult deleteInterfaceParam(@Valid@Size(min = 1,message = "id不能为空") List<Long> ids){
+        interfaceParamService.removeByIds(ids);
+        return ResponseResult.okResult();
+    }
+
+    /**
+     * 修改参数
+     * @param requestUpdateInterfaceParam
+     * @return {@code ResponseResult }
+     * @description:
+     * @author: 杨逸
+     * @data:2025/10/27 11:14:38
+     * @since 1.0.0
+     */
+    @PutMapping
+    public ResponseResult updateInterfaceParam(@Valid@RequestBody RequestUpdateInterfaceParam requestUpdateInterfaceParam){
+        InterfaceParam interfaceParam = BeanCopyUtil.copyBean(requestUpdateInterfaceParam, InterfaceParam.class);
+        interfaceParam.setUpdateTime(new Date());
+        interfaceParamService.updateById(interfaceParam);
+        return ResponseResult.okResult();
+    }
+    @GetMapping("/byInterfaceInfoId/{id}")
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "id",name = "id",required = true,paramType = "path")
+    })
+    public ResponseResult getInterfaceParamByInterfaceInfoId(@PathVariable("id") Long id){
+        List<InterfaceParamVO> listVo = interfaceParamService.getInterfaceParamByInterfaceInfoId(id);
+        return ResponseResult.okResult(listVo);
+    }
+}

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

@@ -0,0 +1,18 @@
+package space.anyi.openAPI.mapper;
+
+import space.anyi.openAPI.model.interfaceParam.InterfaceParam;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+* @author 杨逸
+* @description 针对表【interface_param(接口参数)】的数据库操作Mapper
+* @createDate 2025-10-27 10:32:58
+* @Entity space.anyi.openAPI.model.interfaceParam.InterfaceParam
+*/
+public interface InterfaceParamMapper extends BaseMapper<InterfaceParam> {
+
+}
+
+
+
+

+ 133 - 0
src/main/java/space/anyi/openAPI/model/interfaceParam/InterfaceParam.java

@@ -0,0 +1,133 @@
+package space.anyi.openAPI.model.interfaceParam;
+
+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_param
+ */
+@TableName(value ="interface_param")
+@Data
+public class InterfaceParam implements Serializable {
+    /**
+     * 主键
+     */
+    @TableId(type=IdType.ASSIGN_ID)
+    private Long id;
+
+    /**
+     * 接口信息id
+     */
+    private Long interfaceInfoId;
+
+    /**
+     * 参数名称(参数类型为body时,名称使用body)
+     */
+    private String name;
+
+    /**
+     * 参数描述
+     */
+    private String description;
+
+    /**
+     * 参数值
+     */
+    private String value;
+
+    /**
+     * 参数类型(0:query,1:body)
+     */
+    private Integer paramType;
+
+    /**
+     * 创建人
+     */
+    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;
+        }
+        InterfaceParam other = (InterfaceParam) that;
+        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
+            && (this.getInterfaceInfoId() == null ? other.getInterfaceInfoId() == null : this.getInterfaceInfoId().equals(other.getInterfaceInfoId()))
+            && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
+            && (this.getDescription() == null ? other.getDescription() == null : this.getDescription().equals(other.getDescription()))
+            && (this.getValue() == null ? other.getValue() == null : this.getValue().equals(other.getValue()))
+            && (this.getParamType() == null ? other.getParamType() == null : this.getParamType().equals(other.getParamType()))
+            && (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 + ((getInterfaceInfoId() == null) ? 0 : getInterfaceInfoId().hashCode());
+        result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
+        result = prime * result + ((getDescription() == null) ? 0 : getDescription().hashCode());
+        result = prime * result + ((getValue() == null) ? 0 : getValue().hashCode());
+        result = prime * result + ((getParamType() == null) ? 0 : getParamType().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(", interfaceInfoId=").append(interfaceInfoId);
+        sb.append(", name=").append(name);
+        sb.append(", description=").append(description);
+        sb.append(", value=").append(value);
+        sb.append(", paramType=").append(paramType);
+        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();
+    }
+}

+ 61 - 0
src/main/java/space/anyi/openAPI/model/interfaceParam/dto/RequestAddInterfaceParam.java

@@ -0,0 +1,61 @@
+package space.anyi.openAPI.model.interfaceParam.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @ProjectName: yangyi-open-api-platform
+ * @FileName: RequestAddInterfaceParam
+ * @Author: 杨逸
+ * @Data:2025/10/27 10:45
+ * @Description:
+ */
+@ApiModel("新增接口参数")
+@Data
+public class RequestAddInterfaceParam {
+
+    /**
+     * 接口信息id
+     */
+    @ApiModelProperty(value = "接口信息id",required = true)
+    @NotNull(message = "接口信息id不能为空")
+    private Long interfaceInfoId;
+
+    /**
+     * 参数名称(参数类型为body时,名称使用body)
+     */
+    @ApiModelProperty(value = "参数名称",required = true)
+    @NotEmpty(message = "参数名称不能为空")
+    @NotBlank(message = "参数名称不能为空")
+    private String name;
+
+    /**
+     * 参数描述
+     */
+    @ApiModelProperty(value = "参数描述")
+    private String description;
+
+    /**
+     * 参数值
+     */
+    @ApiModelProperty(value = "参数值",required = true)
+    @NotEmpty(message = "参数值不能为空")
+    @NotBlank(message = "参数值不能为空")
+    private String value;
+
+    /**
+     * 参数类型(0:query,1:body)
+     */
+    @ApiModelProperty(value = "参数类型",required = true,example = "0:query,1:body")
+    @NotNull(message = "参数类型不能为空")
+    @Min(value = 0, message = "参数类型不能小于0")
+    @Min(value = 1, message = "参数类型不能大于1")
+    private Integer paramType;
+
+}

+ 65 - 0
src/main/java/space/anyi/openAPI/model/interfaceParam/dto/RequestUpdateInterfaceParam.java

@@ -0,0 +1,65 @@
+package space.anyi.openAPI.model.interfaceParam.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @ProjectName: yangyi-open-api-platform
+ * @FileName: RequestUpdaInterfaceParam
+ * @Author: 杨逸
+ * @Data:2025/10/27 11:09
+ * @Description:
+ */
+@ApiModel("更新接口参数")
+@Data
+public class RequestUpdateInterfaceParam {
+    /**
+     * 主键
+     */
+    @ApiModelProperty(value = "主键ID",required = true)
+    @NotNull(message = "id不能为空")
+    private Long id;
+
+    /**
+     * 接口信息id
+     */
+    @ApiModelProperty(value = "接口信息id",required = true)
+    @NotNull(message = "接口信息id不能为空")
+    private Long interfaceInfoId;
+
+    /**
+     * 参数名称(参数类型为body时,名称使用body)
+     */
+    @ApiModelProperty(value = "参数名称",required = true)
+    @NotEmpty(message = "参数名称不能为空")
+    private String name;
+
+    /**
+     * 参数描述
+     */
+    @ApiModelProperty("参数描述")
+    private String description;
+
+    /**
+     * 参数值
+     */
+    @ApiModelProperty(value = "参数值",required = true)
+    @NotEmpty(message = "参数值不能为空")
+    private String value;
+
+    /**
+     * 参数类型(0:query,1:body)
+     */
+    @ApiModelProperty(value = "参数类型",required = true,example = "0:query,1:body")
+    @NotNull(message = "参数类型不能为空")
+    @Min(value = 0, message = "参数类型不能小于0")
+    @Max(value = 1, message = "参数类型不能大于1")
+    private Integer paramType;
+
+}

+ 44 - 0
src/main/java/space/anyi/openAPI/model/interfaceParam/vo/InterfaceParamVO.java

@@ -0,0 +1,44 @@
+package space.anyi.openAPI.model.interfaceParam.vo;
+
+import lombok.Data;
+
+/**
+ * @ProjectName: yangyi-open-api-platform
+ * @FileName: interfaceParamVO
+ * @Author: 杨逸
+ * @Data:2025/10/27 11:19
+ * @Description:
+ */
+@Data
+public class InterfaceParamVO {
+    /**
+     * 主键
+     */
+    private Long id;
+
+    /**
+     * 接口信息id
+     */
+    private Long interfaceInfoId;
+
+    /**
+     * 参数名称(参数类型为body时,名称使用body)
+     */
+    private String name;
+
+    /**
+     * 参数描述
+     */
+    private String description;
+
+    /**
+     * 参数值
+     */
+    private String value;
+
+    /**
+     * 参数类型(0:query,1:body)
+     */
+    private Integer paramType;
+
+}

+ 17 - 0
src/main/java/space/anyi/openAPI/service/InterfaceParamService.java

@@ -0,0 +1,17 @@
+package space.anyi.openAPI.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import space.anyi.openAPI.model.interfaceParam.InterfaceParam;
+import space.anyi.openAPI.model.interfaceParam.vo.InterfaceParamVO;
+
+import java.util.List;
+
+/**
+* @author 杨逸
+* @description 针对表【interface_param(接口参数)】的数据库操作Service
+* @createDate 2025-10-27 10:32:58
+*/
+public interface InterfaceParamService extends IService<InterfaceParam> {
+
+    List<InterfaceParamVO> getInterfaceParamByInterfaceInfoId(Long interfaceInfoId);
+}

+ 33 - 0
src/main/java/space/anyi/openAPI/service/impl/InterfaceParamServiceImpl.java

@@ -0,0 +1,33 @@
+package space.anyi.openAPI.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+import space.anyi.openAPI.mapper.InterfaceParamMapper;
+import space.anyi.openAPI.model.interfaceParam.InterfaceParam;
+import space.anyi.openAPI.model.interfaceParam.vo.InterfaceParamVO;
+import space.anyi.openAPI.service.InterfaceParamService;
+import space.anyi.openAPI.util.BeanCopyUtil;
+
+import java.util.List;
+
+/**
+* @author 杨逸
+* @description 针对表【interface_param(接口参数)】的数据库操作Service实现
+* @createDate 2025-10-27 10:32:58
+*/
+@Service
+public class InterfaceParamServiceImpl extends ServiceImpl<InterfaceParamMapper, InterfaceParam>
+    implements InterfaceParamService{
+
+    @Override
+    public List<InterfaceParamVO> getInterfaceParamByInterfaceInfoId(Long interfaceInfoId) {
+        LambdaQueryWrapper<InterfaceParam> lambdaQueryWrapper = new LambdaQueryWrapper<InterfaceParam>().eq(InterfaceParam::getInterfaceInfoId, interfaceInfoId);
+        List<InterfaceParam> list = list(lambdaQueryWrapper);
+        return BeanCopyUtil.copyBean(list, InterfaceParamVO.class);
+    }
+}
+
+
+
+

+ 26 - 0
src/main/resources/mapper/InterfaceParamMapper.xml

@@ -0,0 +1,26 @@
+<?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.InterfaceParamMapper">
+
+    <resultMap id="BaseResultMap" type="space.anyi.openAPI.model.interfaceParam.InterfaceParam">
+            <id property="id" column="id" jdbcType="BIGINT"/>
+            <result property="interfaceInfoId" column="interface_info_id" jdbcType="BIGINT"/>
+            <result property="name" column="name" jdbcType="VARCHAR"/>
+            <result property="description" column="description" jdbcType="VARCHAR"/>
+            <result property="value" column="value" jdbcType="VARCHAR"/>
+            <result property="paramType" column="param_type" jdbcType="INTEGER"/>
+            <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,interface_info_id,name,
+        description,value,param_type,
+        user_id,create_time,update_time,
+        delete_flag
+    </sql>
+</mapper>