From 645ce6ac1da6c46646bb5d2757c9037002532798 Mon Sep 17 00:00:00 2001 From: martsforever Date: Mon, 8 Sep 2025 22:27:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B5=B0=E9=85=92=E5=BA=97=E9=A2=84?= =?UTF-8?q?=E5=AE=9A=E3=80=81=E6=88=96=E8=80=85=E6=8F=90=E4=BA=A4=E6=8A=A5?= =?UTF-8?q?=E9=94=80=E5=8D=95=E5=AE=A1=E6=89=B9=E6=B5=81=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B0=83=E7=94=A8AI=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=EF=BC=8C=E5=AF=B9=E6=AF=94=E6=8A=A5=E9=94=80=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E4=B8=8E=E6=8A=A5=E9=94=80=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=BB=99=E5=87=BA=E5=AE=A1=E6=89=B9=E6=A0=87=E8=AF=86=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E5=AE=A1=E6=89=B9=E4=B8=8D=E9=80=9A=E8=BF=87=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/add_hotel_route.py | 62 ++++++++++++++++++--------- app/controller/add_reimburse_route.py | 2 +- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/app/controller/add_hotel_route.py b/app/controller/add_hotel_route.py index 1d28801..7068fa2 100644 --- a/app/controller/add_hotel_route.py +++ b/app/controller/add_hotel_route.py @@ -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, diff --git a/app/controller/add_reimburse_route.py b/app/controller/add_reimburse_route.py index df4b812..3bf772e 100644 --- a/app/controller/add_reimburse_route.py +++ b/app/controller/add_reimburse_route.py @@ -37,7 +37,7 @@ def add_reimburse_route(app: FastAPI): if reimburse_cls.approve.status == 'approved': return {"message": "报销单已通过审批,请勿重复提交!"} - llm_response_dict = await get_llm_approve_result(session, reimburse_cls) + llm_response_dict = await get_llm_approve_result(session, reimburse_cls.model_dump()) # 1,4,5 的情况下新建审批单 # 创建审批单,使用新的审批单走审批流程