From c0ebb288c3bcb71a93f06c37d9e325f95adab903 Mon Sep 17 00:00:00 2001 From: zhu-mengmeng <15588200382@163.com> Date: Sat, 21 Jun 2025 15:04:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E4=B8=8B=E6=96=99?= =?UTF-8?q?=E6=89=98=E7=9B=98api=20=E6=8E=A5=E5=8F=A3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/pallet_type_dao.py | 13 ++- db/jtDB.db | Bin 77824 -> 77824 bytes ui/unloading_dialog_ui.py | 45 ++++++++- widgets/unloading_dialog_widget.py | 149 +++++++++++++++++------------ 4 files changed, 136 insertions(+), 71 deletions(-) diff --git a/dao/pallet_type_dao.py b/dao/pallet_type_dao.py index e88a4d5..e5f5b34 100644 --- a/dao/pallet_type_dao.py +++ b/dao/pallet_type_dao.py @@ -340,7 +340,8 @@ class PalletTypeDAO: try: # 先查询是否存在该托盘号 check_sql = "SELECT pallet_code FROM wsbz_pallet_archives WHERE pallet_code = ? AND is_deleted = ?" - result = self.db.execute_query(check_sql, (pallet_code, False)) + self.db.execute_query(check_sql, (pallet_code, False)) + result = self.db.cursor.fetchone() # 使用 cursor.fetchone() 获取结果 current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') @@ -354,8 +355,8 @@ class PalletTypeDAO: WHERE pallet_code = ? AND is_deleted = ? """ params = ( - pallet_info.get("cs", ""), - pallet_info.get("cc", ""), + pallet_info.get("tier", ""), + pallet_info.get("size", ""), current_time, user_id, pallet_code, @@ -371,8 +372,8 @@ class PalletTypeDAO: """ params = ( pallet_code, - pallet_info.get("cs", ""), - pallet_info.get("cc", ""), + pallet_info.get("tier", ""), + pallet_info.get("size", ""), current_time, user_id, False @@ -414,8 +415,10 @@ class PalletTypeDAO: for key in result: if result[key] is None: result[key] = "" + logging.info(f"获取到托盘信息: {result}") # 添加日志 return result else: + logging.warning(f"未找到托盘信息: {pallet_code}") # 添加日志 return None except Exception as e: logging.error(f"获取托盘信息失败: {str(e)}") diff --git a/db/jtDB.db b/db/jtDB.db index f857b79a1414c21a48ca44270c27af343f405927..158423dda2efce0aaafe04fedf53cf18ae57e430 100644 GIT binary patch delta 583 zcmZp8z|!!5WrDQeI|c>@VIbxJVm2W5pQvNZ`i?=btb1e1T7Bj;e*eva0_Oaaz3ru0 z?I9Y zL56d0mMM5@FUc>+z|I@Zz~9NYlP{5vlXoL;G`}&g9j_hG3KiaZa~=VpT22OIS+H|d zd3lWtj7)V6%yf+m6+(DnlE$(?x2iJoBS{(>TN#^MnHqV8#5=n9ditSCnOInvn!%*J zLIPZjObyHo3=B+IjKVks7}O;>8I2{4B{#2L8^Xu}bb-=jK>@k25IzDH0!_7qnM$;U zlRMW}Z)Q2b6~M;A#=Dns1JJ7e?TZB%c^SD{f+g9-ot+swbf<5WWt0R5@^oh*MrlT# z>G490jniKWF@`egO#a9tJ^j5TW7G7P!i=($U6^Z`xHPx3i7?i3y4Z@Fnlg6EmLw+S zq?Q*aRmB%1=H#Tdq=*9zW|IU(F9SnM7?1~4*5U`XP8p=U#R13zigqZ2EZ1e^nYh7r R@_j~ooR)6?C(pC1AkdQQrkmO{iS0(Ix)r_YF zWwj^UJ&}Pb-u*^$GWTmgW>q$&$uX}L;6|`bp8fhMn*ysMy7Dxj*-VcoTR#C=x8R+~ zR54;5l+T5<3-59kw#kA56SprGVB}?- zUN6d+$={MG&Mxlk%-9iGl9-f}Iyul@6c{;d({BkfN;7g#|0c-TxLJ-#jd44h2xBd$ zvAVdaDPyNBSZ#T6QdN9GVopwKOA5#kHVIIyGcdG-0eL`W9sV#QMW#QHWfWoLp18qw Q^L@rgjNAXoGcpMP0LB)sNdN!< diff --git a/ui/unloading_dialog_ui.py b/ui/unloading_dialog_ui.py index 6de053e..589fa71 100644 --- a/ui/unloading_dialog_ui.py +++ b/ui/unloading_dialog_ui.py @@ -117,10 +117,13 @@ class UnloadingDialogUI(QDialog): split_layout.addWidget(right_split, 1) container_layout.addLayout(split_layout) - # 第二行:托盘类型 + # 第二行:托盘类型和托盘层数 row2 = QHBoxLayout() row2.setSpacing(0) + # 托盘类型部分 + pallet_type_layout = QHBoxLayout() + pallet_type_layout.setSpacing(0) self.pallet_type_label = QLabel("托盘类型") self.pallet_type_label.setFont(self.normal_font) self.pallet_type_label.setStyleSheet(label_style) @@ -137,9 +140,43 @@ class UnloadingDialogUI(QDialog): self.pallet_type_input.completer().setCaseSensitivity(Qt.CaseInsensitive) # 设置补全不区分大小写 self.pallet_type_input.completer().setFilterMode(Qt.MatchContains) # 设置模糊匹配模式 - row2.addWidget(self.pallet_type_label) - row2.addWidget(self.pallet_type_input, 1) + pallet_type_layout.addWidget(self.pallet_type_label) + pallet_type_layout.addWidget(self.pallet_type_input, 1) + + # 托盘层数部分 + tier_layout = QHBoxLayout() + tier_layout.setSpacing(0) + self.tier_label = QLabel("托盘层数") + self.tier_label.setFont(self.normal_font) + self.tier_label.setStyleSheet(label_style) + self.tier_label.setFixedWidth(100) + self.tier_label.setFixedHeight(45) + + self.tier_input = QLineEdit() + self.tier_input.setFont(self.normal_font) + self.tier_input.setStyleSheet(""" + QLineEdit { + border: none; + border-right: 1px solid #e0e0e0; + border-bottom: 1px solid #e0e0e0; + background-color: white; + selection-background-color: #0078d4; + padding: 0 8px; + } + QLineEdit:focus { + background-color: #f8f8f8; + } + """) + self.tier_input.setFixedHeight(45) + self.tier_input.setPlaceholderText("请输入层数") + + tier_layout.addWidget(self.tier_label) + tier_layout.addWidget(self.tier_input, 1) + + row2.addLayout(pallet_type_layout, 1) + row2.addLayout(tier_layout, 1) container_layout.addLayout(row2) + # 添加水平分隔布局 split_layout2 = QHBoxLayout() split_layout2.setSpacing(0) @@ -153,7 +190,7 @@ class UnloadingDialogUI(QDialog): split_layout2.addWidget(left_split2) split_layout2.addWidget(right_split2, 1) container_layout.addLayout(split_layout2) - + # 第三行:轴型和材质 row3 = QHBoxLayout() row3.setSpacing(0) diff --git a/widgets/unloading_dialog_widget.py b/widgets/unloading_dialog_widget.py index 4c58714..dad5a4d 100644 --- a/widgets/unloading_dialog_widget.py +++ b/widgets/unloading_dialog_widget.py @@ -60,7 +60,10 @@ class UnloadingDialog(UnloadingDialogUI): def get_current_tier(self): """获取当前托盘的层数""" - return self.current_tier if self.current_tier else None + tier = self.tier_input.text().strip() + if not tier: + return self.current_tier if self.current_tier else "3" + return tier def setup_connections(self): """设置事件连接""" @@ -88,84 +91,106 @@ class UnloadingDialog(UnloadingDialogUI): """查询托盘信息""" try: tray_code = self.tray_input.text().strip() + tier = self.tier_input.text().strip() # 获取用户输入的层数 pallet_type = self.pallet_type_input.currentText().strip() if not tray_code: return logging.info(f"查询托盘号: {tray_code}") - pallet_info = {} + # 初始化托盘类型管理器 + pallet_type_manager = PalletTypeManager.get_instance() if AppMode.is_api(): self.tary_api = TaryApi() - # 调用API获取托盘信息,并保存到本地 + # 调用API获取托盘信息 response = self.tary_api.get_tary_info(tray_code) if response.get("success", False) and response.get("data"): tray_data = response.get("data", {}) - logging.info(f"托盘数据: {tray_data}") - pallet_type_manager = PalletTypeManager.get_instance() - pallet_type_manager.save_pallet_info(tray_code, tray_data,self.user_id) - else: - # 不是接口,就查询数据库,如果查到了托盘号就回显,查不到就新增 - pallet_type_manager = PalletTypeManager.get_instance() - pallet_info = pallet_type_manager.get_pallet_info_by_pallet_id(tray_code) - if not pallet_info: - # 获取页面上的数据,保存到数据库中 + logging.info(f"API返回托盘数据: {tray_data}") + # 如果用户输入了层数,使用用户输入的层数 + if tier: + tray_data["tier"] = tier + pallet_type_manager.save_pallet_info(tray_code, tray_data, self.user_id) + else: + # API查询失败,保存基本信息到数据库 + logging.info(f"API查询失败,保存基本信息到数据库") + if not pallet_type or not tier: + QMessageBox.warning(self, "提示", "请选择托盘类型和层数") + return pallet_info = { "cc": pallet_type, - "cs": "", + "cs": tier # 使用用户输入的层数 } - pallet_type_manager.save_pallet_info(tray_code, pallet_info,self.user_id) - - #回显数据到页面 - pallet_info = pallet_type_manager.get_pallet_detail(tray_code) - - if pallet_info: - logging.info(f"托盘数据: {pallet_info}") - - # 显示托盘相关信息 - axis_type = str(pallet_info.get("zx_name", "--")) - material = str(pallet_info.get("cz", "--")) - weight = str(pallet_info.get("weight", "--")) - amount = str(pallet_info.get("amount", "--")) - self.current_tier = pallet_info.get("tier") # 保存层数 - - logging.info(f"显示托盘信息: 轴型={axis_type}, 材质={material}, 重量={weight}, 层数={self.current_tier}") - - # 设置显示值 - self.axis_value.setText(axis_type) - self.material_tier_value.setPlaceholderText(material) - self.material_tier_value.setText("") # 清空文本,让用户输入 - self.quantity_value.setText(amount) - self.weight_value.setText(f"{weight} kg") - self.pallet_type_input.setCurrentText(pallet_info.get("pallet_name", "--")) - - # 发送托盘号到主窗口 - 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: - existed = True - break - - # 如果不存在,则添加 - if not existed: - logging.info(f"添加托盘号到主窗口: {tray_code}") - main_window.tray_edit.addItem(tray_code) - - # 设置当前选中的托盘号 - main_window.tray_edit.setCurrentText(tray_code) - logging.info(f"设置主窗口当前托盘号: {tray_code}") + pallet_type_manager.save_pallet_info(tray_code, pallet_info, self.user_id) else: - # 获取托盘信息失败 - error_msg = response.get("message", "未找到托盘信息") - logging.warning(f"查询失败: {error_msg}") - QMessageBox.warning(self, "查询失败", error_msg) + # 查询数据库中的托盘信息 + pallet_info = pallet_type_manager.get_pallet_info_by_pallet_id(tray_code) + if not pallet_info: + # 数据库中没有记录,保存基本信息 + logging.info(f"数据库中未找到记录,保存基本信息") + if not pallet_type or not tier: + QMessageBox.warning(self, "提示", "请选择托盘类型和层数") + return + pallet_info = { + "cc": pallet_type, + "cs": tier # 使用用户输入的层数 + } + pallet_type_manager.save_pallet_info(tray_code, pallet_info, self.user_id) + + # 重新获取完整的托盘信息 + pallet_info = pallet_type_manager.get_pallet_detail(tray_code) + if not pallet_info: + logging.warning(f"无法获取托盘详细信息: {tray_code}") + pallet_info = { + "zx_name": "--", + "cz": "--", + "weight": "0", + "amount": "0", + "tier": tier if tier else "4", # 使用用户输入的层数,如果没有则默认3层 + "pallet_name": pallet_type + } + + # 显示托盘相关信息 + axis_type = str(pallet_info.get("zx_name", "--")) + material = str(pallet_info.get("cz", "--")) + weight = str(pallet_info.get("weight", "--")) + amount = str(pallet_info.get("amount", "--")) + self.current_tier = pallet_info.get("cs", tier if tier else "4") # 优先使用数据库中的层数,其次是用户输入的层数,最后是默认值 + + logging.info(f"显示托盘信息: 轴型={axis_type}, 材质={material}, 重量={weight}, 层数={self.current_tier}") + + # 设置显示值 + self.axis_value.setText(axis_type) + self.material_tier_value.setPlaceholderText(material) + self.material_tier_value.setText("") # 清空文本,让用户输入 + self.quantity_value.setText(amount) + self.weight_value.setText(f"{weight} kg") + self.tier_input.setText(str(self.current_tier)) # 设置层数输入框的值 + self.pallet_type_input.setCurrentText(pallet_info.get("pallet_name", "--")) + + # 发送托盘号到主窗口 + 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: + existed = True + break + + # 如果不存在,则添加 + if not existed: + logging.info(f"添加托盘号到主窗口: {tray_code}") + main_window.tray_edit.addItem(tray_code) + + # 设置当前选中的托盘号 + main_window.tray_edit.setCurrentText(tray_code) + logging.info(f"设置主窗口当前托盘号: {tray_code}") + except Exception as e: logging.error(f"查询托盘信息异常: {str(e)}") - QMessageBox.critical(self, "查询异常", f"查询托盘信息时发生异常: {str(e)}") + QMessageBox.critical(self, "查询异常", f"查询托盘信息时发生异常: {str(e)}") def keyPressEvent(self, event): """重写键盘事件处理,防止回车关闭对话框"""