接入异常账户命中流水主链路
This commit is contained in:
@@ -953,6 +953,39 @@ PHASE2_STATEMENT_RULE_BUILDERS = {
|
||||
"SALARY_UNUSED": build_salary_unused_samples,
|
||||
}
|
||||
|
||||
ABNORMAL_ACCOUNT_RULE_BUILDERS = {
|
||||
"SUDDEN_ACCOUNT_CLOSURE": build_sudden_account_closure_samples,
|
||||
"DORMANT_ACCOUNT_LARGE_ACTIVATION": build_dormant_account_large_activation_samples,
|
||||
}
|
||||
|
||||
|
||||
def _resolve_abnormal_account_fact(rule_code: str, abnormal_accounts: List[Dict]) -> Optional[Dict]:
|
||||
for account_fact in abnormal_accounts:
|
||||
if account_fact.get("rule_code") == rule_code:
|
||||
return account_fact
|
||||
|
||||
if rule_code == "SUDDEN_ACCOUNT_CLOSURE":
|
||||
return next(
|
||||
(
|
||||
account_fact
|
||||
for account_fact in abnormal_accounts
|
||||
if account_fact.get("status") == 2 and account_fact.get("invalid_date")
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
if rule_code == "DORMANT_ACCOUNT_LARGE_ACTIVATION":
|
||||
return next(
|
||||
(
|
||||
account_fact
|
||||
for account_fact in abnormal_accounts
|
||||
if account_fact.get("status") == 1 and account_fact.get("effective_date")
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def build_seed_statements_for_rule_plan(
|
||||
group_id: int,
|
||||
@@ -961,21 +994,36 @@ def build_seed_statements_for_rule_plan(
|
||||
**kwargs,
|
||||
) -> List[Dict]:
|
||||
statements: List[Dict] = []
|
||||
abnormal_accounts = list(kwargs.get("abnormal_accounts") or [])
|
||||
common_kwargs = {key: value for key, value in kwargs.items() if key != "abnormal_accounts"}
|
||||
|
||||
for rule_code in rule_plan.get("large_transaction_hit_rules", []):
|
||||
builder = LARGE_TRANSACTION_BUILDERS.get(rule_code)
|
||||
if builder is not None:
|
||||
statements.extend(builder(group_id, log_id, **kwargs))
|
||||
statements.extend(builder(group_id, log_id, **common_kwargs))
|
||||
|
||||
for rule_code in rule_plan.get("phase1_hit_rules", []):
|
||||
builder = PHASE1_RULE_BUILDERS.get(rule_code)
|
||||
if builder is not None:
|
||||
statements.extend(builder(group_id, log_id, **kwargs))
|
||||
statements.extend(builder(group_id, log_id, **common_kwargs))
|
||||
|
||||
for rule_code in rule_plan.get("phase2_statement_hit_rules", []):
|
||||
builder = PHASE2_STATEMENT_RULE_BUILDERS.get(rule_code)
|
||||
if builder is not None:
|
||||
statements.extend(builder(group_id, log_id, **kwargs))
|
||||
statements.extend(builder(group_id, log_id, **common_kwargs))
|
||||
|
||||
for rule_code in rule_plan.get("abnormal_account_hit_rules", []):
|
||||
builder = ABNORMAL_ACCOUNT_RULE_BUILDERS.get(rule_code)
|
||||
account_fact = _resolve_abnormal_account_fact(rule_code, abnormal_accounts)
|
||||
if builder is not None and account_fact is not None:
|
||||
statements.extend(
|
||||
builder(
|
||||
group_id,
|
||||
log_id,
|
||||
account_fact=account_fact,
|
||||
le_name=common_kwargs.get("primary_enterprise_name", "模型测试主体"),
|
||||
)
|
||||
)
|
||||
|
||||
return statements
|
||||
|
||||
|
||||
@@ -166,6 +166,9 @@ class StatementService:
|
||||
"phase2_statement_hit_rules": (
|
||||
list(record.phase2_statement_hit_rules) if record is not None else []
|
||||
),
|
||||
"abnormal_account_hit_rules": (
|
||||
list(record.abnormal_account_hit_rules) if record is not None else []
|
||||
),
|
||||
}
|
||||
if record is not None and record.staff_id_card:
|
||||
allowed_identity_cards = tuple([record.staff_id_card, *record.family_id_cards])
|
||||
@@ -180,6 +183,7 @@ class StatementService:
|
||||
primary_account_no=primary_account_no,
|
||||
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,
|
||||
abnormal_accounts=record.abnormal_accounts if record is not None else None,
|
||||
)
|
||||
safe_all_mode_noise = settings.RULE_HIT_MODE == "all" and record is not None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user