From 3be6b964b50f7f29025a09926f892c096dcf8114 Mon Sep 17 00:00:00 2001 From: zhu-mengmeng <15588200382@163.com> Date: Thu, 17 Jul 2025 09:40:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=E4=B8=BB=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E4=B8=AD=E6=96=B0=E5=A2=9E=E8=AE=A2=E5=8D=95=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E5=92=8C=E4=BA=A7=E9=87=8F=E7=BB=9F=E8=AE=A1=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E6=9B=B4=E6=96=B0=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BB=A5=E7=A6=81=E7=94=A8=E7=94=B5=E5=8A=9B=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/app_config.json | 2 +- dao/inspection_dao.py | 81 ++++++++++++++++++++++++++++++++++++++++- db/jtDB.db | Bin 159744 -> 159744 bytes widgets/main_window.py | 73 ++++++++++++++++++++++++++++++++++++- 4 files changed, 153 insertions(+), 3 deletions(-) diff --git a/config/app_config.json b/config/app_config.json index 921f301..27e282e 100644 --- a/config/app_config.json +++ b/config/app_config.json @@ -116,7 +116,7 @@ } }, "electricity": { - "auto_start": true, + "auto_start": false, "interval_minutes": 30 } } \ No newline at end of file diff --git a/dao/inspection_dao.py b/dao/inspection_dao.py index d558423..93a5eb7 100644 --- a/dao/inspection_dao.py +++ b/dao/inspection_dao.py @@ -827,4 +827,83 @@ class InspectionDAO: return result_dict except Exception as e: logging.error(f"获取订单其他信息失败: {str(e)}") - return {} \ No newline at end of file + return {} + def get_order_statistics(self): + """获取订单数量和产量统计数据(日/月/年/累计) + + Returns: + dict: 包含日、月、年、累计订单数量和产量的字典 + """ + try: + # 使用提供的SQL查询 + sql = """ + SELECT CASE + WHEN create_time >= DATE('now') AND create_time < DATE('now', '+1 day') + THEN COUNT(DISTINCT order_id) + ELSE 0 END AS order_cnt_day, + CASE + WHEN create_time >= DATE('now', 'start of month') AND create_time < DATE('now', 'start of month', '+1 month') + THEN COUNT(DISTINCT order_id) + ELSE 0 END AS order_cnt_month, + CASE + WHEN create_time >= DATE('now', 'start of year') AND create_time < DATE('now', 'start of year', '+1 year') + THEN COUNT(DISTINCT order_id) + ELSE 0 END AS order_cnt_year, + COUNT(DISTINCT order_id) AS order_cnt_all, + CASE + WHEN create_time >= DATE('now') AND create_time < DATE('now', '+1 day') + THEN SUM(value) + ELSE 0 END AS order_num_day, + CASE + WHEN create_time >= DATE('now', 'start of month') AND + create_time < DATE('now', 'start of month', '+1 month') + THEN SUM(value) + ELSE 0 END AS order_num_month, + CASE + WHEN create_time >= DATE('now', 'start of year') AND + create_time < DATE('now', 'start of year', '+1 year') + THEN SUM(value) + ELSE 0 END AS order_num_year, + CASE WHEN position = 12 THEN SUM(value) ELSE 0 END AS order_num_all + FROM wsbz_inspection_data WHERE position = 12 + """ + + with SQLUtils('sqlite', database='db/jtDB.db') as db: + db.cursor.execute(sql) + row = db.cursor.fetchone() + + if row: + data = { + 'order_cnt_day': row[0] if row[0] is not None else 0, + 'order_cnt_month': row[1] if row[1] is not None else 0, + 'order_cnt_year': row[2] if row[2] is not None else 0, + 'order_cnt_all': row[3] if row[3] is not None else 0, + 'order_num_day': float(row[4]) if row[4] is not None else 0, + 'order_num_month': float(row[5]) if row[5] is not None else 0, + 'order_num_year': float(row[6]) if row[6] is not None else 0, + 'order_num_all': float(row[7]) if row[7] is not None else 0 + } + return data + else: + return { + 'order_cnt_day': 0, + 'order_cnt_month': 0, + 'order_cnt_year': 0, + 'order_cnt_all': 0, + 'order_num_day': 0, + 'order_num_month': 0, + 'order_num_year': 0, + 'order_num_all': 0 + } + except Exception as e: + logging.error(f"获取订单数量和产量统计数据失败: {str(e)}") + return { + 'order_cnt_day': 0, + 'order_cnt_month': 0, + 'order_cnt_year': 0, + 'order_cnt_all': 0, + 'order_num_day': 0, + 'order_num_month': 0, + 'order_num_year': 0, + 'order_num_all': 0 + } \ No newline at end of file diff --git a/db/jtDB.db b/db/jtDB.db index 034fe412b0cb726be4c0332776c149b2fe247dd4..fc0cc1780bd281147e0ace8726df5f7bd1b21991 100644 GIT binary patch delta 106 zcmZp8z}fJCbAmKu#6%fq#)ypxf9)76o8#=;`> diff --git a/widgets/main_window.py b/widgets/main_window.py index ccb7dd2..3329fd2 100644 --- a/widgets/main_window.py +++ b/widgets/main_window.py @@ -212,6 +212,10 @@ class MainWindow(MainWindowUI): # 启动Modbus监控,确保电力消耗数据在应用启动时就能显示 self.setup_modbus_monitor() + + # 更新订单数量和产量统计数据 + self.update_order_statistics() + logging.info("主窗口初始化时已启动Modbus监控系统") def get_axios_num(self,tray_id): @@ -1663,6 +1667,9 @@ class MainWindow(MainWindowUI): # 立即更新一次用电量数据 self.update_electricity_statistics() + # 立即更新一次订单数量和产量统计数据 + self.update_order_statistics() + logging.info("已连接所有Modbus信号") def update_electricity_statistics(self, value=None): @@ -2096,6 +2103,9 @@ class MainWindow(MainWindowUI): modbus.write_register_until_success(client, 12, 0) modbus.close_client(client) + # 更新订单数量和产量统计数据 + self.update_order_statistics() + # 重新连接单元格变更信号 self.process_table.cellChanged.connect(self.handle_inspection_cell_changed) @@ -2628,6 +2638,9 @@ class MainWindow(MainWindowUI): # 回显数据 self.show_pack_item() + # 更新订单数量和产量统计数据 + self.update_order_statistics() + logging.info(f"NG信号处理完成: 工程号={order_id}, 托盘号={tray_id}, 贴标值={label_value}") except Exception as e: logging.error(f"处理NG信号时发生错误: {str(e)}") @@ -3488,4 +3501,62 @@ class MainWindow(MainWindowUI): except Exception as e: logging.error(f"打印数据失败: {str(e)}") - QMessageBox.critical(self, "错误", f"打印数据失败: {str(e)}") \ No newline at end of file + QMessageBox.critical(self, "错误", f"打印数据失败: {str(e)}") + + def update_order_statistics(self): + """更新订单数量和产量统计数据到项目表格""" + try: + from dao.inspection_dao import InspectionDAO + inspection_dao = InspectionDAO() + + # 获取订单数量和产量统计数据 + statistics = inspection_dao.get_order_statistics() + + # 设置表格项(日、月、年、累计订单数量) + # 当日订单数量 + day_cnt_item = QTableWidgetItem(str(statistics['order_cnt_day'])) + day_cnt_item.setTextAlignment(Qt.AlignCenter) + self.project_table.setItem(0, 1, day_cnt_item) + + # 当月订单数量 + month_cnt_item = QTableWidgetItem(str(statistics['order_cnt_month'])) + month_cnt_item.setTextAlignment(Qt.AlignCenter) + self.project_table.setItem(1, 1, month_cnt_item) + + # 当年订单数量 + year_cnt_item = QTableWidgetItem(str(statistics['order_cnt_year'])) + year_cnt_item.setTextAlignment(Qt.AlignCenter) + self.project_table.setItem(2, 1, year_cnt_item) + + # 累计订单数量 + all_cnt_item = QTableWidgetItem(str(statistics['order_cnt_all'])) + all_cnt_item.setTextAlignment(Qt.AlignCenter) + self.project_table.setItem(3, 1, all_cnt_item) + + # 设置表格项(日、月、年、累计产量) + # 当日产量 + day_num_item = QTableWidgetItem(str(round(statistics['order_num_day'], 2))) + day_num_item.setTextAlignment(Qt.AlignCenter) + self.project_table.setItem(0, 2, day_num_item) + + # 当月产量 + month_num_item = QTableWidgetItem(str(round(statistics['order_num_month'], 2))) + month_num_item.setTextAlignment(Qt.AlignCenter) + self.project_table.setItem(1, 2, month_num_item) + + # 当年产量 + year_num_item = QTableWidgetItem(str(round(statistics['order_num_year'], 2))) + year_num_item.setTextAlignment(Qt.AlignCenter) + self.project_table.setItem(2, 2, year_num_item) + + # 累计产量 + all_num_item = QTableWidgetItem(str(round(statistics['order_num_all'], 2))) + all_num_item.setTextAlignment(Qt.AlignCenter) + self.project_table.setItem(3, 2, all_num_item) + + logging.debug(f"已更新订单数量和产量统计数据: 日订单={statistics['order_cnt_day']}, 月订单={statistics['order_cnt_month']}, 年订单={statistics['order_cnt_year']}, 累计订单={statistics['order_cnt_all']}, 日产量={statistics['order_num_day']}, 月产量={statistics['order_num_month']}, 年产量={statistics['order_num_year']}, 累计产量={statistics['order_num_all']}") + + except Exception as e: + logging.error(f"更新订单数量和产量统计数据失败: {str(e)}") + import traceback + logging.error(traceback.format_exc()) \ No newline at end of file