调整兰溪本地流水条数为200

This commit is contained in:
wkc
2026-03-19 17:18:02 +08:00
parent 948caef532
commit 3ba5f9d266
5 changed files with 77 additions and 3 deletions

View File

@@ -0,0 +1,58 @@
# lsfx-mock-server 兰溪本地流水条数调整实施文档
## 变更目标
`lsfx-mock-server` 中兰溪本地流水相关链路的条数统一调整为固定 `200` 条,保证以下两个口径一致:
- `/watson/api/project/getJZFileOrZjrcuFile` 创建的 `FileRecord.total_records`
- `/watson/api/project/getBSByLogId` 返回的 `data.totalCount`
## 实施内容
### 1. 调整流水列表总条数
修改文件:
- `lsfx-mock-server/services/statement_service.py`
实施内容:
- 新增 `StatementService.FIXED_TOTAL_COUNT = 200`
-`get_bank_statement` 首次缓存生成总条数的逻辑由随机 `1200-1500` 调整为固定 `200`
### 2. 调整兰溪本地流水落库条数
修改文件:
- `lsfx-mock-server/services/file_service.py`
实施内容:
- 新增 `FileService.INNER_FLOW_TOTAL_RECORDS = 200`
-`fetch_inner_flow` 创建 `FileRecord` 时的 `total_records` 由随机 `100-300` 调整为固定 `200`
### 3. 补充测试
修改文件:
- `lsfx-mock-server/tests/test_statement_service.py`
- `lsfx-mock-server/tests/test_file_service.py`
实施内容:
- 增加 `get_bank_statement` 总条数固定为 `200` 的断言
- 增加 `fetch_inner_flow` 创建的 `FileRecord.total_records` 固定为 `200` 的断言
## 验证记录
执行命令:
```bash
python3 -m pytest lsfx-mock-server/tests/test_statement_service.py -k fixed_total_count_200 -q
python3 -m pytest lsfx-mock-server/tests/test_file_service.py -k fetch_inner_flow_persists_primary_binding_record -q
```
验证结果:
- 两条目标测试均通过
- 当前环境存在 `PydanticDeprecatedSince20` 警告,但不影响本次条数调整

View File

@@ -69,6 +69,8 @@ class FileRecord:
class FileService:
"""文件上传和解析服务"""
INNER_FLOW_TOTAL_RECORDS = 200
def __init__(self, staff_identity_repository=None):
self.file_records: Dict[int, FileRecord] = {} # logId -> FileRecord
self.log_counter = settings.INITIAL_LOG_ID
@@ -532,7 +534,7 @@ class FileService:
primary_enterprise_name=primary_enterprise_name,
primary_account_no=primary_account_no,
file_size=random.randint(10000, 100000),
total_records=random.randint(100, 300),
total_records=self.INNER_FLOW_TOTAL_RECORDS,
trx_date_start_id=data_start_date_id,
trx_date_end_id=data_end_date_id,
le_id=10000 + random.randint(0, 9999),

View File

@@ -17,6 +17,8 @@ logger = logging.getLogger(__name__)
class StatementService:
"""流水数据服务"""
FIXED_TOTAL_COUNT = 200
def __init__(self, file_service=None):
# 缓存logId -> (statements_list, total_count)
self._cache: Dict[int, tuple] = {}
@@ -199,8 +201,7 @@ class StatementService:
page_size = request.pageSize
if log_id not in self._cache:
total_rng = random.Random(f"total:{log_id}")
total_count = total_rng.randint(1200, 1500)
total_count = self.FIXED_TOTAL_COUNT
all_statements = self._generate_statements(group_id, log_id, total_count)
self._cache[log_id] = (all_statements, total_count)

View File

@@ -153,3 +153,4 @@ def test_fetch_inner_flow_persists_primary_binding_record(monkeypatch):
assert record.primary_account_no == "6210987654321098"
assert record.enterprise_name_list == ["行内主体"]
assert record.account_no_list == ["6210987654321098"]
assert record.total_records == 200

View File

@@ -152,6 +152,18 @@ def test_get_bank_statement_should_keep_same_cached_result_for_same_log_id():
assert page1["data"]["bankStatementList"] == page2["data"]["bankStatementList"]
def test_get_bank_statement_should_use_fixed_total_count_200():
"""兰溪本地流水列表首次生成后,总条数应固定为 200。"""
service = StatementService()
response = service.get_bank_statement(
{"groupId": 1000, "logId": 30002, "pageNow": 1, "pageSize": 500}
)
assert response["data"]["totalCount"] == 200
assert len(response["data"]["bankStatementList"]) == 200
def test_get_bank_statement_uses_primary_binding_from_file_service(monkeypatch):
"""同一 logId 的流水记录必须复用 FileService 中的主体与账号绑定。"""
file_service = FileService(staff_identity_repository=FakeStaffIdentityRepository())