<?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.dcsoft.system.car.mapper.TbCarMapper">

    <resultMap type="TbCar" id="TbCarResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="carType"    column="car_type"    />
        <result property="drivingUrl"    column="driving_url"    />
        <result property="carNo"    column="car_no"    />
        <result property="plateType"    column="plate_type"    />
        <result property="plateColor"    column="plate_color"    />
        <result property="cardNo"    column="card_no"    />
        <result property="struStartTime"    column="stru_start_time"    />
        <result property="struStopTime"    column="stru_stop_time"    />
        <result property="personNo"    column="person_no"    />
        <result property="isDel"    column="is_del"    />
        <result property="sync"    column="sync"    />
        <result property="ownerName"    column="owner_name"    />
        <result property="ownerPhone"    column="owner_phone"    />
    </resultMap>

    <sql id="selectTbCarVo">
        select id, car_no, plate_type,user_id,car_type,driving_url, plate_color, card_no, stru_start_time, stru_stop_time, person_no, is_del, sync,owner_name,owner_phone from tb_car
    </sql>

    <select id="selectTbCarList" parameterType="TbCar" resultMap="TbCarResult">
        <include refid="selectTbCarVo"/>
        <where>
            <if test="carNo != null  and carNo != ''"> and car_no = #{carNo}</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="plateType != null  and plateType != ''"> and plate_type = #{plateType}</if>
            <if test="plateColor != null  and plateColor != ''"> and plate_color = #{plateColor}</if>
            <if test="struStartTime != null "> and stru_start_time = #{struStartTime}</if>
            <if test="struStopTime != null "> and stru_stop_time = #{struStopTime}</if>
            <if test="personNo != null  and personNo != ''"> and person_no = #{personNo}</if>
            <if test="sync != null  and sync != ''"> and sync = #{sync}</if>
            <if test="carType != null"> and car_type = #{carType}</if>
        </where>
    </select>

    <select id="selectTbCarById" parameterType="Long" resultMap="TbCarResult">
        <include refid="selectTbCarVo"/>
        where id = #{id}
    </select>

    <insert id="insertTbCar" parameterType="TbCar">
        insert into tb_car
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userId != null">user_id,</if>
            <if test="carType != null">car_type,</if>
            <if test="drivingUrl != null">driving_url,</if>
            <if test="carNo != null and carNo != ''">car_no,</if>
            <if test="plateType != null and plateType != ''">plate_type,</if>
            <if test="plateColor != null">plate_color,</if>
            <if test="cardNo != null">card_no,</if>
            <if test="struStartTime != null">stru_start_time,</if>
            <if test="struStopTime != null">stru_stop_time,</if>
            <if test="personNo != null">person_no,</if>
            <if test="isDel != null">is_del,</if>
            <if test="sync != null and sync != ''">sync,</if>
            <if test="ownerName != null and ownerName != ''">owner_name,</if>
            <if test="ownerPhone != null and ownerPhone != ''">owner_phone,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="userId != null">#{userId},</if>
            <if test="carType != null">#{carType},</if>
            <if test="drivingUrl != null">#{drivingUrl},</if>
            <if test="carNo != null and carNo != ''">#{carNo},</if>
            <if test="plateType != null and plateType != ''">#{plateType},</if>
            <if test="plateColor != null">#{plateColor},</if>
            <if test="cardNo != null">#{cardNo},</if>
            <if test="struStartTime != null">#{struStartTime},</if>
            <if test="struStopTime != null">#{struStopTime},</if>
            <if test="personNo != null">#{personNo},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="sync != null and sync != ''">#{sync},</if>
            <if test="ownerName != null and ownerName != ''">#{ownerName},</if>
            <if test="ownerPhone != null and ownerPhone != ''">#{ownerPhone},</if>
         </trim>
    </insert>

    <update id="updateTbCar" parameterType="TbCar">
        update tb_car
        <trim prefix="SET" suffixOverrides=",">
            <if test="carNo != null and carNo != ''">car_no = #{carNo},</if>
            <if test="plateType != null and plateType != ''">plate_type = #{plateType},</if>
            <if test="plateColor != null">plate_color = #{plateColor},</if>
            <if test="cardNo != null">card_no = #{cardNo},</if>
            <if test="struStartTime != null">stru_start_time = #{struStartTime},</if>
            <if test="struStopTime != null">stru_stop_time = #{struStopTime},</if>
            <if test="personNo != null">person_no = #{personNo},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="sync != null and sync != ''">sync = #{sync},</if>
            <if test="ownerName != null and ownerName != ''">owner_name = #{ownerName},</if>
            <if test="ownerPhone != null and ownerPhone != ''">owner_phone = #{ownerPhone},</if>
            <if test="userId != null and userId != ''">user_id = #{userId},</if>
            <if test="carType != null and carType != ''">car_type = #{carType},</if>
            <if test="drivingUrl != null and drivingUrl != ''">driving_url = #{drivingUrl},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTbCarById" parameterType="Long">
        delete from tb_car where id = #{id}
    </delete>

    <delete id="deleteTbCarByIds" parameterType="String">
        delete from tb_car where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
