<?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.hzs.bonus.bonus.mapper.CuMemberBonusDelayDetailMapper">

    <!-- 删除会员延缓发放明细表 -->
    <delete id="deleteCuMemberBonusDelayDetail">
        delete
        from CU_MEMBER_BONUS_DELAY_DETAIL
        where PK_BONUS in (
            select pk_id
            from cu_member_bonus
            where period = #{period} and grant_status &lt;= 2)
    </delete>

    <!-- 批量插入会员延缓发放明细表 -->
    <insert id="batchInsertCuMemberBonusDelayDetail">
        insert ALL
        <foreach item="item" index="index" collection="CuMemberBonusDelayDetail" separator=" ">
            into cu_member_bonus_delay_detail (
            pk_member, period,
            <if test="item.firCalType != null">fir_cal_type, </if>
            <if test="item.firCalAchieve != null">fir_cal_achieve, </if>
            <if test="item.firCalValue != null">fir_cal_value, </if>
            <if test="item.firPretaxIncome != null">fir_pretax_income, </if>
            <if test="item.repCalType != null">rep_cal_type, </if>
            <if test="item.repCalAchieve != null">rep_cal_achieve, </if>
            <if test="item.repCalValue != null">rep_cal_value, </if>
            <if test="item.repPretaxIncome != null">rep_pretax_income, </if>
            <if test="item.beforePretaxIncome != null">before_pretax_income, </if>
            <if test="item.afterPretaxIncome != null">after_pretax_income, </if>
            <if test="item.pretaxIncome != null">pretax_income, </if>
            <if test="item.incomeTax != null">income_tax, </if>
            <if test="item.realIncome != null">real_income, </if>
            type, pk_country, pk_creator, pk_bonus, expand_capping
            )
            values (
            #{item.pkMember}, #{item.period},
            <if test="item.firCalType != null">#{item.firCalType}, </if>
            <if test="item.firCalAchieve != null">#{item.firCalAchieve}, </if>
            <if test="item.firCalValue != null">#{item.firCalValue}, </if>
            <if test="item.firPretaxIncome != null">#{item.firPretaxIncome}, </if>
            <if test="item.repCalType != null">#{item.repCalType}, </if>
            <if test="item.repCalAchieve != null">#{item.repCalAchieve}, </if>
            <if test="item.repCalValue != null">#{item.repCalValue}, </if>
            <if test="item.repPretaxIncome != null">#{item.repPretaxIncome}, </if>
            <if test="item.beforePretaxIncome != null">#{item.beforePretaxIncome}, </if>
            <if test="item.afterPretaxIncome != null">#{item.afterPretaxIncome}, </if>
            <if test="item.pretaxIncome != null">#{item.pretaxIncome}, </if>
            <if test="item.incomeTax != null">#{item.incomeTax}, </if>
            <if test="item.realIncome != null">#{item.realIncome}, </if>
            #{item.type}, #{item.pkCountry}, #{item.pkCreator}, #{item.pkBonus}, #{item.expandCapping}
            )
        </foreach>
        SELECT 1 FROM dual
    </insert>

</mapper>
