兼容性修改
parent
b33d83a287
commit
8f9ee65fe8
|
|
@ -168,8 +168,9 @@ def submit_work_order():
|
||||||
返回: 提交结果
|
返回: 提交结果
|
||||||
"""
|
"""
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
trace_id = data.get('trace_id')
|
# 统一转换为字符串类型,保持与创建工单时的类型一致
|
||||||
process_id = data.get('process_id')
|
trace_id = str(data.get('trace_id')) if data.get('trace_id') is not None else None
|
||||||
|
process_id = str(data.get('process_id')) if data.get('process_id') is not None else None
|
||||||
bolts = data.get('bolts', [])
|
bolts = data.get('bolts', [])
|
||||||
device_sn = data.get('device_sn')
|
device_sn = data.get('device_sn')
|
||||||
device_name = data.get('device_name')
|
device_name = data.get('device_name')
|
||||||
|
|
@ -260,15 +261,24 @@ def create_work_order():
|
||||||
"message": f"字段 {field} 不能为空"
|
"message": f"字段 {field} 不能为空"
|
||||||
}), 400
|
}), 400
|
||||||
|
|
||||||
# 构建工单数据
|
# 构建工单数据,统一类型
|
||||||
|
bolts = data.get('bolts', [])
|
||||||
|
normalized_bolts = []
|
||||||
|
for bolt in bolts:
|
||||||
|
normalized_bolt = bolt.copy()
|
||||||
|
# 统一bolt_id为字符串
|
||||||
|
if 'bolt_id' in normalized_bolt:
|
||||||
|
normalized_bolt['bolt_id'] = str(normalized_bolt['bolt_id'])
|
||||||
|
normalized_bolts.append(normalized_bolt)
|
||||||
|
|
||||||
order_data = {
|
order_data = {
|
||||||
"trace_id": data.get('trace_id'),
|
"trace_id": str(data.get('trace_id')),
|
||||||
"process_id": data.get('process_id'),
|
"process_id": str(data.get('process_id')),
|
||||||
"process_name": data.get('process_name', ''),
|
"process_name": data.get('process_name', ''),
|
||||||
"product_name": data.get('product_name', ''),
|
"product_name": data.get('product_name', ''),
|
||||||
"operator": data.get('operator', ''),
|
"operator": data.get('operator', ''),
|
||||||
"status": data.get('status', 'pending'),
|
"status": data.get('status', 'pending'),
|
||||||
"bolts": data.get('bolts', [])
|
"bolts": normalized_bolts
|
||||||
}
|
}
|
||||||
|
|
||||||
# 创建工单
|
# 创建工单
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
"description": "测试模式:失败也算成功,用于无钉子测试"
|
"description": "测试模式:失败也算成功,用于无钉子测试"
|
||||||
},
|
},
|
||||||
"torque_display": {
|
"torque_display": {
|
||||||
"decimal_mode": true,
|
"decimal_mode": false,
|
||||||
"description": "扭矩显示模式:decimal_mode=true时显示值除以10(如350显示为35.0),false时原样显示"
|
"description": "扭矩显示模式:decimal_mode=true时显示值除以10(如350显示为35.0),false时原样显示"
|
||||||
},
|
},
|
||||||
"bolt_default_config": {
|
"bolt_default_config": {
|
||||||
|
|
|
||||||
|
|
@ -606,8 +606,26 @@ class WrenchGUI:
|
||||||
|
|
||||||
def update_order_list(self, orders):
|
def update_order_list(self, orders):
|
||||||
"""更新工单列表(只在数据变化时更新,并保持选中状态)"""
|
"""更新工单列表(只在数据变化时更新,并保持选中状态)"""
|
||||||
|
# 统一数据类型:将trace_id、process_id、bolt_id转换为字符串
|
||||||
|
normalized_orders = []
|
||||||
|
for order in orders:
|
||||||
|
normalized_order = order.copy()
|
||||||
|
if 'trace_id' in normalized_order:
|
||||||
|
normalized_order['trace_id'] = str(normalized_order['trace_id'])
|
||||||
|
if 'process_id' in normalized_order:
|
||||||
|
normalized_order['process_id'] = str(normalized_order['process_id'])
|
||||||
|
if 'bolts' in normalized_order:
|
||||||
|
normalized_bolts = []
|
||||||
|
for bolt in normalized_order['bolts']:
|
||||||
|
normalized_bolt = bolt.copy()
|
||||||
|
if 'bolt_id' in normalized_bolt:
|
||||||
|
normalized_bolt['bolt_id'] = str(normalized_bolt['bolt_id'])
|
||||||
|
normalized_bolts.append(normalized_bolt)
|
||||||
|
normalized_order['bolts'] = normalized_bolts
|
||||||
|
normalized_orders.append(normalized_order)
|
||||||
|
|
||||||
# 检查数据是否真的变化了
|
# 检查数据是否真的变化了
|
||||||
if self._orders_equal(orders, self.cached_orders):
|
if self._orders_equal(normalized_orders, self.cached_orders):
|
||||||
return # 数据没有变化,不更新
|
return # 数据没有变化,不更新
|
||||||
|
|
||||||
# 保存当前选中状态
|
# 保存当前选中状态
|
||||||
|
|
@ -619,7 +637,7 @@ class WrenchGUI:
|
||||||
self.selected_process_id = item_values[1]
|
self.selected_process_id = item_values[1]
|
||||||
|
|
||||||
# 更新缓存
|
# 更新缓存
|
||||||
self.cached_orders = orders.copy()
|
self.cached_orders = normalized_orders.copy()
|
||||||
|
|
||||||
# 清空并重新填充列表
|
# 清空并重新填充列表
|
||||||
self.order_tree.delete(*self.order_tree.get_children())
|
self.order_tree.delete(*self.order_tree.get_children())
|
||||||
|
|
@ -699,26 +717,41 @@ class WrenchGUI:
|
||||||
|
|
||||||
def on_order_select(self, event):
|
def on_order_select(self, event):
|
||||||
"""工单选择事件处理 - 显示作业列表预览"""
|
"""工单选择事件处理 - 显示作业列表预览"""
|
||||||
|
self.log(f"🔍 工单选择事件触发")
|
||||||
selected = self.order_tree.selection()
|
selected = self.order_tree.selection()
|
||||||
if not selected:
|
if not selected:
|
||||||
|
self.log(f"🔍 没有选中的工单")
|
||||||
return
|
return
|
||||||
|
|
||||||
item = self.order_tree.item(selected[0])
|
item = self.order_tree.item(selected[0])
|
||||||
values = item['values']
|
values = item['values']
|
||||||
trace_id = values[0]
|
trace_id = values[0]
|
||||||
process_id = values[1]
|
process_id = values[1]
|
||||||
|
self.log(f"🔍 选中工单: trace_id={trace_id}, process_id={process_id}")
|
||||||
|
self.log(f"🔍 cached_orders数量: {len(self.cached_orders)}")
|
||||||
|
|
||||||
# 从缓存中查找工单数据
|
# 从缓存中查找工单数据
|
||||||
|
found = False
|
||||||
for order in self.cached_orders:
|
for order in self.cached_orders:
|
||||||
if order.get('trace_id') == trace_id and order.get('process_id') == process_id:
|
order_trace_id = order.get('trace_id')
|
||||||
|
order_process_id = order.get('process_id')
|
||||||
|
self.log(f"🔍 比较: 选中={trace_id}({type(trace_id).__name__}), {process_id}({type(process_id).__name__}) vs 缓存={order_trace_id}({type(order_trace_id).__name__}), {order_process_id}({type(order_process_id).__name__})")
|
||||||
|
if str(order.get('trace_id')) == str(trace_id) and str(order.get('process_id')) == str(process_id):
|
||||||
|
self.log(f"🔍 找到匹配的工单,调用preview_bolt_list")
|
||||||
self.preview_bolt_list(order)
|
self.preview_bolt_list(order)
|
||||||
|
found = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if not found:
|
||||||
|
self.log(f"⚠️ 在cached_orders中未找到匹配的工单", "WARN")
|
||||||
|
|
||||||
def preview_bolt_list(self, order_data):
|
def preview_bolt_list(self, order_data):
|
||||||
"""预览作业列表(认领前)"""
|
"""预览作业列表(认领前)"""
|
||||||
|
self.log(f"🔍 预览工单数据: {order_data}")
|
||||||
self.tree.delete(*self.tree.get_children())
|
self.tree.delete(*self.tree.get_children())
|
||||||
|
|
||||||
bolts = order_data.get('bolts', [])
|
bolts = order_data.get('bolts', [])
|
||||||
|
self.log(f"🔍 预览bolts数量: {len(bolts)}")
|
||||||
for bolt in bolts:
|
for bolt in bolts:
|
||||||
self.tree.insert("", tk.END, values=(
|
self.tree.insert("", tk.END, values=(
|
||||||
bolt.get('bolt_id'),
|
bolt.get('bolt_id'),
|
||||||
|
|
@ -756,17 +789,28 @@ class WrenchGUI:
|
||||||
if not self.work_order:
|
if not self.work_order:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.log(f"🔍 update_bolt_order被调用,当前bolts数量: {len(self.work_order.get('bolts', []))}")
|
||||||
|
|
||||||
# 从树形控件读取新顺序
|
# 从树形控件读取新顺序
|
||||||
new_bolts = []
|
new_bolts = []
|
||||||
for item in self.tree.get_children():
|
for item in self.tree.get_children():
|
||||||
values = self.tree.item(item)['values']
|
values = self.tree.item(item)['values']
|
||||||
bolt_id = values[0]
|
bolt_id = values[0]
|
||||||
# 在原始作业列表中找到对应的作业
|
self.log(f"🔍 从树形控件读取 bolt_id: {bolt_id} (类型: {type(bolt_id).__name__})")
|
||||||
|
|
||||||
|
# 在原始作业列表中找到对应的作业(统一转换为字符串比较)
|
||||||
|
found = False
|
||||||
for bolt in self.work_order.get('bolts', []):
|
for bolt in self.work_order.get('bolts', []):
|
||||||
if bolt.get('bolt_id') == bolt_id:
|
bolt_id_in_order = bolt.get('bolt_id')
|
||||||
|
self.log(f"🔍 比较: 树形控件={bolt_id}({type(bolt_id).__name__}) vs work_order={bolt_id_in_order}({type(bolt_id_in_order).__name__})")
|
||||||
|
if str(bolt.get('bolt_id')) == str(bolt_id):
|
||||||
new_bolts.append(bolt)
|
new_bolts.append(bolt)
|
||||||
|
found = True
|
||||||
break
|
break
|
||||||
|
if not found:
|
||||||
|
self.log(f"⚠️ 未找到匹配的bolt_id: {bolt_id}", "WARN")
|
||||||
|
|
||||||
|
self.log(f"🔍 update_bolt_order完成,new_bolts数量: {len(new_bolts)}")
|
||||||
# 更新work_order中的作业顺序
|
# 更新work_order中的作业顺序
|
||||||
self.work_order['bolts'] = new_bolts
|
self.work_order['bolts'] = new_bolts
|
||||||
|
|
||||||
|
|
@ -795,7 +839,24 @@ class WrenchGUI:
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
result = response.json()
|
result = response.json()
|
||||||
if result.get("success"):
|
if result.get("success"):
|
||||||
self.work_order = result.get("data")
|
self.log(f"🔍 后端返回的原始数据: {result.get('data')}")
|
||||||
|
# 统一数据类型
|
||||||
|
work_order = result.get("data")
|
||||||
|
if work_order:
|
||||||
|
if 'trace_id' in work_order:
|
||||||
|
work_order['trace_id'] = str(work_order['trace_id'])
|
||||||
|
if 'process_id' in work_order:
|
||||||
|
work_order['process_id'] = str(work_order['process_id'])
|
||||||
|
if 'bolts' in work_order:
|
||||||
|
normalized_bolts = []
|
||||||
|
for bolt in work_order['bolts']:
|
||||||
|
normalized_bolt = bolt.copy()
|
||||||
|
if 'bolt_id' in normalized_bolt:
|
||||||
|
normalized_bolt['bolt_id'] = str(normalized_bolt['bolt_id'])
|
||||||
|
normalized_bolts.append(normalized_bolt)
|
||||||
|
work_order['bolts'] = normalized_bolts
|
||||||
|
self.work_order = work_order
|
||||||
|
self.log(f"🔍 保存到work_order后: {self.work_order}")
|
||||||
self.can_sort = True # 认领后允许排序
|
self.can_sort = True # 认领后允许排序
|
||||||
self.update_work_order_info()
|
self.update_work_order_info()
|
||||||
self.update_bolt_list()
|
self.update_bolt_list()
|
||||||
|
|
@ -1062,6 +1123,8 @@ class WrenchGUI:
|
||||||
|
|
||||||
# 遍历所有作业
|
# 遍历所有作业
|
||||||
bolts = self.work_order.get('bolts', [])
|
bolts = self.work_order.get('bolts', [])
|
||||||
|
self.log(f"📋 工单中的作业数量: {len(bolts)}")
|
||||||
|
self.log(f"📋 作业数据: {bolts}")
|
||||||
bolt_results = []
|
bolt_results = []
|
||||||
|
|
||||||
for index, bolt in enumerate(bolts):
|
for index, bolt in enumerate(bolts):
|
||||||
|
|
@ -1094,6 +1157,7 @@ class WrenchGUI:
|
||||||
|
|
||||||
def process_bolt(self, bolt, index):
|
def process_bolt(self, bolt, index):
|
||||||
"""处理单个作业"""
|
"""处理单个作业"""
|
||||||
|
self.log(f"🔧 处理作业 #{index+1}, 原始数据: {bolt}")
|
||||||
bolt_id = bolt.get('bolt_id')
|
bolt_id = bolt.get('bolt_id')
|
||||||
bolt_name = bolt.get('name')
|
bolt_name = bolt.get('name')
|
||||||
target_torque = bolt.get('target_torque')
|
target_torque = bolt.get('target_torque')
|
||||||
|
|
@ -1106,6 +1170,12 @@ class WrenchGUI:
|
||||||
|
|
||||||
# 设定参数
|
# 设定参数
|
||||||
self.log(f"设定参数: 扭矩={self.format_torque(target_torque)}Nm, 模式=M{bolt.get('mode', 1)}")
|
self.log(f"设定参数: 扭矩={self.format_torque(target_torque)}Nm, 模式=M{bolt.get('mode', 1)}")
|
||||||
|
self.log(f"🔧 扳手对象状态: {self.wrench is not None}, is_running: {self.is_running}")
|
||||||
|
|
||||||
|
if not self.wrench:
|
||||||
|
self.log("❌ 扳手对象为None,无法设置参数", "ERROR")
|
||||||
|
return None
|
||||||
|
|
||||||
self.wrench.set_torque_parameters(
|
self.wrench.set_torque_parameters(
|
||||||
target_torque=target_torque,
|
target_torque=target_torque,
|
||||||
mode=bolt.get('mode', 1),
|
mode=bolt.get('mode', 1),
|
||||||
|
|
@ -1118,6 +1188,7 @@ class WrenchGUI:
|
||||||
attempt = 0
|
attempt = 0
|
||||||
result_data = None
|
result_data = None
|
||||||
|
|
||||||
|
self.log(f"🔄 进入拧紧循环,is_running={self.is_running}")
|
||||||
while self.is_running:
|
while self.is_running:
|
||||||
attempt += 1
|
attempt += 1
|
||||||
self.log(f"第 {attempt} 次尝试拧紧作业 {bolt_id}")
|
self.log(f"第 {attempt} 次尝试拧紧作业 {bolt_id}")
|
||||||
|
|
@ -1132,6 +1203,7 @@ class WrenchGUI:
|
||||||
# 等待结果
|
# 等待结果
|
||||||
self.log("等待扳手响应...")
|
self.log("等待扳手响应...")
|
||||||
result = self.wrench.wait_for_result()
|
result = self.wrench.wait_for_result()
|
||||||
|
self.log(f"📊 收到结果: {result}")
|
||||||
|
|
||||||
if result and result.get("success"):
|
if result and result.get("success"):
|
||||||
# 成功
|
# 成功
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue