diff --git a/sf-common/src/main/java/com/sf/common/utils/RegexUtils.java b/sf-common/src/main/java/com/sf/common/utils/RegexUtils.java new file mode 100644 index 0000000..b64a59b --- /dev/null +++ b/sf-common/src/main/java/com/sf/common/utils/RegexUtils.java @@ -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; + } + } +} diff --git a/sf-common/src/main/java/com/sf/common/utils/URLUtils.java b/sf-common/src/main/java/com/sf/common/utils/URLUtils.java new file mode 100644 index 0000000..034ca21 --- /dev/null +++ b/sf-common/src/main/java/com/sf/common/utils/URLUtils.java @@ -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; + } + } +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayConfigController.java b/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayConfigController.java new file mode 100644 index 0000000..5fc7d23 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayConfigController.java @@ -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(); + } + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayInterfaceInfoController.java b/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayInterfaceInfoController.java new file mode 100644 index 0000000..e19129d --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayInterfaceInfoController.java @@ -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 list = gatewayInterfaceInfoService.selectGatewayInterfaceInfoList(gatewayInterfaceInfo); + Set serverIds = list.stream().map(GatewayInterfaceInfo::getServerId).collect(Collectors.toSet()); + List serverList = gatewayServerService.selectGatewayServerByIds(serverIds); + Map serverIdAndNameMap = serverList.stream().collect(Collectors.toMap(GatewayServer::getId, GatewayServer::getServerName)); + List 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 list = gatewayInterfaceInfoService.selectGatewayInterfaceInfoList(gatewayInterfaceInfo); + ExcelUtil util = new ExcelUtil(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 linkList = gatewayInterfaceInfoService.selectGatewayInterfaceLinkStrategyByInterfaceIds(Collections.singleton(id)); + GatewayServer gatewayServer = gatewayServerService.selectGatewayServerById(gatewayInterfaceInfo.getServerId()); + List 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 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()))); + } + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayRouteController.java b/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayRouteController.java new file mode 100644 index 0000000..e23682f --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayRouteController.java @@ -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 list = gatewayRouteService.selectGatewayRouteList(gatewayRoute); + List 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 list = gatewayRouteService.selectGatewayRouteList(gatewayRoute); + ExcelUtil util = new ExcelUtil(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 bindableList(QueryGatewayRouteDTO dto) + { + GatewayRoute gatewayRoute = new GatewayRoute(); + gatewayRoute.setRouteName(dto.getRouteName()); + gatewayRoute.setAppCode(AppUtils.getAppCodeFromRequestHeader()); + Map params = new HashMap<>(8); + params.put("ids",dto.getIds()); + params.put("excludedIds",dto.getExcludedIds()); + gatewayRoute.setParams(params); + List 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()); + } +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayServerController.java b/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayServerController.java new file mode 100644 index 0000000..643ce2a --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayServerController.java @@ -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 list = gatewayServerService.selectGatewayServerList(gatewayServer); + // 如果是路由模式的服务,查询对应的路由服务信息 + Collection routeIds = list.stream().filter(item -> GatewayServiceModel.ROUTE.getCode().equals(item.getServiceModel())) + .map(GatewayServer::getRouteId) + .collect(Collectors.toSet()); + List routeList = gatewayRouteService.selectGatewayRouteByIds(routeIds); + Map routeIdAndNameMap = routeList.stream().collect(Collectors.toMap(GatewayRoute::getId, GatewayRoute::getRouteName)); + List 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 list = gatewayServerService.selectGatewayServerList(gatewayServer); + ExcelUtil util = new ExcelUtil(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 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 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()))); + } +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayStrategyController.java b/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayStrategyController.java new file mode 100644 index 0000000..01105f1 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/controller/GatewayStrategyController.java @@ -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 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 list = gatewayStrategyService.selectGatewayStrategyList(gatewayStrategy); + ExcelUtil util = new ExcelUtil(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 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 params = new HashMap<>(8); + params.put("ids",dto.getIds()); + params.put("excludedIds",dto.getExcludedIds()); + gatewayStrategy.setParams(params); + List 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()); + } +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayConfig.java b/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayConfig.java new file mode 100644 index 0000000..fb4d425 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayConfig.java @@ -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; + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayInterfaceInfo.java b/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayInterfaceInfo.java new file mode 100644 index 0000000..375eda4 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayInterfaceInfo.java @@ -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; + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayInterfaceLinkStrategy.java b/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayInterfaceLinkStrategy.java new file mode 100644 index 0000000..e23de42 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayInterfaceLinkStrategy.java @@ -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; + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayRoute.java b/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayRoute.java new file mode 100644 index 0000000..ef2040b --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayRoute.java @@ -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 headerValues; + + /** + * HEADER模式使用: + * 请求头值匹配类型(EQ,IN) + */ + private String matchType; + + /** + * 服务地址 + */ + private String serverAddress; + } + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayServer.java b/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayServer.java new file mode 100644 index 0000000..98d8945 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayServer.java @@ -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; + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayStrategy.java b/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayStrategy.java new file mode 100644 index 0000000..49a83e9 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/GatewayStrategy.java @@ -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; + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/dto/InsertGatewayInterfaceInfoDTO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/dto/InsertGatewayInterfaceInfoDTO.java new file mode 100644 index 0000000..681c70a --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/dto/InsertGatewayInterfaceInfoDTO.java @@ -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 strategyIds; +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/dto/InsertOrUpdateGatewayRouteDTO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/dto/InsertOrUpdateGatewayRouteDTO.java new file mode 100644 index 0000000..582ab28 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/dto/InsertOrUpdateGatewayRouteDTO.java @@ -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 routeContent; + + /** 路由状态探活(0停用 1启用) */ + @Excel(name = "路由状态探活(0停用 1启用)") + private String routeStatusActiveMonitoring; + + /** 路由探活路径 */ + @Excel(name = "路由探活路径") + private String routeActiveMonitoringPath; + + /** 路由探活超时时间,单位ms */ + @Excel(name = "路由探活超时时间,单位ms") + private Long routeActiveMonitoringTimeout; + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/dto/QueryGatewayRouteDTO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/dto/QueryGatewayRouteDTO.java new file mode 100644 index 0000000..8984545 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/dto/QueryGatewayRouteDTO.java @@ -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 ids; + + @ApiModelProperty("需要排除的id") + private List excludedIds; + + @ApiModelProperty("策略名称") + private String routeName; + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/dto/QueryGatewayStrategyDTO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/dto/QueryGatewayStrategyDTO.java new file mode 100644 index 0000000..2397ae2 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/dto/QueryGatewayStrategyDTO.java @@ -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 ids; + + @ApiModelProperty("状态(0停用 1启用)") + private String status; + + @ApiModelProperty("需要排除的id") + private List excludedIds; + + @ApiModelProperty("策略名称") + private String strategyName; + + @ApiModelProperty("策略类型") + private String strategyType; + + private String appCode; +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/dto/UpdateDataStatusDTO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/dto/UpdateDataStatusDTO.java new file mode 100644 index 0000000..0996e60 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/dto/UpdateDataStatusDTO.java @@ -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 ids; + + /** + * 状态(0停用 1启用) + */ + @NotBlank(message = "状态标识不能为空") + private String status; + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/dto/UpdateGatewayInterfaceInfoDTO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/dto/UpdateGatewayInterfaceInfoDTO.java new file mode 100644 index 0000000..62f8a8e --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/dto/UpdateGatewayInterfaceInfoDTO.java @@ -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 strategyIds; +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayInterfaceInfoDetailedVO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayInterfaceInfoDetailedVO.java new file mode 100644 index 0000000..3d75d63 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayInterfaceInfoDetailedVO.java @@ -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 strategyList; + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayInterfaceInfoListVO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayInterfaceInfoListVO.java new file mode 100644 index 0000000..11f2696 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayInterfaceInfoListVO.java @@ -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 strategyList; + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayRouteListVO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayRouteListVO.java new file mode 100644 index 0000000..e7dd8f8 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayRouteListVO.java @@ -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 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; + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayServerDetailedVO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayServerDetailedVO.java new file mode 100644 index 0000000..8bac930 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayServerDetailedVO.java @@ -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 interfaceInfoList; +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayServerListVO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayServerListVO.java new file mode 100644 index 0000000..7847216 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayServerListVO.java @@ -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; + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayStrategyListVO.java b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayStrategyListVO.java new file mode 100644 index 0000000..c72d47e --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/domain/vo/GatewayStrategyListVO.java @@ -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; + + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/enums/EncryptionAlgorithm.java b/sf-service/src/main/java/com/sf/service/gateway/enums/EncryptionAlgorithm.java new file mode 100644 index 0000000..64c0db4 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/enums/EncryptionAlgorithm.java @@ -0,0 +1,68 @@ +package com.sf.service.gateway.enums; + +/** + * 支持的加密算法 + * 目前支持 ECC、RSA 和国密(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 + */ +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/enums/GatewayDataStatus.java b/sf-service/src/main/java/com/sf/service/gateway/enums/GatewayDataStatus.java new file mode 100644 index 0000000..07df495 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/enums/GatewayDataStatus.java @@ -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; + } +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/enums/GatewayRouteType.java b/sf-service/src/main/java/com/sf/service/gateway/enums/GatewayRouteType.java new file mode 100644 index 0000000..e8c9b59 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/enums/GatewayRouteType.java @@ -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; + } +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/enums/GatewayServiceModel.java b/sf-service/src/main/java/com/sf/service/gateway/enums/GatewayServiceModel.java new file mode 100644 index 0000000..98a91f9 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/enums/GatewayServiceModel.java @@ -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; + } +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/enums/GatewayStrategyType.java b/sf-service/src/main/java/com/sf/service/gateway/enums/GatewayStrategyType.java new file mode 100644 index 0000000..afcddda --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/enums/GatewayStrategyType.java @@ -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; + } +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/enums/MatchType.java b/sf-service/src/main/java/com/sf/service/gateway/enums/MatchType.java new file mode 100644 index 0000000..8d52b3f --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/enums/MatchType.java @@ -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 + */ +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/enums/RequestProtocol.java b/sf-service/src/main/java/com/sf/service/gateway/enums/RequestProtocol.java new file mode 100644 index 0000000..604e17a --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/enums/RequestProtocol.java @@ -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 + */ +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/enums/RouteActiveStatus.java b/sf-service/src/main/java/com/sf/service/gateway/enums/RouteActiveStatus.java new file mode 100644 index 0000000..b7f903a --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/enums/RouteActiveStatus.java @@ -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; + } +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayConfigMapper.java b/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayConfigMapper.java new file mode 100644 index 0000000..f624dd8 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayConfigMapper.java @@ -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); + +} + + + + diff --git a/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayInterfaceInfoMapper.java b/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayInterfaceInfoMapper.java new file mode 100644 index 0000000..d7b2240 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayInterfaceInfoMapper.java @@ -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 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 ids, @Param("status") String status); + + List selectGatewayInterfaceInfoByServerIds(@Param("serverIds") Collection serverIds); +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayInterfaceLinkStrategyMapper.java b/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayInterfaceLinkStrategyMapper.java new file mode 100644 index 0000000..a481772 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayInterfaceLinkStrategyMapper.java @@ -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 linkList); + + void deleteByInterfaceIds(@Param("interfaceIds") Collection interfaceIds); + + List selectGatewayInterfaceLinkStrategyByInterfaceIds(@Param("interfaceIds") Collection interfaceIds); +} + + + + diff --git a/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayRouteMapper.java b/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayRouteMapper.java new file mode 100644 index 0000000..349d6bd --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayRouteMapper.java @@ -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 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 selectGatewayRouteByIds(@Param("ids") Collection ids); +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayServerMapper.java b/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayServerMapper.java new file mode 100644 index 0000000..ef72b60 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayServerMapper.java @@ -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 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 ids, @Param("status") String status); + + List selectGatewayServerByIds(@Param("ids") Collection ids); + + List selectGatewayServerByRouteIds(@Param("routeIds") Collection routeIds); +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayStrategyMapper.java b/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayStrategyMapper.java new file mode 100644 index 0000000..db141a7 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/mapper/GatewayStrategyMapper.java @@ -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 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 ids, @Param("status") String status); + + List selectGatewayStrategyByIds(@Param("ids") Collection ids); +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/service/IGatewayConfigService.java b/sf-service/src/main/java/com/sf/service/gateway/service/IGatewayConfigService.java new file mode 100644 index 0000000..36de00d --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/service/IGatewayConfigService.java @@ -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); +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/service/IGatewayInterfaceInfoService.java b/sf-service/src/main/java/com/sf/service/gateway/service/IGatewayInterfaceInfoService.java new file mode 100644 index 0000000..84bb34e --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/service/IGatewayInterfaceInfoService.java @@ -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 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 ids, GatewayDataStatus status); + + List selectGatewayInterfaceInfoByServerIds(Collection serverIds); + + /** + * 添加接口信息及绑定的策略信息 + * + * @param dto + * @return + */ + Long insertGatewayInterfaceInfoAndBindStrategy(InsertGatewayInterfaceInfoDTO dto); + + /** + * 修改接口信息及绑定的策略信息 + * @param dto + * @return + */ + Long updateGatewayInterfaceInfoAndBindStrategy(UpdateGatewayInterfaceInfoDTO dto); + + List selectGatewayInterfaceLinkStrategyByInterfaceIds(Collection interfaceIds); +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/service/IGatewayRouteService.java b/sf-service/src/main/java/com/sf/service/gateway/service/IGatewayRouteService.java new file mode 100644 index 0000000..1f9a65e --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/service/IGatewayRouteService.java @@ -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 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 selectGatewayRouteByIds(Collection ids); +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/service/IGatewayServerService.java b/sf-service/src/main/java/com/sf/service/gateway/service/IGatewayServerService.java new file mode 100644 index 0000000..55d9d7b --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/service/IGatewayServerService.java @@ -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 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 ids, GatewayDataStatus status); + + List selectGatewayServerByIds(Collection ids); + + List selectGatewayServerByRouteIds(Collection routeIds); +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/service/IGatewayStrategyService.java b/sf-service/src/main/java/com/sf/service/gateway/service/IGatewayStrategyService.java new file mode 100644 index 0000000..e583c83 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/service/IGatewayStrategyService.java @@ -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 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 ids, GatewayDataStatus status); + + List selectGatewayStrategyByIds(Collection ids); +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayConfigServiceImpl.java b/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayConfigServiceImpl.java new file mode 100644 index 0000000..3af1156 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayConfigServiceImpl.java @@ -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); + } + } +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayInterfaceInfoServiceImpl.java b/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayInterfaceInfoServiceImpl.java new file mode 100644 index 0000000..f9d2541 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayInterfaceInfoServiceImpl.java @@ -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 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 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 selectGatewayInterfaceInfoByServerIds(Collection 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 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 linkStrategyList = dto.getStrategyIds() + .stream().map(strategyId -> new GatewayInterfaceLinkStrategy(dto.getId(), strategyId)) + .collect(Collectors.toList()); + gatewayInterfaceLinkStrategyMapper.batchInsertGatewayInterfaceLinkStrategy(linkStrategyList); + } + return gatewayInterfaceInfo.getId(); + } + + @Override + public List selectGatewayInterfaceLinkStrategyByInterfaceIds(Collection interfaceIds) { + if (CollectionUtils.isEmpty(interfaceIds)){ + return Collections.emptyList(); + } + return gatewayInterfaceLinkStrategyMapper.selectGatewayInterfaceLinkStrategyByInterfaceIds(interfaceIds); + } + + private void checkGatewayStrategyTypeCannotBeRepeated(List strategyIds) { + List strategyList = gatewayStrategyService.selectGatewayStrategyByIds(strategyIds); + Map> groupByStrategyTypeMap = strategyList.stream().collect(Collectors.groupingBy(GatewayStrategy::getStrategyType)); + groupByStrategyTypeMap.forEach((type,strategies) ->{ + Assert.isTrue(strategies.size() == 1,type + "类型只能选择一个!"); + }); + } + +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayRouteServiceImpl.java b/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayRouteServiceImpl.java new file mode 100644 index 0000000..98ab095 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayRouteServiceImpl.java @@ -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 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 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 ids) { + List serverList = gatewayServerService.selectGatewayServerByRouteIds(ids); + Assert.isTrue(CollUtil.isEmpty(serverList),"存在关联服务,删除失败!"); + } + + @Override + public List selectGatewayRouteByIds(Collection ids) { + if (CollectionUtils.isEmpty(ids)){ + return Collections.emptyList(); + } + return gatewayRouteMapper.selectGatewayRouteByIds(ids); + } +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayServerServiceImpl.java b/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayServerServiceImpl.java new file mode 100644 index 0000000..cb6a145 --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayServerServiceImpl.java @@ -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 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 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 gatewayInterfaceInfoList = gatewayInterfaceInfoService.selectGatewayInterfaceInfoByServerIds(CollUtil.newHashSet(id)); + Assert.isTrue(CollUtil.isEmpty(gatewayInterfaceInfoList),"服务存在关联的接口,删除失败!"); + return gatewayServerMapper.deleteGatewayServerById(id); + } + + @Override + public int updateGatewayServerStatusByIds(Collection 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 selectGatewayServerByIds(Collection ids) { + if (CollectionUtils.isEmpty(ids)){ + return Collections.emptyList(); + } + return gatewayServerMapper.selectGatewayServerByIds(ids); + } + + @Override + public List selectGatewayServerByRouteIds(Collection routeIds) { + if (CollectionUtils.isEmpty(routeIds)){ + return Collections.emptyList(); + } + return gatewayServerMapper.selectGatewayServerByRouteIds(routeIds); + } +} diff --git a/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayStrategyServiceImpl.java b/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayStrategyServiceImpl.java new file mode 100644 index 0000000..1a1fd9f --- /dev/null +++ b/sf-service/src/main/java/com/sf/service/gateway/service/impl/GatewayStrategyServiceImpl.java @@ -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 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 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 selectGatewayStrategyByIds(Collection ids) { + if (CollectionUtils.isEmpty(ids)){ + return Collections.emptyList(); + } + return gatewayStrategyMapper.selectGatewayStrategyByIds(ids); + } +} diff --git a/sf-service/src/main/resources/mapper/gateway/GatewayConfigMapper.xml b/sf-service/src/main/resources/mapper/gateway/GatewayConfigMapper.xml new file mode 100644 index 0000000..0b10783 --- /dev/null +++ b/sf-service/src/main/resources/mapper/gateway/GatewayConfigMapper.xml @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + + delete from Gateway_config + where app_code = #{appCode,jdbcType=VARCHAR} + + + 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 into Gateway_config + + appCode, + dataEncryptionStatus, + encryptionAlgorithm, + privateKey, + publicKey, + apiCurrentLimitingStatus, + apiCurrentLimitingThreshold, + apiCurrentLimitingTimeWindow, + apiCurrentLimitingDefaultResponse, + appCurrentLimitingStatus, + appCurrentLimitingThreshold, + appCurrentLimitingTimeWindow, + appCurrentLimitingDefaultResponse, + created, + createTime, + modified, + updateTime, + + + app_code = #{appCode,jdbcType=VARCHAR}, + 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}, + + + + update Gateway_config + + + 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 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} + + diff --git a/sf-service/src/main/resources/mapper/gateway/GatewayInterfaceInfoMapper.xml b/sf-service/src/main/resources/mapper/gateway/GatewayInterfaceInfoMapper.xml new file mode 100644 index 0000000..bfa6c95 --- /dev/null +++ b/sf-service/src/main/resources/mapper/gateway/GatewayInterfaceInfoMapper.xml @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + + + + + insert into Gateway_interface_info + + interface_name, + interface_path, + request_method, + description, + version, + status, + document, + create_time, + update_time, + app_code, + created, + modified, + uri_regular, + + + #{interfaceName}, + #{interfacePath}, + #{requestMethod}, + #{description}, + #{version}, + #{status}, + #{document}, + #{createTime}, + #{updateTime}, + #{appCode}, + #{created}, + #{modified}, + #{uriRegular}, + + + + + update Gateway_interface_info + + interface_name = #{interfaceName}, + interface_path = #{interfacePath}, + request_method = #{requestMethod}, + description = #{description}, + version = #{version}, + status = #{status}, + document = #{document}, + modified = #{modified}, + update_time = #{updateTime}, + uri_regular = #{uriRegular}, + + where id = #{id} + + + update Gateway_interface_info + set status = #{status} + where id in + + #{id} + + + + + delete from Gateway_interface_info where id = #{id} + + + + delete from Gateway_interface_info where id in + + #{id} + + + \ No newline at end of file diff --git a/sf-service/src/main/resources/mapper/gateway/GatewayInterfaceLinkStrategyMapper.xml b/sf-service/src/main/resources/mapper/gateway/GatewayInterfaceLinkStrategyMapper.xml new file mode 100644 index 0000000..adaa89a --- /dev/null +++ b/sf-service/src/main/resources/mapper/gateway/GatewayInterfaceLinkStrategyMapper.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + interface_id,strategy_id + + + + + + + delete from Gateway_interface_link_strategy + where interface_id = #{interfaceId,jdbcType=BIGINT} AND strategy_id = #{strategyId,jdbcType=BIGINT} + + + + delete from Gateway_interface_link_strategy + where interface_id in + + #{id} + + + + + insert into Gateway_interface_link_strategy + ( interface_id,strategy_id) + values (#{interfaceId,jdbcType=BIGINT},#{strategyId,jdbcType=BIGINT}) + + + insert into Gateway_interface_link_strategy + + interfaceId, + strategyId, + + + interface_id = #{interfaceId,jdbcType=BIGINT}, + strategy_id = #{strategyId,jdbcType=BIGINT}, + + + + + insert into Gateway_interface_link_strategy (interfaceId,strategyId) + values + + ( + #{link.interfaceId,jdbcType=BIGINT}, + #{link.strategyId,jdbcType=BIGINT} + ) + + + + + update Gateway_interface_link_strategy + + + where interface_id = #{interfaceId,jdbcType=BIGINT} AND strategy_id = #{strategyId,jdbcType=BIGINT} + + + update Gateway_interface_link_strategy + set + where interface_id = #{interfaceId,jdbcType=BIGINT} AND strategy_id = #{strategyId,jdbcType=BIGINT} + + diff --git a/sf-service/src/main/resources/mapper/gateway/GatewayRouteMapper.xml b/sf-service/src/main/resources/mapper/gateway/GatewayRouteMapper.xml new file mode 100644 index 0000000..cde9041 --- /dev/null +++ b/sf-service/src/main/resources/mapper/gateway/GatewayRouteMapper.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + + + + + insert into Gateway_route + + 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, + + + #{routeName}, + #{requestProtocol}, + #{routeType}, + #{routeContent}, + #{routeStatusActiveMonitoring}, + #{routeActiveMonitoringPath}, + #{routeActiveMonitoringTimeout}, + #{created}, + #{createTime}, + #{modified}, + #{updateTime}, + #{appCode}, + #{routeActiveStatus}, + + + + + update Gateway_route + + route_name = #{routeName}, + request_protocol = #{requestProtocol}, + route_type = #{routeType}, + route_content = #{routeContent}, + route_status_active_monitoring = #{routeStatusActiveMonitoring}, + route_active_monitoring_path = #{routeActiveMonitoringPath}, + route_active_monitoring_timeout = #{routeActiveMonitoringTimeout}, + created = #{created}, + create_time = #{createTime}, + modified = #{modified}, + update_time = #{updateTime}, + app_code = #{appCode}, + route_active_status = #{routeActiveStatus}, + + where id = #{id} + + + + delete from Gateway_route where id = #{id} + + + + delete from Gateway_route where id in + + #{id} + + + \ No newline at end of file diff --git a/sf-service/src/main/resources/mapper/gateway/GatewayServerMapper.xml b/sf-service/src/main/resources/mapper/gateway/GatewayServerMapper.xml new file mode 100644 index 0000000..0088e1e --- /dev/null +++ b/sf-service/src/main/resources/mapper/gateway/GatewayServerMapper.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + select id, server_name, server_address, remark, + status, created, create_time, modified, update_time , + service_model,route_id + from Gateway_server + + + + + + + + + + + insert into Gateway_server + + server_name, + server_address, + remark, + status, + created, + create_time, + modified, + update_time, + app_code, + service_model, + route_id, + + + #{serverName}, + #{serverAddress}, + #{remark}, + #{status}, + #{created}, + #{createTime}, + #{modified}, + #{updateTime}, + #{appCode}, + #{serviceModel}, + #{routeId}, + + + + + update Gateway_server + + server_name = #{serverName}, + server_address = #{serverAddress}, + remark = #{remark}, + status = #{status}, + modified = #{modified}, + update_time = #{updateTime}, + service_model = #{serviceModel}, + route_id = #{routeId}, + + where id = #{id} + + + + update Gateway_server + set status = #{status} + where id in + + #{id} + + + + + delete from Gateway_server where id = #{id} + + + + delete from Gateway_server where id in + + #{id} + + + \ No newline at end of file diff --git a/sf-service/src/main/resources/mapper/gateway/GatewayStrategyMapper.xml b/sf-service/src/main/resources/mapper/gateway/GatewayStrategyMapper.xml new file mode 100644 index 0000000..25504c4 --- /dev/null +++ b/sf-service/src/main/resources/mapper/gateway/GatewayStrategyMapper.xml @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + + + + + + insert into Gateway_strategy + + 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, + app_code, + + + #{strategyName}, + #{strategyType}, + #{description}, + #{requestMethod}, + #{status}, + #{currentLimitingThreshold}, + #{currentLimitingTimeWindow}, + #{currentLimitingResponse}, + #{circuitBreakerThreshold}, + #{circuitBreakerTimeWindow}, + #{circuitBreakerRecoveryInterval}, + #{circuitBreakerResponse}, + #{created}, + #{createTime}, + #{modified}, + #{updateTime}, + #{appCode}, + + + + + update Gateway_strategy + + strategy_name = #{strategyName}, + strategy_type = #{strategyType}, + description = #{description}, + request_method = #{requestMethod}, + status = #{status}, + current_limiting_threshold = #{currentLimitingThreshold}, + current_limiting_time_window = #{currentLimitingTimeWindow}, + current_limiting_response = #{currentLimitingResponse}, + circuit_breaker_threshold = #{circuitBreakerThreshold}, + circuit_breaker_time_window = #{circuitBreakerTimeWindow}, + circuit_breaker_recovery_interval = #{circuitBreakerRecoveryInterval}, + circuit_breaker_response = #{circuitBreakerResponse}, + modified = #{modified}, + update_time = #{updateTime}, + + where id = #{id} + + + + update Gateway_strategy + set status = #{status} + where id in + + #{id} + + + + + delete from Gateway_strategy where id = #{id} + + + + delete from Gateway_strategy where id in + + #{id} + + + \ No newline at end of file