mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-20 02:08:15 +08:00
服务管控代码结构调整,接收不到通知问题处理
This commit is contained in:
parent
fa54edaf6e
commit
e07fe57317
17
pom.xml
17
pom.xml
@ -215,6 +215,11 @@
|
|||||||
<version>${spring-boot.version}</version>
|
<version>${spring-boot.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--redisson-->
|
<!--redisson-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.redisson</groupId>
|
||||||
|
<artifactId>redisson</artifactId>
|
||||||
|
<version>${redisson.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.redisson</groupId>
|
<groupId>org.redisson</groupId>
|
||||||
<artifactId>redisson-spring-boot-starter</artifactId>
|
<artifactId>redisson-spring-boot-starter</artifactId>
|
||||||
@ -276,6 +281,16 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- isc模块 -->
|
<!-- isc模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-isc-parent</artifactId>
|
||||||
|
<version>${ruoyi-vue-plus.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-isc-common</artifactId>
|
||||||
|
<version>${ruoyi-vue-plus.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-isc</artifactId>
|
<artifactId>ruoyi-isc</artifactId>
|
||||||
@ -302,7 +317,7 @@
|
|||||||
<module>ruoyi-demo</module>
|
<module>ruoyi-demo</module>
|
||||||
<module>ruoyi-extend</module>
|
<module>ruoyi-extend</module>
|
||||||
<module>ruoyi-oss</module>
|
<module>ruoyi-oss</module>
|
||||||
<module>ruoyi-isc</module>
|
<module>ruoyi-isc-parent</module>
|
||||||
</modules>
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
|||||||
@ -143,4 +143,14 @@ public class Constants
|
|||||||
* LDAP 远程方法调用
|
* LDAP 远程方法调用
|
||||||
*/
|
*/
|
||||||
public static final String LOOKUP_LDAP = "ldap://";
|
public static final String LOOKUP_LDAP = "ldap://";
|
||||||
|
|
||||||
|
/** 待审核 */
|
||||||
|
public static final String AUDIT_WAIT = "0";
|
||||||
|
|
||||||
|
/** 审核通过 */
|
||||||
|
public static final String AUDIT_PASS = "1";
|
||||||
|
|
||||||
|
/** 审核驳回 */
|
||||||
|
public static final String AUDIT_REJECT = "2";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,16 +2,7 @@ package com.ruoyi.common.constant;
|
|||||||
|
|
||||||
public class IscConstants {
|
public class IscConstants {
|
||||||
|
|
||||||
/** 待审核 */
|
/** 在线状态 在线 */
|
||||||
public static final String AUDIT_WAIT = "0";
|
|
||||||
|
|
||||||
/** 审核通过 */
|
|
||||||
public static final String AUDIT_PASS = "1";
|
|
||||||
|
|
||||||
/** 审核驳回 */
|
|
||||||
public static final String AUDIT_REJECT = "2";
|
|
||||||
|
|
||||||
/** 待审核 */
|
|
||||||
public static final String ONLINE_STATUS_ON = "1";
|
public static final String ONLINE_STATUS_ON = "1";
|
||||||
|
|
||||||
/** 申请类型 申请服务 */
|
/** 申请类型 申请服务 */
|
||||||
@ -22,14 +13,4 @@ public class IscConstants {
|
|||||||
|
|
||||||
/** 申请类型 申请修改 */
|
/** 申请类型 申请修改 */
|
||||||
public static final String APPLY_TYPE_MODIFY = "2";
|
public static final String APPLY_TYPE_MODIFY = "2";
|
||||||
|
|
||||||
/**
|
|
||||||
* Gateway 路由信息Redis Key
|
|
||||||
*/
|
|
||||||
public static final String KEY_ROUTES = "ROUTES:";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gateway 服务对应AK规则
|
|
||||||
*/
|
|
||||||
public static final String KEY_RULES = "RULES:";
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,10 @@
|
|||||||
<artifactId>ruoyi-isc-gateway</artifactId>
|
<artifactId>ruoyi-isc-gateway</artifactId>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-isc-common</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-gateway</artifactId>
|
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||||
|
|||||||
@ -5,14 +5,11 @@ import com.ruoyi.gateway.config.handler.GlobalErrorWebExceptionHandler;
|
|||||||
import com.ruoyi.gateway.config.provider.RedisRouteDefinitionRepository;
|
import com.ruoyi.gateway.config.provider.RedisRouteDefinitionRepository;
|
||||||
import com.ruoyi.gateway.filter.CustomerGlobalFilter;
|
import com.ruoyi.gateway.filter.CustomerGlobalFilter;
|
||||||
import com.ruoyi.gateway.ratelimit.CustomerRedisRateLimiter;
|
import com.ruoyi.gateway.ratelimit.CustomerRedisRateLimiter;
|
||||||
import com.ruoyi.gateway.utils.beans.TopicMsg;
|
|
||||||
import com.ruoyi.gateway.utils.caching.CachingRule;
|
import com.ruoyi.gateway.utils.caching.CachingRule;
|
||||||
|
import com.ruoyi.isc.common.utils.beans.TopicMsg;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.redisson.api.RTopic;
|
import org.redisson.api.RTopic;
|
||||||
import org.redisson.api.RedissonClient;
|
import org.redisson.api.RedissonClient;
|
||||||
import org.redisson.client.codec.Codec;
|
|
||||||
import org.redisson.codec.SerializationCodec;
|
|
||||||
import org.redisson.codec.TypedJsonJacksonCodec;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
|
import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
|
||||||
import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
|
import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
|
||||||
@ -32,6 +29,8 @@ import org.springframework.lang.NonNull;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import static com.ruoyi.isc.common.constant.IscGatewayContants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gateway 配置文件
|
* Gateway 配置文件
|
||||||
*
|
*
|
||||||
@ -41,9 +40,6 @@ import java.util.function.Consumer;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Configuration
|
@Configuration
|
||||||
public class GatewayConfig implements ApplicationEventPublisherAware {
|
public class GatewayConfig implements ApplicationEventPublisherAware {
|
||||||
public static final Codec TOPIC_MSG_CODES_INSTANCE = new TypedJsonJacksonCodec(String.class, TopicMsg.class);
|
|
||||||
public static final String TOPIC_GATEWAY_REFRESH_ROUTE = "TOPIC_GATEWAY_REFRESH_ROUTE";
|
|
||||||
public static final String TOPIC_GATEWAY_RULE = "TOPIC_GATEWAY_RULE";
|
|
||||||
public ApplicationEventPublisher publisher;
|
public ApplicationEventPublisher publisher;
|
||||||
private final RedissonClient client = SpringUtil.getBean(RedissonClient.class);
|
private final RedissonClient client = SpringUtil.getBean(RedissonClient.class);
|
||||||
|
|
||||||
@ -105,7 +101,7 @@ public class GatewayConfig implements ApplicationEventPublisherAware {
|
|||||||
* @param consumer 自定义处理
|
* @param consumer 自定义处理
|
||||||
*/
|
*/
|
||||||
public <T> void subscribe(String channelKey, Class<T> clazz, Consumer<T> consumer) {
|
public <T> void subscribe(String channelKey, Class<T> clazz, Consumer<T> consumer) {
|
||||||
RTopic topic = client.getTopic(channelKey, new SerializationCodec());
|
RTopic topic = client.getTopic(channelKey);
|
||||||
topic.addListener(clazz, (channel, msg) -> consumer.accept(msg));
|
topic.addListener(clazz, (channel, msg) -> consumer.accept(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,8 @@ import org.springframework.cloud.gateway.route.RouteDefinitionRepository;
|
|||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import static com.ruoyi.isc.common.constant.IscRedisKeys.KEY_ROUTES;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redis 路由仓库
|
* Redis 路由仓库
|
||||||
*
|
*
|
||||||
@ -20,7 +22,6 @@ import reactor.core.publisher.Mono;
|
|||||||
public class RedisRouteDefinitionRepository implements RouteDefinitionRepository
|
public class RedisRouteDefinitionRepository implements RouteDefinitionRepository
|
||||||
{
|
{
|
||||||
public static final Codec ROUTE_CODES_INSTANCE = new TypedJsonJacksonCodec(String.class, RouteDefinition.class);
|
public static final Codec ROUTE_CODES_INSTANCE = new TypedJsonJacksonCodec(String.class, RouteDefinition.class);
|
||||||
public static final String KEY_ROUTES = "ROUTES:";
|
|
||||||
private final RedissonClient redissonClient;
|
private final RedissonClient redissonClient;
|
||||||
|
|
||||||
public RedisRouteDefinitionRepository(RedissonClient redissonClient)
|
public RedisRouteDefinitionRepository(RedissonClient redissonClient)
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import cn.hutool.json.JSONUtil;
|
|||||||
import com.ruoyi.gateway.exception.*;
|
import com.ruoyi.gateway.exception.*;
|
||||||
import com.ruoyi.gateway.ratelimit.CustomerRedisRateLimiter;
|
import com.ruoyi.gateway.ratelimit.CustomerRedisRateLimiter;
|
||||||
import com.ruoyi.gateway.utils.GatewayUtils;
|
import com.ruoyi.gateway.utils.GatewayUtils;
|
||||||
import com.ruoyi.gateway.utils.beans.IscRule;
|
import com.ruoyi.isc.common.utils.beans.IscRule;
|
||||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||||
import org.springframework.cloud.gateway.route.Route;
|
import org.springframework.cloud.gateway.route.Route;
|
||||||
@ -37,6 +37,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import static com.ruoyi.gateway.filter.CustomerGlobalFilter.AccessKey.AccessKeyType;
|
import static com.ruoyi.gateway.filter.CustomerGlobalFilter.AccessKey.AccessKeyType;
|
||||||
import static com.ruoyi.gateway.filter.CustomerGlobalFilter.AccessKey.AccessKeyType.*;
|
import static com.ruoyi.gateway.filter.CustomerGlobalFilter.AccessKey.AccessKeyType.*;
|
||||||
|
import static com.ruoyi.isc.common.constant.IscGatewayContants.*;
|
||||||
import static org.springframework.util.CollectionUtils.unmodifiableMultiValueMap;
|
import static org.springframework.util.CollectionUtils.unmodifiableMultiValueMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,7 +58,6 @@ public class CustomerGlobalFilter implements GlobalFilter, Ordered {
|
|||||||
this.rateLimiter = rateLimiter;
|
this.rateLimiter = rateLimiter;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String ACCESS_KEY_NAME_DEFAULT = "ak";
|
|
||||||
private static final TimeUnit[] TIME_UNITS = {TimeUnit.SECONDS, TimeUnit.MINUTES, TimeUnit.HOURS, TimeUnit.DAYS};
|
private static final TimeUnit[] TIME_UNITS = {TimeUnit.SECONDS, TimeUnit.MINUTES, TimeUnit.HOURS, TimeUnit.DAYS};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -67,7 +67,7 @@ public class CustomerGlobalFilter implements GlobalFilter, Ordered {
|
|||||||
final ServerHttpRequest request = exchange.getRequest();
|
final ServerHttpRequest request = exchange.getRequest();
|
||||||
//ak 是否存在
|
//ak 是否存在
|
||||||
final HttpMethod httpMethod = request.getMethod();
|
final HttpMethod httpMethod = request.getMethod();
|
||||||
AccessKey accessKey = new AccessKey(String.valueOf(metadata.getOrDefault(GatewayUtils.CONFIG_ACCESS_KEY_NAME_KEY,
|
AccessKey accessKey = new AccessKey(String.valueOf(metadata.getOrDefault(CONFIG_ACCESS_KEY_NAME_KEY,
|
||||||
ACCESS_KEY_NAME_DEFAULT)));
|
ACCESS_KEY_NAME_DEFAULT)));
|
||||||
accessKey.set(GatewayUtils.getValue(null, () -> request.getHeaders().get(accessKey.name)), HEADER);
|
accessKey.set(GatewayUtils.getValue(null, () -> request.getHeaders().get(accessKey.name)), HEADER);
|
||||||
MultiValueMap<String, String> queryParams = request.getQueryParams().containsKey(accessKey.name) ?
|
MultiValueMap<String, String> queryParams = request.getQueryParams().containsKey(accessKey.name) ?
|
||||||
@ -305,7 +305,7 @@ public class CustomerGlobalFilter implements GlobalFilter, Ordered {
|
|||||||
* @param <U> 参数类型
|
* @param <U> 参数类型
|
||||||
*/
|
*/
|
||||||
private <U> void handleHiddenParams(Route route, U result, BiConsumer<Map.Entry<String, Object>, U> mapper) {
|
private <U> void handleHiddenParams(Route route, U result, BiConsumer<Map.Entry<String, Object>, U> mapper) {
|
||||||
final Object obj = route.getMetadata().get(GatewayUtils.CONFIG_ADD_PARAM_KEY);
|
final Object obj = route.getMetadata().get(CONFIG_ADD_PARAM_KEY);
|
||||||
if (Objects.isNull(obj)) {
|
if (Objects.isNull(obj)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.ruoyi.gateway.ratelimit;
|
|||||||
|
|
||||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.ruoyi.gateway.utils.GatewayUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.cloud.gateway.filter.ratelimit.RedisRateLimiter;
|
import org.springframework.cloud.gateway.filter.ratelimit.RedisRateLimiter;
|
||||||
import org.springframework.cloud.gateway.support.ConfigurationService;
|
import org.springframework.cloud.gateway.support.ConfigurationService;
|
||||||
@ -26,12 +27,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class CustomerRedisRateLimiter extends RedisRateLimiter {
|
public class CustomerRedisRateLimiter extends RedisRateLimiter {
|
||||||
|
|
||||||
private ReactiveStringRedisTemplate redisTemplate;
|
private final ReactiveStringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
private RedisScript<List<Long>> script;
|
private final RedisScript<List<Long>> script;
|
||||||
private RedisScript<Long> timeRedisScript;
|
private final RedisScript<Long> timeRedisScript;
|
||||||
|
|
||||||
private AtomicBoolean initialized = new AtomicBoolean(false);
|
private final AtomicBoolean initialized = new AtomicBoolean(false);
|
||||||
|
|
||||||
public CustomerRedisRateLimiter(ReactiveStringRedisTemplate redisTemplate, RedisScript<List<Long>> script,
|
public CustomerRedisRateLimiter(ReactiveStringRedisTemplate redisTemplate, RedisScript<List<Long>> script,
|
||||||
ConfigurationService configurationService, DefaultRedisScript<Long> timeRedisScript) {
|
ConfigurationService configurationService, DefaultRedisScript<Long> timeRedisScript) {
|
||||||
@ -44,7 +45,7 @@ public class CustomerRedisRateLimiter extends RedisRateLimiter {
|
|||||||
|
|
||||||
public Mono<Response> isAllowed(String routeId, String ak, Long replenishRate, TimeUnit timeUnit) {
|
public Mono<Response> isAllowed(String routeId, String ak, Long replenishRate, TimeUnit timeUnit) {
|
||||||
Config routeConfig = new Config().setReplenishRate(replenishRate.intValue());
|
Config routeConfig = new Config().setReplenishRate(replenishRate.intValue());
|
||||||
String id = ak + ':' + routeId;
|
String id = GatewayUtils.getRouteKey(ak, routeId);
|
||||||
int time = 60;
|
int time = 60;
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
List<String> keys;
|
List<String> keys;
|
||||||
|
|||||||
@ -3,9 +3,8 @@ package com.ruoyi.gateway.utils;
|
|||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import com.ruoyi.gateway.utils.beans.IscRule;
|
|
||||||
import com.ruoyi.gateway.utils.caching.CachingRule;
|
import com.ruoyi.gateway.utils.caching.CachingRule;
|
||||||
import org.redisson.api.DeletedObjectListener;
|
import com.ruoyi.isc.common.utils.beans.IscRule;
|
||||||
import org.redisson.api.RMap;
|
import org.redisson.api.RMap;
|
||||||
import org.redisson.api.RedissonClient;
|
import org.redisson.api.RedissonClient;
|
||||||
import org.redisson.client.codec.Codec;
|
import org.redisson.client.codec.Codec;
|
||||||
@ -31,20 +30,14 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import static com.ruoyi.isc.common.constant.IscGatewayContants.RULE_CODES_INSTANCE;
|
||||||
|
import static com.ruoyi.isc.common.constant.IscRedisKeys.KEY_RULES;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Wenchao Gong
|
* @author Wenchao Gong
|
||||||
* @date 2021-10-15
|
* @date 2021-10-15
|
||||||
*/
|
*/
|
||||||
public class GatewayUtils {
|
public class GatewayUtils extends com.ruoyi.isc.common.utils.GatewayUtils {
|
||||||
|
|
||||||
public static final String CONFIG_ACCESS_KEY_NAME_KEY = "accessKeyName";
|
|
||||||
public static final String CONFIG_ADD_PARAM_KEY = "addParam";
|
|
||||||
/**
|
|
||||||
* Gateway 服务对应AK规则
|
|
||||||
*/
|
|
||||||
public static final String KEY_RULES = "RULES:";
|
|
||||||
|
|
||||||
public static final Codec RULE_CODES_INSTANCE = new TypedJsonJacksonCodec(String.class, IscRule.class);
|
|
||||||
private static RedissonClient client = SpringUtil.getBean(RedissonClient.class);
|
private static RedissonClient client = SpringUtil.getBean(RedissonClient.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -166,7 +159,7 @@ public class GatewayUtils {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static IscRule getRule(String ak, String routeId) {
|
public static IscRule getRule(String ak, String routeId) {
|
||||||
String key = ak + ':' + routeId;
|
String key = getRouteKey(ak, routeId);
|
||||||
return CachingRule.getRule(key, GatewayUtils::getRedisRule);
|
return CachingRule.getRule(key, GatewayUtils::getRedisRule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package com.ruoyi.gateway.utils.caching;
|
package com.ruoyi.gateway.utils.caching;
|
||||||
|
|
||||||
import com.ruoyi.gateway.utils.beans.IscRule;
|
import com.ruoyi.isc.common.utils.beans.IscRule;
|
||||||
import org.springframework.cache.Cache;
|
import org.springframework.cache.Cache;
|
||||||
import org.springframework.cache.concurrent.ConcurrentMapCache;
|
import org.springframework.cache.concurrent.ConcurrentMapCache;
|
||||||
|
|
||||||
|
|||||||
33
ruoyi-isc-parent/pom.xml
Normal file
33
ruoyi-isc-parent/pom.xml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>ruoyi-vue-plus</artifactId>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>ruoyi-isc-parent</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<modules>
|
||||||
|
<module>ruoyi-isc-common</module>
|
||||||
|
<module>ruoyi-isc</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-isc-common</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-isc</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
</project>
|
||||||
30
ruoyi-isc-parent/ruoyi-isc-common/pom.xml
Normal file
30
ruoyi-isc-parent/ruoyi-isc-common/pom.xml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>ruoyi-isc-parent</artifactId>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>ruoyi-isc-common</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-annotations</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.redisson</groupId>
|
||||||
|
<artifactId>redisson</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
package com.ruoyi.isc.common.constant;
|
||||||
|
|
||||||
|
import com.ruoyi.isc.common.utils.beans.IscRule;
|
||||||
|
import org.redisson.client.codec.Codec;
|
||||||
|
import org.redisson.codec.TypedJsonJacksonCodec;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Isc Gateway 公共常量
|
||||||
|
* @author Wenchao Gong
|
||||||
|
* @date 2021-10-30
|
||||||
|
*/
|
||||||
|
public interface IscGatewayContants {
|
||||||
|
|
||||||
|
/** AccessKey 默认名称 */
|
||||||
|
String ACCESS_KEY_NAME_DEFAULT = "ak";
|
||||||
|
|
||||||
|
/** 路由刷新通知主题 */
|
||||||
|
String TOPIC_GATEWAY_REFRESH_ROUTE = "TOPIC_GATEWAY_REFRESH_ROUTE";
|
||||||
|
|
||||||
|
/** 规则刷新通知主题 */
|
||||||
|
String TOPIC_GATEWAY_RULE = "TOPIC_GATEWAY_RULE";
|
||||||
|
|
||||||
|
/** AccessKeyName 路由配置名称 */
|
||||||
|
String CONFIG_ACCESS_KEY_NAME_KEY = "accessKeyName";
|
||||||
|
|
||||||
|
/** 添加参数 路由配置名称 */
|
||||||
|
String CONFIG_ADD_PARAM_KEY = "addParam";
|
||||||
|
|
||||||
|
/** 规则编解码器 */
|
||||||
|
Codec RULE_CODES_INSTANCE = new TypedJsonJacksonCodec(String.class, IscRule.class);
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
package com.ruoyi.isc.common.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redis Keys
|
||||||
|
* @author Wenchao Gong
|
||||||
|
* @date 2021-10-30
|
||||||
|
*/
|
||||||
|
public interface IscRedisKeys {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gateway 路由信息Redis Key
|
||||||
|
*/
|
||||||
|
String KEY_ROUTES = "ROUTES:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gateway 服务对应AK规则
|
||||||
|
*/
|
||||||
|
String KEY_RULES = "RULES:";
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package com.ruoyi.isc.common.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Wenchao Gong
|
||||||
|
* @date 2021-10-30
|
||||||
|
*/
|
||||||
|
public class GatewayUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 路由Key
|
||||||
|
*
|
||||||
|
* @param ak AccessKey
|
||||||
|
* @param serviceId 服务ID
|
||||||
|
* @return 路由Key
|
||||||
|
*/
|
||||||
|
public static String getRouteKey(String ak, String serviceId) {
|
||||||
|
return ak + ':' + serviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 路由Key
|
||||||
|
*
|
||||||
|
* @param ak AccessKey
|
||||||
|
* @param serviceId 服务ID
|
||||||
|
* @return 路由Key
|
||||||
|
*/
|
||||||
|
public static String getRouteKey(String ak, Long serviceId) {
|
||||||
|
return getRouteKey(ak, String.valueOf(serviceId));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package com.ruoyi.gateway.utils.beans;
|
package com.ruoyi.isc.common.utils.beans;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package com.ruoyi.gateway.utils.beans;
|
package com.ruoyi.isc.common.utils.beans;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -3,7 +3,7 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>ruoyi-vue-plus</artifactId>
|
<artifactId>ruoyi-isc-parent</artifactId>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<version>3.1.0</version>
|
<version>3.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
@ -12,6 +12,10 @@
|
|||||||
<artifactId>ruoyi-isc</artifactId>
|
<artifactId>ruoyi-isc</artifactId>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-isc-common</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-system</artifactId>
|
<artifactId>ruoyi-system</artifactId>
|
||||||
@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
|||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.ruoyi.common.constant.Constants;
|
||||||
import com.ruoyi.common.constant.IscConstants;
|
import com.ruoyi.common.constant.IscConstants;
|
||||||
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
|
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
|
||||||
import com.ruoyi.common.core.page.PagePlus;
|
import com.ruoyi.common.core.page.PagePlus;
|
||||||
@ -149,7 +150,7 @@ public class IscAppServiceApplyServiceImpl extends ServicePlusImpl<IscAppService
|
|||||||
{
|
{
|
||||||
IscAppServiceApply apply = getOne(Wrappers.<IscAppServiceApply>lambdaQuery()
|
IscAppServiceApply apply = getOne(Wrappers.<IscAppServiceApply>lambdaQuery()
|
||||||
.eq(IscAppServiceApply::getApplyId, id)
|
.eq(IscAppServiceApply::getApplyId, id)
|
||||||
.eq(IscAppServiceApply::getStatus, IscConstants.AUDIT_WAIT), false);
|
.eq(IscAppServiceApply::getStatus, Constants.AUDIT_WAIT), false);
|
||||||
if(Objects.isNull(apply)) {
|
if(Objects.isNull(apply)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -160,7 +161,7 @@ public class IscAppServiceApplyServiceImpl extends ServicePlusImpl<IscAppService
|
|||||||
|
|
||||||
IscAppService updateData = null;
|
IscAppService updateData = null;
|
||||||
IscService service = null;
|
IscService service = null;
|
||||||
if(IscConstants.AUDIT_PASS.equals(bo.getStatus())) {
|
if(Constants.AUDIT_PASS.equals(bo.getStatus())) {
|
||||||
service = serviceService.getById(appService.getServiceId());
|
service = serviceService.getById(appService.getServiceId());
|
||||||
Assert.notNull(service, () -> new ServiceException("服务信息不存在"));
|
Assert.notNull(service, () -> new ServiceException("服务信息不存在"));
|
||||||
updateData = genAuditPassData(apply, appService, service, bo.getStatus());
|
updateData = genAuditPassData(apply, appService, service, bo.getStatus());
|
||||||
@ -201,7 +202,7 @@ public class IscAppServiceApplyServiceImpl extends ServicePlusImpl<IscAppService
|
|||||||
break;
|
break;
|
||||||
case IscConstants.APPLY_TYPE_MODIFY:
|
case IscConstants.APPLY_TYPE_MODIFY:
|
||||||
//如果 应用服务 状态不为通过 则修改状态(如果是通过:续期不能影响使用)
|
//如果 应用服务 状态不为通过 则修改状态(如果是通过:续期不能影响使用)
|
||||||
if(!IscConstants.AUDIT_PASS.equals(appService.getStatus())) {
|
if(!Constants.AUDIT_PASS.equals(appService.getStatus())) {
|
||||||
genServicePassInit(apply, appService, status, updateData, service);
|
genServicePassInit(apply, appService, status, updateData, service);
|
||||||
}
|
}
|
||||||
updateData.setQuotaDays(apply.getQuotaDays());
|
updateData.setQuotaDays(apply.getQuotaDays());
|
||||||
@ -251,7 +252,7 @@ public class IscAppServiceApplyServiceImpl extends ServicePlusImpl<IscAppService
|
|||||||
* @return 需要更新的信息
|
* @return 需要更新的信息
|
||||||
*/
|
*/
|
||||||
private IscAppService genAuditRejectData(IscAppService appService, IscAuditBo bo) {
|
private IscAppService genAuditRejectData(IscAppService appService, IscAuditBo bo) {
|
||||||
if(!IscConstants.AUDIT_PASS.equals(appService.getStatus())) {
|
if(!Constants.AUDIT_PASS.equals(appService.getStatus())) {
|
||||||
IscAppService updateData = new IscAppService().setAppServiceId(appService.getAppServiceId());
|
IscAppService updateData = new IscAppService().setAppServiceId(appService.getAppServiceId());
|
||||||
updateData.setStatus(bo.getStatus());
|
updateData.setStatus(bo.getStatus());
|
||||||
updateData.setAuditMind(bo.getRemark());
|
updateData.setAuditMind(bo.getRemark());
|
||||||
@ -7,6 +7,7 @@ import cn.hutool.core.lang.tree.Tree;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
||||||
|
import com.ruoyi.common.constant.Constants;
|
||||||
import com.ruoyi.common.constant.IscConstants;
|
import com.ruoyi.common.constant.IscConstants;
|
||||||
import com.ruoyi.common.constant.UserConstants;
|
import com.ruoyi.common.constant.UserConstants;
|
||||||
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
|
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
|
||||||
@ -17,6 +18,7 @@ import com.ruoyi.common.utils.DateUtils;
|
|||||||
import com.ruoyi.common.utils.PageUtils;
|
import com.ruoyi.common.utils.PageUtils;
|
||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.isc.common.utils.beans.IscRule;
|
||||||
import com.ruoyi.isc.domain.IscAppService;
|
import com.ruoyi.isc.domain.IscAppService;
|
||||||
import com.ruoyi.isc.domain.IscAppServiceApply;
|
import com.ruoyi.isc.domain.IscAppServiceApply;
|
||||||
import com.ruoyi.isc.domain.IscApplication;
|
import com.ruoyi.isc.domain.IscApplication;
|
||||||
@ -29,7 +31,6 @@ import com.ruoyi.isc.service.IIscAppServiceService;
|
|||||||
import com.ruoyi.isc.service.IIscApplicationService;
|
import com.ruoyi.isc.service.IIscApplicationService;
|
||||||
import com.ruoyi.isc.service.IIscServiceService;
|
import com.ruoyi.isc.service.IIscServiceService;
|
||||||
import com.ruoyi.isc.utils.RouteUtils;
|
import com.ruoyi.isc.utils.RouteUtils;
|
||||||
import com.ruoyi.isc.utils.beans.IscRule;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -120,7 +121,7 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl<IscAppServiceMappe
|
|||||||
{
|
{
|
||||||
IscAppService add = BeanUtil.toBean(bo, IscAppService.class);
|
IscAppService add = BeanUtil.toBean(bo, IscAppService.class);
|
||||||
validEntityBeforeSave(add);
|
validEntityBeforeSave(add);
|
||||||
add.setStatus(IscConstants.AUDIT_WAIT);
|
add.setStatus(Constants.AUDIT_WAIT);
|
||||||
add.setUserId(SecurityUtils.getUserId());
|
add.setUserId(SecurityUtils.getUserId());
|
||||||
boolean result = save(add);
|
boolean result = save(add);
|
||||||
addApplyRecord(bo, IscConstants.APPLY_TYPE_APPLY, add.getAppServiceId());
|
addApplyRecord(bo, IscConstants.APPLY_TYPE_APPLY, add.getAppServiceId());
|
||||||
@ -135,13 +136,13 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl<IscAppServiceMappe
|
|||||||
IscAppService update = new IscAppService().setAppServiceId(bo.getAppServiceId());
|
IscAppService update = new IscAppService().setAppServiceId(bo.getAppServiceId());
|
||||||
validEntityBeforeSave(update);
|
validEntityBeforeSave(update);
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
boolean changeStatus = !IscConstants.AUDIT_PASS.equals(appService.getStatus());
|
boolean changeStatus = !Constants.AUDIT_PASS.equals(appService.getStatus());
|
||||||
boolean changeRemark = !IscConstants.APPLY_TYPE_RENEWAL.equals(bo.getApplyType());
|
boolean changeRemark = !IscConstants.APPLY_TYPE_RENEWAL.equals(bo.getApplyType());
|
||||||
if (changeStatus || changeRemark)
|
if (changeStatus || changeRemark)
|
||||||
{
|
{
|
||||||
if (changeStatus)
|
if (changeStatus)
|
||||||
{
|
{
|
||||||
update.setStatus(IscConstants.AUDIT_WAIT);
|
update.setStatus(Constants.AUDIT_WAIT);
|
||||||
}
|
}
|
||||||
if (changeRemark)
|
if (changeRemark)
|
||||||
{
|
{
|
||||||
@ -166,7 +167,7 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl<IscAppServiceMappe
|
|||||||
if (Objects.nonNull(entity.getAppServiceId())) {
|
if (Objects.nonNull(entity.getAppServiceId())) {
|
||||||
long count = applyService.count(Wrappers.<IscAppServiceApply>lambdaQuery()
|
long count = applyService.count(Wrappers.<IscAppServiceApply>lambdaQuery()
|
||||||
.eq(IscAppServiceApply::getAppServiceId, entity.getAppServiceId())
|
.eq(IscAppServiceApply::getAppServiceId, entity.getAppServiceId())
|
||||||
.eq(IscAppServiceApply::getStatus, IscConstants.AUDIT_WAIT));
|
.eq(IscAppServiceApply::getStatus, Constants.AUDIT_WAIT));
|
||||||
Assert.isFalse(SqlHelper.retBool(count), () -> new ServiceException("有申请未审核, 不能再申请"));
|
Assert.isFalse(SqlHelper.retBool(count), () -> new ServiceException("有申请未审核, 不能再申请"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,7 +204,7 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl<IscAppServiceMappe
|
|||||||
{
|
{
|
||||||
List<IscAppService> list = list(Wrappers.<IscAppService>lambdaQuery()
|
List<IscAppService> list = list(Wrappers.<IscAppService>lambdaQuery()
|
||||||
.eq(IscAppService::getEnabled, UserConstants.NORMAL)
|
.eq(IscAppService::getEnabled, UserConstants.NORMAL)
|
||||||
.eq(IscAppService::getStatus, IscConstants.AUDIT_PASS)
|
.eq(IscAppService::getStatus, Constants.AUDIT_PASS)
|
||||||
.gt(IscAppService::getEndTime, DateUtils.getNowDate()));
|
.gt(IscAppService::getEndTime, DateUtils.getNowDate()));
|
||||||
if(CollectionUtil.isEmpty(list)) {
|
if(CollectionUtil.isEmpty(list)) {
|
||||||
return;
|
return;
|
||||||
@ -240,7 +241,7 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl<IscAppServiceMappe
|
|||||||
IscAppServiceApplyBo entity = new IscAppServiceApplyBo();
|
IscAppServiceApplyBo entity = new IscAppServiceApplyBo();
|
||||||
entity.setAppServiceId(appServiceId);
|
entity.setAppServiceId(appServiceId);
|
||||||
entity.setApplyType(applyType);
|
entity.setApplyType(applyType);
|
||||||
entity.setStatus(IscConstants.AUDIT_WAIT);
|
entity.setStatus(Constants.AUDIT_WAIT);
|
||||||
entity.setRemark(appService.getRemark());
|
entity.setRemark(appService.getRemark());
|
||||||
switch (applyType) {
|
switch (applyType) {
|
||||||
case IscConstants.APPLY_TYPE_APPLY:
|
case IscConstants.APPLY_TYPE_APPLY:
|
||||||
@ -9,6 +9,7 @@ import cn.hutool.core.map.MapUtil;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.ruoyi.common.constant.Constants;
|
||||||
import com.ruoyi.common.constant.IscConstants;
|
import com.ruoyi.common.constant.IscConstants;
|
||||||
import com.ruoyi.common.constant.UserConstants;
|
import com.ruoyi.common.constant.UserConstants;
|
||||||
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
|
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
|
||||||
@ -111,7 +112,7 @@ public class IscServiceServiceImpl extends ServicePlusImpl<IscServiceMapper, Isc
|
|||||||
validEntityBeforeSave(add);
|
validEntityBeforeSave(add);
|
||||||
add.setUserId(SecurityUtils.getUserId());
|
add.setUserId(SecurityUtils.getUserId());
|
||||||
add.setOnlineStatus(IscConstants.ONLINE_STATUS_ON);
|
add.setOnlineStatus(IscConstants.ONLINE_STATUS_ON);
|
||||||
add.setStatus(IscConstants.AUDIT_WAIT);
|
add.setStatus(Constants.AUDIT_WAIT);
|
||||||
return save(add);
|
return save(add);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +171,7 @@ public class IscServiceServiceImpl extends ServicePlusImpl<IscServiceMapper, Isc
|
|||||||
{
|
{
|
||||||
List<IscService> serviceList = list(Wrappers.<IscService>lambdaQuery()
|
List<IscService> serviceList = list(Wrappers.<IscService>lambdaQuery()
|
||||||
.select(IscService::getServiceId, IscService::getServiceName, IscService::getCateFullPath)
|
.select(IscService::getServiceId, IscService::getServiceName, IscService::getCateFullPath)
|
||||||
.eq(IscService::getStatus, IscConstants.AUDIT_PASS)
|
.eq(IscService::getStatus, Constants.AUDIT_PASS)
|
||||||
.eq(IscService::getEnabled, UserConstants.DICT_NORMAL)
|
.eq(IscService::getEnabled, UserConstants.DICT_NORMAL)
|
||||||
.orderByDesc(IscService::getUpdateTime));
|
.orderByDesc(IscService::getUpdateTime));
|
||||||
return cateService.genCateTree(cateService.selectCateList(), serviceList, exitsIds);
|
return cateService.genCateTree(cateService.selectCateList(), serviceList, exitsIds);
|
||||||
@ -181,13 +182,13 @@ public class IscServiceServiceImpl extends ServicePlusImpl<IscServiceMapper, Isc
|
|||||||
{
|
{
|
||||||
checkAuditBO(bo);
|
checkAuditBO(bo);
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
boolean pass = IscConstants.AUDIT_PASS.equals(bo.getStatus());
|
boolean pass = Constants.AUDIT_PASS.equals(bo.getStatus());
|
||||||
Collection<IscRouteDefinition> routes = pass ? ListUtil.list(false) : null;
|
Collection<IscRouteDefinition> routes = pass ? ListUtil.list(false) : null;
|
||||||
for (Long id : bo.getIds())
|
for (Long id : bo.getIds())
|
||||||
{
|
{
|
||||||
IscService service = getOne(Wrappers.<IscService>lambdaQuery()
|
IscService service = getOne(Wrappers.<IscService>lambdaQuery()
|
||||||
.eq(IscService::getServiceId, id)
|
.eq(IscService::getServiceId, id)
|
||||||
.eq(IscService::getStatus, IscConstants.AUDIT_WAIT), false);
|
.eq(IscService::getStatus, Constants.AUDIT_WAIT), false);
|
||||||
if(Objects.isNull(service)) {
|
if(Objects.isNull(service)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -209,9 +210,9 @@ public class IscServiceServiceImpl extends ServicePlusImpl<IscServiceMapper, Isc
|
|||||||
public void checkAuditBO(IscAuditBo bo)
|
public void checkAuditBO(IscAuditBo bo)
|
||||||
{
|
{
|
||||||
switch (bo.getStatus()) {
|
switch (bo.getStatus()) {
|
||||||
case IscConstants.AUDIT_PASS:
|
case Constants.AUDIT_PASS:
|
||||||
break;
|
break;
|
||||||
case IscConstants.AUDIT_REJECT:
|
case Constants.AUDIT_REJECT:
|
||||||
Assert.notBlank(bo.getRemark(), () -> new ServiceException("审核意见不能为空"));
|
Assert.notBlank(bo.getRemark(), () -> new ServiceException("审核意见不能为空"));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -224,7 +225,7 @@ public class IscServiceServiceImpl extends ServicePlusImpl<IscServiceMapper, Isc
|
|||||||
{
|
{
|
||||||
final List<IscService> serviceList = list(Wrappers.<IscService>lambdaQuery()
|
final List<IscService> serviceList = list(Wrappers.<IscService>lambdaQuery()
|
||||||
.select(IscService::getServiceId, IscService::getServiceAddr, IscService::getHiddenParams, IscService::getRequestMethod)
|
.select(IscService::getServiceId, IscService::getServiceAddr, IscService::getHiddenParams, IscService::getRequestMethod)
|
||||||
.eq(IscService::getStatus, IscConstants.AUDIT_PASS));
|
.eq(IscService::getStatus, Constants.AUDIT_PASS));
|
||||||
List<IscRouteDefinition> routes = new ArrayList<>();
|
List<IscRouteDefinition> routes = new ArrayList<>();
|
||||||
for (IscService service : serviceList)
|
for (IscService service : serviceList)
|
||||||
{
|
{
|
||||||
@ -2,13 +2,16 @@ package com.ruoyi.isc.utils;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.ruoyi.common.constant.IscConstants;
|
|
||||||
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||||
|
import com.ruoyi.isc.common.constant.IscRedisKeys;
|
||||||
|
import com.ruoyi.isc.common.utils.GatewayUtils;
|
||||||
|
import com.ruoyi.isc.common.utils.beans.IscRule;
|
||||||
|
import com.ruoyi.isc.common.utils.beans.TopicMsg;
|
||||||
|
import com.ruoyi.isc.common.utils.beans.TopicMsg.Type;
|
||||||
import com.ruoyi.isc.domain.IscAppService;
|
import com.ruoyi.isc.domain.IscAppService;
|
||||||
import com.ruoyi.isc.domain.IscService;
|
import com.ruoyi.isc.domain.IscService;
|
||||||
import com.ruoyi.isc.utils.beans.*;
|
import com.ruoyi.isc.utils.beans.*;
|
||||||
import com.ruoyi.isc.utils.beans.TopicMsg.Type;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.redisson.api.RMap;
|
import org.redisson.api.RMap;
|
||||||
import org.redisson.api.RTopic;
|
import org.redisson.api.RTopic;
|
||||||
@ -23,6 +26,8 @@ import java.util.function.Consumer;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static com.ruoyi.isc.common.constant.IscGatewayContants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Wenchao Gong
|
* @author Wenchao Gong
|
||||||
* @date 2021/9/10 14:46
|
* @date 2021/9/10 14:46
|
||||||
@ -31,15 +36,10 @@ import java.util.stream.Collectors;
|
|||||||
public class RouteUtils {
|
public class RouteUtils {
|
||||||
|
|
||||||
public static final Codec ROUTE_CODES_INSTANCE = new TypedJsonJacksonCodec(String.class, IscRouteDefinition.class);
|
public static final Codec ROUTE_CODES_INSTANCE = new TypedJsonJacksonCodec(String.class, IscRouteDefinition.class);
|
||||||
public static final Codec RULE_CODES_INSTANCE = new TypedJsonJacksonCodec(String.class, IscRule.class);
|
|
||||||
public static final Codec TOPIC_MSG_CODES_INSTANCE = new TypedJsonJacksonCodec(String.class, TopicMsg.class);
|
|
||||||
public static final String TOPIC_GATEWAY_REFRESH_ROUTE = "TOPIC_GATEWAY_REFRESH_ROUTE";
|
|
||||||
public static final String TOPIC_GATEWAY_RULE = "TOPIC_GATEWAY_RULE";
|
|
||||||
/**
|
/**
|
||||||
* Gateway 虚拟路径前缀
|
* Gateway 虚拟路径前缀
|
||||||
*/
|
*/
|
||||||
public static final String PATH_PREFIX = "/proxy";
|
public static final String PATH_PREFIX = "/proxy";
|
||||||
public static final String ACCESS_KEY_NAME = "ak";
|
|
||||||
private static final RedissonClient CLIENT = SpringUtils.getBean(RedissonClient.class);
|
private static final RedissonClient CLIENT = SpringUtils.getBean(RedissonClient.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,7 +88,7 @@ public class RouteUtils {
|
|||||||
* @param consumer 自定义处理
|
* @param consumer 自定义处理
|
||||||
*/
|
*/
|
||||||
public static <T> void publish(String channelKey, T msg, Consumer<T> consumer) {
|
public static <T> void publish(String channelKey, T msg, Consumer<T> consumer) {
|
||||||
RTopic topic = CLIENT.getTopic(channelKey, TOPIC_MSG_CODES_INSTANCE);
|
RTopic topic = CLIENT.getTopic(channelKey);
|
||||||
topic.publish(msg);
|
topic.publish(msg);
|
||||||
consumer.accept(msg);
|
consumer.accept(msg);
|
||||||
}
|
}
|
||||||
@ -119,10 +119,10 @@ public class RouteUtils {
|
|||||||
{
|
{
|
||||||
Map<String, IscRouteDefinition> routeMap = routes.stream().collect(Collectors.toMap(IscRouteDefinition::getId,
|
Map<String, IscRouteDefinition> routeMap = routes.stream().collect(Collectors.toMap(IscRouteDefinition::getId,
|
||||||
Function.identity(), (o1, o2) -> o2));
|
Function.identity(), (o1, o2) -> o2));
|
||||||
final RMap<String, IscRouteDefinition> map = CLIENT.getMap(IscConstants.KEY_ROUTES, ROUTE_CODES_INSTANCE);
|
final RMap<String, IscRouteDefinition> map = CLIENT.getMap(IscRedisKeys.KEY_ROUTES, ROUTE_CODES_INSTANCE);
|
||||||
map.clear();
|
map.clear();
|
||||||
map.putAll(routeMap);
|
map.putAll(routeMap);
|
||||||
sendRefreshRouteToGateway(null, Type.REFRESH,
|
sendRefreshRouteToGateway(null, TopicMsg.Type.REFRESH,
|
||||||
(msg) -> log.info("路由刷新完成,通知网关刷新路由![{}]", msg.getMsg()));
|
(msg) -> log.info("路由刷新完成,通知网关刷新路由![{}]", msg.getMsg()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -149,7 +149,7 @@ public class RouteUtils {
|
|||||||
if(CollectionUtil.isEmpty(routes)) {
|
if(CollectionUtil.isEmpty(routes)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final RMap<String, IscRouteDefinition> map = CLIENT.getMap(IscConstants.KEY_ROUTES, ROUTE_CODES_INSTANCE);
|
final RMap<String, IscRouteDefinition> map = CLIENT.getMap(IscRedisKeys.KEY_ROUTES, ROUTE_CODES_INSTANCE);
|
||||||
Map<String, IscRouteDefinition> collect = routes.stream().collect(Collectors.toMap(IscRouteDefinition::getId, Function.identity()));
|
Map<String, IscRouteDefinition> collect = routes.stream().collect(Collectors.toMap(IscRouteDefinition::getId, Function.identity()));
|
||||||
map.putAll(collect);
|
map.putAll(collect);
|
||||||
final String id = String.join(",", collect.keySet());
|
final String id = String.join(",", collect.keySet());
|
||||||
@ -170,7 +170,7 @@ public class RouteUtils {
|
|||||||
*/
|
*/
|
||||||
public static boolean deleteRoute(Collection<String> routeIds)
|
public static boolean deleteRoute(Collection<String> routeIds)
|
||||||
{
|
{
|
||||||
final RMap<String, IscRouteDefinition> map = CLIENT.getMap(IscConstants.KEY_ROUTES, ROUTE_CODES_INSTANCE);
|
final RMap<String, IscRouteDefinition> map = CLIENT.getMap(IscRedisKeys.KEY_ROUTES, ROUTE_CODES_INSTANCE);
|
||||||
final String[] ids = routeIds.toArray(new String[0]);
|
final String[] ids = routeIds.toArray(new String[0]);
|
||||||
map.fastRemove(ids);
|
map.fastRemove(ids);
|
||||||
final String id = String.join(",", routeIds);
|
final String id = String.join(",", routeIds);
|
||||||
@ -229,8 +229,8 @@ public class RouteUtils {
|
|||||||
|
|
||||||
//其他信息
|
//其他信息
|
||||||
Map<String, Object> metadata = route.getMetadata();
|
Map<String, Object> metadata = route.getMetadata();
|
||||||
metadata.put("accessKeyName", ACCESS_KEY_NAME);
|
metadata.put(CONFIG_ACCESS_KEY_NAME_KEY, ACCESS_KEY_NAME_DEFAULT);
|
||||||
metadata.put("addParam", service.getHiddenParams());
|
metadata.put(CONFIG_ADD_PARAM_KEY, service.getHiddenParams());
|
||||||
return route;
|
return route;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +244,7 @@ public class RouteUtils {
|
|||||||
public static IscRule generateRule(IscAppService appService, String accessKey)
|
public static IscRule generateRule(IscAppService appService, String accessKey)
|
||||||
{
|
{
|
||||||
IscRule rule = new IscRule();
|
IscRule rule = new IscRule();
|
||||||
rule.setId(accessKey + ':' + appService.getServiceId());
|
rule.setId(GatewayUtils.getRouteKey(accessKey, appService.getServiceId()));
|
||||||
rule.setExpire(appService.getEndTime());
|
rule.setExpire(appService.getEndTime());
|
||||||
rule.setDaysLimit(appService.getQuotaDays());
|
rule.setDaysLimit(appService.getQuotaDays());
|
||||||
rule.setHoursLimit(appService.getQuotaHours());
|
rule.setHoursLimit(appService.getQuotaHours());
|
||||||
@ -262,7 +262,7 @@ public class RouteUtils {
|
|||||||
public static boolean refreshRules(List<IscRule> rules)
|
public static boolean refreshRules(List<IscRule> rules)
|
||||||
{
|
{
|
||||||
Map<String, IscRule> ruleMap = rules.stream().collect(Collectors.toMap(IscRule::getId, Function.identity(), (o1, o2) -> o2));
|
Map<String, IscRule> ruleMap = rules.stream().collect(Collectors.toMap(IscRule::getId, Function.identity(), (o1, o2) -> o2));
|
||||||
final RMap<String, IscRule> map = CLIENT.getMap(IscConstants.KEY_RULES, RULE_CODES_INSTANCE);
|
final RMap<String, IscRule> map = CLIENT.getMap(IscRedisKeys.KEY_RULES, RULE_CODES_INSTANCE);
|
||||||
map.clear();
|
map.clear();
|
||||||
map.putAll(ruleMap);
|
map.putAll(ruleMap);
|
||||||
final String id = String.join(",", ruleMap.keySet());
|
final String id = String.join(",", ruleMap.keySet());
|
||||||
@ -290,7 +290,7 @@ public class RouteUtils {
|
|||||||
*/
|
*/
|
||||||
public static boolean saveRule(IscRule rule, Consumer<TopicMsg> consumer)
|
public static boolean saveRule(IscRule rule, Consumer<TopicMsg> consumer)
|
||||||
{
|
{
|
||||||
final RMap<String, IscRule> map = CLIENT.getMap(IscConstants.KEY_RULES, RULE_CODES_INSTANCE);
|
final RMap<String, IscRule> map = CLIENT.getMap(IscRedisKeys.KEY_RULES, RULE_CODES_INSTANCE);
|
||||||
map.put(rule.getId(), rule);
|
map.put(rule.getId(), rule);
|
||||||
Type type = Type.UPDATE;
|
Type type = Type.UPDATE;
|
||||||
if(Objects.isNull(consumer)) {
|
if(Objects.isNull(consumer)) {
|
||||||
@ -309,7 +309,7 @@ public class RouteUtils {
|
|||||||
*/
|
*/
|
||||||
public static boolean deleteRule(String ruleId)
|
public static boolean deleteRule(String ruleId)
|
||||||
{
|
{
|
||||||
final RMap<String, IscRule> map = CLIENT.getMap(IscConstants.KEY_RULES, RULE_CODES_INSTANCE);
|
final RMap<String, IscRule> map = CLIENT.getMap(IscRedisKeys.KEY_RULES, RULE_CODES_INSTANCE);
|
||||||
map.remove(ruleId);
|
map.remove(ruleId);
|
||||||
sendRuleNoticeToGateway(ruleId, Type.DELETE,
|
sendRuleNoticeToGateway(ruleId, Type.DELETE,
|
||||||
(msg) -> log.info("删除[{}]规则[{}]完成,通知网关刷新规则![{}]", msg.getType(), msg.getId(), msg.getMsg()));
|
(msg) -> log.info("删除[{}]规则[{}]完成,通知网关刷新规则![{}]", msg.getType(), msg.getId(), msg.getMsg()));
|
||||||
@ -1,26 +0,0 @@
|
|||||||
package com.ruoyi.isc.utils.beans;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 网关 规则信息(服务对应AK处理规则)
|
|
||||||
* @author Wechao Gong
|
|
||||||
* @date 2021-10-16
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class IscRule implements Serializable
|
|
||||||
{
|
|
||||||
@JsonIgnore
|
|
||||||
private String id;
|
|
||||||
private Date expire;
|
|
||||||
private Long daysLimit;
|
|
||||||
private Long hoursLimit;
|
|
||||||
private Long minutesLimit;
|
|
||||||
private Long secondsLimit;
|
|
||||||
}
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
package com.ruoyi.isc.utils.beans;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Wenchao Gong
|
|
||||||
* @date 2021-10-26
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class TopicMsg implements Serializable {
|
|
||||||
/** 消息ID */
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
/** 消息内容 */
|
|
||||||
private String msg;
|
|
||||||
|
|
||||||
/** 消息类型 */
|
|
||||||
private Type type;
|
|
||||||
|
|
||||||
/** 消息类型枚举 */
|
|
||||||
public static enum Type {
|
|
||||||
/** 新增单条记录 */
|
|
||||||
ADD,
|
|
||||||
/** 更新单条记录 */
|
|
||||||
UPDATE,
|
|
||||||
/** 删除单条记录 */
|
|
||||||
DELETE,
|
|
||||||
/** 刷新所有 */
|
|
||||||
REFRESH
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user