zhouhui.jiang

update

...@@ -13,7 +13,7 @@ API_CONFIG = { ...@@ -13,7 +13,7 @@ API_CONFIG = {
13 "headers": { 13 "headers": {
14 "accept": "*/*", 14 "accept": "*/*",
15 "Content-Type": "application/json", 15 "Content-Type": "application/json",
16 - "Authorization": os.getenv("API_AUTHORIZATION", "Bearer 2.343fa30a6a4d42b6afe62bdd0570a50b"), 16 + "Authorization": os.getenv("API_AUTHORIZATION", "Bearer 2.72961203173b48f8975ea6eb8667e05f"),
17 "Ver": os.getenv("API_VER", "033BD94B1168D7E4F0D644C3C95E35BF.D73E33B659AD1D6B7D181D1DF8D05760"), 17 "Ver": os.getenv("API_VER", "033BD94B1168D7E4F0D644C3C95E35BF.D73E33B659AD1D6B7D181D1DF8D05760"),
18 "Referer": os.getenv("API_REFERER", "http://192.168.1.251/") 18 "Referer": os.getenv("API_REFERER", "http://192.168.1.251/")
19 } 19 }
......
...@@ -96,24 +96,21 @@ def create_waybill_d(consignmentCode: str) -> str: ...@@ -96,24 +96,21 @@ def create_waybill_d(consignmentCode: str) -> str:
96 waybill_id = extra.get('id') 96 waybill_id = extra.get('id')
97 code = extra.get('consignmentCode') or consignmentCode or "" 97 code = extra.get('consignmentCode') or consignmentCode or ""
98 98
99 - # 若拿不到ID,严格按目标格式返回(字段留空) 99 + # 初始化返回数据
100 + result_data = {
101 + "consignmentCode": code,
102 + "waybill_id": str(waybill_id) if waybill_id else "",
103 + "operate_unit_name": "",
104 + "operate_unit_code": "",
105 + "detailList": []
106 + }
107 +
108 + # 若拿不到ID,直接返回空数据
100 if not waybill_id: 109 if not waybill_id:
101 - lines = [ 110 + return json.dumps(result_data, ensure_ascii=False, indent=2)
102 - f"运单号:{code} 的D类运单已成功创建。", 111 +
103 - f"运单号:{code}", 112 + # 请求表头详情获取 operate_unit_name 和 operate_unit_code
104 - "\t公司信息",
105 - "\t发件人公司:",
106 - "\t海关编码:",
107 - "\t商品明细信息",
108 - "\t出口商品编码:",
109 - "\t中文品名:",
110 - ]
111 - return "\n".join(lines)
112 -
113 - # 直接请求表头详情(不引入额外文本,空值留空)
114 head_url = f"{API_CONFIG['base_url']}/Exp/bus-customer/consignment/headInfo" 113 head_url = f"{API_CONFIG['base_url']}/Exp/bus-customer/consignment/headInfo"
115 - operate_unit_name = ""
116 - operate_unit_code = ""
117 try: 114 try:
118 head_resp = requests.post( 115 head_resp = requests.post(
119 head_url, 116 head_url,
...@@ -124,21 +121,19 @@ def create_waybill_d(consignmentCode: str) -> str: ...@@ -124,21 +121,19 @@ def create_waybill_d(consignmentCode: str) -> str:
124 if head_resp.status_code == 200: 121 if head_resp.status_code == 200:
125 head_json = head_resp.json() 122 head_json = head_resp.json()
126 head_extra = (head_json.get("data") or {}).get("extra") or {} 123 head_extra = (head_json.get("data") or {}).get("extra") or {}
127 - operate_unit_name = head_extra.get("operateUnitName") or "" 124 + result_data["operate_unit_name"] = head_extra.get("operateUnitName") or ""
128 - operate_unit_code = head_extra.get("operateUnitCode") or "" 125 + result_data["operate_unit_code"] = head_extra.get("operateUnitCode") or ""
129 except Exception: 126 except Exception:
130 pass 127 pass
131 128
132 - # 直接请求表体明细(取第一条,空值留空 129 + # 请求表体明细获取所有商品明细(sku_code 和 sku_name
133 detail_url = f"{API_CONFIG['base_url']}/Exp/bus-customer/consignment/detail/list" 130 detail_url = f"{API_CONFIG['base_url']}/Exp/bus-customer/consignment/detail/list"
134 - sku_code = ""
135 - sku_name = ""
136 try: 131 try:
137 detail_payload = { 132 detail_payload = {
138 "consType": "consType_D", 133 "consType": "consType_D",
139 "consignmentId": waybill_id, 134 "consignmentId": waybill_id,
140 "pageIndex": 1, 135 "pageIndex": 1,
141 - "pageSize": 5, 136 + "pageSize": 100, # 增加页面大小以获取更多记录
142 } 137 }
143 detail_resp = requests.post( 138 detail_resp = requests.post(
144 detail_url, 139 detail_url,
...@@ -149,25 +144,20 @@ def create_waybill_d(consignmentCode: str) -> str: ...@@ -149,25 +144,20 @@ def create_waybill_d(consignmentCode: str) -> str:
149 if detail_resp.status_code == 200: 144 if detail_resp.status_code == 200:
150 detail_json = detail_resp.json() 145 detail_json = detail_resp.json()
151 records = (detail_json.get("data") or {}).get("records") or [] 146 records = (detail_json.get("data") or {}).get("records") or []
152 - if isinstance(records, list) and records: 147 + if isinstance(records, list):
153 - first = records[0] if isinstance(records[0], dict) else {} 148 + # 遍历所有记录,构建 detailList
154 - sku_code = first.get("skuCode") or "" 149 + for item in records:
155 - sku_name = first.get("skuName") or "" 150 + if isinstance(item, dict):
151 + detail_item = {
152 + "sku_code": item.get("skuCode") or "",
153 + "sku_name": item.get("skuName") or ""
154 + }
155 + result_data["detailList"].append(detail_item)
156 except Exception: 156 except Exception:
157 pass 157 pass
158 158
159 - # 严格按目标格式输出(不添加解释性文字、提示或建议) 159 + # 返回 JSON 格式数据
160 - lines = [ 160 + return json.dumps(result_data, ensure_ascii=False, indent=2)
161 - f"运单号:{code} 的D类运单已成功创建。",
162 - f"运单号:{code}",
163 - "\t公司信息",
164 - f"\t发件人公司:{operate_unit_name}",
165 - f"\t海关编码:{operate_unit_code}",
166 - "\t商品明细信息",
167 - f"\t出口商品编码:{sku_code}",
168 - f"\t中文品名:{sku_name}",
169 - ]
170 - return "\n".join(lines)
171 161
172 except requests.exceptions.RequestException as e: 162 except requests.exceptions.RequestException as e:
173 return f"❌ 网络请求失败: {str(e)}" 163 return f"❌ 网络请求失败: {str(e)}"
...@@ -230,9 +220,21 @@ def query_waybill_list(initialize: int = 1, consStatusName: str = "等待录入" ...@@ -230,9 +220,21 @@ def query_waybill_list(initialize: int = 1, consStatusName: str = "等待录入"
230 if not data: 220 if not data:
231 return f"查询成功: 未找到状态为 '{consStatusName}' 的运单记录。" 221 return f"查询成功: 未找到状态为 '{consStatusName}' 的运单记录。"
232 222
233 - # 生成 HTML 表格 223 + # 提取所需字段并返回 JSON 格式
234 - html_table = generate_waybill_table(data) 224 + result_list = []
235 - return f"查询成功: 找到 {len(data)} 条运单记录。状态: {consStatusName}\n\n{html_table}" 225 + for item in data:
226 + if isinstance(item, dict):
227 + result_item = {
228 + "consignmentCode": item.get('consignmentCode', ''),
229 + "consType": item.get('consType', ''),
230 + "consStatus": item.get('consStatus', ''),
231 + "sender": item.get('sender', ''),
232 + "createTime": item.get('createTime', '')
233 + }
234 + result_list.append(result_item)
235 +
236 + # 返回 JSON 格式数据
237 + return json.dumps(result_list, ensure_ascii=False, indent=2)
236 else: 238 else:
237 return f"查询失败: HTTP {response.status_code}, 错误信息: {response.text}" 239 return f"查询失败: HTTP {response.status_code}, 错误信息: {response.text}"
238 240
......
...@@ -110,14 +110,13 @@ agent = create_react_agent( ...@@ -110,14 +110,13 @@ agent = create_react_agent(
110 - 若调用了工具并获得结果,则必须将该工具返回的文本“原样作为最终答复”输出,不允许添加任何解释、建议或额外文字。 110 - 若调用了工具并获得结果,则必须将该工具返回的文本“原样作为最终答复”输出,不允许添加任何解释、建议或额外文字。
111 111
112 ## 可用工具: 112 ## 可用工具:
113 -- query_waybill_list: 查询运单列表,支持按状态筛选,结果以HTML表格形式展示 113 +- query_waybill_list: 查询运单列表,支持按状态筛选,结果以JSON形式展示
114 - create_waybill_d: 根据运单号创建D类运单,需要提供运单号参数 114 - create_waybill_d: 根据运单号创建D类运单,需要提供运单号参数
115 - upload_clearance_file: 上传清关PDF文件,需要 code、slip_id、pdf_path 115 - upload_clearance_file: 上传清关PDF文件,需要 code、slip_id、pdf_path
116 - push_waybill_for_ocr: 根据运单ID推送OCR进行识别,需要提供运单ID(waybill_id)参数 116 - push_waybill_for_ocr: 根据运单ID推送OCR进行识别,需要提供运单ID(waybill_id)参数
117 117
118 ## query_waybill_list数据展示说明: 118 ## query_waybill_list数据展示说明:
119 -- 运单查询结果会自动格式化为HTML表格,包含:运单号、运单类型、运单状态、发件人、运单日期 119 +- 运单查询结果会自动格式化为JSON形式展示,包含:运单号、运单类型、运单状态、发件人、运单日期
120 -- 表格在终端中会以HTML源码形式显示,用户可以在支持HTML的环境中查看格式化效果
121 - 空字段会显示为空单元格 120 - 空字段会显示为空单元格
122 - 运单创建结果会显示成功/失败状态和详细信息 121 - 运单创建结果会显示成功/失败状态和详细信息
123 122
......
No preview for this file type