feat: 扩展风险规则体系、审批动态路由与预算中心列表化改造
- 新增 25+ 条风险规则(预算/报销/申请/通用类),完善风险规则模拟与反馈发布机制 - 引入费用审批动态路由、平台风险分级、预审与风险阶段管理 - 预算中心列表化改造,优化票据夹仪表盘与数字员工工作看板 - 新增 Hermes 风险线索收集器、Agent 链路追踪中心 - 扩展数字员工能力库(18 个领域 Skill)与交通费用自动预估 - 完善报销申请快速预览、权限控制与前端测试覆盖
This commit is contained in:
@@ -27,6 +27,7 @@ from app.services.expense_claim_constants import (
|
||||
TRAVEL_ALLOWANCE_TRIGGER_ITEM_TYPES,
|
||||
TRAVEL_POLICY_HOTEL_NIGHT_PATTERN,
|
||||
)
|
||||
from app.services.expense_claim_risk_stage import with_risk_business_stage
|
||||
from app.services.expense_rule_runtime import (
|
||||
ExpenseRuleRuntimeService,
|
||||
RuntimeTravelPolicy,
|
||||
@@ -215,6 +216,7 @@ class ExpenseClaimItemSyncMixin:
|
||||
claim.amount = Decimal("0.00")
|
||||
claim.invoice_count = 0
|
||||
claim.risk_flags_json = self._merge_claim_attachment_risk_flags(claim, [])
|
||||
claim.risk_flags_json = self._merge_claim_platform_risk_preview_flags(claim, [])
|
||||
return
|
||||
|
||||
ordered_items = sorted(
|
||||
@@ -253,6 +255,7 @@ class ExpenseClaimItemSyncMixin:
|
||||
claim,
|
||||
self._build_claim_attachment_risk_flags(ordered_items),
|
||||
)
|
||||
self._refresh_claim_platform_risk_preview_flags(claim)
|
||||
if str(claim.status or "").strip().lower() == "draft":
|
||||
claim.approval_stage = "待提交"
|
||||
|
||||
@@ -359,15 +362,18 @@ class ExpenseClaimItemSyncMixin:
|
||||
analysis.get("label") or ("高风险" if severity == "high" else "中风险")
|
||||
).strip()
|
||||
derived_flags.append(
|
||||
{
|
||||
"source": "attachment_analysis",
|
||||
"item_id": item.id,
|
||||
"severity": severity,
|
||||
"label": label,
|
||||
"message": f"费用明细第 {index} 条:{message_detail}",
|
||||
"summary": summary,
|
||||
"points": points,
|
||||
}
|
||||
with_risk_business_stage(
|
||||
{
|
||||
"source": "attachment_analysis",
|
||||
"item_id": item.id,
|
||||
"severity": severity,
|
||||
"label": label,
|
||||
"message": f"费用明细第 {index} 条:{message_detail}",
|
||||
"summary": summary,
|
||||
"points": points,
|
||||
},
|
||||
"reimbursement",
|
||||
)
|
||||
)
|
||||
return derived_flags
|
||||
|
||||
@@ -412,6 +418,38 @@ class ExpenseClaimItemSyncMixin:
|
||||
]
|
||||
return preserved_flags + attachment_risk_flags
|
||||
|
||||
def _refresh_claim_platform_risk_preview_flags(self, claim: ExpenseClaim) -> None:
|
||||
if str(claim.expense_type or "").strip().lower().endswith("_application"):
|
||||
return
|
||||
evaluator = getattr(self, "evaluate_platform_risk_rules", None)
|
||||
if not callable(evaluator):
|
||||
return
|
||||
try:
|
||||
review = evaluator(claim, business_stage="reimbursement")
|
||||
except Exception:
|
||||
return
|
||||
platform_flags = list(review.get("flags") or []) if isinstance(review, dict) else []
|
||||
claim.risk_flags_json = self._merge_claim_platform_risk_preview_flags(
|
||||
claim,
|
||||
platform_flags,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _merge_claim_platform_risk_preview_flags(
|
||||
claim: ExpenseClaim,
|
||||
platform_flags: list[dict[str, Any]],
|
||||
) -> list[Any]:
|
||||
preserved_flags = [
|
||||
flag
|
||||
for flag in list(claim.risk_flags_json or [])
|
||||
if not (
|
||||
isinstance(flag, dict)
|
||||
and str(flag.get("source") or "").strip() == "submission_review"
|
||||
and str(flag.get("hit_source") or "").strip() == "rule_center"
|
||||
)
|
||||
]
|
||||
return preserved_flags + platform_flags
|
||||
|
||||
@staticmethod
|
||||
def _format_submission_blocked_message(issues: list[str]) -> str:
|
||||
normalized_issues = [str(issue or "").strip() for issue in issues if str(issue or "").strip()]
|
||||
|
||||
Reference in New Issue
Block a user