Toggle navigation
Toggle navigation
This project
Loading...
Sign in
zhouhui.jiang
/
Test_LangGraph
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
zhouhui.jiang
2025-11-16 21:00:41 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
34700691343756315d9638fb0b9652f532e03b09
34700691
1 parent
6407b6d0
update
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
10 deletions
API/waybill_api.py
API/waybill_api.py
View file @
3470069
...
...
@@ -9,6 +9,27 @@ import json
from
.api_config
import
API_CONFIG
def
_create_error_response
(
message
:
str
,
consignmentCode
:
str
)
->
str
:
"""创建错误响应的辅助函数
Args:
message: 错误消息
consignmentCode: 运单编号
Returns:
JSON格式的错误响应字符串
"""
error_data
=
{
"message"
:
message
,
"consignmentCode"
:
consignmentCode
,
"waybill_id"
:
""
,
"operate_unit_name"
:
""
,
"operate_unit_code"
:
""
,
"detailList"
:
[]
}
return
json
.
dumps
(
error_data
,
ensure_ascii
=
False
,
indent
=
2
)
def
create_waybill_d
(
consignmentCode
:
str
,
Authorization
:
str
=
None
)
->
str
:
"""根据运单号创建D类运单
...
...
@@ -18,6 +39,7 @@ def create_waybill_d(consignmentCode: str, Authorization: str = None) -> str:
Returns:
创建结果信息(JSON字符串),包含:
- message: 创建结果描述(成功时:"创建运单成功",失败时:具体的失败原因)
- consignmentCode: 运单编号
- waybill_id: 运单ID
- operate_unit_name: 操作单位名称
...
...
@@ -49,7 +71,10 @@ def create_waybill_d(consignmentCode: str, Authorization: str = None) -> str:
# 检查响应状态
if
response
.
status_code
!=
200
:
return
f
"❌ 创建失败: HTTP {response.status_code}, 错误信息: {response.text}"
return
_create_error_response
(
f
"创建运单失败: HTTP {response.status_code}, 错误信息: {response.text}"
,
consignmentCode
)
result
=
response
.
json
()
...
...
@@ -59,7 +84,7 @@ def create_waybill_d(consignmentCode: str, Authorization: str = None) -> str:
# 业务状态判定(保守容错)
if
result
.
get
(
'success'
)
is
False
:
error_msg
=
result
.
get
(
'message'
,
'未知错误'
)
return
f
"❌ 创建失败: {error_msg}"
return
_create_error_response
(
f
"创建运单失败: {error_msg}"
,
consignmentCode
)
# 提取新建的运单ID与编号
data
=
result
.
get
(
'data'
)
or
{}
...
...
@@ -78,6 +103,7 @@ def create_waybill_d(consignmentCode: str, Authorization: str = None) -> str:
# 若拿不到ID,直接返回空数据
if
not
waybill_id
:
result_data
[
"message"
]
=
"创建运单失败:未获取到运单ID"
return
json
.
dumps
(
result_data
,
ensure_ascii
=
False
,
indent
=
2
)
# 请求表头详情获取 operate_unit_name 和 operate_unit_code
...
...
@@ -127,15 +153,18 @@ def create_waybill_d(consignmentCode: str, Authorization: str = None) -> str:
except
Exception
:
pass
# 添加成功消息
result_data
[
"message"
]
=
"创建运单成功"
# 返回 JSON 格式数据
return
json
.
dumps
(
result_data
,
ensure_ascii
=
False
,
indent
=
2
)
except
requests
.
exceptions
.
RequestException
as
e
:
return
f
"❌ 网络请求失败: {str(e)}"
return
_create_error_response
(
f
"创建运单失败: 网络请求失败 - {str(e)}"
,
consignmentCode
)
except
json
.
JSONDecodeError
as
e
:
return
f
"❌ 响应解析失败: {str(e)}"
return
_create_error_response
(
f
"创建运单失败: 响应解析失败 - {str(e)}"
,
consignmentCode
)
except
Exception
as
e
:
return
f
"❌ 创建D类运单失败: {str(e)}"
return
_create_error_response
(
f
"创建运单失败: {str(e)}"
,
consignmentCode
)
def
create_waybill_d_with_id
(
...
...
@@ -211,6 +240,7 @@ def query_waybill_info(consignmentCode: str, Authorization: str = None) -> str:
Returns:
运单信息(JSON字符串),包含:
- message: 查询结果描述(成功时:"查询详情成功",失败时:具体的失败原因)
- consignmentCode: 运单编号
- waybill_id: 运单ID
- operate_unit_name: 操作单位名称
...
...
@@ -262,12 +292,16 @@ def query_waybill_info(consignmentCode: str, Authorization: str = None) -> str:
# 提取运单类型(用于后续查询明细)
cons_type_code
=
head_extra
.
get
(
"consTypeDicCode"
)
or
"consType_D"
else
:
return
f
"❌ 查询运单信息失败: HTTP {head_resp.status_code}, 错误信息: {head_resp.text}"
return
_create_error_response
(
f
"查询详情失败: HTTP {head_resp.status_code}, 错误信息: {head_resp.text}"
,
consignmentCode
)
except
Exception
as
e
:
return
f
"❌ 查询表头信息失败: {str(e)}"
return
_create_error_response
(
f
"查询详情失败: 查询表头信息失败 - {str(e)}"
,
consignmentCode
)
# 若拿不到ID,直接返回已有数据
if
not
waybill_id
:
result_data
[
"message"
]
=
"查询详情失败:未获取到运单ID"
return
json
.
dumps
(
result_data
,
ensure_ascii
=
False
,
indent
=
2
)
# 请求表体明细获取所有商品明细(sku_code 和 sku_name)
...
...
@@ -300,15 +334,18 @@ def query_waybill_info(consignmentCode: str, Authorization: str = None) -> str:
except
Exception
:
pass
# 添加成功消息
result_data
[
"message"
]
=
"查询详情成功"
# 返回 JSON 格式数据
return
json
.
dumps
(
result_data
,
ensure_ascii
=
False
,
indent
=
2
)
except
requests
.
exceptions
.
RequestException
as
e
:
return
f
"❌ 网络请求失败: {str(e)}"
return
_create_error_response
(
f
"查询详情失败: 网络请求失败 - {str(e)}"
,
consignmentCode
)
except
json
.
JSONDecodeError
as
e
:
return
f
"❌ 响应解析失败: {str(e)}"
return
_create_error_response
(
f
"查询详情失败: 响应解析失败 - {str(e)}"
,
consignmentCode
)
except
Exception
as
e
:
return
f
"❌ 查询运单信息失败: {str(e)}"
return
_create_error_response
(
f
"查询详情失败: {str(e)}"
,
consignmentCode
)
def
query_waybill_list
(
initialize
:
int
=
1
,
consStatusName
:
str
=
"等待录入"
,
Authorization
:
str
=
None
)
->
str
:
...
...
Please
register
or
login
to post a comment