83 lines
2.8 KiB
Python
83 lines
2.8 KiB
Python
|
|
from utils.api_utils import ApiUtils
|
||
|
|
import logging
|
||
|
|
import json
|
||
|
|
class GcApi:
|
||
|
|
def __init__(self):
|
||
|
|
"""初始化托盘API工具类"""
|
||
|
|
self.api_utils = ApiUtils()
|
||
|
|
|
||
|
|
def get_gc_info(self, gc_code):
|
||
|
|
"""
|
||
|
|
获取GC信息
|
||
|
|
|
||
|
|
Args:
|
||
|
|
gc_code: GC编号
|
||
|
|
|
||
|
|
Returns:
|
||
|
|
dict: GC信息
|
||
|
|
"""
|
||
|
|
try:
|
||
|
|
# API 配置中的键名
|
||
|
|
api_key = "get_gc_info"
|
||
|
|
# 构建 form-data 格式的数据
|
||
|
|
data = {
|
||
|
|
"sc_gch": gc_code,
|
||
|
|
"data_corp":"JT"
|
||
|
|
}
|
||
|
|
# 将工程号作为参数传递,使用 data 参数传递 form-data 格式数据
|
||
|
|
response = self.api_utils.post(api_key, data=data)
|
||
|
|
|
||
|
|
# 请求失败时返回空数据
|
||
|
|
if not response.get("status", False):
|
||
|
|
return {
|
||
|
|
"success": False,
|
||
|
|
"message": "获取GC信息失败",
|
||
|
|
"data": None
|
||
|
|
}
|
||
|
|
return response
|
||
|
|
except Exception as e:
|
||
|
|
logging.error(f"获取GC信息失败: {str(e)}")
|
||
|
|
return None
|
||
|
|
def get_order_info(self, order_code):
|
||
|
|
"""
|
||
|
|
获取订单信息
|
||
|
|
"""
|
||
|
|
try:
|
||
|
|
# API 配置中的键名
|
||
|
|
api_key = "get_order_info"
|
||
|
|
# 构建 form-data 格式的数据
|
||
|
|
order_dict = {"srch_mo":order_code,"data_corp":"JT"}
|
||
|
|
data = {
|
||
|
|
"parms": json.dumps(order_dict), # 必须将数据序列化为JSON字符串
|
||
|
|
"pageIndex": 0,
|
||
|
|
"pageSize": 10,
|
||
|
|
"sortField": "",
|
||
|
|
"sortOrder": ""
|
||
|
|
}
|
||
|
|
# 将工程号作为参数传递,使用 data 参数传递 form-data 格式数据
|
||
|
|
response = self.api_utils.post(api_key, data=data)
|
||
|
|
return response
|
||
|
|
except Exception as e:
|
||
|
|
logging.error(f"获取订单信息失败: {str(e)}")
|
||
|
|
return None
|
||
|
|
def add_order_info(self, info):
|
||
|
|
"""
|
||
|
|
添加订单信息
|
||
|
|
"""
|
||
|
|
try:
|
||
|
|
# API 配置中的键名
|
||
|
|
api_key = "add_order_info"
|
||
|
|
# 构建 form-data 格式的数据
|
||
|
|
data = {
|
||
|
|
"parms": json.dumps(info), # 必须将数据序列化为JSON字符串
|
||
|
|
"pageIndex": 0,
|
||
|
|
"pageSize": 10,
|
||
|
|
"sortField": "",
|
||
|
|
"sortOrder": ""
|
||
|
|
}
|
||
|
|
# 将工程号作为参数传递,使用 data 参数传递 form-data 格式数据
|
||
|
|
response = self.api_utils.post(api_key, data=data)
|
||
|
|
return response
|
||
|
|
except Exception as e:
|
||
|
|
logging.error(f"添加订单信息失败: {str(e)}")
|
||
|
|
return None
|