更新InspectionDAO以支持托盘号,修改主窗口以处理托盘号输入并保存检验数据,增强数据库查询功能以根据托盘号过滤未完成的检验记录。
This commit is contained in:
parent
ca97662db6
commit
703f03f0bb
@ -237,7 +237,7 @@ class InspectionDAO:
|
|||||||
value = item.get('value')
|
value = item.get('value')
|
||||||
status = item.get('status', 'pass')
|
status = item.get('status', 'pass')
|
||||||
remark = item.get('remark', '')
|
remark = item.get('remark', '')
|
||||||
|
tray_id = item.get('tray_id', '')
|
||||||
# 检查是否已存在该工程号和位置的记录
|
# 检查是否已存在该工程号和位置的记录
|
||||||
check_sql = """
|
check_sql = """
|
||||||
SELECT id FROM inspection_data
|
SELECT id FROM inspection_data
|
||||||
@ -253,7 +253,7 @@ class InspectionDAO:
|
|||||||
update_sql = """
|
update_sql = """
|
||||||
UPDATE inspection_data
|
UPDATE inspection_data
|
||||||
SET config_id = ?, value = ?, status = ?, remark = ?,
|
SET config_id = ?, value = ?, status = ?, remark = ?,
|
||||||
update_time = ?, update_by = ?
|
update_time = ?, update_by = ?, tray_id = ?
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
"""
|
"""
|
||||||
update_params = (
|
update_params = (
|
||||||
@ -266,12 +266,12 @@ class InspectionDAO:
|
|||||||
insert_sql = """
|
insert_sql = """
|
||||||
INSERT INTO inspection_data (
|
INSERT INTO inspection_data (
|
||||||
order_id, position, config_id, value, status, remark,
|
order_id, position, config_id, value, status, remark,
|
||||||
create_time, create_by, is_deleted
|
create_time, create_by, is_deleted, tray_id
|
||||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, FALSE)
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, FALSE, ?)
|
||||||
"""
|
"""
|
||||||
insert_params = (
|
insert_params = (
|
||||||
order_id, position, config_id, value, status, remark,
|
order_id, position, config_id, value, status, remark,
|
||||||
current_time, username
|
current_time, username, tray_id
|
||||||
)
|
)
|
||||||
self.db.cursor.execute(insert_sql, insert_params)
|
self.db.cursor.execute(insert_sql, insert_params)
|
||||||
|
|
||||||
@ -281,7 +281,7 @@ class InspectionDAO:
|
|||||||
self.db.rollback_transaction()
|
self.db.rollback_transaction()
|
||||||
logging.error(f"保存检验数据失败: {str(e)}")
|
logging.error(f"保存检验数据失败: {str(e)}")
|
||||||
return False
|
return False
|
||||||
def get_inspection_data_unfinished(self):
|
def get_inspection_data_unfinished(self, tray_id):
|
||||||
"""获取未完成的检验数据
|
"""获取未完成的检验数据
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -293,11 +293,12 @@ class InspectionDAO:
|
|||||||
c.name, c.display_name, c.data_type, c.unit
|
c.name, c.display_name, c.data_type, c.unit
|
||||||
FROM inspection_data d
|
FROM inspection_data d
|
||||||
JOIN inspection_config c ON d.config_id = c.id
|
JOIN inspection_config c ON d.config_id = c.id
|
||||||
WHERE d.is_deleted = FALSE
|
WHERE d.is_deleted = FALSE AND d.tray_id = ?
|
||||||
AND order_id IN (SELECT distinct order_id FROM inspection_data WHERE status != 'pass')
|
AND order_id IN (SELECT distinct order_id FROM inspection_data WHERE status != 'pass')
|
||||||
ORDER BY d.order_id, d.position
|
ORDER BY d.order_id, d.position
|
||||||
"""
|
"""
|
||||||
self.db.cursor.execute(sql)
|
params = (tray_id,)
|
||||||
|
self.db.cursor.execute(sql, params)
|
||||||
results = self.db.cursor.fetchall()
|
results = self.db.cursor.fetchall()
|
||||||
|
|
||||||
data_list = []
|
data_list = []
|
||||||
@ -321,12 +322,12 @@ class InspectionDAO:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"获取未完成的检验数据失败: {str(e)}")
|
logging.error(f"获取未完成的检验数据失败: {str(e)}")
|
||||||
return []
|
return []
|
||||||
def get_inspection_data_by_order(self, order_id):
|
def get_inspection_data_by_order(self, order_id, tray_id):
|
||||||
"""根据工程号获取检验数据
|
"""根据工程号获取检验数据
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
order_id: 工程号
|
order_id: 工程号
|
||||||
|
tray_id: 托盘号
|
||||||
Returns:
|
Returns:
|
||||||
list: 检验数据列表
|
list: 检验数据列表
|
||||||
"""
|
"""
|
||||||
@ -336,10 +337,10 @@ class InspectionDAO:
|
|||||||
c.name, c.display_name, c.data_type, c.unit
|
c.name, c.display_name, c.data_type, c.unit
|
||||||
FROM inspection_data d
|
FROM inspection_data d
|
||||||
JOIN inspection_config c ON d.config_id = c.id
|
JOIN inspection_config c ON d.config_id = c.id
|
||||||
WHERE d.order_id = ? AND d.is_deleted = FALSE
|
WHERE d.order_id = ? AND d.is_deleted = FALSE AND d.tray_id = ?
|
||||||
ORDER BY d.position
|
ORDER BY d.position
|
||||||
"""
|
"""
|
||||||
params = (order_id,)
|
params = (order_id, tray_id)
|
||||||
|
|
||||||
self.db.cursor.execute(sql, params)
|
self.db.cursor.execute(sql, params)
|
||||||
results = self.db.cursor.fetchall()
|
results = self.db.cursor.fetchall()
|
||||||
|
|||||||
BIN
db/jtDB.db
BIN
db/jtDB.db
Binary file not shown.
@ -115,6 +115,11 @@ class MainWindow(MainWindowUI):
|
|||||||
# 工程号输入框回车事件
|
# 工程号输入框回车事件
|
||||||
self.order_edit.returnPressed.connect(self.handle_order_enter)
|
self.order_edit.returnPressed.connect(self.handle_order_enter)
|
||||||
|
|
||||||
|
# 托盘号输入框回车和切换事件,触发未加载数据查询
|
||||||
|
# QComboBox没有returnPressed信号,只有currentTextChanged和activated信号
|
||||||
|
self.tray_edit.currentTextChanged.connect(self.load_unfinished_inspection_data)
|
||||||
|
self.tray_edit.activated.connect(self.load_unfinished_inspection_data) # 当用户选择一项时触发
|
||||||
|
|
||||||
# 连接按钮事件
|
# 连接按钮事件
|
||||||
self.input_button.clicked.connect(self.handle_input)
|
self.input_button.clicked.connect(self.handle_input)
|
||||||
self.output_button.clicked.connect(self.handle_output)
|
self.output_button.clicked.connect(self.handle_output)
|
||||||
@ -435,6 +440,9 @@ class MainWindow(MainWindowUI):
|
|||||||
if not order_id:
|
if not order_id:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# 获取托盘号
|
||||||
|
tray_id = self.tray_edit.currentText()
|
||||||
|
|
||||||
# 获取启用的检验配置
|
# 获取启用的检验配置
|
||||||
enabled_configs = self.inspection_manager.get_enabled_configs()
|
enabled_configs = self.inspection_manager.get_enabled_configs()
|
||||||
|
|
||||||
@ -467,8 +475,10 @@ class MainWindow(MainWindowUI):
|
|||||||
status = 'warning'
|
status = 'warning'
|
||||||
|
|
||||||
# 保存到数据库
|
# 保存到数据库
|
||||||
self.save_inspection_data(order_id, config['position'], config['id'], value, status)
|
self.save_inspection_data(order_id, tray_id, config['position'], config['id'], value, status)
|
||||||
|
|
||||||
|
# 触发查询, 更新页面记录回显
|
||||||
|
self.load_unfinished_inspection_data()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"处理检验单元格变更失败: {str(e)}")
|
logging.error(f"处理检验单元格变更失败: {str(e)}")
|
||||||
self.statusBar().showMessage(f"处理检验数据失败: {str(e)[:50]}...", 3000)
|
self.statusBar().showMessage(f"处理检验数据失败: {str(e)[:50]}...", 3000)
|
||||||
@ -522,7 +532,7 @@ class MainWindow(MainWindowUI):
|
|||||||
logging.error(f"验证检验值失败: {str(e)}")
|
logging.error(f"验证检验值失败: {str(e)}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def save_inspection_data(self, order_id, position, config_id, value, status):
|
def save_inspection_data(self, order_id, tray_id, position, config_id, value, status):
|
||||||
"""保存检验数据到数据库
|
"""保存检验数据到数据库
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -537,7 +547,7 @@ class MainWindow(MainWindowUI):
|
|||||||
inspection_dao = InspectionDAO()
|
inspection_dao = InspectionDAO()
|
||||||
|
|
||||||
# 记录保存前的详细日志
|
# 记录保存前的详细日志
|
||||||
logging.info(f"正在保存检验数据: 工程号={order_id}, 位置={position}, 配置ID={config_id}, 值={value}, 状态={status}")
|
logging.info(f"正在保存检验数据: 工程号={order_id}, 托盘号={tray_id}, 位置={position}, 配置ID={config_id}, 值={value}, 状态={status}")
|
||||||
|
|
||||||
# 构建数据
|
# 构建数据
|
||||||
data = [{
|
data = [{
|
||||||
@ -545,12 +555,13 @@ class MainWindow(MainWindowUI):
|
|||||||
'config_id': config_id,
|
'config_id': config_id,
|
||||||
'value': value,
|
'value': value,
|
||||||
'status': status,
|
'status': status,
|
||||||
'remark': ''
|
'remark': '',
|
||||||
|
'tray_id': tray_id
|
||||||
}]
|
}]
|
||||||
|
|
||||||
# 保存到数据库
|
# 保存到数据库
|
||||||
result = inspection_dao.save_inspection_data(order_id, data)
|
result = inspection_dao.save_inspection_data(order_id, data)
|
||||||
|
# 判断,如果保存成功后,且当前工程号中,全部为 pass 说明该工序已经完成,需要流转到下一步,回显到包装记录中
|
||||||
if result:
|
if result:
|
||||||
logging.info(f"已成功保存工程号 {order_id} 的检验数据,位置: {position}, 值: {value}")
|
logging.info(f"已成功保存工程号 {order_id} 的检验数据,位置: {position}, 值: {value}")
|
||||||
# 显示临时状态消息
|
# 显示临时状态消息
|
||||||
@ -593,6 +604,9 @@ class MainWindow(MainWindowUI):
|
|||||||
if not order_id:
|
if not order_id:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# 获取托盘号
|
||||||
|
tray_id = self.tray_edit.currentText()
|
||||||
|
|
||||||
# 创建上下文菜单
|
# 创建上下文菜单
|
||||||
menu = QMenu(self)
|
menu = QMenu(self)
|
||||||
|
|
||||||
@ -610,7 +624,7 @@ class MainWindow(MainWindowUI):
|
|||||||
|
|
||||||
# 添加查询数据库菜单项
|
# 添加查询数据库菜单项
|
||||||
check_action = menu.addAction("检查数据库记录")
|
check_action = menu.addAction("检查数据库记录")
|
||||||
check_action.triggered.connect(lambda: self.check_database_record(order_id, position))
|
check_action.triggered.connect(lambda: self.check_database_record(order_id, position, tray_id))
|
||||||
|
|
||||||
# 显示菜单
|
# 显示菜单
|
||||||
menu.exec_(self.process_table.viewport().mapToGlobal(pos))
|
menu.exec_(self.process_table.viewport().mapToGlobal(pos))
|
||||||
@ -618,7 +632,7 @@ class MainWindow(MainWindowUI):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"显示表格上下文菜单失败: {str(e)}")
|
logging.error(f"显示表格上下文菜单失败: {str(e)}")
|
||||||
|
|
||||||
def check_database_record(self, order_id, position):
|
def check_database_record(self, order_id, position, tray_id):
|
||||||
"""检查数据库记录
|
"""检查数据库记录
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -630,7 +644,7 @@ class MainWindow(MainWindowUI):
|
|||||||
inspection_dao = InspectionDAO()
|
inspection_dao = InspectionDAO()
|
||||||
|
|
||||||
# 获取检验数据
|
# 获取检验数据
|
||||||
inspection_data = inspection_dao.get_inspection_data_by_order(order_id)
|
inspection_data = inspection_dao.get_inspection_data_by_order(order_id, tray_id)
|
||||||
|
|
||||||
# 查找对应位置的数据
|
# 查找对应位置的数据
|
||||||
matching_data = None
|
matching_data = None
|
||||||
@ -665,11 +679,17 @@ class MainWindow(MainWindowUI):
|
|||||||
from dao.inspection_dao import InspectionDAO
|
from dao.inspection_dao import InspectionDAO
|
||||||
inspection_dao = InspectionDAO()
|
inspection_dao = InspectionDAO()
|
||||||
|
|
||||||
|
# 获取托盘号
|
||||||
|
tray_id = self.tray_edit.currentText()
|
||||||
|
|
||||||
# 使用get_inspection_data_unfinished获取未完成的数据
|
# 使用get_inspection_data_unfinished获取未完成的数据
|
||||||
unfinished_data = inspection_dao.get_inspection_data_unfinished()
|
unfinished_data = inspection_dao.get_inspection_data_unfinished(tray_id)
|
||||||
|
|
||||||
if not unfinished_data:
|
if not unfinished_data:
|
||||||
logging.info("没有未完成的检验数据")
|
logging.info("没有未完成的检验数据")
|
||||||
|
# 清空表格现有数据行
|
||||||
|
while self.process_table.rowCount() > 2:
|
||||||
|
self.process_table.removeRow(2)
|
||||||
return
|
return
|
||||||
|
|
||||||
logging.info(f"已加载未完成的检验数据,共 {len(unfinished_data)} 条记录")
|
logging.info(f"已加载未完成的检验数据,共 {len(unfinished_data)} 条记录")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user