feat: 新增托盘包装统计数据接口,优化主窗口统计数据更新逻辑及字段名称
This commit is contained in:
parent
d40083b096
commit
0878b05033
@ -360,46 +360,44 @@ class GcApi:
|
||||
def get_package_statistics(self, order_id, corp_id):
|
||||
"""
|
||||
获取订单包装统计数据
|
||||
|
||||
Args:
|
||||
order_id: 订单号
|
||||
corp_id: 公司ID
|
||||
|
||||
Returns:
|
||||
dict: 包含总包装轴数和已包装数量的字典
|
||||
"""
|
||||
try:
|
||||
# API 配置中的键名
|
||||
api_key = "get_package_statistics"
|
||||
|
||||
# 构建GET请求参数
|
||||
# 构建URL参数
|
||||
params = {
|
||||
"orderId": order_id,
|
||||
"data_corp": corp_id
|
||||
}
|
||||
|
||||
# 发送GET请求
|
||||
response = self.api_utils.get(api_key, params=params)
|
||||
|
||||
# 检查响应状态
|
||||
if response.get("status", False):
|
||||
return {
|
||||
"status": True,
|
||||
"data": response.get("data", {}),
|
||||
"message": "获取包装统计数据成功"
|
||||
}
|
||||
else:
|
||||
logging.warning(f"获取包装统计数据失败: {response.get('message', '未知错误')}")
|
||||
return {
|
||||
"status": False,
|
||||
"data": {},
|
||||
"message": response.get("message", "获取包装统计数据失败")
|
||||
}
|
||||
|
||||
return response
|
||||
except Exception as e:
|
||||
logging.error(f"获取包装统计数据失败: {str(e)}")
|
||||
return {
|
||||
"status": False,
|
||||
"data": {},
|
||||
"message": f"获取包装统计数据失败: {str(e)}"
|
||||
logging.error(f"获取订单包装统计数据失败: {str(e)}")
|
||||
return {"status": False, "message": str(e)}
|
||||
|
||||
def get_tray_package_statistics(self, order_id, tray_id, corp_id):
|
||||
"""
|
||||
获取托盘包装统计数据
|
||||
|
||||
Args:
|
||||
order_id: 订单号
|
||||
tray_id: 托盘号
|
||||
corp_id: 公司ID
|
||||
|
||||
Returns:
|
||||
dict: 包含托盘完成轴数和托盘完成数量的字典
|
||||
"""
|
||||
try:
|
||||
# API 配置中的键名
|
||||
api_key = "get_tray_package_statistics"
|
||||
# 构建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:
|
||||
logging.error(f"获取托盘包装统计数据失败: {str(e)}")
|
||||
return {"status": False, "message": str(e)}
|
||||
@ -21,7 +21,8 @@
|
||||
"get_params": "/select/getcombcodeWsbz.do",
|
||||
"get_luno": "/common/luno/getLunoListWsbz.do",
|
||||
"get_order_info_by_xpack": "/jsjt/xcsc/tprk/getXsddBzrkGridListByXpackToWsbz.do",
|
||||
"get_package_statistics": "/jsjt/xcsc/tprk/getBzNumWszb.do"
|
||||
"get_package_statistics": "/jsjt/xcsc/tprk/getBzNumByOrderidWszb.do",
|
||||
"get_tray_package_statistics": "/jsjt/xcsc/tprk/getBzNumByTrayWszb.do"
|
||||
},
|
||||
"database": {
|
||||
"default": "sqlite",
|
||||
|
||||
BIN
db/jtDB.db
BIN
db/jtDB.db
Binary file not shown.
@ -1729,7 +1729,7 @@ class MainWindow(MainWindowUI):
|
||||
logging.warning("托盘号为空,无法显示包装记录")
|
||||
# 清空表格
|
||||
self.record_table.setRowCount(0)
|
||||
self.update_package_statistics()
|
||||
# 托盘号为空时不调用update_package_statistics
|
||||
return
|
||||
|
||||
# 读取已包装的记录信息
|
||||
@ -1803,72 +1803,94 @@ class MainWindow(MainWindowUI):
|
||||
def update_package_statistics(self):
|
||||
"""更新包装记录统计数据"""
|
||||
try:
|
||||
# 获取本地数据库统计数据(用于已完成数量和已完成公斤)
|
||||
from dao.inspection_dao import InspectionDAO
|
||||
inspection_dao = InspectionDAO()
|
||||
local_stats = inspection_dao.get_package_statistics(self._current_order_code)
|
||||
# 检查task_table是否存在
|
||||
if not hasattr(self, 'task_table'):
|
||||
logging.warning("task_table不存在,无法更新统计数据")
|
||||
return
|
||||
|
||||
# 初始化API统计数据(用于总完成轴数和总完成数量)
|
||||
api_stats = {
|
||||
'count_all': 0, # 总轴数默认值
|
||||
'weight_all': 0 # 总包装数量默认值
|
||||
# 获取当前的订单号和托盘号
|
||||
order_id = self._current_order_code if hasattr(self, '_current_order_code') else None
|
||||
tray_id = self.tray_edit.currentText() if hasattr(self, 'tray_edit') else ""
|
||||
|
||||
# 初始化订单API统计数据
|
||||
order_api_stats = {
|
||||
'count_all': 0, # 订单完成轴数默认值
|
||||
'weight_all': 0 # 订单完成数量默认值
|
||||
}
|
||||
|
||||
# 检查是否开启API模式,获取总完成轴数和总完成数量
|
||||
if AppMode.is_api() and self._current_order_code:
|
||||
# 初始化托盘API统计数据
|
||||
tray_api_stats = {
|
||||
'tray_zzs': 0, # 托盘完成轴数默认值
|
||||
'tray_ybzsl': 0 # 托盘完成数量默认值
|
||||
}
|
||||
|
||||
# 检查是否开启API模式
|
||||
if AppMode.is_api() and order_id:
|
||||
# 使用API获取包装统计数据
|
||||
from apis.gc_api import GcApi
|
||||
gc_api = GcApi()
|
||||
response = gc_api.get_package_statistics(self._current_order_code, self.corp_id)
|
||||
|
||||
if response.get("status", True):
|
||||
stats_data = response.get("data", {})
|
||||
api_stats = {
|
||||
'count_all': stats_data.get("zzs", 0), # 总轴数
|
||||
'weight_all': float(stats_data.get("ybzsl", 0)) # 总包装数量
|
||||
# 获取订单包装统计数据
|
||||
order_response = gc_api.get_package_statistics(order_id, self.corp_id)
|
||||
if order_response and order_response.get("status", False):
|
||||
order_data = order_response.get("data", {})
|
||||
order_api_stats = {
|
||||
'count_all': order_data.get("zzs", 0), # 订单完成轴数
|
||||
'weight_all': float(order_data.get("ybzsl", 0)) # 订单完成数量
|
||||
}
|
||||
logging.info(f"从API获取总完成统计数据成功: {api_stats}")
|
||||
logging.info(f"从API获取订单完成统计数据成功: {order_api_stats}")
|
||||
else:
|
||||
# API调用失败,仍使用本地数据库的count_all和weight_all
|
||||
logging.warning(f"从API获取总完成统计数据失败: {response.get('message', '未知错误')}")
|
||||
api_stats = {
|
||||
'count_all': 0,
|
||||
'weight_all': 0
|
||||
}
|
||||
else:
|
||||
# 非API模式,使用本地数据库的count_all和weight_all
|
||||
api_stats = {
|
||||
'count_all': local_stats['count_all'],
|
||||
'weight_all': local_stats['weight_all']
|
||||
}
|
||||
error_msg = order_response.get('message', '未知错误') if order_response else "API响应为空"
|
||||
logging.warning(f"从API获取订单完成统计数据失败: {error_msg}")
|
||||
|
||||
# 更新任务表格中的总完成轴数(第一列)
|
||||
total_count_item = QTableWidgetItem(str(api_stats['count_all']))
|
||||
# 如果有托盘号,获取托盘包装统计数据
|
||||
if tray_id:
|
||||
tray_response = gc_api.get_tray_package_statistics(order_id, tray_id, self.corp_id)
|
||||
if tray_response and tray_response.get("status", False):
|
||||
tray_data = tray_response.get("data", {})
|
||||
tray_api_stats = {
|
||||
'tray_zzs': tray_data.get("tray_zzs", 0), # 托盘完成轴数
|
||||
'tray_ybzsl': float(tray_data.get("tray_ybzsl", 0)) # 托盘完成数量
|
||||
}
|
||||
logging.info(f"从API获取托盘完成统计数据成功: {tray_api_stats}")
|
||||
else:
|
||||
error_msg = tray_response.get('message', '未知错误') if tray_response else "API响应为空"
|
||||
logging.warning(f"从API获取托盘完成统计数据失败: {error_msg}")
|
||||
|
||||
# 更新任务表格中的订单完成轴数(第一列)
|
||||
total_count_item = QTableWidgetItem(str(order_api_stats['count_all']))
|
||||
total_count_item.setTextAlignment(Qt.AlignCenter)
|
||||
self.task_table.setItem(2, 0, total_count_item)
|
||||
|
||||
# 更新任务表格中的总完成数量(第二列)
|
||||
total_kg_item = QTableWidgetItem(f"{api_stats['weight_all']:.2f}")
|
||||
# 更新任务表格中的订单完成数量(第二列)
|
||||
total_kg_item = QTableWidgetItem(f"{order_api_stats['weight_all']:.2f}")
|
||||
total_kg_item.setTextAlignment(Qt.AlignCenter)
|
||||
self.task_table.setItem(2, 1, total_kg_item)
|
||||
|
||||
# 更新任务表格中的已完成数量(第三列)- 使用本地统计
|
||||
completed_item = QTableWidgetItem(str(local_stats['count']))
|
||||
completed_item.setTextAlignment(Qt.AlignCenter)
|
||||
self.task_table.setItem(2, 2, completed_item)
|
||||
# 更新任务表格中的托盘完成轴数(第三列)
|
||||
tray_count_item = QTableWidgetItem(str(tray_api_stats['tray_zzs']))
|
||||
tray_count_item.setTextAlignment(Qt.AlignCenter)
|
||||
self.task_table.setItem(2, 2, tray_count_item)
|
||||
|
||||
# 更新任务表格中的已完成公斤(第四列)- 使用本地统计
|
||||
completed_kg_item = QTableWidgetItem(f"{local_stats['weight']:.2f}")
|
||||
completed_kg_item.setTextAlignment(Qt.AlignCenter)
|
||||
self.task_table.setItem(2, 3, completed_kg_item)
|
||||
# 更新任务表格中的托盘完成数量(第四列)
|
||||
tray_kg_item = QTableWidgetItem(f"{tray_api_stats['tray_ybzsl']:.2f}")
|
||||
tray_kg_item.setTextAlignment(Qt.AlignCenter)
|
||||
self.task_table.setItem(2, 3, tray_kg_item)
|
||||
|
||||
# 更新表头显示(确保表头显示正确)
|
||||
# 首先检查表头项是否存在,如果不存在则创建
|
||||
for col in range(4):
|
||||
if self.task_table.horizontalHeaderItem(col) is None:
|
||||
header_item = QTableWidgetItem()
|
||||
self.task_table.setHorizontalHeaderItem(col, header_item)
|
||||
|
||||
# 设置表头文本
|
||||
self.task_table.horizontalHeaderItem(0).setText("订单完成轴数")
|
||||
self.task_table.horizontalHeaderItem(1).setText("订单完成数量")
|
||||
self.task_table.horizontalHeaderItem(2).setText("托盘完成轴数")
|
||||
self.task_table.horizontalHeaderItem(3).setText("托盘完成数量")
|
||||
|
||||
logging.info(f"已更新包装记录统计数据: 总完成轴数={api_stats['count_all']}, 总完成数量={api_stats['weight_all']:.2f}, 已完成数量={local_stats['count']}, 已完成公斤={local_stats['weight']:.2f}")
|
||||
logging.info(f"已更新包装记录统计数据: 订单完成轴数={order_api_stats['count_all']}, 订单完成数量={order_api_stats['weight_all']:.2f}, 托盘完成轴数={tray_api_stats['tray_zzs']}, 托盘完成数量={tray_api_stats['tray_ybzsl']:.2f}")
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"更新包装记录统计数据失败: {str(e)}")
|
||||
@ -3911,6 +3933,10 @@ class MainWindow(MainWindowUI):
|
||||
# 恢复之前的加载状态
|
||||
self._loading_data_in_progress = prev_loading_state
|
||||
|
||||
# 更新包装统计数据
|
||||
self.update_package_statistics()
|
||||
logging.info(f"托盘号变更:更新包装统计数据, 托盘号={tray_id}")
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"处理托盘号变更失败: {str(e)}")
|
||||
|
||||
@ -3947,6 +3973,10 @@ class MainWindow(MainWindowUI):
|
||||
if order_info:
|
||||
self.order_no_input.setText(order_info.get('mo', '').strip())
|
||||
|
||||
# 更新包装统计数据
|
||||
self.update_package_statistics()
|
||||
logging.info(f"订单号变更:更新包装统计数据, 订单号={order_code}")
|
||||
|
||||
def on_report(self):
|
||||
"""报表按钮点击处理"""
|
||||
try:
|
||||
@ -5183,5 +5213,7 @@ class MainWindow(MainWindowUI):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def safe_str(val):
|
||||
return "" if val is None else str(val)
|
||||
Loading…
Reference in New Issue
Block a user