feat:解决没有正常保存线径问题

This commit is contained in:
zhu-mengmeng 2025-07-20 12:22:52 +08:00
parent dcc778ede6
commit 516d7cb99b
5 changed files with 32 additions and 42 deletions

View File

@ -863,7 +863,7 @@ class InspectionDAO:
""" """
try: try:
sql = """ sql = """
SELECT t1.order_id, CASE WHEN t1.position = 12 THEN 'mzl' ELSE name END AS name, value SELECT t1.order_id, CASE t1.position WHEN 12 THEN 'mzl' when 2 then 'xj' ELSE name END AS name, value
FROM wsbz_inspection_data t1 FROM wsbz_inspection_data t1
LEFT JOIN main.wsbz_inspection_config wic ON t1.config_id = wic.id LEFT JOIN main.wsbz_inspection_config wic ON t1.config_id = wic.id
WHERE gc_note = ? AND t1.order_id = ? WHERE gc_note = ? AND t1.order_id = ?

Binary file not shown.

View File

@ -2,7 +2,7 @@ from pymodbus.client import ModbusTcpClient
import time import time
client = ModbusTcpClient('localhost', port=5020) client = ModbusTcpClient('localhost', port=5020)
client.connect() client.connect()
client.write_registers(address=11, values=[8922]) client.write_registers(address=11, values=[9422])
# client.write_registers(address=3, values=[0]) # client.write_registers(address=3, values=[0])
# time.sleep(2) # time.sleep(2)
# client.write_registers(address=0, values=[0]) # client.write_registers(address=0, values=[0])
@ -13,7 +13,9 @@ client.write_registers(address=11, values=[8922])
# 贴标完成 # 贴标完成
# client.write_registers(address=24, values=[1]) # client.write_registers(address=24, values=[1])
# client.write_registers(address=2, values=[0]) # client.write_registers(address=2, values=[0])
# client.write_registers(address=3, values=[0]) # client.write_registers(address=13, values=[1])
# time.sleep(2)
client.write_registers(address=13, values=[0])

View File

@ -28,7 +28,7 @@ class MainWindowUI(QMainWindow):
"线材类型": "xclx", "线材类型": "xclx",
"包装方式": "bzfs", "包装方式": "bzfs",
"轴重要求": "zzyq", "轴重要求": "zzyq",
"线径公差": "xj", "线径公差": "xjgc",
"备注": "remarks_hb" "备注": "remarks_hb"
} }

View File

@ -753,7 +753,6 @@ class MainWindow(MainWindowUI):
client = modbus.get_client() client = modbus.get_client()
try: try:
# 判断当前操作类型(通过检查当前下料信息是否存在) # 判断当前操作类型(通过检查当前下料信息是否存在)
if self._current_unload_info and self._current_unload_num > 0:
# 下料模式 - 开始下料操作 # 下料模式 - 开始下料操作
# 确保寄存器3(下料启动)设为1寄存器4已在handle_output中设置了当前层数 # 确保寄存器3(下料启动)设为1寄存器4已在handle_output中设置了当前层数
success2 = modbus.write_register_until_success(client, 2, 1) success2 = modbus.write_register_until_success(client, 2, 1)
@ -762,23 +761,8 @@ class MainWindow(MainWindowUI):
if success2 and success3: if success2 and success3:
logging.info(f"开始下料操作:当前层数 {self._current_unload_num}/{self._total_unload_num}") logging.info(f"开始下料操作:当前层数 {self._current_unload_num}/{self._total_unload_num}")
QMessageBox.information(self, "操作提示", f"开始下料操作:当前第{self._current_unload_num}") QMessageBox.information(self, "操作提示", f"开始下料操作:当前第{self._current_unload_num}")
# 填充按钮样式
# self.fill_start_button_style()
else: else:
QMessageBox.warning(self, "错误", "开始下料操作失败") QMessageBox.warning(self, "错误", "开始下料操作失败")
else:
# 上料模式 - 默认操作
# 写入当前层数到D0寄存器
success0 = modbus.write_register_until_success(client, 0, self._current_stow_num)
success2 = modbus.write_register_until_success(client, 2, 1)
if success0 and success2:
self._is_loading_active = True # 标记上料任务已开始
logging.info(f"开始上料操作:当前层数 {self._current_stow_num}")
# 填充按钮样式
# self.fill_start_button_style()
else:
QMessageBox.warning(self, "错误", "开始上料操作失败")
except Exception as e: except Exception as e:
logging.error(f"开始操作失败: {str(e)}") logging.error(f"开始操作失败: {str(e)}")
@ -2299,12 +2283,10 @@ class MainWindow(MainWindowUI):
info['pono'] = self._current_order_code info['pono'] = self._current_order_code
info["dycz"] = info.get("cz") info["dycz"] = info.get("cz")
info['qd'] = self._current_gc_qd info['qd'] = self._current_gc_qd
# 4. 添加sc_gch信息 - 直接使用前端获取到的工程号作为sc_gch
# 4. 添加sc_gch信息 # 避免使用全局的_current_gc_sc_gch因为可能在称重过程中被其他扫码操作更新
if hasattr(self, '_current_gc_sc_gch') and self._current_gc_sc_gch: info['sc_gch'] = gc_note
info['sc_gch'] = self._current_gc_sc_gch logging.info(f"使用前端工程号 {gc_note} 作为sc_gch")
else:
info['sc_gch'] = ""
# 5. 从数据库获取其他信息作为补充 # 5. 从数据库获取其他信息作为补充
order_others_info = inspection_dao.get_order_others_info(gc_note, self._current_order_code, tray_id) order_others_info = inspection_dao.get_order_others_info(gc_note, self._current_order_code, tray_id)
@ -3184,7 +3166,7 @@ class MainWindow(MainWindowUI):
bccd, tccd = inspection_dao.get_xj_range(self._current_order_code) bccd, tccd = inspection_dao.get_xj_range(self._current_order_code)
if bccd is not None and tccd is not None: if bccd is not None and tccd is not None:
if float(bccd) - 0.5 <= final_value <= float(tccd) + 0.5: if float(bccd) - 0.02 <= final_value <= float(tccd) + 0.02:
# 使用set_inspection_value保存数据 # 使用set_inspection_value保存数据
self.set_inspection_value('xj', xj_config, final_value) self.set_inspection_value('xj', xj_config, final_value)
logging.info(f"已将稳定的线径值 {final_value:.3f} 保存到工程号 {gc_note} (行 {data_row})") logging.info(f"已将稳定的线径值 {final_value:.3f} 保存到工程号 {gc_note} (行 {data_row})")
@ -3974,9 +3956,15 @@ class MainWindow(MainWindowUI):
else: else:
new_value = "" new_value = ""
# 智能更新逻辑:如果新值不为空且与当前值不同,则更新;如果新值为空但当前值不为空,则保持当前值 # 智能更新逻辑:强度字段允许空值覆盖,其他字段空值不覆盖
if new_value and new_value != current_value: should_update = False
# 有新值且与当前值不同,进行更新 if field_name == "强度": # 强度字段允许空值覆盖
should_update = new_value != current_value
else: # 其他字段:只有新值不为空且与当前值不同时才更新
should_update = new_value and new_value != current_value
if should_update:
# 进行更新
try: try:
if isinstance(self.info_values[field_name], QTextEdit): if isinstance(self.info_values[field_name], QTextEdit):
self.info_values[field_name].setPlainText(new_value) self.info_values[field_name].setPlainText(new_value)
@ -4009,8 +3997,8 @@ class MainWindow(MainWindowUI):
# 其他异常也记录并跳过 # 其他异常也记录并跳过
logging.warning(f"更新控件文本失败,字段: {field_name}, 错误: {str(e)}") logging.warning(f"更新控件文本失败,字段: {field_name}, 错误: {str(e)}")
continue continue
elif not new_value and current_value: elif not new_value and current_value and field_name != "强度":
# 新值为空但当前值不为空,保持当前值 # 新值为空但当前值不为空,且不是强度字段,保持当前值
logging.debug(f"保持字段 '{field_name}' 的当前值: '{current_value}' (API返回空值)") logging.debug(f"保持字段 '{field_name}' 的当前值: '{current_value}' (API返回空值)")
elif not new_value and not current_value: elif not new_value and not current_value:
# 新值和当前值都为空,无需操作 # 新值和当前值都为空,无需操作