fix(mileage): 未到期年度累计对齐实时监控
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
kkfluous
2026-06-03 11:32:50 +08:00
parent 3f0edfaaf5
commit a3dfe7ab8c

View File

@@ -192,6 +192,10 @@ app.get('/', async (c) => {
}
cutoffMileageMapByDate.set(date, map);
}
const currentMileageMap = new Map<string, number>();
for (const vehicle of await queryDateMileage(todayStr)) {
if (vehicle.totalKm != null) currentMileageMap.set(vehicle.plate, vehicle.totalKm);
}
const yearlyMetricMap = new Map<string, {
actualMileage: number;
@@ -221,7 +225,7 @@ app.get('/', async (c) => {
const key = `${row.target_id}-${year}`;
const goal = annualMileage * year;
const endDate = addYearsMinusOneDay(row.assessment_start_date, year);
const cutoffMap = endDate < todayStr ? cutoffMileageMapByDate.get(endDate) : undefined;
const cutoffMap = endDate < todayStr ? cutoffMileageMapByDate.get(endDate) : currentMileageMap;
const mileageAtCutoff = Math.max(0, cutoffMap?.get(row.plate_number) ?? (Number(row.current_mileage) || 0));
const completed = Math.min(mileageAtCutoff, goal);
const draft = yearlyMetricDraftMap.get(key) || {