feat:修复箱号生成错误
This commit is contained in:
parent
53cd8f60b5
commit
5669bdc8a7
@ -708,7 +708,7 @@ class InspectionDAO:
|
||||
try:
|
||||
sql = """
|
||||
DELETE FROM wsbz_inspection_data
|
||||
WHERE AND gc_note = ? AND tray_id = ?
|
||||
WHERE gc_note = ? AND tray_id = ?
|
||||
"""
|
||||
params = (gc_note, tray_id)
|
||||
|
||||
|
||||
BIN
db/jtDB.db
BIN
db/jtDB.db
Binary file not shown.
@ -2,7 +2,7 @@ from pymodbus.client import ModbusTcpClient
|
||||
import time
|
||||
client = ModbusTcpClient('localhost', port=5020)
|
||||
client.connect()
|
||||
# client.write_registers(address=11, values=[19562])
|
||||
client.write_registers(address=11, values=[3562])
|
||||
# client.write_registers(address=3, values=[0])
|
||||
# time.sleep(2)
|
||||
# client.write_registers(address=0, values=[0])
|
||||
@ -15,10 +15,11 @@ client.connect()
|
||||
# client.write_registers(address=2, values=[0])
|
||||
# client.write_registers(address=13, values=[1])
|
||||
# time.sleep(2)
|
||||
client.write_registers(address=20, values=[0])
|
||||
time.sleep(3)
|
||||
client.write_registers(address=20, values=[1])
|
||||
|
||||
# client.write_registers(address=20, values=[0])
|
||||
# time.sleep(3)
|
||||
# client.write_registers(address=20, values=[1])
|
||||
# time.sleep(3)
|
||||
# client.write_registers(address=20, values=[0])
|
||||
|
||||
result1 = client.read_holding_registers(address=3, count=1)
|
||||
print(result1.registers[0],"123===")
|
||||
|
||||
@ -205,9 +205,15 @@ class LoadingDialog(LoadingDialogUI):
|
||||
xpack_response = gc_api.get_xpack(order_code, self.corp_id)
|
||||
if xpack_response and xpack_response.get("status", False):
|
||||
xpack = xpack_response['xpack']
|
||||
spack = xpack_response['spack']
|
||||
self.tray_input.setText(xpack)
|
||||
self.pallet_tier_value.setText('3')
|
||||
|
||||
# 将spack保存到order_data中,以便后续使用
|
||||
if hasattr(self, 'order_data') and self.order_data:
|
||||
self.order_data['spack'] = spack
|
||||
logging.info(f"已将spack: {spack}保存到order_data中")
|
||||
|
||||
# 发送托盘号到主窗口
|
||||
from widgets.main_window import MainWindow
|
||||
main_window = self.parent
|
||||
@ -221,6 +227,9 @@ class LoadingDialog(LoadingDialogUI):
|
||||
# 手动触发托盘号变更事件
|
||||
main_window.handle_tray_changed(xpack)
|
||||
|
||||
# spack值已经获取,可以在后续处理中使用
|
||||
logging.info(f"已获取spack: {spack},将与xpack一起使用")
|
||||
|
||||
return order_info
|
||||
|
||||
except Exception as e:
|
||||
@ -361,9 +370,17 @@ class LoadingDialog(LoadingDialogUI):
|
||||
Returns:
|
||||
dict: 上料数据字典
|
||||
"""
|
||||
# 获取spack值,如果order_data中有则使用,否则默认使用tray_id
|
||||
spack = ""
|
||||
if hasattr(self, 'order_data') and self.order_data and 'spack' in self.order_data:
|
||||
spack = self.order_data['spack']
|
||||
else:
|
||||
spack = self.tray_input.text().strip()
|
||||
|
||||
return {
|
||||
"order_id": self.order_input.text().strip(),
|
||||
"tray_id": self.tray_input.text().strip(),
|
||||
"spack": spack, # 添加spack字段
|
||||
"pallet_tier": self.pallet_tier_value.text().strip(),
|
||||
"order_data": self.order_data
|
||||
}
|
||||
@ -65,6 +65,8 @@ class MainWindow(MainWindowUI):
|
||||
# 新增的重量警告弹框信号 - 参数:值, 最小值, 最大值
|
||||
weight_alert_signal = Signal(float, float, float)
|
||||
|
||||
# 不需要单独的spack信号,我们直接从loading_data中获取spack
|
||||
|
||||
def __init__(self, user_id=None, user_name=None, corp_name=None, corp_id=None):
|
||||
"""初始化主窗口"""
|
||||
super().__init__(user_id)
|
||||
@ -93,6 +95,7 @@ class MainWindow(MainWindowUI):
|
||||
self._weight_stable_threshold = 2 # 重量稳定阈值(秒)
|
||||
self._weight_processed = False # 新增:标记当前重量是否已处理,避免重复处理
|
||||
self._last_processed_weight = 0.0 # 新增:记录上次处理的重量
|
||||
self._current_spack = "" # 添加全局变量存储当前spack值
|
||||
|
||||
# 线径数据处理相关属性
|
||||
self._last_diameter_value = 0 # 最后一次有效的线径值
|
||||
@ -298,11 +301,14 @@ class MainWindow(MainWindowUI):
|
||||
self.order_edit.returnPressed.connect(self.handle_order_enter)
|
||||
|
||||
# 托盘号输入框信号连接 - 从 QComboBox 改为 QLineEdit
|
||||
# QLineEdit 没有文本变化的信号,因此我们不需要连接信号
|
||||
# QLineEdit 需要连接textChanged信号来监听文本变化
|
||||
self.tray_edit.textChanged.connect(self.handle_tray_changed)
|
||||
# 原来的连接代码:
|
||||
# self.tray_edit.currentTextChanged.connect(self.handle_tray_changed)
|
||||
# self.tray_edit.currentIndexChanged.connect(self.handle_tray_changed)
|
||||
|
||||
# 不需要单独的spack信号连接
|
||||
|
||||
# 连接按钮事件
|
||||
self.input_button.clicked.connect(self.handle_input)
|
||||
self.output_button.clicked.connect(self.handle_output)
|
||||
@ -339,9 +345,6 @@ class MainWindow(MainWindowUI):
|
||||
# 连接急停信号
|
||||
self.emergency_stop_signal.connect(self._handle_emergency_stop_ui)
|
||||
|
||||
# 连接线径警告信号
|
||||
self.diameter_warning_signal.connect(self.show_diameter_warning)
|
||||
|
||||
# 连接炉号查询按钮信号
|
||||
if hasattr(self, 'luno_query_button'):
|
||||
self.luno_query_button.clicked.connect(self.handle_luno_query)
|
||||
@ -402,34 +405,17 @@ class MainWindow(MainWindowUI):
|
||||
# 获取当前文本,以便保留用户选择
|
||||
current_text = self.tray_edit.text()
|
||||
|
||||
# 清空当前文本
|
||||
self.tray_edit.setText("")
|
||||
|
||||
# 获取托盘号
|
||||
pallet_codes = self.pallet_type_manager.get_pallet_code()
|
||||
|
||||
if pallet_codes and len(pallet_codes) > 0:
|
||||
# 由于现在是 QLineEdit,我们不再需要添加多个项目
|
||||
# 如果有之前的选择并且它在托盘号列表中,则恢复它
|
||||
if current_text in pallet_codes:
|
||||
self.tray_edit.setText(current_text)
|
||||
else:
|
||||
self.tray_edit.setText("")
|
||||
|
||||
# 这里可以存储托盘号列表,以便在其他地方使用
|
||||
self._pallet_codes = pallet_codes
|
||||
self._pallet_codes = pallet_codes if pallet_codes else []
|
||||
|
||||
logging.info(f"已加载托盘号,共 {len(pallet_codes)} 个")
|
||||
else:
|
||||
# 如果没有托盘号,则保持为空
|
||||
logging.warning("未找到托盘号,托盘号将为空")
|
||||
self.tray_edit.setText("")
|
||||
self._pallet_codes = []
|
||||
# 不再清空或更改当前托盘号,保留现有值
|
||||
logging.info(f"已加载托盘号列表,共 {len(self._pallet_codes)} 个,当前托盘号保持为 '{current_text}'")
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"加载托盘号失败: {str(e)}")
|
||||
# 如果加载失败,确保文本框为空
|
||||
self.tray_edit.setText("")
|
||||
logging.error(f"加载托盘号列表失败: {str(e)}")
|
||||
self._pallet_codes = []
|
||||
|
||||
def load_warehouse_data(self):
|
||||
@ -682,12 +668,18 @@ class MainWindow(MainWindowUI):
|
||||
|
||||
# 如果用户确认,则执行上料操作
|
||||
if result == QDialog.Accepted:
|
||||
# 从对话框中获取订单号和托盘号,并更新到主窗口
|
||||
order_code = dialog.order_input.text().strip()
|
||||
tray_code = dialog.tray_input.text().strip()
|
||||
# 从对话框中获取订单号、托盘号和spack,并更新到主窗口
|
||||
loading_data = dialog.get_loading_data()
|
||||
order_code = loading_data["order_id"].strip()
|
||||
tray_code = loading_data["tray_id"].strip()
|
||||
spack = loading_data.get("spack", tray_code).strip() # 如果没有spack,使用tray_id作为默认值
|
||||
|
||||
self._current_order_code = order_code
|
||||
self._current_spack = spack # 保存spack到全局变量
|
||||
self.tray_edit.setText(tray_code)
|
||||
|
||||
logging.info(f"从上料对话框获取数据: order_code={order_code}, tray_code={tray_code}, spack={spack}")
|
||||
|
||||
# 获取托盘料值作为拆垛层数
|
||||
stow_num = dialog.pallet_tier_value.text()
|
||||
if stow_num == "--" or not stow_num:
|
||||
@ -1503,6 +1495,11 @@ class MainWindow(MainWindowUI):
|
||||
self._last_load_tray = tray_id
|
||||
self._last_load_time = current_time
|
||||
|
||||
# 确保 _loading_info 中的托盘号与当前托盘号一致
|
||||
if tray_id and self._loading_info:
|
||||
self._loading_info['tray_code'] = tray_id
|
||||
logging.debug(f"同步 _loading_info 中的托盘号为: {tray_id}")
|
||||
|
||||
# 使用InspectionDAO获取未完成的检验数据
|
||||
from dao.inspection_dao import InspectionDAO
|
||||
inspection_dao = InspectionDAO()
|
||||
@ -2666,25 +2663,20 @@ class MainWindow(MainWindowUI):
|
||||
logging.debug(f"字段 '{field_name}' 不在info_values中或为None")
|
||||
|
||||
# 3. 添加其他必要的信息
|
||||
info['xpack'] = self.tray_edit.text()
|
||||
info['spack'] = self.tray_edit.text()
|
||||
xpack = self.tray_edit.text()
|
||||
info['xpack'] = xpack
|
||||
# 使用全局变量中的spack值,如果为空则使用xpack值
|
||||
info['spack'] = self._current_spack if hasattr(self, '_current_spack') and self._current_spack else xpack
|
||||
info['zh'] = axios_num
|
||||
info['mzl'] = weight_kg
|
||||
info['printsl'] = 1
|
||||
# info['pono'] = self._current_order_code
|
||||
logging.info(f"使用的xpack: {xpack}, spack: {info['spack']}")
|
||||
info["dycz"] = info.get("cz")
|
||||
info['qd'] = self._current_gc_qd
|
||||
# 4. 添加sc_gch信息 - 直接使用前端获取到的工程号作为sc_gch
|
||||
# 避免使用全局的_current_gc_sc_gch,因为可能在称重过程中被其他扫码操作更新
|
||||
info['sc_gch'] = gc_note
|
||||
logging.info(f"使用前端工程号 {gc_note} 作为sc_gch")
|
||||
|
||||
# 5. 从数据库获取其他信息作为补充
|
||||
order_others_info = inspection_dao.get_order_others_info(gc_note, self._current_order_code, tray_id)
|
||||
if order_others_info:
|
||||
info.update(order_others_info)
|
||||
|
||||
# 6. 确保data_corp字段存在
|
||||
if 'data_corp' not in info and order_info and 'data_corp' in order_info:
|
||||
info['data_corp'] = order_info['data_corp']
|
||||
# 获取本机IP地址
|
||||
@ -2702,7 +2694,6 @@ class MainWindow(MainWindowUI):
|
||||
info['nw_ip'] = '127.0.0.1'
|
||||
# 调试:检查线材类型字段
|
||||
wire_type_value = info.get('xclx', 'NOT_FOUND')
|
||||
logging.info(f"准备调用接口,线材类型字段值: {wire_type_value}")
|
||||
logging.info(f"完整的info字典: {info}")
|
||||
|
||||
# 调用接口添加到包装记录
|
||||
@ -3055,6 +3046,13 @@ class MainWindow(MainWindowUI):
|
||||
# 重置寄存器 0 和 2 为 0
|
||||
modbus.write_register_until_success(client, 0, 0)
|
||||
modbus.write_register_until_success(client, 2, 0)
|
||||
|
||||
# 确保保留当前托盘号
|
||||
current_tray_id = self.tray_edit.text()
|
||||
if current_tray_id and self._loading_info:
|
||||
self._loading_info['tray_code'] = current_tray_id
|
||||
logging.info(f"上料完成,保留托盘号: {current_tray_id}")
|
||||
|
||||
self.loading_feedback_signal.emit("input", message)
|
||||
# 恢复开始按钮原始样式
|
||||
self.restore_start_button_style()
|
||||
@ -3078,9 +3076,17 @@ class MainWindow(MainWindowUI):
|
||||
if self._loading_info and self._current_stow_num > 0:
|
||||
self.show_operation_status("拆垛层数", "input", str(self._current_stow_num))
|
||||
else:
|
||||
# 上料任务完成,恢复上料按钮样式
|
||||
# 上料任务完成,恢复上料按钮样式,但不清空托盘号
|
||||
self.restore_input_button_style()
|
||||
logging.info("上料任务完成,恢复上料按钮样式")
|
||||
logging.info("上料任务完成,恢复上料按钮样式,保留托盘号")
|
||||
|
||||
# 确保 _loading_info 不被清空
|
||||
if self._loading_info:
|
||||
# 记录当前托盘号,确保不会丢失
|
||||
current_tray_id = self.tray_edit.text()
|
||||
if current_tray_id:
|
||||
self._loading_info['tray_code'] = current_tray_id
|
||||
logging.info(f"上料任务完成,保留托盘号: {current_tray_id}")
|
||||
|
||||
QMessageBox.information(self, "上料操作", desc)
|
||||
except Exception as e:
|
||||
@ -3528,7 +3534,7 @@ class MainWindow(MainWindowUI):
|
||||
self._diameter_measurements.append(xj_value)
|
||||
|
||||
# 保留最近的10个测量值,增加缓冲区大小以便更快收集足够的数据
|
||||
if len(self._diameter_measurements) > 10:
|
||||
if len(self._diameter_measurements) > 6:
|
||||
self._diameter_measurements.pop(0)
|
||||
|
||||
# 显示临时值到状态栏
|
||||
@ -3537,7 +3543,7 @@ class MainWindow(MainWindowUI):
|
||||
return
|
||||
|
||||
# 检查稳定性 - 使用最近的5个测量值
|
||||
measurements = self._diameter_measurements[-5:]
|
||||
measurements = self._diameter_measurements[-3:]
|
||||
min_value = min(measurements)
|
||||
max_value = max(measurements)
|
||||
avg_value = sum(measurements) / len(measurements)
|
||||
@ -3702,13 +3708,7 @@ class MainWindow(MainWindowUI):
|
||||
self._diameter_session_measurements = []
|
||||
self._diameter_session_start_time = 0
|
||||
|
||||
@Slot(float, str, str)
|
||||
def show_diameter_warning(self, final_value, bccd, tccd):
|
||||
"""显示线径超出范围警告(在主线程中执行)- 为避免冲突,此方法已弃用,仅保留接口"""
|
||||
# 这个方法已经被新的线径处理逻辑取代,为避免冲突,此处不再显示弹框
|
||||
# 仅记录日志,保持接口兼容性
|
||||
logging.info(f"线径警告信号已接收,但弹框显示已被新逻辑取代: 线径值 {final_value:.3f}mm, 范围 {bccd} - {tccd}")
|
||||
return
|
||||
|
||||
|
||||
def on_scanner_data_received(self, port_name, data):
|
||||
"""扫码器数据接收回调函数
|
||||
@ -5251,6 +5251,8 @@ class MainWindow(MainWindowUI):
|
||||
except Exception as e:
|
||||
logging.error(f"显示重量警告弹框失败: {str(e)}", exc_info=True)
|
||||
|
||||
# 不需要单独的handle_spack_received方法,我们直接从loading_data中获取spack
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -479,7 +479,12 @@ class OrderQueryDialog(OrderQueryDialogUI):
|
||||
gc_api = GcApi()
|
||||
xpack_response = gc_api.get_xpack(order_code, self.corp_id)
|
||||
if xpack_response and xpack_response.get("status", False):
|
||||
order_data["xpack"] = xpack_response.get("xpack", "")
|
||||
xpack = xpack_response.get("xpack", "")
|
||||
spack = xpack_response.get("spack", "")
|
||||
order_data["xpack"] = xpack
|
||||
order_data["spack"] = spack
|
||||
|
||||
logging.info(f"已获取spack: {spack},已添加到order_data中")
|
||||
# 发出信号
|
||||
self.order_selected.emit(order_data)
|
||||
self.accept()
|
||||
Loading…
Reference in New Issue
Block a user