网关接口管理增加唯一编码apiCode
This commit is contained in:
parent
9d959de9cc
commit
48fc40334c
@ -124,7 +124,7 @@ public class GlobalExceptionHandler
|
||||
{
|
||||
log.error(e.getMessage(), e);
|
||||
String message = e.getAllErrors().get(0).getDefaultMessage();
|
||||
return AjaxResult.error(message);
|
||||
return AjaxResult.error(HttpStatus.BAD_REQUEST,message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,6 +77,7 @@ public class GatewayInterfaceInfoController extends BaseController
|
||||
GatewayInterfaceInfoListVO vo = new GatewayInterfaceInfoListVO();
|
||||
vo.setId(info.getId());
|
||||
vo.setInterfaceName(info.getInterfaceName());
|
||||
vo.setApiCode(info.getApiCode());
|
||||
vo.setInterfacePath(info.getInterfacePath());
|
||||
vo.setRequestMethod(info.getRequestMethod());
|
||||
vo.setDescription(info.getDescription());
|
||||
@ -119,6 +120,7 @@ public class GatewayInterfaceInfoController extends BaseController
|
||||
|
||||
vo.setId(gatewayInterfaceInfo.getId());
|
||||
vo.setInterfaceName(gatewayInterfaceInfo.getInterfaceName());
|
||||
vo.setApiCode(gatewayInterfaceInfo.getApiCode());
|
||||
vo.setInterfacePath(gatewayInterfaceInfo.getInterfacePath());
|
||||
vo.setRequestMethod(gatewayInterfaceInfo.getRequestMethod());
|
||||
vo.setDescription(gatewayInterfaceInfo.getDescription());
|
||||
|
@ -7,6 +7,9 @@ import com.sf.common.annotation.Excel;
|
||||
import com.sf.common.core.domain.BaseEntity;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
|
||||
/**
|
||||
* 接口管理对象 Gateway_interface_info
|
||||
@ -30,6 +33,10 @@ public class GatewayInterfaceInfo extends BaseEntity
|
||||
@ApiModelProperty("接口名称")
|
||||
private String interfaceName;
|
||||
|
||||
/** api编码 */
|
||||
@ApiModelProperty("接口编码")
|
||||
private String apiCode;
|
||||
|
||||
/** 接口路径 */
|
||||
@Excel(name = "接口路径")
|
||||
@ApiModelProperty("接口名称")
|
||||
@ -69,9 +76,6 @@ public class GatewayInterfaceInfo extends BaseEntity
|
||||
@ApiModelProperty("应用编号")
|
||||
private String appCode;
|
||||
|
||||
@ApiModelProperty("请求路径是否是正则表达式,0否,1是")
|
||||
private Boolean uriRegular;
|
||||
|
||||
@ApiModelProperty("网关服务id")
|
||||
private Long serverId;
|
||||
|
||||
|
@ -10,6 +10,7 @@ import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@ -30,6 +31,12 @@ public class InsertGatewayInterfaceInfoDTO {
|
||||
@ApiModelProperty("接口名称")
|
||||
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个字符")
|
||||
@NotBlank(message = "接口路径不能为空")
|
||||
@ApiModelProperty("接口路径")
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.sf.service.gateway.domain.dto;
|
||||
|
||||
import com.sf.common.annotation.Excel;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
@ -8,6 +9,7 @@ import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@ -32,6 +34,12 @@ public class UpdateGatewayInterfaceInfoDTO {
|
||||
@ApiModelProperty("接口名称")
|
||||
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个字符")
|
||||
@NotBlank(message = "接口路径不能为空")
|
||||
@ApiModelProperty("接口路径")
|
||||
|
@ -6,6 +6,8 @@ import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ -29,6 +31,11 @@ public class GatewayInterfaceInfoDetailedVO {
|
||||
@ApiModelProperty("接口名称")
|
||||
private String interfaceName;
|
||||
|
||||
/** api编码 */
|
||||
@Excel(name = "接口编码")
|
||||
@ApiModelProperty("接口编码")
|
||||
private String apiCode;
|
||||
|
||||
/** 接口路径 */
|
||||
@Excel(name = "接口路径")
|
||||
@ApiModelProperty("接口名称")
|
||||
|
@ -30,6 +30,11 @@ public class GatewayInterfaceInfoListVO {
|
||||
@ApiModelProperty("接口名称")
|
||||
private String interfaceName;
|
||||
|
||||
/** api编码 */
|
||||
@Excel(name = "接口编码")
|
||||
@ApiModelProperty("接口编码")
|
||||
private String apiCode;
|
||||
|
||||
/** 接口路径 */
|
||||
@Excel(name = "接口路径")
|
||||
@ApiModelProperty("接口名称")
|
||||
|
@ -84,13 +84,11 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
|
||||
Date nowDate = DateUtils.getNowDate();
|
||||
gatewayInterfaceInfo.setCreateTime(nowDate);
|
||||
gatewayInterfaceInfo.setUpdateTime(nowDate);
|
||||
Assert.hasText(gatewayInterfaceInfo.getInterfacePath(), "接口路径不能为空");
|
||||
gatewayInterfaceInfo.setUriRegular(RegexUtils.isRegex(gatewayInterfaceInfo.getInterfacePath()));
|
||||
try {
|
||||
gatewayInterfaceInfoMapper.insertGatewayInterfaceInfo(gatewayInterfaceInfo);
|
||||
return gatewayInterfaceInfo.getId();
|
||||
} catch (DuplicateKeyException e) {
|
||||
throw new IllegalArgumentException("同名接口,版本不可重复!");
|
||||
throw new IllegalArgumentException("接口编码已存在!");
|
||||
}
|
||||
|
||||
}
|
||||
@ -117,13 +115,10 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
|
||||
public int updateGatewayInterfaceInfo(GatewayInterfaceInfo gatewayInterfaceInfo) {
|
||||
gatewayInterfaceInfo.setModified(SecurityUtils.getUsername());
|
||||
gatewayInterfaceInfo.setUpdateTime(DateUtils.getNowDate());
|
||||
String interfacePath = gatewayInterfaceInfo.getInterfacePath();
|
||||
Assert.hasText(interfacePath, "接口路径不能为空");
|
||||
gatewayInterfaceInfo.setUriRegular(RegexUtils.isRegex(interfacePath));
|
||||
try {
|
||||
return gatewayInterfaceInfoMapper.updateGatewayInterfaceInfo(gatewayInterfaceInfo);
|
||||
} catch (DuplicateKeyException e) {
|
||||
throw new IllegalArgumentException("同名接口,版本不可重复!");
|
||||
throw new IllegalArgumentException("接口编码已存在!");
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,6 +188,7 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
|
||||
public Long insertGatewayInterfaceInfoAndBindStrategy(InsertGatewayInterfaceInfoDTO dto) {
|
||||
GatewayInterfaceInfo gatewayInterfaceInfo = new GatewayInterfaceInfo();
|
||||
gatewayInterfaceInfo.setInterfaceName(dto.getInterfaceName());
|
||||
gatewayInterfaceInfo.setApiCode(dto.getApiCode());
|
||||
gatewayInterfaceInfo.setInterfacePath(dto.getInterfacePath());
|
||||
gatewayInterfaceInfo.setRequestMethod(dto.getRequestMethod());
|
||||
gatewayInterfaceInfo.setDescription(dto.getDescription());
|
||||
@ -217,6 +213,7 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
|
||||
GatewayInterfaceInfo gatewayInterfaceInfo = new GatewayInterfaceInfo();
|
||||
gatewayInterfaceInfo.setId(dto.getId());
|
||||
gatewayInterfaceInfo.setInterfaceName(dto.getInterfaceName());
|
||||
gatewayInterfaceInfo.setApiCode(dto.getApiCode());
|
||||
gatewayInterfaceInfo.setInterfacePath(dto.getInterfacePath());
|
||||
gatewayInterfaceInfo.setRequestMethod(dto.getRequestMethod());
|
||||
gatewayInterfaceInfo.setDescription(dto.getDescription());
|
||||
|
@ -7,6 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<resultMap type="GatewayInterfaceInfo" id="GatewayInterfaceInfoResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="interfaceName" column="interface_name" />
|
||||
<result property="apiCode" column="api_code" />
|
||||
<result property="interfacePath" column="interface_path" />
|
||||
<result property="requestMethod" column="request_method" />
|
||||
<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="modified" column="modified" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="uriRegular" column="uri_regular" />
|
||||
<result property="serverId" column="server_id" />
|
||||
</resultMap>
|
||||
|
||||
<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,
|
||||
create_time, modified, update_time ,
|
||||
uri_regular,server_id
|
||||
server_id
|
||||
from Gateway_interface_info
|
||||
</sql>
|
||||
|
||||
@ -33,6 +33,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<include refid="selectGatewayInterfaceInfoVo"/>
|
||||
<where>
|
||||
<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="appCode != null and appCode != ''"> and app_code = #{appCode}</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
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<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="requestMethod != null and requestMethod != ''">request_method,</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="created != null">created,</if>
|
||||
<if test="modified != null">modified,</if>
|
||||
<if test="uriRegular != null">uri_regular,</if>
|
||||
<if test="serverId != null">server_id,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<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="requestMethod != null and requestMethod != ''">#{requestMethod},</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="created != null">#{created},</if>
|
||||
<if test="modified != null">#{modified},</if>
|
||||
<if test="uriRegular != null">#{uriRegular},</if>
|
||||
<if test="serverId != null">#{serverId},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
@ -99,6 +100,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
update Gateway_interface_info
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<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="requestMethod != null and requestMethod != ''">request_method = #{requestMethod},</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="modified != null">modified = #{modified},</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>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
|
Loading…
x
Reference in New Issue
Block a user