<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hzs.member.base.mapper.CuMemberMapper">

    <!-- 查询登录会员以及状态 -->
    <resultMap id="MemberResultMap" type="com.hzs.common.domain.member.ext.CuMemberExt">
        <id column="PK_ID" property="pkId"/>
        <result column="MEMBER_CODE" property="memberCode"/>
        <result column="MEMBER_NAME" property="memberName"/>
        <result column="CUSTOMER_TYPE" property="customerType"/>
        <result column="PHONE" property="phone"/>
        <result column="ID_CARD" property="idCard"/>
        <result column="SEX" property="sex"/>
        <result column="BIRTH_DATE" property="birthDate"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_SETTLE_COUNTRY" property="pkSettleCountry"/>
        <result column="PARENT" property="parent"/>
        <result column="PK_PARENT" property="pkParent"/>
        <result column="PK_PLACE_PARENT" property="pkPlaceParent"/>
        <result column="PLACE_DEPT" property="placeDept"/>
        <result column="PK_TEAM_CODE" property="pkTeamCode"/>
        <result column="PK_CENTER_CODE" property="pkCenterCode"/>
        <result column="SOURCE" property="source"/>
        <result column="PK_REGISTER_GRADE" property="pkRegisterGrade"/>
        <result column="PK_SETTLE_GRADE" property="pkSettleGrade"/>
        <result column="PK_AWARDS" property="pkAwards"/>
        <result column="CONSUME_MONEY" property="consumeMoney"/>
        <result column="CONSUME_ACHIEVE" property="consumeAchieve"/>
        <result column="PURCHASE_STATUS" property="purchaseStatus"/>
        <result column="SHARE_STATUS" property="shareStatus"/>
        <result column="PAY_TIME" property="payTime"/>
        <result column="PAY_STATUS" property="payStatus"/>
        <result column="LOGIN_PWD" property="loginPwd"/>
        <result column="PAY_PWD" property="payPwd"/>
        <result column="LOGIN_PASSWORD" property="loginPassword"/>
        <result column="PAY_PASSWORD" property="payPassword"/>
        <result column="EDIT_NUMBER" property="editNumber"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="REGISTER_AUTHORITY" property="registerAuthority"/>
        <result column="PK_VERTEX" property="pkVertex"/>
        <result column="ACCOUNT_STATUS" property="accountStatus"/>
        <result column="PAY_STATUS" property="payStatus"/>
        <result column="CATEGORY" property="category"/>
        <result column="EMAIL" property="email"/>
        <result column="ORDER_SOURCE" property="orderSource"/>
        <result column="IS_REAL_NAME" property="isRealName"/>
        <result column="IS_BUS_LICENSE" property="isBusLicense"/>
        <result column="IS_MAKER_SPACE" property="isMakerSpace"/>
        <result column="CHANGE_NUMBER" property="changeNumber"/>
        <result column="WECHAT" property="wechat"/>
        <result column="CARD_TYPE" property="cardType"/>
        <result column="NICK_NAME" property="nickName"/>
        <result column="HEAD_PATH" property="headPath"/>
        <result column="DIRECT_PUSH_NUMBER" property="directPushNumber"/>
        <result column="IS_DEALER" property="isDealer"/>
        <result column="SYSTEM_LEVEL" property="systemLevel"/>
        <result column="LECTURER_LEVEL" property="lecturerLevel"/>
        <result column="SUPER_STUDIO" property="superStudio"/>
        <result column="ID_FRONT" property="idFront"/>
        <result column="ID_BACK" property="idBack"/>
        <result column="PK_PROVINCE" property="pkProvince"/>
        <result column="PK_CITY" property="pkCity"/>
        <result column="PK_COUNTY" property="pkCounty"/>
        <result column="ADDRESS" property="address"/>
        <result column="BANK_NAME" property="bankName"/>
        <result column="SUB_BANK_NAME" property="subBankName"/>
        <result column="ACCOUNT_NAME" property="accountName"/>
        <result column="reservedPhone" property="reservedPhone"/>
        <result column="CARD_NUMBER" property="cardNumber"/>
        <result column="certificationTime" property="certificationTime"/>
        <result column="directPushNumber" property="directPushNumber"/>
        <result column="ID_TYPE" property="idType"/>
        <result column="GLOBAL_CODE" property="globalCode"/>
        <result column="COUNTRY_CODE" property="countryCode"/>
        <result column="recommendedOrderNumber" property="recommendedOrderNumber"/>
        <result column="GLOBAL_CODE" property="globalCode"/>
        <result column="COUNTRY_CODE" property="countryCode"/>
        <result column="GRADE_VALUE" property="gradeValue"/>
        <result column="REGISTER_GRADEVAL" property="registerGradeVal"/>
        <result column="AWARDS_VAL" property="awardsVal"/>
        <result column="TEAM_CODE" property="teamCode"/>
        <result column="TEAM_NAME" property="teamName"/>
        <result column="EXPIRE_DATE" property="expireDate"/>
        <result column="RESALE_INCOME_NUMBER" property="resaleIncomeNumber"/>
        <result column="RESALE_INCOME_BONUS" property="resaleIncomeBonus"/>
    </resultMap>

    <resultMap id="MemberVO" type="com.hzs.member.base.vo.CuMemberVO">
        <id column="PK_ID" property="pkId"/>
        <result column="MEMBER_CODE" property="memberCode"/>
        <result column="MEMBER_NAME" property="memberName"/>
        <result column="CUSTOMER_TYPE" property="customerType"/>
        <result column="PHONE" property="phone"/>
        <result column="ID_CARD" property="idCard"/>
        <result column="SEX" property="sex"/>
        <result column="BIRTH_DATE" property="birthDate"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_SETTLE_COUNTRY" property="pkSettleCountry"/>
        <result column="PAR_MEMBER_CODE" property="parMemberCode"/>
        <result column="PAR_MEMBER_NAME" property="parMemberName"/>
        <result column="PLACE_MEMBER_CODE" property="placeMemberCode"/>
        <result column="PLACE_MEMBER_NAME" property="placeMemberName"/>
        <result column="PLACE_DEPT" property="placeDept"/>
        <result column="CENTER_MEMBER_CODE" property="centerMemberCode"/>
        <result column="CENTER_MEMBER_NAME" property="centerMemberName"/>
        <result column="SOURCE" property="source"/>
        <result column="PK_REGISTER_GRADE" property="pkRegisterGrade"/>
        <result column="PK_SETTLE_GRADE" property="pkSettleGrade"/>
        <result column="PK_AWARDS" property="pkAwards"/>
        <result column="CONSUME_MONEY" property="consumeMoney"/>
        <result column="CONSUME_ACHIEVE" property="consumeAchieve"/>
        <result column="PURCHASE_STATUS" property="purchaseStatus"/>
        <result column="SHARE_STATUS" property="shareStatus"/>
        <result column="PAY_TIME" property="payTime"/>
        <result column="PAY_STATUS" property="payStatus"/>
        <result column="EDIT_NUMBER" property="editNumber"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="REGISTER_AUTHORITY" property="registerAuthority"/>
        <result column="TOP_MEMBER_CODE" property="topMemberCode"/>
        <result column="TOP_MEMBER_NAME" property="topMemberName"/>
        <result column="ACCOUNT_STATUS" property="accountStatus"/>
        <result column="WALLET_STATUS" property="walletStatus"/>
        <result column="PAY_STATUS" property="payStatus"/>
        <result column="CATEGORY" property="category"/>
        <result column="EMAIL" property="email"/>
        <result column="INCOME_STATUS" property="incomeStatus"/>
        <result column="ORDER_SOURCE" property="orderSource"/>
        <result column="IS_REAL_NAME" property="isRealName"/>
        <result column="IS_BUS_LICENSE" property="isBusLicense"/>
        <result column="IS_MAKER_SPACE" property="isMakerSpace"/>
        <result column="CHANGE_NUMBER" property="changeNumber"/>
        <result column="WECHAT" property="wechat"/>
        <result column="CARD_TYPE" property="cardType"/>
        <result column="ID_CARD_JUST" property="idCardJust"/>
        <result column="ID_CARD_BACK" property="idCardBack"/>
        <result column="GIFT_PROVINCE" property="giftProvince"/>
        <result column="GIFT_CITY" property="giftCity"/>
        <result column="GIFT_COUNTY" property="giftCounty"/>
        <result column="GIFT_ADDRESS" property="giftAddress"/>
        <result column="BANK_NAME" property="bankName"/>
        <result column="SUB_BANK_NAME" property="subBankName"/>
        <result column="ACCOUNT_NAME" property="accountName"/>
        <result column="PHONE" property="reservePhone"/>
        <result column="CARD_NUMBER" property="cardNumber"/>
        <result column="NICK_NAME" property="nickName"/>
        <result column="HEAD_PATH" property="headPath"/>
        <result column="agent_grade" property="agentGrade"/>
        <result column="DIRECT_PUSH_NUMBER" property="directPushNumber"/>
        <result column="IS_DEALER" property="isDealer"/>
        <result column="SYSTEM_LEVEL" property="systemLevel"/>
        <result column="LECTURER_LEVEL" property="lecturerLevel"/>
        <result column="SUPER_STUDIO" property="superStudio"/>
        <result column="STORE_LEVEL" property="storeLevel"/>
    </resultMap>

    <sql id="CuMember_Column">
        select cm.pk_id,
               cm.member_code,
               cm.member_name,
               cm.phone,
               cm.pk_settle_country,
               cm.pk_parent,
               cm.pk_place_parent,
               cm.place_dept,
               cm.pk_team_code,
               cm.pk_center_code,
               cm.category,
               cm.pk_settle_grade,
               cm.pk_awards,
               cm.purchase_status,
               cm.order_source,
               cm.is_real_name,
               cm.is_bus_license,
               cm.is_maker_space,
               cm.share_status,
               cm.pay_pwd,
               cm.register_authority,
               cm.nick_name
        from cu_member cm
        where cm.del_flag = 0
    </sql>

    <!-- 保存会员信息 -->
    <insert id="insertCuMember" parameterType="com.hzs.common.domain.member.base.CuMember">
        INSERT INTO CU_MEMBER (PK_ID, MEMBER_CODE, MEMBER_NAME, CATEGORY, CUSTOMER_TYPE, PHONE, EMAIL, ID_CARD, PK_SETTLE_COUNTRY,
                               PK_PARENT, PK_PLACE_PARENT, PLACE_DEPT, PK_TEAM_CODE, PK_CENTER_CODE, SOURCE, PK_REGISTER_GRADE,
                               PK_SETTLE_GRADE, PK_AWARDS, CONSUME_MONEY, CONSUME_ACHIEVE, PAY_STATUS, LOGIN_PWD, PAY_PWD, LOGIN_PASSWORD, PAY_PASSWORD,
                               PK_VERTEX, ACCOUNT_STATUS, ORDER_SOURCE, PK_CREATOR, CREATION_TIME, PK_COUNTRY, PAY_TIME, GLOBAL_CODE, COUNTRY_CODE, REGISTER_AUTHORITY)
        VALUES (#{pkId,jdbcType=INTEGER}, #{memberCode}, #{memberName}, #{category}, #{customerType}, #{phone}, #{email, jdbcType=VARCHAR}, #{idCard, jdbcType=VARCHAR}, #{pkSettleCountry},
                #{pkParent}, #{pkPlaceParent,jdbcType=NUMERIC}, #{placeDept,jdbcType=INTEGER}, #{pkTeamCode,jdbcType=INTEGER}, #{pkCenterCode,jdbcType=INTEGER}, #{source}, #{pkRegisterGrade},
                #{pkSettleGrade}, #{pkAwards}, #{consumeMoney,jdbcType=NUMERIC}, #{consumeAchieve,jdbcType=NUMERIC}, #{payStatus}, #{loginPwd}, #{payPwd},
                #{loginPassword}, #{payPassword}, #{pkVertex,jdbcType=INTEGER}, #{accountStatus}, #{orderSource},
                #{pkCreator,jdbcType=INTEGER}, #{creationTime, jdbcType=TIMESTAMP}, #{pkCountry}, #{payTime, jdbcType=TIMESTAMP},
                #{globalCode, jdbcType=VARCHAR}, #{countryCode, jdbcType=VARCHAR}, #{registerAuthority,jdbcType=INTEGER})
    </insert>

    <!-- 批量保存会员信息 -->
    <insert id="insertBatchCuMember">
        INSERT ALL
        <foreach collection="memberList" item="item" separator=" ">
            into CU_MEMBER (
            PK_ID, MEMBER_CODE, MEMBER_NAME, CUSTOMER_TYPE,
            PHONE, PK_PARENT, PK_PLACE_PARENT, PLACE_DEPT,
            PK_COUNTRY, PK_SETTLE_COUNTRY, SOURCE,
            PK_REGISTER_GRADE, PK_SETTLE_GRADE, PK_AWARDS,
            LOGIN_PWD, PAY_PWD, LOGIN_PASSWORD, PAY_PASSWORD,
            PK_CREATOR, CREATION_TIME, PAY_TIME, PAY_STATUS,
            PK_TEAM_CODE, PK_VERTEX, ORDER_SOURCE, CONSUME_ACHIEVE,
            GLOBAL_CODE, COUNTRY_CODE, EXPIRE_DATE
            )
            values (
            #{item.pkId}, #{item.memberCode}, #{item.memberName}, #{item.customerType},
            #{item.phone}, #{item.pkParent}, #{item.pkPlaceParent}, #{item.placeDept},
            #{item.pkCountry}, #{item.pkSettleCountry}, #{item.source},
            #{item.pkRegisterGrade}, #{item.pkSettleGrade}, #{item.pkAwards},
            #{item.loginPwd}, #{item.payPwd}, #{item.loginPassword}, #{item.payPassword},
            #{item.pkCreator}, #{item.creationTime}, #{item.payTime}, #{item.payStatus},
            #{item.pkTeamCode, jdbcType=NUMERIC}, #{item.pkVertex, jdbcType=NUMERIC}, #{item.orderSource}, #{item.consumeAchieve},
            #{item.globalCode, jdbcType=VARCHAR}, #{item.countryCode, jdbcType=VARCHAR}, #{item.expireDate, jdbcType=DATE}
            )
        </foreach>
        SELECT 1 FROM dual
    </insert>

    <update id="updateMemberReSaleNumber">
        update cu_member
        set resale_income_number= resale_income_number - #{reSaleNumber},
            resale_income_bonus=resale_income_bonus - #{reSaleNumber} * 150
        where del_flag = 0
          and pk_id = #{pkMember}
          and resale_income_number >= #{reSaleNumber}
    </update>

    <!-- 通用查询映射结果 -->
    <select id="queryLoginMember" resultMap="MemberResultMap">
        select cm.*
        from cu_member cm
        where cm.del_flag = 0
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code = #{memberCode}
        </if>
        <if test="pkMember != null">
            and cm.pk_id = #{pkMember}
        </if>
    </select>

    <!-- 批量查询会员 -->
    <select id="queryMemberList" resultType="com.hzs.common.domain.member.ext.CuMemberExt">
        select cm.*, bg.START_VALUE
        from cu_member cm
        inner join bd_grade bg
        on bg.pk_id = cm.pk_settle_grade
        where cm.del_flag = 0
        <if test="memberCodeList != null and memberCodeList.size > 0">
            and cm.member_code in
            <foreach collection="memberCodeList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="pkMemberList != null and pkMemberList.size > 0">
            and cm.pk_id in
            <foreach collection="pkMemberList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
    </select>

    <!--and cm.PAY_STATUS=1-->
    <select id="queryMemberInfoByCondition" resultMap="MemberResultMap">
        <include refid="CuMember_Column"/>
        <choose>
            <when test="category != 10">
                and cm.category = 0
            </when>
        </choose>
        <if test="pkSettleCountry != null">
            and cm.pk_settle_country=#{pkSettleCountry}
        </if>
        <if test="pkId != null ">
            and cm.pk_id = #{pkId}
        </if>
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code = #{memberCode}
        </if>
        <if test="memberName != null and memberName != ''">
            and cm.member_name = #{memberName}
        </if>
        <if test="phone != null and phone != ''">
            and cm.phone = #{phone}
        </if>
        <if test="pkParent != null and pkParent != ''">
            and cm.pk_parent = #{pkParent}
        </if>
        <if test="pkPlaceParent != null and pkPlaceParent != ''">
            and cm.pk_place_parent = #{pkPlaceParent}
        </if>
        <if test="placeDept != null and placeDept != ''">
            and cm.place_dept = #{placeDept}
        </if>
        <if test="pkSettleGrade != null and pkSettleCountry != null">
            <choose>
                <when test="pkSettleGrade == 20 and pkSettleCountry == 1">
                    and cm.pk_settle_grade = 1
                </when>
                <otherwise>
                    and cm.pk_settle_grade > 1
                </otherwise>
            </choose>
        </if>

    </select>
    <select id="selectPlaceSponsorOnUmbrella" resultMap="MemberResultMap">
        select t.pk_id, t.member_code, t.member_name, t.phone, t.pk_place_parent
        from cu_member t
        where t.del_flag = 0
        <if test="memberCode != null and memberCode != ''">
            and member_code = #{memberCode}
        </if>
        <if test="phone != null and phone != ''">
            and t.phone=#{phone}
        </if>
        start with t.pk_id = #{memberId}
        connect by t.pk_id = prior t.pk_place_parent
        order by level desc
    </select>
    <select id="selectPlaceSponsorUnderUmbrella" resultMap="MemberResultMap">
        select t.pk_id,
               t.member_code,
               t.member_name,
               t.phone,
               t.pk_place_parent,
               t.pk_parent,
               t.pk_center_code,
               t.PLACE_DEPT
        from cu_member t
        where t.del_flag = 0 start
        with t.pk_place_parent = #{memberId}
        connect by t.pk_place_parent = prior t.pk_id
        order by level
    </select>

    <select id="selectPlaceSponsorUnderUmbrellaByCondition" resultMap="MemberResultMap">
        select * from (
        select t.pk_id,
        t.member_code,
        t.member_name,
        t.phone,
        t.pk_place_parent,
        t.pk_parent,
        t.pk_center_code,
        t.PLACE_DEPT
        from cu_member t
        where t.del_flag = 0 start
        with t.pk_place_parent = #{memberId}
        connect by t.pk_place_parent = prior t.pk_id
        union
        select t.pk_id,
        t.member_code,
        t.member_name,
        t.phone,
        t.pk_place_parent,
        t.pk_parent,
        t.pk_center_code,
        t.PLACE_DEPT
        from cu_member t
        where t.del_flag = 0 and t.pk_id = #{memberId}
        ) a
        where a.pk_id in
        <foreach collection="cuMemberExtList" item="item" open="(" close=")" separator=",">
            #{item.pkId}
        </foreach>
    </select>

    <select id="selectPlaceSponsorLastLeft" resultMap="MemberResultMap">
        select *
        from (select t.pk_id, t.member_code, t.member_name
              from cu_member t
              where t.del_flag = 0
                and t.place_dept = 1 start
              with t.pk_id = (select u.pk_id
                  from cu_member u
                  where u.del_flag=0 and u.pk_place_parent = #{memberId}
                  and u.place_dept = #{placeDept, jdbcType=INTEGER})
              connect by prior
                  t.pk_id = (select u.pk_place_parent
                  from cu_member u
                  where u.pk_id = t.pk_id
                     and u.place_dept = 1)
              order by level desc) n
        where rownum = 1
    </select>

    <select id="selectBloodKinshipOnUmbrella" resultMap="MemberResultMap">
        select t.pk_id, t.member_code, t.member_name, t.phone, t.pk_parent
        from cu_member t
        where t.del_flag = 0 start
        with t.pk_id = #{memberId}
        connect by t.pk_id = prior t.pk_parent
        order by level
    </select>
    <select id="selectBloodKinshipUnderUmbrella" resultMap="MemberResultMap">
        select t.pk_id, t.member_code, t.member_name, t.phone, t.pk_parent
        from cu_member t
        where t.del_flag = 0 start
        with t.pk_id = #{memberId}
        connect by t.pk_parent = prior t.pk_id
        order by level
    </select>
    <select id="createMemberId" resultType="java.lang.Long">
        SELECT CU_MEMBER_SEQ.NEXTVAL
        FROM DUAL
    </select>
    <!--会员信息列表-->
    <select id="queryCuMemberByCondition" parameterType="com.hzs.member.base.vo.CuMemberVO" resultMap="MemberVO">
        SELECT cm.PK_ID
        FROM cu_member cm
        inner join CU_MEMBER_ACCOUNT cma
        on cm.pk_id = cma.PK_MEMBER
        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 cu_member_team ct
        ON ct.pk_id = cm.pk_team_code
        LEFT JOIN cu_member center
        ON center.pk_id = cm.pk_center_code
        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 bd_grade grr
        on grr.pk_id = cm.PK_SETTLE_GRADE
        left join bd_vertex ver
        on cm.pk_vertex = ver.pk_id
        left join (select pk_member,bg.pk_transaction AGENT_GRADE from cu_member_agent ca
        inner join bd_grade bg
        on ca.agent_grade=bg.pk_id
        where ca.del_flag = 0
        and ca.agent_type = 1) cmat
        on cm.pk_id =cmat.pk_member
        WHERE cm.del_flag = 0
        <if test="pkCountry != null">
            and cm.pk_settle_country=#{pkCountry}
        </if>
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code like #{memberCode}||'%'
        </if>
        <if test="lecturerLevel != null">
            and cm.LECTURER_LEVEL=#{lecturerLevel}
        </if>
        <if test="changeNumber != null">
            and cm.CHANGE_NUMBER=#{changeNumber}
        </if>
        <if test="superStudio != null">
            and cm.super_studio=#{superStudio}
        </if>

        <if test="agentGrade != null">
            and cmat.agent_grade=#{agentGrade}
        </if>
        <if test="isTransfer != null">
            and cma.IS_TRANSFER=#{isTransfer}
        </if>
        <if test="walletStatus != null">
            and cma.IS_WITHDRAW=#{walletStatus}
        </if>
        <if test="isConsume != null">
            and cma.IS_CONSUME=#{isConsume}
        </if>
        <if test="transferStatus != null">
            and cma.TRANSFER_STATUS=#{transferStatus}
        </if>

        <if test="vertexId != null">
            and ver.PK_ID=#{vertexId}
        </if>
        <if test="teamId != null">
            and ct.PK_ID=#{teamId}
        </if>
        <if test="registerAuthority != null">
            and cm.REGISTER_AUTHORITY=#{registerAuthority}
        </if>
        <if test="isDealer != null">
            and cm.IS_DEALER=#{isDealer}
        </if>
        <if test="accountStatus != null">
            and cm.ACCOUNT_STATUS=#{accountStatus}
        </if>
        <if test="isRealName != null">
            and cm.IS_REAL_NAME=#{isRealName}
        </if>
        <if test="isBusLicense != null">
            and cm.is_bus_license=#{isBusLicense}
        </if>
        <if test="isMakerSpace != null">
            and cm.IS_MAKER_SPACE=#{isMakerSpace}
        </if>
        <if test="orderSource != null">
            and cm.order_source=#{orderSource}
        </if>

        <if test="centerMemberCode != null and centerMemberCode != ''">
            and center.member_code like #{centerMemberCode}||'%'
        </if>
        <if test="centerMemberName != null and centerMemberName != ''">
            and center.member_name like #{centerMemberName}||'%'
        </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="placeMemberCode != null and placeMemberCode != ''">
            and place.member_code like #{placeMemberCode}||'%'
        </if>
        <if test="placeMemberName != null and placeMemberName != ''">
            and place.member_name like #{placeMemberName}||'%'
        </if>

        <if test="memberName != null and memberName != ''">
            and cm.member_name like #{memberName}||'%'
        </if>
        <if test="phone != null and phone != ''">
            and cm.phone=#{phone}
        </if>
        <if test="pkRegisterGrade != null ">
            and cm.pk_register_grade =#{pkRegisterGrade}
        </if>
        <if test="pkSettleGrade != null ">
            and cm.PK_SETTLE_GRADE =#{pkSettleGrade}
        </if>

        <if test="pkAwards != null">
            and cm.pk_awards=#{pkAwards}
        </if>
        <if test="directPushNumber != null">
            and cm.DIRECT_PUSH_NUMBER=#{directPushNumber}
        </if>

        <if test="systemLevel != null">
            and cm.SYSTEM_LEVEL=#{systemLevel}
        </if>

        <if test="placeDept != null ">
            and cm.place_dept=#{placeDept}
        </if>

        <if test="teamName != null and teamName !=''">
            and ct.team_name like #{teamName}||'%'
        </if>

        <if test="startDate != null and endDate != null">
            and cm.creation_time between #{startDate, jdbcType=TIMESTAMP} and #{endDate, jdbcType=TIMESTAMP}
        </if>
        <if test="startDatePay != null and endDatePay != null">
            and cm.PAY_TIME between #{startDatePay, jdbcType=TIMESTAMP} and #{endDatePay, jdbcType=TIMESTAMP}
        </if>

        <if test="isTransfer != null ">
            and cma.IS_TRANSFER=#{isTransfer}
        </if>
        <if test="isWithdraw != null ">
            and cma.IS_WITHDRAW=#{isWithdraw}
        </if>
        <if test="isConsume != null ">
            and cma.IS_CONSUME=#{isConsume}
        </if>

        <!-- 体系权限处理 -->
        <if test="vertexList != null and vertexList.size > 0">
            and ver.pk_member in
            <foreach collection="vertexList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <!--团队权限 -->
        <if test="teamList != null and teamList.size > 0">
            and ct.pk_member in
            <foreach collection="teamList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        order by cm.CREATION_TIME desc
    </select>


    <!--会员真实信息列表-->
    <select id="realCuMemberByCondition" parameterType="com.hzs.member.base.vo.CuMemberVO" resultMap="MemberVO">
        SELECT
        cm.PK_ID,
        gr.GRADE_NAME as registerName,
        grr.GRADE_NAME as settleName,
        awa.AWARDS_NAME awardsName,
        cm.member_code,
        cm.SEX,
        cm.BIRTH_DATE,
        cm.member_name,
        cm.phone,
        cm.CARD_TYPE,
        cm.ID_CARD,
        cmg.ID_CARD_JUST,
        cmg.ID_CARD_BACK,
        province.name GIFT_PROVINCE,
        city.name GIFT_CITY,
        county.name GIFT_COUNTY,
        cmg.GIFT_ADDRESS,
        cmb.BANK_NAME,
        cmb.SUB_BANK_NAME,
        cmb.ACCOUNT_NAME,
        cmb.PHONE,
        cmb.CARD_NUMBER,
        cm.EMAIL,
        cm.WECHAT,
        cmg.CREATION_TIME as attestationTime,
        cm.PAY_TIME,
        cm.creation_time
        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_REGISTER_GRADE
        left join bd_grade grr on grr.pk_id=cm.PK_REGISTER_GRADE
        left join cu_member_bank cmb on cmb.PK_MEMBER=cm.PK_ID
        left join CU_MEMBER_GIFT cmg on cmg.PK_MEMBER=cm.PK_ID
        left join bd_area province on province.PK_ID=cmg.GIFT_PROVINCE
        left join bd_area city on city.PK_ID=cmg.GIFT_CITY
        left join bd_area county on county.PK_ID=cmg.GIFT_COUNTY
        WHERE
        cm.del_flag = 0
        and cm.pk_settle_country=#{pkCountry}
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code=#{memberCode}
        </if>

        <if test="memberName != null and memberName != ''">
            and cm.member_name=#{memberName}
        </if>
        <if test="phone != null and phone != ''">
            and cm.phone=#{phone}
        </if>
        <if test="pkRegisterGrade != null ">
            and cm.pk_register_grade =#{pkRegisterGrade}
        </if>
        <if test="pkSettleGrade != null ">
            and cm.PK_SETTLE_GRADE =#{pkSettleGrade}
        </if>

        <if test="pkAwards != null">
            and cm.pk_awards=#{pkAwards}
        </if>
        <if test="cardType != null">
            and cm.CARD_TYPE=#{cardType}
        </if>
        <if test="birthDate != null">
            and cm.BIRTH_DATE=#{birthDate}
        </if>

        <if test="giftProvince != null">
            and cmg.GIFT_PROVINCE=#{giftProvince}
        </if>
        <if test="giftCity != null">
            and cmg.GIFT_CITY=#{giftCity}
        </if>
        <if test="giftCounty != null">
            and cmg.GIFT_COUNTY=#{giftCounty}
        </if>
        <if test="sex != null">
            and cm.SEX=#{sex}
        </if>
        <if test="pkBdBank != null">
            and cmb.PK_BD_BANK=#{pkBdBank}
        </if>

        <if test="subBankName != null and subBankName != ''">
            and cmb.SUB_BANK_NAME=#{subBankName}
        </if>
        <if test="cardNumber != null and cardNumber != ''">
            and cmb.CARD_NUMBER=#{cardNumber}
        </if>
        <if test="email != null and email != ''">
            and cm.EMAIL=#{email}
        </if>
        <if test="wechat != null and wechat != ''">
            and cm.WECHAT=#{wechat}
        </if>

        <if test="startDate != null">
            and cm.creation_time >= #{startDate, jdbcType=DATE}
        </if>
        <if test="endDate != null">
            and cm.creation_time &lt; #{endDate, jdbcType=DATE}
        </if>
        <if test="startDatePay != null">
            and cm.PAY_TIME >= #{startDatePay, jdbcType=DATE}
        </if>
        <if test="endDatePay != null">
            and cm.PAY_TIME &lt; #{endDatePay, jdbcType=DATE}
        </if>

        <if test="startAttestationTime != null">
            and cmg.creation_time >= #{startAttestationTime, jdbcType=DATE}
        </if>
        <if test="endAttestationTime != null">
            and cmg.creation_time &lt; #{endAttestationTime, jdbcType=DATE}
        </if>

    </select>

    <select id="findMemberByMembercodesAndPkcountry" resultMap="MemberResultMap">
        select m.member_code,m.pk_id, m.member_name,m.pk_settle_country
        from cu_member m
        where m.del_flag = 0
        and m.category = 0
        and m.pay_status = 1
        <if test="pkCountry != null">
            and m.pk_settle_country = #{pkCountry}
        </if>
        and m.member_code in
        <foreach collection="memberCodes" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>

    <!-- 根据会员ID列表查询会员 -->
    <select id="findMemberByMemberId" resultMap="MemberResultMap">
        select cm.pk_id,
        cm.member_code,
        cm.MEMBER_NAME,
        cm.phone,
        cm.pk_settle_country
        from cu_member cm
        where cm.del_flag = 0
        <if test="pkCountry != null">
            and cm.pk_settle_country = #{pkCountry}
        </if>
        and cm.pk_id in
        <foreach collection="pkMemberList" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>

    <!--特殊配置-修改会员编号列表-->
    <select id="puCodeList" parameterType="com.hzs.member.base.vo.UpdateCodeVO"
            resultType="com.hzs.member.base.vo.UpdateCodeVO">
        select cm.pk_ID as pkId,
        cm.MEMBER_CODE as memberCode,
        cm.member_name as memberName,
        cm.PHONE as phone,
        cm.PK_SETTLE_GRADE pkSettleGrade,
        cm.PK_AWARDS pkAwards,
        cmp.PK_ID as serviceLogId,
        cmp.NEW_VALUE as newValue,
        cmp.OLD_VALUE as oldValue,
        cmp.changeNumber as changeNumber,
        cmp.CREATION_TIME as creationTime,
        cmp.APPROVE_STATUS as approveStatus,
        cmp.BUSINESS_NO as businessNo,
        cmp.SINGLE_AMOUNT as cost
        from cu_member cm
        INNER JOIN (
        select b.PK_ID,b.pk_member,
        b.OLD_VALUE,
        b.NEW_VALUE,
        b.creation_time,
        b.APPROVE_STATUS,
        b.BUSINESS_NO,
        b.SINGLE_AMOUNT,
        b.APPROVE_NUMBER changeNumber
        from CU_MEMBER_SERVICE_LOG b where b.EDIT_TYPE=109 and b.APPROVE_STATUS=5
        ) cmp on cm.pk_ID=cmp.pk_member
        where cm.del_flag = 0
        and cm.PK_SETTLE_COUNTRY=#{pkCountry}
        <if test="memberCode != null and memberCode != ''">
            and(cm.member_code like #{memberCode} || '%'
            or cmp.OLD_VALUE like #{memberCode} || '%'
            or cmp.NEW_VALUE like #{memberCode} || '%')
        </if>

        <if test="memberName != null and memberName != ''">
            and cm.member_name like #{memberName} || '%'
        </if>
        <if test="businessNo != null and businessNo != ''">
            and cmp.BUSINESS_NO=#{businessNo}
        </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="approveStatus != null">
            and cmp.APPROVE_STATUS=#{approveStatus}
        </if>

        <if test="pkSettleGrade != null">
            and cm.PK_SETTLE_GRADE=#{pkSettleGrade}
        </if>
        ORDER BY cmp.CREATION_TIME DESC
    </select>
    <!--    查询全部修改过会员编号的会员记录-->
    <select id="puCodeAllList" parameterType="com.hzs.member.base.vo.UpdateCodeVO"
            resultType="com.hzs.member.base.vo.UpdateCodeVO">
        select cm.pk_ID as pkId,
        cm.MEMBER_CODE as memberCode,
        cm.member_name as memberName,
        cm.PHONE as phone,
        cm.PK_SETTLE_GRADE pkSettleGrade,
        cm.PK_AWARDS pkAwards,
        cmp.PK_ID as serviceLogId,
        cmp.NEW_VALUE as newValue,
        cmp.OLD_VALUE as oldValue,
        cmp.changeNumber as changeNumber,
        cmp.CREATION_TIME as creationTime,
        cmp.APPROVE_STATUS as approveStatus,
        cmp.BUSINESS_NO as businessNo,
        cmp.SINGLE_AMOUNT as cost
        from cu_member cm
        INNER JOIN (
        select b.PK_ID,b.pk_member,
        b.OLD_VALUE,
        b.NEW_VALUE,
        b.creation_time,
        b.APPROVE_STATUS,
        b.BUSINESS_NO,
        b.SINGLE_AMOUNT,
        b.APPROVE_NUMBER changeNumber
        from CU_MEMBER_SERVICE_LOG b where b.EDIT_TYPE=109
        ) cmp on cm.pk_ID=cmp.pk_member
        where cm.del_flag = 0
        <if test="memberCode != null and memberCode != ''">
            and(cm.member_code like #{memberCode} || '%'
            or cmp.OLD_VALUE like #{memberCode} || '%'
            or cmp.NEW_VALUE like #{memberCode} || '%')
        </if>

        <if test="memberName != null and memberName != ''">
            and cm.member_name like #{memberName} || '%'
        </if>
        <if test="businessNo != null and businessNo != ''">
            and cmp.BUSINESS_NO=#{businessNo}
        </if>
        <if test="phone != null and phone != ''">
            and cm.phone like #{phone} || '%'
        </if>
        <if test="pkCountry != null">
            and cm.PK_COUNTRY=#{pkCountry}
        </if>

        <if test="pkAwards != null">
            and cm.pk_awards=#{pkAwards}
        </if>
        <if test="approveStatus != null">
            and cmp.APPROVE_STATUS=#{approveStatus}
        </if>

        <if test="pkSettleGrade != null">
            and cm.PK_SETTLE_GRADE=#{pkSettleGrade}
        </if>
        ORDER BY cmp.CREATION_TIME DESC
    </select>
    <!--查询会员变更前信息-->
    <select id="specialBusinessQuery" parameterType="com.hzs.member.base.vo.UpdateCodeVO"
            resultType="com.hzs.member.base.vo.UpdateCodeVO">
        select cm.pk_ID as pkId,
        cm.MEMBER_CODE as memberCode,
        cm.member_name as memberName,
        cm.PK_SETTLE_COUNTRY as pkSettleCountry,
        bc.SHORT_NAME as shortName,
        cm.PHONE as phone,
        cm.PK_SETTLE_GRADE pkSettleGrade,
        cm.PK_AWARDS pkAwards,
        cm.PLACE_DEPT as placeDept,
        par.member_code parMemberCode,
        par.member_name parMemberName,
        place.member_code placeMemberCode,
        place.member_name placeMemberName
        from cu_member cm
        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
        INNER JOIN BD_COUNTRY bc on bc.pk_id=cm.PK_SETTLE_COUNTRY
        where cm.del_flag = 0
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code=#{memberCode}
        </if>

        <if test="memberName != null and memberName != ''">
            and cm.member_name=#{memberName}
        </if>

        <if test="pkCountry != null">
            and cm.PK_COUNTRY=#{pkCountry}
        </if>
    </select>

    <!-- 查询会员个人资料 -->
    <select id="queryMemberData" resultType="com.hzs.member.base.vo.MemberDataVO">
        select cm.*,
               bgr.pk_transaction register_grade,
               bgs.pk_transaction settle_grade,
               bga.pk_transaction agent_grade,
               ba.pk_transaction  awards,
               bc.short_name      country_name,
               bc.pk_transaction  pk_country_transaction,
               bcs.short_name     settle_country_name,
               bcs.pk_transaction pk_settle_country_transaction
        from cu_member cm
                 left join BD_GRADE bgr
                           on bgr.pk_id = cm.pk_register_grade
                               and bgr.del_flag = 0
                 left join BD_GRADE bgs
                           on bgs.pk_id = cm.pk_settle_grade
                               and bgr.del_flag = 0
                 left join BD_AWARDS ba
                           on ba.pk_id = cm.pk_awards
                               and bgr.del_flag = 0
                 left join cu_member_agent cma
                           on cma.pk_member = cm.pk_id
                               and cma.agent_type = 1
                               and cma.del_flag = 0
                 left join BD_GRADE bga
                           on bga.pk_id = cma.AGENT_GRADE
                               and bga.del_flag = 0
                 left join BD_COUNTRY bc
                           on bc.pk_id = cm.pk_country
                 left join BD_COUNTRY bcs
                           on bcs.pk_id = cm.pk_settle_country
        where cm.del_flag = 0
          and cm.pk_id = #{memberId}
    </select>

    <update id="batchUpdateMemberNameAndMobileByPkmember">
        MERGE INTO cu_member m
        USING
        (
        <foreach collection="businessMemberList" item="item" index="index" separator="union">
            select #{item.pkMember} pk_member,
            <if test='businessType == "100"'>
                #{item.newValue} member_name
            </if>
            <if test='businessType == "101"'>
                #{item.newValue} phone
            </if>
            <if test='businessType == "114"'>
                #{item.newValue} EMAIL
            </if>
            FROM DUAL
        </foreach>
        ) t
        ON ( t.pk_member=m.pk_id and m.pk_id in
        <foreach collection="businessMemberList" item="item" open="(" close=")" separator=",">
            #{item.pkMember}
        </foreach>)
        WHEN MATCHED THEN
        UPDATE SET
        <if test='businessType == "100"'>
            m.member_name = t.member_name,
        </if>
        <if test='businessType == "101"'>
            m.phone = t.phone,
        </if>
        <if test='businessType == "114"'>
            m.EMAIL = t.EMAIL,
        </if>
        m.MODIFIED_TIME = sysdate,
        m.pk_modified = #{updatePkMember}
    </update>


    <update id="batchUpdateMemberByBusinessType" parameterType="com.hzs.member.handlebusiness.vo.HandleBusinessVO">
        update cu_member
        <set>
            <foreach collection="handleBusinessList" item="item" index="index" separator=",">
                <if test='item.businessType == "103"'>
                    <foreach collection="item.businessValueList" index="index" item="value">
                        <if test='value == "3"'>
                            login_pwd = #{loginPwd},login_password = #{loginPassword},
                            pay_pwd = #{payPwd},pay_password = #{payPassword}
                        </if>
                        <if test='value == "1"'>
                            login_pwd = #{loginPwd},login_password = #{loginPassword}
                        </if>
                        <if test='value == "2"'>
                            pay_pwd = #{payPwd},pay_password = #{payPassword}
                        </if>
                    </foreach>
                </if>
                <if test='item.businessType == "106"'>
                    <foreach collection="item.businessValueList" index="index" item="value">
                        pk_register_grade = #{value}
                    </foreach>
                </if>
                <if test='item.businessType == "113"'>
                    <foreach collection="item.businessValueList" index="index" item="value">
                        pk_settle_grade = #{value}
                    </foreach>
                </if>
                <if test='item.businessType == "107"'>
                    <foreach collection="item.businessValueList" index="index" item="value">
                        pk_awards = #{value}
                    </foreach>
                </if>
                <if test='item.businessType == "115"'>
                    <foreach collection="item.businessValueList" index="index" item="value">
                        pk_country = #{value}
                    </foreach>
                </if>
                <if test='item.businessType == "116"'>
                    <foreach collection="item.businessValueList" index="index" item="value">
                        account_status = #{value}
                    </foreach>
                </if>
                <if test='item.businessType == "117"'>
                    <foreach collection="item.businessValueList" index="index" item="value">
                        income_status = #{value}
                    </foreach>
                </if>

                <if test='item.businessType == "119 "'>
                    <foreach collection="item.businessValueList" index="index" item="value">
                        <if test='value == "1"'>
                            purchase_status = 0
                        </if>
                        <if test="index != (item.businessValueList.size() - 1) ">
                            ,
                        </if>
                        <if test='value == "2"'>
                            share_status = 0
                        </if>
                    </foreach>
                </if>
                <if test='item.businessType == "120"'>
                    <foreach collection="item.businessValueList" index="index" item="value">
                        register_authority = #{value}
                    </foreach>
                </if>
                <if test='item.businessType == "122"'>
                    <foreach collection="item.businessValueList" index="index" item="value">
                        is_maker_space = #{value}
                    </foreach>
                </if>
                <if test='item.businessType == "142"'>
                    <foreach collection="item.businessValueList" index="index" item="value">
                        super_studio = #{value}
                    </foreach>
                </if>
                <if test='item.businessType == "143"'>
                    <foreach collection="item.businessValueList" index="index" item="value">
                        is_dealer = #{value}
                    </foreach>
                </if>
                <if test='item.businessType == "148"'>
                    <foreach collection="item.businessValueList" index="index" item="value">
                        LECTURER_LEVEL = #{value}
                    </foreach>
                </if>
                <if test='item.businessType == "149"'>
                    <foreach collection="item.businessValueList" index="index" item="value">
                        SYSTEM_LEVEL = #{value}
                    </foreach>
                </if>
            </foreach>
            ,MODIFIED_TIME = sysdate,
            PK_MODIFIED = #{updatePkMember}
        </set>
        where pk_id in
        <foreach collection="businessMemberList" item="item" open="(" close=")" separator=",">
            #{item.pkMember}
        </foreach>
    </update>

    <select id="selectBiddingList" resultType="com.hzs.member.marketnews.vo.UserInvestmentVo">
        select
        cm.MEMBER_CODE memberCode,cm.MEMBER_NAME memberName,cm.PK_REGISTER_GRADE pkRegisterGrade,cm.CREATION_TIME
        creationTime,
        cm.PK_PARENT pkParent,cm.PK_PLACE_PARENT pkPlaceParent,
        (select nvl(sum(so.ORDER_AMOUNT),0) from SA_ORDER so where so.PK_MEMBER = cm.PK_ID
        and so.ORDER_TYPE = 1
        and so.ORDER_STATUS = 1
        and so.DEL_FLAG = 0
        ) regMoney,
        (select nvl(sum(so.ORDER_ACHIEVE),0) from SA_ORDER so where so.PK_MEMBER = cm.PK_ID
        and so.ORDER_TYPE = 1
        and so.ORDER_STATUS = 1
        and so.DEL_FLAG = 0
        ) regPv,
        (mbp.ROUND+1) round,
        mbp.SECOND second,
        so.ORDER_TYPE orderType,cm.PAY_TIME payTime,cm.PLACE_DEPT placeDept
        from CU_MEMBER_BONUS_PUSH mbp
        left join cu_member_bonus mb on mbp.PK_BONUS = mb.PK_ID
        left join cu_member cm on cm.PK_ID = mb.PK_MEMBER
        left join SA_ORDER so on so.PK_ID = mbp.PK_ORDER
        where cm.DEL_FLAG = 0
        and cm.PAY_STATUS = 1
        <if test="memberInfo != null and memberInfo != ''">
            and (cm.member_code=#{memberInfo} or cm.member_name=#{memberInfo})
        </if>
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code=#{memberCode}
        </if>
        <if test="pkCountry != null">
            and cm.PK_COUNTRY=#{pkCountry}
        </if>
        <if test="memberName != null and memberName != ''">
            and cm.member_name=#{memberName}
        </if>
        <if test="startCreationTime != null">
            and cm.creation_time >= #{startCreationTime}
        </if>
        <if test="endCreationTime != null">
            and cm.creation_time &lt; #{endCreationTime}
        </if>
        order by mbp.ROUND asc ,mbp.SECOND asc
    </select>

    <!--特殊配置-修改结算国列表-->
    <select id="upseCountryList" parameterType="com.hzs.member.base.vo.UpdateSettleCountryVO"
            resultType="com.hzs.member.base.vo.UpdateSettleCountryVO">
        select cm.pk_ID as pkId,
        cm.MEMBER_CODE as memberCode,
        cm.member_name as memberName,
        cmp.PK_ID as serviceLogId,
        cmp.APPROVE_NUMBER as changeNumber,
        cmp.creation_time as creationTime,
        cm.PK_SETTLE_COUNTRY as pkSettleCountry,
        bc.SHORT_NAME as oldValue,
        bcc.SHORT_NAME as newValue,
        cmp.NEW_VALUE as newSettleCountry,
        cmp.SINGLE_AMOUNT as cost
        from cu_member cm
        INNER JOIN (
        select a.PK_ID,a.pk_member, a.NEW_VALUE, a.APPROVE_NUMBER,
        a.creation_time,a.APPROVE_STATUS,a.BUSINESS_NO,
        a.SINGLE_AMOUNT
        from CU_MEMBER_SERVICE_LOG a
        where a.EDIT_TYPE=124
        <if test="businessNo != null and businessNo != ''">
            and a.BUSINESS_NO=#{businessNo}
        </if>
        ) cmp on cm.pk_ID=cmp.pk_member
        LEFT JOIN BD_COUNTRY bc on bc.PK_ID=cm.PK_SETTLE_COUNTRY
        LEFT JOIN BD_COUNTRY bcc on bcc.PK_ID=cmp.NEW_VALUE
        where cm.del_flag = 0
        <if test="memberName != null and memberName != ''">
            and cm.member_name like #{memberName} || '%'
        </if>
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code like #{memberCode} || '%'
        </if>
        <if test="pkCountry != null">
            and cm.PK_COUNTRY=#{pkCountry}
        </if>
        <if test="approveStatus != null">
            and cmp.APPROVE_STATUS=#{approveStatus}
        </if>
        ORDER BY cmp.CREATION_TIME DESC
    </select>

    <!--特殊配置 修改结算国列表-->
    <select id="upsettleCountryList" parameterType="com.hzs.member.base.vo.UpdateSettleCountryVO"
            resultType="com.hzs.member.base.vo.UpdateSettleCountryVO">
        select
        cm.MEMBER_CODE as memberCode,
        cm.member_name as memberName,
        cm.PHONE phone,
        cmp.PK_ID pkId,
        cmp.PK_MEMBER pkMember,
        cmp.APPROVE_NUMBER changeNumber,
        cmp.CREATION_TIME creationTime,
        bc.SHORT_NAME as oldValue,
        bcc.SHORT_NAME as newValue,
        aw.PK_TRANSACTION pkAwards ,
        ver.VERTEX_NAME as vertexName,
        ct.TEAM_NAME as teamName
        from CU_MEMBER_SERVICE_LOG cmp
        LEFT JOIN CU_SETTLE_COUNTRY_DETAILED b on cmp.PK_ID=b.PK_SERVICE_LOG
        INNER JOIN cu_member cm on cm.pk_ID=cmp.pk_member
        LEFT JOIN BD_COUNTRY bc on bc.PK_ID=cmp.OLD_VALUE
        LEFT JOIN BD_COUNTRY bcc on bcc.PK_ID=cmp.NEW_VALUE
        LEFT JOIN BD_AWARDS aw on aw.PK_ID=cm.PK_AWARDS
        LEFT JOIN cu_member_team ct ON ct.pk_id = cm.pk_team_code
        left join bd_vertex ver on ver.pk_id=ct.PK_BD_VERTEX
        where cmp.EDIT_TYPE = 124 and cm.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="businessNo != null and businessNo != ''">
            and cm.BUSINESS_NO=#{businessNo}
        </if>
        <if test="pkCountry != null">
            and b.PK_COUNTRY=#{pkCountry}
        </if>
        <if test="approveStatus != null">
            and cmp.APPROVE_STATUS=#{approveStatus}
        </if>
        ORDER BY cmp.CREATION_TIME DESC
    </select>

    <!--修改政策币列表-->
    <select id="upPolicyCurrencyList" parameterType="com.hzs.member.base.vo.UpPolicyCurrencyVO"
            resultType="com.hzs.member.base.vo.UpPolicyCurrencyVO">
        select
        cm.MEMBER_CODE as memberCode,
        cm.member_name as memberName,
        cm.PHONE phone,
        cmp.PK_ID pkId,
        cmp.PK_MEMBER pkMember,
        cmp.APPROVE_NUMBER changeNumber,
        cmp.CREATION_TIME creationTime,
        cmp.OLD_VALUE oldValue,
        cmp.NEW_VALUE newValue,
        aw.PK_TRANSACTION pkAwards ,
        ver.VERTEX_NAME as vertexName,
        ct.TEAM_NAME as teamName
        from CU_MEMBER_SERVICE_LOG cmp
        LEFT JOIN cu_member cm on cm.pk_ID=cmp.pk_member
        LEFT JOIN BD_AWARDS aw on aw.PK_ID=cm.PK_AWARDS
        LEFT JOIN cu_member_team ct ON ct.pk_id = cm.pk_team_code
        left join bd_vertex ver on ver.pk_id=cm.pk_vertex
        where cmp.EDIT_TYPE = 125 and cm.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="businessNo != null and businessNo != ''">
            and cm.BUSINESS_NO=#{businessNo}
        </if>
        <if test="pkBdVertex != null">
            and ct.PK_BD_VERTEX=#{pkBdVertex}
        </if>

        <if test="pkAwards != null">
            and cm.PK_AWARDS=#{pkAwards}
        </if>
        <if test="pkTeamCode != null">
            and cm.pk_team_code=#{pkTeamCode}
        </if>
        <if test="pkCountry != null">
            and cmp.PK_COUNTRY=#{pkCountry}
        </if>

        <if test="approveStatus != null">
            and cmp.APPROVE_STATUS=#{approveStatus}
        </if>
        <if test="startDate != null and endDate != null">
            and cmp.creation_time between #{startDate, jdbcType=TIMESTAMP} and #{endDate, jdbcType=TIMESTAMP}
        </if>
        ORDER BY cmp.CREATION_TIME DESC
    </select>

    <select id="checkCecharge" parameterType="java.lang.Long"
            resultType="java.lang.Integer">
        select count(1)
        from cu_member_recharge
        where APPROVE_STATE in (0, 1)
          and PK_MEMBER = #{pkMember}
          and DEL_FLAG = 0
    </select>

    <select id="checkWithdraw" parameterType="java.lang.Long"
            resultType="java.lang.Integer">
        select count(1)
        from cu_member_withdraw
        where PK_MEMBER = #{pkMember}
          and APPROVE_STATE not in (4, 5, 6)
          and STATUS = 0
          and DEL_FLAG = 0
    </select>

    <select id="checkAccount" parameterType="java.lang.Long"
            resultType="java.lang.Integer">
        select count(1)
        from cu_member_account
        where (ACCOUNT1 > 0 or
               ACCOUNT2 > 0 or
               ACCOUNT3 > 0 or
               ACCOUNT4 > 0 or
               ACCOUNT5 > 0 or
               ACCOUNT7 > 0 or
               ACCOUNT8 > 0 or
               ACCOUNT9 > 0 or
               ACCOUNT10 > 0)
          and PK_MEMBER = #{pkMember}
    </select>
    <!--查询会员是否存在未完成基础业务办理-->
    <select id="checkmsLogCount"
            resultType="java.lang.Integer">
        select count(1)
        from CU_MEMBER_SERVICE_LOG
        where (APPROVE_STATUS = 1 or
        APPROVE_STATUS = 2 or
        APPROVE_STATUS = 3)
        and PK_MEMBER = #{pkMember}
        <if test="editType!= null ">
            and EDIT_TYPE = #{editType}
        </if>
    </select>
    <!--查询会员是否存在未完成注水业绩业务-->
    <select id="checkMemberAchieveCount" parameterType="java.lang.Long"
            resultType="java.lang.Integer">
        select count(1)
        from CU_MEMBER_ACHIEVE_LOG
        where (APPROVE_STATUS = 1 or APPROVE_STATUS = 2 or APPROVE_STATUS = 3)
          and PK_MEMBER = #{pkMember}
    </select>

    <!-- 查询选择会员列表 -->
    <select id="queryMemberSelect" resultType="com.hzs.common.domain.member.ext.CuMemberExt">
        select cm.pk_id,
        cm.member_code,
        cm.member_name,
        cm.phone,
        cm.pk_register_grade,
        bdr.pk_transaction register_grade_key,
        cm.pk_settle_grade,
        bds.pk_transaction settle_grade_key,
        cm.pk_awards,
        ba.pk_transaction awards_key
        from cu_member cm
        inner join bd_grade bdr
        on bdr.pk_id = cm.pk_register_grade
        inner join bd_grade bds
        on bds.pk_id = cm.pk_settle_grade
        inner join bd_awards ba
        on ba.pk_id = cm.pk_awards
        where cm.del_flag = 0
        and cm.pk_settle_country = #{pkCountry}
        <if test="param.memberCode != null and param.memberCode != ''">
            and cm.member_code like #{param.memberCode} || '%'
        </if>
        <if test="param.memberName != null and param.memberName != ''">
            and cm.member_name like #{param.memberName} || '%'
        </if>
        <if test="param.phone != null and param.phone != ''">
            and cm.phone = #{param.phone}
        </if>
        <if test="param.pkRegisterGrade != null and param.pkRegisterGrade.size > 0">
            and cm.pk_register_grade in
            <foreach collection="param.pkRegisterGrade" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="param.pkSettleGrade != null and param.pkSettleGrade.size > 0">
            and cm.pk_settle_grade in
            <foreach collection="param.pkSettleGrade" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="param.pkAwards != null and param.pkAwards.size > 0">
            and cm.pk_awards in
            <foreach collection="param.pkAwards" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="param.memberCodeList != null and param.memberCodeList.size > 0">
            and cm.member_code in
            <foreach collection="param.memberCodeList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        order by cm.creation_time desc
    </select>

    <select id="queryCuMemberLastPlaceParent" resultMap="MemberResultMap">
        select cu.place_dept,
        cu.pk_id,
        cu.member_code,
        cu.member_name,
        cu.phone,
        cu.category,
        cu.pk_settle_grade,
        bg.grade_value
        from (
        <foreach item="item" index="index" collection="placeDeptList" separator=" union ">
            select *
            from (
            select #{item} place_dept,
            t.pk_id,
            t.member_code,
            t.member_name,
            t.phone,
            t.category,
            t.pk_settle_grade,
            level lev
            from cu_member t
            where t.place_dept = 1
            and t.del_flag = 0
            start
            with t.pk_id = (select u.pk_id
            from cu_member u
            where u.del_flag=0 and u.pk_place_parent=#{pkMember}
            and place_dept = #{item})
            connect by prior
            t.pk_id = (select u.pk_place_parent
            from cu_member u
            where u.del_flag=0 and u.pk_id = t.pk_id
            and u.place_dept = 1)
            union
            select t.place_dept, t.pk_id, t.member_code, t.member_name, t.phone, t.category, t.pk_settle_grade, 0 lev
            from cu_member t
            where t.place_dept = #{item} and t.del_flag = 0 and t.pk_place_parent=#{pkMember}
            union
            select #{item} place_dept, t.pk_id, t.member_code, t.member_name, t.phone, t.category, t.pk_settle_grade, -1 lev
            from cu_member t
            where t.del_flag = 0 and t.pk_id=#{pkMember}
            order by lev desc) n
            where rownum = 1
        </foreach>
        ) cu
        left join bd_grade bg
        on cu.pk_settle_grade = bg.pk_id
        order by place_dept
    </select>

    <select id="selectByMemberRealInfo" resultType="com.hzs.member.base.vo.MemberRealInfoVO">
        select
        cm.MEMBER_CODE as memberCode,
        cm.MEMBER_NAME memberName,
        cm.PHONE phone,
        bg.PK_TRANSACTION as pkRegisterGrade,
        bgg.PK_TRANSACTION as pkSettleGrade,
        ba.PK_TRANSACTION as pkAwards,
        CASE WHEN ma.SEX is null THEN cm.SEX ELSE ma.SEX end as sex,
        cm.birth_date birthDate,
        ma.ID_TYPE idType,
        ma.ID_CARD idCard,
        ma.ID_FRONT idFront,
        ma.ID_BACK idBack,
        ma.PK_PROVINCE pkProvince,
        ma.PK_CITY pkCity,
        ma.PK_COUNTY pkCounty,
        ma.ADDRESS address,
        bb.BANK_NAME bankName,
        ma.SUB_BANK_NAME subBankName,
        ma.ACCOUNT_NAME accountName,
        ma.PHONE reservedPhone,
        ma.CARD_NUMBER cardNumber,
        cm.EMAIL email,
        ma.CREATION_TIME certificationTime,
        cm.CREATION_TIME creationTime,
        cm.PAY_TIME payTime,
        cm.DIRECT_PUSH_NUMBER directPushNumber
        from CU_MEMBER cm
        left join CU_MEMBER_AUTHENTICATION ma on ma.PK_MEMBER = cm.PK_ID and ma.del_flag = 0
        left join BD_BANK bb on bb.PK_ID = ma.pk_bank
        left join BD_GRADE bg on bg.pk_id=cm.PK_REGISTER_GRADE
        left join BD_GRADE bgg on bgg.pk_id=cm.PK_SETTLE_GRADE
        left join BD_AWARDS ba on ba.pk_id=cm.PK_AWARDS
        where cm.del_flag = 0 and 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 = #{phone}
        </if>
        <if test="pkRegisterGrade != null">
            and cm.PK_REGISTER_GRADE = #{pkRegisterGrade}
        </if>
        <if test="pkAwards != null">
            and cm.PK_AWARDS = #{pkAwards}
        </if>
        <if test="pkSettleGrade != null">
            and cm.PK_SETTLE_GRADE = #{pkSettleGrade}
        </if>
        <if test="idType != null">
            and ma.ID_TYPE = #{idType}
        </if>
        <if test="idCard != null and idCard != ''">
            and ma.ID_CARD = #{idCard}
        </if>
        <if test="birthDate != null">
            and cm.BIRTH_DATE = #{birthDate}
        </if>
        <if test="pkProvince != null">
            and ma.PK_PROVINCE = #{pkProvince}
        </if>
        <if test="pkCity != null">
            and ma.PK_CITY = #{pkCity}
        </if>
        <if test="pkCounty != null">
            and ma.PK_COUNTY = #{pkCounty}
        </if>
        <if test="address != null and address != ''">
            and ma.ADDRESS like #{address} ||'%'
        </if>
        <if test="sex != null">
            and (cm.SEX = #{sex} or ma.SEX = #{sex})
        </if>
        <if test="bankName != null and bankName != ''">
            and ma.BANK_NAME like #{bankName}||'%'
        </if>
        <if test="subBankName != null and subBankName != ''">
            and ma.SUB_BANK_NAME like #{subBankName}||'%'
        </if>
        <if test="cardNumber != null and cardNumber != ''">
            and ma.CARD_NUMBER like #{cardNumber}||'%'
        </if>
        <if test="email != null and email != ''">
            and cm.EMAIL like #{email}||'%'
        </if>
        <if test="startCertificationTime != null">
            and ma.CREATION_TIME &gt;= #{startCertificationTime}
        </if>
        <if test="endCertificationTime != null">
            and ma.CREATION_TIME &lt;= #{endCertificationTime}
        </if>
        <if test="startCreationTime != null">
            and cm.CREATION_TIME &gt;= #{startCreationTime}
        </if>
        <if test="endCreationTime != null">
            and cm.CREATION_TIME &lt;= #{endCreationTime}
        </if>
        <if test="startPayTime != null">
            and cm.PAY_TIME &gt;= #{startPayTime}
        </if>
        <if test="endPayTime != null">
            and cm.PAY_TIME &lt;= #{endPayTime}
        </if>
    </select>

    <select id="selectRegList" resultType="com.hzs.member.marketnews.vo.UserInvestmentVo">
        select
        cm.MEMBER_CODE memberCode,cm.MEMBER_NAME memberName,cm.PK_REGISTER_GRADE pkRegisterGrade,cm.CREATION_TIME
        creationTime,
        cm.PK_PARENT pkParent,cm.PK_PLACE_PARENT pkPlaceParent,
        nvl(a.regMoney,0)regMoney,
        nvl(a.regPv,0)regPv,
        cm.PAY_TIME payTime,cm.PLACE_DEPT placeDept
        from cu_member cm
        left join (
        select nvl(sum(so.ORDER_AMOUNT),0) regMoney ,nvl(sum(so.ORDER_ACHIEVE),0) regPv,so.PK_MEMBER from SA_ORDER so where
        so.ORDER_TYPE = 1
        and so.ORDER_STATUS in (1,7,24)
        and so.DEL_FLAG = 0
        group by so.PK_MEMBER
        )a on a.PK_MEMBER = cm.PK_ID
        where cm.DEL_FLAG = 0
        and cm.PAY_STATUS = 1
        and cm.CATEGORY = 0
        <if test="memberInfo != null and memberInfo != ''">
            and (cm.member_code=#{memberInfo} or cm.member_name=#{memberInfo})
        </if>
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code=#{memberCode}
        </if>
        <if test="pkRegisterGrade != null">
            and cm.PK_REGISTER_GRADE=#{pkRegisterGrade}
        </if>
        <if test="pkCountry != null">
            and cm.PK_COUNTRY=#{pkCountry}
        </if>
        <if test="pkCreator != null">
            and cm.PK_CREATOR=#{pkCreator}
        </if>

        <if test="memberName != null and memberName != ''">
            and cm.member_name=#{memberName}
        </if>
        <if test="startCreationTime != null">
            and cm.creation_time >= #{startCreationTime}
        </if>
        <if test="endCreationTime != null">
            and cm.creation_time &lt; #{endCreationTime}
        </if>
        order by cm.CREATION_TIME desc
    </select>

    <select id="findNoPayMember" resultType="string">
        select m.member_code
        from cu_member m
        where m.del_flag = 0
        and m.category = 0
        and m.pay_status = 0
        and m.pk_settle_country = #{pkCountry}
        and m.member_code in
        <foreach collection="memberCodes" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>
    <select id="queryMemberByCondition" resultType="com.hzs.common.domain.member.ext.CuMemberExt">
        select cm.pk_id,cm.member_code,cm.member_name,cm.phone,cm.pk_settle_country,cm.pk_parent,
        cm.pk_place_parent,cm.place_dept,cm.pk_team_code,cm.pk_center_code,cm.category,cm.pk_settle_grade,
        cm.pk_awards,cm.purchase_status,cm.order_source,cm.is_real_name,cm.is_bus_license,cm.is_maker_space,
        cm.share_status,cm.pay_pwd,cm.register_authority,cm.nick_name,bg.grade_value
        from cu_member cm
        left join bd_grade bg
        on cm.pk_settle_grade = bg.pk_id
        where cm.del_flag=0
        <if test="pkSettleCountry != null">
            and cm.pk_settle_country=#{pkSettleCountry}
        </if>
        <if test="pkId != null ">
            and cm.pk_id = #{pkId}
        </if>
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code = #{memberCode}
        </if>
        <if test="memberName != null and memberName != ''">
            and cm.member_name = #{memberName}
        </if>
        <if test="phone != null and phone != ''">
            and cm.phone = #{phone}
        </if>
        <if test="pkParent != null and pkParent != ''">
            and cm.pk_parent = #{pkParent}
        </if>
        <if test="pkPlaceParent != null and pkPlaceParent != ''">
            and cm.pk_place_parent = #{pkPlaceParent}
        </if>
        <if test="placeDept != null and placeDept != ''">
            and cm.place_dept = #{placeDept}
        </if>
    </select>
    <!--查询最新会员-->
    <select id="queryRecentlyMember" resultType="com.hzs.common.domain.member.base.CuMember">
        select max(COUNTRY_CODE) COUNTRY_CODE
        from cu_member
        where pk_settle_country = #{pkCountry}
          and COUNTRY_CODE is not null
    </select>

    <!--查询最新会员国际编号-->
    <select id="queryInternationalMember" resultType="com.hzs.common.domain.member.base.CuMember">
        select max(to_number(substr(global_code, 3))) global_code
        from cu_member
        where global_code is not null
    </select>


    <select id="parentList" resultType="com.hzs.member.base.vo.ParentMemberVo">
        select a.* from (
        select cm.CONSUME_MONEY consumeMoney,cm.CONSUME_ACHIEVE consumeAchieve,cm.member_code memberCode,cm.member_name memberName,cm.PK_REGISTER_GRADE pkRegisterGrade,
        cm.CREATION_TIME creationTime
        from CU_MEMBER cm
        where 1 = 1 and cm.DEL_FLAG = 0 and cm.pay_status=1 and cm.PK_SETTLE_GRADE != 1
        and cm.category = 0
        <if test="memberInfo != null and memberInfo != ''">
            and (cm.member_code=#{memberInfo} or cm.member_name=#{memberInfo})
        </if>
        <if test="pkParent != null">
            and cm.PK_PARENT = #{pkParent}
        </if>
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code = #{memberCode}
        </if>
        <if test="memberName != null and memberName != ''">
            and cm.member_name = #{memberName}
        </if>
        <if test="startCreateTime != null">
            and cm.CREATION_TIME >= #{startCreateTime}
        </if>
        <if test="endCreateTime != null">
            and cm.CREATION_TIME &lt;= #{endCreateTime}
        </if>

        union all

        select cm.CONSUME_MONEY consumeMoney,cm.CONSUME_ACHIEVE consumeAchieve,cm.member_code memberCode,cm.member_name memberName,cm.PK_REGISTER_GRADE pkRegisterGrade,
        cm.CREATION_TIME creationTime
        from CU_MEMBER cm
        where 1 = 1 and cm.DEL_FLAG = 0 and cm.pay_status=1 and cm.PK_SETTLE_GRADE = 1
        and cm.category = 0
        and (
        (select count(so.PK_ID) from sa_order so where so.PK_MEMBER = cm.pk_id and so.DEL_FLAG = 0 and so.ORDER_STATUS = 1) > 0
        )
        <if test="memberInfo != null and memberInfo != ''">
            and (cm.member_code=#{memberInfo} or cm.member_name=#{memberInfo})
        </if>
        <if test="pkParent != null">
            and cm.PK_PARENT = #{pkParent}
        </if>
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code = #{memberCode}
        </if>
        <if test="memberName != null and memberName != ''">
            and cm.member_name = #{memberName}
        </if>
        <if test="startCreateTime != null">
            and cm.CREATION_TIME >= #{startCreateTime}
        </if>
        <if test="endCreateTime != null">
            and cm.CREATION_TIME &lt;= #{endCreateTime}
        </if>
        ) a
        order by a.creationTime desc
    </select>

    <!-- 校验会员编号是否存在 -->
    <select id="checkMemberCodeExist" resultType="com.hzs.member.base.dto.MemberCountDTO">
        select tmp.member_code, count(tmp.member_code) member_count
        from (
        select cm.member_code
        from cu_member cm
        where cm.del_flag = 0
        and (cm.member_code in ('0'
        <foreach collection="codeList" item="item" close=")" index="index">
            <choose>
                <when test="index % 500 == 0">) or cm.member_code in (#{item}</when>
                <otherwise>, #{item}</otherwise>
            </choose>
        </foreach>
        )
        <if test="checkEmpty != null and checkEmpty">
            <!-- 需要校验批量空单数据 -->
            union all
            select cmed.member_code
            from CU_MEMBER_EMPTY_DETAIL cmed
            inner join CU_MEMBER_EMPTY cme
            on cme.pk_id = cmed.pk_member_empty
            and cme.status in (1, 2, 4)
            and cme.del_flag = 0
            where cmed.del_flag = 0
            <if test="excludeMemberEmpty != null">
                and cmed.pk_member_empty != #{excludeMemberEmpty}
            </if>
            and (cmed.member_code in ('0'
            <foreach collection="codeList" item="item" close=")" index="index">
                <choose>
                    <when test="index % 500 == 0">) or cmed.member_code in (#{item}</when>
                    <otherwise>, #{item}</otherwise>
                </choose>
            </foreach>
            )
        </if>
        ) tmp
        group by tmp.member_code
    </select>

    <select id="queryCuMemberByMemberList" resultType="com.hzs.member.base.vo.CuMemberVO">
        SELECT cm.PK_ID,
        cm.member_code,
        cm.PAY_TIME,
        cm.CHANGE_NUMBER,
        cm.CREATION_TIME,
        cm.INCOME_STATUS,
        cm.IS_REAL_NAME,
        cm.ACCOUNT_STATUS,
        cm.member_name,
        cm.phone,
        cm.customer_type,
        cm.purchase_status,
        cm.share_status,
        cm.super_studio,
        cm.LECTURER_LEVEL,
        cm.SYSTEM_LEVEL,
        cm.source,
        cm.consume_achieve,
        cm.pay_status,
        cm.email,
        cm.register_authority,
        cm.order_source,
        cm.is_bus_license,
        cm.is_maker_space,
        cm.edit_number,
        cm.consume_money,
        cm.CATEGORY as category,
        cm.IS_DEALER,
        cm.EXPIRE_DATE expireDate,
        cma.IS_TRANSFER as isTransfer,
        cma.IS_WITHDRAW as isWithdraw,
        cma.IS_CONSUME as isConsume,
        cma.TRANSFER_STATUS as transferStatus,
        ver.VERTEX_NAME as vertexName,
        gr.PK_TRANSACTION as PK_REGISTER_GRADE,
        grr.PK_TRANSACTION as PK_SETTLE_GRADE,
        awa.PK_TRANSACTION as PK_AWARDS,
        ct.TEAM_NAME as teamName,
        par.member_code par_member_code,
        par.member_name par_member_name,
        place.member_code place_member_code,
        place.member_name place_member_name,
        cm.place_dept,
        center.member_code center_member_code,
        center.member_name center_member_name,
        cmat.AGENT_GRADE,
        cm.DIRECT_PUSH_NUMBER
        FROM cu_member cm
        inner join CU_MEMBER_ACCOUNT cma
        on cm.pk_id = cma.PK_MEMBER
        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 cu_member_team ct
        ON ct.pk_id = cm.pk_team_code
        LEFT JOIN cu_member center
        ON center.pk_id = cm.pk_center_code
        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 bd_grade grr
        on grr.pk_id = cm.PK_SETTLE_GRADE
        left join bd_vertex ver
        on cm.pk_vertex = ver.pk_id
        left join (select pk_member,bg.pk_transaction AGENT_GRADE from cu_member_agent ca
        inner join bd_grade bg
        on ca.agent_grade=bg.pk_id
        where ca.del_flag = 0
        and ca.agent_type = 1) cmat
        on cm.pk_id =cmat.pk_member
        WHERE cm.del_flag = 0 and cm.pk_id in
        <foreach collection="cuMemberVOList" item="item" open="(" close=")" separator=",">
            #{item.pkId}
        </foreach>
        order by cm.CREATION_TIME desc
    </select>

    <!--会员信息导出-->
    <select id="queryCuMemberByMemberListExcel" resultType="com.hzs.member.base.vo.CuMemberVO">
        SELECT cm.PK_ID,
        cm.member_code,
        cm.PAY_TIME,
        cm.CHANGE_NUMBER,
        cm.CREATION_TIME,
        cm.INCOME_STATUS,
        cm.IS_REAL_NAME,
        cm.ACCOUNT_STATUS,
        cm.member_name,
        cm.phone,
        cm.customer_type,
        cm.CATEGORY as category,
        cm.purchase_status,
        cm.share_status,
        cm.super_studio,
        cm.LECTURER_LEVEL,
        cm.SYSTEM_LEVEL,
        cm.source,
        cm.consume_achieve,
        cm.pay_status,
        cm.email,
        cm.register_authority,
        cm.order_source,
        cm.is_bus_license,
        cm.is_maker_space,
        cm.edit_number,
        cm.consume_money,
        cm.IS_DEALER,
        cm.EXPIRE_DATE expireDate,
        cma.IS_TRANSFER as isTransfer,
        cma.IS_WITHDRAW as isWithdraw,
        cma.IS_CONSUME as isConsume,
        cma.TRANSFER_STATUS as transferStatus,
        ver.VERTEX_NAME as vertexName,
        gr.PK_TRANSACTION as PK_REGISTER_GRADE,
        grr.PK_TRANSACTION as PK_SETTLE_GRADE,
        awa.PK_TRANSACTION as PK_AWARDS,
        ct.TEAM_NAME as teamName,
        par.member_code par_member_code,
        par.member_name par_member_name,
        place.member_code place_member_code,
        place.member_name place_member_name,
        cm.place_dept,
        center.member_code center_member_code,
        center.member_name center_member_name,
        cmat.AGENT_GRADE
        FROM cu_member cm
        inner join CU_MEMBER_ACCOUNT cma
        on cm.pk_id = cma.PK_MEMBER
        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 cu_member_team ct
        ON ct.pk_id = cm.pk_team_code
        LEFT JOIN cu_member center
        ON center.pk_id = cm.pk_center_code
        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 bd_grade grr
        on grr.pk_id = cm.PK_SETTLE_GRADE
        left join bd_vertex ver
        on cm.pk_vertex = ver.pk_id
        left join (select pk_member,bg.pk_transaction AGENT_GRADE from cu_member_agent ca
        inner join bd_grade bg
        on ca.agent_grade=bg.pk_id
        where ca.del_flag = 0
        and ca.agent_type = 1) cmat
        on cm.pk_id =cmat.pk_member
        WHERE cm.del_flag = 0 and cm.pk_id in
        (
        SELECT cm.PK_ID
        FROM cu_member cm
        inner join CU_MEMBER_ACCOUNT cma
        on cm.pk_id = cma.PK_MEMBER
        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 cu_member_team ct
        ON ct.pk_id = cm.pk_team_code
        LEFT JOIN cu_member center
        ON center.pk_id = cm.pk_center_code
        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 bd_grade grr
        on grr.pk_id = cm.PK_SETTLE_GRADE
        left join bd_vertex ver
        on cm.pk_vertex = ver.pk_id
        left join (select pk_member,bg.pk_transaction AGENT_GRADE from cu_member_agent ca
        inner join bd_grade bg
        on ca.agent_grade=bg.pk_id
        where ca.del_flag = 0
        and ca.agent_type = 1) cmat
        on cm.pk_id =cmat.pk_member
        WHERE cm.del_flag = 0
        <if test="pkCountry != null">
            and cm.pk_settle_country=#{pkCountry}
        </if>
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code like #{memberCode}||'%'
        </if>
        <if test="lecturerLevel != null">
            and cm.LECTURER_LEVEL=#{lecturerLevel}
        </if>
        <if test="changeNumber != null">
            and cm.CHANGE_NUMBER=#{changeNumber}
        </if>
        <if test="superStudio != null">
            and cm.super_studio=#{superStudio}
        </if>

        <if test="agentGrade != null">
            and cmat.agent_grade=#{agentGrade}
        </if>
        <if test="isTransfer != null">
            and cma.IS_TRANSFER=#{isTransfer}
        </if>
        <if test="walletStatus != null">
            and cma.IS_WITHDRAW=#{walletStatus}
        </if>
        <if test="isConsume != null">
            and cma.IS_CONSUME=#{isConsume}
        </if>
        <if test="transferStatus != null">
            and cma.TRANSFER_STATUS=#{transferStatus}
        </if>

        <if test="vertexId != null">
            and ver.PK_ID=#{vertexId}
        </if>
        <if test="teamId != null">
            and ct.PK_ID=#{teamId}
        </if>
        <if test="registerAuthority != null">
            and cm.REGISTER_AUTHORITY=#{registerAuthority}
        </if>
        <if test="isDealer != null">
            and cm.IS_DEALER=#{isDealer}
        </if>
        <if test="accountStatus != null">
            and cm.ACCOUNT_STATUS=#{accountStatus}
        </if>
        <if test="isRealName != null">
            and cm.IS_REAL_NAME=#{isRealName}
        </if>
        <if test="isBusLicense != null">
            and cm.is_bus_license=#{isBusLicense}
        </if>
        <if test="isMakerSpace != null">
            and cm.IS_MAKER_SPACE=#{isMakerSpace}
        </if>
        <if test="orderSource != null">
            and cm.order_source=#{orderSource}
        </if>

        <if test="centerMemberCode != null and centerMemberCode != ''">
            and center.member_code like #{centerMemberCode}||'%'
        </if>
        <if test="centerMemberName != null and centerMemberName != ''">
            and center.member_name like #{centerMemberName}||'%'
        </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="placeMemberCode != null and placeMemberCode != ''">
            and place.member_code like #{placeMemberCode}||'%'
        </if>
        <if test="placeMemberName != null and placeMemberName != ''">
            and place.member_name like #{placeMemberName}||'%'
        </if>

        <if test="memberName != null and memberName != ''">
            and cm.member_name like #{memberName}||'%'
        </if>
        <if test="phone != null and phone != ''">
            and cm.phone=#{phone}
        </if>
        <if test="pkRegisterGrade != null ">
            and cm.pk_register_grade =#{pkRegisterGrade}
        </if>
        <if test="pkSettleGrade != null ">
            and cm.PK_SETTLE_GRADE =#{pkSettleGrade}
        </if>

        <if test="pkAwards != null">
            and cm.pk_awards=#{pkAwards}
        </if>

        <if test="systemLevel != null">
            and cm.SYSTEM_LEVEL=#{systemLevel}
        </if>

        <if test="placeDept != null ">
            and cm.place_dept=#{placeDept}
        </if>

        <if test="teamName != null and teamName !=''">
            and ct.team_name like #{teamName}||'%'
        </if>

        <if test="startDate != null and endDate != null">
            and cm.creation_time between #{startDate, jdbcType=TIMESTAMP} and #{endDate, jdbcType=TIMESTAMP}
        </if>
        <if test="startDatePay != null and endDatePay != null">
            and cm.PAY_TIME between #{startDatePay, jdbcType=TIMESTAMP} and #{endDatePay, jdbcType=TIMESTAMP}
        </if>

        <if test="isTransfer != null ">
            and cma.IS_TRANSFER=#{isTransfer}
        </if>
        <if test="isWithdraw != null ">
            and cma.IS_WITHDRAW=#{isWithdraw}
        </if>
        <if test="isConsume != null ">
            and cma.IS_CONSUME=#{isConsume}
        </if>

        <!-- 体系权限处理 -->
        <if test="vertexList != null and vertexList.size > 0">
            and ver.pk_member in
            <foreach collection="vertexList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <!--团队权限 -->
        <if test="teamList != null and teamList.size > 0">
            and ct.pk_member in
            <foreach collection="teamList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        )
        order by cm.CREATION_TIME desc
    </select>

    <select id="selectByDeptNumberCount" resultType="long">

        select count(t.pk_id)
        from CU_MEMBER t
        where t.CATEGORY = 0
          and t.del_flag = 0
            start
        with t.PK_PLACE_PARENT = #{pkMember} and t.PLACE_DEPT = #{placeDept}
        connect by t.PK_PLACE_PARENT = prior t.PK_ID
    </select>
    <select id="selectPlaceSponsorUnderUmbrellaByCode" resultMap="MemberResultMap">
        select *
        from (select t.pk_id,
                     t.member_code,
                     t.member_name,
                     t.phone,
                     t.pk_place_parent,
                     t.pk_parent,
                     t.pk_center_code,
                     t.PLACE_DEPT
              from cu_member t
              where t.del_flag = 0 start
              with t.pk_place_parent = #{memberId}
              connect by t.pk_place_parent = prior t.pk_id) a
        where a.member_code = #{placeParentCode}
    </select>

    <!--根据用户编号、用户用户名查询用户信息-->
    <select id="selectMemberByMemberCode" resultMap="MemberResultMap">
        select m.member_code, m.member_name,m.pay_status
        from cu_member m
        where m.del_flag = 0
        and m.category = 0
        and m.pk_settle_country = #{pkCountry}
        <if test="memberCode != null and memberCode != ''">
            and m.member_code=#{memberCode}
        </if>
        <if test="memberName != null and memberName != ''">
            and m.member_name=#{memberName}
        </if>
        ORDER BY m.CREATION_TIME DESC
    </select>

    <!-- 查询最末安置人（根据会员编号） -->
    <select id="queryLastPlaceByMemberCode" resultMap="MemberResultMap">
        select *
        from (select level, cm.*
              from cu_member cm
              where cm.del_flag = 0
                and cm.place_dept = 1
                  start
              with (cm.pk_place_parent =
                  (select pk_id
                  from cu_member
                  where member_code = #{memberCode}) and
                  cm.place_dept = #{placeDept})
              connect by cm.pk_place_parent = prior cm.pk_id
              order by level desc) tmp
        where rownum = 1
    </select>

    <!-- 查询指定数量会员SEQ -->
    <select id="querySeqList" resultType="long">
        SELECT CU_MEMBER_SEQ.nextval
        FROM (select level from dual connect by #{param} >= level)
    </select>

    <!-- 根据会员编号批量查询会员信息 -->
    <select id="queryMemberListByCode" resultType="com.hzs.common.domain.member.base.CuMember">
        select cm.*
        from cu_member cm
        where cm.del_flag = 0
        and (cm.member_code in (''
        <foreach collection="memberCodeList" item="item" close=")" index="index">
            <choose>
                <when test="index % 500 == 0">) or cm.member_code in (#{item}</when>
                <otherwise>, #{item}</otherwise>
            </choose>
        </foreach>
        )
        order by cm.pk_id
    </select>

    <select id="checkPlaceSponsorUnderUmbrella" resultType="long">
        select count(1)
        from cu_member t
        where t.del_flag = 0
          and t.member_code = #{memberCode} start
        with t.pk_place_parent = #{pkMember}
        connect by t.pk_place_parent = prior t.pk_id
        order by level
    </select>
    <select id="queryBloodKinshipUnderUmbrellaCount" resultType="long">
        select count(t.PK_ID)
        from cu_member t
        where t.del_flag = 0
          and t.PK_ID = #{memberId} start
        with t.pk_id = #{pkMember}
        connect by t.pk_parent = prior t.pk_id
        order by level
    </select>
    <select id="selectBloodKinshipUnderUmbrellaByMemberIds" resultType="com.hzs.member.base.vo.MemberTeamInfoVo">
        <foreach collection="memberIds" item="memberId" separator="union">
            select count(t.pk_id) numberCount
            <if test="tableName != null and tableName != ''">
                , sum(t.CONSUME_ACHIEVE) numberAchieve
            </if>
            ,#{memberId} pkMember
            from cu_member t


            where t.del_flag = 0 and t.PAY_STATUS = 1 and t.CATEGORY = 0 and t.PK_VERTEX = (select cm.PK_VERTEX from CU_MEMBER cm where cm.pk_id = #{memberId})
            start
            with t.pk_id = #{memberId}
            connect by t.pk_parent = prior t.pk_id
        </foreach>

    </select>

    <update id="updateParentById">
        update CU_MEMBER
        set PK_PARENT          = #{pkParent},
            DIRECT_PUSH_NUMBER = #{directPushNumber}
        where PK_ID = #{pkMember}
    </update>

    <update id="updatePlaceParentAndPlaceDeptById">
        update CU_MEMBER
        set PK_PLACE_PARENT = #{pkPlaceParent},
            PLACE_DEPT      = #{placeDept}
        where PK_ID = #{pkMember}
    </update>

    <!-- 校验会员编号是否存在 -->
    <select id="checkCodeExist" resultType="string">
        select member_code
        from cu_member cm
        where cm.del_flag = 0
        and (cm.member_code in ('0'
        <foreach collection="memberCodeList" item="item" close=")" index="index">
            <choose>
                <when test="index % 500 == 0">) or cm.member_code in (#{item}</when>
                <otherwise>, #{item}</otherwise>
            </choose>
        </foreach>
        )
        union
        select member_code
        from cu_member_empty_code cmec
        where cmec.del_flag = 0
        and (cmec.member_code in ('0'
        <foreach collection="memberCodeList" item="item" close=")" index="index">
            <choose>
                <when test="index % 500 == 0">) or cmec.member_code in (#{item}</when>
                <otherwise>, #{item}</otherwise>
            </choose>
        </foreach>
        )
    </select>


    <select id="queryDateBySummary" resultType="com.hzs.member.base.vo.MemberMeritsSummaryVo">
        select sa.ORDER_TYPE         orderType,
               sum(sa.order_amount)  amount,
               sum(sa.order_achieve) achieve
        from SA_ORDER sa
        where sa.ORDER_STATUS = 1
          and sa.DEL_FLAG = 0
        group by sa.ORDER_TYPE, to_char(sa.pay_time, 'yyyy-mm-dd'), sa.PK_COUNTRY
        having to_char(sa.pay_time, 'yyyy-mm-dd') = #{time}
           and sa.PK_COUNTRY = #{pkCountry}
    </select>

    <select id="selectPlaceErrorCode" resultType="com.hzs.common.domain.member.ext.CuMemberExt">
        select m.pk_place_parent pkPlaceParent,
               m.place_dept      placeDept,
               count(1)          times
        from cu_member m
        where m.del_flag = 0
          and m.pay_status = 1
          and m.pk_place_parent is not null
          and m.category = 0
        group by m.pk_place_parent, m.place_dept
        having count(1) > 1
    </select>

    <!-- 查询会员部门列表 -->
    <select id="queryMemberPlaceDept" resultType="int">
        select cm.place_dept
        from cu_member cm
        where cm.del_flag = 0
          and cm.pk_place_parent = #{pkMember}
        order by cm.place_dept
    </select>

    <update id="updateExpireDate">
        update cu_member
        set EXPIRE_DATE = #{expireDate}
        where PK_ID = #{pkMember}
          and DEL_FLAG = 0
    </update>

    <select id="selectMemberPlaceDeptByPkMember" resultMap="MemberVO">
        select m.pk_id, m.member_code, m.member_name, m.place_dept, m.pk_settle_country
        from cu_member m
        where m.del_flag = 0
        and m.category in (0, 1)
        and m.pk_place_parent = #{pkMember}
        <if test="placeDept != null">
            and m.place_dept &lt;= #{placeDept}
        </if>
        order by m.place_dept
    </select>

    <select id="getMaxMemberDept" resultType="integer">
        select max(cm.PLACE_DEPT)
        from cu_member cm
        where cm.PK_PLACE_PARENT = #{pkMember}
          and cm.del_flag = 0
    </select>

    <select id="getNotDelPlaceParentMember" resultType="com.hzs.common.domain.member.ext.CuMemberExt">
        select cm.*
        from cu_member cm
        where cm.PK_PLACE_PARENT = #{pkMember}
          and cm.del_flag = 0
    </select>

    <!--    未激活点位列表-->
    <select id="notActiveList" parameterType="com.hzs.member.base.vo.NotActivePointVO"
            resultType="com.hzs.member.base.vo.NotActivePointVO">
        select * from (
        select cm.pk_ID as pkId,
        cm.MEMBER_CODE as memberCode,
        cm.member_name as memberName,
        cm.PHONE as phone,
        gr.PK_TRANSACTION pkSettleGrade,
        awa.PK_TRANSACTION pkAwards,
        par.member_code parMemberCode,
        par.member_name parMemberName,
        place.member_code placeMemberCode,
        place.member_name placeMemberName,
        cm.CREATION_TIME creationTime,
        cm.PAY_STATUS payStatus
        from cu_member cm
        left JOIN CU_MEMBER pat on pat.PK_PARENT=cm.PK_ID and pat.DEL_FLAG=0
        left JOIN CU_MEMBER ppt on ppt.pk_place_parent=cm.pk_id and ppt.DEL_FLAG=0
        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
        INNER join bd_grade grr on grr.pk_id=cm.PK_SETTLE_GRADE
        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
        where cm.del_flag = 0
        and (cm.CATEGORY=1 or cm.CATEGORY=2)
        and awa.del_flag = 0
        and pat.PK_ID is null
        and ppt.PK_ID is null
        <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="pkCountry != null">
            and cm.PK_SETTLE_COUNTRY=#{pkCountry}
        </if>

        <if test="pkAwards != null">
            and cm.pk_awards=#{pkAwards}
        </if>
        <if test="placeMemberCode != null and placeMemberCode != ''">
            and place.member_code like #{placeMemberCode} || '%'
        </if>
        <if test="placeMemberName != null and placeMemberName != ''">
            and place.member_name like #{placeMemberName} || '%'
        </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="pkRegisterGrade != null">
            and cm.PK_REGISTER_GRADE=#{pkRegisterGrade}
        </if>
        UNION ALL
        select cm.pk_ID as pkId,
        cm.MEMBER_CODE as memberCode,
        cm.member_name as memberName,
        cm.PHONE as phone,
        gr.PK_TRANSACTION pkSettleGrade,
        awa.PK_TRANSACTION pkAwards,
        par.member_code parMemberCode,
        par.member_name parMemberName,
        place.member_code placeMemberCode,
        place.member_name placeMemberName,
        cm.CREATION_TIME creationTime,
        cm.PAY_STATUS payStatus
        from cu_member cm
        left JOIN CU_MEMBER pat on pat.PK_PARENT=cm.PK_ID and pat.DEL_FLAG=0
        left JOIN CU_MEMBER ppt on ppt.pk_place_parent=cm.pk_id and ppt.DEL_FLAG=0
        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
        INNER join bd_grade grr on grr.pk_id=cm.PK_SETTLE_GRADE
        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
        where cm.del_flag = 0
        and cm.CATEGORY=0
        and cm.PAY_STATUS=0
        and awa.del_flag = 0
        and pat.PK_ID is null
        and ppt.PK_ID is null
        <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="pkCountry != null">
            and cm.PK_SETTLE_COUNTRY=#{pkCountry}
        </if>

        <if test="pkAwards != null">
            and cm.pk_awards=#{pkAwards}
        </if>
        <if test="placeMemberCode != null and placeMemberCode != ''">
            and place.member_code like #{placeMemberCode} || '%'
        </if>
        <if test="placeMemberName != null and placeMemberName != ''">
            and place.member_name like #{placeMemberName} || '%'
        </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="pkRegisterGrade != null">
            and cm.PK_REGISTER_GRADE=#{pkRegisterGrade}
        </if>
        ) cmm
        ORDER BY cmm.creationTime DESC
    </select>
    <!--    查询会员未激活点位注册订单-->
    <select id="notActiveOrderId" parameterType="com.hzs.member.base.vo.NotActivePointVO"
            resultType="java.lang.Long">
        select PK_ID as pkOrder
        from SA_ORDER
        where PK_MEMBER = #{pkId}
          and DEL_FLAG = 0
          and ORDER_TYPE = 1
          and ORDER_STATUS = 0
    </select>
    <!--     删除未激活会员订单-->
    <update id="delNotActiveOrder">
        update SA_ORDER
        set DEL_FLAG=1,
            PK_MODIFIED=#{pkModified},
            MODIFIED_TIME=sysdate
        where PK_MEMBER = #{pkId}
    </update>
    <!--     删除未激活点位订单明细-->
    <update id="delNotActiveOrderItems">
        update SA_ORDER_ITEMS
        set DEL_FLAG=1,
            PK_MODIFIED=#{pkModified},
            MODIFIED_TIME=sysdate
        where PK_ORDER = #{pkOrder}
    </update>

    <select id="checkMemberParent" resultType="long">
        select count(t.pk_id)
        from cu_member t
        where t.del_flag = 0
          and t.member_code = #{memberCode} start
        with t.pk_id = #{pkMember}
        connect by t.pk_parent = prior t.pk_id

    </select>

    <select id="checkPlaceDeptAndMemberCode" resultType="java.lang.Long">
        select count(c.pk_id)
        from cu_member c
        where c.del_flag = 0
          and c.PLACE_DEPT = #{placeDept}
          and c.PK_PLACE_PARENT = (select cm.pk_id from cu_member cm where cm.MEMBER_CODE = #{placeDeptMemberCode} and cm.del_flag = 0)

    </select>


    <update id="updateMemberEditNumber">
        update cu_member m
        set m.change_number = nvl(m.change_number,0) + 1,
        m.modified_time = sysdate,
        m.pk_modified = #{updatePkMember}
        where m.pk_id in
        <foreach collection="pkMemberList" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </update>

    <select id="checkMemberVertex" resultMap="MemberResultMap">
        select t.pk_id,
        t.member_code,
        t.member_name,
        t.phone,
        t.pk_place_parent,
        t.pk_parent,
        t.pk_center_code,
        t.PLACE_DEPT
        from cu_member t
        where t.del_flag = 0
        and t.MEMBER_CODE = #{memberCode}
        start
        with t.pk_place_parent in (select bv.PK_MEMBER
        from BD_VERTEX bv
        where bv.pk_id in
        <foreach collection="vertexIdList" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        )
        connect by t.pk_place_parent = prior t.pk_id
        union all
        select t.pk_id,
        t.member_code,
        t.member_name,
        t.phone,
        t.pk_place_parent,
        t.pk_parent,
        t.pk_center_code,
        t.PLACE_DEPT
        from cu_member t
        where t.del_flag = 0
        and t.MEMBER_CODE = #{memberCode}
        and t.pk_id in (select bv.PK_MEMBER
        from BD_VERTEX bv
        where bv.pk_id in
        <foreach collection="vertexIdList" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        )
    </select>

    <select id="getMemberByCodeNotDel" resultMap="MemberResultMap">
        select cm.*
        from cu_member cm
        where 1 = 1
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code = #{memberCode}
        </if>
    </select>

    <select id="getMemberAll" resultMap="MemberResultMap">
        select cm.pk_id,cm.PK_SETTLE_GRADE from cu_member cm where cm.del_flag = 0
        and cm.PK_COUNTRY = #{pkCountry}
        <if test="startTime != null">
            and cm.CREATION_TIME &gt;= #{startTime}
        </if>
        <if test="endTime != null">
            and cm.CREATION_TIME &lt;= #{endTime}
        </if>
        and cm.PK_REGISTER_GRADE in
        <foreach collection="gradeId" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>

    <select id="selectByQuerySparentMemberCount" resultType="long">
        select count(t.pk_id)
        from cu_member t
        where t.del_flag = 0 start
        with t.pk_place_parent = #{pkMember}
        connect by t.pk_place_parent = prior t.pk_id
    </select>

</mapper>
