Add core database support and enhance documentation

- Introduced `MYSQL_CORE_DATABASE` in `.env.example` and `settings.py` for core database configuration.
- Added `CoreReadOnlyRepository` for read-only access to the `jinrong_core` database.
- Updated `AGENTS.md`, `README.md`, and various documentation files to reflect new agent onboarding processes and project structure.
- Revised requirements in `requirements.txt` to include `langgraph` and `langchain-core`.
- Enhanced `FLOW.md` with local bootstrap instructions for setting up the core simulation environment.
- Added new scripts for database creation and seeding for the core simulation library.
- Improved overall documentation for clarity on project architecture and memory management.
- Updated `TODO.md` to reflect current development priorities and tasks.
This commit is contained in:
2026-09-05 17:39:16 +08:00
parent 0374010b37
commit 1ddd44a6cb
34 changed files with 1848 additions and 97 deletions
+129
View File
@@ -0,0 +1,129 @@
-- jinrong_core 表结构 · P0
USE jinrong_core;
-- 风险等级字典(客户 C1~C5 · 产品 R1~R5)
CREATE TABLE core_risk_grade (
code VARCHAR(4) NOT NULL PRIMARY KEY COMMENT 'C1~C5 或 R1~R5',
grade_type ENUM('customer','product') NOT NULL,
display_name VARCHAR(32) NOT NULL,
sort_order TINYINT UNSIGNED NOT NULL
) ENGINE=InnoDB COMMENT='风险等级字典';
CREATE TABLE core_industry (
industry_code VARCHAR(16) NOT NULL PRIMARY KEY,
industry_name VARCHAR(64) NOT NULL
) ENGINE=InnoDB COMMENT='行业分类';
-- 内部员工(含 RBAC 角色种子,供 JWT/鉴权联调对照)
CREATE TABLE core_staff (
staff_id VARCHAR(64) NOT NULL PRIMARY KEY,
display_name VARCHAR(64) NOT NULL,
staff_type ENUM('advisor','analyst','risk_officer','compliance','ops') NOT NULL,
roles JSON NOT NULL COMMENT 'JWT roles 数组,如 ["advisor"]',
tenant_id VARCHAR(32) NOT NULL DEFAULT 'TENANT-001',
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3)
) ENGINE=InnoDB COMMENT='内部员工主档(模拟 IdP 账号源)';
CREATE TABLE core_customer (
customer_id VARCHAR(64) NOT NULL PRIMARY KEY,
display_name VARCHAR(64) NOT NULL COMMENT '脱敏展示名',
age TINYINT UNSIGNED NULL,
occupation VARCHAR(64) NULL,
phone_mask VARCHAR(16) NULL COMMENT '138****9527',
tenant_id VARCHAR(32) NOT NULL DEFAULT 'TENANT-001',
open_date DATE NOT NULL,
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3)
) ENGINE=InnoDB COMMENT='客户主档 L0';
CREATE TABLE core_customer_risk (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
customer_id VARCHAR(64) NOT NULL,
risk_code CHAR(2) NOT NULL COMMENT 'C1~C5',
is_authoritative TINYINT(1) NOT NULL DEFAULT 1,
evaluated_at DATE NOT NULL,
source VARCHAR(32) NOT NULL DEFAULT 'risk_questionnaire',
UNIQUE KEY uk_customer_current (customer_id),
KEY idx_risk (risk_code),
CONSTRAINT fk_cust_risk_customer FOREIGN KEY (customer_id) REFERENCES core_customer(customer_id),
CONSTRAINT fk_cust_risk_code FOREIGN KEY (risk_code) REFERENCES core_risk_grade(code)
) ENGINE=InnoDB COMMENT='客户正式风险测评 L0';
CREATE TABLE core_customer_advisor (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
customer_id VARCHAR(64) NOT NULL,
advisor_id VARCHAR(64) NOT NULL COMMENT '对应 core_staff.staff_id',
rel_status ENUM('active','transferred','closed') NOT NULL DEFAULT 'active',
effective_from DATE NOT NULL,
effective_to DATE NULL,
UNIQUE KEY uk_cust_advisor_from (customer_id, advisor_id, effective_from),
KEY idx_advisor (advisor_id, rel_status),
CONSTRAINT fk_ca_customer FOREIGN KEY (customer_id) REFERENCES core_customer(customer_id),
CONSTRAINT fk_ca_advisor FOREIGN KEY (advisor_id) REFERENCES core_staff(staff_id)
) ENGINE=InnoDB COMMENT='客户-代理人归属';
CREATE TABLE core_product (
product_id VARCHAR(64) NOT NULL PRIMARY KEY,
product_name VARCHAR(128) NOT NULL,
product_type ENUM('bond','mixed','stock','index','money') NOT NULL,
min_risk_code CHAR(2) NOT NULL COMMENT 'R1~R5 最低适配',
industry_code VARCHAR(16) NULL,
fee_rate DECIMAL(6,4) NULL,
is_open TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
KEY idx_min_risk (min_risk_code),
CONSTRAINT fk_product_risk FOREIGN KEY (min_risk_code) REFERENCES core_risk_grade(code),
CONSTRAINT fk_product_industry FOREIGN KEY (industry_code) REFERENCES core_industry(industry_code)
) ENGINE=InnoDB COMMENT='产品主档';
CREATE TABLE core_holding (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
customer_id VARCHAR(64) NOT NULL,
product_id VARCHAR(64) NOT NULL,
qty DECIMAL(18,4) NOT NULL,
cost_amount DECIMAL(18,2) NOT NULL,
market_value DECIMAL(18,2) NOT NULL,
pnl_pct DECIMAL(8,4) NOT NULL COMMENT '盈亏比例',
as_of DATE NOT NULL,
UNIQUE KEY uk_cust_product (customer_id, product_id),
KEY idx_customer (customer_id),
CONSTRAINT fk_hold_customer FOREIGN KEY (customer_id) REFERENCES core_customer(customer_id),
CONSTRAINT fk_hold_product FOREIGN KEY (product_id) REFERENCES core_product(product_id)
) ENGINE=InnoDB COMMENT='持仓快照';
CREATE TABLE core_trade (
trade_id VARCHAR(64) NOT NULL PRIMARY KEY,
customer_id VARCHAR(64) NOT NULL,
product_id VARCHAR(64) NOT NULL,
trade_type ENUM('subscribe','redeem','convert') NOT NULL,
amount DECIMAL(18,2) NOT NULL,
qty DECIMAL(18,4) NULL,
trade_status ENUM('confirmed','pending','cancelled') NOT NULL DEFAULT 'confirmed',
traded_at DATETIME(3) NOT NULL,
KEY idx_customer_time (customer_id, traded_at),
KEY idx_amount (amount, traded_at),
CONSTRAINT fk_trade_customer FOREIGN KEY (customer_id) REFERENCES core_customer(customer_id),
CONSTRAINT fk_trade_product FOREIGN KEY (product_id) REFERENCES core_product(product_id)
) ENGINE=InnoDB COMMENT='交易流水';
CREATE TABLE core_cash_flow (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
customer_id VARCHAR(64) NOT NULL,
flow_type ENUM('in','out') NOT NULL,
amount DECIMAL(18,2) NOT NULL,
remark VARCHAR(128) NULL,
occurred_at DATETIME(3) NOT NULL,
KEY idx_customer (customer_id, occurred_at),
CONSTRAINT fk_cf_customer FOREIGN KEY (customer_id) REFERENCES core_customer(customer_id)
) ENGINE=InnoDB COMMENT='资金进出';
CREATE TABLE core_product_nav (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
product_id VARCHAR(64) NOT NULL,
nav DECIMAL(10,4) NOT NULL,
daily_chg_pct DECIMAL(8,4) NOT NULL,
nav_date DATE NOT NULL,
UNIQUE KEY uk_product_date (product_id, nav_date),
CONSTRAINT fk_nav_product FOREIGN KEY (product_id) REFERENCES core_product(product_id)
) ENGINE=InnoDB COMMENT='产品净值';