<?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.pine.admin.modules.business.dao.CarOrderDao">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.pine.admin.modules.business.entity.CarOrder" id="entityMap">
        <result property="id" column="id"/>
        <result property="code" column="code"/>
        <result property="customerId" column="customer_id"/>
        <result property="payType" column="pay_type"/>
        <result property="status" column="status"/>
        <result property="loanStatus" column="loan_status"/>
        <result property="isUse" column="is_use"/>
        <result property="carId" column="car_id"/>
        <result property="carJson" column="car_json"/>
        <result property="pickedCarInformation" column="picked_car_information"/>
        <result property="loanInstalmentCount" column="loan_instalment_count"/>
        <result property="loanRate" column="loan_rate"/>
        <result property="downPaymentRate" column="down_payment_rate"/>
        <result property="realDownPaymentRate" column="real_down_payment_rate"/>
        <result property="totalPrice" column="total_price"/>
        <result property="depositPrice" column="deposit_price"/>
        <result property="finalPaymentPrice" column="final_payment_price"/>
        <result property="downPaymentPrice" column="down_payment_price"/>
        <result property="realDownPaymentPrice" column="real_down_payment_price"/>
        <result property="loanPrice" column="loan_price"/>
        <result property="monthlyInstallmentPaymentPrice" column="monthly_installment_payment_price"/>
        <result property="name" column="name"/>
        <result property="mobile" column="mobile"/>
        <result property="idCard" column="id_card"/>
        <result property="pickCity" column="pick_city"/>
        <result property="carSupplier" column="car_supplier"/>
        <result property="carSupplierNo" column="car_supplier_no"/>
        <result property="createTime" column="create_time"/>
        <result property="orderCancelTime" column="order_cancel_time"/>
        <result property="payDepositTime" column="pay_deposit_time"/>
        <result property="onlineAuditTime" column="online_audit_time"/>
        <result property="offlineAuditTime" column="offline_audit_time"/>
        <result property="orderFinishTime" column="order_finish_time"/>
        <result property="url" column="url"/>
        <result property="cancelReason" column="cancel_reason"/>
        <result property="isSend" column="is_send"/>
    </resultMap>

    <resultMap id="offlinePayments" type="com.pine.admin.modules.business.entity.CarOrder" extends="entityMap">

        <association property="offlinePayments"
                     javaType="com.pine.admin.modules.business.entity.OfflinePayments"
                     select="com.pine.admin.modules.business.dao.OfflinePaymentsDao.queryOne"
                     column="{ carOrderId = id }"/>

        <association property="isRefund"
                     javaType="java.lang.Integer"
                     select="com.pine.admin.modules.business.dao.CarBackOrderDao.isRefund"
                     column="{ orderId = id }"/>
    </resultMap>
    <sql id="Base_Column_List">
                 id,
                     code,
                     customer_id,
                     pay_type,
                     status,
                     loan_status,
                     is_use,
                     car_id,
                     car_json,
                     picked_car_information,
                     loan_instalment_count,
                     loan_rate,
                     down_payment_rate,
                     real_down_payment_rate,
                     total_price,
                     deposit_price,
                     final_payment_price,
                     down_payment_price,
                     real_down_payment_price,
                     loan_price,
                     monthly_installment_payment_price,
                     name,
                     mobile,
                     id_card,
                     pick_city,
                     car_supplier,
                     car_supplier_no,
                     create_time,
                     order_cancel_time,
                     pay_deposit_time,
                     online_audit_time,
                     offline_audit_time,
                     order_finish_time,
                     url,
                     cancel_reason,
                    is_send         </sql>
    <sql id="lco_Column_sql">
            lco.id		id,
            lco.code		code,
            lco.customer_id		customer_id,
            lco.pay_type		pay_type,
            lco.status		status,
            lco.loan_status		loan_status,
            lco.is_use		is_use,
            lco.car_id		car_id,
            lco.car_json		car_json,
            lco.picked_car_information		picked_car_information,
            lco.loan_instalment_count		loan_instalment_count,
            lco.loan_rate		loan_rate,
            lco.down_payment_rate		down_payment_rate,
            lco.real_down_payment_rate		real_down_payment_rate,
            lco.total_price		total_price,
            lco.deposit_price		deposit_price,
            lco.final_payment_price		final_payment_price,
            lco.down_payment_price		down_payment_price,
            lco.real_down_payment_price		real_down_payment_price,
            lco.loan_price		loan_price,
            lco.monthly_installment_payment_price		monthly_installment_payment_price,
            lco.name		name,
            lco.mobile		mobile,
            lco.id_card		id_card,
            lco.pick_city		pick_city,
            lco.car_supplier		car_supplier,
            lco.car_supplier_no		car_supplier_no,
            lco.create_time		create_time,
            lco.order_cancel_time		order_cancel_time,
            lco.pay_deposit_time		pay_deposit_time,
            lco.online_audit_time		online_audit_time,
            lco.offline_audit_time		offline_audit_time,
            lco.order_finish_time		order_finish_time,
            lco.url		url,
            lco.cancel_reason		cancel_reason,


    </sql>
    <!-- 根据Id查询-->
    <select id="selectByPrimaryKey" resultMap="entityMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from ls_car_order
        where id = #{id,jdbcType=INTEGER}
    </select>

    <!-- 根据Id删除-->
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
		delete from ls_car_order
		where id = #{id,jdbcType=INTEGER}
	</delete>

    <!-- 插入数据-->
    <insert id="insertSelective" parameterType="com.pine.admin.modules.business.entity.CarOrder"
            useGeneratedKeys="true" keyProperty="id">
        insert into ls_car_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="code != null">code,</if>
            <if test="customerId != null">customer_id,</if>
            <if test="payType != null">pay_type,</if>
            <if test="status != null">status,</if>
            <if test="loanStatus != null">loan_status,</if>
            <if test="isUse != null">is_use,</if>
            <if test="carId != null">car_id,</if>
            <if test="carJson != null">car_json,</if>
            <if test="pickedCarInformation != null">picked_car_information,</if>
            <if test="loanInstalmentCount != null">loan_instalment_count,</if>
            <if test="loanRate != null">loan_rate,</if>
            <if test="downPaymentRate != null">down_payment_rate,</if>
            <if test="realDownPaymentRate != null">real_down_payment_rate,</if>
            <if test="totalPrice != null">total_price,</if>
            <if test="depositPrice != null">deposit_price,</if>
            <if test="finalPaymentPrice != null">final_payment_price,</if>
            <if test="downPaymentPrice != null">down_payment_price,</if>
            <if test="realDownPaymentPrice != null">real_down_payment_price,</if>
            <if test="loanPrice != null">loan_price,</if>
            <if test="monthlyInstallmentPaymentPrice != null">monthly_installment_payment_price,</if>
            <if test="name != null">name,</if>
            <if test="mobile != null">mobile,</if>
            <if test="idCard != null">id_card,</if>
            <if test="pickCity != null">pick_city,</if>
            <if test="carSupplier != null">car_supplier,</if>
            <if test="carSupplierNo != null">car_supplier_no,</if>
            <if test="createTime != null">create_time,</if>
            <if test="orderCancelTime != null">order_cancel_time,</if>
            <if test="payDepositTime != null">pay_deposit_time,</if>
            <if test="onlineAuditTime != null">online_audit_time,</if>
            <if test="offlineAuditTime != null">offline_audit_time,</if>
            <if test="orderFinishTime != null">order_finish_time,</if>
            <if test="url != null">url,</if>
            <if test="cancelReason != null">cancel_reason,</if>
            <if test="isSend != null">is_send,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="code != null">#{code},</if>
            <if test="customerId != null">#{customerId},</if>
            <if test="payType != null">#{payType},</if>
            <if test="status != null">#{status},</if>
            <if test="loanStatus != null">#{loanStatus},</if>
            <if test="isUse != null">#{isUse},</if>
            <if test="carId != null">#{carId},</if>
            <if test="carJson != null">#{carJson},</if>
            <if test="pickedCarInformation != null">#{pickedCarInformation},</if>
            <if test="loanInstalmentCount != null">#{loanInstalmentCount},</if>
            <if test="loanRate != null">#{loanRate},</if>
            <if test="downPaymentRate != null">#{downPaymentRate},</if>
            <if test="realDownPaymentRate != null">#{realDownPaymentRate},</if>
            <if test="totalPrice != null">#{totalPrice},</if>
            <if test="depositPrice != null">#{depositPrice},</if>
            <if test="finalPaymentPrice != null">#{finalPaymentPrice},</if>
            <if test="downPaymentPrice != null">#{downPaymentPrice},</if>
            <if test="realDownPaymentPrice != null">#{realDownPaymentPrice},</if>
            <if test="loanPrice != null">#{loanPrice},</if>
            <if test="monthlyInstallmentPaymentPrice != null">#{monthlyInstallmentPaymentPrice},</if>
            <if test="name != null">#{name},</if>
            <if test="mobile != null">#{mobile},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="pickCity != null">#{pickCity},</if>
            <if test="carSupplier != null">#{carSupplier},</if>
            <if test="carSupplierNo != null">#{carSupplierNo},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="orderCancelTime != null">#{orderCancelTime},</if>
            <if test="payDepositTime != null">#{payDepositTime},</if>
            <if test="onlineAuditTime != null">#{onlineAuditTime},</if>
            <if test="offlineAuditTime != null">#{offlineAuditTime},</if>
            <if test="orderFinishTime != null">#{orderFinishTime},</if>
            <if test="url != null">#{url},</if>
            <if test="cancelReason != null">#{cancelReason},</if>
            <if test="isSend != null">#{isSend},</if>
        </trim>
    </insert>

    <!-- 更新数据-->
    <update id="updateByPrimaryKeySelective" parameterType="com.pine.admin.modules.business.entity.CarOrder">
        update ls_car_order
        <set>
            <if test="id != null">id = #{id},</if>
            <if test="code != null">code = #{code},</if>
            <if test="customerId != null">customer_id = #{customerId},</if>
            <if test="payType != null">pay_type = #{payType},</if>
            <if test="status != null">status = #{status},</if>
            <if test="loanStatus != null">loan_status = #{loanStatus},</if>
            <if test="isUse != null">is_use = #{isUse},</if>
            <if test="carId != null">car_id = #{carId},</if>
            <if test="carJson != null">car_json = #{carJson},</if>
            <if test="pickedCarInformation != null">picked_car_information = #{pickedCarInformation},</if>
            <if test="loanInstalmentCount != null">loan_instalment_count = #{loanInstalmentCount},</if>
            <if test="loanRate != null">loan_rate = #{loanRate},</if>
            <if test="downPaymentRate != null">down_payment_rate = #{downPaymentRate},</if>
            <if test="realDownPaymentRate != null">real_down_payment_rate = #{realDownPaymentRate},</if>
            <if test="totalPrice != null">total_price = #{totalPrice},</if>
            <if test="depositPrice != null">deposit_price = #{depositPrice},</if>
            <if test="finalPaymentPrice != null">final_payment_price = #{finalPaymentPrice},</if>
            <if test="downPaymentPrice != null">down_payment_price = #{downPaymentPrice},</if>
            <if test="realDownPaymentPrice != null">real_down_payment_price = #{realDownPaymentPrice},</if>
            <if test="loanPrice != null">loan_price = #{loanPrice},</if>
            <if test="monthlyInstallmentPaymentPrice != null">monthly_installment_payment_price =
                #{monthlyInstallmentPaymentPrice},
            </if>
            <if test="name != null">name = #{name},</if>
            <if test="mobile != null">mobile = #{mobile},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="pickCity != null">pick_city = #{pickCity},</if>
            <if test="carSupplier != null">car_supplier = #{carSupplier},</if>
            <if test="carSupplierNo != null">car_supplier_no = #{carSupplierNo},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="orderCancelTime != null">order_cancel_time = #{orderCancelTime},</if>
            <if test="payDepositTime != null">pay_deposit_time = #{payDepositTime},</if>
            <if test="onlineAuditTime != null">online_audit_time = #{onlineAuditTime},</if>
            <if test="offlineAuditTime != null">offline_audit_time = #{offlineAuditTime},</if>
            <if test="orderFinishTime != null">order_finish_time = #{orderFinishTime},</if>
            <if test="url != null">url = #{url},</if>
            <if test="cancelReason != null">cancel_reason = #{cancelReason},</if>
            <if test="isSend != null">is_send = #{isSend},</if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>

    <!-- 线上支付分页查询-->
    <select id="queryByPage" parameterType="java.util.Map"
            resultMap="offlinePayments">
        select
        <include refid="Base_Column_List"/>
        from ls_car_order
        <where>
            <if test="record.id != null and !&quot;&quot;.equals(record.id)">
                and id = #{record.id}
            </if>
            <if test="record.code != null and !&quot;&quot;.equals(record.code)">
                and code = #{record.code}
            </if>
            <if test="record.customerId != null and !&quot;&quot;.equals(record.customerId)">
                and customer_id = #{record.customerId}
            </if>
            <if test="record.payType != null and !&quot;&quot;.equals(record.payType)">
                and pay_type = #{record.payType}
            </if>
            <if test="record.status != null and !&quot;&quot;.equals(record.status)">
                and status = #{record.status}
            </if>
            <if test="record.loanStatus != null and !&quot;&quot;.equals(record.loanStatus)">
                and loan_status = #{record.loanStatus}
            </if>
            <if test="record.isUse != null and !&quot;&quot;.equals(record.isUse)">
                and is_use = #{record.isUse}
            </if>
            <if test="record.carId != null and !&quot;&quot;.equals(record.carId)">
                and car_id = #{record.carId}
            </if>
            <if test="record.carJson != null and !&quot;&quot;.equals(record.carJson)">
                and car_json = #{record.carJson}
            </if>
            <if test="record.pickedCarInformation != null and !&quot;&quot;.equals(record.pickedCarInformation)">
                and picked_car_information = #{record.pickedCarInformation}
            </if>
            <if test="record.loanInstalmentCount != null and !&quot;&quot;.equals(record.loanInstalmentCount)">
                and loan_instalment_count = #{record.loanInstalmentCount}
            </if>
            <if test="record.loanRate != null and !&quot;&quot;.equals(record.loanRate)">
                and loan_rate = #{record.loanRate}
            </if>
            <if test="record.downPaymentRate != null and !&quot;&quot;.equals(record.downPaymentRate)">
                and down_payment_rate = #{record.downPaymentRate}
            </if>
            <if test="record.realDownPaymentRate != null and !&quot;&quot;.equals(record.realDownPaymentRate)">
                and real_down_payment_rate = #{record.realDownPaymentRate}
            </if>
            <if test="record.totalPrice != null and !&quot;&quot;.equals(record.totalPrice)">
                and total_price = #{record.totalPrice}
            </if>
            <if test="record.depositPrice != null and !&quot;&quot;.equals(record.depositPrice)">
                and deposit_price = #{record.depositPrice}
            </if>
            <if test="record.finalPaymentPrice != null and !&quot;&quot;.equals(record.finalPaymentPrice)">
                and final_payment_price = #{record.finalPaymentPrice}
            </if>
            <if test="record.downPaymentPrice != null and !&quot;&quot;.equals(record.downPaymentPrice)">
                and down_payment_price = #{record.downPaymentPrice}
            </if>
            <if test="record.realDownPaymentPrice != null and !&quot;&quot;.equals(record.realDownPaymentPrice)">
                and real_down_payment_price = #{record.realDownPaymentPrice}
            </if>
            <if test="record.loanPrice != null and !&quot;&quot;.equals(record.loanPrice)">
                and loan_price = #{record.loanPrice}
            </if>
            <if test="record.monthlyInstallmentPaymentPrice != null and !&quot;&quot;.equals(record.monthlyInstallmentPaymentPrice)">
                and monthly_installment_payment_price = #{record.monthlyInstallmentPaymentPrice}
            </if>
            <if test="record.name != null and !&quot;&quot;.equals(record.name)">
                and name = #{record.name}
            </if>
            <if test="record.mobile != null and !&quot;&quot;.equals(record.mobile)">
                and mobile = #{record.mobile}
            </if>
            <if test="record.idCard != null and !&quot;&quot;.equals(record.idCard)">
                and id_card = #{record.idCard}
            </if>
            <if test="record.pickCity != null and !&quot;&quot;.equals(record.pickCity)">
                and pick_city = #{record.pickCity}
            </if>
            <if test="record.carSupplier != null and !&quot;&quot;.equals(record.carSupplier)">
                and car_supplier = #{record.carSupplier}
            </if>
            <if test="record.carSupplierNo != null and !&quot;&quot;.equals(record.carSupplierNo)">
                and car_supplier_no = #{record.carSupplierNo}
            </if>
            <if test="record.createTime != null and !&quot;&quot;.equals(record.createTime)">
                and create_time = #{record.createTime}
            </if>
            <if test="record.orderCancelTime != null and !&quot;&quot;.equals(record.orderCancelTime)">
                and order_cancel_time = #{record.orderCancelTime}
            </if>
            <if test="record.payDepositTime != null and !&quot;&quot;.equals(record.payDepositTime)">
                and pay_deposit_time = #{record.payDepositTime}
            </if>
            <if test="record.onlineAuditTime != null and !&quot;&quot;.equals(record.onlineAuditTime)">
                and online_audit_time = #{record.onlineAuditTime}
            </if>
            <if test="record.offlineAuditTime != null and !&quot;&quot;.equals(record.offlineAuditTime)">
                and offline_audit_time = #{record.offlineAuditTime}
            </if>
            <if test="record.orderFinishTime != null and !&quot;&quot;.equals(record.orderFinishTime)">
                and order_finish_time = #{record.orderFinishTime}
            </if>
            <if test="record.url != null and !&quot;&quot;.equals(record.url)">
                and url = #{record.url}
            </if>
            <if test="record.cancelReason != null and !&quot;&quot;.equals(record.cancelReason)">
                and cancel_reason = #{record.cancelReason}
            </if>
            <if test="record.isSend != null and !&quot;&quot;.equals(record.isSend)">
                and is_send = #{record.isSend}
            </if>
            <if test="record.offlinePayType == 2">
                and status = 3
            </if>
            -- and loan_status != 2
            and status != 1
        </where>
        order by id desc
    </select>
    <!-- 查询退订订单  -->
    <select id="queryBackByPage" parameterType="java.util.Map" resultMap="offlinePayments">
        select lco.*, lcbo.status backStatus from ls_car_order lco JOIN ls_car_back_order lcbo on lco.`code` =
        lcbo.order_code
        <where>
            and lco.status != 1 and lco.status !=4
            <if test="record.backStatus != null and !&quot;&quot;.equals(record.backStatus)">
                and lcbo.status = #{record.backStatus}
            </if>
            <if test="record.code != null and !&quot;&quot;.equals(record.code)">
                and lco.code = #{record.code}
            </if>
            <if test="record.payType != null and !&quot;&quot;.equals(record.payType)">
                and lco.pay_type = #{record.payType}
            </if>
            <if test="record.status != null and !&quot;&quot;.equals(record.status)">
                and lco.status = #{record.status}
            </if>
            <if test="record.loanStatus != null and !&quot;&quot;.equals(record.loanStatus)">
                and lco.loan_status = #{record.loanStatus}
            </if>
            <if test="record.carId != null and !&quot;&quot;.equals(record.carId)">
                and lco.car_id = #{record.carId}
            </if>
            <if test="record.pickedCarInformation != null and !&quot;&quot;.equals(record.pickedCarInformation)">
                and lco.picked_car_information = #{record.pickedCarInformation}
            </if>
            <if test="record.loanInstalmentCount != null and !&quot;&quot;.equals(record.loanInstalmentCount)">
                and lco.loan_instalment_count = #{record.loanInstalmentCount}
            </if>
            <if test="record.loanRate != null and !&quot;&quot;.equals(record.loanRate)">
                and lco.loan_rate = #{record.loanRate}
            </if>
            <if test="record.downPaymentRate != null and !&quot;&quot;.equals(record.downPaymentRate)">
                and lco.down_payment_rate = #{record.downPaymentRate}
            </if>
            <if test="record.realDownPaymentRate != null and !&quot;&quot;.equals(record.realDownPaymentRate)">
                and lco.real_down_payment_rate = #{record.realDownPaymentRate}
            </if>
            <if test="record.name != null and !&quot;&quot;.equals(record.name)">
                and lco.name = #{record.name}
            </if>
            <if test="record.mobile != null and !&quot;&quot;.equals(record.mobile)">
                and lco.mobile = #{record.mobile}
            </if>
            <if test="record.idCard != null and !&quot;&quot;.equals(record.idCard)">
                and lco.id_card = #{record.idCard}
            </if>
            <if test="record.pickCity != null and !&quot;&quot;.equals(record.pickCity)">
                and lco.pick_city = #{record.pickCity}
            </if>
            <if test="record.carSupplier != null and !&quot;&quot;.equals(record.carSupplier)">
                and lco.car_supplier = #{record.carSupplier}
            </if>
            <if test="record.carSupplierNo != null and !&quot;&quot;.equals(record.carSupplierNo)">
                and lco.car_supplier_no = #{record.carSupplierNo}
            </if>
            <if test="record.cancelReason != null and !&quot;&quot;.equals(record.cancelReason)">
                and lco.cancel_reason = #{record.cancelReason}
            </if>
        </where>
        order by lco.id desc
    </select>

    <!-- 查询未支付和线下支付的  -->
    <select id="queryOfflineByPage" parameterType="java.util.Map"
            resultMap="offlinePayments">
        select
        lco.*
        from ls_car_order lco
        LEFT JOIN ls_offline_payments lof ON lco.id = lof.car_order_id
        <where>
            and lco.status != 1 and lco.status !=4

            <if test="record.code != null and !&quot;&quot;.equals(record.code)">
                and lco.code = #{record.code}
            </if>
            <if test="record.customerId != null and !&quot;&quot;.equals(record.customerId)">
                and lco.customer_id = #{record.customerId}
            </if>
            <if test="record.payType != null and !&quot;&quot;.equals(record.payType)">
                and lco.pay_type = #{record.payType}
            </if>
            <if test="record.status != null and !&quot;&quot;.equals(record.status)">
                and lco.status = #{record.status}
            </if>
            <if test="record.loanStatus != null and !&quot;&quot;.equals(record.loanStatus)">
                and lco.loan_status = #{record.loanStatus}
            </if>
            <if test="record.isUse != null and !&quot;&quot;.equals(record.isUse)">
                and lco.is_use = #{record.isUse}
            </if>
            <if test="record.carId != null and !&quot;&quot;.equals(record.carId)">
                and lco.car_id = #{record.carId}
            </if>
            <if test="record.carJson != null and !&quot;&quot;.equals(record.carJson)">
                and lco.car_json = #{record.carJson}
            </if>
            <if test="record.pickedCarInformation != null and !&quot;&quot;.equals(record.pickedCarInformation)">
                and lco.picked_car_information = #{record.pickedCarInformation}
            </if>
            <if test="record.loanInstalmentCount != null and !&quot;&quot;.equals(record.loanInstalmentCount)">
                and lco.loan_instalment_count = #{record.loanInstalmentCount}
            </if>
            <if test="record.loanRate != null and !&quot;&quot;.equals(record.loanRate)">
                and lco.loan_rate = #{record.loanRate}
            </if>
            <if test="record.downPaymentRate != null and !&quot;&quot;.equals(record.downPaymentRate)">
                and lco.down_payment_rate = #{record.downPaymentRate}
            </if>
            <if test="record.realDownPaymentRate != null and !&quot;&quot;.equals(record.realDownPaymentRate)">
                and lco.real_down_payment_rate = #{record.realDownPaymentRate}
            </if>
            <if test="record.totalPrice != null and !&quot;&quot;.equals(record.totalPrice)">
                and lco.total_price = #{record.totalPrice}
            </if>
            <if test="record.depositPrice != null and !&quot;&quot;.equals(record.depositPrice)">
                and lco.deposit_price = #{record.depositPrice}
            </if>
            <if test="record.finalPaymentPrice != null and !&quot;&quot;.equals(record.finalPaymentPrice)">
                and lco.final_payment_price = #{record.finalPaymentPrice}
            </if>
            <if test="record.downPaymentPrice != null and !&quot;&quot;.equals(record.downPaymentPrice)">
                and lco.down_payment_price = #{record.downPaymentPrice}
            </if>
            <if test="record.realDownPaymentPrice != null and !&quot;&quot;.equals(record.realDownPaymentPrice)">
                and lco.real_down_payment_price = #{record.realDownPaymentPrice}
            </if>
            <if test="record.loanPrice != null and !&quot;&quot;.equals(record.loanPrice)">
                and lco.loan_price = #{record.loanPrice}
            </if>
            <if test="record.monthlyInstallmentPaymentPrice != null and !&quot;&quot;.equals(record.monthlyInstallmentPaymentPrice)">
                and lco.monthly_installment_payment_price = #{record.monthlyInstallmentPaymentPrice}
            </if>
            <if test="record.name != null and !&quot;&quot;.equals(record.name)">
                and lco.name = #{record.name}
            </if>
            <if test="record.mobile != null and !&quot;&quot;.equals(record.mobile)">
                and lco.mobile = #{record.mobile}
            </if>
            <if test="record.idCard != null and !&quot;&quot;.equals(record.idCard)">
                and lco.id_card = #{record.idCard}
            </if>
            <if test="record.pickCity != null and !&quot;&quot;.equals(record.pickCity)">
                and lco.pick_city = #{record.pickCity}
            </if>
            <if test="record.carSupplier != null and !&quot;&quot;.equals(record.carSupplier)">
                and lco.car_supplier = #{record.carSupplier}
            </if>
            <if test="record.carSupplierNo != null and !&quot;&quot;.equals(record.carSupplierNo)">
                and lco.car_supplier_no = #{record.carSupplierNo}
            </if>
            <if test="record.cancelReason != null and !&quot;&quot;.equals(record.cancelReason)">
                and lco.cancel_reason = #{record.cancelReason}
            </if>
            <if test="record.isSend != null and !&quot;&quot;.equals(record.isSend)">
                and lco.is_send = #{record.isSend}
            </if>
            <if test="record.offlinePayType == 2 ">
                and lof.car_order_id is null
                and lco.status = 3
            </if>
            <if test="record.offlinePayType == 1">
                and lof.car_order_id is not null
            </if>
            <if test="record.offlinePayType == 3">
                and lof.car_order_id is null
                AND lco.status !=3
            </if>
        </where>
        order by lco.id desc
    </select>

    <!-- 全部查询 -->
    <select id="queryAll" parameterType="java.util.Map"
            resultMap="entityMap">
        select
        <include refid="Base_Column_List"/>
        from ls_car_order
        <where>

            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="code != null and !&quot;&quot;.equals(code)">
                and code = #{code}
            </if>
            <if test="customerId != null and !&quot;&quot;.equals(customerId)">
                and customer_id = #{customerId}
            </if>
            <if test="payType != null and !&quot;&quot;.equals(payType)">
                and pay_type = #{payType}
            </if>
            <if test="status != null and !&quot;&quot;.equals(status)">
                and status = #{status}
            </if>
            <if test="loanStatus != null and !&quot;&quot;.equals(loanStatus)">
                and loan_status = #{loanStatus}
            </if>
            <if test="isUse != null and !&quot;&quot;.equals(isUse)">
                and is_use = #{isUse}
            </if>
            <if test="carId != null and !&quot;&quot;.equals(carId)">
                and car_id = #{carId}
            </if>
            <if test="carJson != null and !&quot;&quot;.equals(carJson)">
                and car_json = #{carJson}
            </if>
            <if test="pickedCarInformation != null and !&quot;&quot;.equals(pickedCarInformation)">
                and picked_car_information = #{pickedCarInformation}
            </if>
            <if test="loanInstalmentCount != null and !&quot;&quot;.equals(loanInstalmentCount)">
                and loan_instalment_count = #{loanInstalmentCount}
            </if>
            <if test="loanRate != null and !&quot;&quot;.equals(loanRate)">
                and loan_rate = #{loanRate}
            </if>
            <if test="downPaymentRate != null and !&quot;&quot;.equals(downPaymentRate)">
                and down_payment_rate = #{downPaymentRate}
            </if>
            <if test="realDownPaymentRate != null and !&quot;&quot;.equals(realDownPaymentRate)">
                and real_down_payment_rate = #{realDownPaymentRate}
            </if>
            <if test="totalPrice != null and !&quot;&quot;.equals(totalPrice)">
                and total_price = #{totalPrice}
            </if>
            <if test="depositPrice != null and !&quot;&quot;.equals(depositPrice)">
                and deposit_price = #{depositPrice}
            </if>
            <if test="finalPaymentPrice != null and !&quot;&quot;.equals(finalPaymentPrice)">
                and final_payment_price = #{finalPaymentPrice}
            </if>
            <if test="downPaymentPrice != null and !&quot;&quot;.equals(downPaymentPrice)">
                and down_payment_price = #{downPaymentPrice}
            </if>
            <if test="realDownPaymentPrice != null and !&quot;&quot;.equals(realDownPaymentPrice)">
                and real_down_payment_price = #{realDownPaymentPrice}
            </if>
            <if test="loanPrice != null and !&quot;&quot;.equals(loanPrice)">
                and loan_price = #{loanPrice}
            </if>
            <if test="monthlyInstallmentPaymentPrice != null and !&quot;&quot;.equals(monthlyInstallmentPaymentPrice)">
                and monthly_installment_payment_price = #{monthlyInstallmentPaymentPrice}
            </if>
            <if test="name != null and !&quot;&quot;.equals(name)">
                and name = #{name}
            </if>
            <if test="mobile != null and !&quot;&quot;.equals(mobile)">
                and mobile = #{mobile}
            </if>
            <if test="idCard != null and !&quot;&quot;.equals(idCard)">
                and id_card = #{idCard}
            </if>
            <if test="pickCity != null and !&quot;&quot;.equals(pickCity)">
                and pick_city = #{pickCity}
            </if>
            <if test="carSupplier != null and !&quot;&quot;.equals(carSupplier)">
                and car_supplier = #{carSupplier}
            </if>
            <if test="carSupplierNo != null and !&quot;&quot;.equals(carSupplierNo)">
                and car_supplier_no = #{carSupplierNo}
            </if>
            <if test="createTime != null and !&quot;&quot;.equals(createTime)">
                and create_time = #{createTime}
            </if>
            <if test="orderCancelTime != null and !&quot;&quot;.equals(orderCancelTime)">
                and order_cancel_time = #{orderCancelTime}
            </if>
            <if test="payDepositTime != null and !&quot;&quot;.equals(payDepositTime)">
                and pay_deposit_time = #{payDepositTime}
            </if>
            <if test="onlineAuditTime != null and !&quot;&quot;.equals(onlineAuditTime)">
                and online_audit_time = #{onlineAuditTime}
            </if>
            <if test="offlineAuditTime != null and !&quot;&quot;.equals(offlineAuditTime)">
                and offline_audit_time = #{offlineAuditTime}
            </if>
            <if test="orderFinishTime != null and !&quot;&quot;.equals(orderFinishTime)">
                and order_finish_time = #{orderFinishTime}
            </if>
            <if test="url != null and !&quot;&quot;.equals(url)">
                and url = #{url}
            </if>
            <if test="cancelReason != null and !&quot;&quot;.equals(cancelReason)">
                and cancel_reason = #{cancelReason}
            </if>
            <if test="isSend != null and !&quot;&quot;.equals(isSend)">
                and is_send = #{isSend}
            </if>
        </where>
        order by id desc
    </select>

    <!-- 根据条件查询一个 -->
    <select id="queryOne" parameterType="java.util.Map"
            resultMap="entityMap">
        select
        <include refid="Base_Column_List"/>
        from ls_car_order
        <where>

            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="code != null and !&quot;&quot;.equals(code)">
                and code = #{code}
            </if>
            <if test="customerId != null and !&quot;&quot;.equals(customerId)">
                and customer_id = #{customerId}
            </if>
            <if test="payType != null and !&quot;&quot;.equals(payType)">
                and pay_type = #{payType}
            </if>
            <if test="status != null and !&quot;&quot;.equals(status)">
                and status = #{status}
            </if>
            <if test="loanStatus != null and !&quot;&quot;.equals(loanStatus)">
                and loan_status = #{loanStatus}
            </if>
            <if test="isUse != null and !&quot;&quot;.equals(isUse)">
                and is_use = #{isUse}
            </if>
            <if test="carId != null and !&quot;&quot;.equals(carId)">
                and car_id = #{carId}
            </if>
            <if test="carJson != null and !&quot;&quot;.equals(carJson)">
                and car_json = #{carJson}
            </if>
            <if test="pickedCarInformation != null and !&quot;&quot;.equals(pickedCarInformation)">
                and picked_car_information = #{pickedCarInformation}
            </if>
            <if test="loanInstalmentCount != null and !&quot;&quot;.equals(loanInstalmentCount)">
                and loan_instalment_count = #{loanInstalmentCount}
            </if>
            <if test="loanRate != null and !&quot;&quot;.equals(loanRate)">
                and loan_rate = #{loanRate}
            </if>
            <if test="downPaymentRate != null and !&quot;&quot;.equals(downPaymentRate)">
                and down_payment_rate = #{downPaymentRate}
            </if>
            <if test="realDownPaymentRate != null and !&quot;&quot;.equals(realDownPaymentRate)">
                and real_down_payment_rate = #{realDownPaymentRate}
            </if>
            <if test="totalPrice != null and !&quot;&quot;.equals(totalPrice)">
                and total_price = #{totalPrice}
            </if>
            <if test="depositPrice != null and !&quot;&quot;.equals(depositPrice)">
                and deposit_price = #{depositPrice}
            </if>
            <if test="finalPaymentPrice != null and !&quot;&quot;.equals(finalPaymentPrice)">
                and final_payment_price = #{finalPaymentPrice}
            </if>
            <if test="downPaymentPrice != null and !&quot;&quot;.equals(downPaymentPrice)">
                and down_payment_price = #{downPaymentPrice}
            </if>
            <if test="realDownPaymentPrice != null and !&quot;&quot;.equals(realDownPaymentPrice)">
                and real_down_payment_price = #{realDownPaymentPrice}
            </if>
            <if test="loanPrice != null and !&quot;&quot;.equals(loanPrice)">
                and loan_price = #{loanPrice}
            </if>
            <if test="monthlyInstallmentPaymentPrice != null and !&quot;&quot;.equals(monthlyInstallmentPaymentPrice)">
                and monthly_installment_payment_price = #{monthlyInstallmentPaymentPrice}
            </if>
            <if test="name != null and !&quot;&quot;.equals(name)">
                and name = #{name}
            </if>
            <if test="mobile != null and !&quot;&quot;.equals(mobile)">
                and mobile = #{mobile}
            </if>
            <if test="idCard != null and !&quot;&quot;.equals(idCard)">
                and id_card = #{idCard}
            </if>
            <if test="pickCity != null and !&quot;&quot;.equals(pickCity)">
                and pick_city = #{pickCity}
            </if>
            <if test="carSupplier != null and !&quot;&quot;.equals(carSupplier)">
                and car_supplier = #{carSupplier}
            </if>
            <if test="carSupplierNo != null and !&quot;&quot;.equals(carSupplierNo)">
                and car_supplier_no = #{carSupplierNo}
            </if>
            <if test="createTime != null and !&quot;&quot;.equals(createTime)">
                and create_time = #{createTime}
            </if>
            <if test="orderCancelTime != null and !&quot;&quot;.equals(orderCancelTime)">
                and order_cancel_time = #{orderCancelTime}
            </if>
            <if test="payDepositTime != null and !&quot;&quot;.equals(payDepositTime)">
                and pay_deposit_time = #{payDepositTime}
            </if>
            <if test="onlineAuditTime != null and !&quot;&quot;.equals(onlineAuditTime)">
                and online_audit_time = #{onlineAuditTime}
            </if>
            <if test="offlineAuditTime != null and !&quot;&quot;.equals(offlineAuditTime)">
                and offline_audit_time = #{offlineAuditTime}
            </if>
            <if test="orderFinishTime != null and !&quot;&quot;.equals(orderFinishTime)">
                and order_finish_time = #{orderFinishTime}
            </if>
            <if test="url != null and !&quot;&quot;.equals(url)">
                and url = #{url}
            </if>
            <if test="cancelReason != null and !&quot;&quot;.equals(cancelReason)">
                and cancel_reason = #{cancelReason}
            </if>
            <if test="isSend != null and !&quot;&quot;.equals(isSend)">
                and is_send = #{isSend}
            </if>
        </where>
        LIMIT 1
    </select>

    <update id="delete">
        UPDATE ls_car_order SET del_flag = 'Y'
        <where>
            AND id = #{id}
        </where>
    </update>

    <update id="deleteIds" parameterType="java.util.ArrayList">
        UPDATE ls_car_order SET del_flag = 'Y'
        WHERE id IN
        <foreach item='ids' collection="array" index="index" open="(" separator="," close=")">
            #{ids}
        </foreach>
    </update>

</mapper>
