网关接口管理增加唯一编码apiCode

This commit is contained in:
akun 2024-05-07 16:19:40 +08:00
parent 9d959de9cc
commit 48fc40334c
9 changed files with 48 additions and 17 deletions

View File

@ -124,7 +124,7 @@ public class GlobalExceptionHandler
{ {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
String message = e.getAllErrors().get(0).getDefaultMessage(); String message = e.getAllErrors().get(0).getDefaultMessage();
return AjaxResult.error(message); return AjaxResult.error(HttpStatus.BAD_REQUEST,message);
} }
/** /**

View File

@ -77,6 +77,7 @@ public class GatewayInterfaceInfoController extends BaseController
GatewayInterfaceInfoListVO vo = new GatewayInterfaceInfoListVO(); GatewayInterfaceInfoListVO vo = new GatewayInterfaceInfoListVO();
vo.setId(info.getId()); vo.setId(info.getId());
vo.setInterfaceName(info.getInterfaceName()); vo.setInterfaceName(info.getInterfaceName());
vo.setApiCode(info.getApiCode());
vo.setInterfacePath(info.getInterfacePath()); vo.setInterfacePath(info.getInterfacePath());
vo.setRequestMethod(info.getRequestMethod()); vo.setRequestMethod(info.getRequestMethod());
vo.setDescription(info.getDescription()); vo.setDescription(info.getDescription());
@ -119,6 +120,7 @@ public class GatewayInterfaceInfoController extends BaseController
vo.setId(gatewayInterfaceInfo.getId()); vo.setId(gatewayInterfaceInfo.getId());
vo.setInterfaceName(gatewayInterfaceInfo.getInterfaceName()); vo.setInterfaceName(gatewayInterfaceInfo.getInterfaceName());
vo.setApiCode(gatewayInterfaceInfo.getApiCode());
vo.setInterfacePath(gatewayInterfaceInfo.getInterfacePath()); vo.setInterfacePath(gatewayInterfaceInfo.getInterfacePath());
vo.setRequestMethod(gatewayInterfaceInfo.getRequestMethod()); vo.setRequestMethod(gatewayInterfaceInfo.getRequestMethod());
vo.setDescription(gatewayInterfaceInfo.getDescription()); vo.setDescription(gatewayInterfaceInfo.getDescription());

View File

@ -7,6 +7,9 @@ import com.sf.common.annotation.Excel;
import com.sf.common.core.domain.BaseEntity; import com.sf.common.core.domain.BaseEntity;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
/** /**
* 接口管理对象 Gateway_interface_info * 接口管理对象 Gateway_interface_info
@ -30,6 +33,10 @@ public class GatewayInterfaceInfo extends BaseEntity
@ApiModelProperty("接口名称") @ApiModelProperty("接口名称")
private String interfaceName; private String interfaceName;
/** api编码 */
@ApiModelProperty("接口编码")
private String apiCode;
/** 接口路径 */ /** 接口路径 */
@Excel(name = "接口路径") @Excel(name = "接口路径")
@ApiModelProperty("接口名称") @ApiModelProperty("接口名称")
@ -69,9 +76,6 @@ public class GatewayInterfaceInfo extends BaseEntity
@ApiModelProperty("应用编号") @ApiModelProperty("应用编号")
private String appCode; private String appCode;
@ApiModelProperty("请求路径是否是正则表达式,0否1是")
private Boolean uriRegular;
@ApiModelProperty("网关服务id") @ApiModelProperty("网关服务id")
private Long serverId; private Long serverId;

View File

@ -10,6 +10,7 @@ import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.List; import java.util.List;
@ -30,6 +31,12 @@ public class InsertGatewayInterfaceInfoDTO {
@ApiModelProperty("接口名称") @ApiModelProperty("接口名称")
private String interfaceName; private String interfaceName;
/** api编码 */
@Excel(name = "接口编码")
@NotBlank(message = "接口编码不能为空")
@Pattern(regexp = "^[a-zA-Z_]\\w{0,63}$",message = "接口编码只能以字母或下划线开头只能包含字母、数字、下划线不超过64个字符")
private String apiCode;
@Length(max = 200,message = "接口名称不能超过200个字符") @Length(max = 200,message = "接口名称不能超过200个字符")
@NotBlank(message = "接口路径不能为空") @NotBlank(message = "接口路径不能为空")
@ApiModelProperty("接口路径") @ApiModelProperty("接口路径")

View File

@ -1,5 +1,6 @@
package com.sf.service.gateway.domain.dto; package com.sf.service.gateway.domain.dto;
import com.sf.common.annotation.Excel;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -8,6 +9,7 @@ import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.List; import java.util.List;
@ -32,6 +34,12 @@ public class UpdateGatewayInterfaceInfoDTO {
@ApiModelProperty("接口名称") @ApiModelProperty("接口名称")
private String interfaceName; private String interfaceName;
/** api编码 */
@Excel(name = "接口编码")
@NotBlank(message = "接口编码不能为空")
@Pattern(regexp = "^[a-zA-Z_]\\w{0,63}$",message = "接口编码只能以字母或下划线开头只能包含字母、数字、下划线不超过64个字符")
private String apiCode;
@Length(max = 200,message = "接口名称不能超过200个字符") @Length(max = 200,message = "接口名称不能超过200个字符")
@NotBlank(message = "接口路径不能为空") @NotBlank(message = "接口路径不能为空")
@ApiModelProperty("接口路径") @ApiModelProperty("接口路径")

View File

@ -6,6 +6,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -29,6 +31,11 @@ public class GatewayInterfaceInfoDetailedVO {
@ApiModelProperty("接口名称") @ApiModelProperty("接口名称")
private String interfaceName; private String interfaceName;
/** api编码 */
@Excel(name = "接口编码")
@ApiModelProperty("接口编码")
private String apiCode;
/** 接口路径 */ /** 接口路径 */
@Excel(name = "接口路径") @Excel(name = "接口路径")
@ApiModelProperty("接口名称") @ApiModelProperty("接口名称")

View File

@ -30,6 +30,11 @@ public class GatewayInterfaceInfoListVO {
@ApiModelProperty("接口名称") @ApiModelProperty("接口名称")
private String interfaceName; private String interfaceName;
/** api编码 */
@Excel(name = "接口编码")
@ApiModelProperty("接口编码")
private String apiCode;
/** 接口路径 */ /** 接口路径 */
@Excel(name = "接口路径") @Excel(name = "接口路径")
@ApiModelProperty("接口名称") @ApiModelProperty("接口名称")

View File

@ -84,13 +84,11 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
Date nowDate = DateUtils.getNowDate(); Date nowDate = DateUtils.getNowDate();
gatewayInterfaceInfo.setCreateTime(nowDate); gatewayInterfaceInfo.setCreateTime(nowDate);
gatewayInterfaceInfo.setUpdateTime(nowDate); gatewayInterfaceInfo.setUpdateTime(nowDate);
Assert.hasText(gatewayInterfaceInfo.getInterfacePath(), "接口路径不能为空");
gatewayInterfaceInfo.setUriRegular(RegexUtils.isRegex(gatewayInterfaceInfo.getInterfacePath()));
try { try {
gatewayInterfaceInfoMapper.insertGatewayInterfaceInfo(gatewayInterfaceInfo); gatewayInterfaceInfoMapper.insertGatewayInterfaceInfo(gatewayInterfaceInfo);
return gatewayInterfaceInfo.getId(); return gatewayInterfaceInfo.getId();
} catch (DuplicateKeyException e) { } catch (DuplicateKeyException e) {
throw new IllegalArgumentException("同名接口,版本不可重复!"); throw new IllegalArgumentException("接口编码已存在!");
} }
} }
@ -117,13 +115,10 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
public int updateGatewayInterfaceInfo(GatewayInterfaceInfo gatewayInterfaceInfo) { public int updateGatewayInterfaceInfo(GatewayInterfaceInfo gatewayInterfaceInfo) {
gatewayInterfaceInfo.setModified(SecurityUtils.getUsername()); gatewayInterfaceInfo.setModified(SecurityUtils.getUsername());
gatewayInterfaceInfo.setUpdateTime(DateUtils.getNowDate()); gatewayInterfaceInfo.setUpdateTime(DateUtils.getNowDate());
String interfacePath = gatewayInterfaceInfo.getInterfacePath();
Assert.hasText(interfacePath, "接口路径不能为空");
gatewayInterfaceInfo.setUriRegular(RegexUtils.isRegex(interfacePath));
try { try {
return gatewayInterfaceInfoMapper.updateGatewayInterfaceInfo(gatewayInterfaceInfo); return gatewayInterfaceInfoMapper.updateGatewayInterfaceInfo(gatewayInterfaceInfo);
} catch (DuplicateKeyException e) { } catch (DuplicateKeyException e) {
throw new IllegalArgumentException("同名接口,版本不可重复!"); throw new IllegalArgumentException("接口编码已存在!");
} }
} }
@ -193,6 +188,7 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
public Long insertGatewayInterfaceInfoAndBindStrategy(InsertGatewayInterfaceInfoDTO dto) { public Long insertGatewayInterfaceInfoAndBindStrategy(InsertGatewayInterfaceInfoDTO dto) {
GatewayInterfaceInfo gatewayInterfaceInfo = new GatewayInterfaceInfo(); GatewayInterfaceInfo gatewayInterfaceInfo = new GatewayInterfaceInfo();
gatewayInterfaceInfo.setInterfaceName(dto.getInterfaceName()); gatewayInterfaceInfo.setInterfaceName(dto.getInterfaceName());
gatewayInterfaceInfo.setApiCode(dto.getApiCode());
gatewayInterfaceInfo.setInterfacePath(dto.getInterfacePath()); gatewayInterfaceInfo.setInterfacePath(dto.getInterfacePath());
gatewayInterfaceInfo.setRequestMethod(dto.getRequestMethod()); gatewayInterfaceInfo.setRequestMethod(dto.getRequestMethod());
gatewayInterfaceInfo.setDescription(dto.getDescription()); gatewayInterfaceInfo.setDescription(dto.getDescription());
@ -217,6 +213,7 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
GatewayInterfaceInfo gatewayInterfaceInfo = new GatewayInterfaceInfo(); GatewayInterfaceInfo gatewayInterfaceInfo = new GatewayInterfaceInfo();
gatewayInterfaceInfo.setId(dto.getId()); gatewayInterfaceInfo.setId(dto.getId());
gatewayInterfaceInfo.setInterfaceName(dto.getInterfaceName()); gatewayInterfaceInfo.setInterfaceName(dto.getInterfaceName());
gatewayInterfaceInfo.setApiCode(dto.getApiCode());
gatewayInterfaceInfo.setInterfacePath(dto.getInterfacePath()); gatewayInterfaceInfo.setInterfacePath(dto.getInterfacePath());
gatewayInterfaceInfo.setRequestMethod(dto.getRequestMethod()); gatewayInterfaceInfo.setRequestMethod(dto.getRequestMethod());
gatewayInterfaceInfo.setDescription(dto.getDescription()); gatewayInterfaceInfo.setDescription(dto.getDescription());

View File

@ -7,6 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="GatewayInterfaceInfo" id="GatewayInterfaceInfoResult"> <resultMap type="GatewayInterfaceInfo" id="GatewayInterfaceInfoResult">
<result property="id" column="id" /> <result property="id" column="id" />
<result property="interfaceName" column="interface_name" /> <result property="interfaceName" column="interface_name" />
<result property="apiCode" column="api_code" />
<result property="interfacePath" column="interface_path" /> <result property="interfacePath" column="interface_path" />
<result property="requestMethod" column="request_method" /> <result property="requestMethod" column="request_method" />
<result property="description" column="description" /> <result property="description" column="description" />
@ -17,15 +18,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
<result property="modified" column="modified" /> <result property="modified" column="modified" />
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time" />
<result property="uriRegular" column="uri_regular" />
<result property="serverId" column="server_id" /> <result property="serverId" column="server_id" />
</resultMap> </resultMap>
<sql id="selectGatewayInterfaceInfoVo"> <sql id="selectGatewayInterfaceInfoVo">
select id, interface_name, interface_path, request_method, select id, interface_name,api_code, interface_path, request_method,
description, version, status, document, created, description, version, status, document, created,
create_time, modified, update_time , create_time, modified, update_time ,
uri_regular,server_id server_id
from Gateway_interface_info from Gateway_interface_info
</sql> </sql>
@ -33,6 +33,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectGatewayInterfaceInfoVo"/> <include refid="selectGatewayInterfaceInfoVo"/>
<where> <where>
<if test="interfaceName != null and interfaceName != ''"> and interface_name like concat('%', #{interfaceName}, '%')</if> <if test="interfaceName != null and interfaceName != ''"> and interface_name like concat('%', #{interfaceName}, '%')</if>
<if test="apiCode != null and apiCode != ''"> and api_code = #{apiCode}</if>
<if test="status != null and status != ''"> and status = #{status}</if> <if test="status != null and status != ''"> and status = #{status}</if>
<if test="appCode != null and appCode != ''"> and app_code = #{appCode}</if> <if test="appCode != null and appCode != ''"> and app_code = #{appCode}</if>
<if test="interfacePath != null and interfacePath != ''"> and interface_path = #{interfacePath}</if> <if test="interfacePath != null and interfacePath != ''"> and interface_path = #{interfacePath}</if>
@ -63,6 +64,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
insert into Gateway_interface_info insert into Gateway_interface_info
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="interfaceName != null and interfaceName != ''">interface_name,</if> <if test="interfaceName != null and interfaceName != ''">interface_name,</if>
<if test="apiCode != null and apiCode != ''">api_code,</if>
<if test="interfacePath != null and interfacePath != ''">interface_path,</if> <if test="interfacePath != null and interfacePath != ''">interface_path,</if>
<if test="requestMethod != null and requestMethod != ''">request_method,</if> <if test="requestMethod != null and requestMethod != ''">request_method,</if>
<if test="description != null">description,</if> <if test="description != null">description,</if>
@ -74,11 +76,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="appCode != null">app_code,</if> <if test="appCode != null">app_code,</if>
<if test="created != null">created,</if> <if test="created != null">created,</if>
<if test="modified != null">modified,</if> <if test="modified != null">modified,</if>
<if test="uriRegular != null">uri_regular,</if>
<if test="serverId != null">server_id,</if> <if test="serverId != null">server_id,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="interfaceName != null and interfaceName != ''">#{interfaceName},</if> <if test="interfaceName != null and interfaceName != ''">#{interfaceName},</if>
<if test="apiCode != null and apiCode != ''">#{apiCode},</if>
<if test="interfacePath != null and interfacePath != ''">#{interfacePath},</if> <if test="interfacePath != null and interfacePath != ''">#{interfacePath},</if>
<if test="requestMethod != null and requestMethod != ''">#{requestMethod},</if> <if test="requestMethod != null and requestMethod != ''">#{requestMethod},</if>
<if test="description != null">#{description},</if> <if test="description != null">#{description},</if>
@ -90,7 +92,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="appCode != null">#{appCode},</if> <if test="appCode != null">#{appCode},</if>
<if test="created != null">#{created},</if> <if test="created != null">#{created},</if>
<if test="modified != null">#{modified},</if> <if test="modified != null">#{modified},</if>
<if test="uriRegular != null">#{uriRegular},</if>
<if test="serverId != null">#{serverId},</if> <if test="serverId != null">#{serverId},</if>
</trim> </trim>
</insert> </insert>
@ -99,6 +100,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update Gateway_interface_info update Gateway_interface_info
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="interfaceName != null and interfaceName != ''">interface_name = #{interfaceName},</if> <if test="interfaceName != null and interfaceName != ''">interface_name = #{interfaceName},</if>
<if test="apiCode != null and apiCode != ''">api_code = #{apiCode},</if>
<if test="interfacePath != null and interfacePath != ''">interface_path = #{interfacePath},</if> <if test="interfacePath != null and interfacePath != ''">interface_path = #{interfacePath},</if>
<if test="requestMethod != null and requestMethod != ''">request_method = #{requestMethod},</if> <if test="requestMethod != null and requestMethod != ''">request_method = #{requestMethod},</if>
<if test="description != null">description = #{description},</if> <if test="description != null">description = #{description},</if>
@ -107,7 +109,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="document != null">document = #{document},</if> <if test="document != null">document = #{document},</if>
<if test="modified != null">modified = #{modified},</if> <if test="modified != null">modified = #{modified},</if>
<if test="updateTime != null">update_time = #{updateTime},</if> <if test="updateTime != null">update_time = #{updateTime},</if>
<if test="uriRegular != null">uri_regular = #{uriRegular},</if>
<if test="serverId != null">server_id = #{serverId},</if> <if test="serverId != null">server_id = #{serverId},</if>
</trim> </trim>
where id = #{id} where id = #{id}