feat: 数据分析 Agent 实现(API/服务/表结构元数据/文档/测试)

- 新增 app/api、app/service 数据分析 Agent 全套服务与接口
- schemas.py 重构为 schemas 包(analyst schema)
- 新增 SQL 防注入、guardrail、缓存、字典、LLM 等服务
- 新增 tests 测试套件与 scripts/dev、scripts/setup 脚本
- 补充需求规格、架构说明书、开发清单、表设计等文档
This commit is contained in:
zyi
2026-09-09 18:04:45 +08:00
parent fd9464db0a
commit b19a2415f9
41 changed files with 3463 additions and 16 deletions
+24
View File
@@ -0,0 +1,24 @@
"""查看种子数据关键事实(用于集成测试与演示)。"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
from app.service.analytics_repo import AnalyticsRepo
def main():
repo = AnalyticsRepo()
q = lambda sql: repo.execute_readonly(sql) # noqa: E731
print("advisor ids:", [r[0] for r in q("SELECT staff_id FROM core_staff WHERE staff_type='advisor' AND is_active=1 LIMIT 5")["rows"]])
print("risk_officer ids:", [r[0] for r in q("SELECT staff_id FROM core_staff WHERE staff_type='risk_officer' AND is_active=1 LIMIT 5")["rows"]])
print("ops ids:", [r[0] for r in q("SELECT staff_id FROM core_staff WHERE staff_type='ops' AND is_active=1 LIMIT 5")["rows"]])
print("analyst ids:", [r[0] for r in q("SELECT staff_id FROM core_staff WHERE staff_type='analyst' AND is_active=1 LIMIT 5")["rows"]])
print("risk codes:", q("SELECT risk_code, COUNT(*) c FROM core_customer_risk GROUP BY risk_code ORDER BY risk_code")["rows"])
print("product types:", q("SELECT product_type, COUNT(*) c FROM core_product GROUP BY product_type")["rows"])
print("alert status:", q("SELECT status, COUNT(*) c FROM jinrong_agent.risk_alert GROUP BY status")["rows"])
print("customers sample:", [r[0] for r in q("SELECT customer_id FROM core_customer LIMIT 8")["rows"]])
if __name__ == "__main__":
main()