<?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.report.member.mapper.CuMemberAwardsStatMapper">

    <!--    真实业绩新增奖衔查询-->
    <select id="selectCuMemberAwardsList"
            resultType="com.hzs.report.member.vo.CuMemberAwardsStatVO">
        SELECT
        cm.pk_id AS pkMember,
        cm.MEMBER_CODE AS memberCode,
        cm.MEMBER_NAME AS memberName,
        cm.PHONE AS phone,
        aw.PK_TRANSACTION AS pkAwards,
        ver.VERTEX_NAME AS vertexName,
        ct.TEAM_NAME AS teamName,
        cma.CREATION_TIME AS creationTime,
        bc.SHORT_NAME AS shortName,
        bc.NATIONAL_FLAG1 AS nationalFlag1,
        cmat.A_SUM_REAL_PV AS aNewPv,
        cmat.B_SUM_REAL_PV AS bNewPv
        FROM
        CU_MEMBER cm
        LEFT JOIN CU_MEMBER_AWARDS cma ON cm.pk_ID = cma.PK_MEMBER
        LEFT JOIN BD_AWARDS aw ON aw.pk_ID = cm.PK_AWARDS
        LEFT JOIN bd_vertex ver ON cm.pk_vertex = ver.pk_id
        LEFT JOIN cu_member_team ct ON ct.pk_id = cm.pk_team_code
        LEFT JOIN BD_COUNTRY bc ON bc.PK_ID = cm.PK_SETTLE_COUNTRY
        LEFT JOIN ${achieveTableName} cmat ON cma.PK_MEMBER = cmat.PK_MEMBER
        INNER JOIN (
        SELECT PK_MEMBER, MAX(CREATION_TIME) AS CREATION_TIME
        FROM CU_MEMBER_AWARDS
        GROUP BY PK_MEMBER
        ) latestAward ON cm.pk_ID = latestAward.PK_MEMBER AND cma.CREATION_TIME = latestAward.CREATION_TIME
        where cma.DEL_FLAG=0 and
        cm.DEL_FLAG=0 and
        aw.DEL_FLAG=0 and
        bc.DEL_FLAG=0
        <if test="memberCode != null and memberCode !='' ">
            AND cm.MEMBER_CODE like #{memberCode} || '%'
        </if>
        <if test="memberName != null and memberName !='' ">
            AND cm.MEMBER_NAME like #{memberName} || '%'
        </if>
        <if test="phone != null and phone !='' ">
            AND cm.phone like #{phone} || '%'
        </if>
        <if test="pkAwards != null">
            AND cm.PK_AWARDS=#{pkAwards}
        </if>
        <if test="startDate != null and startDate!=''">
            and cma.CREATION_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!=''">
            and cma.CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="pkVertex != null">
            AND cm.pk_vertex=#{pkVertex}
        </if>
        <if test="pkTeamCode != null">
            AND cm.pk_team_code=#{pkTeamCode}
        </if>
        <if test="pkCountry != null">
            AND cm.PK_SETTLE_COUNTRY=#{pkCountry}
        </if>
        ORDER BY cma.CREATION_TIME DESC
    </select>


    <!--    奖衔晋升列表-->
    <select id="awardPromotionList"
            resultType="com.hzs.report.member.vo.AwardPromotionVO">
        SELECT
        cm.pk_id AS pkMember,
        cm.MEMBER_CODE AS memberCode,
        cm.MEMBER_NAME AS memberName,
        aw.PK_TRANSACTION AS pkAwards,
        oaw.PK_TRANSACTION AS oldPkAwards,
        cmsp.SETTLE_DATE AS creationTime
        FROM
        CU_MEMBER cm
        LEFT JOIN CU_MEMBER_AWARDS cma ON cm.pk_ID = cma.PK_MEMBER
        LEFT JOIN BD_AWARDS aw ON aw.pk_ID = cma.NEW_LEVEL
        LEFT JOIN BD_AWARDS oaw ON oaw.pk_ID = cma.OLD_LEVEL
        LEFT JOIN CU_MEMBER_SETTLE_PERIOD cmsp on cmsp.pk_id=cma.PERIOD

        where cma.DEL_FLAG=0
        and cm.DEL_FLAG=0
        and aw.DEL_FLAG=0
        and cm.CATEGORY=0
        <if test="memberCode != null and memberCode !='' ">
            AND cm.MEMBER_CODE like #{memberCode} || '%'
        </if>
        <if test="memberName != null and memberName !='' ">
            AND cm.MEMBER_NAME like #{memberName} || '%'
        </if>

        <if test="pkAwards != null">
            AND cma.NEW_LEVEL=#{pkAwards}
        </if>
        <if test="oldPkAwards != null">
            AND cma.OLD_LEVEL=#{oldPkAwards}
        </if>
        <if test="pkCountry != null">
            AND cm.PK_SETTLE_COUNTRY=#{pkCountry}
        </if>

        <if test="startDate != null and startDate !='' ">
            and cma.CREATION_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate !='' ">
            and cma.CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        ORDER BY cma.CREATION_TIME DESC
    </select>

    <!--    会员业绩数据查询-->
    <select id="memberAchieveList"
            resultType="com.hzs.report.member.vo.MemberAchieveVO">
        SELECT cm.pk_id,
               MEMBER_CODE,
               MEMBER_NAME,
               nvl(push.pushOrderAchieve, 0) pushOrderAchieve,
               (
                   SELECT nvl(sum(so.ORDER_ACHIEVE), 0) resettleAchieve
                   FROM SA_ORDER so
                            INNER JOIN (
                       SELECT a.pk_id
                       FROM (
                                SELECT pk_id,
                                       del_flag,
                                       CUSTOMER_TYPE
                                FROM cu_member
                                WHERE 1 = 1 START
                                WITH pk_place_parent =#{pkMember}
                                    AND place_dept = 1
                                CONNECT BY pk_place_parent = PRIOR pk_id
                            ) a
                       WHERE a.del_flag = 0
                   ) a ON so.pk_member = a.pk_id
                   WHERE so.del_flag = 0
                     AND so.ORDER_STATUS = 1
                     AND pk_country = #{pkCountry}
                     AND so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
                     AND so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
                     AND SO.ORDER_TYPE IN (
                                           1, 2, 24, 25, 20,
                                           3, 26, 22, 14, 12, 18, 19, 7, 28, 13, 27
                       )
               )                             leftResettleAchieve,
               (
                   SELECT nvl(sum(so.ORDER_ACHIEVE), 0) resettleAchieve
                   FROM SA_ORDER so
                            INNER JOIN (
                       SELECT a.pk_id
                       FROM (
                                SELECT pk_id,
                                       del_flag,
                                       CUSTOMER_TYPE
                                FROM cu_member
                                WHERE 1 = 1 START
                                WITH pk_place_parent =#{pkMember}
                                    AND place_dept = 2
                                CONNECT BY pk_place_parent = PRIOR pk_id
                            ) a
                       WHERE a.del_flag = 0
                   ) a ON so.pk_member = a.pk_id
                   WHERE so.del_flag = 0
                     AND so.ORDER_STATUS = 1
                     AND pk_country = #{pkCountry}
                     AND so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
                     AND so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
                     AND SO.ORDER_TYPE IN (
                                           1, 2, 24, 25, 20,
                                           3, 26, 22, 14, 12, 18, 19, 7, 28, 13, 27
                       )
               )                             rightResettleAchieve,
               (
                   SELECT nvl(sum(so.ORDER_ACHIEVE), 0) register_ACHIEVE
                   FROM SA_ORDER so
                   WHERE so.DEL_FLAG = 0
                     AND so.ORDER_STATUS = 1
                     AND so.PK_COUNTRY = #{pkCountry}
                     AND so.ORDER_TYPE = 1
                     AND so.PK_CREATOR = #{pkMember}
                     AND so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
                     AND so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
               )                             registerAchieve,
               (
                   SELECT nvl(sum(so.ORDER_ACHIEVE), 0) direct_ACHIEVE
                   FROM CU_MEMBER cm
                            INNER JOIN SA_ORDER so ON so.PK_MEMBER = cm.pk_id
                   WHERE cm.DEL_FLAG = 0
                     AND cm.CATEGORY = 0
                     AND so.DEL_FLAG = 0
                     AND so.ORDER_STATUS = 1
                     AND so.PK_COUNTRY = #{pkCountry}
                     AND PK_PARENT = #{pkMember}
                     AND so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
                     AND so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
               )                             directAchieve,
               (
                   SELECT nvl(sum(so.ORDER_ACHIEVE), 0) reply_ACHIEVE
                   FROM SA_ORDER so
                   WHERE so.DEL_FLAG = 0
                     AND so.ORDER_STATUS = 1
                     AND so.PK_COUNTRY = #{pkCountry}
                     AND so.ORDER_TYPE IN (3, 26, 22, 14, 12, 18, 19, 7, 28, 13, 27)
                     AND so.PK_CREATOR = #{pkMember}
                     AND so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
                     AND so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
               )                             replyAchieve,
               (
                   SELECT nvl(sum(a.TRADE_ACHIEVE), 0) tradeAchieve
                   FROM CU_MEMBER_ASSESS_DETAIL a
                   WHERE a.DEL_FLAG = 0
                     AND a.PK_MEMBER = #{pkMember}
                     AND a.PK_COUNTRY = #{pkCountry}
                     AND a.CHANGE_TYPE = 1
                     AND a.TRADE_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
                     AND a.TRADE_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
               )                             tradeAchieve,
               (
                   SELECT nvl(sum(cb.REAL_INCOME_TOTAL), 0) realIncomeTotal
                   FROM cu_member_bonus cb
                            INNER JOIN cu_member cm ON cb.pk_member = cm.pk_id
                            INNER JOIN cu_member_settle_period cp ON cb.period = cp.pk_id
                   WHERE cb.del_flag = 0
                     AND cm.del_flag = 0
                     AND cp.del_flag = 0
                     AND cm.pk_settle_country = #{pkCountry}
                     AND cb.pk_member = #{pkMember}
                     AND cp.settle_date >= to_date(#{startDate}, 'yyyy-mm-dd')
                     AND cp.settle_date &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
               )                             realIncomeTotal
        FROM CU_MEMBER cm
                 LEFT JOIN (
            SELECT #{pkMember}                   pkmember,
                   nvl(sum(so.ORDER_ACHIEVE), 0) pushOrderAchieve,
                   nvl(sum(so.ORDER_AMOUNT), 0)  pushOrderAmount
            FROM SA_ORDER so
            WHERE so.DEL_FLAG = 0
              AND so.ORDER_STATUS = 1
              AND so.PK_COUNTRY = #{pkCountry}
              AND so.pk_member IN (
                SELECT cm.pk_id
                FROM cu_member cm
                WHERE cm.del_flag = 0
            START WITH cm.pk_parent =#{pkMember}
            CONNECT BY cm.pk_parent = PRIOR cm.pk_id
        )
            AND so.ORDER_TYPE IN (
        1,2,24,25,20,
        3,26,22,14,12,18,19,7,28,13,27
        )
        AND so.PAY_TIME >= to_date( #{startDate}
           , 'yyyy-mm-dd' )
            AND so.PAY_TIME &lt;= to_date( #{endDate} || ' 23:59:59'
           , 'yyyy-mm-dd hh24:mi:ss' )
            ) push
        ON push.pkmember = cm.pk_id
        WHERE
            cm.DEL_FLAG = 0
          AND cm.CATEGORY = 0
          AND cm.pk_id =#{pkMember}
    </select>

    <!--    真实奖衔分析-->
    <select id="selectCuMemberAwardsAnalysisList"
            resultType="com.hzs.report.member.vo.CuMemberAwardsAnalysisVO">

        SELECT PKMEMBER,
        PERIOD,
        UPTYPE,
        pkRangeAwards,
        MEMBERCODE,
        MEMBERNAME,
        PHONE,
        PKAWARDS,
        PKREGISTERGRADE,
        VERTEXNAME,
        CREATIONTIME,
        endValidityDate
        FROM (
        SELECT CM.PK_ID AS PKMEMBER,
        CMA.PERIOD,
        CMA.UP_TYPE AS UPTYPE,
        CM.MEMBER_CODE AS MEMBERCODE,
        CM.MEMBER_NAME AS MEMBERNAME,
        CM.PHONE,
        AW.PK_TRANSACTION AS PKAWARDS,
        AWW.PK_TRANSACTION AS pkRangeAwards,
        BG.PK_TRANSACTION AS PKREGISTERGRADE,
        VER.VERTEX_NAME AS VERTEXNAME,
        CMA.CREATION_TIME AS CREATIONTIME,
        CMA.END_VALIDITY_DATE AS endValidityDate,
        ROW_NUMBER() OVER (PARTITION BY CM.MEMBER_CODE ORDER BY CMA.NEW_LEVEL DESC) AS rn
        FROM CU_MEMBER CM
        LEFT JOIN CU_MEMBER_AWARDS CMA
        ON CM.PK_ID = CMA.PK_MEMBER AND CMA.AWARD_TYPE = 2
        LEFT JOIN CU_MEMBER_AWARDS cmas
        ON CM.PK_ID = cmas.PK_MEMBER AND cmas.AWARD_TYPE = 1
        left join CU_MEMBER_SETTLE_PERIOD cmsp on cmsp.pk_id=CMA.PERIOD
        LEFT JOIN BD_AWARDS AW
        ON AW.PK_ID = cmas.NEW_LEVEL
        LEFT JOIN BD_AWARDS AWW
        ON AWW.PK_ID = CMA.NEW_LEVEL
        LEFT JOIN BD_GRADE BG
        ON BG.PK_ID = CM.PK_REGISTER_GRADE
        LEFT JOIN BD_VERTEX VER
        ON CM.PK_VERTEX = VER.PK_ID
        WHERE CMA.DEL_FLAG = 0
        AND CM.DEL_FLAG = 0
        AND AW.DEL_FLAG = 0
        AND BG.DEL_FLAG = 0
        AND cm.PK_SETTLE_COUNTRY=#{pkCountry}
        <if test="memberCode != null and memberCode !='' ">
            AND cm.MEMBER_CODE like #{memberCode} || '%'
        </if>
        <if test="upType != null">
            AND cma.UP_TYPE=#{upType}
        </if>
        <if test="memberName != null and memberName !='' ">
            AND cm.MEMBER_NAME like #{memberName} || '%'
        </if>
        <if test="phone != null and phone !='' ">
            AND cm.phone like #{phone} || '%'
        </if>
        <if test="pkAwards != null">
            AND AW.PK_ID=#{pkAwards}
        </if>
        <if test="pkRangeAwards != null">
            AND AWW.PK_ID=#{pkRangeAwards}
        </if>
        <if test="startDate != null and startDate!='' ">
            and cmsp.SETTLE_DATE &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and cmsp.SETTLE_DATE &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="startEffectiveDate != null and startEffectiveDate!='' ">
            and CMA.END_VALIDITY_DATE &gt;= to_date(#{startEffectiveDate}, 'yyyy-mm-dd')
        </if>
        <if test="endEffectiveDate != null and endEffectiveDate!='' ">
            and CMA.END_VALIDITY_DATE &lt;= to_date(#{endEffectiveDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="pkVertex != null">
            AND cm.pk_vertex=#{pkVertex}
        </if>
        <if test="pkTeamCode != null">
            AND cm.pk_team_code=#{pkTeamCode}
        </if>
        <if test="pkRegisterGrade != null">
            AND cm.PK_REGISTER_GRADE=#{pkRegisterGrade}
        </if>
        ) t
        WHERE rn = 1
        ORDER BY CREATIONTIME DESC
    </select>

<!--     查询会员结算等级升级记录-->
    <select id="querMemberGradeRecordList"
            resultType="com.hzs.report.member.vo.CuMemberGradeRecordVO">
      select * from (
        SELECT
        CM.PK_ID AS PKMEMBER,
        CML.UP_TYPE AS UPTYPE,
        CM.MEMBER_CODE AS MEMBERCODE,
        CM.MEMBER_NAME AS MEMBERNAME,
        CM.PHONE,
        olga.PK_TRANSACTION AS OLDLEVEL,
        nega.PK_TRANSACTION AS NEWLEVEL,
        VER.VERTEX_NAME AS VERTEXNAME,
        cmt.team_name AS teamName,
        CML.UPGRADE_TIME AS CREATIONTIME,
        so.ORDER_CODE orderCode
        FROM CU_MEMBER CM
        LEFT JOIN CU_MEMBER_LEVEL CML
        ON CM.PK_ID = CML.PK_MEMBER
        LEFT JOIN sa_order so
        ON so.PK_ID = CML.PK_ORDER and so.del_flag=0
        LEFT JOIN BD_GRADE olga
        ON olga.PK_ID = CML.OLD_LEVEL AND olga.DEL_FLAG = 0
        LEFT JOIN BD_GRADE nega
        ON nega.PK_ID = CML.NEW_LEVEL AND nega.DEL_FLAG = 0
        LEFT JOIN BD_VERTEX VER
        ON CM.PK_VERTEX = VER.PK_ID AND ver.del_flag=0
        LEFT JOIN CU_MEMBER_TEAM cmt
        ON cm.pk_team_code=cmt.pk_id AND cmt.del_flag=0
        WHERE CML.DEL_FLAG = 0
        AND CM.DEL_FLAG = 0
        AND cm.PK_SETTLE_COUNTRY=#{pkCountry}
        AND cm.system_Type=#{systemType}
        <if test="memberCode != null and memberCode !='' ">
            AND cm.MEMBER_CODE like #{memberCode} || '%'
        </if>
        <if test="upType != null">
            AND CML.UP_TYPE=#{upType}
        </if>
        <if test="memberName != null and memberName !='' ">
            AND cm.MEMBER_NAME like #{memberName} || '%'
        </if>
        <if test="phone != null and phone !='' ">
            AND cm.phone like #{phone} || '%'
        </if>
        <if test="startDate != null and startDate!='' ">
            and CML.CREATION_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and CML.CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="pkVertex != null">
            AND cm.pk_vertex=#{pkVertex}
        </if>
        <if test="pkTeamCode != null">
            AND cm.pk_team_code=#{pkTeamCode}
        </if>
        <if test="pkRegisterGrade != null">
            AND cm.PK_REGISTER_GRADE=#{pkRegisterGrade}
        </if>
        UNION
        SELECT
        CM.PK_ID AS PKMEMBER,
        CMG.UP_TYPE AS UPTYPE,
        CM.MEMBER_CODE AS MEMBERCODE,
        CM.MEMBER_NAME AS MEMBERNAME,
        CM.PHONE,
        olga.PK_TRANSACTION AS OLDLEVEL,
        nega.PK_TRANSACTION AS NEWLEVEL,
        VER.VERTEX_NAME AS VERTEXNAME,
        cmt.team_name AS teamName,
        CMG.CREATION_TIME AS CREATIONTIME,
        '' orderCode
        FROM CU_MEMBER CM
        LEFT JOIN CU_MEMBER_GRADE CMG
        ON CM.PK_ID = CMG.PK_MEMBER
        LEFT JOIN BD_GRADE olga
        ON olga.PK_ID = CMG.OLD_LEVEL AND olga.DEL_FLAG = 0
        LEFT JOIN BD_GRADE nega
        ON nega.PK_ID = CMG.NEW_LEVEL AND nega.DEL_FLAG = 0
        LEFT JOIN BD_VERTEX VER
        ON CM.PK_VERTEX = VER.PK_ID AND ver.del_flag=0
        LEFT JOIN CU_MEMBER_TEAM cmt
        ON cm.pk_team_code=cmt.pk_id AND cmt.del_flag=0
        WHERE CMG.DEL_FLAG = 0
        AND CM.DEL_FLAG = 0
        AND cm.PK_SETTLE_COUNTRY=#{pkCountry}
        AND cm.system_Type=#{systemType}
        <if test="memberCode != null and memberCode !='' ">
            AND cm.MEMBER_CODE like #{memberCode} || '%'
        </if>
        <if test="upType != null">
            AND CMG.UP_TYPE=#{upType}
        </if>
        <if test="memberName != null and memberName !='' ">
            AND cm.MEMBER_NAME like #{memberName} || '%'
        </if>
        <if test="phone != null and phone !='' ">
            AND cm.phone like #{phone} || '%'
        </if>
        <if test="startDate != null and startDate!='' ">
            and CMG.CREATION_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and CMG.CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="pkVertex != null">
            AND cm.pk_vertex=#{pkVertex}
        </if>
        <if test="pkTeamCode != null">
            AND cm.pk_team_code=#{pkTeamCode}
        </if>
        <if test="pkRegisterGrade != null">
            AND cm.PK_REGISTER_GRADE=#{pkRegisterGrade}
        </if>

        )
        ORDER BY CREATIONTIME DESC
    </select>

    <!--     查询奖衔分析会员业绩-->
    <select id="selectAwardsAnalysisList"
            resultType="com.hzs.report.member.vo.CuMemberAwardsAnalysisVO">
        <foreach collection="list" item="item" separator="UNION">
            select
            cma.period,
            cmat.PK_MEMBER pkMember,
            cmat.A_SUM_REAL_PV aSumRealPv,
            cmat.B_SUM_REAL_PV bSumRealPv,
            cmat.A_SUM_PV aSumPv,
            cmat.B_SUM_PV bSumPv,
            cmat.REP_A_SUM_PV repASumPv,
            cmat.REP_B_SUM_PV repBSumPv
            FROM CU_MEMBER_AWARDS cma
            left join ${item.achieveTableName} cmat on cma.PK_MEMBER=cmat.PK_MEMBER
            where cma.DEL_FLAG=0
            and cma.PK_MEMBER=#{item.pkMember}
            and cma.period=#{item.period}
        </foreach>

    </select>

    <!--     真实奖衔分析详情（穿透页面接口）-->
    <select id="selectCuMemberAwardsAnalysisDetailsList"
            resultType="com.hzs.report.member.vo.CuMemberAwardsAnalysisVO">
        select
        cm.pk_id pkMember,
        cma.period,
        cm.MEMBER_CODE memberCode,
        cm.MEMBER_NAME memberName,
        cm.PHONE phone,
        aw.PK_TRANSACTION as pkAwards,
        bg.PK_TRANSACTION as pkRegisterGrade,
        ver.VERTEX_NAME as vertexName,
        ct.TEAM_NAME as teamName,
        cma.CREATION_TIME creationTime,
        bc.SHORT_NAME shortName,
        bc.NATIONAL_FLAG1 nationalFlag1,
        cmat.A_SUM_REAL_PV aSumRealPv,
        cmat.B_SUM_REAL_PV bSumRealPv,
        cmat.A_SUM_PV aSumPv,
        cmat.B_SUM_PV bSumPv,
        cmat.REP_A_SUM_PV repASumPv,
        cmat.REP_B_SUM_PV repBSumPv
        FROM CU_MEMBER_AWARDS cma
        LEFT JOIN CU_MEMBER cm on cm.pk_ID=cma.PK_MEMBER
        LEFT JOIN BD_AWARDS aw on aw.pk_ID=cm.PK_AWARDS
        LEFT JOIN BD_GRADE bg on bg.pk_id=cm.PK_REGISTER_GRADE
        left join bd_vertex ver on cm.pk_vertex = ver.pk_id
        LEFT JOIN cu_member_team ct ON ct.pk_id = cm.pk_team_code
        LEFT JOIN BD_COUNTRY bc on bc.PK_ID=cm.PK_SETTLE_COUNTRY
        left join ${achieveTableName} cmat on cma.PK_MEMBER=cmat.PK_MEMBER
        where cma.DEL_FLAG=0 and
        cm.DEL_FLAG=0 and
        aw.DEL_FLAG=0 and
        bc.DEL_FLAG=0 and
        bg.DEL_FLAG=0
        <if test="pkMember != null and placeDept !=null ">
            AND cm.pk_id in (
            SELECT pk_id FROM cu_member
            start with pk_place_parent =#{pkMember} and place_dept =#{placeDept}
            CONNECT BY pk_place_parent = PRIOR pk_id
            )
        </if>
        <if test="memberCode != null and memberCode !='' ">
            AND cm.MEMBER_CODE like #{memberCode} || '%'
        </if>
        <if test="memberName != null and memberName !='' ">
            AND cm.MEMBER_NAME like #{memberName} || '%'
        </if>
        <if test="phone != null and phone !='' ">
            AND cm.phone like #{phone} || '%'
        </if>
        <if test="pkAwards != null">
            AND cm.PK_AWARDS=#{pkAwards}
        </if>
        <if test="startDate != null and startDate!='' ">
            and cma.CREATION_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and cma.CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="pkVertex != null">
            AND cm.pk_vertex=#{pkVertex}
        </if>
        <if test="pkTeamCode != null">
            AND cm.pk_team_code=#{pkTeamCode}
        </if>
        <if test="pkGrade != null">
            AND cm.PK_REGISTER_GRADE=#{pkGrade}
        </if>
        ORDER BY aw.AWARDS_VALUE DESC
    </select>

    <!--    收入明细-->
    <select id="selectRevenueDetailsList"
            resultType="com.hzs.report.member.vo.RevenueDetailsVO">
        SELECT
        LPAD(row_number() over (ORDER BY realIncomeTotal DESC), 6, '0') AS rowNumber,
        purRealSubtotal,
        repurRealSubtotal,
        realIncomeTotal,
        pkMember,
        memberCode,
        memberName,
        phone,
        pkAwards,
        pkRegisterGrade,
        vertexName,
        teamName
        FROM (
        SELECT
        sum(cmb.PUR_REAL_SUBTOTAL+cmb.MAKER_REAL_SUBTOTAL) AS purRealSubtotal,
        sum(cmb.REPUR_REAL_SUBTOTAL) AS repurRealSubtotal,
        sum(cmb.REAL_INCOME_TOTAL) AS realIncomeTotal,
        cm.pk_id AS pkMember,
        cm.MEMBER_CODE AS memberCode,
        cm.MEMBER_NAME AS memberName,
        cm.PHONE AS phone,
        aw.PK_TRANSACTION AS pkAwards,
        bg.PK_TRANSACTION AS pkRegisterGrade,
        ver.VERTEX_NAME AS vertexName,
        ct.TEAM_NAME AS teamName
        FROM
        CU_MEMBER_BONUS cmb
        inner join cu_member_settle_period cmsp on cmb.PERIOD=cmsp.PK_ID
        LEFT JOIN CU_MEMBER cm ON cm.pk_ID = cmb.PK_MEMBER
        LEFT JOIN BD_AWARDS aw ON aw.pk_ID = cm.PK_AWARDS
        LEFT JOIN BD_GRADE bg ON bg.pk_id = cm.PK_REGISTER_GRADE
        LEFT JOIN bd_vertex ver ON cm.pk_vertex = ver.pk_id
        LEFT JOIN cu_member_team ct ON ct.pk_id = cm.pk_team_code
        WHERE
        cmb.DEL_FLAG = 0
        AND cm.DEL_FLAG = 0
        AND aw.DEL_FLAG = 0
        AND bg.DEL_FLAG = 0
        AND cmb.GRANT_STATUS >=2
        and cmb.INCOME_STATUS=0
        and cmb.pk_Country=#{pkCountry}
        and cm.PK_SETTLE_COUNTRY=#{pkCountry}
        <if test="memberCode != null and memberCode !='' ">
            AND cm.MEMBER_CODE like #{memberCode} || '%'
        </if>
        <if test="memberName != null and memberName !='' ">
            AND cm.MEMBER_NAME like #{memberName} || '%'
        </if>
        <if test="phone != null and phone !='' ">
            AND cm.phone like #{phone} || '%'
        </if>
        <if test="pkAwards != null">
            AND cm.PK_AWARDS=#{pkAwards}
        </if>
        <if test="pkRegisterGrade != null">
            AND cm.PK_REGISTER_GRADE=#{pkRegisterGrade}
        </if>
        <if test="pkVertex != null">
            AND cm.pk_vertex=#{pkVertex}
        </if>
        <if test="pkTeamCode != null">
            AND cm.pk_team_code=#{pkTeamCode}
        </if>
        <if test="startDate != null and startDate!='' ">
            and cmsp.settle_date &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and cmsp.settle_date &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        GROUP BY
        cm.pk_id,
        cm.MEMBER_CODE,
        cm.MEMBER_NAME,
        cm.PHONE,
        aw.PK_TRANSACTION,
        bg.PK_TRANSACTION,
        ver.VERTEX_NAME,
        ct.TEAM_NAME
        )
        ORDER BY realIncomeTotal DESC
    </select>

    <!--      复购bv统计 -->
    <select id="selectRepurchasePVStatList"
            resultType="com.hzs.report.member.vo.RepurchasePVStatVO">
        select
        cm.MEMBER_CODE memberCode,
        cm.MEMBER_NAME memberName,
        cm.PHONE phone,
        ver.VERTEX_NAME as vertexName,
        ct.TEAM_NAME as teamName,
        aw.PK_TRANSACTION as pkAwards,
        cma.REPURCHASE_NEW_PV repurchaseNewPv,
        (cma.REP_A_SUM_PV+cma.REP_B_SUM_PV) as historyPv ,
        cmas.ASSESS_TARGET assessTarget,
        cmas.MONTH_SURPLUS monthSurplus,
        cmas.ASSESS_STATUS assessStatus,
        cmas.IS_EXAMINE isExamine,
        cmas.CREATION_TIME creationTime
        from ${achieveTableName} cma
        LEFT JOIN CU_MEMBER cm on cma.PK_MEMBER=cm.pk_id
        LEFT JOIN BD_AWARDS aw on aw.pk_ID=cm.PK_AWARDS
        left join bd_vertex ver on cm.pk_vertex = ver.pk_id
        LEFT JOIN cu_member_team ct ON ct.pk_id = cm.pk_team_code
        LEFT JOIN ${assessTableName} cmas on cma.PK_MEMBER=cmas.PK_MEMBER
        where
        cm.DEL_FLAG=0
        AND cmas.DEL_FLAG = 0 and cmas.ASSESS_TYPE=0
        and cm.PK_SETTLE_COUNTRY=#{pkCountry}
        <if test="pkMember != null ">
            AND cm.pk_id =#{pkMember}
        </if>
        <if test="memberCode != null and memberCode !='' ">
            AND cm.MEMBER_CODE like #{memberCode} || '%'
        </if>
        <if test="memberName != null and memberName !='' ">
            AND cm.MEMBER_NAME like #{memberName} || '%'
        </if>
        <if test="phone != null and phone !='' ">
            AND cm.phone like #{phone} || '%'
        </if>

        <if test="pkVertex != null">
            AND cm.pk_vertex=#{pkVertex}
        </if>
        <if test="pkTeamCode != null">
            AND cm.pk_team_code=#{pkTeamCode}
        </if>
        <if test="period != null">
            AND cma.PERIOD=#{period}
        </if>
        <if test="period != null">
            AND cmas.PERIOD=#{period}
        </if>

        <if test="pkAwards != null">
            AND cm.PK_AWARDS=#{pkAwards}
        </if>
        <if test="assessStatus != null">
            AND cmas.ASSESS_STATUS=#{assessStatus}
        </if>
        <if test="isExamine != null">
            AND cmas.IS_EXAMINE=#{isExamine}
        </if>
        <if test="startDate != null and startDate!='' ">
            and cmas.CREATION_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and cmas.CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>

        ORDER BY cmas.CREATION_TIME DESC
    </select>

    <!--     商城BV统计-->
    <select id="selectMallPVStatList"
            resultType="com.hzs.report.member.vo.MallPVStatVO">
        select
        cm.MEMBER_CODE memberCode,
        cm.MEMBER_NAME memberName,
        cm.PHONE phone,
        ver.VERTEX_NAME as vertexName,
        ct.TEAM_NAME as teamName,
        aw.PK_TRANSACTION as pkAwards,
        cma.MALL_NEW_PV mallNewPv,
        cma.MALL_PV as historyPv ,
        cmas.ASSESS_TARGET assessTarget,
        cmas.MONTH_SURPLUS monthSurplus,
        cmas.ASSESS_STATUS assessStatus,
        cmas.IS_EXAMINE isExamine,
        cmas.CREATION_TIME creationTime
        from ${achieveTableName} cma
        LEFT JOIN CU_MEMBER cm on cma.PK_MEMBER=cm.pk_id
        LEFT JOIN BD_AWARDS aw on aw.pk_ID=cm.PK_AWARDS
        left join bd_vertex ver on cm.pk_vertex = ver.pk_id
        LEFT JOIN cu_member_team ct ON ct.pk_id = cm.pk_team_code
        LEFT JOIN ${assessTableName} cmas on cma.PK_MEMBER=cmas.PK_MEMBER
        where
        cm.DEL_FLAG=0
        AND cmas.DEL_FLAG = 0 and cmas.ASSESS_TYPE=1
        and cm.PK_SETTLE_COUNTRY=#{pkCountry}
        <if test="pkMember != null ">
            AND cm.pk_id =#{pkMember}
        </if>
        <if test="memberCode != null and memberCode !='' ">
            AND cm.MEMBER_CODE like #{memberCode} || '%'
        </if>
        <if test="memberName != null and memberName !='' ">
            AND cm.MEMBER_NAME like #{memberName} || '%'
        </if>
        <if test="phone != null and phone !='' ">
            AND cm.phone like #{phone} || '%'
        </if>

        <if test="pkVertex != null">
            AND cm.pk_vertex=#{pkVertex}
        </if>
        <if test="pkTeamCode != null">
            AND cm.pk_team_code=#{pkTeamCode}
        </if>
        <if test="period != null">
            AND cma.PERIOD=#{period}
        </if>

        <if test="pkAwards != null">
            AND cm.PK_AWARDS=#{pkAwards}
        </if>
        <if test="assessStatus != null">
            AND cmas.ASSESS_STATUS=#{assessStatus}
        </if>
        <if test="isExamine != null">
            AND cmas.IS_EXAMINE=#{isExamine}
        </if>
        <if test="startDate != null and startDate!='' ">
            and cmas.CREATION_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and cmas.CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        ORDER BY cmas.CREATION_TIME DESC
    </select>

    <!--     查询个人统计-->
    <select id="selectPersonStatList"
            resultType="com.hzs.report.member.vo.PersonStatVO">
        select
        cm.pk_id pkMember,
        cm.MEMBER_CODE memberCode,
        cm.MEMBER_NAME memberName,
        cm.PHONE phone,
        aw.PK_TRANSACTION as pkAwards,
        ver.VERTEX_NAME as vertexName,
        ct.TEAM_NAME as teamName,
        bg.PK_TRANSACTION as pkRegisterGrade
        FROM CU_MEMBER cm
        LEFT JOIN BD_AWARDS aw on aw.pk_ID=cm.PK_AWARDS
        left join bd_vertex ver on cm.pk_vertex = ver.pk_id
        LEFT JOIN cu_member_team ct ON ct.pk_id = cm.pk_team_code
        LEFT JOIN BD_GRADE bg on bg.pk_id=cm.PK_REGISTER_GRADE
        where
        cm.DEL_FLAG=0 and
        aw.DEL_FLAG=0 and
        bg.DEL_FLAG=0
        <if test="memberCode != null and memberCode !='' ">
            AND cm.MEMBER_CODE like #{memberCode} || '%'
        </if>
        <if test="memberName != null and memberName !='' ">
            AND cm.MEMBER_NAME like #{memberName} || '%'
        </if>
        <if test="phone != null and phone !='' ">
            AND cm.phone like #{phone} || '%'
        </if>
        <if test="pkAwards != null">
            AND cm.PK_AWARDS=#{pkAwards}
        </if>
        <if test="startDate != null and startDate!='' ">
            and cm.CREATION_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and cm.CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="pkVertex != null">
            AND cm.pk_vertex=#{pkVertex}
        </if>
        <if test="pkTeamCode != null">
            AND cm.pk_team_code=#{pkTeamCode}
        </if>
        <if test="pkCountry != null">
            AND cm.PK_SETTLE_COUNTRY=#{pkCountry}
        </if>
        <if test="pkRegisterGrade != null">
            AND cm.PK_REGISTER_GRADE=#{pkRegisterGrade}
        </if>
        ORDER BY cm.CREATION_TIME DESC
    </select>

    <!--    个人统计业绩查询-->
    <select id="selectPersonPvList"
            resultType="com.hzs.report.member.vo.PersonStatVO">
        <foreach collection="perList" item="item" separator="UNION">
            select
            REGISTER_PV registerPv,
            UPGRADE_PV upgradePv,
            REPURCHASE_PV repurchasePv,
            HI_FUN_PV hiFunPv,
            MALL_PV mallPv,
            period,
            PK_MEMBER pkMember
            from ${item.achieveTableName}
            <where>
                <if test="item.period!= null">
                    PERIOD =#{item.period}
                </if>
                <if test="item.pkMemberList != null and item.pkMemberList.size >0">
                    and PK_MEMBER in
                    <foreach collection="item.pkMemberList" item="pkMember" open="(" separator="," close=")">
                        #{pkMember}
                    </foreach>
                </if>
            </where>
        </foreach>
    </select>

    <!--     直推统计-->
    <select id="selectDirectPushStatList" resultType="com.hzs.report.member.vo.DirectPushVO">
        SELECT
        #{orderType} orderType,
        cm.PK_ID pkMember,
        cm.member_code memberCode,
        cm.member_name memberName,
        cm.phone,
        gr.PK_TRANSACTION AS pkRegisterGrade,
        awa.PK_TRANSACTION AS pkAwards,
        par.member_code parMemberCode,
        par.member_name parMemberName,

        cm.CREATION_TIME creationTime,
        ver.VERTEX_NAME AS vertexName,
        so.ORDER_ACHIEVE* #{rate} orderAchieve,
        subq.orderAchieve orderAchieveTotal
        FROM
        cu_member cm
        LEFT JOIN bd_vertex ver ON cm.pk_vertex = ver.pk_id and ver.del_flag = 0
        inner JOIN ( select * from (
        SELECT
        sum(so.ORDER_ACHIEVE * #{rate}) orderAchieve,
        so.PK_REFERENCE pkMember
        FROM
        SA_ORDER so
        WHERE
        so.DEL_FLAG = 0
        AND so.order_status = 1
        <if test="pkCountry != null">
            and so.pk_Country=#{pkCountry}
        </if>
        <if test="orderTypeList != null">
            and so.ORDER_TYPE in
            <foreach collection="orderTypeList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="startDate != null and startDate!='' ">
            and so.PAY_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        GROUP BY
        so.PK_REFERENCE
        ) where 1=1
        <if test="orderAchieve != null">
            and orderAchieve &gt;=#{orderAchieve}
        </if>

        ) subq ON cm.PK_PARENT = subq.pkMember
        INNER JOIN cu_member par ON par.pk_id = cm.pk_parent
        LEFT JOIN bd_awards awa ON awa.pk_id = cm.PK_AWARDS
        LEFT JOIN bd_grade gr ON gr.pk_id = cm.PK_REGISTER_GRADE
        LEFT JOIN SA_ORDER so ON so.PK_MEMBER = cm.PK_ID
        and so.DEL_FLAG = 0 and so.ORDER_STATUS=1
        <if test="orderTypeList != null">
            and so.ORDER_TYPE in
            <foreach collection="orderTypeList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        where cm.del_flag = 0  and par.del_flag = 0
        and awa.del_flag = 0 and gr.del_flag = 0 and so.DEL_FLAG = 0 and cm.PK_SETTLE_COUNTRY=#{pkCountry}

        <if test="startDate != null and startDate!='' ">
            and so.PAY_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="pkCountry != null">
            and so.pk_Country=#{pkCountry}
        </if>

        <if test="pkRegisterGrade != null">
            and cm.PK_REGISTER_GRADE =#{pkRegisterGrade}
        </if>
        <if test="pkAwards != null">
            and cm.PK_AWARDS =#{pkAwards}
        </if>
        <if test="pkTeamCode != null">
            and cm.pk_team_code =#{pkTeamCode}
        </if>
        <if test="pkVertex != null">
            and cm.pk_vertex =#{pkVertex}
        </if>
        <if test="memberName != null and memberName!=''">
            and cm.member_name like #{memberName} || '%'
        </if>
        <if test="parMemberCode != null and parMemberCode!=''">
            and par.member_code like #{parMemberCode} || '%'
        </if>
        <if test="parMemberName != null and parMemberName!=''">
            and par.member_name like #{parMemberName} || '%'
        </if>

        <if test="phone != null and phone!=''">
            and cm.phone like #{phone} || '%'
        </if>
        ORDER BY subq.orderAchieve DESC,cm.PK_PARENT DESC
    </select>
    <!--    主推统计 三方-->
    <select id="selectThreeDirectPushStatList" resultType="com.hzs.report.member.vo.DirectPushVO">
        SELECT
        #{orderType} orderType,
        cm.PK_ID pkMember,
        cm.member_code memberCode,
        cm.member_name memberName,
        cm.phone,
        gr.PK_TRANSACTION AS pkRegisterGrade,
        awa.PK_TRANSACTION AS pkAwards,
        par.member_code parMemberCode,
        par.member_name parMemberName,
        place.member_code placeMemberCode,
        place.member_name placeMemberName,
        cm.CREATION_TIME creationTime,
        ver.VERTEX_NAME AS vertexName,
        ct.TEAM_NAME AS teamName,
        subq.orderAchieve
        FROM
        cu_member cm
        LEFT JOIN bd_vertex ver ON cm.pk_vertex = ver.pk_id
        LEFT JOIN cu_member_team ct ON ct.pk_id = cm.pk_team_code
        inner JOIN ( select * from (
        SELECT
        sum(so.ORDER_ACHIEVE * #{rate}) orderAchieve,
        so.PK_REFERENCE pkMember
        FROM
        SA_T_ORDER so
        WHERE
        so.DEL_FLAG = 0
        AND so.order_status = 1
        <if test="pkCountry != null">
            and so.pk_Country=#{pkCountry}
        </if>
        <if test="orderTypeList != null">
            and so.ORDER_TYPE in
            <foreach collection="orderTypeList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="startDate != null and startDate!='' ">
            and so.PAY_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        GROUP BY
        so.PK_REFERENCE
        )
        ) subq ON cm.PK_PARENT = subq.pkMember
        INNER JOIN cu_member par ON par.pk_id = cm.pk_parent
        INNER JOIN cu_member place ON place.pk_id = cm.pk_place_parent
        LEFT JOIN bd_awards awa ON awa.pk_id = cm.PK_AWARDS
        LEFT JOIN bd_grade gr ON gr.pk_id = cm.PK_REGISTER_GRADE
        LEFT JOIN SA_T_ORDER so ON so.PK_MEMBER = cm.PK_ID
        and so.DEL_FLAG = 0 and so.ORDER_STATUS=1
        <if test="orderTypeList != null">
            and so.ORDER_TYPE in
            <foreach collection="orderTypeList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        where cm.del_flag = 0 and ver.del_flag = 0 and par.del_flag = 0 and place.del_flag = 0
        and awa.del_flag = 0 and gr.del_flag = 0 and so.DEL_FLAG = 0 and cm.PK_SETTLE_COUNTRY=#{pkCountry}

        <if test="startDate != null and startDate!='' ">
            and so.PAY_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="pkCountry != null">
            and so.pk_Country=#{pkCountry}
        </if>

        <if test="pkRegisterGrade != null">
            and cm.PK_REGISTER_GRADE =#{pkRegisterGrade}
        </if>
        <if test="pkAwards != null">
            and cm.PK_AWARDS =#{pkAwards}
        </if>
        <if test="pkTeamCode != null">
            and cm.pk_team_code =#{pkTeamCode}
        </if>
        <if test="pkVertex != null">
            and cm.pk_vertex =#{pkVertex}
        </if>
        <if test="memberName != null and memberName!=''">
            and cm.member_name like #{memberName} || '%'
        </if>
        <if test="parMemberCode != null and parMemberCode!=''">
            and par.member_code like #{parMemberCode} || '%'
        </if>
        <if test="parMemberName != null and parMemberName!=''">
            and par.member_name like #{parMemberName} || '%'
        </if>

        <if test="phone != null and phone!=''">
            and cm.phone like #{phone} || '%'
        </if>
        <if test="orderAchieve != null">
            and subq.orderAchieve &gt;=#{orderAchieve}
        </if>
        ORDER BY subq.orderAchieve DESC
    </select>


    <!--    直推数据列表-->
    <select id="selectDirectPushDataList" resultType="com.hzs.report.member.vo.DirectPushDataVO">
        select
        cm.pk_id pkMember,
        cm.MEMBER_CODE memberCode,
        cm.MEMBER_NAME memberName,
        nvl(cmcon.dpNumber,0) dpNumber,
        nvl((so.ORDER_ACHIEVE * #{dpdVO.rate}),0) orderAchieve,
        ver.VERTEX_NAME AS vertexName,
        ct.TEAM_NAME AS teamName,
        cma.PK_PROVINCE pkProvince,
        cma.PK_CITY pkCity,
        cma.PK_COUNTY pkCounty,
        cma.ADDRESS address,
        cma.PHONE PHONE,
        cma.ACCOUNT_NAME accountName,
        <choose>
            <when test="dpdVO.awardsList != null and dpdVO.awardsList.size > 0">
                (select wm_concat(cmm.member_code || '-' || cmm.member_name)
                from cu_member cmm
                where cmm.pk_awards in
                <foreach collection="dpdVO.awardsList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
                start with cmm.pk_id = cm.pk_id
                connect by cmm.pk_id = prior cmm.pk_parent)
            </when>
            <otherwise>''</otherwise>
        </choose>
        parentChief
        from CU_MEMBER cm
        inner JOIN (
        select SUM(so.ORDER_ACHIEVE) ORDER_ACHIEVE,so.PK_REFERENCE from CU_MEMBER cmm
        INNER JOIN SA_ORDER so on so.PK_REFERENCE=cmm.PK_ID and so.DEL_FLAG=0 and so.ORDER_STATUS=1 and so.PK_COUNTRY=#{dpdVO.pkCountry}
        where cmm.DEL_FLAG=0
        and so.ORDER_TYPE in (1,2,24,25)
        <if test="dpdVO.pkMember!=null">
            and cmm.PK_PARENT=#{dpdVO.pkMember}
        </if>
        and cmm.PK_SETTLE_COUNTRY=#{dpdVO.pkCountry}
        and cmm.CATEGORY=0
        <if test="dpdVO.startDate != null and dpdVO.startDate!='' ">
            and so.PAY_TIME >= to_date(#{dpdVO.startDate}, 'yyyy-mm-dd')
        </if>
        <if test="dpdVO.endDate != null and dpdVO.endDate!='' ">
            and so.PAY_TIME &lt;= to_date(#{dpdVO.endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="dpdVO.pkRegisterGradeList != null and dpdVO.pkRegisterGradeList.size > 0">
            and cmm.PK_REGISTER_GRADE in
            <foreach collection="dpdVO.pkRegisterGradeList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        GROUP BY so.PK_REFERENCE
        ) so on cm.pk_id=so.PK_REFERENCE
        LEFT JOIN bd_vertex ver ON cm.pk_vertex = ver.pk_id
        LEFT JOIN cu_member_team ct ON ct.pk_id = cm.pk_team_code
        LEFT JOIN CU_MEMBER_AUTHENTICATION cma on cma.PK_MEMBER=cm.pk_id and cma.DEL_FLAG=0
        LEFT join (
        select count(1) dpNumber, PK_PARENT from (
        select cm.PK_ID PK_PARENT from CU_MEMBER cm
        INNER JOIN SA_ORDER so on so.PK_REFERENCE=cm.PK_ID
        where cm.DEL_FLAG = 0 AND cm.CATEGORY = 0
        AND PK_SETTLE_COUNTRY = 1
        and so.DEL_FLAG = 0 and so.ORDER_STATUS=1
        and so.ORDER_TYPE in (1,2,24,25)
        <if test="dpdVO.memberCode != null and dpdVO.memberCode !='' ">
            AND cm.MEMBER_CODE =#{dpdVO.memberCode}
        </if>
        <if test="dpdVO.memberName != null and dpdVO.memberName !='' ">
            AND cm.MEMBER_NAME =#{dpdVO.memberName}
        </if>
        <if test="dpdVO.startDate != null and dpdVO.startDate!='' ">
            and so.PAY_TIME >= to_date(#{dpdVO.startDate}, 'yyyy-mm-dd')
        </if>
        <if test="dpdVO.endDate != null and dpdVO.endDate!='' ">
            and so.PAY_TIME &lt;= to_date(#{dpdVO.endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>

        <if test="dpdVO.pkRegisterGradeList != null and dpdVO.pkRegisterGradeList.size > 0">
            and cm.PK_REGISTER_GRADE in
            <foreach collection="dpdVO.pkRegisterGradeList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        )
        GROUP BY PK_PARENT
        ) cmcon on cmcon.PK_PARENT=cm.pk_id
        where cm.DEL_FLAG=0 and cm.CATEGORY=0
        <if test="dpdVO.yesNoAddress != null">
            <choose>
                <when test="dpdVO.yesNoAddress == 1">
                    and cma.PK_PROVINCE is null
                    and cma.PK_CITY is null
                </when>
                <otherwise>
                    and cma.PK_PROVINCE is not null
                    and cma.PK_CITY is not null
                </otherwise>
            </choose>
        </if>

        <if test="dpdVO.dpNumber != null and dpdVO.condition != null">
            <choose>
                <when test="dpdVO.condition == 1">
                    and cmcon.dpNumber &gt; #{dpdVO.dpNumber}
                </when>
                <when test="dpdVO.condition == 2">
                    and cmcon.dpNumber &gt;=#{dpdVO.dpNumber}
                </when>
                <when test="dpdVO.condition == 3">
                    and cmcon.dpNumber &lt; #{dpdVO.dpNumber}
                </when>
                <when test="dpdVO.condition == 4">
                    and cmcon.dpNumber &lt;=#{dpdVO.dpNumber}
                </when>
                <otherwise>
                    and cmcon.dpNumber =#{dpdVO.dpNumber}
                </otherwise>
            </choose>
        </if>

        <if test="dpdVO.orderAchieve!=null and dpdVO.acCondition!=null">
            <choose>
                <when test="dpdVO.acCondition == 1">
                    and so.ORDER_ACHIEVE &gt; #{dpdVO.orderAchieve}
                </when>
                <when test="dpdVO.acCondition == 2">
                    and so.ORDER_ACHIEVE &gt;=#{dpdVO.orderAchieve}
                </when>
                <when test="dpdVO.acCondition == 3">
                    and so.ORDER_ACHIEVE &lt; #{dpdVO.orderAchieve}
                </when>
                <when test="dpdVO.acCondition == 4">
                    and so.ORDER_ACHIEVE &lt;=#{dpdVO.orderAchieve}
                </when>
                <otherwise>
                    and so.ORDER_ACHIEVE =#{dpdVO.orderAchieve}
                </otherwise>
            </choose>
        </if>


        <if test="dpdVO.pkVertex!=null">
            and cm.pk_vertex=#{dpdVO.pkVertex}
        </if>
        <if test="dpdVO.memberCode != null and dpdVO.memberCode !='' ">
            AND cm.MEMBER_CODE =#{dpdVO.memberCode}
        </if>
        <if test="dpdVO.memberName != null and dpdVO.memberName !='' ">
            AND cm.MEMBER_NAME =#{dpdVO.memberName}
        </if>
        ORDER BY dpNumber DESC
    </select>

    <!--    直推数据详情-->
    <select id="selectDirectPushDataDetails" resultType="com.hzs.report.member.vo.DirectPushDataVO">
        select
        cm.pk_id pkMember,
        so.MEMBER_CODE memberCode,
        so.MEMBER_NAME memberName,
        so.orderCode,
        so.orderAmount ,
        so.orderAchieve ,
        so.payTime
        from CU_MEMBER cm
        inner join(
        select
        so.ORDER_CODE orderCode,
        so.ORDER_AMOUNT orderAmount,
        so.ORDER_ACHIEVE orderAchieve,
        so.PAY_TIME payTime,
        cmm.PK_PARENT,
        cmm.MEMBER_CODE,
        cmm.MEMBER_NAME
        from CU_MEMBER cmm
        INNER JOIN SA_ORDER so on so.PK_MEMBER=cmm.PK_ID
        and so.DEL_FLAG=0
        and so.ORDER_STATUS=1
        and so.PK_COUNTRY=#{pkCountry}
        where cmm.DEL_FLAG=0
        and so.ORDER_TYPE in (1,2,24,25)
        and cmm.PK_PARENT=#{pkMember}
        and cmm.PK_SETTLE_COUNTRY=#{pkCountry}
        and cmm.CATEGORY=0
        <if test="startDate != null and startDate!='' ">
            and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        )so on cm.pk_id=so.PK_PARENT
        ORDER BY so.payTime DESC
    </select>


    <!-- 会员订单分布统计-->
    <select id="memberOrderScatter" resultType="com.hzs.report.member.vo.OrderScatterVO">
        select * from (
        SELECT
        (sum(so.ORDER_ACHIEVE)*#{rate}) orderAchieve,
        (sum(so.ORDER_AMOUNT - nvl(so.consume_amount, 0))) orderAmount,
        #{orderType} orderType,
        <if test="areaType == 1">
            pr.name prName
        </if>
        <if test="areaType == 2">
            pr.name prName,
            ct.name ctName
        </if>
        <if test="areaType == 3">
            pr.name prName,
            ct.name ctName,
            co.name coName
        </if>
        from SA_ORDER so
        left join BD_AREA pr on pr.pk_id=so.REC_PROVINCE
        left join BD_AREA ct on ct.pk_id=so.REC_CITY
        left join BD_AREA co on co.pk_id=so.REC_COUNTY
        where
        pr.del_flag = 0
        and ct.del_flag = 0
        and co.del_flag = 0
        and so.del_flag = 0
        and so.pk_Country=#{pkCountry}
        and so.ORDER_STATUS=1
        <if test="startDate != null and startDate!='' ">
            and so.pay_time &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and so.pay_time &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="orderTypeList != null">
            and so.ORDER_TYPE in
            <foreach collection="orderTypeList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        GROUP BY
        <if test="areaType == 1">
            pr.name
        </if>
        <if test="areaType == 2">
            pr.name,
            ct.name
        </if>
        <if test="areaType == 3">
            pr.name,
            ct.name,
            co.name
        </if>
        ) ORDER BY orderAchieve DESC
    </select>
    <!--     三方订单分布统计-->
    <select id="memberThreeOrderScatter" resultType="com.hzs.report.member.vo.OrderScatterVO">
        select * from (
        SELECT
        (sum(so.ORDER_ACHIEVE)*#{rate}) orderAchieve,
        (sum(ORDER_AMOUNT)) orderAmount,
        #{orderType} orderType,
        <if test="areaType == 1">
            pr.name prName
        </if>
        <if test="areaType == 2">
            pr.name prName,
            ct.name ctName
        </if>
        <if test="areaType == 3">
            pr.name prName,
            ct.name ctName,
            co.name coName
        </if>
        from SA_T_ORDER so
        left join BD_AREA pr on pr.pk_id=so.REC_PROVINCE
        left join BD_AREA ct on ct.pk_id=so.REC_CITY
        left join BD_AREA co on co.pk_id=so.REC_COUNTY
        where
        pr.del_flag = 0
        and ct.del_flag = 0
        and co.del_flag = 0
        and so.del_flag = 0
        and so.pk_Country=#{pkCountry}
        and so.ORDER_STATUS=1
        <if test="startDate != null and startDate!='' ">
            and so.CREATION_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and so.CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="orderTypeList != null">
            and so.ORDER_TYPE in
            <foreach collection="orderTypeList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        GROUP BY
        <if test="areaType == 1">
            pr.name
        </if>
        <if test="areaType == 2">
            pr.name,
            ct.name
        </if>
        <if test="areaType == 3">
            pr.name,
            ct.name,
            co.name
        </if>
        ) ORDER BY orderAchieve DESC
    </select>
    <!--     根据奖衔查询所有会员-->
    <select id="queryAwardAchieList"
            resultType="com.hzs.report.member.vo.BloodRemoveSameVO" parameterType="com.hzs.report.member.vo.BloodRemoveSameVO">
        select cm.PK_ID pkMember,
        aw.PK_TRANSACTION AS pkAwards,
        cm.MEMBER_CODE AS memberCode,
        cm.MEMBER_NAME AS memberName,
        cm.PHONE AS phone,
        ver.VERTEX_NAME AS vertexName,
        ct.TEAM_NAME AS teamName,
        cm.PK_SETTLE_COUNTRY as pkCountry,
        bc.SHORT_NAME shortName
        from CU_MEMBER cm
        LEFT JOIN bd_vertex ver ON cm.pk_vertex = ver.pk_id
        LEFT JOIN cu_member_team ct ON ct.pk_id = cm.pk_team_code
        LEFT JOIN BD_AWARDS aw ON aw.pk_ID = cm.PK_AWARDS
        left join BD_COUNTRY bc on cm.PK_COUNTRY=bc.PK_ID
        where cm.PK_SETTLE_COUNTRY=#{pkCountry}
        and cm.DEL_FLAG=0
        and ver.del_flag = 0
        and aw.DEL_FLAG=0
        and cm.category = 0
        <if test="pkVertex!= null">
            and cm.pk_vertex=#{pkVertex}
        </if>
        <if test="pkTeamCode!= null">
            and cm.pk_team_code=#{pkTeamCode}
        </if>
        <if test="pkAwardsList!= null">
            and PK_AWARDS in
            <foreach collection="pkAwardsList" item="awitem" open="(" close=")" separator=",">
                #{awitem}
            </foreach>
        </if>
        GROUP BY cm.PK_ID,
        aw.PK_TRANSACTION ,
        cm.MEMBER_CODE ,
        cm.MEMBER_NAME ,
        cm.PHONE ,
        ver.VERTEX_NAME ,
        ct.TEAM_NAME,
        cm.PK_SETTLE_COUNTRY,
        bc.SHORT_NAME

    </select>

    <!--    根据奖衔查询会员（历史）-->
    <select id="queryAwardAchieListHistory"
            resultType="com.hzs.report.member.vo.BloodRemoveSameVO" parameterType="com.hzs.report.member.vo.BloodRemoveSameVO">
        select cm.PK_MEMBER pkMember,
        aw.PK_TRANSACTION AS pkAwards,
        cm.MEMBER_CODE AS memberCode,
        cm.MEMBER_NAME AS memberName,
        cm.PHONE AS phone,
        ver.VERTEX_NAME AS vertexName,
        ct.TEAM_NAME AS teamName,
        cm.PK_SETTLE_COUNTRY as pkCountry,
        bc.SHORT_NAME shortName
        from ${settleTableNameEnd} cm
        LEFT JOIN bd_vertex ver ON cm.pk_vertex = ver.pk_id and ver.del_flag = 0
        LEFT JOIN cu_member_team ct ON ct.pk_id = cm.pk_team_code
        LEFT JOIN BD_AWARDS aw ON aw.pk_ID = cm.PK_AWARDS and aw.DEL_FLAG=0
        left join BD_COUNTRY bc on cm.PK_COUNTRY=bc.PK_ID
        where
        cm.PERIOD =#{periodEnd}
        and cm.PK_SETTLE_COUNTRY=#{pkCountry}
        and cm.category = 0
        <if test="pkVertex!= null">
            and cm.pk_vertex=#{pkVertex}
        </if>
        <if test="pkTeamCode!= null">
            and cm.pk_team_code=#{pkTeamCode}
        </if>
        <if test="pkAwardsList!= null">
            and PK_AWARDS in
            <foreach collection="pkAwardsList" item="awitem" open="(" close=")" separator=",">
                #{awitem}
            </foreach>
        </if>
        GROUP BY cm.PK_MEMBER,
        aw.PK_TRANSACTION ,
        cm.MEMBER_CODE ,
        cm.MEMBER_NAME ,
        cm.PHONE ,
        ver.VERTEX_NAME ,
        ct.TEAM_NAME,
        cm.PK_SETTLE_COUNTRY,
        bc.SHORT_NAME
    </select>

    <!--    查询全部伞下血缘业绩-->
    <select id="bloodRemoveSameAllList"
            resultType="com.hzs.report.member.vo.BloodRemoveSameVO">
        select
        sum(so.ORDER_ACHIEVE) orderAchieve,
        sum(so.ORDER_AMOUNT) orderAmount,
        #{brs.pkMember} pkMember,
        #{brs.pkAwards} AS pkAwards,
        #{brs.memberCode} AS memberCode,
        #{brs.memberName} AS memberName,
        #{brs.phone} AS phone,
        #{brs.pkCountry} AS pkCountry,
        #{brs.shortName} AS shortName,
        <if test="brs.vertexName != null and brs.vertexName!='' ">
            #{brs.vertexName} AS vertexName,
        </if>
        <if test="brs.vertexName == null or brs.vertexName=='' ">
            '' AS vertexName,
        </if>
        <if test="brs.teamName != null and brs.teamName!='' ">
            #{brs.teamName} AS teamName,
        </if>
        <if test="brs.teamName == null or brs.teamName=='' ">
            '' AS teamName,
        </if>
        1
        from SA_ORDER so
        where 1=1
        and so.DEL_FLAG=0
        and so.ORDER_STATUS=1
        and so.PK_COUNTRY=#{brs.pkCountry}
        <if test="startDate != null and startDate!='' ">
            and so.CREATION_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and startDate!='' ">
            and so.CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="orderTypeList != null">
            and so.ORDER_TYPE in
            <foreach collection="orderTypeList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        and so.pk_member in(
        SELECT
        cm.pk_id
        FROM
        cu_member cm
        WHERE
        cm.del_flag = 0
        and cm.pk_settle_country =#{brs.pkCountry}
        and cm.category = 0
        START WITH cm.pk_id =#{brs.pkMember} CONNECT BY cm.pk_parent = PRIOR cm.pk_id
        <if test="pkAwardsList!= null">
            and PK_AWARDS not in
            <foreach collection="pkAwardsList" item="awitem" open="(" close=")" separator=",">
                #{awitem}
            </foreach>
        </if>
        )
    </select>
    <!--查询会员推荐伞下业绩(历史) -->
    <select id="bloodSameAllListHistory"
            resultType="com.hzs.report.member.vo.BloodRemoveSameVO">
        <foreach collection="bloodList" item="item" separator="UNION ALL">
            select
            orderAchieve AS orderAchieve,
            orderAmount AS orderAmount,
            pkMember,
            #{item.pkAwards} AS pkAwards,
            #{item.memberCode} AS memberCode,
            #{item.memberName} AS memberName,
            #{item.phone} AS phone,
            #{item.pkCountry} AS pkCountry,
            #{item.shortName} AS shortName,
            <if test="item.vertexName != null and item.vertexName!='' ">
                #{item.vertexName} AS vertexName,
            </if>
            <if test="item.vertexName == null or item.vertexName=='' ">
                '' AS vertexName,
            </if>
            <if test="item.teamName != null and item.teamName!='' ">
                #{item.teamName} AS teamName,
            </if>
            <if test="item.teamName == null or item.teamName=='' ">
                '' AS teamName,
            </if>
            1
            FROM
            (
            WITH data_1 AS (
            SELECT
            <if test="orderType != null">
                <choose>
                    <when test="orderType == 1">
                        nvl((sum((cma.REGISTER_PV +cma.UPGRADE_PV+cma.REPURCHASE_PV+HI_FUN_PV+MALL_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.REGISTER_AMOUNT+cma.UPGRADE_AMOUNT+cma.REPURCHASE_AMOUNT+HI_FUN_AMOUNT+MALL_AMOUNT)),0) AS orderAmount,
                    </when>
                    <when test="orderType == 2">
                        nvl((sum((cma.REGISTER_PV +cma.UPGRADE_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.REGISTER_AMOUNT+cma.UPGRADE_AMOUNT)),0) AS orderAmount,
                    </when>
                    <when test="orderType == 3">
                        nvl((sum((cma.REPURCHASE_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.REPURCHASE_AMOUNT)),0) AS orderAmount,
                    </when>
                    <when test="orderType == 5">
                        nvl((sum((cma.REGISTER_PV ))),0 ) AS orderAchieve,
                        nvl(sum((cma.REGISTER_AMOUNT)),0) AS orderAmount,
                    </when>
                    <when test="orderType == 6">
                        nvl((sum((cma.UPGRADE_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.UPGRADE_AMOUNT)),0) AS orderAmount,
                    </when>
                    <otherwise>
                        nvl((sum((cma.REGISTER_PV +cma.UPGRADE_PV+cma.REPURCHASE_PV+HI_FUN_PV+MALL_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.REGISTER_AMOUNT+cma.UPGRADE_AMOUNT+cma.REPURCHASE_AMOUNT+HI_FUN_AMOUNT+MALL_AMOUNT)),0) AS orderAmount,
                    </otherwise>
                </choose>
            </if>

            #{item.pkMember} AS pkMember
            FROM
            ${achieveTableNameEnd} cma
            WHERE
            1 = 1
            AND cma.PK_COUNTRY =#{item.pkCountry}
            AND cma.PERIOD =#{periodEnd}
            AND cma.PK_MEMBER IN (
            select cm.PK_MEMBER from (
            SELECT
            cm.PK_MEMBER,cm.pk_parent
            FROM
            ${settleTableNameEnd} cm
            WHERE cm.pk_settle_country =#{item.pkCountry}
            and cm.PERIOD =#{periodEnd}
            ) cm START WITH cm.PK_MEMBER =#{item.pkMember}
            CONNECT BY cm.pk_parent = PRIOR cm.PK_MEMBER
            )
            ),data_2 AS (
            SELECT
            <if test="orderType != null">
                <choose>
                    <when test="orderType == 1">
                        nvl((sum((cma.REGISTER_PV +cma.UPGRADE_PV+cma.REPURCHASE_PV+HI_FUN_PV+MALL_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.REGISTER_AMOUNT+cma.UPGRADE_AMOUNT+cma.REPURCHASE_AMOUNT+HI_FUN_AMOUNT+MALL_AMOUNT)),0) AS orderAmount,
                    </when>
                    <when test="orderType == 2">
                        nvl((sum((cma.REGISTER_PV +cma.UPGRADE_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.REGISTER_AMOUNT+cma.UPGRADE_AMOUNT)),0) AS orderAmount,
                    </when>
                    <when test="orderType == 3">
                        nvl((sum((cma.REPURCHASE_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.REPURCHASE_AMOUNT)),0) AS orderAmount,
                    </when>
                    <when test="orderType == 5">
                        nvl((sum((cma.REGISTER_PV ))),0 ) AS orderAchieve,
                        nvl(sum((cma.REGISTER_AMOUNT)),0) AS orderAmount,
                    </when>
                    <when test="orderType == 6">
                        nvl((sum((cma.UPGRADE_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.UPGRADE_AMOUNT)),0) AS orderAmount,
                    </when>
                    <otherwise>
                        nvl((sum((cma.REGISTER_PV +cma.UPGRADE_PV+cma.REPURCHASE_PV+HI_FUN_PV+MALL_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.REGISTER_AMOUNT+cma.UPGRADE_AMOUNT+cma.REPURCHASE_AMOUNT+HI_FUN_AMOUNT+MALL_AMOUNT)),0) AS orderAmount,
                    </otherwise>
                </choose>
            </if>
            #{item.pkMember} AS pkMember
            FROM
            ${achieveTableNameSta} cma
            WHERE
            1 = 1
            AND cma.PK_COUNTRY =#{item.pkCountry}
            AND cma.PERIOD =#{periodSta}
            AND cma.PK_MEMBER IN (
            select cm.PK_MEMBER from (
            SELECT
            cm.PK_MEMBER,cm.pk_parent
            FROM
            ${settleTableNameSta} cm
            WHERE cm.pk_settle_country =#{item.pkCountry}
            and cm.PERIOD =#{periodSta}
            ) cm START WITH cm.PK_MEMBER =#{item.pkMember}
            CONNECT BY cm.pk_parent = PRIOR cm.PK_MEMBER
            )
            )
            SELECT d1.pkMember,
            d1.orderAchieve - d2.orderAchieve AS orderAchieve,
            d1.orderAmount - d2.orderAmount AS orderAmount
            FROM data_1 d1
            JOIN data_2 d2 ON d1.pkMember = d2.pkMember
            )

        </foreach>
    </select>

    <select id="bloodRemoveSameMemberAchieveNew"
            resultType="com.hzs.report.member.vo.BloodRemoveSameVO">
        <foreach collection="bloodList" item="item" separator="UNION ALL">
            select
            orderAchieve,
            orderAmount,
            #{item.pkMember} pkMember
            from (
            WITH data_1 AS (
            SELECT
            <if test="orderType != null">
                <choose>
                    <when test="orderType == 1">
                        nvl((sum((cma.REGISTER_PV +cma.UPGRADE_PV+cma.REPURCHASE_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.REGISTER_AMOUNT+cma.UPGRADE_AMOUNT+cma.REPURCHASE_AMOUNT)),0) AS orderAmount,
                    </when>
                    <when test="orderType == 2">
                        nvl((sum((cma.REGISTER_PV +cma.UPGRADE_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.REGISTER_AMOUNT+cma.UPGRADE_AMOUNT)),0) AS orderAmount,
                    </when>
                    <when test="orderType == 3">
                        nvl((sum((cma.REPURCHASE_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.REPURCHASE_AMOUNT)),0) AS orderAmount,
                    </when>
                    <when test="orderType == 5">
                        nvl((sum((cma.REGISTER_PV ))),0 ) AS orderAchieve,
                        nvl(sum((cma.REGISTER_AMOUNT)),0) AS orderAmount,
                    </when>
                    <when test="orderType == 6">
                        nvl((sum((cma.UPGRADE_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.UPGRADE_AMOUNT)),0) AS orderAmount,
                    </when>
                    <otherwise>
                        nvl((sum((cma.REGISTER_PV +cma.UPGRADE_PV+cma.REPURCHASE_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.REGISTER_AMOUNT+cma.UPGRADE_AMOUNT+cma.REPURCHASE_AMOUNT)),0) AS orderAmount,
                    </otherwise>
                </choose>
            </if>
            #{item.pkMember} pkMember
            FROM
            ${achieveTableNameEnd} cma
            WHERE
            1 = 1
            AND cma.PK_COUNTRY =#{pkCountry}
            AND cma.PERIOD =#{periodEnd}
            AND cma.PK_MEMBER IN (
            SELECT PK_MEMBER
            FROM (select *
            from (SELECT cm.PK_MEMBER, cm.PK_AWARDS, cm.pk_parent
            FROM ${settleTableNameEnd} cm
            WHERE cm.PERIOD =#{periodEnd}
            AND cm.pk_settle_country =#{pkCountry}) cm
            START WITH cm.pk_parent =#{item.pkMember}
            CONNECT BY PRIOR cm.PK_MEMBER = cm.pk_parent
            AND cm.pk_parent not IN
            (SELECT cm.PK_MEMBER
            FROM ${settleTableNameEnd} cm
            WHERE cm.pk_settle_country =#{pkCountry}
            AND cm.PERIOD =#{periodEnd}
            AND cm.PK_AWARDS IN
            <foreach collection="pkAwardsList" item="awitem" open="(" close=")" separator=",">
                #{awitem}
            </foreach>
            ))
            WHERE PK_AWARDS IN
            <foreach collection="pkAwardsList" item="awitem" open="(" close=")" separator=",">
                #{awitem}
            </foreach>
            )
            ),
            data_2 AS (
            SELECT
            <if test="orderType != null">
                <choose>
                    <when test="orderType == 1">
                        nvl((sum((cma.REGISTER_PV +cma.UPGRADE_PV+cma.REPURCHASE_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.REGISTER_AMOUNT+cma.UPGRADE_AMOUNT+cma.REPURCHASE_AMOUNT)),0) AS orderAmount,
                    </when>
                    <when test="orderType == 2">
                        nvl((sum((cma.REGISTER_PV +cma.UPGRADE_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.REGISTER_AMOUNT+cma.UPGRADE_AMOUNT)),0) AS orderAmount,
                    </when>
                    <when test="orderType == 3">
                        nvl((sum((cma.REPURCHASE_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.REPURCHASE_AMOUNT)),0) AS orderAmount,
                    </when>
                    <when test="orderType == 5">
                        nvl((sum((cma.REGISTER_PV ))),0 ) AS orderAchieve,
                        nvl(sum((cma.REGISTER_AMOUNT)),0) AS orderAmount,
                    </when>
                    <when test="orderType == 6">
                        nvl((sum((cma.UPGRADE_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.UPGRADE_AMOUNT)),0) AS orderAmount,
                    </when>
                    <otherwise>
                        nvl((sum((cma.REGISTER_PV +cma.UPGRADE_PV+cma.REPURCHASE_PV))),0 ) AS orderAchieve,
                        nvl(sum((cma.REGISTER_AMOUNT+cma.UPGRADE_AMOUNT+cma.REPURCHASE_AMOUNT)),0) AS orderAmount,
                    </otherwise>
                </choose>
            </if>
            #{item.pkMember} pkMember
            FROM
            ${achieveTableNameSta} cma
            WHERE
            1 = 1
            AND cma.PK_COUNTRY =#{pkCountry}
            AND cma.PERIOD =#{periodSta}
            AND cma.PK_MEMBER IN (
            SELECT PK_MEMBER
            FROM (select *
            from (SELECT cm.PK_MEMBER, cm.PK_AWARDS, cm.pk_parent
            FROM ${settleTableNameSta} cm
            WHERE cm.PERIOD =#{periodSta}
            AND cm.pk_settle_country =#{pkCountry}) cm
            START WITH cm.pk_parent =#{item.pkMember}
            CONNECT BY PRIOR cm.PK_MEMBER = cm.pk_parent
            AND cm.pk_parent not IN
            (SELECT cm.PK_MEMBER
            FROM ${settleTableNameSta} cm
            WHERE cm.pk_settle_country =#{pkCountry}
            AND cm.PERIOD =#{periodSta}
            AND cm.PK_AWARDS IN
            <foreach collection="pkAwardsList" item="awitem" open="(" close=")" separator=",">
                #{awitem}
            </foreach>
            ))
            WHERE PK_AWARDS IN
            <foreach collection="pkAwardsList" item="awitem" open="(" close=")" separator=",">
                #{awitem}
            </foreach>
            )
            )
            SELECT d1.pkMember,
            d1.orderAchieve - d2.orderAchieve AS orderAchieve,
            d1.orderAmount - d2.orderAmount AS orderAmount
            FROM data_1 d1
            JOIN data_2 d2 ON d1.pkMember = d2.pkMember
            ) ac where (ac.ORDERACHIEVE>0 or ac.ORDERAMOUNT>0)
        </foreach>

    </select>


    <!--    根据奖衔级别查询奖衔-->
    <select id="awardsLevellist"
            resultType="java.lang.Integer">
        select pk_id pkId
        from BD_AWARDS aw
        where aw.PK_COUNTRY=#{pkCountry}
        and aw.DEL_FLAG=0
        <if test="pkAwardsList!= null">
            and aw.AWARDS_VALUE in
            <foreach collection="pkAwardsList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>

    <!--    安置血缘查询-左右区人数-->
    <select id="lrMemberCountList"
            resultType="com.hzs.report.member.vo.ResettleBloodVO">
        select 1 placeDept, COUNT(1) memberCount from (
        SELECT CREATION_TIME
        FROM cu_member
        WHERE del_flag = 0
        START WITH pk_id = (select cm.pk_id from cu_member cm
        where cm.pk_place_parent =#{pkMember}
        and cm.place_dept = 1
        and cm.del_flag = 0
        and cm.CATEGORY=0)
        CONNECT BY pk_place_parent = PRIOR pk_id
        ) cm1 where 1=1
        <if test="startDate != null and startDate!='' ">
            and cm1.CREATION_TIME &gt;=to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and cm1.CREATION_TIME &lt;=to_date(#{endDate} || '23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>

        UNION all

        select 2 placeDept,COUNT(1) memberCount from (
        SELECT CREATION_TIME
        FROM cu_member
        WHERE del_flag = 0
        START WITH pk_id = (select cm.pk_id from cu_member cm
        where cm.pk_place_parent =#{pkMember}
        and cm.place_dept = 2
        and cm.del_flag = 0
        and cm.CATEGORY=0)
        CONNECT BY pk_place_parent = PRIOR pk_id
        ) cm2 where 1=1
        <if test="startDate != null and startDate!='' ">
            and cm2.CREATION_TIME &gt;=to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and cm2.CREATION_TIME &lt;=to_date(#{endDate} || '23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
    </select>
    <!--    安置血缘查询-左右血缘人数-->
    <select id="lrbMemberCountList"
            resultType="com.hzs.report.member.vo.ResettleBloodVO">
        select 1 placeDept,COUNT(1) memberCount from (
        SELECT CREATION_TIME FROM CU_MEMBER where del_flag = 0 AND CATEGORY = 0
        START WITH pk_parent in (
        SELECT PK_ID FROM cu_member
        where del_flag = 0 AND CATEGORY = 0 AND place_dept = 1 START WITH pk_place_parent =#{pkMember}
        CONNECT BY pk_place_parent = PRIOR PK_ID
        )
        CONNECT BY pk_parent = PRIOR PK_ID
        ) cm3
        where 1=1
        <if test="startDate != null and startDate != '' ">
            and cm3.CREATION_TIME &gt;=to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate != '' ">
            and cm3.CREATION_TIME &lt;=to_date(#{endDate} || '23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>

        UNION ALL
        select 2 placeDept,COUNT(1) memberCount from (
        SELECT
        CREATION_TIME
        FROM
        CU_MEMBER where del_flag = 0 AND CATEGORY = 0
        START WITH pk_parent in (
        SELECT PK_ID FROM cu_member
        where del_flag = 0 AND CATEGORY = 0 AND place_dept = 2 START WITH pk_place_parent =#{pkMember}
        CONNECT BY pk_place_parent = PRIOR PK_ID
        )
        CONNECT BY pk_parent = PRIOR PK_ID
        ) cm4
        where 1=1
        <if test="startDate != null and startDate!='' ">
            and cm4.CREATION_TIME &gt;=to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and cm4.CREATION_TIME &lt;=to_date(#{endDate} || '23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
    </select>

    <!--    安置血缘查询-左右区人数详情列表-->
    <select id="lrMemberDetailsList"
            resultType="com.hzs.report.member.vo.ResettleBloodVO">
        select
        cm.lev,
        cm.PK_ID pkMember,
        cm.MEMBER_CODE memberCode,
        cm.MEMBER_NAME memberName,
        cm.PHONE phone,
        cm.PK_REGISTER_GRADE,
        cm.PK_AWARDS,
        cm.PK_TEAM_CODE pkTeamCode,
        cm.PK_VERTEX pkVertex,
        cm.CREATION_TIME creationTime,
        aw.PK_TRANSACTION as pkAwards,
        bg.PK_TRANSACTION as pkRegisterGrade,
        ver.VERTEX_NAME as vertexName,
        ct.TEAM_NAME as teamName
        from (
        SELECT LEVEL lev,PK_ID,MEMBER_CODE,PHONE,MEMBER_NAME,PK_REGISTER_GRADE,PK_AWARDS,PK_TEAM_CODE,PK_VERTEX,CREATION_TIME
        FROM cu_member
        WHERE del_flag = 0
        and PK_SETTLE_COUNTRY=#{pkCountry}
        START WITH pk_id = (select cm.pk_id from cu_member cm
        where cm.pk_place_parent =#{pkMember}
        and cm.place_dept =#{placeDept}
        and cm.del_flag = 0)
        CONNECT BY pk_place_parent = PRIOR pk_id
        ) cm
        LEFT JOIN BD_AWARDS aw on aw.pk_ID=cm.PK_AWARDS
        LEFT JOIN BD_GRADE bg on bg.pk_id=cm.PK_REGISTER_GRADE
        left join bd_vertex ver on cm.pk_vertex = ver.pk_id
        LEFT JOIN cu_member_team ct ON ct.pk_id = cm.pk_team_code
        where aw.DEL_FLAG=0
        and ver.DEL_FLAG=0
        and bg.DEL_FLAG=0
        <if test="startDate != null and startDate !='' ">
            and cm.CREATION_TIME &gt;=to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate !=''">
            and cm.CREATION_TIME &lt;=to_date(#{endDate} || '23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="memberCode != null and memberCode !='' ">
            AND cm.MEMBER_CODE like #{memberCode} || '%'
        </if>
        <if test="memberName != null and memberName !='' ">
            AND cm.MEMBER_NAME like #{memberName} || '%'
        </if>
        <if test="phone != null and phone !='' ">
            AND cm.phone like #{phone} || '%'
        </if>
        <if test="pkAwards != null">
            AND cm.PK_AWARDS=#{pkAwards}
        </if>
        <if test="pkVertex != null">
            AND cm.pk_vertex=#{pkVertex}
        </if>
        <if test="pkTeamCode != null">
            AND cm.pk_team_code=#{pkTeamCode}
        </if>
        <if test="pkRegisterGrade != null">
            AND cm.PK_REGISTER_GRADE=#{pkRegisterGrade}
        </if>
        ORDER BY cm.lev asc
    </select>

    <!--    安置血缘查询-左右区血缘人数详情列表-->
    <select id="lrbMemberDetailsList"
            resultType="com.hzs.report.member.vo.ResettleBloodVO">
        select
        cm.lev,
        cm.PK_ID pkMember,
        cm.MEMBER_CODE memberCode,
        cm.MEMBER_NAME memberName,
        cm.PHONE phone,
        cm.PK_REGISTER_GRADE,
        cm.PK_AWARDS,
        cm.PK_TEAM_CODE pkTeamCode,
        cm.PK_VERTEX pkVertex,
        cm.CREATION_TIME creationTime,
        aw.PK_TRANSACTION as pkAwards,
        bg.PK_TRANSACTION as pkRegisterGrade,
        ver.VERTEX_NAME as vertexName,
        ct.TEAM_NAME as teamName
        from (
        SELECT LEVEL lev,PK_ID,MEMBER_CODE,PHONE,MEMBER_NAME,PK_REGISTER_GRADE,
        PK_SETTLE_COUNTRY,PK_AWARDS,PK_TEAM_CODE,PK_VERTEX,CREATION_TIME, pk_parent FROM
        CU_MEMBER where del_flag = 0 AND CATEGORY = 0
        START WITH pk_parent in (
        SELECT PK_ID FROM cu_member
        where del_flag = 0 AND CATEGORY = 0 AND place_dept =#{placeDept} START WITH pk_place_parent =#{pkMember}
        CONNECT BY pk_place_parent = PRIOR PK_ID
        ) CONNECT BY pk_parent = PRIOR PK_ID
        ) cm
        LEFT JOIN BD_AWARDS aw on aw.pk_ID=cm.PK_AWARDS
        LEFT JOIN BD_GRADE bg on bg.pk_id=cm.PK_REGISTER_GRADE
        left join bd_vertex ver on cm.pk_vertex = ver.pk_id
        LEFT JOIN cu_member_team ct ON ct.pk_id = cm.pk_team_code
        where aw.DEL_FLAG=0
        and cm.PK_SETTLE_COUNTRY=#{pkCountry}
        and ver.DEL_FLAG=0
        and bg.DEL_FLAG=0
        <if test="startDate != null and startDate != '' ">
            and cm.CREATION_TIME &gt;=to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate != '' ">
            and cm.CREATION_TIME &lt;=to_date(#{endDate} || '23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="memberCode != null and memberCode !='' ">
            AND cm.MEMBER_CODE like #{memberCode} || '%'
        </if>
        <if test="memberName != null and memberName !='' ">
            AND cm.MEMBER_NAME like #{memberName} || '%'
        </if>
        <if test="phone != null and phone !='' ">
            AND cm.phone like #{phone} || '%'
        </if>
        <if test="pkAwards != null">
            AND cm.PK_AWARDS=#{pkAwards}
        </if>
        <if test="pkVertex != null">
            AND cm.pk_vertex=#{pkVertex}
        </if>
        <if test="pkTeamCode != null">
            AND cm.pk_team_code=#{pkTeamCode}
        </if>
        <if test="pkRegisterGrade != null">
            AND cm.PK_REGISTER_GRADE=#{pkRegisterGrade}
        </if>
        ORDER BY cm.lev asc
    </select>

    <!--    个人复购统计-->
    <select id="personRepurchaseList" resultType="com.hzs.report.member.vo.PersonRepurchaseVO">
        select * from (
        select
        cm.member_code memberCode,
        cm.member_name memberName,
        gr.PK_TRANSACTION AS pkSettleGrade,
        awa.PK_TRANSACTION AS pkAwards,
        bc.SHORT_NAME shortName,
        bc.NATIONAL_FLAG1 nationalFlag1,
        sum(so.ORDER_AMOUNT) repurchaseAmount,
        sum(so.ORDER_ACHIEVE) repurchasePv
        from CU_MEMBER cm
        INNER JOIN SA_ORDER so on cm.pk_id=so.PK_MEMBER
        LEFT JOIN bd_awards awa ON awa.pk_id = cm.PK_AWARDS
        LEFT JOIN bd_grade gr ON gr.pk_id = cm.PK_SETTLE_GRADE
        LEFT JOIN BD_COUNTRY bc on bc.pk_id=cm.PK_SETTLE_COUNTRY
        where cm.del_flag = 0
        and so.DEL_FLAG = 0
        and so.ORDER_STATUS=1
        and so.ORDER_TYPE in(3,26,22,14,12,18,19,7,28,13,27)
        and awa.del_flag = 0
        and gr.del_flag = 0
        and cm.PK_SETTLE_COUNTRY=#{pkCountry}
        <if test="startDate != null and startDate!='' ">
            and so.PAY_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>

        GROUP BY
        cm.member_code ,
        cm.member_name ,
        gr.PK_TRANSACTION ,
        awa.PK_TRANSACTION ,
        bc.SHORT_NAME,
        bc.NATIONAL_FLAG1
        )
        where 1=1
        <if test="repurchasePv != null">
            and repurchasePv &gt;=#{repurchasePv}
        </if>
        ORDER BY repurchasePv DESC
    </select>

    <!--    安置业绩统计 查询会员-->
    <select id="positStatList" resultType="com.hzs.report.member.vo.PositStatVO">
        select cm.pk_id              pkMember,
               cm.member_code        memberCode,
               cm.member_name        memberName,
               gr.PK_TRANSACTION  AS pkSettleGrade,
               awa.PK_TRANSACTION AS pkAwards,
               bc.SHORT_NAME         shortName,
               bc.NATIONAL_FLAG1     nationalFlag1
        from CU_MEMBER cm
                 LEFT JOIN bd_awards awa ON awa.pk_id = cm.PK_AWARDS
                 LEFT JOIN bd_grade gr ON gr.pk_id = cm.PK_SETTLE_GRADE
                 LEFT JOIN BD_COUNTRY bc on bc.pk_id = cm.PK_SETTLE_COUNTRY
        where cm.del_flag = 0
          and cm.CATEGORY = 0
          and awa.del_flag = 0
          and gr.del_flag = 0
          and cm.PK_SETTLE_COUNTRY = #{pkCountry}

    </select>
    <!--    安置业绩统计 查询左右业绩-->
    <select id="positStatAchieve" resultType="com.hzs.report.member.vo.PositStatVO">
        SELECT
        lef.pkMember,
        lef.leftAchieve,
        lef.leftAmount,
        rig.rightAmount,
        rig.rightAchieve
        FROM (
        SELECT
        #{psVO.pkMember} pkMember,
        1 placeDept,
        nvl(sum(so.ORDER_ACHIEVE), 0) leftAchieve,
        nvl(sum(so.ORDER_AMOUNT), 0) leftAmount
        FROM
        SA_ORDER so
        INNER JOIN (
        SELECT
        a.pk_id
        FROM
        (SELECT pk_id, del_flag, CATEGORY FROM cu_member WHERE 1 = 1
        START WITH pk_place_parent =#{psVO.pkMember} AND place_dept = 1 CONNECT BY pk_place_parent = PRIOR pk_id) a
        WHERE
        a.del_flag = 0
        AND a.CATEGORY = 0
        ) a ON so.pk_member = a.pk_id
        WHERE
        so.del_flag = 0
        AND so.ORDER_STATUS = 1
        AND so.PAY_TIME &gt;= to_date(#{psVO.startDate}, 'yyyy-mm-dd')
        AND so.PAY_TIME &lt;= to_date(#{psVO.endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        <if test="psVO.orderTypeList != null and psVO.orderTypeList.size > 0">
            and SO.ORDER_TYPE in
            <foreach collection="psVO.orderTypeList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        ) lef
        INNER JOIN (
        SELECT
        #{psVO.pkMember} pkMember,
        2 placeDept,
        nvl(sum(so.ORDER_ACHIEVE), 0) rightAchieve,
        nvl(sum(so.ORDER_AMOUNT), 0) rightAmount
        FROM
        SA_ORDER so
        INNER JOIN (
        SELECT
        a.pk_id
        FROM
        (SELECT pk_id, del_flag, CATEGORY FROM cu_member WHERE 1 = 1
        START WITH pk_place_parent =#{psVO.pkMember} AND place_dept = 2 CONNECT BY pk_place_parent = PRIOR pk_id) a
        WHERE
        a.del_flag = 0
        AND a.CATEGORY = 0
        ) a ON so.pk_member = a.pk_id
        WHERE
        so.del_flag = 0
        AND so.ORDER_STATUS = 1
        AND so.PAY_TIME &gt;= to_date(#{psVO.startDate}, 'yyyy-mm-dd')
        AND so.PAY_TIME &lt;= to_date(#{psVO.endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        <if test="psVO.orderTypeList != null and psVO.orderTypeList.size > 0">
            and SO.ORDER_TYPE in
            <foreach collection="psVO.orderTypeList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        ) rig ON lef.pkMember = rig.pkMember
        WHERE 1=1
        <if test="psVO.achieve != null ">
            and rig.rightAchieve &gt;=#{psVO.achieve}
        </if>
        <if test="psVO.achieve != null ">
            and lef.leftAchieve &gt;=#{psVO.achieve}
        </if>


    </select>

    <!--    查询伞下直推产品列表-->
    <select id="umbrellaBelowProductList" resultType="com.hzs.report.member.vo.UmbrellaBelowProductVO">
        SELECT
        so.orderAchieve,
        so.orderAmount,
        so.pkMember,
        cm.MEMBER_CODE,
        cm.MEMBER_NAME,
        aw.PK_TRANSACTION as pkAwards,
        bg.PK_TRANSACTION as pkRegisterGrade
        FROM
        (
        SELECT
        sum( orderAchieve ) orderAchieve,
        sum( orderAmount ) orderAmount,
        #{ubpVO.pkMember} pkMember
        FROM
        (
        SELECT CASE WHEN sum( so.ORDER_ACHIEVE ) IS NULL THEN 0 ELSE sum( so.ORDER_ACHIEVE ) END orderAchieve,
        CASE WHEN sum( so.ORDER_AMOUNT - nvl(so.consume_amount, 0) ) IS NULL THEN 0 ELSE sum( so.ORDER_AMOUNT - nvl(so.consume_amount, 0)) END orderAmount
        FROM
        SA_ORDER so
        WHERE
        so.DEL_FLAG = 0
        AND so.ORDER_STATUS = 1
        AND so.PK_COUNTRY = 1
        <if test="ubpVO.productName != null and ubpVO.productName !='' ">
            AND bpt.PRODUCT_NAME like '%' || #{ubpVO.productName} || '%'
        </if>
        <if test="ubpVO.productCode != null and ubpVO.productCode !='' ">
            AND bpt.PRODUCT_CODE =#{ubpVO.productCode}
        </if>
        <if test="ubpVO.orderTypeList != null">
            and so.ORDER_TYPE in
            <foreach collection="ubpVO.orderTypeList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="ubpVO.startDate != null and ubpVO.startDate !=''">
            and so.PAY_TIME &gt;= to_date(#{ubpVO.startDate}, 'yyyy-mm-dd')
        </if>
        <if test="ubpVO.endDate != null and ubpVO.endDate !=''">
            and so.PAY_TIME &lt;= to_date(#{ubpVO.endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        AND so.pk_member IN (
        SELECT
        cm.pk_id
        FROM
        cu_member cm
        WHERE
        cm.del_flag = 0 START WITH cm.pk_parent =#{ubpVO.pkMember} CONNECT BY cm.pk_parent = PRIOR cm.pk_id )
        )
        ) so
        LEFT JOIN CU_MEMBER cm ON so.pkMember = cm.PK_ID
        LEFT JOIN BD_AWARDS aw on aw.pk_ID=cm.PK_AWARDS
        LEFT JOIN BD_GRADE bg on bg.pk_id=cm.PK_REGISTER_GRADE
        where cm.DEL_FLAG=0 and
        aw.DEL_FLAG=0 and
        bg.DEL_FLAG=0
    </select>

    <!--    伞下直推产品去重-->
    <select id="umbrellaBelowRepeatList" resultType="com.hzs.report.member.vo.UmbrellaBelowRepeatVO">
        select reso.pk_id pkId,
        bpt.PRODUCT_CODE productCode,
        bpt.PRODUCT_NAME productName,
        soi.PRICE price,
        soi.QUANTITY quantity,
        soi.PRICE*soi.QUANTITY as totalPrice,
        soi.ACHIEVEMENT achievement,
        soi.ACHIEVEMENT*soi.QUANTITY as totalAchievement,
        so.PK_MEMBER pkMember,
        so.ORDER_CODE orderCode,
        cu.MEMBER_CODE memberCode,
        cu.MEMBER_NAME memberName,
        bv.VERTEX_NAME vertexName,
        cr.MEMBER_CODE crMemberCode,
        cr.MEMBER_NAME crMemberName,
        so.REC_NAME recName,
        so.REC_PHONE recPhone,
        p.name province,
        c.name city,
        pc.name county,
        so.REC_ADDRESS recAddress,
        so.CREATION_TIME creationTime,
        so.PAY_TIME payTime,
        so.ORDER_TYPE orderType
        FROM
        (
        SELECT
        pk_id
        FROM
        (
        SELECT
        so.pk_id
        FROM
        SA_ORDER so
        WHERE
        so.DEL_FLAG = 0
        AND so.ORDER_STATUS = 1
        AND so.PK_COUNTRY =#{ubrVO.pkCountry}
        <if test="ubrVO.orderTypeList != null">
            and so.ORDER_TYPE in
            <foreach collection="ubrVO.orderTypeList" item="iitem" open="(" close=")" separator=",">
                #{iitem}
            </foreach>
        </if>
        <if test="ubrVO.startDate != null and ubrVO.startDate !=''">
            and so.PAY_TIME &gt;= to_date(#{ubrVO.startDate}, 'yyyy-mm-dd')
        </if>
        <if test="ubrVO.endDate != null and ubrVO.endDate !=''">
            and so.PAY_TIME &lt;= to_date(#{ubrVO.endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        AND so.pk_member IN (
        SELECT
        cm.pk_id
        FROM
        cu_member cm
        WHERE
        cm.del_flag = 0 START WITH cm.pk_parent =#{ubrVO.pkMember} CONNECT BY cm.pk_parent = PRIOR cm.pk_id )
        )

        <if test="ubrVO.pkMemberList!=null and ubrVO.pkMemberList.size>0 ">
            MINUS
            <foreach collection="ubrVO.pkMemberList" item="item" separator="MINUS">
                SELECT
                pk_id
                FROM
                (
                SELECT
                so.pk_id
                FROM
                SA_ORDER so
                WHERE
                so.DEL_FLAG = 0
                AND so.ORDER_STATUS = 1
                AND so.PK_COUNTRY =#{ubrVO.pkCountry}
                <if test="ubrVO.orderTypeList != null">
                    and so.ORDER_TYPE in
                    <foreach collection="ubrVO.orderTypeList" item="iitem" open="(" close=")" separator=",">
                        #{iitem}
                    </foreach>
                </if>
                <if test="ubrVO.startDate != null and ubrVO.startDate !=''">
                    and so.PAY_TIME &gt;= to_date(#{ubrVO.startDate}, 'yyyy-mm-dd')
                </if>
                <if test="ubrVO.endDate != null and ubrVO.endDate !=''">
                    and so.PAY_TIME &lt;= to_date(#{ubrVO.endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
                </if>
                AND so.pk_member IN (
                SELECT
                cm.pk_id
                FROM
                cu_member cm
                WHERE
                cm.del_flag = 0 START WITH cm.pk_parent =#{item} CONNECT BY cm.pk_parent = PRIOR cm.pk_id )
                )
            </foreach>
        </if>
        ) reso
        INNER JOIN SA_ORDER so on reso.pk_id=so.pk_id
        INNER JOIN SA_ORDER_ITEMS soi on soi.PK_ORDER=so.PK_ID
        INNER JOIN BD_PRODUCT bpt on bpt.PK_ID=soi.PK_PRODUCT
        LEFT JOIN CU_MEMBER cu ON so.pk_member = cu.PK_ID
        left join bd_vertex bv on bv.PK_ID = cu.PK_VERTEX
        left join bd_area p on p.pk_id = so.REC_PROVINCE and p.del_flag = 0
        left join bd_area c on c.pk_id = so.REC_CITY and c.del_flag = 0
        left join bd_area pc on pc.pk_id = so.REC_COUNTY and pc.del_flag = 0
        left join CU_MEMBER cr on cr.pk_id=so.PK_CREATOR and cr.del_flag = 0
        where cu.DEL_FLAG=0
        and soi.DEL_FLAG=0
        and bpt.DEL_FLAG=0
        <if test="ubrVO.productName != null and ubrVO.productName !='' ">
            AND bpt.PRODUCT_NAME like '%' || #{ubrVO.productName} || '%'
        </if>
        <if test="ubrVO.productCode != null and ubrVO.productCode !='' ">
            AND bpt.PRODUCT_CODE =#{ubrVO.productCode}
        </if>
        ORDER BY so.PAY_TIME desc

    </select>

    <!--伞下直推产品统计-->
    <select id="statProductList" resultType="com.hzs.report.member.vo.StatProductVO">
        select
        bpt.PRODUCT_CODE productCode,
        bpt.PRODUCT_NAME productName,
        soi.PRICE price,
        sum(soi.QUANTITY) quantity,
        sum(soi.PRICE*soi.QUANTITY) as totalPrice,
        sum(soi.ACHIEVEMENT) achievement
        FROM
        (
        SELECT
        pk_id
        FROM
        (
        SELECT
        so.pk_id
        FROM
        SA_ORDER so
        WHERE
        so.DEL_FLAG = 0
        AND so.ORDER_STATUS = 1
        AND so.PK_COUNTRY =#{sptVO.pkCountry}
        <if test="sptVO.orderTypeList != null">
            and so.ORDER_TYPE in
            <foreach collection="sptVO.orderTypeList" item="iitem" open="(" close=")" separator=",">
                #{iitem}
            </foreach>
        </if>
        <if test="sptVO.startDate != null and sptVO.startDate !=''">
            and so.PAY_TIME &gt;= to_date(#{sptVO.startDate}, 'yyyy-mm-dd')
        </if>
        <if test="sptVO.endDate != null and sptVO.endDate !=''">
            and so.PAY_TIME &lt;= to_date(#{sptVO.endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        AND so.pk_member IN (
        SELECT
        cm.pk_id
        FROM
        cu_member cm
        WHERE
        cm.del_flag = 0 START WITH cm.pk_parent =#{sptVO.pkMember} CONNECT BY cm.pk_parent = PRIOR cm.pk_id )
        )
        <if test="sptVO.pkMemberList!=null and sptVO.pkMemberList.size>0 ">
            MINUS
            <foreach collection="sptVO.pkMemberList" item="item" separator="MINUS">
                SELECT
                pk_id
                FROM
                (
                SELECT
                so.pk_id
                FROM
                SA_ORDER so
                WHERE
                so.DEL_FLAG = 0
                AND so.ORDER_STATUS = 1
                AND so.PK_COUNTRY =#{sptVO.pkCountry}
                <if test="sptVO.orderTypeList != null">
                    and so.ORDER_TYPE in
                    <foreach collection="sptVO.orderTypeList" item="iitem" open="(" close=")" separator=",">
                        #{iitem}
                    </foreach>
                </if>
                <if test="sptVO.startDate != null and sptVO.startDate !=''">
                    and so.PAY_TIME &gt;= to_date(#{sptVO.startDate}, 'yyyy-mm-dd')
                </if>
                <if test="sptVO.endDate != null and sptVO.endDate !=''">
                    and so.PAY_TIME &lt;= to_date(#{sptVO.endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
                </if>
                AND so.pk_member IN (
                SELECT
                cm.pk_id
                FROM
                cu_member cm
                WHERE
                cm.del_flag = 0 START WITH cm.pk_parent =#{item} CONNECT BY cm.pk_parent = PRIOR cm.pk_id )
                )
            </foreach>
        </if>
        ) reso
        INNER JOIN SA_ORDER so on reso.pk_id=so.pk_id
        INNER JOIN SA_ORDER_ITEMS soi on soi.PK_ORDER=so.PK_ID
        INNER JOIN BD_PRODUCT bpt on bpt.PK_ID=soi.PK_PRODUCT
        where
        soi.DEL_FLAG=0
        and bpt.DEL_FLAG=0
        <if test="sptVO.productName != null and sptVO.productName !='' ">
            AND bpt.PRODUCT_NAME like '%' || #{sptVO.productName} || '%'
        </if>
        <if test="sptVO.productCode != null and sptVO.productCode !='' ">
            AND bpt.PRODUCT_CODE =#{sptVO.productCode}
        </if>
        GROUP BY
        bpt.PRODUCT_CODE,
        bpt.PRODUCT_NAME,
        soi.PRICE
        ORDER BY sum(soi.QUANTITY) desc


    </select>


    <!--    会员户籍数据查询-->
    <select id="domicileDataList" resultType="com.hzs.report.member.vo.DomicileDataVO">
        select cm.MEMBER_CODE    AS                               memberCode,
               cm.MEMBER_NAME    AS                               memberName,
               cm.PHONE,
               cm.CREATION_TIME                                   creationTime,
               nvl(
                       (select A_SUM_PV
                        from ${ddVO.endAchieveTableName}
                        where PK_MEMBER = #{ddVO.pkMember}
                          and PERIOD = #{ddVO.endPeriod})
                   , 0
                   )                                              leftAchieve,
               nvl(
                       (select B_SUM_PV
                        from ${ddVO.endAchieveTableName}
                        where PK_MEMBER = #{ddVO.pkMember}
                          and PERIOD = #{ddVO.endPeriod})
                   , 0
                   )                                              rightAchieve,
               aw.PK_TRANSACTION AS                               pkAwards,
               (select count(1)
                from CU_MEMBER
                where del_flag = 0
                  and CATEGORY = 0
                  and PK_PARENT = #{ddVO.pkMember}
                  and pk_settle_country = #{ddVO.pkCountry}
               )                                                  parentCount,
               (
                   SELECT count(1)
                   FROM cu_member cm
                   WHERE cm.del_flag = 0
                     and CATEGORY = 0
                     and cm.PK_SETTLE_COUNTRY = #{ddVO.pkCountry} START WITH cm.pk_id =#{ddVO.pkMember}
        CONNECT BY cm.pk_parent = PRIOR cm.pk_id
            ) suggestCount
                 , (
        select Max (so.PAY_TIME )
        from SA_ORDER so
        where so.DEL_FLAG=0
          and so.ORDER_STATUS=1
          and so.PK_COUNTRY=#{ddVO.pkCountry}
          and so.PK_CREATOR=#{ddVO.pkMember}) payTime
            , (
        select count (1)
        from CU_MEMBER
        where DEL_FLAG=0
          and PK_SETTLE_COUNTRY=#{ddVO.pkCountry}
          and PHONE=#{ddVO.phone}) phoneCount
            , cm.CHANGE_NUMBER changeNumber
        from CU_MEMBER cm
            LEFT JOIN BD_AWARDS aw
        ON aw.pk_ID = cm.PK_AWARDS
        where cm.del_flag = 0 and cm.pk_id=#{ddVO.pkMember}


    </select>


    <select id="areaAchieveStat" resultType="com.hzs.report.member.vo.AreaAchieveStatVO">
        SELECT
        (sum(so.ORDER_ACHIEVE)*#{rate}) orderAchieve,
        (sum(ORDER_AMOUNT)) orderAmount,
        pr.name prName,
        so.REC_PROVINCE reProvince,
        SUBSTR(to_char(so.PAY_TIME, 'yyyy-mm-dd'),9,10) AS creationTime
        from SA_ORDER so
        left join BD_AREA pr on pr.pk_id=so.REC_PROVINCE
        where
        so.del_flag = 0
        and so.REC_PROVINCE is not null
        and so.pk_Country=1
        and so.DEL_FLAG=0
        and so.ORDER_STATUS=1
        <if test="startDate != null and startDate!='' ">
            and so.PAY_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        GROUP BY
        to_char(so.PAY_TIME, 'yyyy-mm-dd'),
        pr.name,
        so.REC_PROVINCE
        ORDER BY so.REC_PROVINCE asc, creationTime asc

    </select>

    <!--    系统业绩统计-->
    <select id="vertexAchieveStat" resultType="com.hzs.report.member.vo.VertexAchieveStatVO">
        SELECT
        (sum(so.ORDER_ACHIEVE)*#{rate}) orderAchieve,
        (sum(ORDER_AMOUNT)) orderAmount,
        bv.VERTEX_NAME vertexName,
        so.PK_VERTEX pkVertex,
        SUBSTR(to_char(so.PAY_TIME, 'yyyy-mm-dd'),9,10) AS creationTime
        from SA_ORDER so
        left join BD_VERTEX bv on bv.pk_id=so.PK_VERTEX and bv.del_flag = 0
        where
        so.del_flag = 0
        and so.pk_Country=1
        and so.ORDER_STATUS=1
        <if test="startDate != null and startDate!='' ">
            and so.PAY_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!='' ">
            and so.PAY_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        GROUP BY
        to_char(so.PAY_TIME, 'yyyy-mm-dd'),
        bv.VERTEX_NAME,
        so.PK_VERTEX
        ORDER BY so.PK_VERTEX asc, creationTime asc
    </select>

    <!--    月度职级名单查询-->
    <select id="monthlyJobLevelList" resultType="com.hzs.report.member.vo.MonthlyJobLevelVo">
        select #{statDate}           statDate,
               dy.A_SUM_PV * #{rate} aSumPv,
               dy.B_SUM_PV * #{rate} bSumPv,
               dy.pk_member          pkMember,
               sy.a_sum_pv * #{rate} lastMonthASumPv,
               sy.b_sum_pv * #{rate} lastMonthBSumPv,
               dy_total              dyTotal,
               sy_total              syTotal
        from (
                 select dy.A_SUM_PV,
                        dy.B_SUM_PV,
                        dy.PK_MEMBER,
                        (
                            SELECT count(1)
                            FROM ${settleTableName}
                            WHERE PERIOD = #{periodEnd}
                              AND PK_PARENT = #{pkMember}
                              AND PK_COUNTRY = #{pkCountry}
                        ) as dy_total,
                        (
                            SELECT count(1)
                            FROM ${lastMonthSettleTableName}
                            WHERE PERIOD = #{lastMonthPeriodEnd}
                              AND PK_PARENT = #{pkMember}
                              AND PK_COUNTRY = #{pkCountry}
                        ) as sy_total
                 from ${achieveTableName} dy
                 where dy.PERIOD = #{periodEnd}
                   and dy.PK_MEMBER = #{pkMember}
                   and dy.PK_COUNTRY = #{pkCountry}
             ) dy
                 LEFT JOIN
             (
                 select sy.A_SUM_PV,
                        sy.B_SUM_PV,
                        sy.PK_MEMBER
                 from ${lastMonthAchieveTableName} sy
                 where sy.PERIOD = #{lastMonthPeriodEnd}
                   and sy.PK_MEMBER = #{pkMember}
                   and sy.PK_COUNTRY = #{pkCountry}
             ) sy on dy.PK_MEMBER = sy.PK_MEMBER
    </select>

<!--    查询收益区域数据-->
    <select id="revenueAreaList" resultType="com.hzs.report.member.vo.RevenueAreaVO">
        SELECT
		cmrr.pk_id pkId,
		cmrr.effective effective,
    cmrr.pk_member pkMember,
    cmrr.creation_time creationTime,
    cmrr.effective_end_date effectiveEndDate,
    cmrr.PROVINCE province,
    cmrr.CITY city,
    cmrr.county,
    so.rec_county,
    cm.member_code memberCode,
    cm.member_name memberName,
    bg.GRADE_NAME gradeName,
    nvl(sum(so.order_amount),0) as totalOrderAmount,
    nvl(sum(so.order_achieve),0) as totalOrderAchieve,
    nvl(sum(so.box_num),0) as totalBoxNum
FROM
    CU_MEMBER_RETAIL_REGION cmrr
    INNER JOIN CU_MEMBER cm ON cmrr.PK_MEMBER = cm.PK_ID and cm.DEL_FLAG = 0
    INNER join BD_GRADE bg on bg.pk_id=cm.PK_SETTLE_GRADE and bg.DEL_FLAG = 0
LEFT JOIN SA_ORDER so ON so.pk_member = cmrr.pk_member AND cmrr.COUNTY = so.REC_COUNTY and so.DEL_FLAG = 0
where cmrr.DEL_FLAG = 0
and cmrr.PK_COUNTRY=#{pkCountry}
        <if test="effective != null ">
            AND cmrr.effective= #{effective}
        </if>
        <if test="memberCode != null and memberCode !='' ">
            AND cm.MEMBER_CODE like #{memberCode} || '%'
        </if>
        <if test="startDate != null and startDate!=''">
            and cmrr.CREATION_TIME &gt;= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate!=''">
            and cmrr.effective_end_date &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
GROUP BY
    cmrr.pk_id,
	cmrr.EFFECTIVE,
    cmrr.PK_MEMBER,
    cm.member_code,
    cm.member_name,
    bg.GRADE_NAME,
    cmrr.CREATION_TIME,
    cmrr.EFFECTIVE_END_DATE,
    cmrr.PROVINCE,
    cmrr.CITY,
    cmrr.COUNTY,
    so.REC_COUNTY
    </select>


</mapper>
