<?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.cmvr.aima.mapper.AimaVehicleMapper">
    
    <resultMap type="AimaVehicle" id="AimaVehicleResult">
        <result property="id"    column="id"    />
        <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"    />
        <result property="vin"    column="vin"    />
        <result property="vehicleModel"    column="vehicle_model"    />
        <result property="vehicleName"    column="vehicle_name"    />
        <result property="color"    column="color"    />
        <result property="productionDate"    column="production_date"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectAimaVehicleVo">
        select id, create_by, create_time, update_by, update_time, remark, vin, vehicle_model, vehicle_name, color, production_date, status from aima_vehicle
    </sql>

    <select id="selectAimaVehicleList" parameterType="AimaVehicle" resultMap="AimaVehicleResult">
        <include refid="selectAimaVehicleVo"/>
        <where>  
            <if test="vin != null  and vin != ''"> and vin = #{vin}</if>
            <if test="vehicleModel != null  and vehicleModel != ''"> and vehicle_model like concat('%', #{vehicleModel}, '%')</if>
            <if test="vehicleName != null  and vehicleName != ''"> and vehicle_name like concat('%', #{vehicleName}, '%')</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectAimaVehicleById" parameterType="String" resultMap="AimaVehicleResult">
        <include refid="selectAimaVehicleVo"/>
        where id = #{id}
    </select>

    <insert id="insertAimaVehicle" parameterType="AimaVehicle">
        insert into aima_vehicle
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</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>
            <if test="vin != null">vin,</if>
            <if test="vehicleModel != null">vehicle_model,</if>
            <if test="vehicleName != null">vehicle_name,</if>
            <if test="color != null">color,</if>
            <if test="productionDate != null">production_date,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</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>
            <if test="vin != null">#{vin},</if>
            <if test="vehicleModel != null">#{vehicleModel},</if>
            <if test="vehicleName != null">#{vehicleName},</if>
            <if test="color != null">#{color},</if>
            <if test="productionDate != null">#{productionDate},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateAimaVehicle" parameterType="AimaVehicle">
        update aima_vehicle
        <trim prefix="SET" suffixOverrides=",">
            <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>
            <if test="vin != null">vin = #{vin},</if>
            <if test="vehicleModel != null">vehicle_model = #{vehicleModel},</if>
            <if test="vehicleName != null">vehicle_name = #{vehicleName},</if>
            <if test="color != null">color = #{color},</if>
            <if test="productionDate != null">production_date = #{productionDate},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAimaVehicleById" parameterType="String">
        delete from aima_vehicle where id = #{id}
    </delete>

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