<?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="io.renren.dao.CarDao">

    <sql id="selectCarVo">
        id ,
       car_no carNo,
       plate_type plateType,
       plate_color plateColor,
       card_no cardNo,
       stru_start_time struStartTime,
       stru_stop_time  struStopTime,
       person_no personNo,
       is_del isDel,
       sync
    </sql>

    <select id="selectCarList" parameterType="io.renren.entity.CarEntity" resultType="io.renren.entity.CarEntity" >
        select
        <include refid="selectCarVo"/>
        from tb_car
        <where>
            <if test="id != null  and id != ''"> and id = #{id}</if>
            <if test="sync != null  and sync != ''"> and sync = #{sync}</if>
        </where>
        order by id desc
    </select>


    <select id="getCarById" resultType="io.renren.entity.CarEntity">
        select
        <include refid="selectCarVo"/>
        from tb_car where id = #{value}
    </select>

    <insert id="insertCar" parameterType="CarEntity" useGeneratedKeys="true" keyProperty="id">
        insert into tb_car
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null and id != ''">id,</if>
            <if test="carNo != null and carNo != ''">car_no,</if>
            <if test="plateType != null and plateType != ''">plate_type,</if>
            <if test="plateColor != null and plateColor != ''">plate_color,</if>
            <if test="cardNo != null  and cardNo != '' ">card_no,</if>
            <if test="struStartTime != null">stru_start_time,</if>
            <if test="struStopTime != null">stru_stop_time,</if>
            <if test="personNo != null and personNo != ''">person_no,</if>
            <if test="isDel != null and isDel != '' ">is_del,</if>
            <if test="sync != null and sync != '' ">sync,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null and id != ''">#{id},</if>
            <if test="carNo != null and carNo != ''">#{carNo},</if>
            <if test="plateType != null and plateType != ''">#{plateType},</if>
            <if test="plateColor != null and plateColor != ''">#{plateColor},</if>
            <if test="cardNo != null  and cardNo != '' ">#{cardNo},</if>
            <if test="struStartTime != null">#{struStartTime},</if>
            <if test="struStopTime != null">#{struStopTime},</if>
            <if test="personNo != null and personNo != ''">#{personNo},</if>
            <if test="isDel != null and isDel != '' ">#{isDel},</if>
            <if test="sync != null and sync != '' ">#{sync},</if>
        </trim>
    </insert>

    <update id="updateCar" parameterType="CarEntity">
        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 and plateColor != ''">plate_color=#{plateColor},</if>
            <if test="cardNo != null  and cardNo != '' ">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 and personNo != ''">person_no=#{personNo},</if>
            <if test="isDel != null and isDel != '' ">is_del=#{isDel},</if>
            <if test="sync != null and sync != '' ">sync=#{sync},</if>
        </trim>
        where id = #{id}
    </update>

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


</mapper>
