feat: 完成下料托盘api 接口功能

This commit is contained in:
zhu-mengmeng 2025-06-21 15:04:16 +08:00
parent 370bf03d13
commit c0ebb288c3
4 changed files with 136 additions and 71 deletions

View File

@ -340,7 +340,8 @@ class PalletTypeDAO:
try: try:
# 先查询是否存在该托盘号 # 先查询是否存在该托盘号
check_sql = "SELECT pallet_code FROM wsbz_pallet_archives WHERE pallet_code = ? AND is_deleted = ?" 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') current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
@ -354,8 +355,8 @@ class PalletTypeDAO:
WHERE pallet_code = ? AND is_deleted = ? WHERE pallet_code = ? AND is_deleted = ?
""" """
params = ( params = (
pallet_info.get("cs", ""), pallet_info.get("tier", ""),
pallet_info.get("cc", ""), pallet_info.get("size", ""),
current_time, current_time,
user_id, user_id,
pallet_code, pallet_code,
@ -371,8 +372,8 @@ class PalletTypeDAO:
""" """
params = ( params = (
pallet_code, pallet_code,
pallet_info.get("cs", ""), pallet_info.get("tier", ""),
pallet_info.get("cc", ""), pallet_info.get("size", ""),
current_time, current_time,
user_id, user_id,
False False
@ -414,8 +415,10 @@ class PalletTypeDAO:
for key in result: for key in result:
if result[key] is None: if result[key] is None:
result[key] = "" result[key] = ""
logging.info(f"获取到托盘信息: {result}") # 添加日志
return result return result
else: else:
logging.warning(f"未找到托盘信息: {pallet_code}") # 添加日志
return None return None
except Exception as e: except Exception as e:
logging.error(f"获取托盘信息失败: {str(e)}") logging.error(f"获取托盘信息失败: {str(e)}")

Binary file not shown.

View File

@ -117,10 +117,13 @@ class UnloadingDialogUI(QDialog):
split_layout.addWidget(right_split, 1) split_layout.addWidget(right_split, 1)
container_layout.addLayout(split_layout) container_layout.addLayout(split_layout)
# 第二行:托盘类型 # 第二行:托盘类型和托盘层数
row2 = QHBoxLayout() row2 = QHBoxLayout()
row2.setSpacing(0) row2.setSpacing(0)
# 托盘类型部分
pallet_type_layout = QHBoxLayout()
pallet_type_layout.setSpacing(0)
self.pallet_type_label = QLabel("托盘类型") self.pallet_type_label = QLabel("托盘类型")
self.pallet_type_label.setFont(self.normal_font) self.pallet_type_label.setFont(self.normal_font)
self.pallet_type_label.setStyleSheet(label_style) 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().setCaseSensitivity(Qt.CaseInsensitive) # 设置补全不区分大小写
self.pallet_type_input.completer().setFilterMode(Qt.MatchContains) # 设置模糊匹配模式 self.pallet_type_input.completer().setFilterMode(Qt.MatchContains) # 设置模糊匹配模式
row2.addWidget(self.pallet_type_label) pallet_type_layout.addWidget(self.pallet_type_label)
row2.addWidget(self.pallet_type_input, 1) 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) container_layout.addLayout(row2)
# 添加水平分隔布局 # 添加水平分隔布局
split_layout2 = QHBoxLayout() split_layout2 = QHBoxLayout()
split_layout2.setSpacing(0) split_layout2.setSpacing(0)
@ -153,7 +190,7 @@ class UnloadingDialogUI(QDialog):
split_layout2.addWidget(left_split2) split_layout2.addWidget(left_split2)
split_layout2.addWidget(right_split2, 1) split_layout2.addWidget(right_split2, 1)
container_layout.addLayout(split_layout2) container_layout.addLayout(split_layout2)
# 第三行:轴型和材质 # 第三行:轴型和材质
row3 = QHBoxLayout() row3 = QHBoxLayout()
row3.setSpacing(0) row3.setSpacing(0)

View File

@ -60,7 +60,10 @@ class UnloadingDialog(UnloadingDialogUI):
def get_current_tier(self): 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): def setup_connections(self):
"""设置事件连接""" """设置事件连接"""
@ -88,84 +91,106 @@ class UnloadingDialog(UnloadingDialogUI):
"""查询托盘信息""" """查询托盘信息"""
try: try:
tray_code = self.tray_input.text().strip() tray_code = self.tray_input.text().strip()
tier = self.tier_input.text().strip() # 获取用户输入的层数
pallet_type = self.pallet_type_input.currentText().strip() pallet_type = self.pallet_type_input.currentText().strip()
if not tray_code: if not tray_code:
return return
logging.info(f"查询托盘号: {tray_code}") logging.info(f"查询托盘号: {tray_code}")
pallet_info = {} # 初始化托盘类型管理器
pallet_type_manager = PalletTypeManager.get_instance()
if AppMode.is_api(): if AppMode.is_api():
self.tary_api = TaryApi() self.tary_api = TaryApi()
# 调用API获取托盘信息,并保存到本地 # 调用API获取托盘信息
response = self.tary_api.get_tary_info(tray_code) response = self.tary_api.get_tary_info(tray_code)
if response.get("success", False) and response.get("data"): if response.get("success", False) and response.get("data"):
tray_data = response.get("data", {}) tray_data = response.get("data", {})
logging.info(f"托盘数据: {tray_data}") logging.info(f"API返回托盘数据: {tray_data}")
pallet_type_manager = PalletTypeManager.get_instance() # 如果用户输入了层数,使用用户输入的层数
pallet_type_manager.save_pallet_info(tray_code, tray_data,self.user_id) if tier:
else: tray_data["tier"] = tier
# 不是接口,就查询数据库,如果查到了托盘号就回显,查不到就新增 pallet_type_manager.save_pallet_info(tray_code, tray_data, self.user_id)
pallet_type_manager = PalletTypeManager.get_instance() else:
pallet_info = pallet_type_manager.get_pallet_info_by_pallet_id(tray_code) # API查询失败保存基本信息到数据库
if not pallet_info: logging.info(f"API查询失败保存基本信息到数据库")
# 获取页面上的数据,保存到数据库中 if not pallet_type or not tier:
QMessageBox.warning(self, "提示", "请选择托盘类型和层数")
return
pallet_info = { pallet_info = {
"cc": pallet_type, "cc": pallet_type,
"cs": "", "cs": tier # 使用用户输入的层数
} }
pallet_type_manager.save_pallet_info(tray_code, pallet_info,self.user_id) 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}")
else: else:
# 获取托盘信息失败 # 查询数据库中的托盘信息
error_msg = response.get("message", "未找到托盘信息") pallet_info = pallet_type_manager.get_pallet_info_by_pallet_id(tray_code)
logging.warning(f"查询失败: {error_msg}") if not pallet_info:
QMessageBox.warning(self, "查询失败", error_msg) # 数据库中没有记录,保存基本信息
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: except Exception as e:
logging.error(f"查询托盘信息异常: {str(e)}") logging.error(f"查询托盘信息异常: {str(e)}")
QMessageBox.critical(self, "查询异常", f"查询托盘信息时发生异常: {str(e)}") QMessageBox.critical(self, "查询异常", f"查询托盘信息时发生异常: {str(e)}")
def keyPressEvent(self, event): def keyPressEvent(self, event):
"""重写键盘事件处理,防止回车关闭对话框""" """重写键盘事件处理,防止回车关闭对话框"""