让Mock流水查询复用logId主体账号绑定
This commit is contained in:
@@ -13,19 +13,38 @@ logger = logging.getLogger(__name__)
|
||||
class StatementService:
|
||||
"""流水数据服务"""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, file_service=None):
|
||||
# 缓存:logId -> (statements_list, total_count)
|
||||
self._cache: Dict[int, tuple] = {}
|
||||
self.file_service = file_service
|
||||
# 配置日志级别为 INFO
|
||||
logger.info(f"StatementService initialized with empty cache")
|
||||
|
||||
def _generate_random_statement(self, index: int, group_id: int, log_id: int) -> Dict:
|
||||
def _resolve_primary_binding(self, log_id: int) -> tuple:
|
||||
"""优先从 FileService 读取真实主绑定,不存在时再走 fallback。"""
|
||||
if self.file_service is not None:
|
||||
record = self.file_service.get_file_record(log_id)
|
||||
if record is not None:
|
||||
return record.primary_enterprise_name, record.primary_account_no
|
||||
|
||||
return "张传伟", f"{random.randint(100000000000000, 999999999999999)}"
|
||||
|
||||
def _generate_random_statement(
|
||||
self,
|
||||
index: int,
|
||||
group_id: int,
|
||||
log_id: int,
|
||||
primary_enterprise_name: str,
|
||||
primary_account_no: str,
|
||||
) -> Dict:
|
||||
"""生成单条随机流水记录
|
||||
|
||||
Args:
|
||||
index: 流水序号
|
||||
group_id: 项目ID
|
||||
log_id: 文件ID
|
||||
primary_enterprise_name: 本方主体名称
|
||||
primary_account_no: 本方账号
|
||||
|
||||
Returns:
|
||||
单条流水记录字典
|
||||
@@ -75,7 +94,7 @@ class StatementService:
|
||||
|
||||
return {
|
||||
"accountId": 0,
|
||||
"accountMaskNo": f"{random.randint(100000000000000, 999999999999999)}",
|
||||
"accountMaskNo": primary_account_no,
|
||||
"accountingDate": accounting_date,
|
||||
"accountingDateId": accounting_date_id,
|
||||
"archivingFlag": 0,
|
||||
@@ -104,7 +123,7 @@ class StatementService:
|
||||
"groupId": group_id,
|
||||
"internalFlag": 0,
|
||||
"leId": 16308,
|
||||
"leName": "张传伟",
|
||||
"leName": primary_enterprise_name,
|
||||
"overrideBsId": 0,
|
||||
"paymentMethod": "",
|
||||
"sourceCatalogId": 0,
|
||||
@@ -137,11 +156,31 @@ class StatementService:
|
||||
Returns:
|
||||
流水记录列表
|
||||
"""
|
||||
primary_enterprise_name, primary_account_no = self._resolve_primary_binding(log_id)
|
||||
statements = []
|
||||
for i in range(count):
|
||||
statements.append(self._generate_random_statement(i, group_id, log_id))
|
||||
statements.append(
|
||||
self._generate_random_statement(
|
||||
i,
|
||||
group_id,
|
||||
log_id,
|
||||
primary_enterprise_name,
|
||||
primary_account_no,
|
||||
)
|
||||
)
|
||||
return statements
|
||||
|
||||
def _apply_primary_binding(
|
||||
self,
|
||||
statements: List[Dict],
|
||||
primary_enterprise_name: str,
|
||||
primary_account_no: str,
|
||||
) -> None:
|
||||
"""将解析出的主绑定统一回填到已有流水记录。"""
|
||||
for statement in statements:
|
||||
statement["leName"] = primary_enterprise_name
|
||||
statement["accountMaskNo"] = primary_account_no
|
||||
|
||||
def get_bank_statement(self, request: Union[Dict, object]) -> Dict:
|
||||
"""获取银行流水列表
|
||||
|
||||
@@ -174,6 +213,12 @@ class StatementService:
|
||||
|
||||
# 从缓存获取数据
|
||||
all_statements, total_count = self._cache[log_id]
|
||||
primary_enterprise_name, primary_account_no = self._resolve_primary_binding(log_id)
|
||||
self._apply_primary_binding(
|
||||
all_statements,
|
||||
primary_enterprise_name,
|
||||
primary_account_no,
|
||||
)
|
||||
|
||||
# 模拟分页
|
||||
start = (page_now - 1) * page_size
|
||||
|
||||
Reference in New Issue
Block a user