You've already forked DataMate
Fix the ratio task bug (#194)
* fix: add feign client configurations * fix: add nacos configurations * fix: add python to gateway * fix: Fix the ratio task bug
This commit is contained in:
@@ -4,7 +4,9 @@ import org.springframework.boot.SpringApplication;
|
|||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.gateway.route.RouteLocator;
|
import org.springframework.cloud.gateway.route.RouteLocator;
|
||||||
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
|
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API Gateway & Auth Service Application
|
* API Gateway & Auth Service Application
|
||||||
@@ -12,6 +14,8 @@ import org.springframework.context.annotation.Bean;
|
|||||||
* 提供路由、鉴权、限流等功能
|
* 提供路由、鉴权、限流等功能
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@ComponentScan(basePackages = {"com.datamate.gateway", "com.terrabase"})
|
||||||
|
@EnableFeignClients(basePackages = {"com.terrabase"})
|
||||||
public class ApiGatewayApplication {
|
public class ApiGatewayApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package com.datamate.gateway.filter;
|
package com.datamate.gateway.filter;
|
||||||
|
|
||||||
|
import com.terrabase.enterprise.api.UserManagementService;
|
||||||
import com.terrabase.enterprise.api.dto.LoginUserDto;
|
import com.terrabase.enterprise.api.dto.LoginUserDto;
|
||||||
import com.terrabase.enterprise.api.sdk.TerrabaseSDK;
|
|
||||||
import com.terrabase.enterprise.api.sdk.TerrabaseSDKConfig;
|
|
||||||
import jakarta.annotation.PostConstruct;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
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;
|
||||||
@@ -15,25 +14,15 @@ import reactor.core.publisher.Mono;
|
|||||||
/**
|
/**
|
||||||
* 用户信息过滤器
|
* 用户信息过滤器
|
||||||
*
|
*
|
||||||
* @since 2025/12/22
|
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class UserContextFilter implements GlobalFilter {
|
public class UserContextFilter implements GlobalFilter {
|
||||||
@Value("${terrabase.jar.path:/opt/terrabase}")
|
|
||||||
private String jarPath;
|
|
||||||
|
|
||||||
@Value("${commercial.switch:false}")
|
@Value("${commercial.switch:false}")
|
||||||
private boolean isCommercial;
|
private boolean isCommercial;
|
||||||
|
|
||||||
private TerrabaseSDK terrabaseSDK;
|
@Autowired
|
||||||
|
private UserManagementService userManagementService;
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
TerrabaseSDKConfig sdkConfig = TerrabaseSDKConfig.createDefault();
|
|
||||||
sdkConfig.setJarPath(jarPath);
|
|
||||||
terrabaseSDK = TerrabaseSDK.init(sdkConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
@@ -41,7 +30,7 @@ public class UserContextFilter implements GlobalFilter {
|
|||||||
return chain.filter(exchange);
|
return chain.filter(exchange);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
LoginUserDto loginUserDto = terrabaseSDK.userManagement().getCurrentUserInfo().getData().getFirst();
|
LoginUserDto loginUserDto = userManagementService.getCurrentUserInfo().getData().getFirst();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("get current user info error", e);
|
log.error("get current user info error", e);
|
||||||
return chain.filter(exchange);
|
return chain.filter(exchange);
|
||||||
|
|||||||
22
backend/api-gateway/src/main/resources/application.yml
Normal file
22
backend/api-gateway/src/main/resources/application.yml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
spring:
|
||||||
|
main:
|
||||||
|
allow-circular-references: true
|
||||||
|
application:
|
||||||
|
name: datamate-gateway # 必须设置应用名
|
||||||
|
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
fail-fast: false
|
||||||
|
# 显式设置端口
|
||||||
|
port: ${server.port:30000} # 与服务端口一致
|
||||||
|
server-addr: ${NACOS_ADDR:https://consulservice:18302}
|
||||||
|
username: consul
|
||||||
|
password:
|
||||||
|
ip: ${spring.application.name}
|
||||||
|
secure: true
|
||||||
|
cluster-name: DEFAULT
|
||||||
|
|
||||||
|
# 服务器端口配置
|
||||||
|
server:
|
||||||
|
port: 8080 # 必须有这个配置
|
||||||
@@ -294,7 +294,7 @@ class RatioTaskService:
|
|||||||
for tag in all_tags:
|
for tag in all_tags:
|
||||||
if conditions.label.label and tag.get("label") != conditions.label.label:
|
if conditions.label.label and tag.get("label") != conditions.label.label:
|
||||||
continue
|
continue
|
||||||
if conditions.label.value is not None:
|
if conditions.label.value is None:
|
||||||
return True
|
return True
|
||||||
if tag.get("value") == conditions.label.value:
|
if tag.get("value") == conditions.label.value:
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ RUN cd /opt/gateway/api-gateway && \
|
|||||||
FROM eclipse-temurin:21-jdk
|
FROM eclipse-temurin:21-jdk
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y vim wget curl dos2unix && \
|
apt-get install -y vim wget curl python3 python3-pip python-is-python3 dos2unix && \
|
||||||
apt-get clean && \
|
apt-get clean && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user