From 73e810fc9569597be99accd08d63aab6e7c0daac Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期二, 06 十月 2026 09:36:41 +0800
Subject: [PATCH] fix(holiday): 提高平均拥挤度走势图标签精度

---
 traffic-audit-server/src/main/java/com/trafficaudit/holiday/service/HolidayVehicleAdjustmentService.java |   61 ++++++++++++++++++++++++++++--
 1 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/holiday/service/HolidayVehicleAdjustmentService.java b/traffic-audit-server/src/main/java/com/trafficaudit/holiday/service/HolidayVehicleAdjustmentService.java
index d04d192..7823197 100644
--- a/traffic-audit-server/src/main/java/com/trafficaudit/holiday/service/HolidayVehicleAdjustmentService.java
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/holiday/service/HolidayVehicleAdjustmentService.java
@@ -1,8 +1,11 @@
 package com.trafficaudit.holiday.service;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.trafficaudit.holiday.HolidayConstants;
 import com.trafficaudit.holiday.HolidayNumberUtils;
 import com.trafficaudit.holiday.entity.HolidayVehicleAdjustment;
+import com.trafficaudit.holiday.entity.HolidayVehicleFlow;
+import com.trafficaudit.holiday.mapper.HolidayVehicleFlowMapper;
 import com.trafficaudit.holiday.mapper.HolidayVehicleAdjustmentMapper;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -11,8 +14,11 @@
 import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 @Service
 public class HolidayVehicleAdjustmentService {
@@ -21,12 +27,55 @@
 
     @Resource
     private HolidayVehicleAdjustmentMapper adjustmentMapper;
+    @Resource
+    private HolidayVehicleFlowMapper vehicleFlowMapper;
 
     public List<HolidayVehicleAdjustment> list(Integer year) {
-        return adjustmentMapper.selectList(new LambdaQueryWrapper<HolidayVehicleAdjustment>()
-                .eq(year != null, HolidayVehicleAdjustment::getYear, year)
-                .orderByDesc(HolidayVehicleAdjustment::getYear)
-                .orderByAsc(HolidayVehicleAdjustment::getFlowDate));
+        List<HolidayVehicleAdjustment> rows = adjustmentMapper.selectList(
+                new LambdaQueryWrapper<HolidayVehicleAdjustment>()
+                        .eq(year != null, HolidayVehicleAdjustment::getYear, year)
+                        .orderByDesc(HolidayVehicleAdjustment::getYear)
+                        .orderByAsc(HolidayVehicleAdjustment::getFlowDate));
+        if (rows.isEmpty()) return rows;
+
+        Set<Integer> years = new HashSet<>();
+        for (HolidayVehicleAdjustment row : rows) {
+            if (row.getYear() != null) years.add(row.getYear());
+        }
+        if (years.isEmpty()) return rows;
+
+        List<HolidayVehicleFlow> sourceRows = vehicleFlowMapper.selectList(
+                new LambdaQueryWrapper<HolidayVehicleFlow>()
+                        .eq(HolidayVehicleFlow::getRoadCategory, HolidayConstants.ROAD_NATIONAL_PROVINCIAL)
+                        .eq(HolidayVehicleFlow::getVehicleType, HolidayConstants.VEHICLE_MEDIUM_SMALL_PASSENGER)
+                        .in(HolidayVehicleFlow::getYear, years));
+        Map<String, BigDecimal> originalValues = new HashMap<>();
+        for (HolidayVehicleFlow sourceRow : sourceRows) {
+            if (sourceRow.getYear() == null || sourceRow.getFlowDate() == null || sourceRow.getVehicleCount() == null) {
+                continue;
+            }
+            originalValues.put(sourceKey(sourceRow.getYear(), sourceRow.getFlowDate()), sourceRow.getVehicleCount());
+        }
+        for (HolidayVehicleAdjustment row : rows) {
+            if (row.getYear() != null && row.getFlowDate() != null) {
+                row.setOriginalValue(originalValues.get(sourceKey(row.getYear(), row.getFlowDate())));
+            }
+        }
+        return rows;
+    }
+
+    public BigDecimal findOriginalValue(Integer year, LocalDate flowDate) {
+        if (year == null || flowDate == null || flowDate.getYear() != year) {
+            throw new IllegalArgumentException("骞翠唤鍜屾棩鏈熶笉姝g‘");
+        }
+        HolidayVehicleFlow sourceRow = vehicleFlowMapper.selectOne(
+                new LambdaQueryWrapper<HolidayVehicleFlow>()
+                        .eq(HolidayVehicleFlow::getYear, year)
+                        .eq(HolidayVehicleFlow::getFlowDate, flowDate)
+                        .eq(HolidayVehicleFlow::getRoadCategory, HolidayConstants.ROAD_NATIONAL_PROVINCIAL)
+                        .eq(HolidayVehicleFlow::getVehicleType, HolidayConstants.VEHICLE_MEDIUM_SMALL_PASSENGER)
+                        .last("limit 1"));
+        return sourceRow == null ? null : sourceRow.getVehicleCount();
     }
 
     @Transactional
@@ -98,6 +147,10 @@
         adjustmentMapper.deleteById(id);
     }
 
+    private String sourceKey(Integer year, LocalDate flowDate) {
+        return year + "|" + flowDate;
+    }
+
     private Long longValue(Object value) {
         if (value == null || value.toString().trim().isEmpty()) return null;
         return Long.valueOf(value.toString().trim());

--
Gitblit v1.9.1