Skip to content

Commit 90c2b42

Browse files
committed
feature: add gateway
1 parent 8fc4455 commit 90c2b42

File tree

24 files changed

+288
-248
lines changed

24 files changed

+288
-248
lines changed

backend/api-gateway/pom.xml

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,38 @@
1313
</parent>
1414

1515
<artifactId>api-gateway</artifactId>
16+
<packaging>jar</packaging>
1617
<name>API Gateway</name>
1718
<description>API网关服务</description>
1819

20+
<properties>
21+
<spring-boot.version>3.5.6</spring-boot.version>
22+
<spring-cloud.version>2025.0.0</spring-cloud.version>
23+
</properties>
24+
1925
<dependencies>
2026
<dependency>
2127
<groupId>org.springframework.cloud</groupId>
2228
<artifactId>spring-cloud-starter-gateway</artifactId>
2329
</dependency>
2430
<dependency>
25-
<groupId>org.springframework.boot</groupId>
26-
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
27-
</dependency>
28-
<dependency>
29-
<groupId>org.springframework.boot</groupId>
30-
<artifactId>spring-boot-starter-security</artifactId>
31-
</dependency>
32-
<dependency>
33-
<groupId>org.springframework.boot</groupId>
34-
<artifactId>spring-boot-starter-actuator</artifactId>
35-
</dependency>
36-
<dependency>
37-
<groupId>org.springframework.cloud</groupId>
38-
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
31+
<groupId>com.terrabase</groupId>
32+
<artifactId>enterprise-impl-commercial</artifactId>
33+
<version>1.0.0</version>
34+
<exclusions>
35+
<exclusion>
36+
<artifactId>spring-web</artifactId>
37+
<groupId>org.springframework</groupId>
38+
</exclusion>
39+
<exclusion>
40+
<artifactId>spring-boot-starter-web</artifactId>
41+
<groupId>org.springframework.boot</groupId>
42+
</exclusion>
43+
</exclusions>
3944
</dependency>
4045
<dependency>
41-
<groupId>org.springframework.boot</groupId>
42-
<artifactId>spring-boot-starter-test</artifactId>
43-
<scope>test</scope>
46+
<groupId>com.alibaba.fastjson2</groupId>
47+
<artifactId>fastjson2</artifactId>
4448
</dependency>
4549
</dependencies>
4650

@@ -49,6 +53,18 @@
4953
<plugin>
5054
<groupId>org.springframework.boot</groupId>
5155
<artifactId>spring-boot-maven-plugin</artifactId>
56+
<version>${spring-boot.version}</version>
57+
<configuration>
58+
<finalName>gateway</finalName>
59+
<mainClass>com.datamate.gateway.ApiGatewayApplication</mainClass>
60+
</configuration>
61+
<executions>
62+
<execution>
63+
<goals>
64+
<goal>repackage</goal>
65+
</goals>
66+
</execution>
67+
</executions>
5268
</plugin>
5369
</plugins>
5470
</build>

backend/api-gateway/src/main/java/com/datamate/gateway/ApiGatewayApplication.java

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@
55
import org.springframework.cloud.gateway.route.RouteLocator;
66
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
77
import org.springframework.context.annotation.Bean;
8-
import org.springframework.context.annotation.ComponentScan;
98

109
/**
1110
* API Gateway & Auth Service Application
1211
* 统一的API网关和认证授权微服务
1312
* 提供路由、鉴权、限流等功能
1413
*/
1514
@SpringBootApplication
16-
@ComponentScan(basePackages = {
17-
"com.datamate.gateway",
18-
"com.datamate.shared"
19-
})
2015
public class ApiGatewayApplication {
2116

2217
public static void main(String[] args) {
@@ -26,51 +21,21 @@ public static void main(String[] args) {
2621
@Bean
2722
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
2823
return builder.routes()
29-
// 数据归集服务路由
30-
.route("data-collection", r -> r.path("/api/data-collection/**")
31-
.uri("lb://data-collection-service"))
32-
33-
// 数据管理服务路由
34-
.route("data-management", r -> r.path("/api/data-management/**")
35-
.uri("lb://data-management-service"))
36-
37-
// 算子市场服务路由
38-
.route("operator-market", r -> r.path("/api/operators/**")
39-
.uri("lb://operator-market-service"))
40-
41-
// 数据清洗服务路由
42-
.route("data-cleaning", r -> r.path("/api/cleaning/**")
43-
.uri("lb://data-cleaning-service"))
44-
4524
// 数据合成服务路由
4625
.route("data-synthesis", r -> r.path("/api/synthesis/**")
47-
.uri("lb://data-synthesis-service"))
26+
.uri("http://datamate-backend-python:18000"))
4827

4928
// 数据标注服务路由
5029
.route("data-annotation", r -> r.path("/api/annotation/**")
51-
.uri("lb://data-annotation-service"))
30+
.uri("http://datamate-backend-python:18000"))
5231

5332
// 数据评估服务路由
5433
.route("data-evaluation", r -> r.path("/api/evaluation/**")
55-
.uri("lb://data-evaluation-service"))
56-
57-
// 流程编排服务路由
58-
.route("pipeline-orchestration", r -> r.path("/api/pipelines/**")
59-
.uri("lb://pipeline-orchestration-service"))
60-
61-
// 执行引擎服务路由
62-
.route("execution-engine", r -> r.path("/api/execution/**")
63-
.uri("lb://execution-engine-service"))
64-
65-
// 认证服务路由
66-
.route("auth-service", r -> r.path("/api/auth/**")
67-
.uri("lb://auth-service"))
34+
.uri("http://datamate-backend-python:18000"))
6835

69-
// RAG服务路由
70-
.route("rag-indexer", r -> r.path("/api/rag/indexer/**")
71-
.uri("lb://rag-indexer-service"))
72-
.route("rag-query", r -> r.path("/api/rag/query/**")
73-
.uri("lb://rag-query-service"))
36+
// 其他后端服务
37+
.route("default", r -> r.path("/api/**")
38+
.uri("http://datamate-backend:8080"))
7439

7540
.build();
7641
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.datamate.gateway.filter;
2+
3+
import com.terrabase.enterprise.api.dto.LoginUserDto;
4+
import com.terrabase.enterprise.api.sdk.TerrabaseSDK;
5+
import com.terrabase.enterprise.api.sdk.TerrabaseSDKConfig;
6+
import jakarta.annotation.PostConstruct;
7+
import lombok.extern.slf4j.Slf4j;
8+
import org.springframework.beans.factory.annotation.Value;
9+
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
10+
import org.springframework.cloud.gateway.filter.GlobalFilter;
11+
import org.springframework.stereotype.Component;
12+
import org.springframework.web.server.ServerWebExchange;
13+
import reactor.core.publisher.Mono;
14+
15+
/**
16+
* 用户信息过滤器
17+
*
18+
* @since 2025/12/22
19+
*/
20+
@Slf4j
21+
@Component
22+
public class UserContextFilter implements GlobalFilter {
23+
@Value("${terrabase.jar.path:/opt/terrabase}")
24+
private String jarPath;
25+
26+
@Value("${commercial.switch:false}")
27+
private boolean isCommercial;
28+
29+
private TerrabaseSDK terrabaseSDK;
30+
31+
@PostConstruct
32+
public void init() {
33+
TerrabaseSDKConfig sdkConfig = TerrabaseSDKConfig.createDefault();
34+
sdkConfig.setJarPath(jarPath);
35+
terrabaseSDK = TerrabaseSDK.init(sdkConfig);
36+
}
37+
38+
@Override
39+
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
40+
if (!isCommercial) {
41+
return chain.filter(exchange);
42+
}
43+
try {
44+
LoginUserDto loginUserDto = terrabaseSDK.userManagement().getCurrentUserInfo().getData().getFirst();
45+
} catch (Exception e) {
46+
log.error("get current user info error", e);
47+
return chain.filter(exchange);
48+
}
49+
return chain.filter(exchange);
50+
}
51+
}

backend/pom.xml

Lines changed: 15 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,24 @@
3838
<poi.version>5.4.0</poi.version>
3939
<log4j2.version>2.21.1</log4j2.version>
4040
<commons-compress.version>1.26.1</commons-compress.version>
41+
<fastjson-version>2.0.52</fastjson-version>
4142
</properties>
4243

4344
<modules>
44-
<!-- 共享库 -->
45-
<module>shared/domain-common</module>
46-
<module>shared/security-common</module>
47-
4845
<!-- 核心服务 -->
49-
<module>services/data-management-service</module>
50-
<module>services/data-collection-service</module>
51-
<module>services/operator-market-service</module>
52-
<module>services/data-cleaning-service</module>
53-
<module>services/data-synthesis-service</module>
54-
<module>services/data-annotation-service</module>
55-
<module>services/data-evaluation-service</module>
56-
<module>services/pipeline-orchestration-service</module>
57-
<module>services/execution-engine-service</module>
58-
59-
<!-- RAG服务 -->
60-
<module>services/rag-indexer-service</module>
61-
<module>services/rag-query-service</module>
62-
63-
<!-- 主启动模块 -->
64-
<module>services/main-application</module>
46+
<module>services</module>
6547

6648
<!-- API Gateway微服务 -->
6749
<module>api-gateway</module>
6850
</modules>
6951

52+
<dependencies>
53+
<dependency>
54+
<groupId>org.projectlombok</groupId>
55+
<artifactId>lombok</artifactId>
56+
</dependency>
57+
</dependencies>
58+
7059
<dependencyManagement>
7160
<dependencies>
7261
<dependency>
@@ -158,70 +147,15 @@
158147
<version>${commons-compress.version}</version>
159148
</dependency>
160149

150+
<dependency>
151+
<groupId>com.alibaba.fastjson2</groupId>
152+
<artifactId>fastjson2</artifactId>
153+
<version>${fastjson-version}</version>
154+
</dependency>
155+
161156
</dependencies>
162157
</dependencyManagement>
163158

164-
<dependencies>
165-
<dependency>
166-
<groupId>org.springframework.boot</groupId>
167-
<artifactId>spring-boot-starter-web</artifactId>
168-
<version>${spring-boot.version}</version>
169-
<exclusions>
170-
<exclusion>
171-
<groupId>org.springframework.boot</groupId>
172-
<artifactId>spring-boot-starter-logging</artifactId>
173-
</exclusion>
174-
</exclusions>
175-
</dependency>
176-
177-
<dependency>
178-
<groupId>org.springframework.boot</groupId>
179-
<artifactId>spring-boot-starter</artifactId>
180-
<version>${spring-boot.version}</version>
181-
<exclusions>
182-
<exclusion>
183-
<groupId>org.springframework.boot</groupId>
184-
<artifactId>spring-boot-starter-logging</artifactId>
185-
</exclusion>
186-
</exclusions>
187-
</dependency>
188-
189-
<dependency>
190-
<groupId>com.baomidou</groupId>
191-
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
192-
<version>${mybatis-plus.version}</version>
193-
</dependency>
194-
<dependency>
195-
<groupId>com.baomidou</groupId>
196-
<artifactId>mybatis-plus-jsqlparser</artifactId>
197-
</dependency>
198-
199-
<!-- Log4j2 API -->
200-
<dependency>
201-
<groupId>org.springframework.boot</groupId>
202-
<artifactId>spring-boot-starter-log4j2</artifactId>
203-
<version>${spring-boot.version}</version>
204-
</dependency>
205-
206-
<dependency>
207-
<groupId>org.projectlombok</groupId>
208-
<artifactId>lombok</artifactId>
209-
<version>${lombok.version}</version>
210-
</dependency>
211-
212-
<dependency>
213-
<groupId>org.mapstruct</groupId>
214-
<artifactId>mapstruct</artifactId>
215-
<version>${mapstruct.version}</version>
216-
</dependency>
217-
218-
<dependency>
219-
<groupId>org.apache.poi</groupId>
220-
<artifactId>poi</artifactId>
221-
<version>${poi.version}</version>
222-
</dependency>
223-
</dependencies>
224-
225159
<build>
226160
<plugins>
227161
<plugin>

backend/services/data-annotation-service/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
<parent>
99
<groupId>com.datamate</groupId>
10-
<artifactId>datamate</artifactId>
10+
<artifactId>services</artifactId>
1111
<version>1.0.0-SNAPSHOT</version>
12-
<relativePath>../../pom.xml</relativePath>
12+
<relativePath>../pom.xml</relativePath>
1313
</parent>
1414

1515
<artifactId>data-annotation-service</artifactId>

backend/services/data-cleaning-service/pom.xml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
<parent>
99
<groupId>com.datamate</groupId>
10-
<artifactId>datamate</artifactId>
10+
<artifactId>services</artifactId>
1111
<version>1.0.0-SNAPSHOT</version>
12-
<relativePath>../../pom.xml</relativePath>
12+
<relativePath>../pom.xml</relativePath>
1313
</parent>
1414

1515
<artifactId>data-cleaning-service</artifactId>
@@ -53,10 +53,6 @@
5353
<groupId>org.openapitools</groupId>
5454
<artifactId>jackson-databind-nullable</artifactId>
5555
</dependency>
56-
<dependency>
57-
<groupId>com.baomidou</groupId>
58-
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
59-
</dependency>
6056
<dependency>
6157
<groupId>com.mysql</groupId>
6258
<artifactId>mysql-connector-j</artifactId>

backend/services/data-collection-service/pom.xml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
<parent>
88
<groupId>com.datamate</groupId>
9-
<artifactId>datamate</artifactId>
9+
<artifactId>services</artifactId>
1010
<version>1.0.0-SNAPSHOT</version>
11-
<relativePath>../../pom.xml</relativePath>
11+
<relativePath>../pom.xml</relativePath>
1212
</parent>
1313

1414
<artifactId>data-collection-service</artifactId>
@@ -31,12 +31,6 @@
3131
<artifactId>spring-boot-starter-actuator</artifactId>
3232
</dependency>
3333

34-
<!-- MyBatis Dependencies -->
35-
<dependency>
36-
<groupId>com.baomidou</groupId>
37-
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
38-
</dependency>
39-
4034
<!-- Database -->
4135
<dependency>
4236
<groupId>com.mysql</groupId>
@@ -109,13 +103,6 @@
109103
<artifactId>jakarta.validation-api</artifactId>
110104
</dependency>
111105

112-
<!-- Lombok -->
113-
<dependency>
114-
<groupId>org.projectlombok</groupId>
115-
<artifactId>lombok</artifactId>
116-
<optional>true</optional>
117-
</dependency>
118-
119106
<!-- Test Dependencies -->
120107
<dependency>
121108
<groupId>org.springframework.boot</groupId>

0 commit comments

Comments
 (0)