<?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.xxfc.platform.app.mapper.BuyVehicleFormMapper">

	<!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.xxfc.platform.app.entity.BuyVehicleForm" id="buyVehicleFormMap">
        <result property="id" column="id"/>
        <result property="crtTime" column="crt_time"/>
        <result property="updTime" column="upd_time"/>
        <result property="modelId" column="model_id"/>
        <result property="contactName" column="contact_name"/>
        <result property="contactPhone" column="contact_phone"/>
        <result property="bookTime" column="book_time"/>
        <result property="companyId" column="company_id"/>
        <result property="remark" column="remark"/>
        <result property="status" column="status"/>
    </resultMap>


    <select id="findBuyVehicleForms" resultMap="buyVehicleFormMap">
        select * from `buy_vehicle_form` where 1=1
        <if test="bvf.startTime != null and bvf.endTime !=null">
            and `book_time` between #{bvf.startTime} and #{bvf.endTime}
        </if>
        <if test="bvf.startTime != null and bvf.endTime == null">
            and `book_time`>= #{bvf.startTime}
        </if>
        <if test="bvf.endTime != null and bvf.startTime == null">
            and  <![CDATA[ `book_time`<= #{bvf.endTime}]]>
        </if>
        <if test="bvf.areaId != null || bvf.companyId !=null">
            <if test="companyIds != null and companyIds.size() != 0">
                and `company_id` in
                <foreach collection="companyIds" item="cpyId"  close=")" open="(" separator=",">
                    #{cpyId}
                </foreach>
            </if>
        </if>
        <if test="bvf.status != null">
            and `status`=#{bvf.status}
        </if>
        order by `book_time` desc
    </select>

    <update id="updateApplyStatusById">
        update `buy_vehicle_form` set `status`=1 where `id`=#{id}
    </update>
</mapper>