<?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.member.swing.mapper.CuMemberSwingNetDetailMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="CuMemberSwingNetDetail" type="com.hzs.common.domain.member.swing.ext.CuMemberSwingNetDetailExt">
        <id column="PK_ID" property="pkId"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="PK_SWING_NET" property="pkSwingNet"/>
        <result column="PK_MEMBER" property="pkMember"/>
        <result column="PLACE_DEPT" property="placeDept"/>
        <result column="FIRST_ACHIEVE_RATIO" property="firstAchieveRatio"/>
        <result column="FIRST_REACH_POINT" property="firstReachPoint"/>
        <result column="REPURCHASE_REACH_POINT" property="repurchaseReachPoint"/>
        <result column="REPURCHASE_ACHIEVE_RATIO" property="repurchaseAchieveRatio"/>
        <result column="FIRST_CALCULATE" property="firstCalculate"/>
        <result column="REPURCHASE_CALCULATE" property="repurchaseCalculate"/>
    </resultMap>

    <update id="mergeCuMemberSwingNetDetail">
        merge into CU_MEMBER_SWING_NET_DETAIL a
        using(
        <foreach collection="cuMemberSwingNetDetailVOList" item="item" separator=" union ">
            select #{item.pkId, jdbcType = BIGINT} pk_id,
            #{item.pkSwingNet, jdbcType = BIGINT} pk_swing_net,
            #{item.pkMember} pk_member,
            #{item.placeDept, jdbcType = INTEGER} place_dept,
            #{item.firstAchieveRatio, jdbcType = NUMERIC} first_achieve_ratio,
            #{item.firstReachPoint, jdbcType = INTEGER} first_reach_point,
            #{item.repurchaseAchieveRatio, jdbcType = NUMERIC} repurchase_achieve_ratio,
            #{item.repurchaseReachPoint, jdbcType = INTEGER} repurchase_reach_point,
            #{item.pkCountry, jdbcType = INTEGER} pk_country,
            #{item.pkCreator, jdbcType = NUMERIC} pk_creator,
            #{item.creationTime, jdbcType = TIMESTAMP} creation_time
            from dual
        </foreach>
        ) b
        on (a.pk_id = b.pk_id)
        when matched then
        update set
        a.pk_swing_net = b.pk_swing_net,
        a.pk_member = b.pk_member,
        a.place_dept = b.place_dept,
        a.first_achieve_ratio = b.first_achieve_ratio,
        a.first_reach_point = b.first_reach_point,
        a.repurchase_achieve_ratio = b.repurchase_achieve_ratio,
        a.repurchase_reach_point = b.repurchase_reach_point,
        a.pk_country = b.pk_country,
        a.pk_modified = b.pk_creator,
        a.modified_time = b.creation_time
        WHEN NOT MATCHED THEN
        insert (
        pk_id,
        pk_swing_net,
        pk_member,
        place_dept,
        first_achieve_ratio,
        first_reach_point,
        repurchase_achieve_ratio,
        repurchase_reach_point,
        pk_country,
        pk_creator,
        creation_time
        ) values(
        cu_member_swing_net_detail_seq.nextval,
        b.pk_swing_net,
        b.pk_member,
        b.place_dept,
        b.first_achieve_ratio,
        b.first_reach_point,
        b.repurchase_achieve_ratio,
        b.repurchase_reach_point,
        b.pk_country,
        b.pk_creator,
        b.creation_time
        )
    </update>

</mapper>
