feat: 实现月底/月初数据调整功能

1. 新增月底/月初智能数据调整功能
   - 月底最后一天自动弹出剔除数据对话框
   - 月初1号自动弹出添加数据对话框
   - 普通日期不弹出对话框

2. 实现月底剔除数据自动转移到次月1号
   - 月底剔除的数据自动添加到次月1号统计
   - 支持跨月、跨年数据转移
   - 数据备注自动记录转移信息

3. 修复自动获取数据后不弹出调整对话框的问题
   - 修改auto_fetch_data()方法,成功获取数据后调用调整处理
   - 确保第一次打开GUI也能弹出相应对话框

4. 修复月度统计不包含调整数据的问题
   - 修改get_monthly_stats()方法包含手动调整数据
   - 确保调整数据正确影响月度统计

5. 恢复日报原始模板格式
   - 移除调整数据的详细说明
   - 保持原始日报模板,只显示最终结果

6. 数据库增强
   - 新增manual_adjustments表存储手动调整数据
   - 实现调整数据的增删改查方法
   - 实现包含调整数据的每日数据获取方法

测试通过:所有功能正常工作,数据计算准确。
This commit is contained in:
2026-01-02 00:08:57 +08:00
parent 9b19015156
commit 0cbc587bf3
7 changed files with 1021 additions and 65 deletions

View File

@@ -52,7 +52,7 @@ class DailyReportGenerator:
def get_daily_data(self, date: str) -> Dict[str, Any]:
"""
获取指定日期的数据
获取指定日期的数据(包含手动调整)
参数:
date: 日期字符串,格式 "YYYY-MM-DD"
@@ -61,6 +61,11 @@ class DailyReportGenerator:
每日数据字典
"""
try:
# 使用数据库的新方法获取包含调整的数据
if hasattr(self.db, 'get_daily_data_with_adjustments'):
return self.db.get_daily_data_with_adjustments(date)
# 降级处理:如果没有新方法,使用原始逻辑
logs = self.db.query_by_date(date)
# 按船名汇总TEU和尺寸箱量
@@ -86,7 +91,9 @@ class DailyReportGenerator:
'date': date,
'ships': ships,
'total_teu': total_teu,
'ship_count': len(ships)
'ship_count': len(ships),
'adjustments': [],
'total_adjustment_teu': 0
}
except Exception as e:
@@ -95,7 +102,9 @@ class DailyReportGenerator:
'date': date,
'ships': {},
'total_teu': 0,
'ship_count': 0
'ship_count': 0,
'adjustments': [],
'total_adjustment_teu': 0
}
def get_monthly_stats(self, date: str) -> Dict[str, Any]:
@@ -116,12 +125,12 @@ class DailyReportGenerator:
# 只统计当月且在指定日期之前的数据
monthly_logs = [
log for log in logs
if log['date'].startswith(year_month)
log for log in logs
if log['date'].startswith(year_month)
and datetime.strptime(log['date'], '%Y-%m-%d').date() <= target_date
]
# 按日期汇总
# 按日期汇总原始数据
daily_totals: Dict[str, int] = {}
for log in monthly_logs:
d = log['date']
@@ -130,6 +139,25 @@ class DailyReportGenerator:
if log.get('teu'):
daily_totals[d] += log['teu']
# 获取当月所有日期的调整数据
total_adjustment_teu = 0
adjustment_details: Dict[str, Dict[str, int]] = {}
# 获取当月所有日期的调整数据
for day in range(1, target_date.day + 1):
day_str = f"{year_month}-{day:02d}"
if day_str <= date: # 只统计到指定日期
# 获取该日期的调整数据
if hasattr(self.db, 'get_daily_data_with_adjustments'):
daily_data = self.db.get_daily_data_with_adjustments(day_str)
adjustment_teu = daily_data.get('total_adjustment_teu', 0)
if adjustment_teu != 0:
total_adjustment_teu += adjustment_teu
adjustment_details[day_str] = {
'adjustment_teu': adjustment_teu,
'total_teu': daily_data.get('total_teu', 0)
}
# 计算当月天数(已过的天数)
current_date = datetime.strptime(date, '%Y-%m-%d')
if current_date.day == config.FIRST_DAY_OF_MONTH_SPECIAL:
@@ -141,7 +169,8 @@ class DailyReportGenerator:
unaccounted = self.db.get_unaccounted(year_month)
planned = days_passed * config.DAILY_TARGET_TEU
actual = sum(daily_totals.values()) + unaccounted
# 实际作业量 = 原始数据总计 + 未统计数据 + 调整数据总计
actual = sum(daily_totals.values()) + unaccounted + total_adjustment_teu
completion = round(actual / planned * 100, 2) if planned > 0 else 0
@@ -151,8 +180,10 @@ class DailyReportGenerator:
'planned': planned,
'actual': actual,
'unaccounted': unaccounted,
'adjustment_total': total_adjustment_teu,
'completion': completion,
'daily_totals': daily_totals
'daily_totals': daily_totals,
'adjustment_details': adjustment_details
}
except Exception as e:
@@ -163,8 +194,10 @@ class DailyReportGenerator:
'planned': 0,
'actual': 0,
'unaccounted': 0,
'adjustment_total': 0,
'completion': 0,
'daily_totals': {}
'daily_totals': {},
'adjustment_details': {}
}
def get_shift_personnel(self, date: str) -> Dict[str, str]:
@@ -279,6 +312,7 @@ class DailyReportGenerator:
ship_lines.append(f"作业量:{teu}TEU{size_str}")
else:
ship_lines.append(f"作业量:{teu}TEU")
lines.extend(ship_lines)
lines.append("")