From fe33646ee6e2d1e57f2b51812e94983a0e9efb04 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期日, 14 十二月 2025 16:51:28 +0800
Subject: [PATCH] feat: 修复统计

---
 ruoyi-system/src/main/resources/mapper/system/VehicleMileageStatsMapper.xml |   74 ++++++++++++++++++++++++++++--------
 1 files changed, 57 insertions(+), 17 deletions(-)

diff --git a/ruoyi-system/src/main/resources/mapper/system/VehicleMileageStatsMapper.xml b/ruoyi-system/src/main/resources/mapper/system/VehicleMileageStatsMapper.xml
index 95439e9..1a2218f 100644
--- a/ruoyi-system/src/main/resources/mapper/system/VehicleMileageStatsMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/VehicleMileageStatsMapper.xml
@@ -8,6 +8,8 @@
         <id     property="statsId"         column="stats_id"           />
         <result property="vehicleId"       column="vehicle_id"         />
         <result property="vehicleNo"       column="vehicle_no"         />
+        <result property="deptName"        column="dept_name"          />
+        <result property="deptId"          column="dept_id"            />
         <result property="statDate"        column="stat_date"          />
         <result property="totalMileage"    column="total_mileage"      />
         <result property="taskMileage"     column="task_mileage"       />
@@ -15,6 +17,8 @@
         <result property="taskRatio"       column="task_ratio"         />
         <result property="gpsPointCount"   column="gps_point_count"    />
         <result property="taskCount"       column="task_count"         />
+        <result property="segmentCount"    column="segment_count"      />
+        <result property="dataSource"      column="data_source"        />
         <result property="createTime"      column="create_time"        />
         <result property="updateTime"      column="update_time"        />
     </resultMap>
@@ -26,54 +30,73 @@
     </resultMap>
 
     <sql id="selectVehicleMileageStatsVo">
-        select stats_id, vehicle_id, vehicle_no, stat_date, total_mileage, task_mileage, 
-               non_task_mileage, task_ratio, gps_point_count, task_count, create_time, update_time
-        from tb_vehicle_mileage_stats
+        select s.stats_id, s.vehicle_id, s.vehicle_no, s.stat_date, s.total_mileage, s.task_mileage, 
+               s.non_task_mileage, s.task_ratio, s.gps_point_count, s.task_count, s.segment_count, 
+               s.data_source, s.create_time, s.update_time,
+               GROUP_CONCAT(DISTINCT d.dept_name ORDER BY d.dept_name SEPARATOR ',') as dept_name,
+               vd.dept_id
+        from tb_vehicle_mileage_stats s
+        left join tb_vehicle_info v on s.vehicle_id = v.vehicle_id
+        left join tb_vehicle_dept vd on v.vehicle_id = vd.vehicle_id
+        left join sys_dept d on vd.dept_id = d.dept_id
     </sql>
 
     <select id="selectVehicleMileageStatsList" parameterType="VehicleMileageStats" resultMap="VehicleMileageStatsResult">
         <include refid="selectVehicleMileageStatsVo"/>
         <where>  
             <if test="vehicleId != null">
-                and vehicle_id = #{vehicleId}
+                and s.vehicle_id = #{vehicleId}
             </if>
             <if test="vehicleNo != null and vehicleNo != ''">
-                and vehicle_no = #{vehicleNo}
+                and s.vehicle_no like concat('%', #{vehicleNo}, '%')
+            </if>
+            <if test="deptId != null">
+                and vd.dept_id = #{deptId}
             </if>
             <if test="statDate != null">
-                and stat_date = #{statDate}
+                and s.stat_date = #{statDate}
             </if>
             <if test="params.beginStatDate != null and params.beginStatDate != ''">
-                and stat_date &gt;= #{params.beginStatDate}
+                and s.stat_date &gt;= #{params.beginStatDate}
             </if>
             <if test="params.endStatDate != null and params.endStatDate != ''">
-                and stat_date &lt;= #{params.endStatDate}
+                and s.stat_date &lt;= #{params.endStatDate}
             </if>
         </where>
-        order by stat_date desc, vehicle_id
+        group by s.stats_id, s.vehicle_id, s.vehicle_no, s.stat_date, s.total_mileage, s.task_mileage,
+                 s.non_task_mileage, s.task_ratio, s.gps_point_count, s.task_count, s.segment_count,
+                 s.data_source, s.create_time, s.update_time, vd.dept_id
+        order by s.stat_date desc, s.vehicle_id
     </select>
     
     <select id="selectVehicleMileageStatsById" parameterType="Long" resultMap="VehicleMileageStatsResult">
         <include refid="selectVehicleMileageStatsVo"/>
-        where stats_id = #{statsId}
+        where s.stats_id = #{statsId}
+        group by s.stats_id, s.vehicle_id, s.vehicle_no, s.stat_date, s.total_mileage, s.task_mileage,
+                 s.non_task_mileage, s.task_ratio, s.gps_point_count, s.task_count, s.segment_count,
+                 s.data_source, s.create_time, s.update_time, vd.dept_id
     </select>
 
+    <!-- 鏍规嵁杞﹁締ID鍜岀粺璁℃棩鏈熸煡璇㈠敮涓�缁熻璁板綍 -->
     <select id="selectByVehicleIdAndDate" resultMap="VehicleMileageStatsResult">
-        <include refid="selectVehicleMileageStatsVo"/>
-        where vehicle_id = #{vehicleId} and stat_date = #{statDate}
+        select s.stats_id, s.vehicle_id, s.vehicle_no, s.stat_date, s.total_mileage, s.task_mileage, 
+               s.non_task_mileage, s.task_ratio, s.gps_point_count, s.task_count, s.segment_count, 
+               s.data_source, s.create_time, s.update_time
+        from tb_vehicle_mileage_stats s
+        where s.vehicle_id = #{vehicleId} and DATE(s.stat_date) = DATE(#{statDate})
+        limit 1
     </select>
 
     <select id="selectTaskTimeIntervals" resultMap="TaskTimeIntervalResult">
-        select tv.task_id, t.create_time as start_time, 
+        select tv.task_id, t.actual_start_time as start_time,
                IFNULL(t.actual_end_time, NOW()) as end_time
         from sys_task_vehicle tv
         inner join sys_task t on tv.task_id = t.task_id
         where tv.vehicle_id = #{vehicleId}
           and t.del_flag = '0'
-          and t.actual_end_time is not null
-          and t.create_time &lt; #{endTime}
-          and t.actual_end_time &gt; #{startTime}
-        order by t.create_time
+          and (t.actual_start_time &lt;= #{endTime} and (t.actual_end_time is null or t.actual_end_time &gt;= #{startTime}))
+
+        order by t.actual_start_time
     </select>
         
     <insert id="insertVehicleMileageStats" parameterType="VehicleMileageStats" useGeneratedKeys="true" keyProperty="statsId">
@@ -88,6 +111,8 @@
             <if test="taskRatio != null">task_ratio,</if>
             <if test="gpsPointCount != null">gps_point_count,</if>
             <if test="taskCount != null">task_count,</if>
+            <if test="segmentCount != null">segment_count,</if>
+            <if test="dataSource != null">data_source,</if>
             create_time
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
@@ -100,8 +125,21 @@
             <if test="taskRatio != null">#{taskRatio},</if>
             <if test="gpsPointCount != null">#{gpsPointCount},</if>
             <if test="taskCount != null">#{taskCount},</if>
+            <if test="segmentCount != null">#{segmentCount},</if>
+            <if test="dataSource != null">#{dataSource},</if>
             NOW()
          </trim>
+        ON DUPLICATE KEY UPDATE
+            vehicle_no = VALUES(vehicle_no),
+            total_mileage = VALUES(total_mileage),
+            task_mileage = VALUES(task_mileage),
+            non_task_mileage = VALUES(non_task_mileage),
+            task_ratio = VALUES(task_ratio),
+            gps_point_count = VALUES(gps_point_count),
+            task_count = VALUES(task_count),
+            segment_count = VALUES(segment_count),
+            data_source = VALUES(data_source),
+            update_time = NOW()
     </insert>
 
     <update id="updateVehicleMileageStats" parameterType="VehicleMileageStats">
@@ -114,6 +152,8 @@
             <if test="taskRatio != null">task_ratio = #{taskRatio},</if>
             <if test="gpsPointCount != null">gps_point_count = #{gpsPointCount},</if>
             <if test="taskCount != null">task_count = #{taskCount},</if>
+            <if test="segmentCount != null">segment_count = #{segmentCount},</if>
+            <if test="dataSource != null">data_source = #{dataSource},</if>
             update_time = NOW()
         </trim>
         where stats_id = #{statsId}

--
Gitblit v1.9.1