Fundamental_Analysis/services/data-persistence-service
Lv, Qi 427776b863 feat(analysis): Implement Configurable Analysis Template Engine
This commit introduces a comprehensive, template-based analysis orchestration system, refactoring the entire analysis generation workflow from the ground up.

Key Changes:

1.  **Backend Architecture (`report-generator-service`):**
    *   Replaced the naive analysis workflow with a robust orchestrator based on a Directed Acyclic Graph (DAG) of module dependencies.
    *   Implemented a full topological sort (`petgraph`) to determine the correct execution order and detect circular dependencies.

2.  **Data Models (`common-contracts`, `data-persistence-service`):**
    *   Introduced the concept of `AnalysisTemplateSets` to allow for multiple, independent, and configurable analysis workflows.
    *   Created a new `analysis_results` table to persist the output of each module for every analysis run, ensuring traceability.
    *   Implemented a file-free data seeding mechanism to populate default analysis templates on service startup.

3.  **API Layer (`api-gateway`):**
    *   Added a new asynchronous endpoint (`POST /analysis-requests/{symbol}`) to trigger analysis workflows via NATS messages.
    *   Updated all configuration endpoints to support the new `AnalysisTemplateSets` model.

4.  **Frontend UI (`/config`, `/query`):**
    *   Completely refactored the "Analysis Config" page into a two-level management UI for "Template Sets" and the "Modules" within them, supporting full CRUD operations.
    *   Updated the "Query" page to allow users to select which analysis template to use when generating a report.

This new architecture provides a powerful, flexible, and robust foundation for all future development of our intelligent analysis capabilities.
2025-11-18 07:47:08 +08:00
..
.cargo feat(realtime): 接入前端实时报价并完善后端缓存 2025-11-09 05:12:14 +08:00
.sqlx feat(realtime): 接入前端实时报价并完善后端缓存 2025-11-09 05:12:14 +08:00
assets feat(realtime): 接入前端实时报价并完善后端缓存 2025-11-09 05:12:14 +08:00
src feat(analysis): Implement Configurable Analysis Template Engine 2025-11-18 07:47:08 +08:00
tests feat(realtime): 接入前端实时报价并完善后端缓存 2025-11-09 05:12:14 +08:00
Cargo.lock chore(build): unify Dockerfiles and root .dockerignore; fix services after deps upgrade 2025-11-16 23:34:28 +08:00
Cargo.toml feat(analysis): Implement Configurable Analysis Template Engine 2025-11-18 07:47:08 +08:00
Dockerfile feat(analysis): Implement Configurable Analysis Template Engine 2025-11-18 07:47:08 +08:00
env.sample feat(realtime): 接入前端实时报价并完善后端缓存 2025-11-09 05:12:14 +08:00
README.md feat(realtime): 接入前端实时报价并完善后端缓存 2025-11-09 05:12:14 +08:00

数据持久化服务 (Data Persistence Service)

本服务是“基本面分析”微服务架构中数据库的唯一所有者,为所有数据持久化需求提供一个 RESTful API。

概览

  • 语言: Rust
  • 框架: Axum
  • 数据库: PostgreSQL (带有 TimescaleDB 扩展)
  • 核心任务: 为数据库提供一个稳定、高性能且类型安全的 API 层。

本地开发指南

1. 先决条件

  • Rust 工具链 (rustup)
  • sqlx-cli (cargo install sqlx-cli)
  • 一个正在运行的、并已启用 TimescaleDB 扩展的 PostgreSQL 实例。

2. 配置

env.sample 文件复制为 .env,并根据您的本地环境配置 DATABASE_URL

cp env.sample .env

您的 .env 文件应如下所示:

# 服务监听的端口
PORT=3000

# 用于 sqlx 连接数据库的 URL
# 请确保用户、密码、主机、端口和数据库名称都正确无误
DATABASE_URL=postgres://user:password@localhost:5432/fundamental_analysis

3. 数据库迁移

在首次运行本服务之前,或在任何数据库结构变更之后,请运行迁移命令以更新数据库:

sqlx migrate run

4. 运行服务

编译并运行本服务:

cargo run

服务将会启动并在您 .env 文件中指定的端口(默认为 3000上监听。服务的 OpenAPI 规范 (Swagger JSON) 将在 /api-docs/openapi.json 路径下可用。

测试

要运行所有测试(包括数据库集成测试和 API 集成测试),请使用以下命令。请确保您的 .env 文件中的 DATABASE_URL 指向一个有效的、已应用迁移的测试数据库。

cargo test

如果需要查看详细的测试输出,可以使用:

cargo test -- --nocapture