网关Mock配置管理
This commit is contained in:
parent
c3b1d01968
commit
c1666350f3
61
sf-common/src/main/java/com/sf/common/utils/JSONUtils.java
Normal file
61
sf-common/src/main/java/com/sf/common/utils/JSONUtils.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
|
||||||
|
package com.sf.common.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author zoukun
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@UtilityClass
|
||||||
|
public class JSONUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否为JSONObject
|
||||||
|
* @param obj instanceof String ? parseObject
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isJSONObject(Object obj) {
|
||||||
|
if (obj instanceof JSONObject) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj instanceof String) {
|
||||||
|
try {
|
||||||
|
JSONObject json = JSON.parseObject((String) obj);
|
||||||
|
return json != null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error( "JSONUtils.isJSONObject catch \n" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 判断是否为JSONArray
|
||||||
|
* @param obj instanceof String ? parseArray
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isJSONArray(Object obj) {
|
||||||
|
if (obj instanceof JSONArray) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj instanceof String) {
|
||||||
|
try {
|
||||||
|
JSONArray json = JSON.parseArray((String) obj);
|
||||||
|
return json != null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("JSONUtils.isJSONArray catch \n" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -5,16 +5,13 @@ import java.util.function.Function;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import com.sf.service.gateway.domain.*;
|
||||||
import com.sf.service.index.utils.AppUtils;
|
import com.sf.service.index.utils.AppUtils;
|
||||||
import com.sf.file.domain.SysOss;
|
import com.sf.file.domain.SysOss;
|
||||||
import com.sf.file.service.ISysOssService;
|
import com.sf.file.service.ISysOssService;
|
||||||
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
|
|
||||||
import com.sf.service.gateway.domain.GatewayInterfaceLinkStrategy;
|
|
||||||
import com.sf.service.gateway.domain.GatewayServer;
|
|
||||||
import com.sf.service.gateway.domain.GatewayStrategy;
|
|
||||||
import com.sf.service.gateway.domain.dto.InsertGatewayInterfaceInfoDTO;
|
|
||||||
import com.sf.service.gateway.domain.dto.UpdateDataStatusDTO;
|
import com.sf.service.gateway.domain.dto.UpdateDataStatusDTO;
|
||||||
import com.sf.service.gateway.domain.dto.UpdateGatewayInterfaceInfoDTO;
|
import com.sf.service.gateway.domain.dto.InsertOrUpdateGatewayInterfaceInfoDTO;
|
||||||
import com.sf.service.gateway.domain.vo.GatewayInterfaceInfoDetailedVO;
|
import com.sf.service.gateway.domain.vo.GatewayInterfaceInfoDetailedVO;
|
||||||
import com.sf.service.gateway.domain.vo.GatewayInterfaceInfoListVO;
|
import com.sf.service.gateway.domain.vo.GatewayInterfaceInfoListVO;
|
||||||
import com.sf.service.gateway.enums.GatewayDataStatus;
|
import com.sf.service.gateway.enums.GatewayDataStatus;
|
||||||
@ -100,10 +97,11 @@ public class GatewayInterfaceInfoController extends BaseController {
|
|||||||
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
||||||
GatewayInterfaceInfo gatewayInterfaceInfo = gatewayInterfaceInfoService.selectGatewayInterfaceInfoById(id);
|
GatewayInterfaceInfo gatewayInterfaceInfo = gatewayInterfaceInfoService.selectGatewayInterfaceInfoById(id);
|
||||||
List<GatewayInterfaceLinkStrategy> linkList = gatewayInterfaceInfoService.selectGatewayInterfaceLinkStrategyByInterfaceIds(Collections.singleton(id));
|
List<GatewayInterfaceLinkStrategy> linkList = gatewayInterfaceInfoService.selectGatewayInterfaceLinkStrategyByInterfaceIds(Collections.singleton(id));
|
||||||
|
List<GatewayInterfaceMock> mockExpectations = gatewayInterfaceInfoService.selectGatewayInterfaceMockListByInterfaceIds(Collections.singleton(id));
|
||||||
GatewayServer gatewayServer = gatewayServerService.selectGatewayServerById(gatewayInterfaceInfo.getServerId());
|
GatewayServer gatewayServer = gatewayServerService.selectGatewayServerById(gatewayInterfaceInfo.getServerId());
|
||||||
List<GatewayStrategy> strategyList = gatewayStrategyService.selectGatewayStrategyByIds(linkList.stream().map(GatewayInterfaceLinkStrategy::getStrategyId).collect(Collectors.toSet()));
|
List<GatewayStrategy> strategyList = gatewayStrategyService.selectGatewayStrategyByIds(linkList.stream().map(GatewayInterfaceLinkStrategy::getStrategyId).collect(Collectors.toSet()));
|
||||||
SysOss document = sysOssService.selectSysOssById(gatewayInterfaceInfo.getDocument());
|
SysOss document = sysOssService.selectSysOssById(gatewayInterfaceInfo.getDocument());
|
||||||
GatewayInterfaceInfoDetailedVO vo = GatewayInterfaceInfoDetailedVO.convert(gatewayInterfaceInfo,gatewayServer,strategyList,document);
|
GatewayInterfaceInfoDetailedVO vo = GatewayInterfaceInfoDetailedVO.convert(gatewayInterfaceInfo,gatewayServer,strategyList,document,mockExpectations);
|
||||||
// TODO 调用次数和平均时间暂时没有来源
|
// TODO 调用次数和平均时间暂时没有来源
|
||||||
vo.setNumberOfCalls(0L);
|
vo.setNumberOfCalls(0L);
|
||||||
vo.setAverageResponseTime(0L);
|
vo.setAverageResponseTime(0L);
|
||||||
@ -114,7 +112,7 @@ public class GatewayInterfaceInfoController extends BaseController {
|
|||||||
@PreAuthorize("@ss.hasPermi('gateway:interface:add')")
|
@PreAuthorize("@ss.hasPermi('gateway:interface:add')")
|
||||||
@Log(title = "接口管理", businessType = BusinessType.INSERT)
|
@Log(title = "接口管理", businessType = BusinessType.INSERT)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@Validated @RequestBody InsertGatewayInterfaceInfoDTO dto) {
|
public AjaxResult add(@Validated @RequestBody InsertOrUpdateGatewayInterfaceInfoDTO dto) {
|
||||||
return success(gatewayInterfaceInfoService.insertGatewayInterfaceInfoAndBindStrategy(dto));
|
return success(gatewayInterfaceInfoService.insertGatewayInterfaceInfoAndBindStrategy(dto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +120,8 @@ public class GatewayInterfaceInfoController extends BaseController {
|
|||||||
@PreAuthorize("@ss.hasPermi('gateway:interface:edit')")
|
@PreAuthorize("@ss.hasPermi('gateway:interface:edit')")
|
||||||
@Log(title = "接口管理", businessType = BusinessType.UPDATE)
|
@Log(title = "接口管理", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@Validated @RequestBody UpdateGatewayInterfaceInfoDTO dto) {
|
public AjaxResult edit(@Validated @RequestBody InsertOrUpdateGatewayInterfaceInfoDTO dto) {
|
||||||
|
Assert.notNull(dto.getId(),"接口ID不能为空");
|
||||||
return success(gatewayInterfaceInfoService.updateGatewayInterfaceInfoAndBindStrategy(dto));
|
return success(gatewayInterfaceInfoService.updateGatewayInterfaceInfoAndBindStrategy(dto));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,8 +85,11 @@ public class GatewayInterfaceInfo extends BaseEntity
|
|||||||
@ApiModelProperty("Mock状态(0=停用,1=启用)")
|
@ApiModelProperty("Mock状态(0=停用,1=启用)")
|
||||||
private String mockStatus;
|
private String mockStatus;
|
||||||
|
|
||||||
@ApiModelProperty("Mock响应,json格式")
|
@ApiModelProperty("Mock默认响应HTTP状态码")
|
||||||
private String mockResponse;
|
private Integer mockDefaultHttpStatus;
|
||||||
|
|
||||||
|
@ApiModelProperty("Mock默认响应,json格式")
|
||||||
|
private String mockDefaultResponse;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
package com.sf.service.gateway.domain;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 网关服务-接口Mock配置表
|
||||||
|
* @TableName Gateway_interface_mock
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class GatewayInterfaceMock {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("ID")
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 接口id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("接口id")
|
||||||
|
private Long interfaceId;
|
||||||
|
/**
|
||||||
|
* http状态码
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("http状态码")
|
||||||
|
private Integer httpStatus;
|
||||||
|
/**
|
||||||
|
* 匹配条件
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("匹配条件")
|
||||||
|
private String matchConditions;
|
||||||
|
/**
|
||||||
|
* Mock响应,JSON字符串
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("Mock响应,JSON字符串")
|
||||||
|
private String mockResponse;
|
||||||
|
/**
|
||||||
|
* 状态(0停用 1启用)
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("状态(0停用 1启用)")
|
||||||
|
private String status;
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("排序")
|
||||||
|
private Integer orderNum;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,76 +0,0 @@
|
|||||||
package com.sf.service.gateway.domain.dto;
|
|
||||||
|
|
||||||
import com.sf.common.annotation.Excel;
|
|
||||||
import com.sf.common.core.domain.BaseEntity;
|
|
||||||
import com.sf.file.domain.SysOss;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import org.hibernate.validator.constraints.Length;
|
|
||||||
|
|
||||||
import javax.validation.constraints.*;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加接口信息对象 Gateway_interface_info
|
|
||||||
*
|
|
||||||
* @author zoukun
|
|
||||||
* @date 2024-04-22
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@ApiModel(value = "InsertGatewayInterfaceInfoDTO", description = "添加接口信息对象")
|
|
||||||
public class InsertGatewayInterfaceInfoDTO {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@Length(max = 50,message = "接口名称不能超过50个字符")
|
|
||||||
@NotBlank(message = "接口名称不能为空")
|
|
||||||
@ApiModelProperty("接口名称")
|
|
||||||
private String interfaceName;
|
|
||||||
|
|
||||||
/** api编码 */
|
|
||||||
@Excel(name = "接口编码")
|
|
||||||
@NotBlank(message = "接口编码不能为空")
|
|
||||||
@Pattern(regexp = "^[a-zA-Z][a-zA-Z0-9.-]{0,63}$",message = "接口编码只能以字母开头,只能包含字母、数字和.-,不超过64个字符")
|
|
||||||
private String apiCode;
|
|
||||||
|
|
||||||
@Length(max = 200,message = "接口名称不能超过200个字符")
|
|
||||||
@NotBlank(message = "接口路径不能为空")
|
|
||||||
@ApiModelProperty("接口路径")
|
|
||||||
private String interfacePath;
|
|
||||||
|
|
||||||
@NotBlank(message = "请求方式不能为空")
|
|
||||||
@ApiModelProperty("请求方式")
|
|
||||||
private String requestMethod;
|
|
||||||
|
|
||||||
@Length(max = 200,message = "接口描述不能超过200个字符")
|
|
||||||
@ApiModelProperty("接口描述")
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
@Length(max = 20,message = "接口版本不能超过20个字符")
|
|
||||||
@ApiModelProperty("接口版本")
|
|
||||||
private String version;
|
|
||||||
|
|
||||||
@ApiModelProperty("接口文档(文档地址)")
|
|
||||||
private SysOss document;
|
|
||||||
|
|
||||||
@NotNull(message = "网关服务不能为空")
|
|
||||||
@ApiModelProperty("网关服务id")
|
|
||||||
private Long serverId;
|
|
||||||
|
|
||||||
@DecimalMin(value = "1",message = "超时时间为大于等于1的正整数")
|
|
||||||
@DecimalMax(value = "150000",message = "超时时间不能大于150000")
|
|
||||||
@ApiModelProperty("超时时间,单位毫秒,1-150000之间")
|
|
||||||
private Integer timeout;
|
|
||||||
|
|
||||||
@ApiModelProperty("策略ID集合")
|
|
||||||
private List<Long> strategyIds;
|
|
||||||
|
|
||||||
@ApiModelProperty("Mock状态(0=停用,1=启用)")
|
|
||||||
private String mockStatus;
|
|
||||||
|
|
||||||
@ApiModelProperty("Mock响应,json格式")
|
|
||||||
private String mockResponse;
|
|
||||||
}
|
|
@ -0,0 +1,57 @@
|
|||||||
|
package com.sf.service.gateway.domain.dto;
|
||||||
|
|
||||||
|
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
|
||||||
|
import com.sf.service.gateway.domain.GatewayInterfaceMock;
|
||||||
|
import com.sf.vertx.api.pojo.MockMatchCondition;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.apache.commons.lang3.StringUtils.EMPTY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 网关服务-接口Mock配置表
|
||||||
|
* @TableName Gateway_interface_mock
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class InsertGatewayInterfaceMockDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("ID")
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 接口id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("接口id")
|
||||||
|
private Long interfaceId;
|
||||||
|
/**
|
||||||
|
* http状态码
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("http状态码")
|
||||||
|
private Integer httpStatus;
|
||||||
|
/**
|
||||||
|
* 匹配条件
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("匹配条件")
|
||||||
|
private List<MockMatchCondition> matchConditions;
|
||||||
|
/**
|
||||||
|
* Mock响应,JSON字符串
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("Mock响应,JSON字符串")
|
||||||
|
private String mockResponse;
|
||||||
|
/**
|
||||||
|
* 状态(0停用 1启用)
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("状态(0停用 1启用)")
|
||||||
|
private String status;
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("排序")
|
||||||
|
private Integer orderNum;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,10 @@ package com.sf.service.gateway.domain.dto;
|
|||||||
|
|
||||||
import com.sf.common.annotation.Excel;
|
import com.sf.common.annotation.Excel;
|
||||||
import com.sf.file.domain.SysOss;
|
import com.sf.file.domain.SysOss;
|
||||||
|
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
|
||||||
|
import com.sf.service.gateway.domain.GatewayInterfaceMock;
|
||||||
|
import com.sf.service.gateway.domain.GatewayServer;
|
||||||
|
import com.sf.service.gateway.domain.vo.GatewayInterfaceInfoListVO;
|
||||||
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;
|
||||||
@ -11,20 +15,21 @@ import org.hibernate.validator.constraints.Length;
|
|||||||
import javax.validation.constraints.*;
|
import javax.validation.constraints.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.apache.commons.lang3.StringUtils.EMPTY;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改接口信息对象 Gateway_interface_info
|
* 新增或修改接口信息对象 Gateway_interface_info
|
||||||
*
|
*
|
||||||
* @author zoukun
|
* @author zoukun
|
||||||
* @date 2024-04-22
|
* @date 2024-04-22
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@ApiModel(value = "UpdateGatewayInterfaceInfoDTO", description = "修改接口信息对象")
|
@ApiModel(value = "InsertOrUpdateGatewayInterfaceInfoDTO", description = "新增或修改接口信息对象")
|
||||||
public class UpdateGatewayInterfaceInfoDTO {
|
public class InsertOrUpdateGatewayInterfaceInfoDTO {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@NotNull(message = "ID不能为空")
|
|
||||||
@ApiModelProperty("ID")
|
@ApiModelProperty("ID")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@ -74,6 +79,32 @@ public class UpdateGatewayInterfaceInfoDTO {
|
|||||||
@ApiModelProperty("Mock状态(0=停用,1=启用)")
|
@ApiModelProperty("Mock状态(0=停用,1=启用)")
|
||||||
private String mockStatus;
|
private String mockStatus;
|
||||||
|
|
||||||
@ApiModelProperty("Mock响应,json格式")
|
@ApiModelProperty("Mock默认响应HTTP状态码")
|
||||||
private String mockResponse;
|
private Integer mockDefaultHttpStatus;
|
||||||
|
|
||||||
|
@ApiModelProperty("Mock默认响应,json格式")
|
||||||
|
private String mockDefaultResponse;
|
||||||
|
|
||||||
|
@ApiModelProperty("Mock默认响应,json格式")
|
||||||
|
private List<InsertGatewayInterfaceMockDTO> mockExpectations;
|
||||||
|
|
||||||
|
public GatewayInterfaceInfo convertToGatewayInterfaceInfo() {
|
||||||
|
GatewayInterfaceInfo gatewayInterfaceInfo = new GatewayInterfaceInfo();
|
||||||
|
gatewayInterfaceInfo.setId(this.id);
|
||||||
|
gatewayInterfaceInfo.setInterfaceName(this.interfaceName);
|
||||||
|
gatewayInterfaceInfo.setApiCode(this.apiCode);
|
||||||
|
gatewayInterfaceInfo.setInterfacePath(this.interfacePath);
|
||||||
|
gatewayInterfaceInfo.setRequestMethod(this.requestMethod);
|
||||||
|
gatewayInterfaceInfo.setDescription(this.description);
|
||||||
|
gatewayInterfaceInfo.setVersion(this.version);
|
||||||
|
String document = this.document == null ? EMPTY : this.document.getId();
|
||||||
|
gatewayInterfaceInfo.setDocument(document);
|
||||||
|
gatewayInterfaceInfo.setServerId(this.serverId);
|
||||||
|
gatewayInterfaceInfo.setTimeout(this.timeout);
|
||||||
|
gatewayInterfaceInfo.setMockStatus(this.mockStatus);
|
||||||
|
gatewayInterfaceInfo.setMockDefaultHttpStatus(this.mockDefaultHttpStatus);
|
||||||
|
gatewayInterfaceInfo.setMockDefaultResponse(this.mockDefaultResponse);
|
||||||
|
return gatewayInterfaceInfo;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
|||||||
import com.sf.common.annotation.Excel;
|
import com.sf.common.annotation.Excel;
|
||||||
import com.sf.file.domain.SysOss;
|
import com.sf.file.domain.SysOss;
|
||||||
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
|
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
|
||||||
|
import com.sf.service.gateway.domain.GatewayInterfaceMock;
|
||||||
import com.sf.service.gateway.domain.GatewayServer;
|
import com.sf.service.gateway.domain.GatewayServer;
|
||||||
import com.sf.service.gateway.domain.GatewayStrategy;
|
import com.sf.service.gateway.domain.GatewayStrategy;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
@ -118,13 +119,22 @@ public class GatewayInterfaceInfoDetailedVO {
|
|||||||
@ApiModelProperty("Mock状态(0=停用,1=启用)")
|
@ApiModelProperty("Mock状态(0=停用,1=启用)")
|
||||||
private String mockStatus;
|
private String mockStatus;
|
||||||
|
|
||||||
@ApiModelProperty("Mock响应,json格式")
|
@ApiModelProperty("Mock默认响应HTTP状态码")
|
||||||
private String mockResponse;
|
private Integer mockDefaultHttpStatus;
|
||||||
|
|
||||||
|
@ApiModelProperty("Mock默认响应,json格式")
|
||||||
|
private String mockDefaultResponse;
|
||||||
|
|
||||||
|
@ApiModelProperty("Mock默认响应,json格式")
|
||||||
|
private List<GatewayInterfaceMock> mockExpectations;
|
||||||
|
|
||||||
|
|
||||||
public static GatewayInterfaceInfoDetailedVO convert(GatewayInterfaceInfo gatewayInterfaceInfo
|
public static GatewayInterfaceInfoDetailedVO convert(GatewayInterfaceInfo gatewayInterfaceInfo
|
||||||
, GatewayServer gatewayServer
|
, GatewayServer gatewayServer
|
||||||
, List<GatewayStrategy> strategyList
|
, List<GatewayStrategy> strategyList
|
||||||
, SysOss document
|
, SysOss document
|
||||||
|
, List<GatewayInterfaceMock> mockExpectations
|
||||||
|
|
||||||
) {
|
) {
|
||||||
GatewayInterfaceInfoDetailedVO vo = new GatewayInterfaceInfoDetailedVO();
|
GatewayInterfaceInfoDetailedVO vo = new GatewayInterfaceInfoDetailedVO();
|
||||||
vo.setId(gatewayInterfaceInfo.getId());
|
vo.setId(gatewayInterfaceInfo.getId());
|
||||||
@ -142,7 +152,10 @@ public class GatewayInterfaceInfoDetailedVO {
|
|||||||
vo.setServerName(gatewayServer.getServerName());
|
vo.setServerName(gatewayServer.getServerName());
|
||||||
vo.setTimeout(gatewayInterfaceInfo.getTimeout());
|
vo.setTimeout(gatewayInterfaceInfo.getTimeout());
|
||||||
vo.setMockStatus(gatewayInterfaceInfo.getMockStatus());
|
vo.setMockStatus(gatewayInterfaceInfo.getMockStatus());
|
||||||
vo.setMockResponse(gatewayInterfaceInfo.getMockResponse());
|
vo.setMockDefaultHttpStatus(gatewayInterfaceInfo.getMockDefaultHttpStatus());
|
||||||
|
vo.setMockDefaultResponse(gatewayInterfaceInfo.getMockDefaultResponse());
|
||||||
|
// mock配置
|
||||||
|
vo.setMockExpectations(mockExpectations);
|
||||||
// 策略信息
|
// 策略信息
|
||||||
List<GatewayStrategyListVO> strategyListVOList = strategyList.stream()
|
List<GatewayStrategyListVO> strategyListVOList = strategyList.stream()
|
||||||
.map(GatewayStrategyListVO::convert)
|
.map(GatewayStrategyListVO::convert)
|
||||||
|
@ -110,12 +110,6 @@ public class GatewayInterfaceInfoListVO {
|
|||||||
@ApiModelProperty
|
@ApiModelProperty
|
||||||
private List<GatewayStrategyListVO> strategyList;
|
private List<GatewayStrategyListVO> strategyList;
|
||||||
|
|
||||||
@ApiModelProperty("Mock状态(0=停用,1=启用)")
|
|
||||||
private String mockStatus;
|
|
||||||
|
|
||||||
@ApiModelProperty("Mock响应,json格式")
|
|
||||||
private String mockResponse;
|
|
||||||
|
|
||||||
public static GatewayInterfaceInfoListVO convert(GatewayInterfaceInfo info, GatewayServer gatewayServer) {
|
public static GatewayInterfaceInfoListVO convert(GatewayInterfaceInfo info, GatewayServer gatewayServer) {
|
||||||
GatewayInterfaceInfoListVO vo = new GatewayInterfaceInfoListVO();
|
GatewayInterfaceInfoListVO vo = new GatewayInterfaceInfoListVO();
|
||||||
vo.setId(info.getId());
|
vo.setId(info.getId());
|
||||||
@ -131,8 +125,6 @@ public class GatewayInterfaceInfoListVO {
|
|||||||
vo.setServerId(info.getServerId());
|
vo.setServerId(info.getServerId());
|
||||||
vo.setServerName(gatewayServer != null ? gatewayServer.getServerName() : EMPTY);
|
vo.setServerName(gatewayServer != null ? gatewayServer.getServerName() : EMPTY);
|
||||||
vo.setTimeout(info.getTimeout());
|
vo.setTimeout(info.getTimeout());
|
||||||
vo.setMockStatus(info.getMockStatus());
|
|
||||||
vo.setMockResponse(info.getMockResponse());
|
|
||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.sf.service.gateway.mapper;
|
||||||
|
|
||||||
|
import com.sf.service.gateway.domain.GatewayInterfaceMock;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity com.sf.service.gateway.domain.GatewayInterfaceMock
|
||||||
|
*/
|
||||||
|
public interface GatewayInterfaceMockMapper {
|
||||||
|
|
||||||
|
int deleteByPrimaryKey(Long id);
|
||||||
|
|
||||||
|
int insert(GatewayInterfaceMock record);
|
||||||
|
|
||||||
|
int insertSelective(GatewayInterfaceMock record);
|
||||||
|
|
||||||
|
GatewayInterfaceMock selectByPrimaryKey(Long id);
|
||||||
|
|
||||||
|
int updateByPrimaryKeySelective(GatewayInterfaceMock record);
|
||||||
|
|
||||||
|
int updateByPrimaryKey(GatewayInterfaceMock record);
|
||||||
|
|
||||||
|
List<GatewayInterfaceMock> selectGatewayInterfaceMockByInterfaceIds(@Param("interfaceIds") Collection<Long> interfaceIds);
|
||||||
|
|
||||||
|
void batchInsertGatewayInterfaceMock(@Param("mockList") List<GatewayInterfaceMock> mockList);
|
||||||
|
|
||||||
|
void deleteByInterfaceIds(@Param("interfaceIds") Set<Long> interfaceIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -2,12 +2,13 @@ package com.sf.service.gateway.service;
|
|||||||
|
|
||||||
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
|
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
|
||||||
import com.sf.service.gateway.domain.GatewayInterfaceLinkStrategy;
|
import com.sf.service.gateway.domain.GatewayInterfaceLinkStrategy;
|
||||||
import com.sf.service.gateway.domain.dto.InsertGatewayInterfaceInfoDTO;
|
import com.sf.service.gateway.domain.GatewayInterfaceMock;
|
||||||
import com.sf.service.gateway.domain.dto.UpdateGatewayInterfaceInfoDTO;
|
import com.sf.service.gateway.domain.dto.InsertOrUpdateGatewayInterfaceInfoDTO;
|
||||||
import com.sf.service.gateway.enums.GatewayDataStatus;
|
import com.sf.service.gateway.enums.GatewayDataStatus;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口管理Service接口
|
* 接口管理Service接口
|
||||||
@ -77,14 +78,16 @@ public interface IGatewayInterfaceInfoService
|
|||||||
* @param dto
|
* @param dto
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Long insertGatewayInterfaceInfoAndBindStrategy(InsertGatewayInterfaceInfoDTO dto);
|
Long insertGatewayInterfaceInfoAndBindStrategy(InsertOrUpdateGatewayInterfaceInfoDTO dto);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改接口信息及绑定的策略信息
|
* 修改接口信息及绑定的策略信息
|
||||||
* @param dto
|
* @param dto
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Long updateGatewayInterfaceInfoAndBindStrategy(UpdateGatewayInterfaceInfoDTO dto);
|
Long updateGatewayInterfaceInfoAndBindStrategy(InsertOrUpdateGatewayInterfaceInfoDTO dto);
|
||||||
|
|
||||||
List<GatewayInterfaceLinkStrategy> selectGatewayInterfaceLinkStrategyByInterfaceIds(Collection<Long> interfaceIds);
|
List<GatewayInterfaceLinkStrategy> selectGatewayInterfaceLinkStrategyByInterfaceIds(Collection<Long> interfaceIds);
|
||||||
|
|
||||||
|
List<GatewayInterfaceMock> selectGatewayInterfaceMockListByInterfaceIds(Collection<Long> interfaceIds);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import com.alibaba.fastjson2.JSON;
|
|||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.sf.common.constant.HttpStatus;
|
import com.sf.common.constant.HttpStatus;
|
||||||
import com.sf.common.exception.ServiceException;
|
import com.sf.common.exception.ServiceException;
|
||||||
|
import com.sf.common.utils.JSONUtils;
|
||||||
import com.sf.service.index.utils.AppUtils;
|
import com.sf.service.index.utils.AppUtils;
|
||||||
import com.sf.common.utils.DateUtils;
|
import com.sf.common.utils.DateUtils;
|
||||||
import com.sf.common.utils.SecurityUtils;
|
import com.sf.common.utils.SecurityUtils;
|
||||||
@ -145,7 +146,8 @@ public class GatewayConfigServiceImpl implements IGatewayConfigService {
|
|||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
Map<Long, List<GatewayInterfaceInfo>> groupByServerInterfaceMap = interfaceInfoList.stream().collect(Collectors.groupingBy(GatewayInterfaceInfo::getServerId));
|
Map<Long, List<GatewayInterfaceInfo>> groupByServerInterfaceMap = interfaceInfoList.stream().collect(Collectors.groupingBy(GatewayInterfaceInfo::getServerId));
|
||||||
List<GatewayInterfaceLinkStrategy> linkList = gatewayInterfaceInfoService.selectGatewayInterfaceLinkStrategyByInterfaceIds(interfaceInfoList.stream().map(GatewayInterfaceInfo::getId).collect(Collectors.toSet()));
|
Set<Long> interfaceIds = interfaceInfoList.stream().map(GatewayInterfaceInfo::getId).collect(Collectors.toSet());
|
||||||
|
List<GatewayInterfaceLinkStrategy> linkList = gatewayInterfaceInfoService.selectGatewayInterfaceLinkStrategyByInterfaceIds(interfaceIds);
|
||||||
Map<Long, List<GatewayInterfaceLinkStrategy>> groupByInterfaceLinkMap = linkList.stream().collect(Collectors.groupingBy(GatewayInterfaceLinkStrategy::getInterfaceId));
|
Map<Long, List<GatewayInterfaceLinkStrategy>> groupByInterfaceLinkMap = linkList.stream().collect(Collectors.groupingBy(GatewayInterfaceLinkStrategy::getInterfaceId));
|
||||||
// 如果是路由模式的服务,查询对应的路由服务信息
|
// 如果是路由模式的服务,查询对应的路由服务信息
|
||||||
Collection<Long> routeIds = serverList.stream().filter(item -> GatewayServiceModel.ROUTE.getCode().equals(item.getServiceModel()))
|
Collection<Long> routeIds = serverList.stream().filter(item -> GatewayServiceModel.ROUTE.getCode().equals(item.getServiceModel()))
|
||||||
@ -158,6 +160,11 @@ public class GatewayConfigServiceImpl implements IGatewayConfigService {
|
|||||||
// 启用的
|
// 启用的
|
||||||
strategyList = strategyList.stream().filter(strategy -> GatewayDataStatus.ENABLE.getCode().equals(strategy.getStatus())).collect(Collectors.toList());
|
strategyList = strategyList.stream().filter(strategy -> GatewayDataStatus.ENABLE.getCode().equals(strategy.getStatus())).collect(Collectors.toList());
|
||||||
Map<Long, GatewayStrategy> strategyMap = strategyList.stream().collect(Collectors.toMap(GatewayStrategy::getId, Function.identity()));
|
Map<Long, GatewayStrategy> strategyMap = strategyList.stream().collect(Collectors.toMap(GatewayStrategy::getId, Function.identity()));
|
||||||
|
// mock
|
||||||
|
List<GatewayInterfaceMock> mockList = gatewayInterfaceInfoService.selectGatewayInterfaceMockListByInterfaceIds(interfaceIds);
|
||||||
|
Map<Long, List<GatewayInterfaceMock>> groupByInterfaceMockMap = mockList.stream()
|
||||||
|
.filter(mock -> GatewayDataStatus.ENABLE.getCode().equals(mock.getStatus()))
|
||||||
|
.collect(Collectors.groupingBy(GatewayInterfaceMock::getInterfaceId));
|
||||||
return serverList.stream()
|
return serverList.stream()
|
||||||
.filter(server -> CollUtil.isNotEmpty(groupByServerInterfaceMap.getOrDefault(server.getId(), Collections.emptyList())))
|
.filter(server -> CollUtil.isNotEmpty(groupByServerInterfaceMap.getOrDefault(server.getId(), Collections.emptyList())))
|
||||||
.map(server -> {
|
.map(server -> {
|
||||||
@ -179,8 +186,22 @@ public class GatewayConfigServiceImpl implements IGatewayConfigService {
|
|||||||
apiConfig.setMethod(api.getRequestMethod());
|
apiConfig.setMethod(api.getRequestMethod());
|
||||||
apiConfig.setTimeout(api.getTimeout() != null ? api.getTimeout().longValue() : serviceTimeout);
|
apiConfig.setTimeout(api.getTimeout() != null ? api.getTimeout().longValue() : serviceTimeout);
|
||||||
apiConfig.setStrategy(currentApiStrategyList);
|
apiConfig.setStrategy(currentApiStrategyList);
|
||||||
|
// Mock
|
||||||
if (GatewayDataStatus.ENABLE.getCode().equals(api.getMockStatus())) {
|
if (GatewayDataStatus.ENABLE.getCode().equals(api.getMockStatus())) {
|
||||||
apiConfig.setMockResponse(api.getMockResponse());
|
apiConfig.setMockDefaultHttpStatus(api.getMockDefaultHttpStatus());
|
||||||
|
apiConfig.setMockDefaultResponse(api.getMockDefaultResponse());
|
||||||
|
List<GatewayInterfaceMock> currentMocks = groupByInterfaceMockMap.getOrDefault(api.getId(), Collections.emptyList());
|
||||||
|
List<MockExpectation> mockExpectations = currentMocks.stream()
|
||||||
|
.sorted(Comparator.comparingInt(GatewayInterfaceMock::getOrderNum))
|
||||||
|
.map(mock ->{
|
||||||
|
MockExpectation mockExpectation = new MockExpectation();
|
||||||
|
mockExpectation.setHttpStatus(mock.getHttpStatus());
|
||||||
|
mockExpectation.setMockResponse(mock.getMockResponse());
|
||||||
|
mockExpectation.setMatchConditions(JSON.parseArray(mock.getMatchConditions(),MockMatchCondition.class));
|
||||||
|
return mockExpectation;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
apiConfig.setMockExpectations(mockExpectations);
|
||||||
}
|
}
|
||||||
return apiConfig;
|
return apiConfig;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
@ -307,7 +328,7 @@ public class GatewayConfigServiceImpl implements IGatewayConfigService {
|
|||||||
} else {
|
} else {
|
||||||
Assert.isTrue(gatewayConfig.getApiCurrentLimitingTimeWindow() >= 0, "限流窗口值>=0");
|
Assert.isTrue(gatewayConfig.getApiCurrentLimitingTimeWindow() >= 0, "限流窗口值>=0");
|
||||||
}
|
}
|
||||||
Assert.isTrue(apijson.JSON.isJSONObject(gatewayConfig.getApiCurrentLimitingDefaultResponse()), "请输入正确的JSON格式限流响应信息");
|
Assert.isTrue(JSONUtils.isJSONObject(gatewayConfig.getApiCurrentLimitingDefaultResponse()), "请输入正确的JSON格式限流响应信息");
|
||||||
}
|
}
|
||||||
if (GatewayDataStatus.ENABLE.getCode().equals(gatewayConfig.getAppCurrentLimitingStatus())) {
|
if (GatewayDataStatus.ENABLE.getCode().equals(gatewayConfig.getAppCurrentLimitingStatus())) {
|
||||||
Assert.notNull(gatewayConfig.getAppCurrentLimitingThreshold(), "限流值不能为空");
|
Assert.notNull(gatewayConfig.getAppCurrentLimitingThreshold(), "限流值不能为空");
|
||||||
@ -318,7 +339,7 @@ public class GatewayConfigServiceImpl implements IGatewayConfigService {
|
|||||||
} else {
|
} else {
|
||||||
Assert.isTrue(gatewayConfig.getAppCurrentLimitingTimeWindow() >= 0, "限流窗口值>=0");
|
Assert.isTrue(gatewayConfig.getAppCurrentLimitingTimeWindow() >= 0, "限流窗口值>=0");
|
||||||
}
|
}
|
||||||
Assert.isTrue(apijson.JSON.isJSONObject(gatewayConfig.getAppCurrentLimitingDefaultResponse()), "请输入正确的JSON格式限流响应信息");
|
Assert.isTrue(JSONUtils.isJSONObject(gatewayConfig.getAppCurrentLimitingDefaultResponse()), "请输入正确的JSON格式限流响应信息");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,21 +3,25 @@ package com.sf.service.gateway.service.impl;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import apijson.JSON;
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.sf.common.utils.*;
|
import com.sf.common.utils.*;
|
||||||
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
|
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
|
||||||
import com.sf.service.gateway.domain.GatewayInterfaceLinkStrategy;
|
import com.sf.service.gateway.domain.GatewayInterfaceLinkStrategy;
|
||||||
|
import com.sf.service.gateway.domain.GatewayInterfaceMock;
|
||||||
import com.sf.service.gateway.domain.GatewayStrategy;
|
import com.sf.service.gateway.domain.GatewayStrategy;
|
||||||
import com.sf.service.gateway.domain.dto.InsertGatewayInterfaceInfoDTO;
|
import com.sf.service.gateway.domain.dto.InsertGatewayInterfaceMockDTO;
|
||||||
import com.sf.service.gateway.domain.dto.UpdateGatewayInterfaceInfoDTO;
|
import com.sf.vertx.api.pojo.MockMatchCondition;
|
||||||
|
import com.sf.service.gateway.domain.dto.InsertOrUpdateGatewayInterfaceInfoDTO;
|
||||||
import com.sf.service.gateway.enums.GatewayDataStatus;
|
import com.sf.service.gateway.enums.GatewayDataStatus;
|
||||||
import com.sf.service.gateway.enums.GatewayStrategyType;
|
import com.sf.service.gateway.enums.GatewayStrategyType;
|
||||||
import com.sf.service.gateway.mapper.GatewayInterfaceInfoMapper;
|
import com.sf.service.gateway.mapper.GatewayInterfaceInfoMapper;
|
||||||
import com.sf.service.gateway.mapper.GatewayInterfaceLinkStrategyMapper;
|
import com.sf.service.gateway.mapper.GatewayInterfaceLinkStrategyMapper;
|
||||||
|
import com.sf.service.gateway.mapper.GatewayInterfaceMockMapper;
|
||||||
import com.sf.service.gateway.service.IGatewayInterfaceInfoService;
|
import com.sf.service.gateway.service.IGatewayInterfaceInfoService;
|
||||||
import com.sf.service.gateway.service.IGatewayStrategyService;
|
import com.sf.service.gateway.service.IGatewayStrategyService;
|
||||||
import com.sf.service.index.utils.AppUtils;
|
import com.sf.service.index.utils.AppUtils;
|
||||||
|
import com.sf.vertx.enums.MatchType;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.dao.DuplicateKeyException;
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -27,8 +31,6 @@ import org.springframework.util.CollectionUtils;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.EMPTY;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口管理Service业务层处理
|
* 接口管理Service业务层处理
|
||||||
*
|
*
|
||||||
@ -45,6 +47,9 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
|
|||||||
@Resource
|
@Resource
|
||||||
private GatewayInterfaceLinkStrategyMapper gatewayInterfaceLinkStrategyMapper;
|
private GatewayInterfaceLinkStrategyMapper gatewayInterfaceLinkStrategyMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private GatewayInterfaceMockMapper gatewayInterfaceMockMapper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IGatewayStrategyService gatewayStrategyService;
|
private IGatewayStrategyService gatewayStrategyService;
|
||||||
|
|
||||||
@ -98,7 +103,8 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
|
|||||||
|
|
||||||
private void checkGatewayInterfaceInfoCanInsertOrUpdate(GatewayInterfaceInfo gatewayInterfaceInfo) {
|
private void checkGatewayInterfaceInfoCanInsertOrUpdate(GatewayInterfaceInfo gatewayInterfaceInfo) {
|
||||||
if (GatewayDataStatus.ENABLE.getCode().equals(gatewayInterfaceInfo.getMockStatus())) {
|
if (GatewayDataStatus.ENABLE.getCode().equals(gatewayInterfaceInfo.getMockStatus())) {
|
||||||
Assert.isTrue(JSON.isJSONObject(gatewayInterfaceInfo.getMockResponse()), "请输入正确格式的响应信息");
|
Assert.notNull(gatewayInterfaceInfo.getMockDefaultHttpStatus(), "请输入默认响应HTTP状态码");
|
||||||
|
Assert.isTrue(JSONUtils.isJSONObject(gatewayInterfaceInfo.getMockDefaultResponse()), "请输入正确格式的默认响应信息");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,21 +186,9 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
|
|||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@Override
|
@Override
|
||||||
public Long insertGatewayInterfaceInfoAndBindStrategy(InsertGatewayInterfaceInfoDTO dto) {
|
public Long insertGatewayInterfaceInfoAndBindStrategy(InsertOrUpdateGatewayInterfaceInfoDTO dto) {
|
||||||
GatewayInterfaceInfo gatewayInterfaceInfo = new GatewayInterfaceInfo();
|
GatewayInterfaceInfo gatewayInterfaceInfo = dto.convertToGatewayInterfaceInfo();
|
||||||
gatewayInterfaceInfo.setInterfaceName(dto.getInterfaceName());
|
|
||||||
gatewayInterfaceInfo.setApiCode(dto.getApiCode());
|
|
||||||
gatewayInterfaceInfo.setInterfacePath(dto.getInterfacePath());
|
|
||||||
gatewayInterfaceInfo.setRequestMethod(dto.getRequestMethod());
|
|
||||||
gatewayInterfaceInfo.setDescription(dto.getDescription());
|
|
||||||
gatewayInterfaceInfo.setVersion(dto.getVersion());
|
|
||||||
gatewayInterfaceInfo.setStatus(GatewayDataStatus.DISABLE.getCode());
|
gatewayInterfaceInfo.setStatus(GatewayDataStatus.DISABLE.getCode());
|
||||||
String document = dto.getDocument() == null ? EMPTY : dto.getDocument().getId();
|
|
||||||
gatewayInterfaceInfo.setDocument(document);
|
|
||||||
gatewayInterfaceInfo.setServerId(dto.getServerId());
|
|
||||||
gatewayInterfaceInfo.setTimeout(dto.getTimeout());
|
|
||||||
gatewayInterfaceInfo.setMockStatus(dto.getMockStatus());
|
|
||||||
gatewayInterfaceInfo.setMockResponse(dto.getMockResponse());
|
|
||||||
Long interfaceInfoId = insertGatewayInterfaceInfo(gatewayInterfaceInfo);
|
Long interfaceInfoId = insertGatewayInterfaceInfo(gatewayInterfaceInfo);
|
||||||
if (CollUtil.isNotEmpty(dto.getStrategyIds())) {
|
if (CollUtil.isNotEmpty(dto.getStrategyIds())) {
|
||||||
checkGatewayStrategyTypeCannotBeRepeated(dto.getStrategyIds());
|
checkGatewayStrategyTypeCannotBeRepeated(dto.getStrategyIds());
|
||||||
@ -203,26 +197,52 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
gatewayInterfaceLinkStrategyMapper.batchInsertGatewayInterfaceLinkStrategy(linkStrategyList);
|
gatewayInterfaceLinkStrategyMapper.batchInsertGatewayInterfaceLinkStrategy(linkStrategyList);
|
||||||
}
|
}
|
||||||
|
if (CollUtil.isNotEmpty(dto.getMockExpectations())) {
|
||||||
|
checkInsertGatewayInterfaceMockList(dto.getMockExpectations());
|
||||||
|
List<GatewayInterfaceMock> mockList = dto.getMockExpectations().stream().map(mockDTO ->{
|
||||||
|
GatewayInterfaceMock mock = new GatewayInterfaceMock();
|
||||||
|
mock.setInterfaceId(interfaceInfoId);
|
||||||
|
mock.setHttpStatus(mockDTO.getHttpStatus());
|
||||||
|
mock.setMatchConditions(JSON.toJSONString(mockDTO.getMatchConditions()));
|
||||||
|
mock.setMockResponse(mockDTO.getMockResponse());
|
||||||
|
mock.setStatus(mockDTO.getStatus());
|
||||||
|
mock.setOrderNum(mockDTO.getOrderNum());
|
||||||
|
return mock;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
gatewayInterfaceMockMapper.batchInsertGatewayInterfaceMock(mockList);
|
||||||
|
}
|
||||||
return interfaceInfoId;
|
return interfaceInfoId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkInsertGatewayInterfaceMockList(List<InsertGatewayInterfaceMockDTO> gatewayInterfaceMockList) {
|
||||||
|
gatewayInterfaceMockList.forEach(mock ->{
|
||||||
|
Assert.notNull(mock.getHttpStatus(),"HTTP状态码不能为空");
|
||||||
|
Assert.isTrue(JSONUtils.isJSONObject(mock.getMockResponse()), "请输入正确格式的默认响应信息");
|
||||||
|
try {
|
||||||
|
List<MockMatchCondition> conditionDTOList = mock.getMatchConditions();
|
||||||
|
Assert.notEmpty(conditionDTOList,"至少存在一条匹配条件");
|
||||||
|
conditionDTOList.forEach(condition -> {
|
||||||
|
MatchType matchType = MatchType.getByCode(condition.getMatchType());
|
||||||
|
Assert.notNull(matchType,"不支持的匹配类型");
|
||||||
|
switch (matchType){
|
||||||
|
case IS_NULL:
|
||||||
|
case NOT_NULL:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Assert.notEmpty(condition.getParameterValue(),"请输入参数值");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("JSONUtils.isJSONArray catch \n" + e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@Override
|
@Override
|
||||||
public Long updateGatewayInterfaceInfoAndBindStrategy(UpdateGatewayInterfaceInfoDTO dto) {
|
public Long updateGatewayInterfaceInfoAndBindStrategy(InsertOrUpdateGatewayInterfaceInfoDTO dto) {
|
||||||
GatewayInterfaceInfo gatewayInterfaceInfo = new GatewayInterfaceInfo();
|
GatewayInterfaceInfo gatewayInterfaceInfo = dto.convertToGatewayInterfaceInfo();
|
||||||
gatewayInterfaceInfo.setId(dto.getId());
|
|
||||||
gatewayInterfaceInfo.setInterfaceName(dto.getInterfaceName());
|
|
||||||
gatewayInterfaceInfo.setApiCode(dto.getApiCode());
|
|
||||||
gatewayInterfaceInfo.setInterfacePath(dto.getInterfacePath());
|
|
||||||
gatewayInterfaceInfo.setRequestMethod(dto.getRequestMethod());
|
|
||||||
gatewayInterfaceInfo.setDescription(dto.getDescription());
|
|
||||||
gatewayInterfaceInfo.setVersion(dto.getVersion());
|
|
||||||
String document = dto.getDocument() == null ? EMPTY : dto.getDocument().getId();
|
|
||||||
gatewayInterfaceInfo.setDocument(document);
|
|
||||||
gatewayInterfaceInfo.setServerId(dto.getServerId());
|
|
||||||
gatewayInterfaceInfo.setTimeout(dto.getTimeout());
|
|
||||||
gatewayInterfaceInfo.setMockStatus(dto.getMockStatus());
|
|
||||||
gatewayInterfaceInfo.setMockResponse(dto.getMockResponse());
|
|
||||||
updateGatewayInterfaceInfo(gatewayInterfaceInfo);
|
updateGatewayInterfaceInfo(gatewayInterfaceInfo);
|
||||||
// 先删除
|
// 先删除
|
||||||
gatewayInterfaceLinkStrategyMapper.deleteByInterfaceIds(Collections.singleton(dto.getId()));
|
gatewayInterfaceLinkStrategyMapper.deleteByInterfaceIds(Collections.singleton(dto.getId()));
|
||||||
@ -233,6 +253,21 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
gatewayInterfaceLinkStrategyMapper.batchInsertGatewayInterfaceLinkStrategy(linkStrategyList);
|
gatewayInterfaceLinkStrategyMapper.batchInsertGatewayInterfaceLinkStrategy(linkStrategyList);
|
||||||
}
|
}
|
||||||
|
gatewayInterfaceMockMapper.deleteByInterfaceIds(Collections.singleton(dto.getId()));
|
||||||
|
if (CollUtil.isNotEmpty(dto.getMockExpectations())) {
|
||||||
|
checkInsertGatewayInterfaceMockList(dto.getMockExpectations());
|
||||||
|
List<GatewayInterfaceMock> mockList = dto.getMockExpectations().stream().map(mockDTO -> {
|
||||||
|
GatewayInterfaceMock mock = new GatewayInterfaceMock();
|
||||||
|
mock.setInterfaceId(dto.getId());
|
||||||
|
mock.setHttpStatus(mockDTO.getHttpStatus());
|
||||||
|
mock.setMatchConditions(JSON.toJSONString(mockDTO.getMatchConditions()));
|
||||||
|
mock.setMockResponse(mockDTO.getMockResponse());
|
||||||
|
mock.setStatus(mockDTO.getStatus());
|
||||||
|
mock.setOrderNum(mockDTO.getOrderNum());
|
||||||
|
return mock;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
gatewayInterfaceMockMapper.batchInsertGatewayInterfaceMock(mockList);
|
||||||
|
}
|
||||||
return gatewayInterfaceInfo.getId();
|
return gatewayInterfaceInfo.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,6 +279,15 @@ public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoSer
|
|||||||
return gatewayInterfaceLinkStrategyMapper.selectGatewayInterfaceLinkStrategyByInterfaceIds(interfaceIds);
|
return gatewayInterfaceLinkStrategyMapper.selectGatewayInterfaceLinkStrategyByInterfaceIds(interfaceIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GatewayInterfaceMock> selectGatewayInterfaceMockListByInterfaceIds(Collection<Long> interfaceIds) {
|
||||||
|
if (CollectionUtils.isEmpty(interfaceIds)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return gatewayInterfaceMockMapper.selectGatewayInterfaceMockByInterfaceIds(interfaceIds);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void checkGatewayStrategyTypeCannotBeRepeated(List<Long> strategyIds) {
|
private void checkGatewayStrategyTypeCannotBeRepeated(List<Long> strategyIds) {
|
||||||
List<GatewayStrategy> strategyList = gatewayStrategyService.selectGatewayStrategyByIds(strategyIds);
|
List<GatewayStrategy> strategyList = gatewayStrategyService.selectGatewayStrategyByIds(strategyIds);
|
||||||
Map<String, List<GatewayStrategy>> groupByStrategyTypeMap = strategyList.stream().collect(Collectors.groupingBy(GatewayStrategy::getStrategyType));
|
Map<String, List<GatewayStrategy>> groupByStrategyTypeMap = strategyList.stream().collect(Collectors.groupingBy(GatewayStrategy::getStrategyType));
|
||||||
|
@ -17,6 +17,7 @@ import com.sf.service.gateway.enums.*;
|
|||||||
import com.sf.service.gateway.mapper.GatewayRouteMapper;
|
import com.sf.service.gateway.mapper.GatewayRouteMapper;
|
||||||
import com.sf.service.gateway.service.IGatewayRouteService;
|
import com.sf.service.gateway.service.IGatewayRouteService;
|
||||||
import com.sf.service.gateway.service.IGatewayServerService;
|
import com.sf.service.gateway.service.IGatewayServerService;
|
||||||
|
import com.sf.vertx.enums.MatchType;
|
||||||
import org.springframework.dao.DuplicateKeyException;
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
@ -8,6 +8,7 @@ import java.util.List;
|
|||||||
import apijson.JSON;
|
import apijson.JSON;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import com.sf.common.utils.DateUtils;
|
import com.sf.common.utils.DateUtils;
|
||||||
|
import com.sf.common.utils.JSONUtils;
|
||||||
import com.sf.service.gateway.domain.GatewayInterfaceLinkStrategy;
|
import com.sf.service.gateway.domain.GatewayInterfaceLinkStrategy;
|
||||||
import com.sf.service.gateway.domain.GatewayServer;
|
import com.sf.service.gateway.domain.GatewayServer;
|
||||||
import com.sf.service.gateway.domain.GatewayStrategy;
|
import com.sf.service.gateway.domain.GatewayStrategy;
|
||||||
@ -142,7 +143,7 @@ public class GatewayStrategyServiceImpl implements IGatewayStrategyService
|
|||||||
}else {
|
}else {
|
||||||
Assert.isTrue(currentLimitingTimeWindow >= 0,"限流窗口值>=0");
|
Assert.isTrue(currentLimitingTimeWindow >= 0,"限流窗口值>=0");
|
||||||
}
|
}
|
||||||
Assert.isTrue(JSON.isJSONObject(currentLimitingResponse),"请输入正确的JSON格式限流响应信息");
|
Assert.isTrue(JSONUtils.isJSONObject(currentLimitingResponse),"请输入正确的JSON格式限流响应信息");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,7 +162,7 @@ public class GatewayStrategyServiceImpl implements IGatewayStrategyService
|
|||||||
Assert.isTrue(circuitBreakerTimeWindow >= 0,"调用失败阈值对应的单位时间>=0");
|
Assert.isTrue(circuitBreakerTimeWindow >= 0,"调用失败阈值对应的单位时间>=0");
|
||||||
Assert.notNull(circuitBreakerRecoveryInterval,"熔断后恢复的时间间隔不能为空");
|
Assert.notNull(circuitBreakerRecoveryInterval,"熔断后恢复的时间间隔不能为空");
|
||||||
Assert.isTrue(circuitBreakerRecoveryInterval >= 0,"熔断后恢复的时间间隔>=0");
|
Assert.isTrue(circuitBreakerRecoveryInterval >= 0,"熔断后恢复的时间间隔>=0");
|
||||||
Assert.isTrue(JSON.isJSONObject(circuitBreakerResponse),"请输入正确的JSON格式熔断响应信息");
|
Assert.isTrue(JSONUtils.isJSONObject(circuitBreakerResponse),"请输入正确的JSON格式熔断响应信息");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,7 +20,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<result property="updateTime" column="update_time" />
|
<result property="updateTime" column="update_time" />
|
||||||
<result property="serverId" column="server_id" />
|
<result property="serverId" column="server_id" />
|
||||||
<result property="mockStatus" column="mock_status" />
|
<result property="mockStatus" column="mock_status" />
|
||||||
<result property="mockResponse" column="mock_response" />
|
<result property="mockDefaultHttpStatus" column="mock_default_http_status" />
|
||||||
|
<result property="mockDefaultResponse" column="mock_default_response" />
|
||||||
<result property="timeout" column="timeout" />
|
<result property="timeout" column="timeout" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
select id, interface_name,api_code, 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 ,
|
||||||
server_id,mock_status,mock_response,timeout
|
server_id,mock_status,mock_default_http_status,mock_default_response,timeout
|
||||||
from Gateway_interface_info
|
from Gateway_interface_info
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
@ -81,7 +82,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="modified != null">modified,</if>
|
<if test="modified != null">modified,</if>
|
||||||
<if test="serverId != null">server_id,</if>
|
<if test="serverId != null">server_id,</if>
|
||||||
<if test="mockStatus != null">mock_status,</if>
|
<if test="mockStatus != null">mock_status,</if>
|
||||||
<if test="mockResponse != null">mock_response,</if>
|
<if test="mockDefaultHttpStatus != null">mock_default_http_status,</if>
|
||||||
|
<if test="mockDefaultResponse != null">mock_default_response,</if>
|
||||||
<if test="timeout != null">timeout,</if>
|
<if test="timeout != null">timeout,</if>
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
@ -100,7 +102,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="modified != null">#{modified},</if>
|
<if test="modified != null">#{modified},</if>
|
||||||
<if test="serverId != null">#{serverId},</if>
|
<if test="serverId != null">#{serverId},</if>
|
||||||
<if test="mockStatus != null">#{mockStatus},</if>
|
<if test="mockStatus != null">#{mockStatus},</if>
|
||||||
<if test="mockResponse != null">#{mockResponse},</if>
|
<if test="mockDefaultHttpStatus != null">#{mockDefaultHttpStatus},</if>
|
||||||
|
<if test="mockDefaultResponse != null">#{mockDefaultResponse},</if>
|
||||||
<if test="timeout != null">#{timeout},</if>
|
<if test="timeout != null">#{timeout},</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
@ -120,7 +123,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||||
<if test="serverId != null">server_id = #{serverId},</if>
|
<if test="serverId != null">server_id = #{serverId},</if>
|
||||||
<if test="mockStatus != null">mock_status = #{mockStatus},</if>
|
<if test="mockStatus != null">mock_status = #{mockStatus},</if>
|
||||||
<if test="mockResponse != null">mock_response = #{mockResponse},</if>
|
<if test="mockDefaultHttpStatus != null">mock_default_http_status = #{mockDefaultHttpStatus},</if>
|
||||||
|
<if test="mockDefaultResponse != null">mock_default_response = #{mockDefaultResponse},</if>
|
||||||
timeout = #{timeout}
|
timeout = #{timeout}
|
||||||
</trim>
|
</trim>
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
|
@ -0,0 +1,137 @@
|
|||||||
|
<?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="com.sf.service.gateway.mapper.GatewayInterfaceMockMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="com.sf.service.gateway.domain.GatewayInterfaceMock">
|
||||||
|
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||||
|
<result property="interfaceId" column="interface_id" jdbcType="BIGINT"/>
|
||||||
|
<result property="httpStatus" column="http_status" jdbcType="INTEGER"/>
|
||||||
|
<result property="matchConditions" column="match_conditions" jdbcType="VARCHAR"/>
|
||||||
|
<result property="mockResponse" column="mock_response" jdbcType="VARCHAR"/>
|
||||||
|
<result property="status" column="status" jdbcType="CHAR"/>
|
||||||
|
<result property="orderNum" column="order_num" jdbcType="INTEGER"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id,interface_id,http_status,
|
||||||
|
match_conditions,mock_response,status,
|
||||||
|
order_num
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from Gateway_interface_mock
|
||||||
|
where id = #{id,jdbcType=BIGINT}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectGatewayInterfaceMockByInterfaceIds" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from Gateway_interface_mock
|
||||||
|
where interface_id in
|
||||||
|
<foreach item="id" collection="interfaceIds" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
|
||||||
|
delete from Gateway_interface_mock
|
||||||
|
where id = #{id,jdbcType=BIGINT}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete id="deleteByInterfaceIds">
|
||||||
|
delete from Gateway_interface_mock
|
||||||
|
where interface_id in
|
||||||
|
<foreach item="id" collection="interfaceIds" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.sf.service.gateway.domain.GatewayInterfaceMock" useGeneratedKeys="true">
|
||||||
|
insert into Gateway_interface_mock
|
||||||
|
( id,interface_id,http_status
|
||||||
|
,match_conditions,mock_response,status
|
||||||
|
,order_num)
|
||||||
|
values (#{id,jdbcType=BIGINT},#{interfaceId,jdbcType=BIGINT},#{httpStatus,jdbcType=INTEGER}
|
||||||
|
,#{matchConditions,jdbcType=VARCHAR},#{mockResponse,jdbcType=VARCHAR},#{status,jdbcType=CHAR}
|
||||||
|
,#{orderNum,jdbcType=INTEGER})
|
||||||
|
</insert>
|
||||||
|
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.sf.service.gateway.domain.GatewayInterfaceMock" useGeneratedKeys="true">
|
||||||
|
insert into Gateway_interface_mock
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="id != null">id,</if>
|
||||||
|
<if test="interfaceId != null">interfaceId,</if>
|
||||||
|
<if test="httpStatus != null">httpStatus,</if>
|
||||||
|
<if test="matchConditions != null">matchConditions,</if>
|
||||||
|
<if test="mockResponse != null">mockResponse,</if>
|
||||||
|
<if test="status != null">status,</if>
|
||||||
|
<if test="orderNum != null">orderNum,</if>
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="id != null">id = #{id,jdbcType=BIGINT},</if>
|
||||||
|
<if test="interfaceId != null">interface_id = #{interfaceId,jdbcType=BIGINT},</if>
|
||||||
|
<if test="httpStatus != null">http_status = #{httpStatus,jdbcType=INTEGER},</if>
|
||||||
|
<if test="matchConditions != null">match_conditions = #{matchConditions,jdbcType=VARCHAR},</if>
|
||||||
|
<if test="mockResponse != null">mock_response = #{mockResponse,jdbcType=VARCHAR},</if>
|
||||||
|
<if test="status != null">status = #{status,jdbcType=CHAR},</if>
|
||||||
|
<if test="orderNum != null">order_num = #{orderNum,jdbcType=INTEGER},</if>
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<insert id="batchInsertGatewayInterfaceMock">
|
||||||
|
insert into Gateway_interface_mock
|
||||||
|
( interface_id,http_status
|
||||||
|
,match_conditions,mock_response,status
|
||||||
|
,order_num)
|
||||||
|
values
|
||||||
|
<foreach collection="mockList" index="" item="mock" separator=",">
|
||||||
|
(
|
||||||
|
#{mock.interfaceId,jdbcType=BIGINT},
|
||||||
|
#{mock.httpStatus,jdbcType=INTEGER},
|
||||||
|
#{mock.matchConditions,jdbcType=VARCHAR},
|
||||||
|
#{mock.mockResponse,jdbcType=VARCHAR},
|
||||||
|
#{mock.status,jdbcType=CHAR},
|
||||||
|
#{mock.orderNum,jdbcType=INTEGER}
|
||||||
|
)
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="updateByPrimaryKeySelective" parameterType="com.sf.service.gateway.domain.GatewayInterfaceMock">
|
||||||
|
update Gateway_interface_mock
|
||||||
|
<set>
|
||||||
|
<if test="interfaceId != null">
|
||||||
|
interface_id = #{interfaceId,jdbcType=BIGINT},
|
||||||
|
</if>
|
||||||
|
<if test="httpStatus != null">
|
||||||
|
http_status = #{httpStatus,jdbcType=INTEGER},
|
||||||
|
</if>
|
||||||
|
<if test="matchConditions != null">
|
||||||
|
match_conditions = #{matchConditions,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
<if test="mockResponse != null">
|
||||||
|
mock_response = #{mockResponse,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
status = #{status,jdbcType=CHAR},
|
||||||
|
</if>
|
||||||
|
<if test="orderNum != null">
|
||||||
|
order_num = #{orderNum,jdbcType=INTEGER},
|
||||||
|
</if>
|
||||||
|
</set>
|
||||||
|
where id = #{id,jdbcType=BIGINT}
|
||||||
|
</update>
|
||||||
|
<update id="updateByPrimaryKey" parameterType="com.sf.service.gateway.domain.GatewayInterfaceMock">
|
||||||
|
update Gateway_interface_mock
|
||||||
|
set
|
||||||
|
interface_id = #{interfaceId,jdbcType=BIGINT},
|
||||||
|
http_status = #{httpStatus,jdbcType=INTEGER},
|
||||||
|
match_conditions = #{matchConditions,jdbcType=VARCHAR},
|
||||||
|
mock_response = #{mockResponse,jdbcType=VARCHAR},
|
||||||
|
status = #{status,jdbcType=CHAR},
|
||||||
|
order_num = #{orderNum,jdbcType=INTEGER}
|
||||||
|
where id = #{id,jdbcType=BIGINT}
|
||||||
|
</update>
|
||||||
|
</mapper>
|
@ -12,6 +12,8 @@ public class ApiConfig implements Serializable {
|
|||||||
private String uri;
|
private String uri;
|
||||||
private String method; // 大写
|
private String method; // 大写
|
||||||
private Long timeout = 3000L; // 超时时间,单位毫秒
|
private Long timeout = 3000L; // 超时时间,单位毫秒
|
||||||
private String mockResponse;
|
private Integer mockDefaultHttpStatus;
|
||||||
|
private String mockDefaultResponse;
|
||||||
private List<Strategy> strategy; // 策略
|
private List<Strategy> strategy; // 策略
|
||||||
|
private List<MockExpectation> mockExpectations; // mock期望
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.sf.vertx.api.pojo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 网关服务-接口Mock期望
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MockExpectation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http状态码
|
||||||
|
*/
|
||||||
|
private Integer httpStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock响应,JSON字符串
|
||||||
|
*/
|
||||||
|
private String mockResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 匹配条件
|
||||||
|
*/
|
||||||
|
private List<MockMatchCondition> matchConditions;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.sf.vertx.api.pojo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接口Mock匹配条件
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MockMatchCondition {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数位置,header、query、body
|
||||||
|
*/
|
||||||
|
private String parameterPosition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数键值
|
||||||
|
*/
|
||||||
|
private String parameterKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数值,包含、不包含类型允许多个值,所以使用数组,其余类型都只有一个值。
|
||||||
|
*/
|
||||||
|
private List<String> parameterValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 匹配类型
|
||||||
|
*/
|
||||||
|
private String matchType;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.sf.service.gateway.enums;
|
package com.sf.vertx.enums;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 匹配方式
|
* 匹配方式
|
||||||
@ -7,8 +7,16 @@ package com.sf.service.gateway.enums;
|
|||||||
*/
|
*/
|
||||||
public enum MatchType
|
public enum MatchType
|
||||||
{
|
{
|
||||||
EQ("EQ", "完全匹配"),
|
EQ("EQ", "等于"),
|
||||||
IN("IN", "包含匹配"),
|
NOT_EQ("NOT_EQ", "不等于"),
|
||||||
|
GT("GT", "大于"),
|
||||||
|
GE("GE", "大于或等于"),
|
||||||
|
LT("LT", "小于"),
|
||||||
|
LE("LE", "小于或等于"),
|
||||||
|
IN("IN", "包含"),
|
||||||
|
NOT_IN("NOT_IN", "不包含"),
|
||||||
|
IS_NULL("IS_NULL", "等于空"),
|
||||||
|
NOT_NULL("NOT_NULL", "不等于空"),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final String code;
|
private final String code;
|
||||||
@ -32,7 +40,7 @@ public enum MatchType
|
|||||||
|
|
||||||
public static MatchType getByCode(String code){
|
public static MatchType getByCode(String code){
|
||||||
for (MatchType value : MatchType.values()) {
|
for (MatchType value : MatchType.values()) {
|
||||||
if (value.code.equals(code)){
|
if (value.code.equalsIgnoreCase(code)){
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user