实现lsfx-mock全命中SQL对齐

This commit is contained in:
wkc
2026-03-25 10:05:30 +08:00
parent f217d59f09
commit 5eea3c66ff
9 changed files with 523 additions and 24 deletions

View File

@@ -4,6 +4,8 @@ import random
import uuid
from datetime import datetime, timedelta
from config.settings import settings
from services.statement_rule_samples import (
build_seed_statements_for_rule_plan,
resolve_identity_cards,
@@ -43,34 +45,44 @@ class StatementService:
primary_account_no: str,
allowed_identity_cards: tuple,
rng: random.Random,
noise_index: int = 0,
safe_all_mode_noise: bool = False,
) -> Dict:
"""生成单条随机噪声流水记录。"""
reference_now = datetime(2026, 3, 18, 9, 0, 0)
days_ago = rng.randint(0, 365)
trx_datetime = reference_now - timedelta(days=days_ago, minutes=rng.randint(0, 1439))
trans_amount = round(rng.uniform(10, 10000), 2)
if rng.random() > 0.5:
if safe_all_mode_noise:
trans_amount = round(rng.uniform(10, 200), 2)
dr_amount = trans_amount
cr_amount = 0.0
trans_flag = "P"
customer_name = f"日常消费商户{noise_index}"
user_memo = f"日常消费_{noise_index}"
else:
cr_amount = trans_amount
dr_amount = 0.0
trans_flag = "R"
trans_amount = round(rng.uniform(10, 10000), 2)
customer_name = rng.choice(
["小店", "支付宝", "微信支付", "财付通", "美团", "京东", "淘宝", "银行转账"]
)
user_memo = rng.choice(
[
f"消费_{customer_name}",
f"转账_{customer_name}",
f"收款_{customer_name}",
f"支付_{customer_name}",
f"退款_{customer_name}",
]
)
if rng.random() > 0.5:
dr_amount = trans_amount
cr_amount = 0.0
trans_flag = "P"
else:
cr_amount = trans_amount
dr_amount = 0.0
trans_flag = "R"
customer_name = rng.choice(
["小店", "支付宝", "微信支付", "财付通", "美团", "京东", "淘宝", "银行转账"]
)
user_memo = rng.choice(
[
f"消费_{customer_name}",
f"转账_{customer_name}",
f"收款_{customer_name}",
f"支付_{customer_name}",
f"退款_{customer_name}",
]
)
return {
"accountId": 0,
@@ -167,10 +179,11 @@ class StatementService:
staff_id_card=record.staff_id_card if record is not None else None,
family_id_cards=record.family_id_cards if record is not None else None,
)
safe_all_mode_noise = settings.RULE_HIT_MODE == "all" and record is not None
total_count = max(count, len(seeded_statements))
statements = list(seeded_statements)
for _ in range(total_count - len(seeded_statements)):
for noise_index in range(total_count - len(seeded_statements)):
statements.append(
self._generate_random_statement(
group_id,
@@ -179,6 +192,8 @@ class StatementService:
primary_account_no,
allowed_identity_cards,
rng,
noise_index=noise_index,
safe_all_mode_noise=safe_all_mode_noise,
)
)