feat: 更新加载对话框逻辑,移除托盘输入框回车事件处理,整合订单查询功能,优化托盘号和订单信息的处理流程
This commit is contained in:
parent
c0ebb288c3
commit
0b2eb87a6d
@ -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)
|
||||
|
||||
|
||||
|
||||
# 阻止事件继续传播
|
||||
return True
|
||||
def handle_tray_return_pressed(self):
|
||||
"""处理托盘输入框的回车事件"""
|
||||
# 阻止事件传播
|
||||
logging.info("托盘输入框回车事件触发")
|
||||
self.on_tray_query()
|
||||
self.on_order_query(order_code)
|
||||
|
||||
# 阻止事件继续传播
|
||||
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
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user