76 lines
2.1 KiB
Python
76 lines
2.1 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
创建工单示例
|
|
演示如何使用API创建工单
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
|
|
API_BASE_URL = "http://localhost:5000/api"
|
|
|
|
def create_work_order():
|
|
"""创建工单示例"""
|
|
|
|
# 工单数据
|
|
order_data = {
|
|
"trace_id": "TR20260119001",
|
|
"process_id": "P001",
|
|
"process_name": "前轮装配",
|
|
"product_name": "汽车底盘组件",
|
|
"station": "装配工位A1",
|
|
"operator": "张三",
|
|
"status": "pending",
|
|
"bolts": [
|
|
{
|
|
"bolt_id": 1,
|
|
"name": "前轮螺栓1",
|
|
"target_torque": 280,
|
|
"mode": 1,
|
|
"torque_tolerance": 0.10,
|
|
"angle_min": 1,
|
|
"angle_max": 360,
|
|
"status": "pending"
|
|
},
|
|
{
|
|
"bolt_id": 2,
|
|
"name": "前轮螺栓2",
|
|
"target_torque": 300,
|
|
"mode": 1,
|
|
"torque_tolerance": 0.10,
|
|
"angle_min": 1,
|
|
"angle_max": 360,
|
|
"status": "pending"
|
|
}
|
|
]
|
|
}
|
|
|
|
try:
|
|
# 发送创建请求
|
|
url = f"{API_BASE_URL}/work-orders/create"
|
|
response = requests.post(url, json=order_data, timeout=5)
|
|
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
if result.get("success"):
|
|
print("[OK] 工单创建成功")
|
|
print(f" 追溯号: {result['data']['trace_id']}")
|
|
print(f" 工序号: {result['data']['process_id']}")
|
|
else:
|
|
print(f"[FAIL] 创建失败: {result.get('message')}")
|
|
else:
|
|
print(f"[FAIL] HTTP错误: {response.status_code}")
|
|
print(response.text)
|
|
|
|
except requests.exceptions.RequestException as e:
|
|
print(f"[FAIL] 请求失败: {e}")
|
|
print("请确保后端服务器已启动 (python app.py)")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("="*60)
|
|
print("创建工单示例")
|
|
print("="*60)
|
|
create_work_order()
|