chore(assets): 参赛提交规范红线修复(ASCII 化 + 相对路径)
按《参赛成果物提交规范·赛道一》§6 红线: - samples/ 目录改名 sample/(git mv,保留历史) - 10 个中日文样本文件 + docs 参赛手册 PDF 重命名为 ASCII (requirements_*/template_*/rules_*/contestant-handbook.pdf) - tests/test_zh_template.py 硬编码绝对路径 D:\00_project\Genesis 改为相对路径 - 全局更新 21 个活动文件引用;历史日志/审查文档不改(追加说明记录) 全量 pytest 431 passed / 99.15%
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.stock</groupId>
|
||||
<artifactId>stock-trade-system</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<groupId>com.stock</groupId>
|
||||
<artifactId>trade-gateway</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>trade-gateway</name>
|
||||
<description>API Gateway for the trading system</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring Cloud Starter Gateway -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Cloud Nacos Discovery (for dynamic routing based on service discovery) -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Cloud Alibaba Nacos Config (for centralized configuration) -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Starter Actuator (for gateway monitoring) -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Trade Common Module -->
|
||||
<dependency>
|
||||
<groupId>com.stock</groupId>
|
||||
<artifactId>trade-common</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Starter Security (if gateway handles authentication/authorization) -->
|
||||
<!-- <dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency> -->
|
||||
<!-- Or use Spring Cloud Security if integrating with OAuth2/OIDC -->
|
||||
<!-- <dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-security</artifactId>
|
||||
</dependency> -->
|
||||
|
||||
<!-- Resilience4j for circuit breaking, rate limiting (alternative to Sentinel if preferred) -->
|
||||
<!-- <dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
|
||||
</dependency> -->
|
||||
|
||||
<!-- Spring Cloud LoadBalancer (comes with Gateway, but explicit if needed for customization) -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringDoc OpenAPI for Gateway (special configuration needed) -->
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId> <!-- Use webflux for Gateway -->
|
||||
<version>${springdoc-openapi.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.trade.gateway;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* 网关应用启动类
|
||||
*
|
||||
* @author Trade Team
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient // 开启服务注册与发现功能
|
||||
public class GatewayApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GatewayApplication.class, args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ Trade Gateway 启动成功 ლ(´ڡ`ლ)゙ \n" +
|
||||
" .-------. ____ __ \n" +
|
||||
" | _ _ | \\ \\ / / \n" +
|
||||
" | ( ' ) | \\ _. / ' \n" +
|
||||
" |(_ o _) / _( )_ .' \n" +
|
||||
" | (_,_).' __ ___(_ o _)' \n" +
|
||||
" | |\ \ | || |(_,_)' \n" +
|
||||
" | | \ `' /| `-' / \n" +
|
||||
" | | \ / \ / \n" +
|
||||
" ''-' `'-' `-..-' ");
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.trade.gateway;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* 网关服务启动类
|
||||
* Created by macro on 2020/6/17.
|
||||
*/
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class TradeGatewayApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TradeGatewayApplication.class, args);
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.trade.gateway.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.reactive.CorsWebFilter;
|
||||
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.util.pattern.PathPatternParser;
|
||||
|
||||
/**
|
||||
* 网关配置类
|
||||
*
|
||||
* @author Trade Team
|
||||
*/
|
||||
@Configuration
|
||||
public class GatewayConfig {
|
||||
|
||||
/**
|
||||
* 配置CORS跨域支持
|
||||
*
|
||||
* @return CorsWebFilter
|
||||
*/
|
||||
@Bean
|
||||
public CorsWebFilter corsFilter() {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
config.addAllowedMethod("*"); // 允许所有请求方法 (GET, POST, PUT, DELETE, OPTIONS等)
|
||||
config.addAllowedOriginPattern("*"); // 允许所有来源,生产环境建议配置具体域名
|
||||
config.addAllowedHeader("*"); // 允许所有请求头
|
||||
config.setAllowCredentials(true); // 允许发送Cookie
|
||||
config.setMaxAge(3600L); // 预检请求的有效期,单位秒
|
||||
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
|
||||
source.registerCorsConfiguration("/**", config); // 对所有路径生效
|
||||
|
||||
return new CorsWebFilter(source);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
spring:
|
||||
redis:
|
||||
database: 0
|
||||
host: localhost
|
||||
port: 6379
|
||||
password: #
|
||||
cloud:
|
||||
gateway:
|
||||
routes:
|
||||
- id: trade-user
|
||||
uri: lb://trade-user
|
||||
predicates:
|
||||
- Path=/user/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-order
|
||||
uri: lb://trade-order
|
||||
predicates:
|
||||
- Path=/order/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-market-data
|
||||
uri: lb://trade-market-data
|
||||
predicates:
|
||||
- Path=/market-data/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-notification
|
||||
uri: lb://trade-notification
|
||||
predicates:
|
||||
- Path=/notification/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-strategy
|
||||
uri: lb://trade-strategy
|
||||
predicates:
|
||||
- Path=/strategy/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-risk
|
||||
uri: lb://trade-risk
|
||||
predicates:
|
||||
- Path=/risk/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-backtest
|
||||
uri: lb://trade-backtest
|
||||
predicates:
|
||||
- Path=/backtest/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-indicator
|
||||
uri: lb://trade-indicator
|
||||
predicates:
|
||||
- Path=/indicator/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-application
|
||||
uri: lb://trade-application
|
||||
predicates:
|
||||
- Path=/application/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
@@ -0,0 +1,63 @@
|
||||
spring:
|
||||
redis:
|
||||
database: 0
|
||||
host: localhost
|
||||
port: 6379
|
||||
password: #
|
||||
cloud:
|
||||
gateway:
|
||||
routes:
|
||||
- id: trade-user
|
||||
uri: lb://trade-user
|
||||
predicates:
|
||||
- Path=/user/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-order
|
||||
uri: lb://trade-order
|
||||
predicates:
|
||||
- Path=/order/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-market-data
|
||||
uri: lb://trade-market-data
|
||||
predicates:
|
||||
- Path=/market-data/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-notification
|
||||
uri: lb://trade-notification
|
||||
predicates:
|
||||
- Path=/notification/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-strategy
|
||||
uri: lb://trade-strategy
|
||||
predicates:
|
||||
- Path=/strategy/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-risk
|
||||
uri: lb://trade-risk
|
||||
predicates:
|
||||
- Path=/risk/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-backtest
|
||||
uri: lb://trade-backtest
|
||||
predicates:
|
||||
- Path=/backtest/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-indicator
|
||||
uri: lb://trade-indicator
|
||||
predicates:
|
||||
- Path=/indicator/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-application
|
||||
uri: lb://trade-application
|
||||
predicates:
|
||||
- Path=/application/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
@@ -0,0 +1,63 @@
|
||||
spring:
|
||||
redis:
|
||||
database: 0
|
||||
host: localhost
|
||||
port: 6379
|
||||
password: #
|
||||
cloud:
|
||||
gateway:
|
||||
routes:
|
||||
- id: trade-user
|
||||
uri: lb://trade-user
|
||||
predicates:
|
||||
- Path=/user/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-order
|
||||
uri: lb://trade-order
|
||||
predicates:
|
||||
- Path=/order/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-market-data
|
||||
uri: lb://trade-market-data
|
||||
predicates:
|
||||
- Path=/market-data/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-notification
|
||||
uri: lb://trade-notification
|
||||
predicates:
|
||||
- Path=/notification/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-strategy
|
||||
uri: lb://trade-strategy
|
||||
predicates:
|
||||
- Path=/strategy/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-risk
|
||||
uri: lb://trade-risk
|
||||
predicates:
|
||||
- Path=/risk/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-backtest
|
||||
uri: lb://trade-backtest
|
||||
predicates:
|
||||
- Path=/backtest/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-indicator
|
||||
uri: lb://trade-indicator
|
||||
predicates:
|
||||
- Path=/indicator/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: trade-application
|
||||
uri: lb://trade-application
|
||||
predicates:
|
||||
- Path=/application/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
@@ -0,0 +1,125 @@
|
||||
server:
|
||||
port: 8080 # 网关服务端口
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: trade-gateway # 应用名称
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848 # Nacos Server地址
|
||||
namespace: # Nacos命名空间ID,根据实际情况配置
|
||||
group: DEFAULT_GROUP # Nacos分组,根据实际情况配置
|
||||
config:
|
||||
server-addr: ${spring.cloud.nacos.discovery.server-addr} # Nacos配置中心地址,同服务发现
|
||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
group: ${spring.cloud.nacos.discovery.group}
|
||||
file-extension: yml # 配置文件格式
|
||||
shared-configs: # 共享配置
|
||||
- data-id: application-common.yml # 通用配置
|
||||
group: ${spring.cloud.nacos.discovery.group}
|
||||
refresh: true # 是否动态刷新
|
||||
# ext-config: # 扩展配置,可以加载多个配置文件
|
||||
# - data-id: trade-gateway-ext.yml
|
||||
# group: ${spring.cloud.nacos.discovery.group}
|
||||
# refresh: true
|
||||
|
||||
gateway:
|
||||
discovery:
|
||||
locator:
|
||||
enabled: true # 开启从注册中心动态创建路由的功能
|
||||
lower-case-service-id: true # 将服务名转为小写进行路由
|
||||
routes:
|
||||
# 示例:路由到用户服务 (trade-user)
|
||||
- id: trade-user-route
|
||||
uri: lb://trade-user # lb代表从Nacos负载均衡,trade-user是服务名
|
||||
predicates:
|
||||
- Path=/user/** # 所有/user/**的请求都路由到trade-user服务
|
||||
filters:
|
||||
- StripPrefix=1 # 转发前去掉第一层路径,例如 /user/login -> /login
|
||||
# - AddRequestHeader=X-Request-Source, gateway # 添加请求头
|
||||
|
||||
# 示例:路由到行情服务 (trade-market)
|
||||
- id: trade-market-route
|
||||
uri: lb://trade-market
|
||||
predicates:
|
||||
- Path=/market/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
|
||||
# 示例:路由到订单服务 (trade-order)
|
||||
- id: trade-order-route
|
||||
uri: lb://trade-order
|
||||
predicates:
|
||||
- Path=/order/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
|
||||
# 示例:路由到认证服务 (trade-auth) - 如果有单独的认证服务
|
||||
# 如果认证逻辑在网关或者trade-security中,则不需要此路由
|
||||
# - id: trade-auth-route
|
||||
# uri: lb://trade-auth
|
||||
# predicates:
|
||||
# - Path=/auth/**
|
||||
# filters:
|
||||
# - StripPrefix=1
|
||||
|
||||
# 静态资源路由 (如果前端项目部署在网关之后)
|
||||
# - id: static-content-route
|
||||
# uri: http://localhost:8081 # 前端静态资源服务器地址
|
||||
# predicates:
|
||||
# - Path=/static/**, /
|
||||
# filters:
|
||||
# - RewritePath=/static/(?<segment>.*), /\${segment}
|
||||
|
||||
# 日志配置 (可选, Spring Boot默认有日志输出)
|
||||
logging:
|
||||
level:
|
||||
org.springframework.cloud.gateway: DEBUG # 网关日志级别
|
||||
reactor.netty.http.client: DEBUG # Netty客户端日志级别
|
||||
com.trade.gateway: INFO # 自定义包日志级别
|
||||
|
||||
# Actuator端点配置 (可选, 用于监控和管理)
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: '*' # 暴露所有端点,生产环境请按需配置
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always # 显示健康检查详情
|
||||
|
||||
# Sentinel配置 (可选, 用于流量控制和熔断降级)
|
||||
# spring:
|
||||
# cloud:
|
||||
# sentinel:
|
||||
# transport:
|
||||
# dashboard: localhost:8080 # Sentinel控制台地址
|
||||
# port: 8719 # Sentinel API端口
|
||||
# datasource:
|
||||
# ds1:
|
||||
# nacos:
|
||||
# server-addr: ${spring.cloud.nacos.discovery.server-addr}
|
||||
# namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
# group-id: ${spring.cloud.nacos.discovery.group}
|
||||
# data-id: sentinel-rules-gateway.json
|
||||
# rule-type: flow # 流控规则
|
||||
|
||||
# Seata 分布式事务配置 (如果需要)
|
||||
# seata:
|
||||
# tx-service-group: trade_tx_group # 事务组
|
||||
# service:
|
||||
# vgroup-mapping:
|
||||
# trade_tx_group: default
|
||||
# registry:
|
||||
# type: nacos
|
||||
# nacos:
|
||||
# server-addr: ${spring.cloud.nacos.discovery.server-addr}
|
||||
# namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
# group: SEATA_GROUP
|
||||
# config:
|
||||
# type: nacos
|
||||
# nacos:
|
||||
# server-addr: ${spring.cloud.nacos.discovery.server-addr}
|
||||
# namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
# group: SEATA_GROUP
|
||||
@@ -0,0 +1,45 @@
|
||||
spring:
|
||||
application:
|
||||
name: trade-gateway # 应用名称,必须与Nacos中配置的Data ID相关联或作为前缀
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
server-addr: 127.0.0.1:8848 # Nacos配置中心地址
|
||||
namespace: # Nacos命名空间ID,根据实际情况配置
|
||||
group: DEFAULT_GROUP # Nacos分组,根据实际情况配置
|
||||
file-extension: yml # 拉取配置文件的格式
|
||||
# 如果配置了shared-configs或者ext-config,这里可以不指定data-id,会默认加载 {spring.application.name}.{file-extension}
|
||||
# data-id: trade-gateway.yml # 如果需要显式指定主配置文件Data ID
|
||||
# refresh-enabled: true # 是否开启动态刷新,默认为true
|
||||
discovery:
|
||||
server-addr: ${spring.cloud.nacos.config.server-addr} # Nacos服务发现地址,通常与配置中心地址一致
|
||||
namespace: ${spring.cloud.nacos.config.namespace}
|
||||
group: ${spring.cloud.nacos.config.group}
|
||||
|
||||
# 如果使用了Spring Cloud Alibaba Sentinel,可以在这里配置
|
||||
# spring:
|
||||
# cloud:
|
||||
# sentinel:
|
||||
# transport:
|
||||
# dashboard: localhost:8080 # Sentinel控制台地址
|
||||
# port: 8719 # Sentinel客户端与控制台通信的端口,默认8719
|
||||
# # Nacos数据源配置,用于持久化规则
|
||||
# datasource:
|
||||
# flow:
|
||||
# nacos:
|
||||
# server-addr: ${spring.cloud.nacos.config.server-addr}
|
||||
# namespace: ${spring.cloud.nacos.config.namespace}
|
||||
# group-id: ${spring.cloud.nacos.config.group}
|
||||
# data-id: ${spring.application.name}-flow-rules.json
|
||||
# rule-type: flow
|
||||
# degrade:
|
||||
# nacos:
|
||||
# server-addr: ${spring.cloud.nacos.config.server-addr}
|
||||
# namespace: ${spring.cloud.nacos.config.namespace}
|
||||
# group-id: ${spring.cloud.nacos.config.group}
|
||||
# data-id: ${spring.application.name}-degrade-rules.json
|
||||
# rule-type: degrade
|
||||
|
||||
# 日志配置,也可以放在application.yml中
|
||||
# logging:
|
||||
# config: classpath:logback-spring.xml # 指定日志配置文件
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<include resource="org/springframework/boot/logging/logback/base.xml"/>
|
||||
<logger name="com.trade.gateway" level="DEBUG"/>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user