<?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.CarBackOrderDao">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.pine.admin.modules.business.entity.CarBackOrder" id="entityMap">
        <result property="id" column="id"/>
        <result property="backCode" column="back_code"/>
        <result property="orderId" column="order_id"/>
        <result property="orderCode" column="order_code"/>
        <result property="customerId" column="customer_id"/>
        <result property="backPrice" column="back_price"/>
        <result property="status" column="status"/>
        <result property="reason" column="reason"/>
        <result property="name" column="name"/>
        <result property="account" column="account"/>
        <result property="bank" column="bank"/>
        <result property="createTime" column="create_time"/>
        <result property="auditTime" column="audit_time"/>
        <result property="auditor" column="auditor"/>
        <result property="finishTime" column="finish_time"/>
        <result property="dealerReason" column="dealer_reason"/>
    </resultMap>

    <sql id="Base_Column_List">
                 id,
                     back_code,
                     order_id,
                     order_code,
                     customer_id,
                     back_price,
                     status,
                     reason,
                     name,
                     account,
                     bank,
                     create_time,
                     audit_time,
                     auditor,
                     finish_time,
                    dealer_reason         </sql>
    <!-- 根据Id查询-->
    <select id="selectByPrimaryKey" resultMap="entityMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from ls_car_back_order
        where id = #{id,jdbcType=INTEGER}
    </select>

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

    <!-- 插入数据-->
    <insert id="insertSelective" parameterType="com.pine.admin.modules.business.entity.CarBackOrder"
            useGeneratedKeys="true" keyProperty="id">
        insert into ls_car_back_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="backCode != null">back_code,</if>
            <if test="orderId != null">order_id,</if>
            <if test="orderCode != null">order_code,</if>
            <if test="customerId != null">customer_id,</if>
            <if test="backPrice != null">back_price,</if>
            <if test="status != null">status,</if>
            <if test="reason != null">reason,</if>
            <if test="name != null">name,</if>
            <if test="account != null">account,</if>
            <if test="bank != null">bank,</if>
            <if test="createTime != null">create_time,</if>
            <if test="auditTime != null">audit_time,</if>
            <if test="auditor != null">auditor,</if>
            <if test="finishTime != null">finish_time,</if>
            <if test="dealerReason != null">dealer_reason,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="backCode != null">#{backCode},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="orderCode != null">#{orderCode},</if>
            <if test="customerId != null">#{customerId},</if>
            <if test="backPrice != null">#{backPrice},</if>
            <if test="status != null">#{status},</if>
            <if test="reason != null">#{reason},</if>
            <if test="name != null">#{name},</if>
            <if test="account != null">#{account},</if>
            <if test="bank != null">#{bank},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="auditTime != null">#{auditTime},</if>
            <if test="auditor != null">#{auditor},</if>
            <if test="finishTime != null">#{finishTime},</if>
            <if test="dealerReason != null">#{dealerReason},</if>
        </trim>
    </insert>

    <!-- 更新数据-->
    <update id="updateByPrimaryKeySelective" parameterType="com.pine.admin.modules.business.entity.CarBackOrder">
        update ls_car_back_order
        <set>
            <if test="id != null">id = #{id},</if>
            <if test="backCode != null">back_code = #{backCode},</if>
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="orderCode != null">order_code = #{orderCode},</if>
            <if test="customerId != null">customer_id = #{customerId},</if>
            <if test="backPrice != null">back_price = #{backPrice},</if>
            <if test="status != null">status = #{status},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="name != null">name = #{name},</if>
            <if test="account != null">account = #{account},</if>
            <if test="bank != null">bank = #{bank},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="auditTime != null">audit_time = #{auditTime},</if>
            <if test="auditor != null">auditor = #{auditor},</if>
            <if test="finishTime != null">finish_time = #{finishTime},</if>
            <if test="dealerReason != null">dealer_reason = #{dealerReason},</if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>

    <!-- 分页查询-->
    <select id="queryByPage" parameterType="java.util.Map"
            resultMap="entityMap">
        select
        <include refid="Base_Column_List"/>
        from ls_car_back_order
        <where>
            <if test="record.id != null and !&quot;&quot;.equals(record.id)">
                and id = #{record.id}
            </if>
            <if test="record.backCode != null and !&quot;&quot;.equals(record.backCode)">
                and back_code = #{record.backCode}
            </if>
            <if test="record.orderId != null and !&quot;&quot;.equals(record.orderId)">
                and order_id = #{record.orderId}
            </if>
            <if test="record.orderCode != null and !&quot;&quot;.equals(record.orderCode)">
                and order_code = #{record.orderCode}
            </if>
            <if test="record.customerId != null and !&quot;&quot;.equals(record.customerId)">
                and customer_id = #{record.customerId}
            </if>
            <if test="record.backPrice != null and !&quot;&quot;.equals(record.backPrice)">
                and back_price = #{record.backPrice}
            </if>
            <if test="record.status != null and !&quot;&quot;.equals(record.status)">
                and status = #{record.status}
            </if>
            <if test="record.reason != null and !&quot;&quot;.equals(record.reason)">
                and reason = #{record.reason}
            </if>
            <if test="record.name != null and !&quot;&quot;.equals(record.name)">
                and name = #{record.name}
            </if>
            <if test="record.account != null and !&quot;&quot;.equals(record.account)">
                and account = #{record.account}
            </if>
            <if test="record.bank != null and !&quot;&quot;.equals(record.bank)">
                and bank = #{record.bank}
            </if>
            <if test="record.createTime != null and !&quot;&quot;.equals(record.createTime)">
                and create_time = #{record.createTime}
            </if>
            <if test="record.auditTime != null and !&quot;&quot;.equals(record.auditTime)">
                and audit_time = #{record.auditTime}
            </if>
            <if test="record.auditor != null and !&quot;&quot;.equals(record.auditor)">
                and auditor = #{record.auditor}
            </if>
            <if test="record.finishTime != null and !&quot;&quot;.equals(record.finishTime)">
                and finish_time = #{record.finishTime}
            </if>
            <if test="record.dealerReason != null and !&quot;&quot;.equals(record.dealerReason)">
                and dealer_reason = #{record.dealerReason}
            </if>
        </where>
        order by id desc
    </select>

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

            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="backCode != null and !&quot;&quot;.equals(backCode)">
                and back_code = #{backCode}
            </if>
            <if test="orderId != null and !&quot;&quot;.equals(orderId)">
                and order_id = #{orderId}
            </if>
            <if test="orderCode != null and !&quot;&quot;.equals(orderCode)">
                and order_code = #{orderCode}
            </if>
            <if test="customerId != null and !&quot;&quot;.equals(customerId)">
                and customer_id = #{customerId}
            </if>
            <if test="backPrice != null and !&quot;&quot;.equals(backPrice)">
                and back_price = #{backPrice}
            </if>
            <if test="status != null and !&quot;&quot;.equals(status)">
                and status = #{status}
            </if>
            <if test="reason != null and !&quot;&quot;.equals(reason)">
                and reason = #{reason}
            </if>
            <if test="name != null and !&quot;&quot;.equals(name)">
                and name = #{name}
            </if>
            <if test="account != null and !&quot;&quot;.equals(account)">
                and account = #{account}
            </if>
            <if test="bank != null and !&quot;&quot;.equals(bank)">
                and bank = #{bank}
            </if>
            <if test="createTime != null and !&quot;&quot;.equals(createTime)">
                and create_time = #{createTime}
            </if>
            <if test="auditTime != null and !&quot;&quot;.equals(auditTime)">
                and audit_time = #{auditTime}
            </if>
            <if test="auditor != null and !&quot;&quot;.equals(auditor)">
                and auditor = #{auditor}
            </if>
            <if test="finishTime != null and !&quot;&quot;.equals(finishTime)">
                and finish_time = #{finishTime}
            </if>
            <if test="dealerReason != null and !&quot;&quot;.equals(dealerReason)">
                and dealer_reason = #{dealerReason}
            </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_back_order
        <where>

            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="backCode != null and !&quot;&quot;.equals(backCode)">
                and back_code = #{backCode}
            </if>
            <if test="orderId != null and !&quot;&quot;.equals(orderId)">
                and order_id = #{orderId}
            </if>
            <if test="orderCode != null and !&quot;&quot;.equals(orderCode)">
                and order_code = #{orderCode}
            </if>
            <if test="customerId != null and !&quot;&quot;.equals(customerId)">
                and customer_id = #{customerId}
            </if>
            <if test="backPrice != null and !&quot;&quot;.equals(backPrice)">
                and back_price = #{backPrice}
            </if>
            <if test="status != null and !&quot;&quot;.equals(status)">
                and status = #{status}
            </if>
            <if test="reason != null and !&quot;&quot;.equals(reason)">
                and reason = #{reason}
            </if>
            <if test="name != null and !&quot;&quot;.equals(name)">
                and name = #{name}
            </if>
            <if test="account != null and !&quot;&quot;.equals(account)">
                and account = #{account}
            </if>
            <if test="bank != null and !&quot;&quot;.equals(bank)">
                and bank = #{bank}
            </if>
            <if test="createTime != null and !&quot;&quot;.equals(createTime)">
                and create_time = #{createTime}
            </if>
            <if test="auditTime != null and !&quot;&quot;.equals(auditTime)">
                and audit_time = #{auditTime}
            </if>
            <if test="auditor != null and !&quot;&quot;.equals(auditor)">
                and auditor = #{auditor}
            </if>
            <if test="finishTime != null and !&quot;&quot;.equals(finishTime)">
                and finish_time = #{finishTime}
            </if>
            <if test="dealerReason != null and !&quot;&quot;.equals(dealerReason)">
                and dealer_reason = #{dealerReason}
            </if>
        </where>
        LIMIT 1
    </select>

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

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

    <select id = "isRefund"  parameterType="java.util.Map"
            resultType="java.lang.Integer">
  SELECT count(*) FROM ls_car_back_order where order_id  = #{orderId} and status !=3
    </select>
</mapper>
