Files
group_xinghuo_jinrong/scripts/agent/seed-analyst-query-templates.sql
T
zhanghongyu_0626 ddcf53cfa8 feat(template): Implement template caching and SQL rendering for enhanced query handling
- Introduced `TemplateService` for managing SQL templates, allowing for parameterized queries based on user input.
- Added functionality to automatically reload templates upon asset creation in `analyst.py`.
- Enhanced `CacheService` to support table generation bumping, ensuring cache invalidation on data changes.
- Updated `RiskRepository` and `GatewayRepository` to trigger cache invalidation for relevant operations.
- Expanded `analyst_schemas.py` to include new fields for template tracking in response metadata.
- Created seed SQL script for populating initial templates and added unit tests for template rendering logic.

This update significantly improves the efficiency of query handling by leveraging SQL templates, reducing reliance on LLM for common queries.
2026-09-10 15:22:07 +08:00

52 lines
1.5 KiB
SQL

-- 数据分析 Agent · 已发布 SQL 模板种子(D-06 模板缓存演示)
-- 前置:migrate-analyst-d07-d11.sql 已执行
-- 用法:mysql -u root -p jinrong_agent < scripts/agent/seed-analyst-query-templates.sql
USE jinrong_agent;
DELETE FROM analytics_query_template WHERE created_by = 'SEED';
INSERT INTO analytics_query_template
(template_key, template_sql, params_schema, tags, status, version, created_by, published_by)
VALUES
(
'customer_total_count',
'SELECT COUNT(*) AS customer_count FROM core_customer',
JSON_OBJECT('match_all', JSON_ARRAY('客户', '总数')),
JSON_ARRAY('客户', '总数'),
'published',
1,
'SEED',
'SEED'
),
(
'subscribe_amount_recent_days',
'SELECT COALESCE(SUM(amount), 0) AS subscribe_total FROM core_trade WHERE trade_type = ''subscribe'' AND trade_date >= DATE_SUB(CURDATE(), INTERVAL :days DAY)',
JSON_OBJECT(
'match_all', JSON_ARRAY('申购', '金额'),
'params', JSON_ARRAY(
JSON_OBJECT(
'name', 'days',
'placeholder', ':days',
'extract', 'recent_days',
'default', 30
)
)
),
JSON_ARRAY('申购', '金额', '近30天'),
'published',
1,
'SEED',
'SEED'
),
(
'pending_alert_count',
'SELECT COUNT(*) AS pending_count FROM jinrong_agent.risk_alert WHERE status = ''pending_review''',
JSON_OBJECT('match_all', JSON_ARRAY('待处理', '预警')),
JSON_ARRAY('待处理', '预警'),
'published',
1,
'SEED',
'SEED'
);