feat: 接入dify工作流来控制审批流程
This commit is contained in:
@@ -3,6 +3,7 @@ import json
|
||||
from typing import List
|
||||
from typing import TypedDict, Union
|
||||
|
||||
import httpx
|
||||
from langgraph.constants import START
|
||||
from langgraph.graph import StateGraph
|
||||
from langgraph.types import interrupt, Command
|
||||
@@ -70,12 +71,16 @@ def create_approve_graph(
|
||||
if approve_result.get('flag'):
|
||||
# 审批回执标识为通过
|
||||
|
||||
# 当前审批人的id
|
||||
user_id = approve_result.get('user_id')
|
||||
# 审批单id
|
||||
approve_id = state.get('input_approve_id')
|
||||
|
||||
# 下一个准备要审批的上级主管用户
|
||||
supervisor_user = await aget_supervisor_user(user_id=user_id, session=session)
|
||||
|
||||
user_cls: UserServiceModel = await UserService.query_item(session=session, row_dict={"id": user_id})
|
||||
|
||||
print('\n\n', ":::::::::::node_supervisor_approve start::::::::::::", '\n\n')
|
||||
print(supervisor_user.full_name if supervisor_user else '无上级主管', user_id, approve_id)
|
||||
print('\n\n', ":::::::::::node_supervisor_approve end::::::::::::", '\n\n')
|
||||
@@ -85,6 +90,31 @@ def create_approve_graph(
|
||||
# 审批通过
|
||||
return Command(goto="node_accept", update={})
|
||||
else:
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.post(
|
||||
url="http://110.42.233.30:8055/v1/workflows/run",
|
||||
headers={
|
||||
"Authorization": f"Bearer app-ujHKbO9PFFmgarVutW5TdBaC"
|
||||
},
|
||||
json={
|
||||
"inputs": {
|
||||
"approve_pos_level": user_cls.pos.pos_level,
|
||||
"amount": state.get('input_amount')
|
||||
},
|
||||
"user": "abc-123"
|
||||
},
|
||||
|
||||
)
|
||||
result = response.json()
|
||||
print('\n\n', ":::::::::::httpx.AsyncClient start::::::::::::", '\n\n')
|
||||
print(result)
|
||||
print('\n\n', ":::::::::::httpx.AsyncClient end::::::::::::", '\n\n')
|
||||
is_need_supervisor_approve = result.get('data').get('outputs').get('flag')
|
||||
|
||||
if is_need_supervisor_approve == "Y":
|
||||
# 审批通过
|
||||
return Command(goto="node_accept", update={})
|
||||
|
||||
# 还有上级主管,继续触发下一个上级主管审批
|
||||
return Command(
|
||||
update={"update_approve": {
|
||||
@@ -192,6 +222,7 @@ class NodeUpdateApproveSchema(TypedDict):
|
||||
class ApproveGraphSchema(TypedDict):
|
||||
input_user_id: str
|
||||
input_approve_id: str
|
||||
input_amount: str
|
||||
|
||||
# 更新审批信息数据,用来执行节点:node_update_approve(入参),实际就是指派哪个用户来审批
|
||||
update_approve: NodeUpdateApproveSchema
|
||||
|
||||
Reference in New Issue
Block a user