<?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.muyu.car.mapper.SysCarMapper">

    <resultMap type="SysCar" id="SysCarResult">
        <result property="id"    column="id"    />
        <result property="carVin"    column="car_vin"    />
        <result property="carPlate"    column="car_plate"    />
        <result property="carBrand"    column="car_brand"    />
        <result property="carModel"    column="car_model"    />
        <result property="carType"    column="car_type"    />
        <result property="carLastJoinTime"    column="car_last_join_time"    />
        <result property="carLastOfflineTime"    column="car_last_offline_time"    />
        <result property="state"    column="state"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectSysCarVo">
        select id, car_vin, car_plate, car_brand, car_model, car_type, car_last_join_time, car_last_offline_time, state, create_by, create_time, update_by, update_time, remark from sys_car
    </sql>

    <select id="selectSysCarList" parameterType="SysCar" resultMap="SysCarResult">
        <include refid="selectSysCarVo"/>
        <where>
            <if test="carVin != null  and carVin != ''"> and car_vin = #{carVin}</if>
            <if test="carPlate != null  and carPlate != ''"> and car_plate = #{carPlate}</if>
            <if test="carBrand != null  and carBrand != ''"> and car_brand = #{carBrand}</if>
            <if test="carModel != null  and carModel != ''"> and car_model = #{carModel}</if>
            <if test="carType != null  and carType != ''"> and car_type = #{carType}</if>
            <if test="carLastJoinTime != null "> and car_last_join_time = #{carLastJoinTime}</if>
            <if test="carLastOfflineTime != null "> and car_last_offline_time = #{carLastOfflineTime}</if>
            <if test="state != null  and state != ''"> and state = #{state}</if>
        </where>
    </select>

    <select id="selectSysCarById" parameterType="Long" resultMap="SysCarResult">
        <include refid="selectSysCarVo"/>
        where id = #{id}
    </select>

    <insert id="insertSysCar" parameterType="SysCar" useGeneratedKeys="true" keyProperty="id">
        insert into sys_car
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="carVin != null and carVin != ''">car_vin,</if>
            <if test="carPlate != null and carPlate != ''">car_plate,</if>
            <if test="carBrand != null">car_brand,</if>
            <if test="carModel != null">car_model,</if>
            <if test="carType != null">car_type,</if>
            <if test="carLastJoinTime != null">car_last_join_time,</if>
            <if test="carLastOfflineTime != null">car_last_offline_time,</if>
            <if test="state != null">state,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="carVin != null and carVin != ''">#{carVin},</if>
            <if test="carPlate != null and carPlate != ''">#{carPlate},</if>
            <if test="carBrand != null">#{carBrand},</if>
            <if test="carModel != null">#{carModel},</if>
            <if test="carType != null">#{carType},</if>
            <if test="carLastJoinTime != null">#{carLastJoinTime},</if>
            <if test="carLastOfflineTime != null">#{carLastOfflineTime},</if>
            <if test="state != null">#{state},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateSysCar" parameterType="SysCar">
        update sys_car
        <trim prefix="SET" suffixOverrides=",">
            <if test="carVin != null and carVin != ''">car_vin = #{carVin},</if>
            <if test="carPlate != null and carPlate != ''">car_plate = #{carPlate},</if>
            <if test="carBrand != null">car_brand = #{carBrand},</if>
            <if test="carModel != null">car_model = #{carModel},</if>
            <if test="carType != null">car_type = #{carType},</if>
            <if test="carLastJoinTime != null">car_last_join_time = #{carLastJoinTime},</if>
            <if test="carLastOfflineTime != null">car_last_offline_time = #{carLastOfflineTime},</if>
            <if test="state != null">state = #{state},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysCarById" parameterType="Long">
        delete from sys_car where id = #{id}
    </delete>

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