datatestool/examples/requirements/customer_risk_complex.md

115 lines
5.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 客户交易风险画像与日增量指标加工需求 V2
## 1. 需求目标
建设客户交易风险主题数据集,将客户、账户、风险标签、汇率和交易流水进行多表关联,产出:
1. 客户风险画像全量表 `dwd.dwd_customer_risk_profile_full`
2. 客户日交易风险增量表 `dwd.dws_customer_trade_risk_di`
测试批次日期为 `2026-08-22`,交易统计窗口覆盖 `2026-07-24``2026-08-22` 共 30 个业务日期。
## 2. 输入表及装载类型
| 库表 | 装载类型 | 主键/分区 | 用途 |
|---|---|---|---|
| `ods.ods_customer_master_full` | 每日全量 | `cust_id` | 客户主数据 |
| `ods.ods_account_full` | 每日全量 | `account_id` | 客户账户及余额 |
| `ods.ods_risk_tag_full` | 每日全量 | `risk_tag_id` | 风险标签、基础分和权重 |
| `ods.ods_fx_rate_full` | 每日全量 | `currency_code, rate_date` | 交易金额折算人民币 |
| `ods.ods_transaction_inc` | 日增量 | `biz_date`,流水主键 `txn_id` | 30 日交易流水 |
仅客户状态为 `ACTIVE`、账户状态为 `ACTIVE` 的数据参与风险指标加工。失败交易计入交易笔数和失败率,但不计入交易金额、均值、最大值、跨境笔数和大额笔数。
## 3. 全量客户风险画像
目标表:`dwd.dwd_customer_risk_profile_full`,每日按 `etl_batch_date` 全量覆盖。
基础字段:
- `cust_id``ods_customer_master_full.cust_id`,非空、唯一;
- `cust_name``customer_name`
- `customer_type``customer_type`
- `region_code``region_code`
- `total_account_count`:客户全部账户数;
- `active_account_count`:客户有效账户数;
- `total_balance`:有效账户余额求和,保留 2 位小数。
V2 新增字段:
- `risk_tag_code`:关联 `risk_tag_id` 获取;
- `txn_count_30d`30 日交易总笔数;
- `txn_amount_cny_30d`:成功交易按交易日汇率折算人民币后求和,保留 2 位;
- `avg_txn_amount_cny_30d`:人民币交易金额除以成功交易数,保留 2 位;
- `cross_border_ratio_30d`:成功跨境交易数除以成功交易数,保留 6 位;
- `large_txn_count_30d`:成功交易折算人民币后单笔金额大于等于 50,000 元的笔数;
- `failed_txn_ratio_30d`:失败交易数除以全部交易数,保留 6 位;
- `risk_score`:复合风险分,范围 0100保留 2 位;
- `risk_level`:风险等级;
- `data_quality_flag`:无有效账户时为 `NO_ACTIVE_ACCOUNT`,否则为 `OK`
- `profile_version`:固定为 `2`
- `etl_batch_date`:当前批次日期。
全量画像风险分公式:
```text
min(100,
base_score × score_weight
+ cross_border_ratio_30d × 25
+ large_txn_count_30d × 0.4
+ failed_txn_ratio_30d × 15
+ if txn_amount_cny_30d >= 1,000,000 then 5 else 0
)
```
## 4. 日增量交易风险指标
目标表:`dwd.dws_customer_trade_risk_di`,按 `biz_date` 日增量写入,以 `cust_id, biz_date` 为联合主键。重复调度同一业务日期时必须覆盖该分区,不允许追加重复记录。
指标字段:
- `txn_count`:当日交易总笔数;
- `successful_txn_count`:成功交易笔数;
- `failed_txn_count`:失败交易笔数;
- `txn_amount_cny`:成功交易人民币金额合计;
- `avg_txn_amount_cny`:成功交易人民币平均金额;
- `max_txn_amount_cny`:成功交易人民币最大金额;
- `cross_border_count`:成功跨境交易笔数;
- `cross_border_ratio`:成功跨境交易笔数除以成功交易笔数;
- `large_txn_count`:成功交易中人民币金额大于等于 50,000 元的笔数;
- `source_max_update_seq`:该客户当日参与加工的源流水最大更新序号;
- `etl_batch_time`:批次完成时间。
日增量风险分公式:
```text
min(100,
base_score × score_weight
+ cross_border_ratio × 25
+ large_txn_count × 2
+ failed_txn_count / txn_count × 20
+ if txn_amount_cny >= 500,000 then 10 else 0
)
```
风险等级统一按复合风险分映射:
- `risk_score >= 80``HIGH`
- `50 <= risk_score < 80``MEDIUM`
- `risk_score < 50``LOW`
## 5. 数据质量与核对要求
1. 全量画像记录数必须等于有效客户记录数;
2. 所有主键及联合主键必须唯一;
3. 新增字段必须存在且按规则非空;
4. 源交易汇率换算金额与目标汇总金额误差不得超过 0.01
5. `cross_border_ratio`、`failed_txn_ratio_30d` 必须在 01
6. 风险分和风险等级必须严格符合公式;
7. 增量目标必须覆盖 30 个业务日期,源目标有效交易总笔数必须一致;
8. Metadata、案例、运行结果、失败样例、Agent 调查结论和测试报告均须绑定本需求版本保存。
## 6. 演示验收说明
SQLite 演示数据会在日增量目标表中故意写入一条错误的 `risk_score/risk_level` 组合。预期只有“复合风险评分与等级计算一致性校验”失败,用于体验失败证据和 Codex 根因调查;框架不得把该错误自动修复为通过。