<?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.cpxt.biz.mapper.BizDriverStateMapper">
    
    <resultMap type="BizDriverState" id="BizDriverStateResult">
        <result property="id"    column="id"    />
        <result property="driverId"    column="driver_id"    />
        <result property="driverName"    column="driver_name"    />
        <result property="vin"    column="vin"    />
        <result property="gpsTime"    column="gps_time"    />
        <result property="lat"    column="lat"    />
        <result property="lng"    column="lng"    />
        <result property="speed"    column="speed"    />
        <result property="direction"    column="direction"    />
        <result property="placeName"    column="place_name"    />
        <result property="provice"    column="provice"    />
        <result property="city"    column="city"    />
        <result property="district"    column="district"    />
        <result property="roadName"    column="road_name"    />
        <result property="areaName"    column="area_name"    />
        <result property="height"    column="height"    />
        <result property="createTime"    column="create_time"    />
        <result property="status"    column="status"    />
    </resultMap>

    <insert id="insertBizDriverState" parameterType="BizDriverState" useGeneratedKeys="true" keyProperty="id">
        insert into track_driver_${driverId}
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="driverId != null">driver_id,</if>
            <if test="driverName != null">driver_name,</if>
            <if test="vin != null">vin,</if>
            <if test="gpsTime != null">gps_time,</if>
            <if test="lat != null">lat,</if>
            <if test="lng != null">lng,</if>
            <if test="speed != null">speed,</if>
            <if test="direction != null">direction,</if>
            <if test="placeName != null">place_name,</if>
            <if test="provice != null">provice,</if>
            <if test="city != null">city,</if>
            <if test="district != null">district,</if>
            <if test="roadName != null">road_name,</if>
            <if test="areaName != null">area_name,</if>
            <if test="height != null">height,</if>
            <if test="createTime != null">create_time,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="driverId != null">#{driverId},</if>
            <if test="driverName != null">#{driverName},</if>
            <if test="vin != null">#{vin},</if>
            <if test="gpsTime != null">#{gpsTime},</if>
            <if test="lat != null">#{lat},</if>
            <if test="lng != null">#{lng},</if>
            <if test="speed != null">#{speed},</if>
            <if test="direction != null">#{direction},</if>
            <if test="placeName != null">#{placeName},</if>
            <if test="provice != null">#{provice},</if>
            <if test="city != null">#{city},</if>
            <if test="district != null">#{district},</if>
            <if test="roadName != null">#{roadName},</if>
            <if test="areaName != null">#{areaName},</if>
            <if test="height != null">#{height},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <select id="selectDriverTrack" resultType="java.util.Map">
        select * from ${tableName}
        <where>
            1=1
            <if test="null != startTime and startTime != ''">
                and gps_time &gt;= #{startTime}
            </if>
            <if test="null != endTime and endTime != ''">
                and gps_time &lt;= #{endTime}
            </if>
        </where>
        order by gps_time desc
    </select>

</mapper>