让拉取本行信息链路复用Mock主体账号绑定

This commit is contained in:
wkc
2026-03-18 15:01:58 +08:00
parent 0120d097be
commit 6fb728709e
4 changed files with 214 additions and 21 deletions

View File

@@ -97,6 +97,54 @@ class FileService:
"enterpriseNameList": [primary_enterprise_name],
}
def _create_file_record(
self,
*,
log_id: int,
group_id: int,
file_name: str,
download_file_name: str,
bank_name: str,
template_name: str,
primary_enterprise_name: str,
primary_account_no: str,
file_size: int,
total_records: int,
trx_date_start_id: int,
trx_date_end_id: int,
le_id: int,
login_le_id: int,
parsing: bool = True,
status: int = -5,
) -> FileRecord:
"""创建文件记录并写入主绑定信息。"""
binding_lists = self._build_primary_binding_lists(
primary_enterprise_name,
primary_account_no,
)
return FileRecord(
log_id=log_id,
group_id=group_id,
file_name=file_name,
download_file_name=download_file_name,
bank_name=bank_name,
real_bank_name=bank_name,
template_name=template_name,
primary_enterprise_name=primary_enterprise_name,
primary_account_no=primary_account_no,
account_no_list=binding_lists["accountNoList"],
enterprise_name_list=binding_lists["enterpriseNameList"],
le_id=le_id,
login_le_id=login_le_id,
file_size=file_size,
total_records=total_records,
trx_date_start_id=trx_date_start_id,
trx_date_end_id=trx_date_end_id,
parsing=parsing,
status=status,
)
async def upload_file(
self, group_id: int, file: UploadFile, background_tasks: BackgroundTasks
) -> Dict:
@@ -125,31 +173,23 @@ class FileService:
# 生成单一主绑定
primary_enterprise_name, primary_account_no = self._generate_primary_binding()
binding_lists = self._build_primary_binding_lists(
primary_enterprise_name, primary_account_no
)
# 创建完整的文件记录
file_record = FileRecord(
file_record = self._create_file_record(
log_id=log_id,
group_id=group_id,
file_name=file.filename,
download_file_name=file.filename,
bank_name=bank_name,
real_bank_name=bank_name,
template_name=template_name,
primary_enterprise_name=primary_enterprise_name,
primary_account_no=primary_account_no,
account_no_list=binding_lists["accountNoList"],
enterprise_name_list=binding_lists["enterpriseNameList"],
le_id=10000 + random.randint(0, 9999),
login_le_id=10000 + random.randint(0, 9999),
file_size=random.randint(10000, 100000),
total_records=random.randint(100, 300),
trx_date_start_id=trx_date_start_id,
trx_date_end_id=trx_date_end_id,
parsing=True,
status=-5
le_id=10000 + random.randint(0, 9999),
login_le_id=10000 + random.randint(0, 9999),
)
# 存储记录
@@ -367,12 +407,15 @@ class FileService:
logs = []
if log_id:
# 使用局部随机源,避免污染全局随机状态
rng = random.Random(log_id)
if log_id in self.file_records:
logs.append(self._build_log_detail(self.file_records[log_id]))
else:
# 使用局部随机源,避免污染全局随机状态
rng = random.Random(log_id)
# 生成确定性的文件记录
record = self._generate_deterministic_record(log_id, group_id, rng)
logs.append(record)
# 生成确定性的文件记录
record = self._generate_deterministic_record(log_id, group_id, rng)
logs.append(record)
# 返回响应
return {
@@ -416,16 +459,50 @@ class FileService:
}
def fetch_inner_flow(self, request: Union[Dict, object]) -> Dict:
"""拉取行内流水(返回随机logId
"""拉取行内流水(创建并保存绑定记录
Args:
request: 拉取流水请求(保留参数以符合接口规范当前Mock实现不使用
request: 拉取流水请求(可以是字典或对象
Returns:
流水响应字典,包含随机生成的logId数组
流水响应字典,包含创建并保存的logId数组
"""
# 随机生成一个logId范围10000-99999
log_id = random.randint(10000, 99999)
# 支持 dict 或对象
if isinstance(request, dict):
group_id = request.get("groupId", 1000)
customer_no = request.get("customerNo", "")
data_start_date_id = request.get("dataStartDateId", 20240101)
data_end_date_id = request.get("dataEndDateId", 20241231)
else:
group_id = request.groupId
customer_no = request.customerNo
data_start_date_id = request.dataStartDateId
data_end_date_id = request.dataEndDateId
# 使用递增 logId确保与上传链路一致
self.log_counter += 1
log_id = self.log_counter
primary_enterprise_name, primary_account_no = self._generate_primary_binding()
file_record = self._create_file_record(
log_id=log_id,
group_id=group_id,
file_name=f"{customer_no or 'inner_flow'}_{log_id}.csv",
download_file_name=f"{customer_no or 'inner_flow'}_{log_id}.csv",
bank_name="ZJRCU",
template_name="ZJRCU_T251114",
primary_enterprise_name=primary_enterprise_name,
primary_account_no=primary_account_no,
file_size=random.randint(10000, 100000),
total_records=random.randint(100, 300),
trx_date_start_id=data_start_date_id,
trx_date_end_id=data_end_date_id,
le_id=10000 + random.randint(0, 9999),
login_le_id=10000 + random.randint(0, 9999),
parsing=False,
)
self.file_records[log_id] = file_record
# 返回成功的响应包含logId数组
return {