feat: 走酒店预定、或者提交报销单审批流时,自动调用AI服务,对比报销规范文档与报销信息给出审批标识以及审批不通过时的意见

This commit is contained in:
martsforever
2025-09-08 22:28:01 +08:00
parent 645ce6ac1d
commit d5836c6fbf
+22 -23
View File
@@ -5,7 +5,6 @@ from langchain_core.prompts import ChatPromptTemplate
from pydantic import BaseModel, Field
from app.model.KnowledgeDoc import KnowledgeDocServiceWithCreator, KnowledgeDocModel
from app.model.ReimburseModel import ReimburseModel
from app.utils.db_utils import AsyncSessionDep
from app.utils.llm_utils import create_llm
@@ -15,7 +14,7 @@ class LlmApproveResult(BaseModel):
llm_reason: str | None = Field(default=None, description="审核不通过时的原因")
async def get_llm_approve_result(session: AsyncSessionDep, reimburse_cls: ReimburseModel):
async def get_llm_approve_result(session: AsyncSessionDep, reimburse_dict: dict):
try:
reimburse_document: KnowledgeDocModel = await KnowledgeDocServiceWithCreator.query_item(session, {"code": "REIMBURSE"})
except Exception as e:
@@ -37,7 +36,7 @@ async def get_llm_approve_result(session: AsyncSessionDep, reimburse_cls: Reimbu
print(reimburse_document.content)
print(":::::::::::::::报销单描述::::::::::::::::::::::::")
reimburse_description = get_reimburse_description(reimburse_cls)
reimburse_description = get_reimburse_description(reimburse_dict)
print(reimburse_description)
llm_response_content = await chain.ainvoke({
@@ -53,38 +52,38 @@ async def get_llm_approve_result(session: AsyncSessionDep, reimburse_cls: Reimbu
return llm_response_dict
def get_reimburse_description(reimrbuse_cls: ReimburseModel):
if not reimrbuse_cls.project:
def get_reimburse_description(reimburse_dict: dict):
if not reimburse_dict["project"]:
raise Exception("报销单关联项目不存在")
reimbruse_content = f"""
报销申请人:{reimrbuse_cls.user.full_name}
报销单标题:{str(reimrbuse_cls.title)}
报销单金额:{str(reimrbuse_cls.amount)}
报销单备注信息:{str(reimrbuse_cls.remarks)}
报销项目:{str(reimrbuse_cls.project.name)}
报销申请人:{reimburse_dict["user"]["full_name"]}
报销单标题:{str(reimburse_dict["title"])}
报销单金额:{str(reimburse_dict["amount"])}
报销单备注信息:{str(reimburse_dict["remarks"])}
报销项目:{str(reimburse_dict["project"]["name"])}
"""
for index, travel_item in enumerate(reimrbuse_cls.travel_list):
for index, travel_item in enumerate(reimburse_dict["travel_list"]):
reimbruse_content += f"""
第{index + 1}条差旅费用信息:
差旅费用名称:{travel_item.title}
差旅费用类型:{travel_item.type}
差旅出发时间:{travel_item.depart_time}
差旅出发地点:{travel_item.depart_city}
差旅到达时间:{travel_item.arrive_time}
差旅到达地点:{travel_item.arrive_city}
差旅报销金额:{travel_item.amount}
差旅费用名称:{travel_item["title"]}
差旅费用类型:{travel_item["type"]}
差旅出发时间:{travel_item["depart_time"]}
差旅出发地点:{travel_item["depart_city"]}
差旅到达时间:{travel_item["arrive_time"]}
差旅到达地点:{travel_item["arrive_city"]}
差旅报销金额:{travel_item["amount"]}
"""
for index, other_item in enumerate(reimrbuse_cls.other_list):
for index, other_item in enumerate(reimburse_dict["other_list"]):
reimbruse_content += f"""
第{index + 1}条费用信息:
费用名称:{other_item.title}
费用类型:{other_item.type}
报销金额:{other_item.amount}
票据类型:{other_item.recipe_type}
费用名称:{other_item["title"]}
费用类型:{other_item["type"]}
报销金额:{other_item["amount"]}
票据类型:{other_item["recipe_type"]}
"""
return reimbruse_content