From 4d2f9302ff3a42334bad9cab2989d1389b4e2bc1 Mon Sep 17 00:00:00 2001 From: "qichi.liang" Date: Mon, 29 Dec 2025 02:50:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BD=93=E6=9C=88=E6=AF=8F=E8=89=98=E8=88=B9?= =?UTF-8?q?=E7=9A=84=E4=BD=9C=E4=B8=9A=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database.py | 24 ++++++++++++++++++++++++ src/gui.py | 20 +++++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/database.py b/src/database.py index e47bd66..410810c 100644 --- a/src/database.py +++ b/src/database.py @@ -191,6 +191,30 @@ class DailyLogsDatabase: 'date_range': {'start': date_range[0], 'end': date_range[1]} } + def get_ships_with_monthly_teu(self, year_month: str = None) -> List[Dict]: + """获取所有船只及其当月TEU总量""" + cursor = self.conn.cursor() + + if year_month: + # 按年月筛选 + cursor.execute(''' + SELECT ship_name, SUM(teu) as monthly_teu + FROM daily_handover_logs + WHERE date LIKE ? + GROUP BY ship_name + ORDER BY monthly_teu DESC + ''', (f'{year_month}%',)) + else: + # 全部 + cursor.execute(''' + SELECT ship_name, SUM(teu) as monthly_teu + FROM daily_handover_logs + GROUP BY ship_name + ORDER BY monthly_teu DESC + ''') + + return [{'ship_name': row[0], 'monthly_teu': row[1]} for row in cursor.fetchall()] + def insert_unaccounted(self, year_month: str, teu: int, note: str = '') -> bool: """插入未统计数据""" try: diff --git a/src/gui.py b/src/gui.py index 19c55f8..51a8791 100644 --- a/src/gui.py +++ b/src/gui.py @@ -86,7 +86,7 @@ class OrbitInGUI: btn_report_today = ttk.Button( left_frame, - text="昨日日报", + text="今日日报", command=self.generate_today_report, width=20 ) @@ -422,17 +422,27 @@ class OrbitInGUI: try: db = DailyLogsDatabase() stats = db.get_stats() + + # 获取当月船次统计 + current_month = datetime.now().strftime('%Y-%m') + ships_monthly = db.get_ships_with_monthly_teu(current_month) + db.close() self.log_message(f"总记录数: {stats['total']}") self.log_message(f"船次数量: {len(stats['ships'])}") self.log_message(f"日期范围: {stats['date_range']['start']} ~ {stats['date_range']['end']}") - if stats['ships']: + if ships_monthly: self.log_message("") - self.log_message("船次列表:") - for ship in sorted(stats['ships']): - self.log_message(f" - {ship}") + self.log_message(f"{current_month}月船次统计:") + total_monthly_teu = 0 + for ship in ships_monthly: + monthly_teu = ship['monthly_teu'] or 0 + total_monthly_teu += monthly_teu + self.log_message(f" {ship['ship_name']}: {monthly_teu}TEU") + self.log_message(f" ---") + self.log_message(f" 本月合计: {total_monthly_teu}TEU") self.set_status("完成")