<?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.ningdatech.carapi.scheduler.mapper.OverSpeedGpsDataMapper">

    <select id="getOverSpeedDataInGps" resultType="com.ningdatech.carapi.scheduler.model.dto.OverSpeedGpsDataDTO">
        select
        aa.record_id id
        ,aa.car_plate carPlate
        ,aa.car_longitude longitude
        ,aa.car_latitude latitude
        ,aa.car_velocity speed
        ,bb.region_id regionId
        ,bb.region_name regionName
        ,bb.company_id companyId
        ,c.`name` companyName
        ,aa.create_time overSpeedTime
        ,aa.operator_id operatorId
        from nd_data_access_gps_${date} as aa
        inner join nd_vehicle_base_info as bb on aa.car_plate = bb.car_plate
        inner join nd_region as r on bb.region_id = r.id
        inner join nd_company_info as c on bb.company_id = c.id
        where aa.record_id &gt; #{startIndex}
              and aa.record_id &lt; #{endIndex}
    </select>
    <select id="getDataInGps" resultType="com.ningdatech.carapi.scheduler.model.dto.GpsSpeedDataDTO">
        select aa.car_plate,aa.dashboard_speed as speed
        from nd_data_access_gps_${date} as aa
                 right join (
            select car_plate, max(update_time) as max, dashboard_speed as speed
            from nd_data_access_gps_${date}
            WHERE
                update_time BETWEEN DATE_SUB(#{warnTime},INTERVAL #{timeBucket} minute) AND DATE_ADD(#{warnTime}, INTERVAL #{timeBucket} minute)
              AND STATUS IS NOT NULL
              and car_plate = #{carPlate}
            group by car_plate
        ) as bb
                            on bb.max = aa.update_time and bb.car_plate = aa.car_plate
                                and aa.update_time BETWEEN DATE_SUB(#{warnTime},INTERVAL #{timeBucket} minute) AND DATE_ADD(#{warnTime}, INTERVAL #{timeBucket} minute)
                                AND aa.STATUS IS NOT NULL
    </select>
</mapper>
