| | |
| | | <resultMap type="VehicleGps" id="VehicleGpsResult"> |
| | | <result property="gpsId" column="gps_id" /> |
| | | <result property="vehicleId" column="vehicle_id" /> |
| | | <result property="deviceId" column="device_id" /> |
| | | <result property="vehicleNo" column="vehicle_no" /> |
| | | <result property="longitude" column="longitude" /> |
| | | <result property="latitude" column="latitude" /> |
| | |
| | | <result property="speed" column="speed" /> |
| | | <result property="direction" column="direction" /> |
| | | <result property="collectTime" column="collect_time" /> |
| | | <result property="deviceReportTime" column="device_report_time" /> |
| | | <result property="platformProcessTime" column="platform_process_time" /> |
| | | <result property="createTime" column="create_time" /> |
| | | </resultMap> |
| | | |
| | | <sql id="selectVehicleGpsVo"> |
| | | select g.gps_id, g.vehicle_id, v.vehicle_no, g.longitude, g.latitude, g.altitude, g.speed, g.direction, g.collect_time, g.create_time |
| | | select g.gps_id, g.vehicle_id, g.device_id, v.vehicle_no, g.longitude, g.latitude, g.altitude, g.speed, g.direction, |
| | | g.collect_time, g.device_report_time, g.platform_process_time, g.create_time |
| | | from tb_vehicle_gps g |
| | | left join tb_vehicle_info v on g.vehicle_id = v.vehicle_id |
| | | </sql> |
| | |
| | | <select id="selectVehicleGpsList" parameterType="VehicleGps" resultMap="VehicleGpsResult"> |
| | | <include refid="selectVehicleGpsVo"/> |
| | | <where> |
| | | <if test="vehicleId != null "> and g.vehicle_id = #{vehicleId}</if> |
| | | <if test="vehicleNo != null and vehicleNo != ''"> and v.vehicle_no like concat('%', #{vehicleNo}, '%')</if> |
| | | <if test="longitude != null "> and g.longitude = #{longitude}</if> |
| | | <if test="latitude != null "> and g.latitude = #{latitude}</if> |
| | | <if test="altitude != null "> and g.altitude = #{altitude}</if> |
| | | <if test="speed != null "> and g.speed = #{speed}</if> |
| | | <if test="direction != null "> and g.direction = #{direction}</if> |
| | | <if test="collectTime != null and collectTime != ''"> and g.collect_time = #{collectTime}</if> |
| | | <if test="vehicleNo != null and vehicleNo != ''"> and v.vehicle_no like concat('%', #{vehicleNo}, '%')</if> |
| | | <if test="longitude != null "> and longitude = #{longitude}</if> |
| | | <if test="latitude != null "> and latitude = #{latitude}</if> |
| | | <if test="speed != null "> and speed = #{speed}</if> |
| | | <if test="direction != null "> and direction = #{direction}</if> |
| | | <if test="collectTime != null "> and collect_time = #{collectTime}</if> |
| | | <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 --> |
| | | AND date_format(collect_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d') |
| | | </if> |
| | | <if test="endTime != null and endTime != ''"><!-- 结束时间检索 --> |
| | | AND date_format(collect_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d') |
| | | </if> |
| | | </where> |
| | | order by collect_time desc |
| | | </select> |
| | | |
| | | <select id="selectVehicleGpsById" parameterType="Long" resultMap="VehicleGpsResult"> |
| | |
| | | insert into tb_vehicle_gps |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <if test="vehicleId != null">vehicle_id,</if> |
| | | <if test="deviceId != null">device_id,</if> |
| | | <if test="longitude != null">longitude,</if> |
| | | <if test="latitude != null">latitude,</if> |
| | | <if test="altitude != null">altitude,</if> |
| | | <if test="speed != null">speed,</if> |
| | | <if test="direction != null">direction,</if> |
| | | <if test="collectTime != null">collect_time,</if> |
| | | <if test="deviceReportTime != null">device_report_time,</if> |
| | | <if test="platformProcessTime != null">platform_process_time,</if> |
| | | <if test="createTime != null">create_time,</if> |
| | | </trim> |
| | | <trim prefix="values (" suffix=")" suffixOverrides=","> |
| | | <if test="vehicleId != null">#{vehicleId},</if> |
| | | <if test="deviceId != null">#{deviceId},</if> |
| | | <if test="longitude != null">#{longitude},</if> |
| | | <if test="latitude != null">#{latitude},</if> |
| | | <if test="altitude != null">#{altitude},</if> |
| | | <if test="speed != null">#{speed},</if> |
| | | <if test="direction != null">#{direction},</if> |
| | | <if test="collectTime != null">#{collectTime},</if> |
| | | <if test="deviceReportTime != null">#{deviceReportTime},</if> |
| | | <if test="platformProcessTime != null">#{platformProcessTime},</if> |
| | | <if test="createTime != null">#{createTime},</if> |
| | | </trim> |
| | | </insert> |
| | |
| | | <select id="getVehicleIdByNo" parameterType="String" resultType="Long"> |
| | | select vehicle_id from tb_vehicle_info where vehicle_no = #{vehicleNo} |
| | | </select> |
| | | |
| | | <delete id="deleteVehicleGpsBeforeDate"> |
| | | delete g from tb_vehicle_gps g |
| | | where g.collect_time < ( |
| | | select date_sub(max(collect_time), interval 2 day) |
| | | from tb_vehicle_gps g2 |
| | | where g2.vehicle_id = g.vehicle_id |
| | | ) |
| | | </delete> |
| | | |
| | | <select id="selectGpsDataByTimeRange" resultMap="VehicleGpsResult"> |
| | | select gps_id, vehicle_id, device_id, longitude, latitude, altitude, speed, direction, |
| | | collect_time, device_report_time, platform_process_time, create_time |
| | | from tb_vehicle_gps |
| | | where vehicle_id = #{vehicleId} |
| | | and collect_time >= #{startTime} |
| | | and collect_time <= #{endTime} |
| | | order by collect_time |
| | | </select> |
| | | |
| | | <!-- 查询活跃车辆ID(优化:使用GROUP BY替代DISTINCT,提升性能) --> |
| | | <select id="selectActiveVehicleIds" resultType="Long"> |
| | | select vehicle_id |
| | | from tb_vehicle_gps |
| | | where collect_time >= #{startTime} |
| | | group by vehicle_id |
| | | order by vehicle_id |
| | | </select> |
| | | |
| | | <!-- 查询未被计算的GPS坐标(优化:使用NOT EXISTS替代LEFT JOIN ... IS NULL) --> |
| | | <select id="selectUncalculatedGps" resultMap="VehicleGpsResult"> |
| | | SELECT g.gps_id, g.vehicle_id, g.device_id, g.longitude, g.latitude, g.altitude, |
| | | g.speed, g.direction, g.collect_time, g.device_report_time, |
| | | g.platform_process_time, g.create_time, v.vehicle_no |
| | | FROM tb_vehicle_gps g |
| | | INNER JOIN tb_vehicle_info v ON g.vehicle_id = v.vehicle_id |
| | | WHERE g.vehicle_id = #{vehicleId} |
| | | AND g.collect_time >= #{startTime} |
| | | AND g.collect_time <= #{endTime} |
| | | AND NOT EXISTS ( |
| | | SELECT 1 FROM tb_vehicle_gps_calculated c |
| | | WHERE c.gps_id = g.gps_id |
| | | ) |
| | | ORDER BY g.collect_time |
| | | </select> |
| | | </mapper> |