feat: 新增风险规则生成引擎与知识图谱可视化
后端新增风险规则自动生成和模板执行服务,支持从规则资产 批量生成并持久化风险规则文件;知识库入库日志增强图谱 查询和本地 RAG 回退,前端审计页面增加风险规则模型和流 程图组件,知识入库面板拆分为图谱可视化子组件,报销创 建页面增加引导式流程模型,更新知识库索引数据。
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import threading
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
@@ -31,6 +33,8 @@ from app.services.agent_foundation_risk_rules import AgentFoundationRiskRuleMixi
|
||||
from app.services.agent_foundation_spreadsheets import AgentFoundationSpreadsheetMixin
|
||||
|
||||
logger = get_logger("app.services.agent_foundation")
|
||||
_foundation_ready_lock = threading.RLock()
|
||||
_foundation_ready_keys: set[str] = set()
|
||||
|
||||
|
||||
def prepare_agent_foundation() -> None:
|
||||
@@ -57,6 +61,17 @@ class AgentFoundationService(
|
||||
self.db = db
|
||||
|
||||
def ensure_foundation_ready(self) -> None:
|
||||
cache_key = self._foundation_cache_key()
|
||||
if cache_key in _foundation_ready_keys:
|
||||
return
|
||||
|
||||
with _foundation_ready_lock:
|
||||
if cache_key in _foundation_ready_keys:
|
||||
return
|
||||
self._prepare_foundation()
|
||||
_foundation_ready_keys.add(cache_key)
|
||||
|
||||
def _prepare_foundation(self) -> None:
|
||||
try:
|
||||
Base.metadata.create_all(bind=self.db.get_bind())
|
||||
self._ensure_agent_asset_schema()
|
||||
@@ -69,6 +84,10 @@ class AgentFoundationService(
|
||||
logger.exception("Failed to prepare agent foundation")
|
||||
raise
|
||||
|
||||
def _foundation_cache_key(self) -> str:
|
||||
bind = self.db.get_bind()
|
||||
return str(getattr(bind, "url", "") or id(bind))
|
||||
|
||||
def _sync_demo_financial_records(self) -> None:
|
||||
if get_settings().seed_demo_financial_records:
|
||||
self._seed_financial_records()
|
||||
|
||||
Reference in New Issue
Block a user