From 8f9ee65fe8e7248b1909bb238d38e4051a017cdf Mon Sep 17 00:00:00 2001 From: "COT001\\DEV" <871066422@qq.com> Date: Wed, 1 Apr 2026 18:39:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=80=A7=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app.py | 22 ++++++++--- config.json | 2 +- frontend/wrench_gui.py | 84 ++++++++++++++++++++++++++++++++++++++--- wrench.db | Bin 28672 -> 0 bytes 4 files changed, 95 insertions(+), 13 deletions(-) delete mode 100644 wrench.db diff --git a/backend/app.py b/backend/app.py index 600e1c6..51c417c 100644 --- a/backend/app.py +++ b/backend/app.py @@ -168,8 +168,9 @@ def submit_work_order(): 返回: 提交结果 """ 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', []) device_sn = data.get('device_sn') device_name = data.get('device_name') @@ -260,15 +261,24 @@ def create_work_order(): "message": f"字段 {field} 不能为空" }), 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 = { - "trace_id": data.get('trace_id'), - "process_id": data.get('process_id'), + "trace_id": str(data.get('trace_id')), + "process_id": str(data.get('process_id')), "process_name": data.get('process_name', ''), "product_name": data.get('product_name', ''), "operator": data.get('operator', ''), "status": data.get('status', 'pending'), - "bolts": data.get('bolts', []) + "bolts": normalized_bolts } # 创建工单 diff --git a/config.json b/config.json index 7c7988d..78d85ee 100644 --- a/config.json +++ b/config.json @@ -25,7 +25,7 @@ "description": "测试模式:失败也算成功,用于无钉子测试" }, "torque_display": { - "decimal_mode": true, + "decimal_mode": false, "description": "扭矩显示模式:decimal_mode=true时显示值除以10(如350显示为35.0),false时原样显示" }, "bolt_default_config": { diff --git a/frontend/wrench_gui.py b/frontend/wrench_gui.py index df11ec0..1a31cbf 100644 --- a/frontend/wrench_gui.py +++ b/frontend/wrench_gui.py @@ -606,8 +606,26 @@ class WrenchGUI: 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 # 数据没有变化,不更新 # 保存当前选中状态 @@ -619,7 +637,7 @@ class WrenchGUI: 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()) @@ -699,26 +717,41 @@ class WrenchGUI: def on_order_select(self, event): """工单选择事件处理 - 显示作业列表预览""" + self.log(f"🔍 工单选择事件触发") selected = self.order_tree.selection() if not selected: + self.log(f"🔍 没有选中的工单") return item = self.order_tree.item(selected[0]) values = item['values'] trace_id = values[0] 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: - 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) + found = True break + + if not found: + self.log(f"⚠️ 在cached_orders中未找到匹配的工单", "WARN") def preview_bolt_list(self, order_data): """预览作业列表(认领前)""" + self.log(f"🔍 预览工单数据: {order_data}") self.tree.delete(*self.tree.get_children()) bolts = order_data.get('bolts', []) + self.log(f"🔍 预览bolts数量: {len(bolts)}") for bolt in bolts: self.tree.insert("", tk.END, values=( bolt.get('bolt_id'), @@ -756,17 +789,28 @@ class WrenchGUI: if not self.work_order: return + self.log(f"🔍 update_bolt_order被调用,当前bolts数量: {len(self.work_order.get('bolts', []))}") + # 从树形控件读取新顺序 new_bolts = [] for item in self.tree.get_children(): values = self.tree.item(item)['values'] 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', []): - 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) + found = True 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中的作业顺序 self.work_order['bolts'] = new_bolts @@ -795,7 +839,24 @@ class WrenchGUI: if response.status_code == 200: result = response.json() 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.update_work_order_info() self.update_bolt_list() @@ -1062,6 +1123,8 @@ class WrenchGUI: # 遍历所有作业 bolts = self.work_order.get('bolts', []) + self.log(f"📋 工单中的作业数量: {len(bolts)}") + self.log(f"📋 作业数据: {bolts}") bolt_results = [] for index, bolt in enumerate(bolts): @@ -1094,6 +1157,7 @@ class WrenchGUI: def process_bolt(self, bolt, index): """处理单个作业""" + self.log(f"🔧 处理作业 #{index+1}, 原始数据: {bolt}") bolt_id = bolt.get('bolt_id') bolt_name = bolt.get('name') 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.wrench is not None}, is_running: {self.is_running}") + + if not self.wrench: + self.log("❌ 扳手对象为None,无法设置参数", "ERROR") + return None + self.wrench.set_torque_parameters( target_torque=target_torque, mode=bolt.get('mode', 1), @@ -1118,6 +1188,7 @@ class WrenchGUI: attempt = 0 result_data = None + self.log(f"🔄 进入拧紧循环,is_running={self.is_running}") while self.is_running: attempt += 1 self.log(f"第 {attempt} 次尝试拧紧作业 {bolt_id}") @@ -1132,6 +1203,7 @@ class WrenchGUI: # 等待结果 self.log("等待扳手响应...") result = self.wrench.wait_for_result() + self.log(f"📊 收到结果: {result}") if result and result.get("success"): # 成功 diff --git a/wrench.db b/wrench.db deleted file mode 100644 index 2a53d5bebf7f8b4ac147ebe239d766d032b76c81..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 28672 zcmeI&&rj1}7zgl{!KwrTw_V?4LDm2&F`m3wv6|t2z}6-1)RgwsG;Zr?-$u^_6FnFc ziHQe8IC{}|7B2oVO#cLqzU@|7R||OD@@>-5H}BiGdq2L|{+PO1Y&a@wLc|ofduRxG!{2}jUrMc5R_mHl-XagxM@pllk&Q;J##f~O z?TIZ--oG&|&06$G39vQcsn~?>Ke>(Q^F7}^=iJ!Fq%%g z+oGcpN{;iG!TdqIqwp;cF20-`9%jd&9QyB^khL|kS+7=lM<=Hz?@zyeI^Fy7>-eB| z___D-d+*)1SnPwkXjF>Z4Yd$u_bNHhUpY2dzBiN2Rb^4II~INA?Y8)HjBfbM3EO%^ z)Xy7zJ>Jf4WwN=I6|ouS*x+Q3?)tRDi={tT)SQlG*+^$0D3(<|RNiNzl*{MEx3|vk z4E>9T<=;P?ip@3DG2ZFQV`TXz(=WJl1gT^@os@*WB;Ws;hh5sS?9TJlJhTjET#$vo z4}bKI4pOqvbg3~~9_cr*WF`1re)TKg0F&omy$bG5Wpl-RS``dsn7%&L2%hDy1s}Qd z!OLRsf(-%?fB*y_009U<00Izz00bZafk_pZ4Hkyy|49um)&&6wKmY;|fB*y_009U< z00IyQ1@Qep5&;4bfB*y_009U<00Izz00bZ~`2u+UpZpkOg%E%M1Rwwb2tWV=5P$## zAOHdU{vSC20SG_<0uX=z1Rwwb2tWV=5SV-ceE&cBF~$lZ009U<00Izz00bZa0SG_< G0)GGnIPd}h