feat: fix the data-collector
This commit is contained in:
24
backend/Dockerfile
Normal file
24
backend/Dockerfile
Normal file
@@ -0,0 +1,24 @@
|
||||
FROM openjdk:17-jdk-slim
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 复制Maven构建结果
|
||||
COPY target/*.jar app.jar
|
||||
|
||||
# 创建日志目录
|
||||
RUN mkdir -p /app/logs
|
||||
|
||||
# 设置环境变量
|
||||
ENV SPRING_PROFILES_ACTIVE=docker
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 8080
|
||||
|
||||
# 健康检查
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||||
CMD curl -f http://localhost:8080/actuator/health || exit 1
|
||||
|
||||
# 启动应用
|
||||
ENTRYPOINT ["java", "-Xms512m", "-Xmx2g", "-Dspring.profiles.active=${SPRING_PROFILES_ACTIVE}", "-jar", "app.jar"]
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.agricultural.stock.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* CORS跨域配置类
|
||||
*
|
||||
* @author Agricultural Stock Platform Team
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("*")
|
||||
.maxAge(3600);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.agricultural.stock.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
@@ -26,4 +27,6 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
registry.addViewController("/swagger-ui").setViewName("redirect:/swagger-ui/index.html");
|
||||
registry.addViewController("/api").setViewName("redirect:/swagger-ui/index.html");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
@@ -26,6 +27,14 @@ public class MarketAnalysisController {
|
||||
@Autowired
|
||||
private MarketAnalysisService marketAnalysisService;
|
||||
|
||||
/**
|
||||
* 处理预检请求
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.OPTIONS)
|
||||
public Result<String> options() {
|
||||
return Result.success("OK");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最新的市场分析数据
|
||||
*/
|
||||
|
||||
@@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
@@ -29,6 +30,14 @@ public class StockController {
|
||||
@Autowired
|
||||
private StockService stockService;
|
||||
|
||||
/**
|
||||
* 处理预检请求
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.OPTIONS)
|
||||
public Result<String> options() {
|
||||
return Result.success("OK");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取实时股票数据
|
||||
*/
|
||||
|
||||
50
backend/src/main/resources/application-dev.yml
Normal file
50
backend/src/main/resources/application-dev.yml
Normal file
@@ -0,0 +1,50 @@
|
||||
# 开发环境配置
|
||||
spring:
|
||||
# 数据源配置 - 本地开发环境
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/agricultural_stock?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: root
|
||||
hikari:
|
||||
minimum-idle: 5
|
||||
maximum-pool-size: 20
|
||||
connection-timeout: 30000
|
||||
idle-timeout: 600000
|
||||
max-lifetime: 1800000
|
||||
|
||||
# Redis配置 - 本地开发环境
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6379
|
||||
database: 0
|
||||
timeout: 6000ms
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 10
|
||||
max-wait: -1ms
|
||||
max-idle: 8
|
||||
min-idle: 0
|
||||
|
||||
# JPA配置
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: none
|
||||
show-sql: true # 开发环境显示SQL
|
||||
database-platform: org.hibernate.dialect.MySQL8Dialect
|
||||
properties:
|
||||
hibernate:
|
||||
dialect: org.hibernate.dialect.MySQL8Dialect
|
||||
format_sql: true
|
||||
|
||||
# 日志配置 - 开发环境更详细
|
||||
logging:
|
||||
level:
|
||||
com.agricultural.stock: DEBUG
|
||||
org.springframework: WARN
|
||||
com.baomidou.mybatisplus: DEBUG
|
||||
pattern:
|
||||
console: "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
|
||||
file: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
|
||||
file:
|
||||
name: logs/agricultural-stock-platform-dev.log
|
||||
50
backend/src/main/resources/application-docker.yml
Normal file
50
backend/src/main/resources/application-docker.yml
Normal file
@@ -0,0 +1,50 @@
|
||||
# Docker环境配置
|
||||
spring:
|
||||
# 数据源配置 - Docker环境
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://mysql:3306/agricultural_stock?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: 123456
|
||||
hikari:
|
||||
minimum-idle: 10
|
||||
maximum-pool-size: 30
|
||||
connection-timeout: 30000
|
||||
idle-timeout: 600000
|
||||
max-lifetime: 1800000
|
||||
|
||||
# Redis配置 - Docker环境
|
||||
redis:
|
||||
host: redis
|
||||
port: 6379
|
||||
database: 0
|
||||
timeout: 6000ms
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 20
|
||||
max-wait: -1ms
|
||||
max-idle: 10
|
||||
min-idle: 2
|
||||
|
||||
# JPA配置
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: none
|
||||
show-sql: false # 生产环境不显示SQL
|
||||
database-platform: org.hibernate.dialect.MySQL8Dialect
|
||||
properties:
|
||||
hibernate:
|
||||
dialect: org.hibernate.dialect.MySQL8Dialect
|
||||
format_sql: false
|
||||
|
||||
# 日志配置 - Docker环境
|
||||
logging:
|
||||
level:
|
||||
com.agricultural.stock: INFO
|
||||
org.springframework: WARN
|
||||
com.baomidou.mybatisplus: WARN
|
||||
pattern:
|
||||
console: "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
|
||||
file: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
|
||||
file:
|
||||
name: logs/agricultural-stock-platform.log
|
||||
75
backend/src/main/resources/application-prod.yml
Normal file
75
backend/src/main/resources/application-prod.yml
Normal file
@@ -0,0 +1,75 @@
|
||||
# 生产环境配置
|
||||
spring:
|
||||
# 数据源配置 - 生产环境(使用环境变量)
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: ${DATABASE_URL:jdbc:mysql://43.143.145.172:3306/agricultural_stock?useSSL=false&serverTimezone=Asia/Shanghai}
|
||||
username: ${DATABASE_USERNAME:root}
|
||||
password: ${DATABASE_PASSWORD:kyff145972}
|
||||
hikari:
|
||||
minimum-idle: 20
|
||||
maximum-pool-size: 50
|
||||
connection-timeout: 30000
|
||||
idle-timeout: 600000
|
||||
max-lifetime: 1800000
|
||||
leak-detection-threshold: 60000
|
||||
|
||||
# Redis配置 - 生产环境
|
||||
redis:
|
||||
host: ${REDIS_HOST:localhost}
|
||||
port: ${REDIS_PORT:6379}
|
||||
password: ${REDIS_PASSWORD:}
|
||||
database: 0
|
||||
timeout: 10000ms
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 50
|
||||
max-wait: -1ms
|
||||
max-idle: 20
|
||||
min-idle: 5
|
||||
|
||||
# JPA配置
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: none
|
||||
show-sql: false
|
||||
database-platform: org.hibernate.dialect.MySQL8Dialect
|
||||
properties:
|
||||
hibernate:
|
||||
dialect: org.hibernate.dialect.MySQL8Dialect
|
||||
format_sql: false
|
||||
use_sql_comments: false
|
||||
jdbc.batch_size: 100
|
||||
order_inserts: true
|
||||
order_updates: true
|
||||
|
||||
# 日志配置 - 生产环境
|
||||
logging:
|
||||
level:
|
||||
com.agricultural.stock: INFO
|
||||
org.springframework: WARN
|
||||
com.baomidou.mybatisplus: WARN
|
||||
org.hibernate: WARN
|
||||
pattern:
|
||||
console: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n"
|
||||
file: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n"
|
||||
file:
|
||||
name: ${LOG_FILE:/app/logs/agricultural-stock-platform.log}
|
||||
logback:
|
||||
rollingpolicy:
|
||||
max-file-size: 100MB
|
||||
max-history: 30
|
||||
total-size-cap: 3GB
|
||||
|
||||
# 服务器配置 - 生产环境优化
|
||||
server:
|
||||
tomcat:
|
||||
threads:
|
||||
max: 200
|
||||
min-spare: 10
|
||||
max-connections: 8192
|
||||
accept-count: 100
|
||||
connection-timeout: 20000ms
|
||||
compression:
|
||||
enabled: true
|
||||
mime-types: text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json
|
||||
@@ -7,7 +7,11 @@ spring:
|
||||
application:
|
||||
name: agricultural-stock-platform-backend
|
||||
|
||||
# 数据源配置
|
||||
# 设置默认环境为开发环境
|
||||
profiles:
|
||||
active: ${SPRING_PROFILES_ACTIVE:dev}
|
||||
|
||||
# 数据源配置 (默认配置,会被环境配置覆盖)
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/agricultural_stock?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||
|
||||
Reference in New Issue
Block a user