wlzboy
2025-11-22 d4fe921568bc29d72644a55fd194adf7f9277cb5
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?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.VehicleGpsSegmentMileageMapper">
    
    <resultMap type="VehicleGpsSegmentMileage" id="VehicleGpsSegmentMileageResult">
        <result property="segmentId"         column="segment_id"        />
        <result property="vehicleId"         column="vehicle_id"        />
        <result property="vehicleNo"         column="vehicle_no"        />
        <result property="segmentStartTime"  column="segment_start_time" />
        <result property="segmentEndTime"    column="segment_end_time"  />
        <result property="startLongitude"    column="start_longitude"   />
        <result property="startLatitude"     column="start_latitude"    />
        <result property="endLongitude"      column="end_longitude"     />
        <result property="endLatitude"       column="end_latitude"      />
        <result property="segmentDistance"   column="segment_distance"  />
        <result property="gpsPointCount"     column="gps_point_count"   />
        <result property="gpsIds"            column="gps_ids"           />
        <result property="taskId"            column="task_id"           />
        <result property="taskCode"          column="task_code"         />
        <result property="calculateMethod"   column="calculate_method"  />
        <result property="createTime"        column="create_time"       />
        <result property="updateTime"        column="update_time"       />
    </resultMap>
 
    <sql id="selectVehicleGpsSegmentMileageVo">
        SELECT segment_id, vehicle_id, vehicle_no, segment_start_time, segment_end_time,
               start_longitude, start_latitude, end_longitude, end_latitude, 
               segment_distance, gps_point_count, gps_ids, task_id, task_code, 
               calculate_method, create_time, update_time
        FROM tb_vehicle_gps_segment_mileage
    </sql>
 
    <select id="selectVehicleGpsSegmentMileageList" parameterType="VehicleGpsSegmentMileage" resultMap="VehicleGpsSegmentMileageResult">
        <include refid="selectVehicleGpsSegmentMileageVo"/>
        <where>  
            <if test="vehicleId != null">
                AND vehicle_id = #{vehicleId}
            </if>
            <if test="vehicleNo != null and vehicleNo != ''">
                AND vehicle_no = #{vehicleNo}
            </if>
            <if test="params.beginTime != null and params.beginTime != ''">
                AND segment_start_time &gt;= #{params.beginTime}
            </if>
            <if test="params.endTime != null and params.endTime != ''">
                AND segment_end_time &lt;= #{params.endTime}
            </if>
        </where>
        ORDER BY segment_start_time DESC
    </select>
    
    <select id="selectVehicleGpsSegmentMileageById" parameterType="Long" resultMap="VehicleGpsSegmentMileageResult">
        <include refid="selectVehicleGpsSegmentMileageVo"/>
        WHERE segment_id = #{segmentId}
    </select>
 
    <select id="selectByVehicleIdAndTime" resultMap="VehicleGpsSegmentMileageResult">
        <include refid="selectVehicleGpsSegmentMileageVo"/>
        WHERE vehicle_id = #{vehicleId} AND segment_start_time = #{segmentStartTime}
    </select>
 
    <select id="selectSegmentsByDateRange" resultMap="VehicleGpsSegmentMileageResult">
        <include refid="selectVehicleGpsSegmentMileageVo"/>
        WHERE vehicle_id = #{vehicleId}
          AND segment_start_time &gt;= #{startDate}
          AND segment_end_time &lt;= #{endDate}
        ORDER BY segment_start_time
    </select>
    
    <!-- 按任务ID查询分段里程列表 -->
    <select id="selectSegmentsByTaskId" resultMap="VehicleGpsSegmentMileageResult">
        <include refid="selectVehicleGpsSegmentMileageVo"/>
        WHERE task_id = #{taskId}
        ORDER BY segment_start_time
    </select>
    
    <!-- 查询任务的总里程(直接求和) -->
    <select id="selectTotalMileageByTaskId" resultType="java.math.BigDecimal">
        SELECT COALESCE(SUM(segment_distance), 0) 
        FROM tb_vehicle_gps_segment_mileage 
        WHERE task_id = #{taskId}
    </select>
        
    <insert id="insertVehicleGpsSegmentMileage" parameterType="VehicleGpsSegmentMileage">
        INSERT INTO tb_vehicle_gps_segment_mileage
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="vehicleId != null">vehicle_id,</if>
            <if test="vehicleNo != null">vehicle_no,</if>
            <if test="segmentStartTime != null">segment_start_time,</if>
            <if test="segmentEndTime != null">segment_end_time,</if>
            <if test="startLongitude != null">start_longitude,</if>
            <if test="startLatitude != null">start_latitude,</if>
            <if test="endLongitude != null">end_longitude,</if>
            <if test="endLatitude != null">end_latitude,</if>
            <if test="segmentDistance != null">segment_distance,</if>
            <if test="gpsPointCount != null">gps_point_count,</if>
            <if test="gpsIds != null">gps_ids,</if>
            <if test="taskId != null">task_id,</if>
            <if test="taskCode != null">task_code,</if>
            <if test="calculateMethod != null">calculate_method,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="vehicleId != null">#{vehicleId},</if>
            <if test="vehicleNo != null">#{vehicleNo},</if>
            <if test="segmentStartTime != null">#{segmentStartTime},</if>
            <if test="segmentEndTime != null">#{segmentEndTime},</if>
            <if test="startLongitude != null">#{startLongitude},</if>
            <if test="startLatitude != null">#{startLatitude},</if>
            <if test="endLongitude != null">#{endLongitude},</if>
            <if test="endLatitude != null">#{endLatitude},</if>
            <if test="segmentDistance != null">#{segmentDistance},</if>
            <if test="gpsPointCount != null">#{gpsPointCount},</if>
            <if test="gpsIds != null">#{gpsIds},</if>
            <if test="taskId != null">#{taskId},</if>
            <if test="taskCode != null">#{taskCode},</if>
            <if test="calculateMethod != null">#{calculateMethod},</if>
        </trim>
    </insert>
 
    <update id="updateVehicleGpsSegmentMileage" parameterType="VehicleGpsSegmentMileage">
        UPDATE tb_vehicle_gps_segment_mileage
        <trim prefix="SET" suffixOverrides=",">
            <if test="vehicleNo != null">vehicle_no = #{vehicleNo},</if>
            <if test="segmentEndTime != null">segment_end_time = #{segmentEndTime},</if>
            <if test="endLongitude != null">end_longitude = #{endLongitude},</if>
            <if test="endLatitude != null">end_latitude = #{endLatitude},</if>
            <if test="segmentDistance != null">segment_distance = #{segmentDistance},</if>
            <if test="gpsPointCount != null">gps_point_count = #{gpsPointCount},</if>
            <if test="calculateMethod != null">calculate_method = #{calculateMethod},</if>
        </trim>
        WHERE segment_id = #{segmentId}
    </update>
 
    <delete id="deleteVehicleGpsSegmentMileageById" parameterType="Long">
        DELETE FROM tb_vehicle_gps_segment_mileage WHERE segment_id = #{segmentId}
    </delete>
 
    <delete id="deleteVehicleGpsSegmentMileageByIds" parameterType="String">
        DELETE FROM tb_vehicle_gps_segment_mileage WHERE segment_id IN
        <foreach item="segmentId" collection="array" open="(" separator="," close=")">
            #{segmentId}
        </foreach>
    </delete>
    
    <!-- 记录GPS点已被计算 -->
    <insert id="insertGpsCalculated">
        INSERT INTO tb_vehicle_gps_calculated (gps_id, segment_id, vehicle_id, create_time)
        VALUES (#{gpsId}, #{segmentId}, #{vehicleId}, NOW())
    </insert>
    
    <!-- 检查GPS点是否已被计算 -->
    <select id="selectGpsCalculatedSegmentId" resultType="Long">
        SELECT segment_id FROM tb_vehicle_gps_calculated WHERE gps_id = #{gpsId} LIMIT 1
    </select>
</mapper>