feat: 处理审批接口

This commit is contained in:
martsforever
2025-08-24 16:25:46 +08:00
parent d1c29455ab
commit af184259cd
+24 -1
View File
@@ -1,12 +1,14 @@
from fastapi import FastAPI
from langchain_core.runnables import RunnableConfig
from langgraph.func import entrypoint
from langgraph.types import Command
from pydantic import BaseModel, Field
from app.model.ApproveModel import ApproveService
from app.model.ReimburseModel import ReimburseService, ReimburseModel
from app.utils.db_utils import AsyncSessionDep
from app.utils.postgres_checkpointer import AsyncPostgresSaverDep
from app.workflow.approve import create_approve_workflow, ApproveWorkflowInputs
from app.workflow.approve import create_approve_workflow, ApproveWorkflowInputs, ApproveResult
def add_approve_route(app: FastAPI):
@@ -61,6 +63,27 @@ def add_approve_route(app: FastAPI):
return {"message": "报销单提交成功!"}
class ProcessApproveClass(BaseModel):
flag: bool = Field(..., description="审批标识,是审批通过还是审批驳回")
reason: str = Field(default=None, description="审批驳回原因")
user_id: str = Field(..., description="审批人id")
approve_id: str = Field(..., description="审批单id")
# 审批接口
@app.post('/process_approve')
async def process_approve(
body: ProcessApproveClass,
session: AsyncSessionDep,
checkpointer: AsyncPostgresSaverDep,
):
reimburse_workflow = create_reimburse_workflow(session=session, checkpointer=checkpointer)
approve_result: ApproveResult = {
"flag": body.flag,
"reason": body.reason,
"user_id": body.user_id,
}
await reimburse_workflow.ainvoke(Command(resume=approve_result), config={"configurable": {"thread_id": body.approve_id}})
def create_reimburse_workflow(
checkpointer: AsyncPostgresSaverDep,