Files
group_xinghuo_jinrong/scripts/agent/migrate-advisor-agent-sprint1-3.sql
T
zhanghongyu_0626 70aa861983 feat(advisor-agent): Introduce advisor agent functionalities with compliance, KYC, and script templates
- Added new modules for advisor compliance, KYC sessions, and script templates, enhancing the advisor agent's capabilities.
- Implemented a comprehensive API structure under the `/api/advisor-agent` prefix, ensuring clear organization and access to new features.
- Established database models and repositories for compliance rules and KYC sessions, facilitating robust data management.
- Integrated exception handling and response models to improve error management and user feedback.
- Updated settings to include new configurations for compliance and KYC features, ensuring flexibility and adaptability.

This update significantly expands the advisor agent's functionality, providing essential tools for compliance and customer interaction while maintaining a structured API design.
2026-09-12 16:33:07 +08:00

154 lines
5.9 KiB
SQL

-- 投资顾问 Agent 专用表(Sprint1~3 · 不含共用底座 01 已建表)
-- 执行:mysql jinrong_agent < scripts/agent/migrate-advisor-agent-sprint1-3.sql
USE jinrong_agent;
CREATE TABLE IF NOT EXISTS compliance_rule (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
rule_code VARCHAR(32) NOT NULL UNIQUE,
rule_type VARCHAR(16) NOT NULL,
pattern VARCHAR(1024) NOT NULL,
severity VARCHAR(8) NOT NULL,
category VARCHAR(32) NOT NULL,
suggestion VARCHAR(2048) NULL,
is_active TINYINT(1) NOT NULL DEFAULT 1,
priority INT NOT NULL DEFAULT 100,
created_by VARCHAR(64) NOT NULL,
updated_by VARCHAR(64) NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
KEY idx_type_active (rule_type, is_active),
KEY idx_severity (severity),
KEY idx_category (category)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS compliance_check_log (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
check_id VARCHAR(64) NOT NULL UNIQUE,
trace_id VARCHAR(64) NOT NULL,
advisor_id VARCHAR(64) NOT NULL,
scene VARCHAR(32) NULL,
input_text TEXT NOT NULL,
input_hash VARCHAR(64) NULL,
risk_level VARCHAR(8) NOT NULL,
hit_count INT NOT NULL DEFAULT 0,
hit_details JSON NULL,
ai_analysis JSON NULL,
ai_degraded TINYINT(1) NOT NULL DEFAULT 0,
latency_ms INT NULL,
customer_risk_level VARCHAR(4) NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
KEY idx_trace (trace_id),
KEY idx_advisor_time (advisor_id, created_at),
KEY idx_risk_time (risk_level, created_at),
KEY idx_scene_time (scene, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS copy_track_log (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
track_id VARCHAR(64) NOT NULL UNIQUE,
trace_id VARCHAR(64) NOT NULL,
advisor_id VARCHAR(64) NOT NULL,
content_type VARCHAR(32) NOT NULL,
content_summary VARCHAR(512) NOT NULL,
content_hash VARCHAR(64) NOT NULL,
source_type VARCHAR(32) NOT NULL,
source_id VARCHAR(64) NULL,
compliance_check_id VARCHAR(64) NULL,
compliance_risk_level VARCHAR(8) NOT NULL,
warn_confirmed TINYINT(1) NOT NULL DEFAULT 0,
export_format VARCHAR(8) NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
KEY idx_trace (trace_id),
KEY idx_advisor (advisor_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS script_template (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
scene VARCHAR(32) NOT NULL,
customer_type VARCHAR(32) NULL,
title VARCHAR(256) NOT NULL,
content TEXT NOT NULL,
tags JSON NULL,
embedding_id VARCHAR(64) NULL,
is_approved TINYINT(1) NOT NULL DEFAULT 0,
approved_by VARCHAR(64) NULL,
approved_at DATETIME NULL,
version INT NOT NULL DEFAULT 1,
usage_count INT NOT NULL DEFAULT 0,
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_by VARCHAR(64) NOT NULL,
updated_by VARCHAR(64) NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
KEY idx_scene (scene),
KEY idx_approved (is_approved)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS template_use_log (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
use_id VARCHAR(64) NOT NULL UNIQUE,
trace_id VARCHAR(64) NOT NULL,
template_id BIGINT UNSIGNED NOT NULL,
advisor_id VARCHAR(64) NOT NULL,
is_modified TINYINT(1) NOT NULL DEFAULT 0,
original_content TEXT NULL,
modified_content TEXT NULL,
content_diff TEXT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
KEY idx_template (template_id),
KEY idx_trace (trace_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS market_alert (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
alert_id VARCHAR(64) NOT NULL UNIQUE,
trace_id VARCHAR(64) NULL,
fund_code VARCHAR(16) NOT NULL,
fund_name VARCHAR(128) NULL,
alert_type VARCHAR(16) NOT NULL,
threshold_hit DECIMAL(8,4) NOT NULL,
nav DECIMAL(10,4) NULL,
nav_date DATE NOT NULL,
category VARCHAR(32) NULL,
generated_text TEXT NULL,
compliance_result JSON NULL,
generation_latency_ms INT NULL,
status VARCHAR(16) NOT NULL DEFAULT 'pending',
advisor_id VARCHAR(64) NULL,
advisor_feedback VARCHAR(16) NULL,
edited_text TEXT NULL,
feedback_at DATETIME NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
KEY idx_fund (fund_code),
KEY idx_status (status),
KEY idx_nav_date (nav_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS kyc_session (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
session_id VARCHAR(64) NOT NULL UNIQUE,
trace_id VARCHAR(64) NOT NULL,
advisor_id VARCHAR(64) NOT NULL,
customer_id VARCHAR(64) NOT NULL,
session_type VARCHAR(16) NOT NULL,
status VARCHAR(16) NOT NULL DEFAULT 'in_progress',
current_node VARCHAR(32) NOT NULL DEFAULT 'basic_info',
collected_fields JSON NULL,
missing_fields JSON NULL,
progress_pct INT NOT NULL DEFAULT 0,
dialog_turns INT NOT NULL DEFAULT 0,
started_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
completed_at DATETIME NULL,
duration_seconds INT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
KEY idx_advisor (advisor_id),
KEY idx_customer (customer_id),
KEY idx_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- agent_message 序号唯一(共用底座已建表时执行)
-- ALTER TABLE agent_message ADD UNIQUE KEY uk_agent_message_session_seq (session_id, seq_no);