feat: 新增获取托盘包装统计数据接口,优化加载对话框和主窗口的spack处理逻辑
This commit is contained in:
parent
e3ab0502be
commit
d10c51edca
@ -103,6 +103,28 @@ class GcApi:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"获取订单信息失败: {str(e)}")
|
logging.error(f"获取订单信息失败: {str(e)}")
|
||||||
return None
|
return None
|
||||||
|
def get_spakc_info(self, order_code,corp_id,tray_id):
|
||||||
|
"""
|
||||||
|
获取订单信息
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# API 配置中的键名
|
||||||
|
api_key = "get_spack_info"
|
||||||
|
# 构建 form-data 格式的数据
|
||||||
|
order_dict = {"orderId":order_code,"data_corp":corp_id,"trayId":tray_id}
|
||||||
|
data = {
|
||||||
|
"parms": json.dumps(order_dict), # 必须将数据序列化为JSON字符串
|
||||||
|
"pageIndex": 0,
|
||||||
|
"pageSize": 10,
|
||||||
|
"sortField": "",
|
||||||
|
"sortOrder": ""
|
||||||
|
}
|
||||||
|
# 将工程号作为参数传递,使用 data 参数传递 form-data 格式数据
|
||||||
|
response = self.api_utils.post(api_key, data=data)
|
||||||
|
return response
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"获取订单信息失败: {str(e)}")
|
||||||
|
return None
|
||||||
def add_order_info(self, info):
|
def add_order_info(self, info):
|
||||||
"""
|
"""
|
||||||
添加订单信息
|
添加订单信息
|
||||||
@ -398,6 +420,33 @@ class GcApi:
|
|||||||
}
|
}
|
||||||
response = self.api_utils.get(api_key, params=params)
|
response = self.api_utils.get(api_key, params=params)
|
||||||
return response
|
return response
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"获取托盘包装统计数据失败: {str(e)}")
|
||||||
|
return {"status": False, "message": str(e)}
|
||||||
|
|
||||||
|
def get_spack_info(self, order_id, tray_id, corp_id):
|
||||||
|
"""
|
||||||
|
获取托盘包装统计数据
|
||||||
|
|
||||||
|
Args:
|
||||||
|
order_id: 订单号
|
||||||
|
tray_id: 托盘号
|
||||||
|
corp_id: 公司ID
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: 包含托盘完成轴数和托盘完成数量的字典
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# API 配置中的键名
|
||||||
|
api_key = "get_spack_info"
|
||||||
|
# 构建URL参数
|
||||||
|
params = {
|
||||||
|
"orderId": order_id,
|
||||||
|
"trayId": tray_id,
|
||||||
|
"data_corp": corp_id
|
||||||
|
}
|
||||||
|
response = self.api_utils.get(api_key, params=params)
|
||||||
|
return response
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"获取托盘包装统计数据失败: {str(e)}")
|
logging.error(f"获取托盘包装统计数据失败: {str(e)}")
|
||||||
return {"status": False, "message": str(e)}
|
return {"status": False, "message": str(e)}
|
||||||
@ -7,7 +7,7 @@
|
|||||||
"enable_keyboard_listener": false,
|
"enable_keyboard_listener": false,
|
||||||
"enable_camera": false
|
"enable_camera": false
|
||||||
},
|
},
|
||||||
"base_url": "https://jsjtnew.tengzhicn.com/",
|
"base_url": "http://localhost:8085",
|
||||||
"mode": "api"
|
"mode": "api"
|
||||||
},
|
},
|
||||||
"apis": {
|
"apis": {
|
||||||
@ -22,7 +22,8 @@
|
|||||||
"get_luno": "/common/luno/getLunoListWsbz.do",
|
"get_luno": "/common/luno/getLunoListWsbz.do",
|
||||||
"get_order_info_by_xpack": "/jsjt/xcsc/tprk/getXsddBzrkGridListByXpackToWsbz.do",
|
"get_order_info_by_xpack": "/jsjt/xcsc/tprk/getXsddBzrkGridListByXpackToWsbz.do",
|
||||||
"get_package_statistics": "/jsjt/xcsc/tprk/getBzNumByOrderidWszb.do",
|
"get_package_statistics": "/jsjt/xcsc/tprk/getBzNumByOrderidWszb.do",
|
||||||
"get_tray_package_statistics": "/jsjt/xcsc/tprk/getBzNumByTrayWszb.do"
|
"get_tray_package_statistics": "/jsjt/xcsc/tprk/getBzNumByTrayWszb.do",
|
||||||
|
"get_spack_info": "/jsjt/xcsc/tprk/getSpackWszb.do"
|
||||||
},
|
},
|
||||||
"database": {
|
"database": {
|
||||||
"default": "sqlite",
|
"default": "sqlite",
|
||||||
|
|||||||
@ -1332,71 +1332,94 @@ class InspectionDAO:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"查询检验数据失败: {str(e)}")
|
logging.error(f"查询检验数据失败: {str(e)}")
|
||||||
return None
|
return None
|
||||||
def get_package_statistics(self, order_id=None):
|
# def get_package_statistics(self, order_id=None):
|
||||||
"""获取包装记录的统计数据
|
# """获取包装记录的统计数据
|
||||||
|
|
||||||
|
# Args:
|
||||||
|
# order_id: 订单号,如果为None则获取所有订单的统计
|
||||||
|
|
||||||
|
# Returns:
|
||||||
|
# dict: 包含当前订单和所有订单的统计数据
|
||||||
|
# {
|
||||||
|
# 'count': 当前订单的记录数量,
|
||||||
|
# 'weight': 当前订单的总重量,
|
||||||
|
# 'count_all': 所有订单的记录数量,
|
||||||
|
# 'weight_all': 所有订单的总重量
|
||||||
|
# }
|
||||||
|
# """
|
||||||
|
# try:
|
||||||
|
# # 构建SQL查询
|
||||||
|
# sql = """
|
||||||
|
# SELECT SUM(weight) weight,
|
||||||
|
# SUM(count) count,
|
||||||
|
# SUM(count_all) count_all,
|
||||||
|
# SUM(weight_all) weight_all
|
||||||
|
# FROM (
|
||||||
|
# SELECT COUNT(gc_note) AS count,
|
||||||
|
# SUM(weight) AS weight,
|
||||||
|
# '' AS count_all,
|
||||||
|
# '' AS weight_all
|
||||||
|
# FROM wsbz_inspection_pack_data
|
||||||
|
# WHERE order_id = ?
|
||||||
|
# UNION ALL
|
||||||
|
# SELECT '', '',
|
||||||
|
# COUNT(gc_note) AS count_all,
|
||||||
|
# SUM(weight) AS weight_all
|
||||||
|
# FROM wsbz_inspection_pack_data
|
||||||
|
# ) a
|
||||||
|
# """
|
||||||
|
|
||||||
|
# with SQLUtils('sqlite', database='db/jtDB.db') as db:
|
||||||
|
# # 执行查询
|
||||||
|
# db.cursor.execute(sql, (order_id or '',))
|
||||||
|
|
||||||
|
# # 获取结果
|
||||||
|
# row = db.cursor.fetchone()
|
||||||
|
|
||||||
|
# # 如果有结果,转换为字典
|
||||||
|
# if row:
|
||||||
|
# return {
|
||||||
|
# 'weight': float(row[0] or 0),
|
||||||
|
# 'count': int(row[1] or 0),
|
||||||
|
# 'count_all': int(row[2] or 0),
|
||||||
|
# 'weight_all': float(row[3] or 0)
|
||||||
|
# }
|
||||||
|
# else:
|
||||||
|
# return {
|
||||||
|
# 'weight': 0,
|
||||||
|
# 'count': 0,
|
||||||
|
# 'count_all': 0,
|
||||||
|
# 'weight_all': 0
|
||||||
|
# }
|
||||||
|
|
||||||
|
# except Exception as e:
|
||||||
|
# logging.error(f"获取包装记录统计数据失败: {str(e)}")
|
||||||
|
# return {
|
||||||
|
# 'weight': 0,
|
||||||
|
# 'count': 0,
|
||||||
|
# 'count_all': 0,
|
||||||
|
# 'weight_all': 0
|
||||||
|
# }
|
||||||
|
def get_spack_by_order_id(self, order_id,tray_id):
|
||||||
|
"""根据订单号和托盘号获取箱号(spack)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
order_id: 订单号,如果为None则获取所有订单的统计
|
order_id: 订单号
|
||||||
|
tray_id: 托盘号
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: 包含当前订单和所有订单的统计数据
|
str: 箱号(spack),如果不存在则返回空字符串
|
||||||
{
|
|
||||||
'count': 当前订单的记录数量,
|
|
||||||
'weight': 当前订单的总重量,
|
|
||||||
'count_all': 所有订单的记录数量,
|
|
||||||
'weight_all': 所有订单的总重量
|
|
||||||
}
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 构建SQL查询
|
|
||||||
sql = """
|
|
||||||
SELECT SUM(weight) weight,
|
|
||||||
SUM(count) count,
|
|
||||||
SUM(count_all) count_all,
|
|
||||||
SUM(weight_all) weight_all
|
|
||||||
FROM (
|
|
||||||
SELECT COUNT(gc_note) AS count,
|
|
||||||
SUM(weight) AS weight,
|
|
||||||
'' AS count_all,
|
|
||||||
'' AS weight_all
|
|
||||||
FROM wsbz_inspection_pack_data
|
|
||||||
WHERE order_id = ?
|
|
||||||
UNION ALL
|
|
||||||
SELECT '', '',
|
|
||||||
COUNT(gc_note) AS count_all,
|
|
||||||
SUM(weight) AS weight_all
|
|
||||||
FROM wsbz_inspection_pack_data
|
|
||||||
) a
|
|
||||||
"""
|
|
||||||
|
|
||||||
with SQLUtils('sqlite', database='db/jtDB.db') as db:
|
with SQLUtils('sqlite', database='db/jtDB.db') as db:
|
||||||
# 执行查询
|
db.cursor.execute("SELECT package_id FROM wsbz_inspection_data WHERE order_id = ? AND tray_id = ? LIMIT 1", (order_id, tray_id))
|
||||||
db.cursor.execute(sql, (order_id or '',))
|
|
||||||
|
|
||||||
# 获取结果
|
|
||||||
row = db.cursor.fetchone()
|
row = db.cursor.fetchone()
|
||||||
|
if row:
|
||||||
|
return row[0]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
# 如果有结果,转换为字典
|
|
||||||
if row:
|
|
||||||
return {
|
|
||||||
'weight': float(row[0] or 0),
|
|
||||||
'count': int(row[1] or 0),
|
|
||||||
'count_all': int(row[2] or 0),
|
|
||||||
'weight_all': float(row[3] or 0)
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
return {
|
|
||||||
'weight': 0,
|
|
||||||
'count': 0,
|
|
||||||
'count_all': 0,
|
|
||||||
'weight_all': 0
|
|
||||||
}
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"获取包装记录统计数据失败: {str(e)}")
|
logging.error(f"获取箱号(spack)失败: {str(e)}")
|
||||||
return {
|
return None
|
||||||
'weight': 0,
|
|
||||||
'count': 0,
|
|
||||||
'count_all': 0,
|
|
||||||
'weight_all': 0
|
|
||||||
}
|
|
||||||
BIN
db/jtDB.db
BIN
db/jtDB.db
Binary file not shown.
@ -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=[4762])
|
client.write_registers(address=11, values=[5062])
|
||||||
# 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,7 @@ client.write_registers(address=11, values=[4762])
|
|||||||
# 贴标完成
|
# 贴标完成
|
||||||
# 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=13, values=[1])
|
client.write_registers(address=13, values=[0])
|
||||||
# time.sleep(2)
|
# time.sleep(2)
|
||||||
# client.write_registers(address=20, values=[0])
|
# client.write_registers(address=20, values=[0])
|
||||||
# time.sleep(3)
|
# time.sleep(3)
|
||||||
|
|||||||
@ -372,16 +372,20 @@ class LoadingDialog(LoadingDialogUI):
|
|||||||
Returns:
|
Returns:
|
||||||
dict: 上料数据字典
|
dict: 上料数据字典
|
||||||
"""
|
"""
|
||||||
# 获取spack值,如果order_data中有则使用,否则默认使用tray_id
|
order_id = self.order_input.text().strip()
|
||||||
|
tray_id = self.tray_input.text().strip()
|
||||||
spack = ""
|
spack = ""
|
||||||
if self.order_data and isinstance(self.order_data, dict) and 'spack' in self.order_data:
|
|
||||||
spack = self.order_data['spack']
|
gc_api = GcApi()
|
||||||
|
response = gc_api.get_spack_info(order_id, tray_id, self.corp_id)
|
||||||
|
if response and response.get("status", False):
|
||||||
|
spack = response.get("data", {}).get("spack", "")
|
||||||
else:
|
else:
|
||||||
spack = self.tray_input.text().strip()
|
spack = ""
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"order_id": self.order_input.text().strip(),
|
"order_id": order_id,
|
||||||
"tray_id": self.tray_input.text().strip(),
|
"tray_id": tray_id,
|
||||||
"spack": spack, # 添加spack字段
|
"spack": spack, # 添加spack字段
|
||||||
"pallet_tier": self.pallet_tier_value.text().strip(),
|
"pallet_tier": self.pallet_tier_value.text().strip(),
|
||||||
"order_data": self.order_data if self.order_data else {}
|
"order_data": self.order_data if self.order_data else {}
|
||||||
|
|||||||
@ -673,10 +673,9 @@ class MainWindow(MainWindowUI):
|
|||||||
loading_data = dialog.get_loading_data()
|
loading_data = dialog.get_loading_data()
|
||||||
order_code = loading_data.get("order_id", "").strip()
|
order_code = loading_data.get("order_id", "").strip()
|
||||||
tray_code = loading_data.get("tray_id", "").strip()
|
tray_code = loading_data.get("tray_id", "").strip()
|
||||||
spack = loading_data.get("spack", tray_code).strip() if loading_data.get("spack") else tray_code.strip()
|
spack = loading_data.get("spack")
|
||||||
|
self._current_spack = spack or self._current_spack or tray_code # 保存spack到全局变量
|
||||||
self._current_order_code = order_code
|
self._current_order_code = order_code
|
||||||
self._current_spack = spack # 保存spack到全局变量
|
|
||||||
self.tray_edit.setText(tray_code)
|
self.tray_edit.setText(tray_code)
|
||||||
|
|
||||||
logging.info(f"从上料对话框获取数据: order_code={order_code}, tray_code={tray_code}, spack={spack}")
|
logging.info(f"从上料对话框获取数据: order_code={order_code}, tray_code={tray_code}, spack={spack}")
|
||||||
@ -1155,10 +1154,10 @@ class MainWindow(MainWindowUI):
|
|||||||
'status': 'init', # 设置初始状态
|
'status': 'init', # 设置初始状态
|
||||||
'remark': '',
|
'remark': '',
|
||||||
'tray_id': tray_id,
|
'tray_id': tray_id,
|
||||||
'package_id': self._current_spack
|
'package_id': self._current_spack or tray_id
|
||||||
}]
|
}]
|
||||||
inspection_dao.save_inspection_data(self._current_order_code,gc_note, data)
|
inspection_dao.save_inspection_data(self._current_order_code,gc_note, data)
|
||||||
package_id = self._current_spack if hasattr(self, '_current_spack') and self._current_spack else None
|
package_id = self._current_spack if hasattr(self, '_current_spack') and self._current_spack else tray_id
|
||||||
# 为贴标和称重也创建空记录
|
# 为贴标和称重也创建空记录
|
||||||
for position in [11, 12, 13]: # 11是贴标,12是毛重,13是净重
|
for position in [11, 12, 13]: # 11是贴标,12是毛重,13是净重
|
||||||
data = [{
|
data = [{
|
||||||
@ -1378,7 +1377,7 @@ class MainWindow(MainWindowUI):
|
|||||||
# 构建数据
|
# 构建数据
|
||||||
# 如果没有提供package_id,则使用当前的_current_spack
|
# 如果没有提供package_id,则使用当前的_current_spack
|
||||||
if package_id is None:
|
if package_id is None:
|
||||||
package_id = getattr(self, '_current_spack', '')
|
package_id = getattr(self, '_current_spack', '') or tray_id
|
||||||
|
|
||||||
data = [{
|
data = [{
|
||||||
'position': position,
|
'position': position,
|
||||||
@ -1523,7 +1522,7 @@ class MainWindow(MainWindowUI):
|
|||||||
inspection_dao = InspectionDAO()
|
inspection_dao = InspectionDAO()
|
||||||
|
|
||||||
# 获取箱号
|
# 获取箱号
|
||||||
package_id = self._current_spack if hasattr(self, '_current_spack') and self._current_spack else None
|
package_id = self._current_spack if hasattr(self, '_current_spack') and self._current_spack else tray_id
|
||||||
|
|
||||||
# 使用get_inspection_data_unfinished获取未完成的数据
|
# 使用get_inspection_data_unfinished获取未完成的数据
|
||||||
unfinished_data = inspection_dao.get_inspection_data_unfinished(tray_id, package_id)
|
unfinished_data = inspection_dao.get_inspection_data_unfinished(tray_id, package_id)
|
||||||
@ -1776,7 +1775,7 @@ class MainWindow(MainWindowUI):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# 获取箱号
|
# 获取箱号
|
||||||
package_id = self._current_spack if hasattr(self, '_current_spack') and self._current_spack else None
|
package_id = self._current_spack if hasattr(self, '_current_spack') and self._current_spack else tray_id
|
||||||
|
|
||||||
# 读取已包装的记录信息
|
# 读取已包装的记录信息
|
||||||
package_record = inspection_dao.get_package_record(tray_id, package_id)
|
package_record = inspection_dao.get_package_record(tray_id, package_id)
|
||||||
@ -1989,7 +1988,7 @@ class MainWindow(MainWindowUI):
|
|||||||
|
|
||||||
# 添加查询数据库菜单项
|
# 添加查询数据库菜单项
|
||||||
check_action = menu.addAction("检查数据库记录")
|
check_action = menu.addAction("检查数据库记录")
|
||||||
package_id = self._current_spack if hasattr(self, '_current_spack') and self._current_spack else None
|
package_id = self._current_spack if hasattr(self, '_current_spack') and self._current_spack else tray_id
|
||||||
check_action.triggered.connect(lambda: self.check_database_record(order_id, position, tray_id, package_id))
|
check_action.triggered.connect(lambda: self.check_database_record(order_id, position, tray_id, package_id))
|
||||||
|
|
||||||
# 显示菜单
|
# 显示菜单
|
||||||
@ -2012,7 +2011,7 @@ class MainWindow(MainWindowUI):
|
|||||||
inspection_dao = InspectionDAO()
|
inspection_dao = InspectionDAO()
|
||||||
|
|
||||||
# 如果没有提供package_id,则使用当前的_current_spack
|
# 如果没有提供package_id,则使用当前的_current_spack
|
||||||
package_id = self._current_spack if hasattr(self, '_current_spack') and self._current_spack else None
|
package_id = self._current_spack if hasattr(self, '_current_spack') and self._current_spack else tray_id
|
||||||
|
|
||||||
# 获取检验数据
|
# 获取检验数据
|
||||||
inspection_data = inspection_dao.get_inspection_data_by_order(order_id, order_id, tray_id, package_id)
|
inspection_data = inspection_dao.get_inspection_data_by_order(order_id, order_id, tray_id, package_id)
|
||||||
@ -2868,7 +2867,7 @@ class MainWindow(MainWindowUI):
|
|||||||
# 写入单元格
|
# 写入单元格
|
||||||
self.process_table.setItem(data_row, label_col, label_item)
|
self.process_table.setItem(data_row, label_col, label_item)
|
||||||
logging.info(f"已将贴标数据 {axios_num} 写入表格单元格 [{data_row}, {label_col}]")
|
logging.info(f"已将贴标数据 {axios_num} 写入表格单元格 [{data_row}, {label_col}]")
|
||||||
package_id = self._current_spack if hasattr(self, '_current_spack') and self._current_spack else None
|
package_id = self._current_spack if hasattr(self, '_current_spack') and self._current_spack else tray_id
|
||||||
# 在这里添加保存贴标数据到数据库的代码
|
# 在这里添加保存贴标数据到数据库的代码
|
||||||
self.save_inspection_data(self._current_order_code, gc_note, tray_id, 11, 11, str(axios_num), "pass", package_id)
|
self.save_inspection_data(self._current_order_code, gc_note, tray_id, 11, 11, str(axios_num), "pass", package_id)
|
||||||
logging.info(f"已将贴标数据 {axios_num} 保存到数据库")
|
logging.info(f"已将贴标数据 {axios_num} 保存到数据库")
|
||||||
@ -3564,16 +3563,16 @@ class MainWindow(MainWindowUI):
|
|||||||
# 添加当前测量值到列表
|
# 添加当前测量值到列表
|
||||||
self._diameter_measurements.append(xj_value)
|
self._diameter_measurements.append(xj_value)
|
||||||
|
|
||||||
# 保留最近的10个测量值,增加缓冲区大小以便更快收集足够的数据
|
# 保留最近的6个测量值,增加缓冲区大小以便更快收集足够的数据
|
||||||
if len(self._diameter_measurements) > 6:
|
if len(self._diameter_measurements) > 6:
|
||||||
self._diameter_measurements.pop(0)
|
self._diameter_measurements.pop(0)
|
||||||
|
|
||||||
# 显示临时值到状态栏
|
# 显示临时值到状态栏
|
||||||
if len(self._diameter_measurements) < 5:
|
if len(self._diameter_measurements) < 3:
|
||||||
self.statusBar().showMessage(f"线径数据收集中: {xj_value:.3f} ({len(self._diameter_measurements)}/5)", 2000)
|
self.statusBar().showMessage(f"线径数据收集中: {xj_value:.3f} ({len(self._diameter_measurements)}/3)", 2000)
|
||||||
return
|
return
|
||||||
|
|
||||||
# 检查稳定性 - 使用最近的5个测量值
|
# 检查稳定性 - 使用最近的3个测量值
|
||||||
measurements = self._diameter_measurements[-3:]
|
measurements = self._diameter_measurements[-3:]
|
||||||
min_value = min(measurements)
|
min_value = min(measurements)
|
||||||
max_value = max(measurements)
|
max_value = max(measurements)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user