网关服务管理

This commit is contained in:
akun 2024-04-23 18:13:18 +08:00
parent 487649c164
commit 0a5b0e8d78
55 changed files with 4742 additions and 0 deletions

View File

@ -0,0 +1,25 @@
package com.sf.common.utils;
import lombok.experimental.UtilityClass;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
/**
* 功能描述: 正则工具类
*
* @author a_kun
* @date 2024/4/23 14:04
*/
@UtilityClass
public class RegexUtils {
public static boolean isRegex(String input) {
try {
Pattern.compile(input);
return true;
} catch (PatternSyntaxException e) {
return false;
}
}
}

View File

@ -0,0 +1,104 @@
package com.sf.common.utils;
import lombok.experimental.UtilityClass;
import org.hibernate.validator.internal.util.DomainNameUtil;
import javax.security.auth.x500.X500Principal;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
/**
* 功能描述: URL工具类
*
* @author a_kun
* @date 2024/4/23 14:04
*/
@UtilityClass
public class URLUtils {
private static final Pattern URL_REGEX = Pattern
.compile(
"(?i)^([a-z](?:[-a-z0-9\\+\\.])*)" + // protocol
":(?:\\/\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:])*@)?" + // auth
"((?:\\[(?:(?:(?:[0-9a-f]{1,4}:){6}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|::(?:[0-9a-f]{1,4}:){5}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:[0-9a-f]{1,4}:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|v[0-9a-f]+[-a-z0-9\\._~!\\$&'\\(\\)\\*\\+,;=:]+)\\]|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}|(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=@])*))" + // host/ip
"(?::([0-9]*))?" + // port
"(?:\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))*)*|\\/(?:(?:(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))+)(?:\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))*)*)?|(?:(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))+)(?:\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))*)*|(?!(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@])))(?:\\?(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@])|[\\x{E000}-\\x{F8FF}\\x{F0000}-\\x{FFFFD}|\\x{100000}-\\x{10FFFD}\\/\\?])*)?(?:\\#(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@])|[\\/\\?])*)?$"
);
public static boolean isURL(String input) {
try {
if ( input == null || input.length() == 0 ) {
return false;
}
URLUtils.ValueHolder values = parseUrl(input);
if ( values == null ) {
return false;
}
if ( !DomainNameUtil.isValidDomainAddress( values.getHost() ) ) {
return false;
}
URL url = new URL(input);
String protocol= url.getProtocol();
String host= url.getHost();;
int port= url.getPort();
if ( protocol != null && protocol.length() > 0 && !protocol.equals( values.getProtocol() ) ) {
return false;
}
if ( host != null && host.length() > 0 && !host.equals( values.getHost() ) ) {
return false;
}
if ( port != -1 && values.getPort() != port ) {
return false;
}
return true;
} catch (MalformedURLException e) {
return false;
}
}
private URLUtils.ValueHolder parseUrl(String stringUrl) {
URLUtils.ValueHolder valueHolder = null;
Matcher regexpMatcher = URL_REGEX.matcher( stringUrl );
if ( regexpMatcher.matches() ) {
String protocol = regexpMatcher.group( 1 );
String host = regexpMatcher.group( 2 );
int port = -1;
String portMatch = regexpMatcher.group( 3 );
if ( portMatch != null ) {
port = Integer.parseInt( portMatch );
}
valueHolder = new URLUtils.ValueHolder( protocol, host, port );
}
return valueHolder;
}
private static class ValueHolder {
private final String protocol;
private final String host;
private final int port;
public ValueHolder(String protocol, String host, int port) {
this.protocol = protocol;
this.host = host;
this.port = port;
}
public String getHost() {
return host;
}
public String getProtocol() {
return protocol;
}
public int getPort() {
return port;
}
}
}

View File

@ -0,0 +1,78 @@
package com.sf.service.gateway.controller;
import apijson.JSON;
import com.sf.common.annotation.Log;
import com.sf.common.core.controller.BaseController;
import com.sf.common.core.domain.AjaxResult;
import com.sf.common.core.page.TableDataInfo;
import com.sf.common.enums.BusinessType;
import com.sf.common.utils.poi.ExcelUtil;
import com.sf.service.gateway.domain.GatewayConfig;
import com.sf.service.gateway.domain.GatewayStrategy;
import com.sf.service.gateway.domain.dto.QueryGatewayStrategyDTO;
import com.sf.service.gateway.domain.dto.UpdateDataStatusDTO;
import com.sf.service.gateway.domain.vo.GatewayStrategyListVO;
import com.sf.service.gateway.enums.GatewayDataStatus;
import com.sf.service.gateway.service.IGatewayConfigService;
import com.sf.service.gateway.service.IGatewayStrategyService;
import com.sf.service.index.util.AppUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 网关配置管理Controller
*
* @author zoukun
* @date 2024-04-25
*/
@RestController
@RequestMapping("/gateway/config")
public class GatewayConfigController extends BaseController
{
@Autowired
private IGatewayConfigService gatewayConfigService;
/**
* 获取网关配置信息
*/
@PreAuthorize("@ss.hasPermi('gateway:config:query')")
@GetMapping
public AjaxResult getInfo()
{
String appCode = AppUtils.getAppCodeFromRequestHeader();
GatewayConfig gatewayConfig = gatewayConfigService.selectGatewayConfigByAppCode(appCode);
if (gatewayConfig == null) {
gatewayConfig = new GatewayConfig();
gatewayConfig.setAppCode(appCode);
gatewayConfig.setDataEncryptionStatus(GatewayDataStatus.DISABLE.getCode());
gatewayConfig.setApiCurrentLimitingStatus(GatewayDataStatus.DISABLE.getCode());
String defaultResponse = JSON.toJSONString(AjaxResult.error("系统繁忙,请稍后重试!"));
gatewayConfig.setApiCurrentLimitingDefaultResponse(defaultResponse);
gatewayConfig.setAppCurrentLimitingStatus(GatewayDataStatus.DISABLE.getCode());
gatewayConfig.setAppCurrentLimitingDefaultResponse(defaultResponse);
}
return success(gatewayConfig);
}
/**
* 修改网关配置
*/
@PreAuthorize("@ss.hasPermi('gateway:config:edit')")
@Log(title = "网关配置", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody GatewayConfig gatewayConfig)
{
gatewayConfigService.updateGatewayConfig(gatewayConfig);
return success();
}
}

View File

@ -0,0 +1,185 @@
package com.sf.service.gateway.controller;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
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.UpdateGatewayInterfaceInfoDTO;
import com.sf.service.gateway.domain.vo.GatewayInterfaceInfoDetailedVO;
import com.sf.service.gateway.domain.vo.GatewayInterfaceInfoListVO;
import com.sf.service.gateway.domain.vo.GatewayStrategyListVO;
import com.sf.service.gateway.enums.GatewayDataStatus;
import com.sf.service.gateway.service.IGatewayInterfaceInfoService;
import com.sf.service.gateway.service.IGatewayServerService;
import com.sf.service.gateway.service.IGatewayStrategyService;
import com.sf.service.index.util.AppUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sf.common.annotation.Log;
import com.sf.common.core.controller.BaseController;
import com.sf.common.core.domain.AjaxResult;
import com.sf.common.enums.BusinessType;
import com.sf.common.utils.poi.ExcelUtil;
import com.sf.common.core.page.TableDataInfo;
/**
* 接口管理Controller
*
* @author zoukun
* @date 2024-04-22
*/
@Api("网关服务-接口管理")
@RestController
@RequestMapping("/gateway/interface")
public class GatewayInterfaceInfoController extends BaseController
{
@Autowired
private IGatewayInterfaceInfoService gatewayInterfaceInfoService;
@Autowired
private IGatewayServerService gatewayServerService;
@Autowired
private IGatewayStrategyService gatewayStrategyService;
@ApiOperation("查询接口信息列表")
@PreAuthorize("@ss.hasPermi('gateway:interface:list')")
@GetMapping("/list")
public TableDataInfo list(GatewayInterfaceInfo gatewayInterfaceInfo)
{
gatewayInterfaceInfo.setAppCode(AppUtils.getAppCodeFromRequestHeader());
startPage();
List<GatewayInterfaceInfo> list = gatewayInterfaceInfoService.selectGatewayInterfaceInfoList(gatewayInterfaceInfo);
Set<Long> serverIds = list.stream().map(GatewayInterfaceInfo::getServerId).collect(Collectors.toSet());
List<GatewayServer> serverList = gatewayServerService.selectGatewayServerByIds(serverIds);
Map<Long, String> serverIdAndNameMap = serverList.stream().collect(Collectors.toMap(GatewayServer::getId, GatewayServer::getServerName));
List<GatewayInterfaceInfoListVO> voList = list.stream().map(info -> {
GatewayInterfaceInfoListVO vo = new GatewayInterfaceInfoListVO();
vo.setId(info.getId());
vo.setInterfaceName(info.getInterfaceName());
vo.setInterfacePath(info.getInterfacePath());
vo.setRequestMethod(info.getRequestMethod());
vo.setDescription(info.getDescription());
vo.setVersion(info.getVersion());
vo.setStatus(info.getStatus());
vo.setDocument(info.getDocument());
// TODO 调用次数和平均时间暂时没有来源
vo.setNumberOfCalls(0L);
vo.setAverageResponseTime(0L);
vo.setCreateTime(info.getCreateTime());
vo.setServerId(info.getServerId());
vo.setServerName(serverIdAndNameMap.get(info.getServerId()));
return vo;
}).collect(Collectors.toList());
return getDataTable(voList);
}
@ApiOperation("导出接口信息列表")
@PreAuthorize("@ss.hasPermi('gateway:interface:export')")
@Log(title = "接口管理", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, GatewayInterfaceInfo gatewayInterfaceInfo)
{
List<GatewayInterfaceInfo> list = gatewayInterfaceInfoService.selectGatewayInterfaceInfoList(gatewayInterfaceInfo);
ExcelUtil<GatewayInterfaceInfo> util = new ExcelUtil<GatewayInterfaceInfo>(GatewayInterfaceInfo.class);
util.exportExcel(response, list, "接口管理数据");
}
@ApiOperation("获取接口详细信息")
@PreAuthorize("@ss.hasPermi('gateway:interface:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
GatewayInterfaceInfoDetailedVO vo = new GatewayInterfaceInfoDetailedVO();
GatewayInterfaceInfo gatewayInterfaceInfo = gatewayInterfaceInfoService.selectGatewayInterfaceInfoById(id);
List<GatewayInterfaceLinkStrategy> linkList = gatewayInterfaceInfoService.selectGatewayInterfaceLinkStrategyByInterfaceIds(Collections.singleton(id));
GatewayServer gatewayServer = gatewayServerService.selectGatewayServerById(gatewayInterfaceInfo.getServerId());
List<GatewayStrategy> strategyList = gatewayStrategyService.selectGatewayStrategyByIds(linkList.stream().map(GatewayInterfaceLinkStrategy::getStrategyId).collect(Collectors.toSet()));
vo.setId(gatewayInterfaceInfo.getId());
vo.setInterfaceName(gatewayInterfaceInfo.getInterfaceName());
vo.setInterfacePath(gatewayInterfaceInfo.getInterfacePath());
vo.setRequestMethod(gatewayInterfaceInfo.getRequestMethod());
vo.setDescription(gatewayInterfaceInfo.getDescription());
vo.setVersion(gatewayInterfaceInfo.getVersion());
vo.setStatus(gatewayInterfaceInfo.getStatus());
vo.setDocument(gatewayInterfaceInfo.getDocument());
// TODO 调用次数和平均时间暂时没有来源
vo.setNumberOfCalls(0L);
vo.setAverageResponseTime(0L);
vo.setCreateTime(gatewayInterfaceInfo.getCreateTime());
vo.setUpdateTime(gatewayInterfaceInfo.getUpdateTime());
vo.setServerId(gatewayInterfaceInfo.getServerId());
vo.setServerName(gatewayServer.getServerName());
// 策略信息
List<GatewayStrategyListVO> strategyListVOList = strategyList.stream().map(strategy -> {
GatewayStrategyListVO strategyListVO = new GatewayStrategyListVO();
strategyListVO.setId(strategy.getId());
strategyListVO.setStrategyName(strategy.getStrategyName());
strategyListVO.setStrategyType(strategy.getStrategyType());
strategyListVO.setDescription(strategy.getDescription());
strategyListVO.setStatus(strategy.getStatus());
return strategyListVO;
})
.collect(Collectors.toList());
vo.setStrategyList(strategyListVOList);
return success(vo);
}
@ApiOperation("新增接口信息")
@PreAuthorize("@ss.hasPermi('gateway:interface:add')")
@Log(title = "接口管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody InsertGatewayInterfaceInfoDTO dto)
{
return success(gatewayInterfaceInfoService.insertGatewayInterfaceInfoAndBindStrategy(dto));
}
@ApiOperation("修改接口信息")
@PreAuthorize("@ss.hasPermi('gateway:interface:edit')")
@Log(title = "接口管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody UpdateGatewayInterfaceInfoDTO dto)
{
return success(gatewayInterfaceInfoService.updateGatewayInterfaceInfoAndBindStrategy(dto));
}
@ApiOperation("删除接口信息")
@PreAuthorize("@ss.hasPermi('gateway:interface:remove')")
@Log(title = "接口管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(gatewayInterfaceInfoService.deleteGatewayInterfaceInfoByIds(ids));
}
@ApiOperation("启用/停用接口信息")
@Log(title = "启用/停用接口信息", businessType = BusinessType.UPDATE)
@PutMapping("/status")
public AjaxResult updateStatus(@Validated @RequestBody UpdateDataStatusDTO dto)
{
return toAjax(gatewayInterfaceInfoService.updateGatewayInterfaceInfoStatusByIds(dto.getIds(), GatewayDataStatus.getByCode(dto.getStatus())));
}
}

View File

@ -0,0 +1,157 @@
package com.sf.service.gateway.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson2.JSON;
import com.sf.service.gateway.domain.GatewayRoute;
import com.sf.service.gateway.domain.GatewayStrategy;
import com.sf.service.gateway.domain.dto.InsertOrUpdateGatewayRouteDTO;
import com.sf.service.gateway.domain.dto.QueryGatewayRouteDTO;
import com.sf.service.gateway.domain.dto.QueryGatewayStrategyDTO;
import com.sf.service.gateway.domain.vo.GatewayRouteListVO;
import com.sf.service.gateway.domain.vo.GatewayStrategyListVO;
import com.sf.service.gateway.enums.GatewayDataStatus;
import com.sf.service.gateway.service.IGatewayRouteService;
import com.sf.service.index.util.AppUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sf.common.annotation.Log;
import com.sf.common.core.controller.BaseController;
import com.sf.common.core.domain.AjaxResult;
import com.sf.common.enums.BusinessType;
import com.sf.common.utils.poi.ExcelUtil;
import com.sf.common.core.page.TableDataInfo;
/**
* 路由管理Controller
*
* @author 邹坤
* @date 2024-04-22
*/
@RestController
@RequestMapping("/gateway/route")
public class GatewayRouteController extends BaseController
{
@Autowired
private IGatewayRouteService gatewayRouteService;
/**
* 查询路由管理列表
*/
@PreAuthorize("@ss.hasPermi('gateway:route:list')")
@GetMapping("/list")
public TableDataInfo list(GatewayRoute gatewayRoute)
{
startPage();
List<GatewayRoute> list = gatewayRouteService.selectGatewayRouteList(gatewayRoute);
List<GatewayRouteListVO> voList = list.stream().map(item ->{
GatewayRouteListVO vo = new GatewayRouteListVO();
vo.setId(item.getId());
vo.setRouteName(item.getRouteName());
vo.setRequestProtocol(item.getRequestProtocol());
vo.setRouteType(item.getRouteType());
vo.setRouteContent(JSON.parseArray(item.getRouteContent(),GatewayRoute.RouteContent.class));
vo.setRouteStatusActiveMonitoring(item.getRouteStatusActiveMonitoring());
vo.setRouteActiveMonitoringPath(item.getRouteActiveMonitoringPath());
vo.setRouteActiveMonitoringTimeout(item.getRouteActiveMonitoringTimeout());
vo.setCreated(item.getCreated());
vo.setCreateTime(item.getCreateTime());
vo.setRouteActiveStatus(item.getRouteActiveStatus());
return vo;
}).collect(Collectors.toList());
return getDataTable(voList);
}
/**
* 导出路由管理列表
*/
@PreAuthorize("@ss.hasPermi('gateway:route:export')")
@Log(title = "路由管理", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, GatewayRoute gatewayRoute)
{
List<GatewayRoute> list = gatewayRouteService.selectGatewayRouteList(gatewayRoute);
ExcelUtil<GatewayRoute> util = new ExcelUtil<GatewayRoute>(GatewayRoute.class);
util.exportExcel(response, list, "路由管理数据");
}
/**
* 获取路由管理详细信息
*/
@PreAuthorize("@ss.hasPermi('gateway:route:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return success(gatewayRouteService.selectGatewayRouteById(id));
}
/**
* 新增路由管理
*/
@PreAuthorize("@ss.hasPermi('gateway:route:add')")
@Log(title = "路由管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody InsertOrUpdateGatewayRouteDTO dto)
{
return toAjax(gatewayRouteService.insertGatewayRoute(dto));
}
/**
* 修改路由管理
*/
@PreAuthorize("@ss.hasPermi('gateway:route:edit')")
@Log(title = "路由管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody InsertOrUpdateGatewayRouteDTO dto)
{
return toAjax(gatewayRouteService.updateGatewayRoute(dto));
}
/**
* 删除路由管理
*/
@PreAuthorize("@ss.hasPermi('gateway:route:remove')")
@Log(title = "路由管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(gatewayRouteService.deleteGatewayRouteByIds(ids));
}
/**
* 查询可绑定的路由列表不分页
*/
@GetMapping("/bindableList")
public List<GatewayRouteListVO> bindableList(QueryGatewayRouteDTO dto)
{
GatewayRoute gatewayRoute = new GatewayRoute();
gatewayRoute.setRouteName(dto.getRouteName());
gatewayRoute.setAppCode(AppUtils.getAppCodeFromRequestHeader());
Map<String, Object> params = new HashMap<>(8);
params.put("ids",dto.getIds());
params.put("excludedIds",dto.getExcludedIds());
gatewayRoute.setParams(params);
List<GatewayRoute> list = gatewayRouteService.selectGatewayRouteList(gatewayRoute);
return list.stream().map(item ->{
GatewayRouteListVO vo = new GatewayRouteListVO();
vo.setId(item.getId());
vo.setRouteName(item.getRouteName());
vo.setRouteType(item.getRouteType());
return vo;
}).collect(Collectors.toList());
}
}

View File

@ -0,0 +1,185 @@
package com.sf.service.gateway.controller;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
import com.sf.service.gateway.domain.GatewayRoute;
import com.sf.service.gateway.domain.GatewayServer;
import com.sf.service.gateway.domain.dto.UpdateDataStatusDTO;
import com.sf.service.gateway.domain.vo.GatewayInterfaceInfoListVO;
import com.sf.service.gateway.domain.vo.GatewayServerDetailedVO;
import com.sf.service.gateway.domain.vo.GatewayServerListVO;
import com.sf.service.gateway.enums.GatewayDataStatus;
import com.sf.service.gateway.enums.GatewayServiceModel;
import com.sf.service.gateway.service.IGatewayInterfaceInfoService;
import com.sf.service.gateway.service.IGatewayRouteService;
import com.sf.service.gateway.service.IGatewayServerService;
import com.sf.service.index.util.AppUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sf.common.annotation.Log;
import com.sf.common.core.controller.BaseController;
import com.sf.common.core.domain.AjaxResult;
import com.sf.common.enums.BusinessType;
import com.sf.common.utils.poi.ExcelUtil;
import com.sf.common.core.page.TableDataInfo;
/**
* 服务管理Controller
*
* @author zoukun
* @date 2024-04-22
*/
@RestController
@RequestMapping("/gateway/server")
public class GatewayServerController extends BaseController {
@Autowired
private IGatewayServerService gatewayServerService;
@Autowired
private IGatewayRouteService gatewayRouteService;
@Autowired
private IGatewayInterfaceInfoService gatewayInterfaceInfoService;
/**
* 查询服务管理列表
*/
@PreAuthorize("@ss.hasPermi('gateway:server:list')")
@GetMapping("/list")
public TableDataInfo list(GatewayServer gatewayServer) {
gatewayServer.setAppCode(AppUtils.getAppCodeFromRequestHeader());
startPage();
List<GatewayServer> list = gatewayServerService.selectGatewayServerList(gatewayServer);
// 如果是路由模式的服务查询对应的路由服务信息
Collection<Long> routeIds = list.stream().filter(item -> GatewayServiceModel.ROUTE.getCode().equals(item.getServiceModel()))
.map(GatewayServer::getRouteId)
.collect(Collectors.toSet());
List<GatewayRoute> routeList = gatewayRouteService.selectGatewayRouteByIds(routeIds);
Map<Long, String> routeIdAndNameMap = routeList.stream().collect(Collectors.toMap(GatewayRoute::getId, GatewayRoute::getRouteName));
List<GatewayServerListVO> voList = list.stream().map(item -> {
GatewayServerListVO vo = new GatewayServerListVO();
vo.setId(item.getId());
vo.setServerName(item.getServerName());
vo.setServerAddress(GatewayServiceModel.ROUTE.getCode().equals(item.getServiceModel()) ?
routeIdAndNameMap.get(item.getRouteId()) : item.getServerAddress());
vo.setStatus(item.getStatus());
vo.setCreated(item.getCreated());
vo.setModified(item.getModified());
vo.setServiceModel(item.getServiceModel());
vo.setRouteId(item.getRouteId());
vo.setCreateTime(item.getCreateTime());
vo.setUpdateTime(item.getUpdateTime());
return vo;
}).collect(Collectors.toList());
return getDataTable(voList);
}
/**
* 导出服务管理列表
*/
@PreAuthorize("@ss.hasPermi('gateway:server:export')")
@Log(title = "服务管理", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, GatewayServer gatewayServer) {
List<GatewayServer> list = gatewayServerService.selectGatewayServerList(gatewayServer);
ExcelUtil<GatewayServer> util = new ExcelUtil<GatewayServer>(GatewayServer.class);
util.exportExcel(response, list, "服务管理数据");
}
/**
* 获取服务管理详细信息
*/
@PreAuthorize("@ss.hasPermi('gateway:server:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
GatewayServerDetailedVO vo = new GatewayServerDetailedVO();
GatewayServer gatewayServer = gatewayServerService.selectGatewayServerById(id);
List<GatewayInterfaceInfo> interfaceInfoList = gatewayInterfaceInfoService.selectGatewayInterfaceInfoByServerIds(Collections.singleton(id));
if (GatewayServiceModel.ROUTE.getCode().equals(gatewayServer.getServiceModel())){
GatewayRoute route = gatewayRouteService.selectGatewayRouteById(gatewayServer.getRouteId());
vo.setServerAddress(route.getRouteName());
}else {
vo.setServerAddress(gatewayServer.getServerAddress());
}
vo.setId(gatewayServer.getId());
vo.setServerName(gatewayServer.getServerName());
vo.setStatus(gatewayServer.getStatus());
vo.setCreated(gatewayServer.getCreated());
vo.setModified(gatewayServer.getModified());
vo.setServiceModel(gatewayServer.getServiceModel());
vo.setRouteId(gatewayServer.getRouteId());
vo.setCreateTime(gatewayServer.getCreateTime());
vo.setUpdateTime(gatewayServer.getUpdateTime());
List<GatewayInterfaceInfoListVO> interfaceInfoListVOList = interfaceInfoList.stream().map(info -> {
GatewayInterfaceInfoListVO interfaceInfoListVO = new GatewayInterfaceInfoListVO();
interfaceInfoListVO.setId(info.getId());
interfaceInfoListVO.setInterfaceName(info.getInterfaceName());
interfaceInfoListVO.setInterfacePath(info.getInterfacePath());
interfaceInfoListVO.setRequestMethod(info.getRequestMethod());
interfaceInfoListVO.setDescription(info.getDescription());
interfaceInfoListVO.setVersion(info.getVersion());
interfaceInfoListVO.setStatus(info.getStatus());
interfaceInfoListVO.setDocument(info.getDocument());
return interfaceInfoListVO;
}).collect(Collectors.toList());
vo.setInterfaceInfoList(interfaceInfoListVOList);
return success(vo);
}
/**
* 新增服务管理
*/
@PreAuthorize("@ss.hasPermi('gateway:server:add')")
@Log(title = "服务管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody GatewayServer gatewayServer) {
gatewayServer.setAppCode(AppUtils.getAppCodeFromRequestHeader());
String username = getUsername();
gatewayServer.setCreated(username);
gatewayServer.setModified(username);
return toAjax(gatewayServerService.insertGatewayServer(gatewayServer));
}
/**
* 修改服务管理
*/
@PreAuthorize("@ss.hasPermi('gateway:server:edit')")
@Log(title = "服务管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody GatewayServer gatewayServer) {
return toAjax(gatewayServerService.updateGatewayServer(gatewayServer));
}
/**
* 删除服务管理
*/
@PreAuthorize("@ss.hasPermi('gateway:server:remove')")
@Log(title = "服务管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(gatewayServerService.deleteGatewayServerByIds(ids));
}
@ApiOperation("启用/停用网关服务")
@Log(title = "启用/停用网关服务", businessType = BusinessType.UPDATE)
@PutMapping("/status")
public AjaxResult updateStatus(@Validated @RequestBody UpdateDataStatusDTO dto) {
return toAjax(gatewayServerService.updateGatewayServerStatusByIds(dto.getIds(), GatewayDataStatus.getByCode(dto.getStatus())));
}
}

View File

@ -0,0 +1,157 @@
package com.sf.service.gateway.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import com.sf.service.gateway.domain.GatewayStrategy;
import com.sf.service.gateway.domain.dto.QueryGatewayStrategyDTO;
import com.sf.service.gateway.domain.dto.UpdateDataStatusDTO;
import com.sf.service.gateway.domain.vo.GatewayInterfaceInfoListVO;
import com.sf.service.gateway.domain.vo.GatewayStrategyListVO;
import com.sf.service.gateway.enums.GatewayDataStatus;
import com.sf.service.gateway.service.IGatewayStrategyService;
import com.sf.service.index.util.AppUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sf.common.annotation.Log;
import com.sf.common.core.controller.BaseController;
import com.sf.common.core.domain.AjaxResult;
import com.sf.common.enums.BusinessType;
import com.sf.common.utils.poi.ExcelUtil;
import com.sf.common.core.page.TableDataInfo;
/**
* 策略管理Controller
*
* @author zoukun
* @date 2024-04-22
*/
@RestController
@RequestMapping("/gateway/strategy")
public class GatewayStrategyController extends BaseController
{
@Autowired
private IGatewayStrategyService gatewayStrategyService;
/**
* 查询策略管理列表
*/
@PreAuthorize("@ss.hasPermi('gateway:strategy:list')")
@GetMapping("/list")
public TableDataInfo list(GatewayStrategy gatewayStrategy)
{
gatewayStrategy.setAppCode(AppUtils.getAppCodeFromRequestHeader());
startPage();
List<GatewayStrategy> list = gatewayStrategyService.selectGatewayStrategyList(gatewayStrategy);
return getDataTable(list);
}
/**
* 导出策略管理列表
*/
@PreAuthorize("@ss.hasPermi('gateway:strategy:export')")
@Log(title = "策略管理", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, GatewayStrategy gatewayStrategy)
{
List<GatewayStrategy> list = gatewayStrategyService.selectGatewayStrategyList(gatewayStrategy);
ExcelUtil<GatewayStrategy> util = new ExcelUtil<GatewayStrategy>(GatewayStrategy.class);
util.exportExcel(response, list, "策略管理数据");
}
/**
* 获取策略管理详细信息
*/
@PreAuthorize("@ss.hasPermi('gateway:strategy:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return success(gatewayStrategyService.selectGatewayStrategyById(id));
}
/**
* 新增策略管理
*/
@PreAuthorize("@ss.hasPermi('gateway:strategy:add')")
@Log(title = "策略管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody GatewayStrategy gatewayStrategy)
{
gatewayStrategy.setAppCode(AppUtils.getAppCodeFromRequestHeader());
String username = getUsername();
gatewayStrategy.setCreated(username);
gatewayStrategy.setModified(username);
return toAjax(gatewayStrategyService.insertGatewayStrategy(gatewayStrategy));
}
/**
* 修改策略管理
*/
@PreAuthorize("@ss.hasPermi('gateway:strategy:edit')")
@Log(title = "策略管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody GatewayStrategy gatewayStrategy)
{
gatewayStrategy.setModified(getUsername());
return toAjax(gatewayStrategyService.updateGatewayStrategy(gatewayStrategy));
}
/**
* 删除策略管理
*/
@PreAuthorize("@ss.hasPermi('gateway:strategy:remove')")
@Log(title = "策略管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(gatewayStrategyService.deleteGatewayStrategyByIds(ids));
}
@ApiOperation("启用/停用网关策略")
@Log(title = "启用/停用网关策略", businessType = BusinessType.UPDATE)
@PutMapping("/status")
public AjaxResult updateStatus(@Validated @RequestBody UpdateDataStatusDTO dto)
{
return toAjax(gatewayStrategyService.updateGatewayStrategyStatusByIds(dto.getIds(), GatewayDataStatus.getByCode(dto.getStatus())));
}
/**
* 查询可用的策略列表状态为启用的,不分页
*/
@GetMapping("/bindableList")
public List<GatewayStrategyListVO> bindableList(QueryGatewayStrategyDTO dto)
{
GatewayStrategy gatewayStrategy = new GatewayStrategy();
gatewayStrategy.setStatus(GatewayDataStatus.ENABLE.getCode());
gatewayStrategy.setStrategyName(dto.getStrategyName());
gatewayStrategy.setStrategyType(dto.getStrategyType());
gatewayStrategy.setAppCode(AppUtils.getAppCodeFromRequestHeader());
Map<String, Object> params = new HashMap<>(8);
params.put("ids",dto.getIds());
params.put("excludedIds",dto.getExcludedIds());
gatewayStrategy.setParams(params);
List<GatewayStrategy> list = gatewayStrategyService.selectGatewayStrategyList(gatewayStrategy);
return list.stream().map(item ->{
GatewayStrategyListVO vo = new GatewayStrategyListVO();
vo.setId(item.getId());
vo.setStrategyName(item.getStrategyName());
vo.setStrategyType(item.getStrategyType());
vo.setDescription(item.getDescription());
vo.setStatus(item.getStatus());
return vo;
}).collect(Collectors.toList());
}
}

View File

@ -0,0 +1,102 @@
package com.sf.service.gateway.domain;
import java.util.Date;
import java.util.Date;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
/**
* 网关服务-app网关配置表
* @TableName Gateway_config
*/
@Data
public class GatewayConfig {
/**
* 应用编号
*/
@ApiModelProperty("应用编号")
private String appCode;
/**
* 是否启用数据加密0关闭1启用
*/
@ApiModelProperty("是否启用数据加密0关闭1启用")
private String dataEncryptionStatus;
/**
* 加密算法ECC RSA 国密
*/
@ApiModelProperty("加密算法ECC RSA 国密SM2")
private String encryptionAlgorithm;
/**
* 私钥当加密算法为 ECC 或国密SM2时填写私钥内容当加密算法为 RSA 分别填写公私钥内容)
*/
@ApiModelProperty("私钥(当加密算法为 ECC 或国密SM2时填写私钥内容。当加密算法为 RSA 时,分别填写公私钥内容。)")
private String privateKey;
/**
* 公钥
*/
@ApiModelProperty("公钥")
private String publicKey;
/**
* 接口限流状态0停用 1启用
*/
@ApiModelProperty("接口限流状态0停用 1启用")
private String apiCurrentLimitingStatus;
/**
* 接口限流阈值
*/
@ApiModelProperty("接口限流阈值")
private Integer apiCurrentLimitingThreshold;
/**
* 接口限流时间窗口单位s
*/
@ApiModelProperty("接口限流时间窗口单位s")
private Integer apiCurrentLimitingTimeWindow;
/**
* 接口默认限流响应JSON字符串
*/
@ApiModelProperty("接口默认限流响应JSON字符串")
private String apiCurrentLimitingDefaultResponse;
/**
* APP限流状态0停用 1启用
*/
@ApiModelProperty("APP限流状态0停用 1启用")
private String appCurrentLimitingStatus;
/**
* APP限流阈值
*/
@ApiModelProperty("APP限流阈值")
private Integer appCurrentLimitingThreshold;
/**
* APP限流时间窗口单位s
*/
@ApiModelProperty("APP限流时间窗口单位s")
private Integer appCurrentLimitingTimeWindow;
/**
* APP默认限流响应JSON字符串
*/
@ApiModelProperty("APP默认限流响应JSON字符串")
private String appCurrentLimitingDefaultResponse;
/**
* 创建者
*/
@ApiModelProperty("创建者")
private String created;
/**
* 创建时间
*/
@ApiModelProperty("创建时间")
private Date createTime;
/**
* 更新者
*/
@ApiModelProperty("更新者")
private String modified;
/**
* 更新时间
*/
@ApiModelProperty("更新时间")
private Date updateTime;
}

View File

@ -0,0 +1,78 @@
package com.sf.service.gateway.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import com.sf.common.annotation.Excel;
import com.sf.common.core.domain.BaseEntity;
import lombok.EqualsAndHashCode;
/**
* 接口管理对象 Gateway_interface_info
*
* @author zoukun
* @date 2024-04-22
*/
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "GatewayInterfaceInfo", description = "接口信息对象")
public class GatewayInterfaceInfo extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** ID */
@ApiModelProperty("ID")
private Long id;
/** 接口名称 */
@Excel(name = "接口名称")
@ApiModelProperty("接口名称")
private String interfaceName;
/** 接口路径 */
@Excel(name = "接口路径")
@ApiModelProperty("接口名称")
private String interfacePath;
/** 请求方式 */
@Excel(name = "请求方式")
@ApiModelProperty("请求方式")
private String requestMethod;
/** 接口描述 */
@Excel(name = "接口描述")
@ApiModelProperty("接口描述")
private String description;
/** 接口版本 */
@Excel(name = "接口版本")
@ApiModelProperty("接口版本")
private String version;
/** 接口状态0停用 1启用 */
@Excel(name = "接口状态", readConverterExp = "0=停用,1=启用")
@ApiModelProperty("接口状态(0=停用,1=启用)")
private String status;
/** 接口文档(文档地址) */
@Excel(name = "接口文档", readConverterExp = "文档地址")
@ApiModelProperty("接口文档(文档地址)")
private String document;
@ApiModelProperty("创建者")
private String created;
@ApiModelProperty("更新者")
private String modified;
@ApiModelProperty("应用编号")
private String appCode;
@ApiModelProperty("请求路径是否是正则表达式,0否1是")
private Boolean uriRegular;
@ApiModelProperty("网关服务id")
private Long serverId;
}

View File

@ -0,0 +1,29 @@
package com.sf.service.gateway.domain;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
/**
* 网关服务-接口策略关联表
* @TableName Gateway_interface_link_strategy
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GatewayInterfaceLinkStrategy {
/**
* 接口信息ID
*/
@ApiModelProperty("接口信息ID")
private Long interfaceId;
/**
* 策略id
*/
@ApiModelProperty("策略id")
private Long strategyId;
}

View File

@ -0,0 +1,109 @@
package com.sf.service.gateway.domain;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.sf.common.annotation.Excel;
import com.sf.common.core.domain.BaseEntity;
import org.hibernate.validator.constraints.URL;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* 路由管理对象 Gateway_route
*
* @author 邹坤
* @date 2024-04-22
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class GatewayRoute extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** ID */
private Long id;
/** 路由名称 */
@Excel(name = "路由名称")
@NotBlank(message = "路由名称不能为空")
private String routeName;
/** 请求协议目前只支持HTTP */
@Excel(name = "请求协议")
@NotBlank(message = "请求协议不能为空")
private String requestProtocol;
/** 路由类型WEIGHT_ROUTE=权重路由HEADER_ROUTE=请求头路由) */
@Excel(name = "路由类型")
@NotBlank(message = "路由类型不能为空")
private String routeType;
/** 路由配置信息json数组格式*/
@Excel(name = "路由配置信息json数组格式")
@NotBlank(message = "路由配置信息不能为空")
private String routeContent;
/** 路由状态探活0停用 1启用 */
@Excel(name = "路由状态探活0停用 1启用")
private String routeStatusActiveMonitoring;
/** 路由探活路径 */
@Excel(name = "路由探活路径")
private String routeActiveMonitoringPath;
/** 路由探活超时时间单位ms */
@Excel(name = "路由探活超时时间单位ms")
private Long routeActiveMonitoringTimeout;
@ApiModelProperty("创建者")
private String created;
@ApiModelProperty("更新者")
private String modified;
@ApiModelProperty("应用编号")
private String appCode;
@ApiModelProperty("路由活跃状态0=探活未开启1=状态获取中2=正常3=异常)")
private String routeActiveStatus;
@Data
public static class RouteContent{
/**
* 权重模式使用
* 权重值总值100不能为负数
*/
private Integer weight;
/**
* HEADER模式使用
* 请求头键值
*/
private String headerKey;
/**
* HEADER模式使用
* 请求头value集合
*/
private List<String> headerValues;
/**
* HEADER模式使用
* 请求头值匹配类型EQ,IN
*/
private String matchType;
/**
* 服务地址
*/
private String serverAddress;
}
}

View File

@ -0,0 +1,57 @@
package com.sf.service.gateway.domain;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.sf.common.annotation.Excel;
import com.sf.common.core.domain.BaseEntity;
import org.hibernate.validator.constraints.URL;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
/**
* 服务管理对象 Gateway_server
*
* @author zoukun
* @date 2024-04-22
*/
@Data
public class GatewayServer extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** ID */
private Long id;
/** 服务名称 */
@Excel(name = "服务名称")
@NotBlank(message = "服务名称不能为空")
@Pattern(regexp = "^[a-zA-Z_]\\w{0,49}$",message = "服务名只能以字母或下划线开头只能包含字母、数字、下划线不超过50个字符")
private String serverName;
/** 服务地址 */
@Excel(name = "服务地址")
private String serverAddress;
/** 服务状态 */
@Excel(name = "服务状态")
private String status;
@ApiModelProperty("应用编号")
private String appCode;
@ApiModelProperty("创建者")
private String created;
@ApiModelProperty("更新者")
private String modified;
@ApiModelProperty("服务模式NORMAL=普通模式ROUTE=路由模式)")
private String serviceModel;
@ApiModelProperty("路由规则id")
private Long routeId;
}

View File

@ -0,0 +1,84 @@
package com.sf.service.gateway.domain;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.sf.common.annotation.Excel;
import com.sf.common.core.domain.BaseEntity;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotBlank;
/**
* 策略管理对象 Gateway_strategy
*
* @author zoukun
* @date 2024-04-22
*/
@Data
public class GatewayStrategy extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** ID */
private Long id;
/** 策略名称 */
@Excel(name = "策略名称")
@NotBlank(message = "策略名称不能为空")
private String strategyName;
/** 策略类型AUTHENTICATION=认证策略PERMISSION=鉴权策略CURRENT_LIMITING=限流策略CIRCUIT_BREAKER=熔断策略) */
@Excel(name = "策略类型")
@NotBlank(message = "策略类型不能为空")
private String strategyType;
/** 策略描述 */
@Excel(name = "策略描述")
private String description;
/** 请求方式 */
@Excel(name = "请求方式")
private String requestMethod;
/** 策略状态0停用 1启用 */
@Excel(name = "策略状态", readConverterExp = "0=停用,1=启用")
private String status;
@ApiModelProperty("应用编号")
private String appCode;
@ApiModelProperty("创建者")
private String created;
@ApiModelProperty("更新者")
private String modified;
@ApiModelProperty("接口限流阈值")
@DecimalMin(value = "0",message = "接口限流阈值大于等于0" )
private Integer currentLimitingThreshold;
@ApiModelProperty("接口限流时间窗口单位s")
@DecimalMin(value = "0",message = "接口限流时间窗口大于等于0" )
private Integer currentLimitingTimeWindow;
@ApiModelProperty("接口限流响应JSON字符串")
private String currentLimitingResponse;
@ApiModelProperty("熔断阈值(调用失败阈值)")
@DecimalMin(value = "0",message = "熔断阈值大于等于0" )
private Integer circuitBreakerThreshold;
@ApiModelProperty("调用失败阈值对应的时间窗口单位s")
@DecimalMin(value = "0",message = "调用失败阈值对应的时间窗口大于等于0" )
private Integer circuitBreakerTimeWindow;
@ApiModelProperty("熔断后的恢复时间间隔单位s")
@DecimalMin(value = "0",message = "熔断后的恢复时间间隔大于等于0" )
private Integer circuitBreakerRecoveryInterval;
@ApiModelProperty("熔断响应JSON字符串")
private String circuitBreakerResponse;
}

View File

@ -0,0 +1,55 @@
package com.sf.service.gateway.domain.dto;
import com.sf.common.annotation.Excel;
import com.sf.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
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;
@NotBlank(message = "接口名称不能为空")
@ApiModelProperty("接口名称")
private String interfaceName;
@NotBlank(message = "接口路径不能为空")
@ApiModelProperty("接口路径")
private String interfacePath;
@NotBlank(message = "请求方式不能为空")
@ApiModelProperty("请求方式")
private String requestMethod;
@ApiModelProperty("接口描述")
private String description;
@ApiModelProperty("接口版本")
private String version;
@ApiModelProperty("接口状态(0=停用,1=启用)")
private String status;
@ApiModelProperty("接口文档(文档地址)")
private String document;
@ApiModelProperty("网关服务id")
private Long serverId;
@ApiModelProperty("策略ID集合")
private List<Long> strategyIds;
}

View File

@ -0,0 +1,61 @@
package com.sf.service.gateway.domain.dto;
import com.sf.common.annotation.Excel;
import com.sf.service.gateway.domain.GatewayRoute;
import com.sf.service.gateway.enums.GatewayRouteType;
import com.sf.service.gateway.enums.RequestProtocol;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
/**
* 路由管理对象 Gateway_route
*
* @author 邹坤
* @date 2024-04-22
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class InsertOrUpdateGatewayRouteDTO {
private static final long serialVersionUID = 1L;
/** ID */
private Long id;
/** 路由名称 */
@NotBlank(message = "路由名称不能为空")
private String routeName;
/** 请求协议目前只支持HTTP */
@NotNull(message = "请求协议不正确")
private RequestProtocol requestProtocol;
/** 路由类型WEIGHT_ROUTE=权重路由HEADER_ROUTE=请求头路由) */
@NotNull(message = "路由类型不正确")
private GatewayRouteType routeType;
/** 路由配置信息json格式*/
@Excel(name = "路由配置信息json格式")
@NotNull(message = "路由配置信息不能为空")
@Size(min = 1,message = "路由配置信息最少存在一条")
@Valid
private List<GatewayRoute.RouteContent> routeContent;
/** 路由状态探活0停用 1启用 */
@Excel(name = "路由状态探活0停用 1启用")
private String routeStatusActiveMonitoring;
/** 路由探活路径 */
@Excel(name = "路由探活路径")
private String routeActiveMonitoringPath;
/** 路由探活超时时间单位ms */
@Excel(name = "路由探活超时时间单位ms")
private Long routeActiveMonitoringTimeout;
}

View File

@ -0,0 +1,29 @@
package com.sf.service.gateway.domain.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* 功能描述:
* 查询网关路由
* @author a_kun
* @date 2024/4/26 10:38
*/
@ApiModel("查询网关路由DTO")
@Data
public class QueryGatewayRouteDTO {
@ApiModelProperty("ids")
private List<Long> ids;
@ApiModelProperty("需要排除的id")
private List<Long> excludedIds;
@ApiModelProperty("策略名称")
private String routeName;
}

View File

@ -0,0 +1,40 @@
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;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
/**
* 功能描述:
* 查询网关策略
* @author a_kun
* @date 2024/4/23 10:38
*/
@ApiModel("查询网关策略DTO")
@Data
public class QueryGatewayStrategyDTO {
@ApiModelProperty("ids")
private List<Long> ids;
@ApiModelProperty("状态0停用 1启用")
private String status;
@ApiModelProperty("需要排除的id")
private List<Long> excludedIds;
@ApiModelProperty("策略名称")
private String strategyName;
@ApiModelProperty("策略类型")
private String strategyType;
private String appCode;
}

View File

@ -0,0 +1,29 @@
package com.sf.service.gateway.domain.dto;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
/**
* 功能描述:
* 更新数据状态
* @author a_kun
* @date 2024/4/23 10:38
*/
@Data
public class UpdateDataStatusDTO {
@NotNull(message = "至少需要一条数据ID")
@Size(min = 1,message = "至少需要一条数据ID")
private List<Long> ids;
/**
* 状态0停用 1启用
*/
@NotBlank(message = "状态标识不能为空")
private String status;
}

View File

@ -0,0 +1,58 @@
package com.sf.service.gateway.domain.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* 修改接口信息对象 Gateway_interface_info
*
* @author zoukun
* @date 2024-04-22
*/
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "UpdateGatewayInterfaceInfoDTO", description = "修改接口信息对象")
public class UpdateGatewayInterfaceInfoDTO {
private static final long serialVersionUID = 1L;
@NotNull(message = "ID不能为空")
@ApiModelProperty("ID")
private Long id;
@NotBlank(message = "接口名称不能为空")
@ApiModelProperty("接口名称")
private String interfaceName;
@NotBlank(message = "接口路径不能为空")
@ApiModelProperty("接口路径")
private String interfacePath;
@NotBlank(message = "请求方式不能为空")
@ApiModelProperty("请求方式")
private String requestMethod;
@ApiModelProperty("接口描述")
private String description;
@ApiModelProperty("接口版本")
private String version;
@ApiModelProperty("接口状态(0=停用,1=启用)")
private String status;
@ApiModelProperty("接口文档(文档地址)")
private String document;
@ApiModelProperty("网关服务id")
private Long serverId;
@ApiModelProperty("策略ID集合")
private List<Long> strategyIds;
}

View File

@ -0,0 +1,83 @@
package com.sf.service.gateway.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.sf.common.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* 接口信息详细展示
*
* @author zoukun
* @date 2024-04-22
*/
@Data
@ApiModel(value = "GatewayInterfaceInfoDetailedVO", description = "接口信息详细展示对象")
public class GatewayInterfaceInfoDetailedVO {
private static final long serialVersionUID = 1L;
/** ID */
@ApiModelProperty("ID")
private Long id;
/** 接口名称 */
@Excel(name = "接口名称")
@ApiModelProperty("接口名称")
private String interfaceName;
/** 接口路径 */
@Excel(name = "接口路径")
@ApiModelProperty("接口名称")
private String interfacePath;
/** 请求方式 */
@Excel(name = "请求方式")
@ApiModelProperty("请求方式")
private String requestMethod;
/** 接口描述 */
@Excel(name = "接口描述")
@ApiModelProperty("接口描述")
private String description;
/** 接口版本 */
@Excel(name = "接口版本")
@ApiModelProperty("接口版本")
private String version;
/** 接口状态0停用 1启用 */
@Excel(name = "接口状态", readConverterExp = "0=停用,1=启用")
@ApiModelProperty("接口状态(0=停用,1=启用)")
private String status;
/** 接口文档(文档地址) */
@Excel(name = "接口文档", readConverterExp = "文档地址")
@ApiModelProperty("接口文档(文档地址)")
private String document;
@ApiModelProperty("调用次数")
private Long numberOfCalls;
@ApiModelProperty("响应时间(平均 ms")
private Long averageResponseTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
@ApiModelProperty("网关服务id")
private Long serverId;
@ApiModelProperty("网关服务名称")
private String serverName;
@ApiModelProperty
private List<GatewayStrategyListVO> strategyList;
}

View File

@ -0,0 +1,82 @@
package com.sf.service.gateway.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.sf.common.annotation.Excel;
import com.sf.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* 接口信息列表展示
*
* @author zoukun
* @date 2024-04-22
*/
@Data
@ApiModel(value = "GatewayInterfaceInfoListVO", description = "接口信息列表展示对象")
public class GatewayInterfaceInfoListVO {
private static final long serialVersionUID = 1L;
/** ID */
@ApiModelProperty("ID")
private Long id;
/** 接口名称 */
@Excel(name = "接口名称")
@ApiModelProperty("接口名称")
private String interfaceName;
/** 接口路径 */
@Excel(name = "接口路径")
@ApiModelProperty("接口名称")
private String interfacePath;
/** 请求方式 */
@Excel(name = "请求方式")
@ApiModelProperty("请求方式")
private String requestMethod;
/** 接口描述 */
@Excel(name = "接口描述")
@ApiModelProperty("接口描述")
private String description;
/** 接口版本 */
@Excel(name = "接口版本")
@ApiModelProperty("接口版本")
private String version;
/** 接口状态0停用 1启用 */
@Excel(name = "接口状态", readConverterExp = "0=停用,1=启用")
@ApiModelProperty("接口状态(0=停用,1=启用)")
private String status;
/** 接口文档(文档地址) */
@Excel(name = "接口文档", readConverterExp = "文档地址")
@ApiModelProperty("接口文档(文档地址)")
private String document;
@ApiModelProperty("调用次数")
private Long numberOfCalls;
@ApiModelProperty("响应时间(平均 ms")
private Long averageResponseTime;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@ApiModelProperty("网关服务id")
private Long serverId;
@ApiModelProperty("网关服务名称")
private String serverName;
@ApiModelProperty
private List<GatewayStrategyListVO> strategyList;
}

View File

@ -0,0 +1,65 @@
package com.sf.service.gateway.domain.vo;
import com.sf.common.annotation.Excel;
import com.sf.service.gateway.domain.GatewayRoute;
import com.sf.service.gateway.enums.GatewayRouteType;
import com.sf.service.gateway.enums.RequestProtocol;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;
/**
* 路由列表展示
*
* @author 邹坤
* @date 2024-04-22
*/
@Data
public class GatewayRouteListVO {
private static final long serialVersionUID = 1L;
/** ID */
private Long id;
/** 路由名称 */
private String routeName;
/** 请求协议目前只支持HTTP */
private String requestProtocol;
/** 路由类型WEIGHT_ROUTE=权重路由HEADER_ROUTE=请求头路由) */
private String routeType;
/** 路由配置信息json格式*/
@Excel(name = "路由配置信息json格式")
@NotNull(message = "路由配置信息不能为空")
@Size(min = 1,message = "路由配置信息最少存在一条")
@Valid
private List<GatewayRoute.RouteContent> routeContent;
/** 路由状态探活0停用 1启用 */
private String routeStatusActiveMonitoring;
/** 路由探活路径 */
private String routeActiveMonitoringPath;
/** 路由探活超时时间单位ms */
private Long routeActiveMonitoringTimeout;
@ApiModelProperty("创建者")
private String created;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("路由活跃状态0=探活未开启1=状态获取中2=正常3=异常)")
private String routeActiveStatus;
}

View File

@ -0,0 +1,55 @@
package com.sf.service.gateway.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* 服务详细信息
*
* @author zoukun
* @date 2024-04-22
*/
@Data
@ApiModel( description = "服务详细信息展示对象")
public class GatewayServerDetailedVO {
private static final long serialVersionUID = 1L;
private Long id;
@ApiModelProperty("服务名称")
private String serverName;
@ApiModelProperty("服务地址,路由模式为路由名称")
private String serverAddress;
@ApiModelProperty("服务状态")
private String status;
@ApiModelProperty("创建者")
private String created;
@ApiModelProperty("更新者")
private String modified;
@ApiModelProperty("服务模式NORMAL=普通模式ROUTE=路由模式)")
private String serviceModel;
@ApiModelProperty("路由规则id")
private Long routeId;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 更新时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
@ApiModelProperty("包含的接口信息")
private List<GatewayInterfaceInfoListVO> interfaceInfoList;
}

View File

@ -0,0 +1,55 @@
package com.sf.service.gateway.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.sf.common.annotation.Excel;
import com.sf.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.URL;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.util.Date;
/**
* 服务列表
*
* @author zoukun
* @date 2024-04-22
*/
@Data
public class GatewayServerListVO {
private static final long serialVersionUID = 1L;
private Long id;
@ApiModelProperty("服务名称")
private String serverName;
@ApiModelProperty("服务地址,路由模式为路由名称")
private String serverAddress;
@ApiModelProperty("服务状态")
private String status;
@ApiModelProperty("创建者")
private String created;
@ApiModelProperty("更新者")
private String modified;
@ApiModelProperty("服务模式NORMAL=普通模式ROUTE=路由模式)")
private String serviceModel;
@ApiModelProperty("路由规则id")
private Long routeId;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 更新时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}

View File

@ -0,0 +1,36 @@
package com.sf.service.gateway.domain.vo;
import com.sf.common.annotation.Excel;
import com.sf.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* 策略管理对象 Gateway_strategy
*
* @author zoukun
* @date 2024-04-22
*/
@Data
public class GatewayStrategyListVO {
private static final long serialVersionUID = 1L;
/** ID */
private Long id;
/** 策略名称 */
private String strategyName;
/** 策略类型 */
private String strategyType;
/** 策略描述 */
private String description;
/** 策略状态0停用 1启用 */
private String status;
}

View File

@ -0,0 +1,68 @@
package com.sf.service.gateway.enums;
/**
* 支持的加密算法
* 目前支持 ECCRSA 和国密SM2
*
* @author zoukun
*/
public enum EncryptionAlgorithm
{
ECC("ECC", "ECC"),
RSA("RSA", "RSA"),
SM2("SM2", "国密SM2"),
;
private final String code;
private final String info;
EncryptionAlgorithm(String code, String info)
{
this.code = code;
this.info = info;
}
public String getCode()
{
return code;
}
public String getInfo()
{
return info;
}
public static EncryptionAlgorithm getByCode(String code){
for (EncryptionAlgorithm value : EncryptionAlgorithm.values()) {
if (value.code.equals(code)){
return value;
}
}
return null;
}
/*
密钥生成方法
根据您的业务需求查看生成密钥的方法密钥包括 RSA 密钥ECC 密钥国密密钥
前置条件
您已通过 OpenSSL 官网 下载并安装 OpenSSL 工具1.1.1 或以上版本
生成 RSA 密钥
打开 OpenSSL 工具使用以下命令行生成 RSA 私钥您可以选择生成 1024 2048 位的私钥
openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
根据 RSA 私钥生成 RSA 公钥
openssl rsa -pubout -in private_key.pem -out public_key.pem
生成 ECC 密钥
打开 OpenSSL 工具使用以下命令行生成 ECC 的密钥对您必须选择 secp256k1 椭圆曲线算法
openssl ecparam -name secp256k1 -genkey -noout -out secp256k1-key.pem
根据 secp256k1-key.pem 密钥对生成 ECC 公钥
openssl ec -in secp256k1-key.pem -pubout -out ecpubkey.pem
生成国密密钥
打开 OpenSSL 工具使用以下命令行生成国密 SM2 私钥 sm2-key.pem
openssl ecparam -name SM2 -genkey -noout -out sm2-key.pem
根据 sm2-key.pem 密钥对生成国密 SM2 公钥 sm2pubkey.pem
openssl ec -in sm2-key.pem -pubout -out sm2pubkey.pem
*/
}

View File

@ -0,0 +1,41 @@
package com.sf.service.gateway.enums;
/**
* 网关系统数据状态
*
* @author zoukun
*/
public enum GatewayDataStatus
{
DISABLE("0", "停用"),
ENABLE("1", "启用")
;
private final String code;
private final String info;
GatewayDataStatus(String code, String info)
{
this.code = code;
this.info = info;
}
public String getCode()
{
return code;
}
public String getInfo()
{
return info;
}
public static GatewayDataStatus getByCode(String code){
for (GatewayDataStatus value : GatewayDataStatus.values()) {
if (value.code.equals(code)){
return value;
}
}
return null;
}
}

View File

@ -0,0 +1,45 @@
package com.sf.service.gateway.enums;
import org.springframework.util.StringUtils;
/**
* 网关路由类型
*
* @author zoukun
*/
public enum GatewayRouteType
{
WEIGHT_ROUTE("WEIGHT_ROUTE", "权重路由策略"),
HEADER_ROUTE("HEADER_ROUTE", "请求头路由策略"),
;
private final String code;
private final String info;
GatewayRouteType(String code, String info)
{
this.code = code;
this.info = info;
}
public String getCode()
{
return code;
}
public String getInfo()
{
return info;
}
public static GatewayRouteType getByCode(String code){
if (StringUtils.hasText(code)) {
for (GatewayRouteType value : GatewayRouteType.values()) {
if (value.code.equals(code)){
return value;
}
}
}
return null;
}
}

View File

@ -0,0 +1,45 @@
package com.sf.service.gateway.enums;
import org.springframework.util.StringUtils;
/**
* 网关服务模式
*
* @author zoukun
*/
public enum GatewayServiceModel
{
NORMAL("NORMAL", "普通模式"),
ROUTE("ROUTE", "路由模式"),
;
private final String code;
private final String info;
GatewayServiceModel(String code, String info)
{
this.code = code;
this.info = info;
}
public String getCode()
{
return code;
}
public String getInfo()
{
return info;
}
public static GatewayServiceModel getByCode(String code){
if (StringUtils.hasText(code)) {
for (GatewayServiceModel value : GatewayServiceModel.values()) {
if (value.code.equals(code)){
return value;
}
}
}
return null;
}
}

View File

@ -0,0 +1,43 @@
package com.sf.service.gateway.enums;
/**
* 网关策略类型
*
* @author zoukun
*/
public enum GatewayStrategyType
{
AUTHENTICATION("AUTHENTICATION", "认证策略"),
PERMISSION("PERMISSION", "鉴权策略"),
CURRENT_LIMITING("CURRENT_LIMITING", "限流策略"),
CIRCUIT_BREAKER("CIRCUIT_BREAKER", "熔断策略")
;
private final String code;
private final String info;
GatewayStrategyType(String code, String info)
{
this.code = code;
this.info = info;
}
public String getCode()
{
return code;
}
public String getInfo()
{
return info;
}
public static GatewayStrategyType getByCode(String code){
for (GatewayStrategyType value : GatewayStrategyType.values()) {
if (value.code.equals(code)){
return value;
}
}
return null;
}
}

View File

@ -0,0 +1,66 @@
package com.sf.service.gateway.enums;
/**
* 匹配方式
*
* @author zoukun
*/
public enum MatchType
{
EQ("EQ", "完全匹配"),
IN("IN", "包含匹配"),
;
private final String code;
private final String info;
MatchType(String code, String info)
{
this.code = code;
this.info = info;
}
public String getCode()
{
return code;
}
public String getInfo()
{
return info;
}
public static MatchType getByCode(String code){
for (MatchType value : MatchType.values()) {
if (value.code.equals(code)){
return value;
}
}
return null;
}
/*
密钥生成方法
根据您的业务需求查看生成密钥的方法密钥包括 RSA 密钥ECC 密钥国密密钥
前置条件
您已通过 OpenSSL 官网 下载并安装 OpenSSL 工具1.1.1 或以上版本
生成 RSA 密钥
打开 OpenSSL 工具使用以下命令行生成 RSA 私钥您可以选择生成 1024 2048 位的私钥
openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
根据 RSA 私钥生成 RSA 公钥
openssl rsa -pubout -in private_key.pem -out public_key.pem
生成 ECC 密钥
打开 OpenSSL 工具使用以下命令行生成 ECC 的密钥对您必须选择 secp256k1 椭圆曲线算法
openssl ecparam -name secp256k1 -genkey -noout -out secp256k1-key.pem
根据 secp256k1-key.pem 密钥对生成 ECC 公钥
openssl ec -in secp256k1-key.pem -pubout -out ecpubkey.pem
生成国密密钥
打开 OpenSSL 工具使用以下命令行生成国密 SM2 私钥 sm2-key.pem
openssl ecparam -name SM2 -genkey -noout -out sm2-key.pem
根据 sm2-key.pem 密钥对生成国密 SM2 公钥 sm2pubkey.pem
openssl ec -in sm2-key.pem -pubout -out sm2pubkey.pem
*/
}

View File

@ -0,0 +1,66 @@
package com.sf.service.gateway.enums;
/**
* 支持的请求协议
* 目前支持 HTTP
*
* @author zoukun
*/
public enum RequestProtocol
{
HTTP("HTTP", "HTTP"),
;
private final String code;
private final String info;
RequestProtocol(String code, String info)
{
this.code = code;
this.info = info;
}
public String getCode()
{
return code;
}
public String getInfo()
{
return info;
}
public static RequestProtocol getByCode(String code){
for (RequestProtocol value : RequestProtocol.values()) {
if (value.code.equals(code)){
return value;
}
}
return null;
}
/*
密钥生成方法
根据您的业务需求查看生成密钥的方法密钥包括 RSA 密钥ECC 密钥国密密钥
前置条件
您已通过 OpenSSL 官网 下载并安装 OpenSSL 工具1.1.1 或以上版本
生成 RSA 密钥
打开 OpenSSL 工具使用以下命令行生成 RSA 私钥您可以选择生成 1024 2048 位的私钥
openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
根据 RSA 私钥生成 RSA 公钥
openssl rsa -pubout -in private_key.pem -out public_key.pem
生成 ECC 密钥
打开 OpenSSL 工具使用以下命令行生成 ECC 的密钥对您必须选择 secp256k1 椭圆曲线算法
openssl ecparam -name secp256k1 -genkey -noout -out secp256k1-key.pem
根据 secp256k1-key.pem 密钥对生成 ECC 公钥
openssl ec -in secp256k1-key.pem -pubout -out ecpubkey.pem
生成国密密钥
打开 OpenSSL 工具使用以下命令行生成国密 SM2 私钥 sm2-key.pem
openssl ecparam -name SM2 -genkey -noout -out sm2-key.pem
根据 sm2-key.pem 密钥对生成国密 SM2 公钥 sm2pubkey.pem
openssl ec -in sm2-key.pem -pubout -out sm2pubkey.pem
*/
}

View File

@ -0,0 +1,47 @@
package com.sf.service.gateway.enums;
import org.springframework.util.StringUtils;
/**
* 路由活跃状态
*
* @author zoukun
*/
public enum RouteActiveStatus
{
NOT_ENABLED("0", "探活未开启"),
OBTAINING("1", "状态获取中"),
NORMAL("2", "正常"),
ABNORMAL("3", "异常"),
;
private final String code;
private final String info;
RouteActiveStatus(String code, String info)
{
this.code = code;
this.info = info;
}
public String getCode()
{
return code;
}
public String getInfo()
{
return info;
}
public static RouteActiveStatus getByCode(String code){
if (StringUtils.hasText(code)) {
for (RouteActiveStatus value : RouteActiveStatus.values()) {
if (value.code.equals(code)){
return value;
}
}
}
return null;
}
}

View File

@ -0,0 +1,26 @@
package com.sf.service.gateway.mapper;
import com.sf.service.gateway.domain.GatewayConfig;
/**
* @Entity com.sf.service.gateway.domain.GatewayConfig
*/
public interface GatewayConfigMapper {
int deleteByAppCode(String appCode);
int insert(GatewayConfig record);
int insertSelective(GatewayConfig record);
GatewayConfig selectByAppCode(String appCode);
int updateByAppCodeSelective(GatewayConfig record);
int updateByAppCode(GatewayConfig record);
}

View File

@ -0,0 +1,68 @@
package com.sf.service.gateway.mapper;
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
/**
* 接口管理Mapper接口
*
* @author zoukun
* @date 2024-04-22
*/
public interface GatewayInterfaceInfoMapper
{
/**
* 查询接口管理
*
* @param id 接口管理主键
* @return 接口管理
*/
public GatewayInterfaceInfo selectGatewayInterfaceInfoById(Long id);
/**
* 查询接口管理列表
*
* @param gatewayInterfaceInfo 接口管理
* @return 接口管理集合
*/
public List<GatewayInterfaceInfo> selectGatewayInterfaceInfoList(GatewayInterfaceInfo gatewayInterfaceInfo);
/**
* 新增接口管理
*
* @param gatewayInterfaceInfo 接口管理
* @return 结果
*/
public int insertGatewayInterfaceInfo(GatewayInterfaceInfo gatewayInterfaceInfo);
/**
* 修改接口管理
*
* @param gatewayInterfaceInfo 接口管理
* @return 结果
*/
public int updateGatewayInterfaceInfo(GatewayInterfaceInfo gatewayInterfaceInfo);
/**
* 删除接口管理
*
* @param id 接口管理主键
* @return 结果
*/
public int deleteGatewayInterfaceInfoById(Long id);
/**
* 批量删除接口管理
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteGatewayInterfaceInfoByIds(Long[] ids);
int updateGatewayInterfaceInfoStatusByIds(@Param("ids") Collection<Long> ids, @Param("status") String status);
List<GatewayInterfaceInfo> selectGatewayInterfaceInfoByServerIds(@Param("serverIds") Collection<Long> serverIds);
}

View File

@ -0,0 +1,36 @@
package com.sf.service.gateway.mapper;
import com.sf.service.gateway.domain.GatewayInterfaceLinkStrategy;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
* @Entity com.sf.service.gateway.domain.GatewayInterfaceLinkStrategy
*/
public interface GatewayInterfaceLinkStrategyMapper {
int deleteByPrimaryKey(Long id);
int insert(GatewayInterfaceLinkStrategy record);
int insertSelective(GatewayInterfaceLinkStrategy record);
GatewayInterfaceLinkStrategy selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(GatewayInterfaceLinkStrategy record);
int updateByPrimaryKey(GatewayInterfaceLinkStrategy record);
void batchInsertGatewayInterfaceLinkStrategy(@Param("linkList") List<GatewayInterfaceLinkStrategy> linkList);
void deleteByInterfaceIds(@Param("interfaceIds") Collection<Long> interfaceIds);
List<GatewayInterfaceLinkStrategy> selectGatewayInterfaceLinkStrategyByInterfaceIds(@Param("interfaceIds") Collection<Long> interfaceIds);
}

View File

@ -0,0 +1,66 @@
package com.sf.service.gateway.mapper;
import com.sf.service.gateway.domain.GatewayRoute;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
/**
* 路由管理Mapper接口
*
* @author 邹坤
* @date 2024-04-22
*/
public interface GatewayRouteMapper
{
/**
* 查询路由管理
*
* @param id 路由管理主键
* @return 路由管理
*/
public GatewayRoute selectGatewayRouteById(Long id);
/**
* 查询路由管理列表
*
* @param gatewayRoute 路由管理
* @return 路由管理集合
*/
public List<GatewayRoute> selectGatewayRouteList(GatewayRoute gatewayRoute);
/**
* 新增路由管理
*
* @param gatewayRoute 路由管理
* @return 结果
*/
public int insertGatewayRoute(GatewayRoute gatewayRoute);
/**
* 修改路由管理
*
* @param gatewayRoute 路由管理
* @return 结果
*/
public int updateGatewayRoute(GatewayRoute gatewayRoute);
/**
* 删除路由管理
*
* @param id 路由管理主键
* @return 结果
*/
public int deleteGatewayRouteById(Long id);
/**
* 批量删除路由管理
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteGatewayRouteByIds(Long[] ids);
List<GatewayRoute> selectGatewayRouteByIds(@Param("ids") Collection<Long> ids);
}

View File

@ -0,0 +1,70 @@
package com.sf.service.gateway.mapper;
import com.sf.service.gateway.domain.GatewayServer;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
/**
* 服务管理Mapper接口
*
* @author zoukun
* @date 2024-04-22
*/
public interface GatewayServerMapper
{
/**
* 查询服务管理
*
* @param id 服务管理主键
* @return 服务管理
*/
public GatewayServer selectGatewayServerById(Long id);
/**
* 查询服务管理列表
*
* @param gatewayServer 服务管理
* @return 服务管理集合
*/
public List<GatewayServer> selectGatewayServerList(GatewayServer gatewayServer);
/**
* 新增服务管理
*
* @param gatewayServer 服务管理
* @return 结果
*/
public int insertGatewayServer(GatewayServer gatewayServer);
/**
* 修改服务管理
*
* @param gatewayServer 服务管理
* @return 结果
*/
public int updateGatewayServer(GatewayServer gatewayServer);
/**
* 删除服务管理
*
* @param id 服务管理主键
* @return 结果
*/
public int deleteGatewayServerById(Long id);
/**
* 批量删除服务管理
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteGatewayServerByIds(Long[] ids);
int updateGatewayServerStatusByIds(@Param("ids") Collection<Long> ids, @Param("status") String status);
List<GatewayServer> selectGatewayServerByIds(@Param("ids") Collection<Long> ids);
List<GatewayServer> selectGatewayServerByRouteIds(@Param("routeIds") Collection<Long> routeIds);
}

View File

@ -0,0 +1,68 @@
package com.sf.service.gateway.mapper;
import com.sf.service.gateway.domain.GatewayStrategy;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
/**
* 策略管理Mapper接口
*
* @author zoukun
* @date 2024-04-22
*/
public interface GatewayStrategyMapper
{
/**
* 查询策略管理
*
* @param id 策略管理主键
* @return 策略管理
*/
public GatewayStrategy selectGatewayStrategyById(Long id);
/**
* 查询策略管理列表
*
* @param gatewayStrategy 策略管理
* @return 策略管理集合
*/
public List<GatewayStrategy> selectGatewayStrategyList(GatewayStrategy gatewayStrategy);
/**
* 新增策略管理
*
* @param gatewayStrategy 策略管理
* @return 结果
*/
public int insertGatewayStrategy(GatewayStrategy gatewayStrategy);
/**
* 修改策略管理
*
* @param gatewayStrategy 策略管理
* @return 结果
*/
public int updateGatewayStrategy(GatewayStrategy gatewayStrategy);
/**
* 删除策略管理
*
* @param id 策略管理主键
* @return 结果
*/
public int deleteGatewayStrategyById(Long id);
/**
* 批量删除策略管理
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteGatewayStrategyByIds(Long[] ids);
int updateGatewayStrategyStatusByIds(@Param("ids") List<Long> ids, @Param("status") String status);
List<GatewayStrategy> selectGatewayStrategyByIds(@Param("ids") Collection<Long> ids);
}

View File

@ -0,0 +1,22 @@
package com.sf.service.gateway.service;
import com.sf.service.gateway.domain.GatewayConfig;
/**
* 功能描述:
*
* @author a_kun
* @date 2024/4/25 17:22
*/
public interface IGatewayConfigService {
/**
* 通过appCode查询网关配置
*
* @param appCode
* @return
*/
GatewayConfig selectGatewayConfigByAppCode(String appCode);
void updateGatewayConfig(GatewayConfig gatewayConfig);
}

View File

@ -0,0 +1,89 @@
package com.sf.service.gateway.service;
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
import com.sf.service.gateway.domain.GatewayInterfaceLinkStrategy;
import com.sf.service.gateway.domain.dto.InsertGatewayInterfaceInfoDTO;
import com.sf.service.gateway.domain.dto.UpdateGatewayInterfaceInfoDTO;
import com.sf.service.gateway.enums.GatewayDataStatus;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
* 接口管理Service接口
*
* @author zoukun
* @date 2024-04-22
*/
public interface IGatewayInterfaceInfoService
{
/**
* 查询接口管理
*
* @param id 接口管理主键
* @return 接口管理
*/
public GatewayInterfaceInfo selectGatewayInterfaceInfoById(Long id);
/**
* 查询接口管理列表
*
* @param gatewayInterfaceInfo 接口管理
* @return 接口管理集合
*/
public List<GatewayInterfaceInfo> selectGatewayInterfaceInfoList(GatewayInterfaceInfo gatewayInterfaceInfo);
/**
* 新增接口管理
*
* @param gatewayInterfaceInfo 接口管理
* @return 插入后的id
*/
public Long insertGatewayInterfaceInfo(GatewayInterfaceInfo gatewayInterfaceInfo);
/**
* 修改接口管理
*
* @param gatewayInterfaceInfo 接口管理
* @return 结果
*/
public int updateGatewayInterfaceInfo(GatewayInterfaceInfo gatewayInterfaceInfo);
/**
* 批量删除接口管理
*
* @param ids 需要删除的接口管理主键集合
* @return 结果
*/
public int deleteGatewayInterfaceInfoByIds(Long[] ids);
/**
* 删除接口管理信息
*
* @param id 接口管理主键
* @return 结果
*/
public int deleteGatewayInterfaceInfoById(Long id);
int updateGatewayInterfaceInfoStatusByIds(Collection<Long> ids, GatewayDataStatus status);
List<GatewayInterfaceInfo> selectGatewayInterfaceInfoByServerIds(Collection<Long> serverIds);
/**
* 添加接口信息及绑定的策略信息
*
* @param dto
* @return
*/
Long insertGatewayInterfaceInfoAndBindStrategy(InsertGatewayInterfaceInfoDTO dto);
/**
* 修改接口信息及绑定的策略信息
* @param dto
* @return
*/
Long updateGatewayInterfaceInfoAndBindStrategy(UpdateGatewayInterfaceInfoDTO dto);
List<GatewayInterfaceLinkStrategy> selectGatewayInterfaceLinkStrategyByInterfaceIds(Collection<Long> interfaceIds);
}

View File

@ -0,0 +1,66 @@
package com.sf.service.gateway.service;
import com.sf.service.gateway.domain.GatewayRoute;
import com.sf.service.gateway.domain.dto.InsertOrUpdateGatewayRouteDTO;
import java.util.Collection;
import java.util.List;
/**
* 路由管理Service接口
*
* @author 邹坤
* @date 2024-04-22
*/
public interface IGatewayRouteService
{
/**
* 查询路由管理
*
* @param id 路由管理主键
* @return 路由管理
*/
public GatewayRoute selectGatewayRouteById(Long id);
/**
* 查询路由管理列表
*
* @param gatewayRoute 路由管理
* @return 路由管理集合
*/
public List<GatewayRoute> selectGatewayRouteList(GatewayRoute gatewayRoute);
/**
* 新增路由管理
*
* @param gatewayRoute 路由管理
* @return 结果
*/
public int insertGatewayRoute(InsertOrUpdateGatewayRouteDTO gatewayRoute);
/**
* 修改路由管理
*
* @param gatewayRoute 路由管理
* @return 结果
*/
public int updateGatewayRoute(InsertOrUpdateGatewayRouteDTO gatewayRoute);
/**
* 批量删除路由管理
*
* @param ids 需要删除的路由管理主键集合
* @return 结果
*/
public int deleteGatewayRouteByIds(Long[] ids);
/**
* 删除路由管理信息
*
* @param id 路由管理主键
* @return 结果
*/
public int deleteGatewayRouteById(Long id);
List<GatewayRoute> selectGatewayRouteByIds(Collection<Long> ids);
}

View File

@ -0,0 +1,71 @@
package com.sf.service.gateway.service;
import com.sf.service.gateway.domain.GatewayServer;
import com.sf.service.gateway.enums.GatewayDataStatus;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
* 服务管理Service接口
*
* @author zoukun
* @date 2024-04-22
*/
public interface IGatewayServerService
{
/**
* 查询服务管理
*
* @param id 服务管理主键
* @return 服务管理
*/
public GatewayServer selectGatewayServerById(Long id);
/**
* 查询服务管理列表
*
* @param gatewayServer 服务管理
* @return 服务管理集合
*/
public List<GatewayServer> selectGatewayServerList(GatewayServer gatewayServer);
/**
* 新增服务管理
*
* @param gatewayServer 服务管理
* @return 结果
*/
public int insertGatewayServer(GatewayServer gatewayServer);
/**
* 修改服务管理
*
* @param gatewayServer 服务管理
* @return 结果
*/
public int updateGatewayServer(GatewayServer gatewayServer);
/**
* 批量删除服务管理
*
* @param ids 需要删除的服务管理主键集合
* @return 结果
*/
public int deleteGatewayServerByIds(Long[] ids);
/**
* 删除服务管理信息
*
* @param id 服务管理主键
* @return 结果
*/
public int deleteGatewayServerById(Long id);
int updateGatewayServerStatusByIds(Collection<Long> ids, GatewayDataStatus status);
List<GatewayServer> selectGatewayServerByIds(Collection<Long> ids);
List<GatewayServer> selectGatewayServerByRouteIds(Collection<Long> routeIds);
}

View File

@ -0,0 +1,68 @@
package com.sf.service.gateway.service;
import com.sf.service.gateway.domain.GatewayStrategy;
import com.sf.service.gateway.enums.GatewayDataStatus;
import java.util.Collection;
import java.util.List;
/**
* 策略管理Service接口
*
* @author zoukun
* @date 2024-04-22
*/
public interface IGatewayStrategyService
{
/**
* 查询策略管理
*
* @param id 策略管理主键
* @return 策略管理
*/
public GatewayStrategy selectGatewayStrategyById(Long id);
/**
* 查询策略管理列表
*
* @param gatewayStrategy 策略管理
* @return 策略管理集合
*/
public List<GatewayStrategy> selectGatewayStrategyList(GatewayStrategy gatewayStrategy);
/**
* 新增策略管理
*
* @param gatewayStrategy 策略管理
* @return 结果
*/
public int insertGatewayStrategy(GatewayStrategy gatewayStrategy);
/**
* 修改策略管理
*
* @param gatewayStrategy 策略管理
* @return 结果
*/
public int updateGatewayStrategy(GatewayStrategy gatewayStrategy);
/**
* 批量删除策略管理
*
* @param ids 需要删除的策略管理主键集合
* @return 结果
*/
public int deleteGatewayStrategyByIds(Long[] ids);
/**
* 删除策略管理信息
*
* @param id 策略管理主键
* @return 结果
*/
public int deleteGatewayStrategyById(Long id);
int updateGatewayStrategyStatusByIds(List<Long> ids, GatewayDataStatus status);
List<GatewayStrategy> selectGatewayStrategyByIds(Collection<Long> ids);
}

View File

@ -0,0 +1,55 @@
package com.sf.service.gateway.service.impl;
import com.sf.common.utils.DateUtils;
import com.sf.common.utils.SecurityUtils;
import com.sf.service.gateway.domain.GatewayConfig;
import com.sf.service.gateway.mapper.GatewayConfigMapper;
import com.sf.service.gateway.service.IGatewayConfigService;
import com.sf.service.index.util.AppUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.Date;
/**
* 功能描述:
*
* @author a_kun
* @date 2024/4/25 17:24
*/
@Service
public class GatewayConfigServiceImpl implements IGatewayConfigService {
@Autowired
private GatewayConfigMapper gatewayConfigMapper;
@Override
public GatewayConfig selectGatewayConfigByAppCode(String appCode) {
if (StringUtils.hasText(appCode)){
return gatewayConfigMapper.selectByAppCode(appCode);
}
return null;
}
@Override
public void updateGatewayConfig(GatewayConfig gatewayConfig) {
String appCode = AppUtils.getAppCodeFromRequestHeader();
String username = SecurityUtils.getUsername();
Date nowDate = DateUtils.getNowDate();
GatewayConfig inDbConfig = gatewayConfigMapper.selectByAppCode(appCode);
if (inDbConfig == null) {
gatewayConfig.setAppCode(appCode);
gatewayConfig.setCreated(username);
gatewayConfig.setModified(username);
gatewayConfig.setCreateTime(nowDate);
gatewayConfig.setUpdateTime(nowDate);
gatewayConfigMapper.insert(gatewayConfig);
}else {
gatewayConfig.setModified(username);
gatewayConfig.setCreateTime(nowDate);
gatewayConfig.setUpdateTime(nowDate);
gatewayConfigMapper.updateByAppCodeSelective(gatewayConfig);
}
}
}

View File

@ -0,0 +1,228 @@
package com.sf.service.gateway.service.impl;
import java.util.*;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollUtil;
import com.sf.common.utils.*;
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
import com.sf.service.gateway.domain.GatewayInterfaceLinkStrategy;
import com.sf.service.gateway.domain.GatewayStrategy;
import com.sf.service.gateway.domain.dto.InsertGatewayInterfaceInfoDTO;
import com.sf.service.gateway.domain.dto.UpdateGatewayInterfaceInfoDTO;
import com.sf.service.gateway.enums.GatewayDataStatus;
import com.sf.service.gateway.mapper.GatewayInterfaceInfoMapper;
import com.sf.service.gateway.mapper.GatewayInterfaceLinkStrategyMapper;
import com.sf.service.gateway.service.IGatewayInterfaceInfoService;
import com.sf.service.gateway.service.IGatewayStrategyService;
import com.sf.service.index.util.AppUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
* 接口管理Service业务层处理
*
* @author zoukun
* @date 2024-04-22
*/
@Slf4j
@Service
public class GatewayInterfaceInfoServiceImpl implements IGatewayInterfaceInfoService {
@Autowired
private GatewayInterfaceInfoMapper gatewayInterfaceInfoMapper;
@Autowired
private GatewayInterfaceLinkStrategyMapper gatewayInterfaceLinkStrategyMapper;
@Autowired
private IGatewayStrategyService gatewayStrategyService;
/**
* 查询接口管理
*
* @param id 接口管理主键
* @return 接口管理
*/
@Override
public GatewayInterfaceInfo selectGatewayInterfaceInfoById(Long id) {
return gatewayInterfaceInfoMapper.selectGatewayInterfaceInfoById(id);
}
/**
* 查询接口管理列表
*
* @param gatewayInterfaceInfo 接口管理
* @return 接口管理
*/
@Override
public List<GatewayInterfaceInfo> selectGatewayInterfaceInfoList(GatewayInterfaceInfo gatewayInterfaceInfo) {
return gatewayInterfaceInfoMapper.selectGatewayInterfaceInfoList(gatewayInterfaceInfo);
}
/**
* 新增接口管理
*
* @param gatewayInterfaceInfo 接口管理
* @return 结果
*/
@Override
public Long insertGatewayInterfaceInfo(GatewayInterfaceInfo gatewayInterfaceInfo) {
gatewayInterfaceInfo.setAppCode(AppUtils.getAppCodeFromRequestHeader());
String username = SecurityUtils.getUsername();
gatewayInterfaceInfo.setCreated(username);
gatewayInterfaceInfo.setModified(username);
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("接口名称不可重复!");
}
}
/**
* 修改接口管理
*
* @param gatewayInterfaceInfo 接口管理
* @return 结果
*/
@Override
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("接口名称不可重复!");
}
}
/**
* 批量删除接口管理
*
* @param ids 需要删除的接口管理主键
* @return 结果
*/
@Transactional(rollbackFor = Exception.class)
@Override
public int deleteGatewayInterfaceInfoByIds(Long[] ids) {
if (ids == null || ids.length == 0) {
return 0;
}
gatewayInterfaceLinkStrategyMapper.deleteByInterfaceIds(CollUtil.newHashSet(ids));
return gatewayInterfaceInfoMapper.deleteGatewayInterfaceInfoByIds(ids);
}
/**
* 删除接口管理信息
*
* @param id 接口管理主键
* @return 结果
*/
@Transactional(rollbackFor = Exception.class)
@Override
public int deleteGatewayInterfaceInfoById(Long id) {
if (id == null) {
return 0;
}
gatewayInterfaceLinkStrategyMapper.deleteByInterfaceIds(Collections.singleton(id));
return gatewayInterfaceInfoMapper.deleteGatewayInterfaceInfoById(id);
}
@Override
public int updateGatewayInterfaceInfoStatusByIds(Collection<Long> ids, GatewayDataStatus status) {
if (CollectionUtils.isEmpty(ids) || status == null){
log.warn("Insufficient update conditions");
return 0;
}
return gatewayInterfaceInfoMapper.updateGatewayInterfaceInfoStatusByIds(ids,status.getCode());
}
@Override
public List<GatewayInterfaceInfo> selectGatewayInterfaceInfoByServerIds(Collection<Long> serverIds) {
if (CollectionUtils.isEmpty(serverIds)){
return Collections.emptyList();
}
return gatewayInterfaceInfoMapper.selectGatewayInterfaceInfoByServerIds(serverIds);
}
@Transactional(rollbackFor = Exception.class)
@Override
public Long insertGatewayInterfaceInfoAndBindStrategy(InsertGatewayInterfaceInfoDTO dto) {
GatewayInterfaceInfo gatewayInterfaceInfo = new GatewayInterfaceInfo();
gatewayInterfaceInfo.setInterfaceName(dto.getInterfaceName());
gatewayInterfaceInfo.setInterfacePath(dto.getInterfacePath());
gatewayInterfaceInfo.setRequestMethod(dto.getRequestMethod());
gatewayInterfaceInfo.setDescription(dto.getDescription());
gatewayInterfaceInfo.setVersion(dto.getVersion());
gatewayInterfaceInfo.setStatus(dto.getStatus());
gatewayInterfaceInfo.setDocument(dto.getDocument());
gatewayInterfaceInfo.setServerId(dto.getServerId());
Long interfaceInfoId = insertGatewayInterfaceInfo(gatewayInterfaceInfo);
if (CollUtil.isNotEmpty(dto.getStrategyIds())){
checkGatewayStrategyTypeCannotBeRepeated(dto.getStrategyIds());
List<GatewayInterfaceLinkStrategy> linkStrategyList = dto.getStrategyIds()
.stream().map(strategyId -> new GatewayInterfaceLinkStrategy(interfaceInfoId, strategyId))
.collect(Collectors.toList());
gatewayInterfaceLinkStrategyMapper.batchInsertGatewayInterfaceLinkStrategy(linkStrategyList);
}
return interfaceInfoId;
}
@Transactional(rollbackFor = Exception.class)
@Override
public Long updateGatewayInterfaceInfoAndBindStrategy(UpdateGatewayInterfaceInfoDTO dto) {
GatewayInterfaceInfo gatewayInterfaceInfo = new GatewayInterfaceInfo();
gatewayInterfaceInfo.setId(dto.getId());
gatewayInterfaceInfo.setInterfaceName(dto.getInterfaceName());
gatewayInterfaceInfo.setInterfacePath(dto.getInterfacePath());
gatewayInterfaceInfo.setRequestMethod(dto.getRequestMethod());
gatewayInterfaceInfo.setDescription(dto.getDescription());
gatewayInterfaceInfo.setVersion(dto.getVersion());
gatewayInterfaceInfo.setStatus(dto.getStatus());
gatewayInterfaceInfo.setDocument(dto.getDocument());
gatewayInterfaceInfo.setServerId(dto.getServerId());
updateGatewayInterfaceInfo(gatewayInterfaceInfo);
// 先删除
gatewayInterfaceLinkStrategyMapper.deleteByInterfaceIds(Collections.singleton(dto.getId()));
if (CollUtil.isNotEmpty(dto.getStrategyIds())){
checkGatewayStrategyTypeCannotBeRepeated(dto.getStrategyIds());
List<GatewayInterfaceLinkStrategy> linkStrategyList = dto.getStrategyIds()
.stream().map(strategyId -> new GatewayInterfaceLinkStrategy(dto.getId(), strategyId))
.collect(Collectors.toList());
gatewayInterfaceLinkStrategyMapper.batchInsertGatewayInterfaceLinkStrategy(linkStrategyList);
}
return gatewayInterfaceInfo.getId();
}
@Override
public List<GatewayInterfaceLinkStrategy> selectGatewayInterfaceLinkStrategyByInterfaceIds(Collection<Long> interfaceIds) {
if (CollectionUtils.isEmpty(interfaceIds)){
return Collections.emptyList();
}
return gatewayInterfaceLinkStrategyMapper.selectGatewayInterfaceLinkStrategyByInterfaceIds(interfaceIds);
}
private void checkGatewayStrategyTypeCannotBeRepeated(List<Long> strategyIds) {
List<GatewayStrategy> strategyList = gatewayStrategyService.selectGatewayStrategyByIds(strategyIds);
Map<String, List<GatewayStrategy>> groupByStrategyTypeMap = strategyList.stream().collect(Collectors.groupingBy(GatewayStrategy::getStrategyType));
groupByStrategyTypeMap.forEach((type,strategies) ->{
Assert.isTrue(strategies.size() == 1,type + "类型只能选择一个!");
});
}
}

View File

@ -0,0 +1,203 @@
package com.sf.service.gateway.service.impl;
import java.util.*;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONException;
import com.sf.common.utils.DateUtils;
import com.sf.common.utils.SecurityUtils;
import com.sf.common.utils.URLUtils;
import com.sf.service.gateway.domain.GatewayRoute;
import com.sf.service.gateway.domain.GatewayServer;
import com.sf.service.gateway.domain.dto.InsertOrUpdateGatewayRouteDTO;
import com.sf.service.gateway.enums.*;
import com.sf.service.gateway.mapper.GatewayRouteMapper;
import com.sf.service.gateway.service.IGatewayRouteService;
import com.sf.service.gateway.service.IGatewayServerService;
import com.sf.service.index.util.AppUtils;
import org.hibernate.validator.constraints.URL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.validation.constraints.NotBlank;
/**
* 路由管理Service业务层处理
*
* @author 邹坤
* @date 2024-04-22
*/
@Service
public class GatewayRouteServiceImpl implements IGatewayRouteService
{
@Autowired
private GatewayRouteMapper gatewayRouteMapper;
@Autowired
private IGatewayServerService gatewayServerService;
/**
* 查询路由管理
*
* @param id 路由管理主键
* @return 路由管理
*/
@Override
public GatewayRoute selectGatewayRouteById(Long id)
{
return gatewayRouteMapper.selectGatewayRouteById(id);
}
/**
* 查询路由管理列表
*
* @param gatewayRoute 路由管理
* @return 路由管理
*/
@Override
public List<GatewayRoute> selectGatewayRouteList(GatewayRoute gatewayRoute)
{
return gatewayRouteMapper.selectGatewayRouteList(gatewayRoute);
}
/**
* 新增路由管理
*
* @param dto 路由管理
* @return 结果
*/
@Override
public int insertGatewayRoute(InsertOrUpdateGatewayRouteDTO dto)
{
checkRouteConfig(dto);
GatewayRoute gatewayRoute = new GatewayRoute();
gatewayRoute.setRouteName(dto.getRouteName());
gatewayRoute.setRequestProtocol(dto.getRequestProtocol().getCode());
gatewayRoute.setRouteType(dto.getRouteType().getCode());
gatewayRoute.setRouteContent(JSON.toJSONString(dto.getRouteContent()));
gatewayRoute.setRouteStatusActiveMonitoring(dto.getRouteStatusActiveMonitoring());
gatewayRoute.setRouteActiveMonitoringPath(dto.getRouteActiveMonitoringPath());
gatewayRoute.setRouteActiveMonitoringTimeout(dto.getRouteActiveMonitoringTimeout());
gatewayRoute.setAppCode(AppUtils.getAppCodeFromRequestHeader());
String username = SecurityUtils.getUsername();
gatewayRoute.setCreated(username);
gatewayRoute.setModified(username);
Date nowDate = DateUtils.getNowDate();
gatewayRoute.setCreateTime(nowDate);
gatewayRoute.setUpdateTime(nowDate);
gatewayRoute.setRouteActiveStatus(GatewayDataStatus.ENABLE.getCode().equals(dto.getRouteStatusActiveMonitoring())?
RouteActiveStatus.OBTAINING.getCode()
:RouteActiveStatus.NOT_ENABLED.getCode());
try {
return gatewayRouteMapper.insertGatewayRoute(gatewayRoute);
}catch (DuplicateKeyException e){
throw new IllegalArgumentException("路由名称不可重复!");
}
}
private void checkRouteConfig(InsertOrUpdateGatewayRouteDTO dto) {
RequestProtocol requestProtocol = dto.getRequestProtocol();
GatewayRouteType routeType = dto.getRouteType();
Assert.notNull(requestProtocol,"不支持的协议类型!");
Assert.notNull(routeType,"不支持的路由类型!");
List<GatewayRoute.RouteContent> contentList = dto.getRouteContent();
int sumWeight = 0;
for (GatewayRoute.RouteContent content : contentList) {
Assert.isTrue(URLUtils.isURL(content.getServerAddress()),"请输入正确的服务地址");
switch (routeType){
case WEIGHT_ROUTE:
if (content.getWeight() == null){
content.setWeight(0);
}
sumWeight += content.getWeight();
break;
case HEADER_ROUTE:
Assert.notBlank(content.getHeaderKey(),"请求头键值不能为空");
MatchType matchType = MatchType.getByCode(content.getMatchType());
Assert.notNull(matchType,"匹配方式不能为空");
break;
default:
break;
}
}
if (GatewayRouteType.WEIGHT_ROUTE.equals(routeType)){
Assert.isTrue(sumWeight == 100,"权重总值为100");
}
}
/**
* 修改路由管理
*
* @param dto 路由管理
* @return 结果
*/
@Override
public int updateGatewayRoute(InsertOrUpdateGatewayRouteDTO dto)
{
checkRouteConfig(dto);
GatewayRoute gatewayRoute = new GatewayRoute();
gatewayRoute.setId(dto.getId());
gatewayRoute.setRouteName(dto.getRouteName());
gatewayRoute.setRequestProtocol(dto.getRequestProtocol().getCode());
gatewayRoute.setRouteType(dto.getRouteType().getCode());
gatewayRoute.setRouteContent(JSON.toJSONString(dto.getRouteContent()));
gatewayRoute.setRouteStatusActiveMonitoring(dto.getRouteStatusActiveMonitoring());
gatewayRoute.setRouteActiveMonitoringPath(dto.getRouteActiveMonitoringPath());
gatewayRoute.setRouteActiveMonitoringTimeout(dto.getRouteActiveMonitoringTimeout());
gatewayRoute.setModified(SecurityUtils.getUsername());
gatewayRoute.setUpdateTime(DateUtils.getNowDate());
if (GatewayDataStatus.DISABLE.getCode().equals(dto.getRouteStatusActiveMonitoring())){
gatewayRoute.setRouteActiveStatus(RouteActiveStatus.NOT_ENABLED.getCode());
}
try {
return gatewayRouteMapper.updateGatewayRoute(gatewayRoute);
}catch (DuplicateKeyException e){
throw new IllegalArgumentException("路由名称不可重复!");
}
}
/**
* 批量删除路由管理
*
* @param ids 需要删除的路由管理主键
* @return 结果
*/
@Override
public int deleteGatewayRouteByIds(Long[] ids)
{
checkDeleteConditions(CollUtil.newHashSet(ids));
return gatewayRouteMapper.deleteGatewayRouteByIds(ids);
}
/**
* 删除路由管理信息
*
* @param id 路由管理主键
* @return 结果
*/
@Override
public int deleteGatewayRouteById(Long id)
{
checkDeleteConditions(Collections.singleton(id));
return gatewayRouteMapper.deleteGatewayRouteById(id);
}
private void checkDeleteConditions(Collection<Long> ids) {
List<GatewayServer> serverList = gatewayServerService.selectGatewayServerByRouteIds(ids);
Assert.isTrue(CollUtil.isEmpty(serverList),"存在关联服务,删除失败!");
}
@Override
public List<GatewayRoute> selectGatewayRouteByIds(Collection<Long> ids) {
if (CollectionUtils.isEmpty(ids)){
return Collections.emptyList();
}
return gatewayRouteMapper.selectGatewayRouteByIds(ids);
}
}

View File

@ -0,0 +1,174 @@
package com.sf.service.gateway.service.impl;
import java.util.*;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import com.sf.common.utils.DateUtils;
import com.sf.common.utils.URLUtils;
import com.sf.service.gateway.domain.GatewayInterfaceInfo;
import com.sf.service.gateway.domain.GatewayServer;
import com.sf.service.gateway.enums.GatewayDataStatus;
import com.sf.service.gateway.enums.GatewayServiceModel;
import com.sf.service.gateway.mapper.GatewayServerMapper;
import com.sf.service.gateway.service.IGatewayInterfaceInfoService;
import com.sf.service.gateway.service.IGatewayServerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
/**
* 服务管理Service业务层处理
*
* @author zoukun
* @date 2024-04-22
*/
@Slf4j
@Service
public class GatewayServerServiceImpl implements IGatewayServerService
{
@Autowired
private GatewayServerMapper gatewayServerMapper;
@Autowired
private IGatewayInterfaceInfoService gatewayInterfaceInfoService;
/**
* 查询服务管理
*
* @param id 服务管理主键
* @return 服务管理
*/
@Override
public GatewayServer selectGatewayServerById(Long id)
{
if (id == null) {
return null;
}
return gatewayServerMapper.selectGatewayServerById(id);
}
/**
* 查询服务管理列表
*
* @param gatewayServer 服务管理
* @return 服务管理
*/
@Override
public List<GatewayServer> selectGatewayServerList(GatewayServer gatewayServer)
{
return gatewayServerMapper.selectGatewayServerList(gatewayServer);
}
/**
* 新增服务管理
*
* @param gatewayServer 服务管理
* @return 结果
*/
@Override
public int insertGatewayServer(GatewayServer gatewayServer)
{
checkServerModelConfig(gatewayServer);
Date nowDate = DateUtils.getNowDate();
gatewayServer.setCreateTime(nowDate);
gatewayServer.setUpdateTime(nowDate);
try {
return gatewayServerMapper.insertGatewayServer(gatewayServer);
}catch (DuplicateKeyException e){
throw new IllegalArgumentException("服务名称不可重复!");
}
}
private void checkServerModelConfig(GatewayServer gatewayServer) {
GatewayServiceModel serviceModel = GatewayServiceModel.getByCode(gatewayServer.getServiceModel());
Assert.notNull(serviceModel,"不支持的服务模式!");
switch (serviceModel){
case NORMAL:
Assert.notBlank(gatewayServer.getServerAddress(),"服务地址不能为空");
Assert.isTrue(URLUtils.isURL(gatewayServer.getServerAddress()),"请输入正确的URL服务地址如:http://sac.zsmarter.com");
break;
case ROUTE:
Assert.notNull(gatewayServer.getRouteId(),"请选择路由规则");
break;
default:
break;
}
}
/**
* 修改服务管理
*
* @param gatewayServer 服务管理
* @return 结果
*/
@Override
public int updateGatewayServer(GatewayServer gatewayServer)
{
checkServerModelConfig(gatewayServer);
gatewayServer.setUpdateTime(DateUtils.getNowDate());
try {
return gatewayServerMapper.updateGatewayServer(gatewayServer);
}catch (DuplicateKeyException e){
throw new IllegalArgumentException("服务名称不可重复!");
}
}
/**
* 批量删除服务管理
*
* @param ids 需要删除的服务管理主键
* @return 结果
*/
@Override
public int deleteGatewayServerByIds(Long[] ids)
{
if (ids == null || ids.length == 0) {
return 0;
}
List<GatewayInterfaceInfo> gatewayInterfaceInfoList = gatewayInterfaceInfoService.selectGatewayInterfaceInfoByServerIds(CollUtil.newHashSet(ids));
Assert.isTrue(CollUtil.isEmpty(gatewayInterfaceInfoList),"服务存在关联的接口,删除失败!");
return gatewayServerMapper.deleteGatewayServerByIds(ids);
}
/**
* 删除服务管理信息
*
* @param id 服务管理主键
* @return 结果
*/
@Override
public int deleteGatewayServerById(Long id)
{
List<GatewayInterfaceInfo> gatewayInterfaceInfoList = gatewayInterfaceInfoService.selectGatewayInterfaceInfoByServerIds(CollUtil.newHashSet(id));
Assert.isTrue(CollUtil.isEmpty(gatewayInterfaceInfoList),"服务存在关联的接口,删除失败!");
return gatewayServerMapper.deleteGatewayServerById(id);
}
@Override
public int updateGatewayServerStatusByIds(Collection<Long> ids, GatewayDataStatus status) {
if (CollectionUtils.isEmpty(ids) || status == null){
log.warn("Insufficient update conditions");
return 0;
}
return gatewayServerMapper.updateGatewayServerStatusByIds(ids,status.getCode());
}
@Override
public List<GatewayServer> selectGatewayServerByIds(Collection<Long> ids) {
if (CollectionUtils.isEmpty(ids)){
return Collections.emptyList();
}
return gatewayServerMapper.selectGatewayServerByIds(ids);
}
@Override
public List<GatewayServer> selectGatewayServerByRouteIds(Collection<Long> routeIds) {
if (CollectionUtils.isEmpty(routeIds)){
return Collections.emptyList();
}
return gatewayServerMapper.selectGatewayServerByRouteIds(routeIds);
}
}

View File

@ -0,0 +1,219 @@
package com.sf.service.gateway.service.impl;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import com.sf.common.utils.DateUtils;
import com.sf.service.gateway.domain.GatewayStrategy;
import com.sf.service.gateway.enums.GatewayDataStatus;
import com.sf.service.gateway.enums.GatewayStrategyType;
import com.sf.service.gateway.mapper.GatewayStrategyMapper;
import com.sf.service.gateway.service.IGatewayStrategyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
/**
* 策略管理Service业务层处理
*
* @author zoukun
* @date 2024-04-22
*/
@Slf4j
@Service
public class GatewayStrategyServiceImpl implements IGatewayStrategyService
{
@Autowired
private GatewayStrategyMapper gatewayStrategyMapper;
/**
* 查询策略管理
*
* @param id 策略管理主键
* @return 策略管理
*/
@Override
public GatewayStrategy selectGatewayStrategyById(Long id)
{
return gatewayStrategyMapper.selectGatewayStrategyById(id);
}
/**
* 查询策略管理列表
*
* @param gatewayStrategy 策略管理
* @return 策略管理
*/
@Override
public List<GatewayStrategy> selectGatewayStrategyList(GatewayStrategy gatewayStrategy)
{
return gatewayStrategyMapper.selectGatewayStrategyList(gatewayStrategy);
}
/**
* 新增策略管理
*
* @param gatewayStrategy 策略管理
* @return 结果
*/
@Override
public int insertGatewayStrategy(GatewayStrategy gatewayStrategy)
{
Date nowDate = DateUtils.getNowDate();
gatewayStrategy.setCreateTime(nowDate);
gatewayStrategy.setUpdateTime(nowDate);
GatewayStrategyType strategyType = GatewayStrategyType.getByCode(gatewayStrategy.getStrategyType());
Assert.notNull(strategyType,"不支持的策略类型!");
switch (strategyType){
case AUTHENTICATION:
checkAuthenticationConfig(gatewayStrategy);
break;
case PERMISSION:
checkPermissionConfig(gatewayStrategy);
break;
case CURRENT_LIMITING:
checkAndInitCurrentLimitingConfig(gatewayStrategy);
break;
case CIRCUIT_BREAKER:
checkAndInitCircuitBreakerConfig(gatewayStrategy);
break;
default:
break;
}
try {
return gatewayStrategyMapper.insertGatewayStrategy(gatewayStrategy);
}catch (DuplicateKeyException e){
throw new IllegalArgumentException("策略名称不可重复!");
}
}
/**
* 认证策略配置检查
*
* @param gatewayStrategy
*/
private void checkAuthenticationConfig(GatewayStrategy gatewayStrategy) {
}
/**
* 鉴权策略配置检查
*
* @param gatewayStrategy
*/
private void checkPermissionConfig(GatewayStrategy gatewayStrategy) {
}
/**
* 限流策略配置检查
*
* @param gatewayStrategy
*/
private void checkAndInitCurrentLimitingConfig(GatewayStrategy gatewayStrategy) {
Integer currentLimitingThreshold = gatewayStrategy.getCurrentLimitingThreshold();
Integer currentLimitingTimeWindow = gatewayStrategy.getCurrentLimitingTimeWindow();
String currentLimitingResponse = gatewayStrategy.getCurrentLimitingResponse();
if (currentLimitingThreshold == null){
gatewayStrategy.setCurrentLimitingThreshold(1);
}
if (currentLimitingTimeWindow == null){
gatewayStrategy.setCurrentLimitingTimeWindow(1);
}
if (!StringUtils.hasText(currentLimitingResponse)){
gatewayStrategy.setCurrentLimitingResponse("{}");
}
}
/**
* 熔断策略配置检查
*
* @param gatewayStrategy
*/
private void checkAndInitCircuitBreakerConfig(GatewayStrategy gatewayStrategy) {
Integer circuitBreakerThreshold = gatewayStrategy.getCircuitBreakerThreshold();
Integer circuitBreakerTimeWindow = gatewayStrategy.getCircuitBreakerTimeWindow();
Integer circuitBreakerRecoveryInterval = gatewayStrategy.getCircuitBreakerRecoveryInterval();
String circuitBreakerResponse = gatewayStrategy.getCircuitBreakerResponse();
if (circuitBreakerThreshold == null){
gatewayStrategy.setCircuitBreakerThreshold(1);
}
if (circuitBreakerTimeWindow == null){
gatewayStrategy.setCircuitBreakerTimeWindow(1);
}
if (circuitBreakerRecoveryInterval == null){
gatewayStrategy.setCircuitBreakerRecoveryInterval(1);
}
if (!StringUtils.hasText(circuitBreakerResponse)){
gatewayStrategy.setCircuitBreakerResponse("{}");
}
}
/**
* 修改策略管理
*
* @param gatewayStrategy 策略管理
* @return 结果
*/
@Override
public int updateGatewayStrategy(GatewayStrategy gatewayStrategy)
{
gatewayStrategy.setUpdateTime(DateUtils.getNowDate());
try {
return gatewayStrategyMapper.updateGatewayStrategy(gatewayStrategy);
}catch (DuplicateKeyException e){
throw new IllegalArgumentException("策略名称不可重复!");
}
}
/**
* 批量删除策略管理
*
* @param ids 需要删除的策略管理主键
* @return 结果
*/
@Override
public int deleteGatewayStrategyByIds(Long[] ids)
{
if (ids == null || ids.length == 0) {
return 0;
}
return gatewayStrategyMapper.deleteGatewayStrategyByIds(ids);
}
/**
* 删除策略管理信息
*
* @param id 策略管理主键
* @return 结果
*/
@Override
public int deleteGatewayStrategyById(Long id)
{
if (id == null) {
return 0;
}
return gatewayStrategyMapper.deleteGatewayStrategyById(id);
}
@Override
public int updateGatewayStrategyStatusByIds(List<Long> ids, GatewayDataStatus status) {
if (CollectionUtils.isEmpty(ids) || status == null){
log.warn("Insufficient update conditions");
return 0;
}
return gatewayStrategyMapper.updateGatewayStrategyStatusByIds(ids,status.getCode());
}
@Override
public List<GatewayStrategy> selectGatewayStrategyByIds(Collection<Long> ids) {
if (CollectionUtils.isEmpty(ids)){
return Collections.emptyList();
}
return gatewayStrategyMapper.selectGatewayStrategyByIds(ids);
}
}

View File

@ -0,0 +1,178 @@
<?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.GatewayConfigMapper">
<resultMap id="BaseResultMap" type="com.sf.service.gateway.domain.GatewayConfig">
<id property="appCode" column="app_code" jdbcType="VARCHAR"/>
<result property="dataEncryptionStatus" column="data_encryption_status" jdbcType="CHAR"/>
<result property="encryptionAlgorithm" column="encryption_algorithm" jdbcType="VARCHAR"/>
<result property="privateKey" column="private_key" jdbcType="VARCHAR"/>
<result property="publicKey" column="public_key" jdbcType="VARCHAR"/>
<result property="apiCurrentLimitingStatus" column="api_current_limiting_status" jdbcType="CHAR"/>
<result property="apiCurrentLimitingThreshold" column="api_current_limiting_threshold" jdbcType="INTEGER"/>
<result property="apiCurrentLimitingTimeWindow" column="api_current_limiting_time_window" jdbcType="INTEGER"/>
<result property="apiCurrentLimitingDefaultResponse" column="api_current_limiting_default_response" jdbcType="VARCHAR"/>
<result property="appCurrentLimitingStatus" column="app_current_limiting_status" jdbcType="CHAR"/>
<result property="appCurrentLimitingThreshold" column="app_current_limiting_threshold" jdbcType="INTEGER"/>
<result property="appCurrentLimitingTimeWindow" column="app_current_limiting_time_window" jdbcType="INTEGER"/>
<result property="appCurrentLimitingDefaultResponse" column="app_current_limiting_default_response" jdbcType="VARCHAR"/>
<result property="created" column="created" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="modified" column="modified" jdbcType="VARCHAR"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
app_code,data_encryption_status,encryption_algorithm,
private_key,public_key,api_current_limiting_status,
api_current_limiting_threshold,api_current_limiting_time_window,api_current_limiting_default_response,
app_current_limiting_status,app_current_limiting_threshold,app_current_limiting_time_window,
app_current_limiting_default_response,created,create_time,
modified,update_time
</sql>
<select id="selectByAppCode" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from Gateway_config
where app_code = #{appCode,jdbcType=VARCHAR}
</select>
<delete id="deleteByAppCode" parameterType="java.lang.String">
delete from Gateway_config
where app_code = #{appCode,jdbcType=VARCHAR}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.sf.service.gateway.domain.GatewayConfig" useGeneratedKeys="true">
insert into Gateway_config
( app_code,data_encryption_status,encryption_algorithm
,private_key,public_key,api_current_limiting_status
,api_current_limiting_threshold,api_current_limiting_time_window,api_current_limiting_default_response
,app_current_limiting_status,app_current_limiting_threshold,app_current_limiting_time_window
,app_current_limiting_default_response,created,create_time
,modified,update_time)
values (#{appCode,jdbcType=VARCHAR},#{dataEncryptionStatus,jdbcType=CHAR},#{encryptionAlgorithm,jdbcType=VARCHAR}
,#{privateKey,jdbcType=VARCHAR},#{publicKey,jdbcType=VARCHAR},#{apiCurrentLimitingStatus,jdbcType=CHAR}
,#{apiCurrentLimitingThreshold,jdbcType=INTEGER},#{apiCurrentLimitingTimeWindow,jdbcType=INTEGER},#{apiCurrentLimitingDefaultResponse,jdbcType=VARCHAR}
,#{appCurrentLimitingStatus,jdbcType=CHAR},#{appCurrentLimitingThreshold,jdbcType=INTEGER},#{appCurrentLimitingTimeWindow,jdbcType=INTEGER}
,#{appCurrentLimitingDefaultResponse,jdbcType=VARCHAR},#{created,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP}
,#{modified,jdbcType=VARCHAR},#{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.sf.service.gateway.domain.GatewayConfig" useGeneratedKeys="true">
insert into Gateway_config
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="appCode != null">appCode,</if>
<if test="dataEncryptionStatus != null">dataEncryptionStatus,</if>
<if test="encryptionAlgorithm != null">encryptionAlgorithm,</if>
<if test="privateKey != null">privateKey,</if>
<if test="publicKey != null">publicKey,</if>
<if test="apiCurrentLimitingStatus != null">apiCurrentLimitingStatus,</if>
<if test="apiCurrentLimitingThreshold != null">apiCurrentLimitingThreshold,</if>
<if test="apiCurrentLimitingTimeWindow != null">apiCurrentLimitingTimeWindow,</if>
<if test="apiCurrentLimitingDefaultResponse != null">apiCurrentLimitingDefaultResponse,</if>
<if test="appCurrentLimitingStatus != null">appCurrentLimitingStatus,</if>
<if test="appCurrentLimitingThreshold != null">appCurrentLimitingThreshold,</if>
<if test="appCurrentLimitingTimeWindow != null">appCurrentLimitingTimeWindow,</if>
<if test="appCurrentLimitingDefaultResponse != null">appCurrentLimitingDefaultResponse,</if>
<if test="created != null">created,</if>
<if test="createTime != null">createTime,</if>
<if test="modified != null">modified,</if>
<if test="updateTime != null">updateTime,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="appCode != null">app_code = #{appCode,jdbcType=VARCHAR},</if>
<if test="dataEncryptionStatus != null">data_encryption_status = #{dataEncryptionStatus,jdbcType=CHAR},</if>
<if test="encryptionAlgorithm != null">encryption_algorithm = #{encryptionAlgorithm,jdbcType=VARCHAR},</if>
<if test="privateKey != null">private_key = #{privateKey,jdbcType=VARCHAR},</if>
<if test="publicKey != null">public_key = #{publicKey,jdbcType=VARCHAR},</if>
<if test="apiCurrentLimitingStatus != null">api_current_limiting_status = #{apiCurrentLimitingStatus,jdbcType=CHAR},</if>
<if test="apiCurrentLimitingThreshold != null">api_current_limiting_threshold = #{apiCurrentLimitingThreshold,jdbcType=INTEGER},</if>
<if test="apiCurrentLimitingTimeWindow != null">api_current_limiting_time_window = #{apiCurrentLimitingTimeWindow,jdbcType=INTEGER},</if>
<if test="apiCurrentLimitingDefaultResponse != null">api_current_limiting_default_response = #{apiCurrentLimitingDefaultResponse,jdbcType=VARCHAR},</if>
<if test="appCurrentLimitingStatus != null">app_current_limiting_status = #{appCurrentLimitingStatus,jdbcType=CHAR},</if>
<if test="appCurrentLimitingThreshold != null">app_current_limiting_threshold = #{appCurrentLimitingThreshold,jdbcType=INTEGER},</if>
<if test="appCurrentLimitingTimeWindow != null">app_current_limiting_time_window = #{appCurrentLimitingTimeWindow,jdbcType=INTEGER},</if>
<if test="appCurrentLimitingDefaultResponse != null">app_current_limiting_default_response = #{appCurrentLimitingDefaultResponse,jdbcType=VARCHAR},</if>
<if test="created != null">created = #{created,jdbcType=VARCHAR},</if>
<if test="createTime != null">create_time = #{createTime,jdbcType=TIMESTAMP},</if>
<if test="modified != null">modified = #{modified,jdbcType=VARCHAR},</if>
<if test="updateTime != null">update_time = #{updateTime,jdbcType=TIMESTAMP},</if>
</trim>
</insert>
<update id="updateByAppCodeSelective" parameterType="com.sf.service.gateway.domain.GatewayConfig">
update Gateway_config
<set>
<if test="dataEncryptionStatus != null">
data_encryption_status = #{dataEncryptionStatus,jdbcType=CHAR},
</if>
<if test="encryptionAlgorithm != null">
encryption_algorithm = #{encryptionAlgorithm,jdbcType=VARCHAR},
</if>
<if test="privateKey != null">
private_key = #{privateKey,jdbcType=VARCHAR},
</if>
<if test="publicKey != null">
public_key = #{publicKey,jdbcType=VARCHAR},
</if>
<if test="apiCurrentLimitingStatus != null">
api_current_limiting_status = #{apiCurrentLimitingStatus,jdbcType=CHAR},
</if>
<if test="apiCurrentLimitingThreshold != null">
api_current_limiting_threshold = #{apiCurrentLimitingThreshold,jdbcType=INTEGER},
</if>
<if test="apiCurrentLimitingTimeWindow != null">
api_current_limiting_time_window = #{apiCurrentLimitingTimeWindow,jdbcType=INTEGER},
</if>
<if test="apiCurrentLimitingDefaultResponse != null">
api_current_limiting_default_response = #{apiCurrentLimitingDefaultResponse,jdbcType=VARCHAR},
</if>
<if test="appCurrentLimitingStatus != null">
app_current_limiting_status = #{appCurrentLimitingStatus,jdbcType=CHAR},
</if>
<if test="appCurrentLimitingThreshold != null">
app_current_limiting_threshold = #{appCurrentLimitingThreshold,jdbcType=INTEGER},
</if>
<if test="appCurrentLimitingTimeWindow != null">
app_current_limiting_time_window = #{appCurrentLimitingTimeWindow,jdbcType=INTEGER},
</if>
<if test="appCurrentLimitingDefaultResponse != null">
app_current_limiting_default_response = #{appCurrentLimitingDefaultResponse,jdbcType=VARCHAR},
</if>
<if test="created != null">
created = #{created,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="modified != null">
modified = #{modified,jdbcType=VARCHAR},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where app_code = #{appCode,jdbcType=VARCHAR}
</update>
<update id="updateByAppCode" parameterType="com.sf.service.gateway.domain.GatewayConfig">
update Gateway_config
set
data_encryption_status = #{dataEncryptionStatus,jdbcType=CHAR},
encryption_algorithm = #{encryptionAlgorithm,jdbcType=VARCHAR},
private_key = #{privateKey,jdbcType=VARCHAR},
public_key = #{publicKey,jdbcType=VARCHAR},
api_current_limiting_status = #{apiCurrentLimitingStatus,jdbcType=CHAR},
api_current_limiting_threshold = #{apiCurrentLimitingThreshold,jdbcType=INTEGER},
api_current_limiting_time_window = #{apiCurrentLimitingTimeWindow,jdbcType=INTEGER},
api_current_limiting_default_response = #{apiCurrentLimitingDefaultResponse,jdbcType=VARCHAR},
app_current_limiting_status = #{appCurrentLimitingStatus,jdbcType=CHAR},
app_current_limiting_threshold = #{appCurrentLimitingThreshold,jdbcType=INTEGER},
app_current_limiting_time_window = #{appCurrentLimitingTimeWindow,jdbcType=INTEGER},
app_current_limiting_default_response = #{appCurrentLimitingDefaultResponse,jdbcType=VARCHAR},
created = #{created,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
modified = #{modified,jdbcType=VARCHAR},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where app_code = #{appCode,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -0,0 +1,123 @@
<?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.GatewayInterfaceInfoMapper">
<resultMap type="GatewayInterfaceInfo" id="GatewayInterfaceInfoResult">
<result property="id" column="id" />
<result property="interfaceName" column="interface_name" />
<result property="interfacePath" column="interface_path" />
<result property="requestMethod" column="request_method" />
<result property="description" column="description" />
<result property="version" column="version" />
<result property="status" column="status" />
<result property="document" column="document" />
<result property="created" column="created" />
<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,
description, version, status, document, created,
create_time, modified, update_time ,
uri_regular,server_id
from Gateway_interface_info
</sql>
<select id="selectGatewayInterfaceInfoList" parameterType="GatewayInterfaceInfo" resultMap="GatewayInterfaceInfoResult">
<include refid="selectGatewayInterfaceInfoVo"/>
<where>
<if test="interfaceName != null and interfaceName != ''"> and interface_name like concat('%', #{interfaceName}, '%')</if>
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="appCode != null and appCode != ''"> and app_code = #{appCode}</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
</where>
</select>
<select id="selectGatewayInterfaceInfoById" parameterType="Long" resultMap="GatewayInterfaceInfoResult">
<include refid="selectGatewayInterfaceInfoVo"/>
where id = #{id}
</select>
<select id="selectGatewayInterfaceInfoByServerIds" resultMap="GatewayInterfaceInfoResult">
<include refid="selectGatewayInterfaceInfoVo"/>
where server_id in
<foreach item="serverId" collection="serverIds" open="(" separator="," close=")">
#{serverId}
</foreach>
</select>
<insert id="insertGatewayInterfaceInfo" parameterType="GatewayInterfaceInfo" useGeneratedKeys="true" keyProperty="id">
insert into Gateway_interface_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="interfaceName != null and interfaceName != ''">interface_name,</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>
<if test="version != null">version,</if>
<if test="status != null">status,</if>
<if test="document != null">document,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
<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>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="interfaceName != null and interfaceName != ''">#{interfaceName},</if>
<if test="interfacePath != null and interfacePath != ''">#{interfacePath},</if>
<if test="requestMethod != null and requestMethod != ''">#{requestMethod},</if>
<if test="description != null">#{description},</if>
<if test="version != null">#{version},</if>
<if test="status != null">#{status},</if>
<if test="document != null">#{document},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="appCode != null">#{appCode},</if>
<if test="created != null">#{created},</if>
<if test="modified != null">#{modified},</if>
<if test="uriRegular != null">#{uriRegular},</if>
</trim>
</insert>
<update id="updateGatewayInterfaceInfo" parameterType="GatewayInterfaceInfo">
update Gateway_interface_info
<trim prefix="SET" suffixOverrides=",">
<if test="interfaceName != null and interfaceName != ''">interface_name = #{interfaceName},</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>
<if test="version != null">version = #{version},</if>
<if test="status != null">status = #{status},</if>
<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>
</trim>
where id = #{id}
</update>
<update id="updateGatewayInterfaceInfoStatusByIds">
update Gateway_interface_info
set status = #{status}
where id in
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<delete id="deleteGatewayInterfaceInfoById" parameterType="Long">
delete from Gateway_interface_info where id = #{id}
</delete>
<delete id="deleteGatewayInterfaceInfoByIds" parameterType="String">
delete from Gateway_interface_info where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -0,0 +1,84 @@
<?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.GatewayInterfaceLinkStrategyMapper">
<resultMap id="BaseResultMap" type="com.sf.service.gateway.domain.GatewayInterfaceLinkStrategy">
<id property="interfaceId" column="interface_id" jdbcType="BIGINT"/>
<id property="strategyId" column="strategy_id" jdbcType="BIGINT"/>
</resultMap>
<sql id="Base_Column_List">
interface_id,strategy_id
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from Gateway_interface_link_strategy
where interface_id = #{interfaceId,jdbcType=BIGINT} AND strategy_id = #{strategyId,jdbcType=BIGINT}
</select>
<select id="selectGatewayInterfaceLinkStrategyByInterfaceIds" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from Gateway_interface_link_strategy
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_link_strategy
where interface_id = #{interfaceId,jdbcType=BIGINT} AND strategy_id = #{strategyId,jdbcType=BIGINT}
</delete>
<delete id="deleteByInterfaceIds">
delete from Gateway_interface_link_strategy
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.GatewayInterfaceLinkStrategy" useGeneratedKeys="true">
insert into Gateway_interface_link_strategy
( interface_id,strategy_id)
values (#{interfaceId,jdbcType=BIGINT},#{strategyId,jdbcType=BIGINT})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.sf.service.gateway.domain.GatewayInterfaceLinkStrategy" useGeneratedKeys="true">
insert into Gateway_interface_link_strategy
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="interfaceId != null">interfaceId,</if>
<if test="strategyId != null">strategyId,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="interfaceId != null">interface_id = #{interfaceId,jdbcType=BIGINT},</if>
<if test="strategyId != null">strategy_id = #{strategyId,jdbcType=BIGINT},</if>
</trim>
</insert>
<insert id="batchInsertGatewayInterfaceLinkStrategy">
insert into Gateway_interface_link_strategy (interfaceId,strategyId)
values
<foreach collection="linkList" index="" item="link" separator=",">
(
#{link.interfaceId,jdbcType=BIGINT},
#{link.strategyId,jdbcType=BIGINT}
)
</foreach>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.sf.service.gateway.domain.GatewayInterfaceLinkStrategy">
update Gateway_interface_link_strategy
<set>
</set>
where interface_id = #{interfaceId,jdbcType=BIGINT} AND strategy_id = #{strategyId,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.sf.service.gateway.domain.GatewayInterfaceLinkStrategy">
update Gateway_interface_link_strategy
set
where interface_id = #{interfaceId,jdbcType=BIGINT} AND strategy_id = #{strategyId,jdbcType=BIGINT}
</update>
</mapper>

View File

@ -0,0 +1,130 @@
<?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.GatewayRouteMapper">
<resultMap type="GatewayRoute" id="GatewayRouteResult">
<result property="id" column="id" />
<result property="routeName" column="route_name" />
<result property="requestProtocol" column="request_protocol" />
<result property="routeType" column="route_type" />
<result property="routeContent" column="route_content" />
<result property="routeStatusActiveMonitoring" column="route_status_active_monitoring" />
<result property="routeActiveMonitoringPath" column="route_active_monitoring_path" />
<result property="routeActiveMonitoringTimeout" column="route_active_monitoring_timeout" />
<result property="created" column="created" />
<result property="createTime" column="create_time" />
<result property="modified" column="modified" />
<result property="updateTime" column="update_time" />
<result property="appCode" column="app_code" />
<result property="routeActiveStatus" column="route_active_status" />
</resultMap>
<sql id="selectGatewayRouteVo">
select id, route_name, request_protocol, route_type,
route_content, route_status_active_monitoring, route_active_monitoring_path,
route_active_monitoring_timeout, created, create_time,
modified,update_time ,app_code,route_active_status
from Gateway_route
</sql>
<select id="selectGatewayRouteList" parameterType="GatewayRoute" resultMap="GatewayRouteResult">
<include refid="selectGatewayRouteVo"/>
<where>
<if test="routeName != null and routeName != ''"> and route_name like concat('%', #{routeName}, '%')</if>
<if test="requestProtocol != null and requestProtocol != ''"> and request_protocol = #{requestProtocol}</if>
<if test="created != null "> and created = #{created}</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
<if test="params.ids != null and params.ids.size() > 0">
and id in
<foreach item="id" collection="params.ids" open="(" separator="," close=")">
#{id}
</foreach>
</if>
<if test="params.excludedIds != null and params.excludedIds.size() > 0">
and id not in
<foreach item="id" collection="params.excludedIds" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</where>
</select>
<select id="selectGatewayRouteById" parameterType="Long" resultMap="GatewayRouteResult">
<include refid="selectGatewayRouteVo"/>
where id = #{id}
</select>
<select id="selectGatewayRouteByIds" resultMap="GatewayRouteResult">
<include refid="selectGatewayRouteVo"/>
where id in
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<insert id="insertGatewayRoute" parameterType="GatewayRoute" useGeneratedKeys="true" keyProperty="id">
insert into Gateway_route
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="routeName != null and routeName != ''">route_name,</if>
<if test="requestProtocol != null and requestProtocol != ''">request_protocol,</if>
<if test="routeType != null and routeType != ''">route_type,</if>
<if test="routeContent != null">route_content,</if>
<if test="routeStatusActiveMonitoring != null">route_status_active_monitoring,</if>
<if test="routeActiveMonitoringPath != null">route_active_monitoring_path,</if>
<if test="routeActiveMonitoringTimeout != null">route_active_monitoring_timeout,</if>
<if test="created != null">created,</if>
<if test="createTime != null">create_time,</if>
<if test="modified != null">modified,</if>
<if test="updateTime != null">update_time,</if>
<if test="appCode != null">app_code,</if>
<if test="routeActiveStatus != null">route_active_status,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="routeName != null and routeName != ''">#{routeName},</if>
<if test="requestProtocol != null and requestProtocol != ''">#{requestProtocol},</if>
<if test="routeType != null and routeType != ''">#{routeType},</if>
<if test="routeContent != null">#{routeContent},</if>
<if test="routeStatusActiveMonitoring != null">#{routeStatusActiveMonitoring},</if>
<if test="routeActiveMonitoringPath != null">#{routeActiveMonitoringPath},</if>
<if test="routeActiveMonitoringTimeout != null">#{routeActiveMonitoringTimeout},</if>
<if test="created != null">#{created},</if>
<if test="createTime != null">#{createTime},</if>
<if test="modified != null">#{modified},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="appCode != null">#{appCode},</if>
<if test="routeActiveStatus != null">#{routeActiveStatus},</if>
</trim>
</insert>
<update id="updateGatewayRoute" parameterType="GatewayRoute">
update Gateway_route
<trim prefix="SET" suffixOverrides=",">
<if test="routeName != null and routeName != ''">route_name = #{routeName},</if>
<if test="requestProtocol != null and requestProtocol != ''">request_protocol = #{requestProtocol},</if>
<if test="routeType != null and routeType != ''">route_type = #{routeType},</if>
<if test="routeContent != null">route_content = #{routeContent},</if>
<if test="routeStatusActiveMonitoring != null">route_status_active_monitoring = #{routeStatusActiveMonitoring},</if>
<if test="routeActiveMonitoringPath != null">route_active_monitoring_path = #{routeActiveMonitoringPath},</if>
<if test="routeActiveMonitoringTimeout != null">route_active_monitoring_timeout = #{routeActiveMonitoringTimeout},</if>
<if test="created != null">created = #{created},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="modified != null">modified = #{modified},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="appCode != null">app_code = #{appCode},</if>
<if test="routeActiveStatus != null">route_active_status = #{routeActiveStatus},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteGatewayRouteById" parameterType="Long">
delete from Gateway_route where id = #{id}
</delete>
<delete id="deleteGatewayRouteByIds" parameterType="String">
delete from Gateway_route where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -0,0 +1,124 @@
<?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.GatewayServerMapper">
<resultMap type="GatewayServer" id="GatewayServerResult">
<result property="id" column="id" />
<result property="serverName" column="server_name" />
<result property="serverAddress" column="server_address" />
<result property="remark" column="remark" />
<result property="status" column="status" />
<result property="created" column="created" />
<result property="createTime" column="create_time" />
<result property="modified" column="modified" />
<result property="updateTime" column="update_time" />
<result property="serviceModel" column="service_model" />
<result property="routeId" column="route_id" />
</resultMap>
<sql id="selectGatewayServerVo">
select id, server_name, server_address, remark,
status, created, create_time, modified, update_time ,
service_model,route_id
from Gateway_server
</sql>
<select id="selectGatewayServerList" parameterType="GatewayServer" resultMap="GatewayServerResult">
<include refid="selectGatewayServerVo"/>
<where>
<if test="serverName != null and serverName != ''"> and server_name like concat('%', #{serverName}, '%')</if>
<if test="serverAddress != null and serverAddress != ''"> and server_address = #{serverAddress}</if>
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="created != null "> and created = #{created}</if>
<if test="appCode != null "> and app_code = #{appCode}</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
</where>
</select>
<select id="selectGatewayServerById" parameterType="Long" resultMap="GatewayServerResult">
<include refid="selectGatewayServerVo"/>
where id = #{id}
</select>
<select id="selectGatewayServerByIds" resultMap="GatewayServerResult">
<include refid="selectGatewayServerVo"/>
where id in
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<select id="selectGatewayServerByRouteIds" resultMap="GatewayServerResult">
<include refid="selectGatewayServerVo"/>
where route_id in
<foreach item="id" collection="routeIds" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<insert id="insertGatewayServer" parameterType="GatewayServer" useGeneratedKeys="true" keyProperty="id">
insert into Gateway_server
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="serverName != null and serverName != ''">server_name,</if>
<if test="serverAddress != null and serverAddress != ''">server_address,</if>
<if test="remark != null">remark,</if>
<if test="status != null">status,</if>
<if test="created != null">created,</if>
<if test="createTime != null">create_time,</if>
<if test="modified != null">modified,</if>
<if test="updateTime != null">update_time,</if>
<if test="appCode != null">app_code,</if>
<if test="serviceModel != null">service_model,</if>
<if test="routeId != null">route_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="serverName != null and serverName != ''">#{serverName},</if>
<if test="serverAddress != null and serverAddress != ''">#{serverAddress},</if>
<if test="remark != null">#{remark},</if>
<if test="status != null">#{status},</if>
<if test="created != null">#{created},</if>
<if test="createTime != null">#{createTime},</if>
<if test="modified != null">#{modified},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="appCode != null">#{appCode},</if>
<if test="serviceModel != null">#{serviceModel},</if>
<if test="routeId != null">#{routeId},</if>
</trim>
</insert>
<update id="updateGatewayServer" parameterType="GatewayServer">
update Gateway_server
<trim prefix="SET" suffixOverrides=",">
<if test="serverName != null and serverName != ''">server_name = #{serverName},</if>
<if test="serverAddress != null and serverAddress != ''">server_address = #{serverAddress},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="status != null">status = #{status},</if>
<if test="modified != null">modified = #{modified},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="serviceModel != null">service_model = #{serviceModel},</if>
<if test="routeId != null">route_id = #{routeId},</if>
</trim>
where id = #{id}
</update>
<update id="updateGatewayServerStatusByIds">
update Gateway_server
set status = #{status}
where id in
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<delete id="deleteGatewayServerById" parameterType="Long">
delete from Gateway_server where id = #{id}
</delete>
<delete id="deleteGatewayServerByIds" parameterType="String">
delete from Gateway_server where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -0,0 +1,155 @@
<?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.GatewayStrategyMapper">
<resultMap type="GatewayStrategy" id="GatewayStrategyResult">
<result property="id" column="id" />
<result property="strategyName" column="strategy_name" />
<result property="strategyType" column="strategy_type" />
<result property="description" column="description" />
<result property="requestMethod" column="request_method" />
<result property="status" column="status" />
<result property="currentLimitingThreshold" column="current_limiting_threshold" />
<result property="currentLimitingTimeWindow" column="current_limiting_time_window" />
<result property="currentLimitingResponse" column="current_limiting_response" />
<result property="circuitBreakerThreshold" column="circuit_breaker_threshold" />
<result property="circuitBreakerTimeWindow" column="circuit_breaker_time_window" />
<result property="circuitBreakerRecoveryInterval" column="circuit_breaker_recovery_interval" />
<result property="circuitBreakerResponse" column="circuit_breaker_response" />
<result property="created" column="created" />
<result property="createTime" column="create_time" />
<result property="modified" column="modified" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectGatewayStrategyVo">
select id, strategy_name, strategy_type,
description, request_method, status,
current_limiting_threshold,current_limiting_time_window,current_limiting_response,
circuit_breaker_threshold, circuit_breaker_time_window,circuit_breaker_recovery_interval,circuit_breaker_response,
created, create_time, modified, update_time
from Gateway_strategy
</sql>
<select id="selectGatewayStrategyList" parameterType="GatewayStrategy" resultMap="GatewayStrategyResult">
<include refid="selectGatewayStrategyVo"/>
<where>
<if test="strategyName != null and strategyName != ''"> and strategy_name like concat('%', #{strategyName}, '%')</if>
<if test="strategyType != null and strategyType != ''"> and strategy_type = #{strategyType}</if>
<if test="requestMethod != null and requestMethod != ''"> and request_method = #{requestMethod}</if>
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="appCode != null and appCode != ''"> and app_code = #{appCode}</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
<if test="params.ids != null and params.ids.size() > 0">
and id in
<foreach item="id" collection="params.ids" open="(" separator="," close=")">
#{id}
</foreach>
</if>
<if test="params.excludedIds != null and params.excludedIds.size() > 0">
and id not in
<foreach item="id" collection="params.excludedIds" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</where>
</select>
<select id="selectGatewayStrategyById" parameterType="Long" resultMap="GatewayStrategyResult">
<include refid="selectGatewayStrategyVo"/>
where id = #{id}
</select>
<select id="selectGatewayStrategyByIds" resultMap="GatewayStrategyResult">
<include refid="selectGatewayStrategyVo"/>
where id in
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<insert id="insertGatewayStrategy" parameterType="GatewayStrategy" useGeneratedKeys="true" keyProperty="id">
insert into Gateway_strategy
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="strategyName != null and strategyName != ''">strategy_name,</if>
<if test="strategyType != null and strategyType != ''">strategy_type,</if>
<if test="description != null">description,</if>
<if test="requestMethod != null and requestMethod != ''">request_method,</if>
<if test="status != null">status,</if>
<if test="currentLimitingThreshold != null">current_limiting_threshold,</if>
<if test="currentLimitingTimeWindow != null">current_limiting_time_window,</if>
<if test="currentLimitingResponse != null">current_limiting_response,</if>
<if test="circuitBreakerThreshold != null">circuit_breaker_threshold,</if>
<if test="circuitBreakerTimeWindow != null">circuit_breaker_time_window,</if>
<if test="circuitBreakerRecoveryInterval != null">circuit_breaker_recovery_interval,</if>
<if test="circuitBreakerResponse != null">circuit_breaker_response,</if>
<if test="created != null">created,</if>
<if test="createTime != null">create_time,</if>
<if test="modified != null">modified,</if>
<if test="updateTime != null">update_time,</if>
<if test="appCode != null">app_code,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="strategyName != null and strategyName != ''">#{strategyName},</if>
<if test="strategyType != null and strategyType != ''">#{strategyType},</if>
<if test="description != null">#{description},</if>
<if test="requestMethod != null and requestMethod != ''">#{requestMethod},</if>
<if test="status != null">#{status},</if>
<if test="currentLimitingThreshold != null">#{currentLimitingThreshold},</if>
<if test="currentLimitingTimeWindow != null">#{currentLimitingTimeWindow},</if>
<if test="currentLimitingResponse != null">#{currentLimitingResponse},</if>
<if test="circuitBreakerThreshold != null">#{circuitBreakerThreshold},</if>
<if test="circuitBreakerTimeWindow != null">#{circuitBreakerTimeWindow},</if>
<if test="circuitBreakerRecoveryInterval != null">#{circuitBreakerRecoveryInterval},</if>
<if test="circuitBreakerResponse != null">#{circuitBreakerResponse},</if>
<if test="created != null">#{created},</if>
<if test="createTime != null">#{createTime},</if>
<if test="modified != null">#{modified},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="appCode != null">#{appCode},</if>
</trim>
</insert>
<update id="updateGatewayStrategy" parameterType="GatewayStrategy">
update Gateway_strategy
<trim prefix="SET" suffixOverrides=",">
<if test="strategyName != null and strategyName != ''">strategy_name = #{strategyName},</if>
<if test="strategyType != null and strategyType != ''">strategy_type = #{strategyType},</if>
<if test="description != null">description = #{description},</if>
<if test="requestMethod != null and requestMethod != ''">request_method = #{requestMethod},</if>
<if test="status != null">status = #{status},</if>
<if test="currentLimitingThreshold != null">current_limiting_threshold = #{currentLimitingThreshold},</if>
<if test="currentLimitingTimeWindow != null">current_limiting_time_window = #{currentLimitingTimeWindow},</if>
<if test="currentLimitingResponse != null">current_limiting_response = #{currentLimitingResponse},</if>
<if test="circuitBreakerThreshold != null">circuit_breaker_threshold = #{circuitBreakerThreshold},</if>
<if test="circuitBreakerTimeWindow != null">circuit_breaker_time_window = #{circuitBreakerTimeWindow},</if>
<if test="circuitBreakerRecoveryInterval != null">circuit_breaker_recovery_interval = #{circuitBreakerRecoveryInterval},</if>
<if test="circuitBreakerResponse != null">circuit_breaker_response = #{circuitBreakerResponse},</if>
<if test="modified != null">modified = #{modified},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<update id="updateGatewayStrategyStatusByIds">
update Gateway_strategy
set status = #{status}
where id in
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<delete id="deleteGatewayStrategyById" parameterType="Long">
delete from Gateway_strategy where id = #{id}
</delete>
<delete id="deleteGatewayStrategyByIds" parameterType="String">
delete from Gateway_strategy where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>