feat: 本体字段治理与风险规则模板执行器重构
- 新增本体字段注册表与字段治理审计脚本 - 重构风险规则模板执行器、DSL 验证与清单分类器 - 完善票据夹服务与差旅请求详情页交互 - 优化趋势图表与总览页数据展示 - 增强报销平台风险分级与模拟公司筛选 - 补充本体字段、风险规则生成与票据夹服务测试覆盖
This commit is contained in:
@@ -13,6 +13,7 @@ from app.api.deps import get_db
|
||||
from app.db.base import Base
|
||||
from app.schemas.ontology import OntologyParseRequest
|
||||
from app.services.ontology import LlmOntologyParseResult, SemanticOntologyService
|
||||
from app.services.ontology_field_registry import normalize_ontology_context_json
|
||||
from app.services.runtime_chat import RuntimeChatCallTrace, RuntimeChatResult
|
||||
|
||||
|
||||
@@ -866,6 +867,64 @@ def test_semantic_ontology_service_treats_application_session_as_application_con
|
||||
assert "amount" in result.missing_slots
|
||||
|
||||
|
||||
def test_semantic_ontology_service_normalizes_business_aliases_to_ontology_fields(
|
||||
monkeypatch,
|
||||
) -> None:
|
||||
session_factory = build_session_factory()
|
||||
with session_factory() as db:
|
||||
service = SemanticOntologyService(db)
|
||||
monkeypatch.setattr(
|
||||
service,
|
||||
"_parse_with_model",
|
||||
lambda **kwargs: (None, [], "model_disabled_for_field_registry_test"),
|
||||
)
|
||||
|
||||
result = service.parse(
|
||||
OntologyParseRequest(
|
||||
query="生成差旅费报销草稿",
|
||||
user_id="pytest",
|
||||
context_json={
|
||||
"review_action": "save_draft",
|
||||
"review_form_values": {
|
||||
"reimbursement_type": "差旅费",
|
||||
"business_time": "2026-06-01 至 2026-06-03",
|
||||
"business_location": "上海",
|
||||
"reason_value": "支撑国网仿生产环境部署",
|
||||
"application_amount": "3000元",
|
||||
"transport_type": "火车",
|
||||
},
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
entity_map = {(item.type, item.normalized_value) for item in result.entities}
|
||||
assert ("transport_mode", "火车") in entity_map
|
||||
assert ("reason", "支撑国网仿生产环境部署") in entity_map
|
||||
assert ("location", "上海") in entity_map
|
||||
assert "time_range" not in result.missing_slots
|
||||
assert "reason" not in result.missing_slots
|
||||
|
||||
|
||||
def test_ontology_context_normalizes_employee_profile_aliases() -> None:
|
||||
context = normalize_ontology_context_json(
|
||||
{
|
||||
"name": "曹笑竹",
|
||||
"department": "技术部",
|
||||
"position": "财务智能化产品经理",
|
||||
"grade": "P5",
|
||||
"managerName": "向万红",
|
||||
"costCenter": "TECH-DEPT",
|
||||
}
|
||||
)
|
||||
|
||||
assert context["employee_name"] == "曹笑竹"
|
||||
assert context["department_name"] == "技术部"
|
||||
assert context["employee_position"] == "财务智能化产品经理"
|
||||
assert context["employee_grade"] == "P5"
|
||||
assert context["manager_name"] == "向万红"
|
||||
assert context["cost_center"] == "TECH-DEPT"
|
||||
|
||||
|
||||
def test_semantic_ontology_service_uses_model_parse_when_available(monkeypatch) -> None:
|
||||
session_factory = build_session_factory()
|
||||
with session_factory() as db:
|
||||
|
||||
Reference in New Issue
Block a user