79 lines
2.7 KiB
Markdown
79 lines
2.7 KiB
Markdown
|
|
# LSFX Mock Server 异常账户后端实施记录
|
|||
|
|
|
|||
|
|
## 1. 实施范围
|
|||
|
|
|
|||
|
|
本次改动仅覆盖 `lsfx-mock-server` 后端 Mock 造数主链路,目标是在不新增接口的前提下,为异常账户规则补齐稳定命中能力。
|
|||
|
|
|
|||
|
|
涉及规则:
|
|||
|
|
|
|||
|
|
- `SUDDEN_ACCOUNT_CLOSURE`
|
|||
|
|
- `DORMANT_ACCOUNT_LARGE_ACTIVATION`
|
|||
|
|
|
|||
|
|
## 2. 主要改动
|
|||
|
|
|
|||
|
|
### 2.1 FileRecord 新增异常账户计划与事实
|
|||
|
|
|
|||
|
|
在 `lsfx-mock-server/services/file_service.py` 中扩展了 `FileRecord`:
|
|||
|
|
|
|||
|
|
- 新增 `abnormal_account_hit_rules`
|
|||
|
|
- 新增 `abnormal_accounts`
|
|||
|
|
|
|||
|
|
同时把异常账户规则池并入现有规则命中计划生成逻辑:
|
|||
|
|
|
|||
|
|
- `subset` 模式下按 `logId` 稳定随机命中异常账户规则
|
|||
|
|
- `all` 模式下自动纳入全部异常账户规则
|
|||
|
|
- 在上传链路与 `fetch_inner_flow(...)` 中同步生成最小异常账户事实
|
|||
|
|
|
|||
|
|
最小账户事实字段包括:
|
|||
|
|
|
|||
|
|
- `account_no`
|
|||
|
|
- `owner_id_card`
|
|||
|
|
- `account_name`
|
|||
|
|
- `status`
|
|||
|
|
- `effective_date`
|
|||
|
|
- `invalid_date`
|
|||
|
|
|
|||
|
|
### 2.2 新增两类异常账户样本生成器
|
|||
|
|
|
|||
|
|
在 `lsfx-mock-server/services/statement_rule_samples.py` 中新增:
|
|||
|
|
|
|||
|
|
- `build_sudden_account_closure_samples(...)`
|
|||
|
|
- `build_dormant_account_large_activation_samples(...)`
|
|||
|
|
|
|||
|
|
口径落实如下:
|
|||
|
|
|
|||
|
|
- `SUDDEN_ACCOUNT_CLOSURE` 的样本流水全部落在销户日前 30 天窗口内
|
|||
|
|
- `DORMANT_ACCOUNT_LARGE_ACTIVATION` 的首笔流水晚于开户满 6 个月
|
|||
|
|
- 休眠激活样本同时满足累计金额阈值与单笔最大金额阈值
|
|||
|
|
|
|||
|
|
### 2.3 接入现有种子流水主链路
|
|||
|
|
|
|||
|
|
未新增平行入口,直接复用现有:
|
|||
|
|
|
|||
|
|
- `FileService -> FileRecord`
|
|||
|
|
- `StatementService._generate_statements(...)`
|
|||
|
|
- `build_seed_statements_for_rule_plan(...)`
|
|||
|
|
|
|||
|
|
接入方式:
|
|||
|
|
|
|||
|
|
- 在统一种子流水构造入口增加 `abnormal_account_hit_rules` 分支
|
|||
|
|
- 根据 `abnormal_accounts` 为每条异常账户规则选择匹配账户事实
|
|||
|
|
- 生成的异常账户样本继续与既有规则样本一起补噪声、编号、打乱和分页
|
|||
|
|
|
|||
|
|
## 3. 测试补充
|
|||
|
|
|
|||
|
|
新增并通过的关键测试包括:
|
|||
|
|
|
|||
|
|
- `test_fetch_inner_flow_should_attach_abnormal_account_rule_plan`
|
|||
|
|
- `test_sudden_account_closure_samples_should_stay_within_30_days_before_invalid_date`
|
|||
|
|
- `test_dormant_account_large_activation_samples_should_exceed_threshold_after_6_months`
|
|||
|
|
- `test_generate_statements_should_follow_abnormal_account_rule_plan_from_file_record`
|
|||
|
|
|
|||
|
|
## 4. 联动修正
|
|||
|
|
|
|||
|
|
在 `all` 模式安全噪声测试中,原有用例只清空了旧规则维度,未同步清空新增的 `abnormal_account_hit_rules`。本次已将该测试夹具补齐,保证它继续只验证“月固定收入 + 安全噪声”的原始语义。
|
|||
|
|
|
|||
|
|
## 5. 结果
|
|||
|
|
|
|||
|
|
异常账户命中计划、最小账户事实、样本生成器和服务层主链路均已落地,现有 Mock 服务可以为同一个 `logId` 稳定提供异常账户命中流水样本。
|