Files
group_xinghuo_jinrong/scripts/agent/seed-analyst-query-templates.sql
T
zhanghongyu_0626 0fb7d34d7a feat(analyst): Implement audit logging for query denial and clarification
- Enhanced the `AnalystAgent` class to include an `_audit_terminal` method for logging query denials, clarifications, and errors, ensuring compliance and traceability.
- Updated error handling paths to call the new audit method, capturing relevant details such as question, user authentication, and SQL context.
- Introduced new validation checks in `sql_guard.py` to enforce ownership filters for sensitive queries, improving security measures.
- Added unit tests to verify the correct logging behavior and ownership filter enforcement, ensuring robust functionality.

This update significantly strengthens the auditing capabilities of the analyst agent, enhancing security and compliance in query handling.
2026-09-11 14:45:16 +08:00

87 lines
2.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'
),
(
'total_holding_aum',
'SELECT COALESCE(SUM(market_value), 0) AS total_aum FROM core_holding',
JSON_OBJECT('match_all', JSON_ARRAY('持仓', '规模')),
JSON_ARRAY('持仓', '规模', 'AUM'),
'published',
1,
'SEED',
'SEED'
),
(
'customer_self_trade_count_recent',
'SELECT COUNT(*) AS trade_count FROM core_trade WHERE customer_id = '':customer_id'' AND trade_date >= DATE_SUB(CURDATE(), INTERVAL :days DAY)',
JSON_OBJECT(
'match_all', JSON_ARRAY('交易', '笔'),
'params', JSON_ARRAY(
JSON_OBJECT(
'name', 'customer_id',
'placeholder', ':customer_id',
'extract', 'scope_customer'
),
JSON_OBJECT(
'name', 'days',
'placeholder', ':days',
'extract', 'recent_days',
'default', 30
)
)
),
JSON_ARRAY('客户', '交易', '笔数', 'self'),
'published',
1,
'SEED',
'SEED'
);