40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
|
|
def save_inspection_data(self, order_id, gc_note, tray_id, position, config_id, value, status):
|
|||
|
|
"""保存检验数据到数据库
|
|||
|
|
|
|||
|
|
Args:
|
|||
|
|
order_id: 订单号
|
|||
|
|
gc_note: 工程号
|
|||
|
|
position: 位置序号
|
|||
|
|
config_id: 配置ID
|
|||
|
|
value: 检验值
|
|||
|
|
status: 状态
|
|||
|
|
"""
|
|||
|
|
try:
|
|||
|
|
from dao.inspection_dao import InspectionDAO
|
|||
|
|
inspection_dao = InspectionDAO()
|
|||
|
|
modbus = ModbusUtils()
|
|||
|
|
client = modbus.get_client()
|
|||
|
|
|
|||
|
|
# 获取当前产品状态,优先使用产品状态管理中的状态
|
|||
|
|
current_status = inspection_dao.get_product_status(order_id, gc_note, tray_id)
|
|||
|
|
|
|||
|
|
# 如果当前状态不是初始状态,则使用当前状态而不是传入的status
|
|||
|
|
if current_status not in ['', 'init']:
|
|||
|
|
status = current_status
|
|||
|
|
|
|||
|
|
# 记录保存前的详细日志
|
|||
|
|
logging.info(f"正在保存检验数据: 工程号={gc_note}, 托盘号={tray_id}, 位置={position}, 配置ID={config_id}, 值={value}, 状态={status}")
|
|||
|
|
|
|||
|
|
# 构建数据
|
|||
|
|
data = [{
|
|||
|
|
'position': position,
|
|||
|
|
'config_id': config_id,
|
|||
|
|
'value': value,
|
|||
|
|
'status': status,
|
|||
|
|
'remark': '',
|
|||
|
|
'tray_id': tray_id
|
|||
|
|
}]
|
|||
|
|
|
|||
|
|
# 保存到数据库
|
|||
|
|
inspection_dao.save_inspection_data(order_id, gc_note, data)
|