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

This commit is contained in:
martsforever
2025-09-08 22:27:35 +08:00
parent f320682c49
commit 645ce6ac1d
2 changed files with 43 additions and 21 deletions
+42 -20
View File
@@ -1,3 +1,5 @@
import uuid
from fastapi import FastAPI
from langchain_core.runnables import RunnableConfig
from langgraph.constants import START
@@ -7,10 +9,13 @@ from pydantic import BaseModel
from app.model.ApproveModel import ApproveModel, ApproveService
from app.model.HotelModel import HotelService, HotelModel
from app.model.OrderModel import OrderService
from app.model.ReimburseModel import ReimburseService
from app.model.ProjectModel import ProjectModel
from app.model.ProjectService import ProjectService
from app.model.ReimburseModel import ReimburseService, ReimburseModel
from app.model.ReimburseOtherModel import ReimburseOtherService
from app.model.UserModel import UserServiceModel, UserService
from app.utils.db_utils import AsyncSessionDep
from app.utils.db_utils import AsyncSessionDep, async_session
from app.utils.llm_approve_utils import get_llm_approve_result
from app.utils.postgres_checkpointer import AsyncPostgresSaverDep
from app.workflow.approve import create_approve_graph, ApproveGraphSchema
@@ -22,11 +27,43 @@ def add_hotel_route(app: FastAPI):
session: AsyncSessionDep,
checkpointer: AsyncPostgresSaverDep,
):
user_cls: UserServiceModel = await UserService.query_item(session, row_dict={"id": body.user_id})
hotel_cls: HotelModel = await HotelService.query_item(session, row_dict={"id": body.hotel_id})
async with async_session() as session2:
user_cls: UserServiceModel = await UserService.query_item(session2, row_dict={"id": body.user_id})
hotel_cls: HotelModel = await HotelService.query_item(session2, row_dict={"id": body.hotel_id})
project_cls: ProjectModel = await ProjectService.query_item(session2, row_dict={"id": body.proj_id})
new_approve_id = str(uuid.uuid4())
reimburse_id = str(uuid.uuid4())
# 审批通过之后,要创建的报销单信息
input_reimburse_dict = {
"id": reimburse_id,
"title": f"{user_cls.full_name} - 酒店预定",
"remarks": f"酒店预定信息:{hotel_cls.title}, {hotel_cls.description}, {hotel_cls.discount_price}",
"proj_id": body.proj_id,
"amount": str(hotel_cls.discount_price),
"project": project_cls.model_dump(),
"approve_id": new_approve_id,
"user_id": body.user_id,
}
input_reimburse_other_dict = {
"title": f"{user_cls.full_name} - 酒店预定",
"type": "酒店宾馆",
"amount": str(hotel_cls.discount_price),
"recipe_type": "电子普通发票",
"reimburse_id": reimburse_id,
}
llm_response_dict = await get_llm_approve_result(session, {
**input_reimburse_dict,
"user": user_cls.model_dump(),
"travel_list": [],
"other_list": [input_reimburse_other_dict]
})
# 新建审批单信息
new_approve_dict = {
"id": new_approve_id,
"title": f"{user_cls.full_name} - 酒店预定审批",
"description": f"酒店预定信息:{hotel_cls.title}, {hotel_cls.description}, {hotel_cls.discount_price}",
"status": "approving",
@@ -36,28 +73,13 @@ def add_hotel_route(app: FastAPI):
"apply_user_id": body.user_id,
"proj_id": body.proj_id,
"approve_from": "book_hotel",
**llm_response_dict,
}
# 马上插入审批单信息
insert_approve_cls: ApproveModel = await ApproveService.item_insert(session=session, row_dict=new_approve_dict)
book_hotel_graph = create_book_hotel_graph(session=session, checkpointer=checkpointer)
# 审批通过之后,要创建的报销单信息
input_reimburse_dict = {
"title": f"{user_cls.full_name} - 酒店预定",
"remarks": f"酒店预定信息:{hotel_cls.title}, {hotel_cls.description}, {hotel_cls.discount_price}",
"proj_id": body.proj_id,
"approve_id": insert_approve_cls.id,
"user_id": body.user_id,
}
input_reimburse_other_dict = {
"title": f"{user_cls.full_name} - 酒店预定",
"type": "酒店宾馆",
"amount": str(hotel_cls.discount_price),
"recipy_type": "电子普通发票",
"reimburse_id": "",
}
graph_state = await book_hotel_graph.ainvoke(
{
"input_user_id": body.user_id,