记录异常账户基线同步后端实施
This commit is contained in:
@@ -0,0 +1,54 @@
|
|||||||
|
# LSFX Mock Server 异常账户基线同步后端实施记录
|
||||||
|
|
||||||
|
**日期**: 2026-03-31
|
||||||
|
**范围**: `lsfx-mock-server` 异常账户基线同步后端
|
||||||
|
|
||||||
|
## 1. 本次实施内容
|
||||||
|
|
||||||
|
本次后端完成以下改动:
|
||||||
|
|
||||||
|
- 新增 `AbnormalAccountBaselineService`
|
||||||
|
- 复用 `settings.CCDI_DB_*` 连接真实数据库
|
||||||
|
- 以 `account_no` 为唯一键向 `ccdi_account_info` 执行幂等 upsert
|
||||||
|
- 固定写入最小命中字段:`DEBIT`、`EMPLOYEE`、`兰溪农商银行`、`LXNCSY`、`CNY`、`HIGH`
|
||||||
|
- 调整 `FileService`
|
||||||
|
- 新增 `abnormal_account_baseline_service` 注入点
|
||||||
|
- 在 `fetch_inner_flow(...)` 和上传建档链路中,先同步异常账户基线,再写入 `file_records`
|
||||||
|
- 当存在异常账户命中计划但未生成 `abnormal_accounts` 时直接抛错
|
||||||
|
- 锁定 `StatementService` 链路一致性
|
||||||
|
- 继续保持只读 `FileRecord` 生成异常账户样本流水
|
||||||
|
- 通过新增测试确认不会用主账号覆盖异常账户样本自身的 `accountMaskNo`
|
||||||
|
|
||||||
|
## 2. 关键实现语义
|
||||||
|
|
||||||
|
- 基线同步触发点固定在建 `logId` 阶段,不放到 `getBSByLogId`
|
||||||
|
- 异常账户事实为空时直接跳过,不做无意义写库
|
||||||
|
- 任一 `owner_id_card` 与当前 `staff_id_card` 不一致时,立即失败
|
||||||
|
- 数据库写入失败时执行回滚,并且本次 `logId` 不进入 `file_records`
|
||||||
|
- 同一个 `logId` 下:
|
||||||
|
- `record.abnormal_accounts`
|
||||||
|
- 返回的异常账户样本流水
|
||||||
|
- `ccdi_account_info` 中的最小账户事实
|
||||||
|
保持账号级一致
|
||||||
|
|
||||||
|
## 3. 测试补充
|
||||||
|
|
||||||
|
本次新增或扩展了以下测试:
|
||||||
|
|
||||||
|
- `tests/test_file_service.py`
|
||||||
|
- 校验 `fetch_inner_flow(...)` 会在缓存前调用异常账户基线同步
|
||||||
|
- 校验同步失败时不会留下半成品 `logId`
|
||||||
|
- `tests/test_abnormal_account_baseline_service.py`
|
||||||
|
- 校验空输入跳过
|
||||||
|
- 校验证件号不一致直接失败
|
||||||
|
- 校验按账号插入
|
||||||
|
- 校验按账号更新
|
||||||
|
- `tests/test_statement_service.py`
|
||||||
|
- 校验异常账户样本流水仅使用 `record.abnormal_accounts` 中的账号
|
||||||
|
|
||||||
|
## 4. 实施结果
|
||||||
|
|
||||||
|
- `FileService -> AbnormalAccountBaselineService -> StatementService` 的职责边界保持清晰
|
||||||
|
- 异常账户基线写库与内存建档顺序已固定为“先同步、后缓存”
|
||||||
|
- 异常账户样本流水与账户事实的一致性已通过测试锁定
|
||||||
|
- 本轮未扩展接口协议,也未新增补丁式降级链路
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# LSFX Mock Server 异常账户基线同步后端验证记录
|
||||||
|
|
||||||
|
## 1. 验证命令
|
||||||
|
|
||||||
|
本次按实施过程实际执行了以下命令:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd lsfx-mock-server
|
||||||
|
python3 -m pytest tests/test_file_service.py -k "abnormal_account_baseline" -v
|
||||||
|
python3 -m pytest tests/test_abnormal_account_baseline_service.py -v
|
||||||
|
python3 -m pytest tests/test_statement_service.py::test_get_bank_statement_should_only_use_abnormal_account_numbers_from_file_record -v
|
||||||
|
python3 -m pytest tests/test_statement_service.py -k "abnormal_account" -v
|
||||||
|
python3 -m pytest tests/test_abnormal_account_baseline_service.py tests/test_file_service.py tests/test_statement_service.py -k "abnormal_account or abnormal_account_baseline" -v
|
||||||
|
```
|
||||||
|
|
||||||
|
## 2. 验证结果摘要
|
||||||
|
|
||||||
|
- `tests/test_file_service.py -k "abnormal_account_baseline" -v`:`2 passed`
|
||||||
|
- `tests/test_abnormal_account_baseline_service.py -v`:`4 passed`
|
||||||
|
- `tests/test_statement_service.py::test_get_bank_statement_should_only_use_abnormal_account_numbers_from_file_record -v`:通过
|
||||||
|
- `tests/test_statement_service.py -k "abnormal_account" -v`:`3 passed`
|
||||||
|
- 聚合回归:
|
||||||
|
- `python3 -m pytest tests/test_abnormal_account_baseline_service.py tests/test_file_service.py tests/test_statement_service.py -k "abnormal_account or abnormal_account_baseline" -v`
|
||||||
|
- 结果:`10 passed, 41 deselected`
|
||||||
|
|
||||||
|
## 3. 关键通过点
|
||||||
|
|
||||||
|
- `FileService` 已在缓存 `logId` 前触发异常账户基线同步
|
||||||
|
- 基线同步失败时不会把半成品 `logId` 写入内存缓存
|
||||||
|
- `AbnormalAccountBaselineService` 已覆盖空输入、校验失败、插入、更新四类行为
|
||||||
|
- `StatementService` 返回的异常账户样本流水账号与 `record.abnormal_accounts` 保持一致
|
||||||
|
|
||||||
|
## 4. 进程清理
|
||||||
|
|
||||||
|
本轮验证仅执行了 `pytest` 命令,未启动前后端或 Mock 服务长驻进程,因此无需额外清理进程。
|
||||||
Reference in New Issue
Block a user