Files
ccdi/docs/reports/implementation/2026-03-31-lsfx-mock-server-abnormal-account-backend-implementation.md

86 lines
3.3 KiB
Markdown
Raw 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.
# 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`。本次已将该测试夹具补齐,保证它继续只验证“月固定收入 + 安全噪声”的原始语义。
在合并到 `dev` 后的运行态验证中,又发现 `getBSByLogId` 返回前统一回填主绑定时,会把异常账户样本原本正确的 `accountMaskNo` 覆盖成主账号,导致 HTTP 实际返回数据无法体现异常账户事实。对此补充了以下修正:
- 新增回归用例 `test_get_bank_statement_should_preserve_abnormal_account_mask_no`
-`StatementService._apply_primary_binding(...)` 调整为只兜底缺失账号,不覆盖已有的异常账户样本账号
修正后,接口返回中的异常账户流水可以保留各自独立的账号,与异常账户事实保持一致。
## 5. 结果
异常账户命中计划、最小账户事实、样本生成器和服务层主链路均已落地,现有 Mock 服务可以为同一个 `logId` 稳定提供异常账户命中流水样本。