<?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.younike.system.mapper.BondPaymentMapper">
    
    <resultMap type="BondPayment" id="BondPaymentResult">
        <result property="paymentId"    column="payment_id"    />
        <result property="merchantId"    column="merchant_id"    />
        <result property="orderNo"    column="order_no"    />
        <result property="payType"    column="pay_type"    />
        <result property="bondBefore"    column="bond_before"    />
        <result property="bondAfter"    column="bond_after"    />
        <result property="bondMoney"    column="bond_money"    />
        <result property="bondState"    column="bond_state"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectBondPaymentVo">
        select payment_id, merchant_id, order_no, pay_type, bond_before, bond_after, bond_money, bond_state, del_flag, create_by, create_time, update_by, update_time from bond_payment
    </sql>

    <select id="selectBondPaymentList" parameterType="BondPayment" resultMap="BondPaymentResult">
        <include refid="selectBondPaymentVo"/>
        <where>  
            <if test="merchantId != null "> and merchant_id = #{merchantId}</if>
            <if test="orderNo != null  and orderNo != ''"> and order_no = #{orderNo}</if>
            <if test="payType != null  and payType != ''"> and pay_type = #{payType}</if>
            <if test="bondBefore != null "> and bond_before = #{bondBefore}</if>
            <if test="bondAfter != null "> and bond_after = #{bondAfter}</if>
            <if test="bondMoney != null "> and bond_money = #{bondMoney}</if>
            <if test="bondState != null  and bondState != ''"> and bond_state = #{bondState}</if>
            and del_flag = 0
        </where>
    </select>
    
    <select id="selectBondPaymentByPaymentId" parameterType="String" resultMap="BondPaymentResult">
        <include refid="selectBondPaymentVo"/>
        where payment_id = #{paymentId}
    </select>
        
    <insert id="insertBondPayment" parameterType="BondPayment">
        insert into bond_payment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="paymentId != null">payment_id,</if>
            <if test="merchantId != null">merchant_id,</if>
            <if test="orderNo != null and orderNo != ''">order_no,</if>
            <if test="payType != null and payType != ''">pay_type,</if>
            <if test="bondBefore != null">bond_before,</if>
            <if test="bondAfter != null">bond_after,</if>
            <if test="bondMoney != null">bond_money,</if>
            <if test="bondState != null">bond_state,</if>
            <if test="delFlag != null">del_flag,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="paymentId != null">#{paymentId},</if>
            <if test="merchantId != null">#{merchantId},</if>
            <if test="orderNo != null and orderNo != ''">#{orderNo},</if>
            <if test="payType != null and payType != ''">#{payType},</if>
            <if test="bondBefore != null">#{bondBefore},</if>
            <if test="bondAfter != null">#{bondAfter},</if>
            <if test="bondMoney != null">#{bondMoney},</if>
            <if test="bondState != null">#{bondState},</if>
            <if test="delFlag != null">#{delFlag},</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>
         </trim>
    </insert>

    <update id="updateBondPayment" parameterType="BondPayment">
        update bond_payment
        <trim prefix="SET" suffixOverrides=",">
            <if test="merchantId != null">merchant_id = #{merchantId},</if>
            <if test="orderNo != null and orderNo != ''">order_no = #{orderNo},</if>
            <if test="payType != null and payType != ''">pay_type = #{payType},</if>
            <if test="bondBefore != null">bond_before = #{bondBefore},</if>
            <if test="bondAfter != null">bond_after = #{bondAfter},</if>
            <if test="bondMoney != null">bond_money = #{bondMoney},</if>
            <if test="bondState != null">bond_state = #{bondState},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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>
        </trim>
        where payment_id = #{paymentId}
    </update>

    <delete id="deleteBondPaymentByPaymentId" parameterType="String">
        delete from bond_payment where payment_id = #{paymentId}
    </delete>

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