diff --git a/apis/gc_api.py b/apis/gc_api.py index 10b951d..10dfac2 100644 --- a/apis/gc_api.py +++ b/apis/gc_api.py @@ -125,6 +125,34 @@ class GcApi: logging.error(f"添加订单信息失败: {str(e)}") return None + def remove_order_info(self, xpack, ddmo, sgc): + """ + 删除订单信息 + + Args: + xpack: 托盘号 + ddmo: 订单号 + sgc: 工程号 + + Returns: + dict: 接口响应结果 + """ + try: + # API 配置中的键名 + api_key = "remove_order_info" + # 构建 form-data 格式的数据 + data = { + "xpack": xpack, + "ddmo": ddmo, + "gch": sgc + } + # 调用接口 + response = self.api_utils.post(api_key, data=data) + return response + except Exception as e: + logging.error(f"删除订单信息失败: {str(e)}") + return {"status": False, "message": f"删除订单信息失败: {str(e)}"} + def get_xpack(self, order_id,corp_id): """ 获取包装号 diff --git a/config/app_config.json b/config/app_config.json index 36bc314..963bb67 100644 --- a/config/app_config.json +++ b/config/app_config.json @@ -15,6 +15,7 @@ "get_gc_info": "/jsjt/xcsc/tprk/getBZGCInfoToWsbz.do", "get_order_info": "/jsjt/xcsc/tprk/getXsddBzrkGridListToWsbz.do", "add_order_info": "/jsjt/xcsc/tprk/bzrkAdd01.do", + "remove_order_info": "/jsjt/xcsc/tprk/removeByOrder.do", "get_xpack": "/jsjt/xcsc/tprk/getXpackToWsbz.do", "ismt_option": "/jsjt/xcsc/tprk/ismtOptioTonWsbz.do", "get_params": "/select/getcombcodeWsbz.do", diff --git a/db/jtDB.db b/db/jtDB.db index faadd79..b23c4db 100644 Binary files a/db/jtDB.db and b/db/jtDB.db differ diff --git a/from pymodbus.py b/from pymodbus.py index cbb9ec3..237b659 100644 --- a/from pymodbus.py +++ b/from pymodbus.py @@ -2,7 +2,7 @@ from pymodbus.client import ModbusTcpClient import time client = ModbusTcpClient('localhost', port=5020) client.connect() -client.write_registers(address=11, values=[9422]) +client.write_registers(address=11, values=[14322]) # client.write_registers(address=3, values=[0]) # time.sleep(2) # client.write_registers(address=0, values=[0]) diff --git a/widgets/main_window.py b/widgets/main_window.py index 011a7d6..6ae64cf 100644 --- a/widgets/main_window.py +++ b/widgets/main_window.py @@ -294,7 +294,7 @@ class MainWindow(MainWindowUI): self.start_button.clicked.connect(self.handle_start) self.stop_button.clicked.connect(self.handle_stop) self.delete_row_button.clicked.connect(self.handle_delete_row) - + # 连接托盘完成按钮事件 self.tray_complete_button.clicked.connect(self.handle_tray_complete) @@ -3831,6 +3831,20 @@ class MainWindow(MainWindowUI): # 获取托盘号 tray_id = self.tray_edit.currentText() + # 如果开启 api 模式,则调用接口删除远程数据 + if AppMode.is_api(): + from apis.gc_api import GcApi + gc_api = GcApi() + + # 调用删除接口 + response = gc_api.remove_order_info(tray_id, self._current_order_code, gc_note) + if response.get("status", False): + logging.info(f"已从远程删除订单信息: 托盘号={tray_id}, 订单号={self._current_order_code}, 工程号={gc_note}") + else: + error_msg = response.get("message", "未知错误") + logging.warning(f"远程删除订单信息失败: {error_msg}") + # 可以选择是否继续删除本地数据,这里选择继续 + # 从数据库中删除该工程号的检验数据 inspection_dao.delete_inspection_data(self._current_order_code, gc_note, tray_id) logging.info(f"已从数据库中删除工程号 {gc_note} 的检验数据") @@ -3842,8 +3856,9 @@ class MainWindow(MainWindowUI): # 重新加载数据 self._safe_load_data() - # 清除选中状态,防止误操作 + # 确保清除选中状态,防止误操作 self.process_table.clearSelection() + self.process_table.setCurrentItem(None) # 显示成功消息 QMessageBox.information(self, "删除成功", "已成功删除选中的微丝产线数据") @@ -3911,17 +3926,26 @@ class MainWindow(MainWindowUI): logging.warning(f"第 {row} 行工程号为空,跳过删除") continue - # 获取托盘号(第6列) - tray_id_item = self.record_table.item(row, 5) - if not tray_id_item: - logging.warning(f"第 {row} 行托盘号为空,跳过删除") - continue - - tray_id = tray_id_item.text().strip() + # 获取托盘号(从前端组件获取) + tray_id = self.tray_edit.currentText() if not tray_id: - logging.warning(f"第 {row} 行托盘号为空,跳过删除") + logging.warning("托盘号为空,跳过删除") continue + # 如果开启 api 模式,则调用接口删除远程数据 + if AppMode.is_api(): + from apis.gc_api import GcApi + gc_api = GcApi() + + # 调用删除接口 + response = gc_api.remove_order_info(tray_id, order_id, gc_note) + if response.get("status", False): + logging.info(f"已从远程删除订单信息: 托盘号={tray_id}, 订单号={order_id}, 工程号={gc_note}") + else: + error_msg = response.get("message", "未知错误") + logging.warning(f"远程删除订单信息失败: {error_msg}") + # 可以选择是否继续删除本地数据,这里选择继续 + # 从数据库中删除该包装记录 success = inspection_dao.delete_package_record(order_id, gc_note, tray_id) if success: @@ -3936,7 +3960,11 @@ class MainWindow(MainWindowUI): # 重新加载包装记录 self.show_pack_item() + + # 确保清除选中状态,防止误操作 self.record_table.clearSelection() + self.record_table.setCurrentItem(None) + # 显示成功消息 QMessageBox.information(self, "删除成功", "已成功删除选中的包装记录")