diff --git a/dao/inspection_dao.py b/dao/inspection_dao.py index 1df316d..df3ce4d 100644 --- a/dao/inspection_dao.py +++ b/dao/inspection_dao.py @@ -624,7 +624,19 @@ class InspectionDAO: except Exception as e: logging.error(f"获取工字轮重量失败: {str(e)}") return 0 - + def get_xj_range(self,order_id): + """获取线径范围""" + try: + sql = """ + SELECT bccd, tccd FROM wsbz_order_info WHERE ddmo = ? + """ + params = (order_id,) + self.db.cursor.execute(sql, params) + result = self.db.cursor.fetchone() + return result[0],result[1] if result else None,None + except Exception as e: + logging.error(f"获取线径范围失败: {str(e)}") + return None,None def get_order_create_time(self, order_id): """获取工程号的最早创建时间 diff --git a/db/jtDB.db b/db/jtDB.db index 96c8542..70019cb 100644 Binary files a/db/jtDB.db and b/db/jtDB.db differ diff --git a/from pymodbus.py b/from pymodbus.py index 3cd0ae8..7a6dc49 100644 --- a/from pymodbus.py +++ b/from pymodbus.py @@ -2,7 +2,7 @@ from pymodbus.client import ModbusTcpClient import time client = ModbusTcpClient('localhost', port=5020) client.connect() -client.write_registers(address=11, values=[2243]) +client.write_registers(address=11, values=[2242]) client.write_registers(address=13, values=[0]) client.write_registers(address=21, values=[0]) diff --git a/widgets/main_window.py b/widgets/main_window.py index ecb7208..e0e2e2e 100644 --- a/widgets/main_window.py +++ b/widgets/main_window.py @@ -657,21 +657,15 @@ class MainWindow(MainWindowUI): logging.info("工程号输入框按下回车事件") # 获取当前输入的工程号 gc_note = self.order_edit.text().strip() - tray_id = self.tray_edit.currentText() if gc_note: logging.info(f"输入的工程号: {gc_note}") #判断是否是接口,如果不是接口直接添加如果是则走接口 # 如果开启接口模式,则需要调用接口同步到业务库 self.add_new_inspection_row(gc_note, self._current_order_code) - - else: logging.warning("工程号为空") QMessageBox.warning(self, "输入提示", "请输入有效的工程号") - # 处理完后可以清除焦点,让输入框失去焦点 - self.central_widget.setFocus() - def add_new_inspection_row(self, gc_note, order_code): """在微丝产线表格中添加一条新记录,添加到表格末尾 @@ -2369,8 +2363,31 @@ class MainWindow(MainWindowUI): break if xj_config: - # 找到对应的检验项,将数据写入对应的单元格 - self.set_inspection_value('xj', xj_config, xj_value) + from dao.inspection_dao import InspectionDAO + inspection_dao = InspectionDAO() + bccd, tccd = inspection_dao.get_xj_range(self._current_order_code) + + if bccd is not None and tccd is not None: + if bccd <= xj_value <= tccd: + self.set_inspection_value('xj', xj_config, xj_value) + else: + logging.warning(f"线径 {xj_value} 不在公差范围内 ({bccd} - {tccd})") + reply = QMessageBox.question( + self, + '确认保存', + f"线径 {xj_value} 不在公差范围内 ({bccd} - {tccd}),\n是否继续保存?", + QMessageBox.Yes | QMessageBox.No, + QMessageBox.No + ) + if reply == QMessageBox.Yes: + self.set_inspection_value('xj', xj_config, xj_value) + else: + logging.info(f"用户取消保存超出范围的线径值: {xj_value}") + # TODO:后续根据实际情况实现 + pass + else: + logging.info(f"未找到订单 {self._current_order_code} 的线径公差范围,直接保存值 {xj_value}") + self.set_inspection_value('xj', xj_config, xj_value) else: logging.warning("未找到线径对应的检验项配置")