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,
               cm.pk_vertex,
               cm.service_code
        from cu_member cm
        where cm.del_flag = 0
    
    
    
        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,
                               EXPIRE_DATE, STOP_DATE, IS_MAKER_GIFT, MAKER_GIFT_TIME)
        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},
                #{expireDate, jdbcType=DATE}, #{stopDate, jdbcType=DATE}, #{isMakerGift,jdbcType=INTEGER},
                #{makerGiftTime,jdbcType=TIMESTAMP})
    
    
    
        insert ALL
        
            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, STOP_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}, #{item.stopDate, jdbcType=DATE}
            )
        
        SELECT 1 FROM dual
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        MERGE INTO cu_member m
        USING
        (
        
            select #{item.pkMember} pk_member,
            
                #{item.newValue} member_name
            
            
                #{item.newValue} phone
            
            FROM DUAL
        
        ) t
        ON ( t.pk_member=m.pk_id and m.pk_id in
        
            #{item.pkMember}
        )
        WHEN MATCHED THEN
        UPDATE SET
        
            m.member_name = t.member_name,
        
        
            m.member_name = DECODE(m.system_type,1,t.phone,m.member_name),
            m.phone = t.phone,
        
        m.MODIFIED_TIME = sysdate,
        m.pk_modified = #{updatePkMember}
    
    
    
        update cu_member
        
            
                
                    
                        is_real_name = #{value}
                    
                
                
                    
                        
                            login_pwd = #{loginPwd},login_password = #{loginPassword},
                            pay_pwd = #{payPwd},pay_password = #{payPassword}
                        
                        
                            login_pwd = #{loginPwd},login_password = #{loginPassword}
                        
                        
                            pay_pwd = #{payPwd},pay_password = #{payPassword}
                        
                    
                
                
                    
                        pk_register_grade = #{value}
                    
                
                
                    
                        pk_settle_grade = #{value}
                    
                
                
                    
                        pk_awards = #{value}
                    
                
                
                    
                        pk_country = #{value}
                    
                
                
                    
                        account_status = #{value}
                    
                
                
                    
                        income_status = #{value}
                    
                
                
                    
                        
                            purchase_status = 0
                        
                        
                            share_status = 0
                        
                        
                            purchase_status = 1
                        
                        
                            share_status = 1
                        
                    
                
                
                    
                        register_authority = #{value}
                    
                
                
                    
                        is_maker_space = #{value}
                    
                
                
                    
                        super_studio = #{value}
                    
                
                
                    
                        is_dealer = #{value}
                    
                
                
                    
                        LECTURER_LEVEL = #{value}
                    
                
                
                    
                        SYSTEM_LEVEL = #{value}
                    
                
                
                    
                        pk_max_awards = #{value}
                    
                
            
            ,MODIFIED_TIME = sysdate,
            PK_MODIFIED = #{updatePkMember}
        
        where pk_id in
        
            #{item.pkMember}
        
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        update CU_MEMBER
        set PK_PARENT          = #{pkParent},
            DIRECT_PUSH_NUMBER = #{directPushNumber}
        where PK_ID = #{pkMember}
    
    
        update CU_MEMBER
        set PK_PLACE_PARENT = #{pkPlaceParent},
            PLACE_DEPT      = #{placeDept}
        where PK_ID = #{pkMember}
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        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
        
            #{item}
        
    
    
    
    
    
    
    
    
        UPDATE cu_member m
        SET m.modified_time = SYSDATE,
            m.pk_modified   = 100000000,
            m.expire_date   = add_months(m.expire_date, 12),
            m.stop_date     = add_months(m.stop_date, 12)
        WHERE m.expire_date <= add_months(trunc(SYSDATE), 4)
          AND m.pk_id IN (SELECT rw.pk_member
                          FROM bd_agreement_renewal_white rw
                          WHERE rw.del_flag = 0
                            AND rw.type = 1)
    
    
    
    
    
    
    
    
    
    
        update cu_member cm
        set cm.expire_date   = #{expireDate},
            cm.stop_date     = #{stopDate},
            cm.modified_time = sysdate
        where cm.del_flag = 0
          and cm.category = 0
          and cm.pk_settle_country = #{pkCountry}
          and cm.member_name = #{memberName}
          and cm.phone = #{phone}
    
    
    
        update cu_member cm
        set (cm.expire_date, cm.stop_date) =
        (select cm.expire_date, add_months(cm.expire_date, ${stopMonth}) stop_date
        from cu_member cm
        where cm.pk_id = #{pkMember}),
        cm.pk_modified = #{pkMember},
        cm.modified_time = sysdate
        where cm.del_flag = 0
        and cm.category = 0
        and cm.pk_settle_country = #{pkCountry}
        and cm.member_name = #{memberName}
        and cm.phone = #{phone}
        
            and #{expireDate} >= cm.expire_date
        
    
    
    
        update cu_member cm
        set cm.stop_date     = add_months(cm.expire_date, ${stopMonth}),
            cm.modified_time = sysdate,
            cm.pk_modified   = #{pkMember}
        where cm.del_flag = 0
          and cm.category = 0
          and cm.pk_settle_country = #{pkCountry}
          and cm.member_name = #{memberName}
          and cm.phone = #{phone}
          and cm.stop_date != add_months(cm.expire_date, ${stopMonth})
    
    
    
        update cu_member cm
        set (cm.expire_date, cm.stop_date) =
                (select max(cm.expire_date)                           expire_date,
                        add_months(max(cm.expire_date), ${stopMonth}) stop_date
                 from cu_member cm
                 where cm.del_flag = 0
                   and cm.category = 0
                   and cm.pk_settle_country = #{pkCountry}
                   and cm.member_name = #{memberName}
                   and cm.phone = #{phone}),
            cm.pk_modified                 = #{pkMember},
            cm.modified_time               = sysdate
        where cm.del_flag = 0
          and cm.category = 0
          and cm.pk_settle_country = #{pkCountry}
          and cm.member_name = #{memberName}
          and cm.phone = #{phone}
    
    
    
        update cu_member cm
        set cm.expire_status = (case
        when cm.expire_date >= TRUNC(sysdate) then
        1
        when TRUNC(sysdate) > cm.expire_date and
        cm.stop_date >= TRUNC(sysdate) then
        2
        end)
        where cm.del_flag = 0
        and cm.category = 0
        and cm.pk_settle_country = #{pkCountry}
        and cm.member_name = #{memberName}
        and cm.phone = #{phone}
        
            and cm.pk_id = #{pkMember}
        
    
    
    
        merge into cu_member cm
            using (select cm.member_name, cm.phone, max(cm.pk_max_awards)
                   from cu_member cm
                   where cm.del_flag = 0
                     and cm.pk_settle_country = #{pkCountry}
                     and cm.category = 0
                     and cm.pk_max_awards != 1
                   group by cm.member_name, cm.phone) tmp
            on (cm.member_name = tmp.member_name and cm.phone = tmp.phone and cm.del_flag = 0 and
                cm.pk_settle_country = #{pkCountry} and cm.category = 0)
            WHEN MATCHED THEN
                update set cm.stop_date = add_months(cm.expire_date, 12),
                    cm.modified_time = sysdate
    
    
    
        update cu_member cm
        set cm.expire_status = 2,
            cm.modified_time = sysdate
        where cm.del_flag = 0
          and cm.category = 0
          and cm.pk_settle_country = #{pkCountry}
          and TRUNC(sysdate) > cm.expire_date
          and cm.stop_date >= TRUNC(sysdate)
    
    
    
        update cu_member cm
        set cm.expire_status = 3,
            cm.category      = 2,
            cm.modified_time = sysdate
        where cm.del_flag = 0
          and cm.category = 0
          and cm.pk_settle_country = #{pkCountry}
          and TRUNC(sysdate) > cm.stop_date
    
    
    
    
    
        update CU_MEMBER
        set SERVICE_CODE = null
        where MEMBER_CODE = #{memberCode}