wlzboy
2025-11-11 9529220c815bfe6e43c992fde2f392be823450eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.VehicleMileageStatsMapper">
    
    <resultMap type="VehicleMileageStats" id="VehicleMileageStatsResult">
        <id     property="statsId"         column="stats_id"           />
        <result property="vehicleId"       column="vehicle_id"         />
        <result property="vehicleNo"       column="vehicle_no"         />
        <result property="statDate"        column="stat_date"          />
        <result property="totalMileage"    column="total_mileage"      />
        <result property="taskMileage"     column="task_mileage"       />
        <result property="nonTaskMileage"  column="non_task_mileage"   />
        <result property="taskRatio"       column="task_ratio"         />
        <result property="gpsPointCount"   column="gps_point_count"    />
        <result property="taskCount"       column="task_count"         />
        <result property="createTime"      column="create_time"        />
        <result property="updateTime"      column="update_time"        />
    </resultMap>
 
    <resultMap type="TaskTimeInterval" id="TaskTimeIntervalResult">
        <result property="taskId"          column="task_id"            />
        <result property="startTime"       column="start_time"         />
        <result property="endTime"         column="end_time"           />
    </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
    </sql>
 
    <select id="selectVehicleMileageStatsList" parameterType="VehicleMileageStats" resultMap="VehicleMileageStatsResult">
        <include refid="selectVehicleMileageStatsVo"/>
        <where>  
            <if test="vehicleId != null">
                and vehicle_id = #{vehicleId}
            </if>
            <if test="vehicleNo != null and vehicleNo != ''">
                and vehicle_no = #{vehicleNo}
            </if>
            <if test="statDate != null">
                and stat_date = #{statDate}
            </if>
            <if test="params.beginStatDate != null and params.beginStatDate != ''">
                and stat_date &gt;= #{params.beginStatDate}
            </if>
            <if test="params.endStatDate != null and params.endStatDate != ''">
                and stat_date &lt;= #{params.endStatDate}
            </if>
        </where>
        order by stat_date desc, vehicle_id
    </select>
    
    <select id="selectVehicleMileageStatsById" parameterType="Long" resultMap="VehicleMileageStatsResult">
        <include refid="selectVehicleMileageStatsVo"/>
        where stats_id = #{statsId}
    </select>
 
    <select id="selectByVehicleIdAndDate" resultMap="VehicleMileageStatsResult">
        <include refid="selectVehicleMileageStatsVo"/>
        where vehicle_id = #{vehicleId} and stat_date = #{statDate}
    </select>
 
    <select id="selectTaskTimeIntervals" resultMap="TaskTimeIntervalResult">
        select tv.task_id, t.create_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
    </select>
        
    <insert id="insertVehicleMileageStats" parameterType="VehicleMileageStats" useGeneratedKeys="true" keyProperty="statsId">
        insert into tb_vehicle_mileage_stats
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="vehicleId != null">vehicle_id,</if>
            <if test="vehicleNo != null">vehicle_no,</if>
            <if test="statDate != null">stat_date,</if>
            <if test="totalMileage != null">total_mileage,</if>
            <if test="taskMileage != null">task_mileage,</if>
            <if test="nonTaskMileage != null">non_task_mileage,</if>
            <if test="taskRatio != null">task_ratio,</if>
            <if test="gpsPointCount != null">gps_point_count,</if>
            <if test="taskCount != null">task_count,</if>
            create_time
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="vehicleId != null">#{vehicleId},</if>
            <if test="vehicleNo != null">#{vehicleNo},</if>
            <if test="statDate != null">#{statDate},</if>
            <if test="totalMileage != null">#{totalMileage},</if>
            <if test="taskMileage != null">#{taskMileage},</if>
            <if test="nonTaskMileage != null">#{nonTaskMileage},</if>
            <if test="taskRatio != null">#{taskRatio},</if>
            <if test="gpsPointCount != null">#{gpsPointCount},</if>
            <if test="taskCount != null">#{taskCount},</if>
            NOW()
         </trim>
    </insert>
 
    <update id="updateVehicleMileageStats" parameterType="VehicleMileageStats">
        update tb_vehicle_mileage_stats
        <trim prefix="SET" suffixOverrides=",">
            <if test="vehicleNo != null">vehicle_no = #{vehicleNo},</if>
            <if test="totalMileage != null">total_mileage = #{totalMileage},</if>
            <if test="taskMileage != null">task_mileage = #{taskMileage},</if>
            <if test="nonTaskMileage != null">non_task_mileage = #{nonTaskMileage},</if>
            <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>
            update_time = NOW()
        </trim>
        where stats_id = #{statsId}
    </update>
 
    <delete id="deleteVehicleMileageStatsById" parameterType="Long">
        delete from tb_vehicle_mileage_stats where stats_id = #{statsId}
    </delete>
 
    <delete id="deleteVehicleMileageStatsByIds" parameterType="Long">
        delete from tb_vehicle_mileage_stats where stats_id in 
        <foreach item="statsId" collection="array" open="(" separator="," close=")">
            #{statsId}
        </foreach>
    </delete>
</mapper>