feat:确保扫码数据永远在最后一个

This commit is contained in:
zhu-mengmeng 2025-07-19 17:20:09 +08:00
parent e36d5475dd
commit 668700353f
3 changed files with 73 additions and 2 deletions

View File

@ -8,7 +8,7 @@
"enable_camera": false "enable_camera": false
}, },
"base_url": "http://localhost:8085", "base_url": "http://localhost:8085",
"mode": "api" "mode": "standalone"
}, },
"apis": { "apis": {
"get_tray_info": "/apjt/xcsc/tpda/getByTp_note/", "get_tray_info": "/apjt/xcsc/tpda/getByTp_note/",

Binary file not shown.

View File

@ -943,6 +943,44 @@ class MainWindow(MainWindowUI):
logging.warning("工程号为空") logging.warning("工程号为空")
QMessageBox.warning(self, "输入提示", "请输入有效的工程号") QMessageBox.warning(self, "输入提示", "请输入有效的工程号")
def test_rapid_scanning(self):
"""测试快速连续扫码的场景,确保最新扫码的工程号始终在最后"""
logging.info("开始测试快速连续扫码场景")
# 模拟扫码工程号A
logging.info("模拟扫码工程号A")
self.order_edit.setText("A")
self.handle_order_enter()
# 等待一小段时间
QTimer.singleShot(100, lambda: self._test_scan_b())
def _test_scan_b(self):
"""测试扫码工程号B"""
logging.info("模拟扫码工程号B")
self.order_edit.setText("B")
self.handle_order_enter()
# 等待一小段时间后检查结果
QTimer.singleShot(200, self._check_test_result)
def _check_test_result(self):
"""检查测试结果"""
logging.info("检查快速连续扫码测试结果")
total_rows = self.process_table.rowCount()
if total_rows > 2:
last_gc_note = self.process_table.item(total_rows - 1, 1)
if last_gc_note:
logging.info(f"最后一行的工程号: {last_gc_note.text()}")
if last_gc_note.text() == "B":
logging.info("✅ 测试通过最新扫码的工程号B正确显示在最后")
else:
logging.error("❌ 测试失败最新扫码的工程号B没有显示在最后")
else:
logging.error("❌ 测试失败:无法获取最后一行的工程号")
else:
logging.error("❌ 测试失败:表格中没有数据行")
def add_new_inspection_row(self, gc_note, order_code): def add_new_inspection_row(self, gc_note, order_code):
"""在微丝产线表格中添加一条新记录,添加到表格末尾 """在微丝产线表格中添加一条新记录,添加到表格末尾
@ -950,6 +988,12 @@ class MainWindow(MainWindowUI):
gc_note: 工程号 gc_note: 工程号
order_info: 从接口获取的工程号信息 order_info: 从接口获取的工程号信息
""" """
# 设置当前正在处理的工程号,确保它在重新加载时显示在最后
self._current_gc_note = gc_note
# 记录添加时间,用于确保最新添加的工程号在最后
self._current_gc_note_timestamp = time.time()
logging.info(f"设置最新扫码的工程号: {gc_note}, 时间戳: {self._current_gc_note_timestamp}")
try: try:
# 获取启用的检验配置 # 获取启用的检验配置
enabled_configs = self.inspection_manager.get_enabled_configs() enabled_configs = self.inspection_manager.get_enabled_configs()
@ -1091,6 +1135,9 @@ class MainWindow(MainWindowUI):
finally: finally:
# 重新加载数据确保UI显示正确 # 重新加载数据确保UI显示正确
self._safe_load_data() self._safe_load_data()
# 清除当前工程号标记和时间戳
self._current_gc_note = None
self._current_gc_note_timestamp = None
def limit_table_rows(self, max_rows): def limit_table_rows(self, max_rows):
"""限制表格最大行数 """限制表格最大行数
@ -1354,9 +1401,29 @@ class MainWindow(MainWindowUI):
row_idx = 2 row_idx = 2
# 使用DAO方法按创建时间排序工程号确保FIFO顺序最早创建的在最前面 # 使用DAO方法按创建时间排序工程号确保FIFO顺序最早创建的在最前面
# 但是新添加的工程号应该始终显示在最后
from dao.inspection_dao import InspectionDAO from dao.inspection_dao import InspectionDAO
inspection_dao = InspectionDAO() inspection_dao = InspectionDAO()
# 获取当前正在处理的工程号(如果有的话)
current_gc_note = getattr(self, '_current_gc_note', None)
current_timestamp = getattr(self, '_current_gc_note_timestamp', None)
# 按创建时间排序,但确保新添加的工程号在最后
sorted_gc_notes = inspection_dao.get_orders_by_create_time(list(orders_data.keys())) sorted_gc_notes = inspection_dao.get_orders_by_create_time(list(orders_data.keys()))
logging.info(f"按创建时间排序后的工程号列表: {sorted_gc_notes}")
# 如果当前有正在处理的工程号,确保它在最后
if current_gc_note and current_gc_note in sorted_gc_notes:
# 将当前工程号移到列表末尾
sorted_gc_notes.remove(current_gc_note)
sorted_gc_notes.append(current_gc_note)
logging.info(f"将最新扫码的工程号 {current_gc_note} (时间戳: {current_timestamp}) 移到列表末尾,确保显示在最后")
logging.info(f"调整后的工程号列表: {sorted_gc_notes}")
elif current_gc_note:
logging.info(f"当前正在处理的工程号 {current_gc_note} 不在数据库记录中,可能是新添加的")
else:
logging.info("没有当前正在处理的工程号")
for gc_note in sorted_gc_notes: for gc_note in sorted_gc_notes:
items = orders_data[gc_note] items = orders_data[gc_note]
@ -3251,7 +3318,11 @@ class MainWindow(MainWindowUI):
if self.process_table.rowCount() <= 2: # 只有表头行 if self.process_table.rowCount() <= 2: # 只有表头行
order_id = self.order_edit.text().strip() order_id = self.order_edit.text().strip()
if order_id: if order_id:
self.add_new_inspection_row(order_id) # 设置当前正在处理的工程号,确保它在重新加载时显示在最后
self._current_gc_note = order_id
self._current_gc_note_timestamp = time.time()
logging.info(f"在set_inspection_value中设置最新扫码的工程号: {order_id}, 时间戳: {self._current_gc_note_timestamp}")
self.add_new_inspection_row(order_id, self._current_order_code)
data_row = 2 # 新添加的行 data_row = 2 # 新添加的行
else: else:
logging.warning("无法添加新行,订单号为空") logging.warning("无法添加新行,订单号为空")