From 0b2eb87a6dae601a41892bdefe255ef1a4f003be Mon Sep 17 00:00:00 2001 From: zhu-mengmeng <15588200382@163.com> Date: Sun, 22 Jun 2025 01:28:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E6=A1=86=E9=80=BB=E8=BE=91=EF=BC=8C=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E6=89=98=E7=9B=98=E8=BE=93=E5=85=A5=E6=A1=86=E5=9B=9E?= =?UTF-8?q?=E8=BD=A6=E4=BA=8B=E4=BB=B6=E5=A4=84=E7=90=86=EF=BC=8C=E6=95=B4?= =?UTF-8?q?=E5=90=88=E8=AE=A2=E5=8D=95=E6=9F=A5=E8=AF=A2=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E6=89=98=E7=9B=98=E5=8F=B7=E5=92=8C?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E4=BF=A1=E6=81=AF=E7=9A=84=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- widgets/loading_dialog_widget.py | 153 +++++++++---------------------- widgets/main_window.py | 11 --- 2 files changed, 42 insertions(+), 122 deletions(-) diff --git a/widgets/loading_dialog_widget.py b/widgets/loading_dialog_widget.py index e903cf5..87f835c 100644 --- a/widgets/loading_dialog_widget.py +++ b/widgets/loading_dialog_widget.py @@ -37,7 +37,6 @@ class LoadingDialog(LoadingDialogUI): def setup_connections(self): """设置事件连接""" # 托盘号输入框回车事件触发查询 - self.tray_input.returnPressed.connect(self.handle_tray_return_pressed) self.order_input.returnPressed.connect(self.handle_order_return_pressed) # 确认按钮点击事件 @@ -64,136 +63,62 @@ class LoadingDialog(LoadingDialogUI): #判断是否是接口,如果不是接口直接添加如果是则走接口 # 如果开启接口模式,则需要调用接口同步到业务库 order_info = None - if AppMode.is_api(): - # 调用接口 - gc_api = GcApi() - # 防止response为None导致异常 - # 获取工程号信息,并且初始化数据 - order_response = gc_api.get_order_info(order_code) - if(order_response.get("status",False)): - # 将接口数据保存到数据库,用于后续的关联使用 - from dao.inspection_dao import InspectionDAO - inspection_dao = InspectionDAO() - order_info = order_response.get("data", {})[0] - # 设置轴数 - order_info['user_id'] = self.user_id - order_info['user_name'] = self.user_name - order_info['data_corp'] = self.corp_id - inspection_dao.save_order_info(order_code,order_info) - - + self.on_order_query(order_code) # 阻止事件继续传播 return True - def handle_tray_return_pressed(self): - """处理托盘输入框的回车事件""" - # 阻止事件传播 - logging.info("托盘输入框回车事件触发") - self.on_tray_query() - - # 阻止事件继续传播 - return True - - def on_tray_query(self): - """查询托盘信息""" + + def on_order_query(self,order_code): + """查询订单信息,同时生成托盘号,并且回显到页面上""" try: - tray_code = self.tray_input.text().strip() - if not tray_code: - return - - logging.info(f"查询托盘号: {tray_code}") if AppMode.is_api(): - self.tary_api = TaryApi() - # 调用API获取托盘信息 - response = self.tary_api.get_tary_info(tray_code) - else: - pallet_type_manager = PalletTypeManager.get_instance() - pallet_info = pallet_type_manager.get_pallet_info_by_pallet_id(tray_code) - - # 检查返回的数据类型并进行适当处理 - if pallet_info is None: - response = { - "success": False, - "message": "未找到托盘信息" - } - else: - # 如果返回的是元组(数据库查询结果),将其转换为字典 - # 根据dao/pallet_type_dao.py中get_pallet_info_by_pallet_id方法的SQL查询 - # 返回的字段顺序为:pallet_code, pallet_name, description, axios_name, axios_type, tier, size, amount, weight - try: - response = { - "success": True, - "data": { - "tp_note": pallet_info[0] if isinstance(pallet_info, tuple) and len(pallet_info) > 0 else "", - "product_name": pallet_info[1] if isinstance(pallet_info, tuple) and len(pallet_info) > 1 else "", - "axis_type": pallet_info[4] if isinstance(pallet_info, tuple) and len(pallet_info) > 4 else "", - "tier": str(pallet_info[5]) if isinstance(pallet_info, tuple) and len(pallet_info) > 5 else "", - } - } - except (IndexError, TypeError) as e: - logging.warning(f"处理托盘信息时出错: {str(e)}, pallet_info类型: {type(pallet_info)}") - # 如果pallet_info是字符串或其他非元组类型,创建一个基本响应 - response = { - "success": True, - "data": { - "tp_note": tray_code, - "product_name": "", - "axis_type": "", - "tier": "", - "weight": "", - "quantity": "" - } - } - - - logging.info(f"托盘信息响应: {response}") - logging.info(f"response.success={response.get('success')}, response.data存在={response.get('data') is not None}") - - if response.get("success", False) and response.get("data"): - tray_data = response.get("data", {}) - logging.info(f"托盘数据: {tray_data}") - - # 显示托盘相关信息 - 只更新轴型、托盘料和重量,不更新订单号和产品 - axis_type = str(tray_data.get("axis_type", "--")) - tier = str(tray_data.get("tier", "--")) - weight = str(tray_data.get("weight", "--")) - - logging.info(f"显示托盘信息: 轴型={axis_type}, 托盘料={tier}, 重量={weight}") - - # 只设置轴型、托盘料和重量字段,不设置产品名称 - self.axis_value.setText(axis_type) - self.pallet_tier_value.setText(tier) - self.quantity_value.setText("") # 数量为空 - self.weight_value.setText(f"{weight} kg") - - # 发送托盘号到主窗口 + # 调用接口 + gc_api = GcApi() + # 防止response为None导致异常 + # 获取工程号信息,并且初始化数据 + order_response = gc_api.get_order_info(order_code) + # 生成托盘号 + if(order_response.get("status",False)): + # 将接口数据保存到数据库,用于后续的关联使用 + from dao.inspection_dao import InspectionDAO + inspection_dao = InspectionDAO() + order_info = order_response.get("data", {})[0] + # 设置轴数 + order_info['user_id'] = self.user_id + order_info['user_name'] = self.user_name + order_info['data_corp'] = self.corp_id + inspection_dao.save_order_info(order_code,order_info) + self.axis_value.setText(order_info['zx_name']) + self.quantity_value.setText(str(order_info['sl'])) + self.weight_value.setText(str(order_info['sl'])) + xpack_response = gc_api.get_xpack(order_code) + if(xpack_response.get("status",False)): + xpack = xpack_response['xpack'] + self.tray_input.setText(xpack) + # 发送托盘号到主窗口 from widgets.main_window import MainWindow main_window = self.parent if main_window and isinstance(main_window, MainWindow): # 检查托盘号是否已存在 existed = False for i in range(main_window.tray_edit.count()): - if main_window.tray_edit.itemText(i) == tray_code: + if main_window.tray_edit.itemText(i) == xpack: existed = True break # 如果不存在,则添加 if not existed: - logging.info(f"添加托盘号到主窗口: {tray_code}") - main_window.tray_edit.addItem(tray_code) + logging.info(f"添加托盘号到主窗口: {xpack}") + main_window.tray_edit.addItem(xpack) # 设置当前选中的托盘号 - main_window.tray_edit.setCurrentText(tray_code) - logging.info(f"设置主窗口当前托盘号: {tray_code}") + main_window.tray_edit.setCurrentText(xpack) + logging.info(f"设置主窗口当前托盘号: {xpack}") - else: - # 获取托盘信息失败 - error_msg = response.get("message", "未找到托盘信息") - logging.warning(f"查询失败: {error_msg}") - QMessageBox.warning(self, "查询失败", error_msg) + return order_info except Exception as e: - logging.error(f"查询托盘信息异常: {str(e)}") - QMessageBox.critical(self, "查询异常", f"查询托盘信息时发生异常: {str(e)}") + logging.error(f"查询订单信息异常: {str(e)}") + return None def keyPressEvent(self, event): """重写键盘事件处理,防止回车关闭对话框""" @@ -223,6 +148,12 @@ class LoadingDialog(LoadingDialogUI): """重写接受方法,确保在确认前所有数据都已处理""" logging.info("确认按钮被点击或回车触发确认") + # 检查托盘层数是否有值 + tier_value = self.pallet_tier_value.text().strip() + if not tier_value: + QMessageBox.warning(self, "提示", "请输入托盘层数") + return + # 确保主窗口启动了监听 from widgets.main_window import MainWindow main_window = self.parent diff --git a/widgets/main_window.py b/widgets/main_window.py index 96b14cd..36b20c0 100644 --- a/widgets/main_window.py +++ b/widgets/main_window.py @@ -390,17 +390,6 @@ class MainWindow(MainWindowUI): if stow_num == "--" or not stow_num: QMessageBox.warning(self, "错误", "未获取到托盘料信息,请重试") return - - # 获取托盘号对应的托盘类型 - pallet_type = self.pallet_type_manager.get_pallet_type_by_pallet_id(tray_id) - # 初始化托盘号对应的序号 - if tray_id not in self.init_seq: - self.init_seq[tray_id] = 1 - - if not pallet_type: - QMessageBox.warning(self, "错误", "未查到对应托盘类型") - return - # 执行Modbus操作 modbus = ModbusUtils() client = modbus.get_client()