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

    <!-- 通用查询映射结果 -->
    <resultMap id="CuMemberBonusPush" type="com.hzs.common.domain.member.ext.CuMemberBonusPushExt">
        <id column="PK_ID" property="pkId"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="PK_BONUS" property="pkBonus"/>
        <result column="PK_ORDER" property="pkOrder"/>
        <result column="PK_BONUS_ITEMS" property="pkBonusItems"/>
        <result column="INCOME_STATUS" property="incomeStatus"/>
        <result column="CAL_TYPE" property="calType"/>
        <result column="CAL_ACHIEVE" property="calAchieve"/>
        <result column="CAL_VALUE" property="calValue"/>
        <result column="PRETAX_INCOME" property="pretaxIncome"/>
        <result column="INCOME_TAX" property="incomeTax"/>
        <result column="REAL_INCOME" property="realIncome"/>
        <result column="ROUND" property="round"/>
        <result column="SECOND" property="second"/>
        <result column="REMARK" property="remark"/>
        <result column="INCOME_RATIO" property="incomeRatio"/>
        <result column="INCOME_DIAL_RATIO" property="incomeDialRatio"/>
        <result column="ORDER_DIAL_RATIO" property="orderDialRatio"/>
        <result column="ORDER_CODE" property="orderCode"/>
        <result column="ORDER_TYPE" property="orderType"/>
        <result column="PK_SOURCE_COUNTRY" property="pkSourceCountry"/>
        <result column="SOURCE_COUNTRY_NAME" property="sourceCountryName"/>
        <result column="SOURCE_MEMBER_CODE" property="sourceMemberCode"/>
        <result column="SOURCE_MEMBER_NAME" property="sourceMemberName"/>
        <result column="PK_RATE" property="pkRate"/>
        <result column="ORDER_AMOUNT" property="orderAmount"/>
        <result column="ORDER_ACHIEVE" property="orderAchieve"/>
        <result column="MEMBER_CODE" property="memberCode"/>
        <result column="MEMBER_NAME" property="memberName"/>
        <result column="PK_SETTLE_GRADE" property="pkSettleGrade"/>
        <result column="PK_AWARDS" property="pkAwards"/>
        <result column="VERTEX_NAME" property="vertexName"/>
        <result column="TEAM_NAME" property="teamName"/>
        <result column="TEAM_CODE" property="teamCode"/>
        <result column="SETTLE_DATE" property="settleDate"/>
        <result column="SETTLE_COUNTRY" property="settleCountry"/>
        <result column="PERIOD" property="period"/>
        <result column="OUT_EXCHANGE_RATE" property="outExchangeRate"/>
        <result column="PK_REGISTER_GRADE" property="pkRegisterGrade"/>
        <result column="ORDER_TYPE" property="orderType"/>
        <result column="memberPayTime" property="memberPayTime"/>

        <result column="service_code" property="serviceCode"/>
        <result column="pk_vertex" property="pkVertex"/>
        <result column="nick_name" property="nickName"/>
    </resultMap>

    <insert id="batchInsertCuMemberBonusPush">
        insert ALL
        <foreach item="item" index="index" collection="cuMemberBonusPushList" separator=" ">
            into cu_member_bonus_push(pk_bonus,pk_order,pk_bonus_items,income_status,
            cal_type,cal_achieve,cal_value,pretax_income,
            income_tax,real_income,round,second,remark,
            income_ratio,income_dial_ratio,order_dial_ratio,pk_country,pk_creator)
            values
            (
            #{item.pkBonus},#{item.pkOrder},#{item.pkBonusItems},#{item.incomeStatus},
            #{item.calType},#{item.calAchieve},#{item.calValue},#{item.pretaxIncome},
            #{item.incomeTax},#{item.realIncome},#{item.round},#{item.second},
            #{item.remark},#{item.incomeRatio},#{item.incomeDialRatio},#{item.orderDialRatio},
            #{item.pkCountry},#{item.pkCreator}
            )
        </foreach>
        SELECT 1 FROM dual
    </insert>

    <delete id="deleteCuMemberBonusPush">
        delete
        from CU_MEMBER_BONUS_PUSH
        where PK_BONUS in (
            select pk_id
            from cu_member_bonus
            where period = #{period}
              and grant_status &lt;= 2)
    </delete>

</mapper>
