<?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.yiqi.order.mapper.OrderRechargeInstalmentMapper">

    <resultMap type="OrderRechargeInstalment" id="OrderRechargeInstalmentResult">
        <result property="id" column="id"/>
        <result property="mstrOrderNo" column="mstr_order_no"/>
        <result property="orderNo" column="order_no"/>
        <result property="payType" column="pay_type"/>
        <result property="outTradeOrderNo" column="out_trade_order_no"/>
        <result property="payAmount" column="pay_amount"/>
        <result property="payTime" column="pay_time"/>
        <result property="createById" column="create_by_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateById" column="update_by_id"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectOrderRechargeInstalmentVo">
        select id, mstr_order_no, order_no, pay_type, out_trade_order_no, pay_amount, pay_time, create_by_id, create_by, create_time, update_by_id, update_by, update_time, remark
        from order_recharge_instalment
    </sql>

    <select id="selectOrderRechargeInstalmentList" parameterType="OrderRechargeInstalment" resultMap="OrderRechargeInstalmentResult">
        <include refid="selectOrderRechargeInstalmentVo"/>
        <where>
            <if test="mstrOrderNo != null  and mstrOrderNo != ''">
                and mstr_order_no = #{mstrOrderNo}
            </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="outTradeOrderNo != null  and outTradeOrderNo != ''">
                and out_trade_order_no = #{outTradeOrderNo}
            </if>
            <if test="payAmount != null ">
                and pay_amount = #{payAmount}
            </if>
            <if test="payTime != null ">
                and pay_time = #{payTime}
            </if>
        </where>
    </select>

    <select id="selectOrderRechargeInstalmentById" parameterType="Long"
            resultMap="OrderRechargeInstalmentResult">
        <include refid="selectOrderRechargeInstalmentVo"/>
        where id = #{id}
    </select>
    <select id="getTotalPayAmount" resultType="java.math.BigDecimal">
        select sum(pay_amount) as totalPayAmount from order_recharge_instalment where mstr_order_no = #{orderNo} and order_status = '2'
    </select>

    <insert id="insertOrderRechargeInstalment" parameterType="OrderRechargeInstalment" useGeneratedKeys="true"
            keyProperty="id">
        insert into order_recharge_instalment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="mstrOrderNo != null">mstr_order_no,
            </if>
            <if test="orderNo != null">order_no,
            </if>
            <if test="payType != null">pay_type,
            </if>
            <if test="outTradeOrderNo != null">out_trade_order_no,
            </if>
            <if test="payAmount != null">pay_amount,
            </if>
            <if test="payTime != null">pay_time,
            </if>
            <if test="createById != null">create_by_id,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateById != null">update_by_id,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
            <if test="remark != null">remark,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="mstrOrderNo != null">#{mstrOrderNo},
            </if>
            <if test="orderNo != null">#{orderNo},
            </if>
            <if test="payType != null">#{payType},
            </if>
            <if test="outTradeOrderNo != null">#{outTradeOrderNo},
            </if>
            <if test="payAmount != null">#{payAmount},
            </if>
            <if test="payTime != null">#{payTime},
            </if>
            <if test="createById != null">#{createById},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateById != null">#{updateById},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
            <if test="remark != null">#{remark},
            </if>
        </trim>
    </insert>

    <update id="updateOrderRechargeInstalment" parameterType="OrderRechargeInstalment">
        update order_recharge_instalment
        <trim prefix="SET" suffixOverrides=",">
            <if test="mstrOrderNo != null">mstr_order_no =
                #{mstrOrderNo},
            </if>
            <if test="orderNo != null">order_no =
                #{orderNo},
            </if>
            <if test="payType != null">pay_type =
                #{payType},
            </if>
            <if test="outTradeOrderNo != null">out_trade_order_no =
                #{outTradeOrderNo},
            </if>
            <if test="payAmount != null">pay_amount =
                #{payAmount},
            </if>
            <if test="payTime != null">pay_time =
                #{payTime},
            </if>
            <if test="createById != null">create_by_id =
                #{createById},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateById != null">update_by_id =
                #{updateById},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
            <if test="remark != null">remark =
                #{remark},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOrderRechargeInstalmentById" parameterType="Long">
        delete from order_recharge_instalment where id = #{id}
    </delete>

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



</mapper>