数据库统计增加当月每艘船的作业量
This commit is contained in:
@@ -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:
|
||||
|
||||
20
src/gui.py
20
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("完成")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user