<?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.system.config.mapper.CuMemberTransferWhiteMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.config.CuMemberTransferWhite">
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="PK_ID" property="pkId"/>
        <result column="PK_MEMBER" property="pkMember"/>
        <result column="PK_ACCOUNT" property="pkAccount"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        DEL_FLAG
        ,
        CREATION_TIME,
        MODIFIED_TIME,
        PK_COUNTRY,
        PK_CREATOR,
        PK_MODIFIED,
        PK_ID, PK_MEMBER, PK_ACCOUNT
    </sql>

    <select id="selectTransferWhiteConfigList"
            resultType="com.hzs.common.domain.system.config.ext.CuMemberTransferWhiteExt">
        SELECT c.pk_id pkId,
        c.pk_member pkMember,
        m.member_code memberCode,
        m.member_name memberName,
        c.pk_account pkAccount,
        c.creation_time creationTime,
        awa.PK_TRANSACTION pkAwards,
        ver.VERTEX_NAME vertexName,
        ct.TEAM_NAME teamName
        FROM cu_member_transfer_white c, cu_member m
        LEFT JOIN cu_member_team ct
        ON ct.pk_id = m.pk_team_code
        LEFT JOIN bd_vertex ver
        ON ver.pk_id = m.PK_VERTEX
        LEFT JOIN bd_awards awa
        ON awa.pk_id = m.pk_awards
        WHERE c.pk_member = m.pk_id
        AND c.del_flag = 0
        and c.pk_country = #{pkCountry}
        <if test="pkMember != null">
            and c.PK_MEMBER = #{pkMember}
        </if>
        <if test="pkAccount != null">
            and c.PK_ACCOUNT = #{pkAccount}
        </if>
        <if test="startDate != null and startDate != ''">
            and c.CREATION_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate != ''">
            and c.CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="memberName != null and memberName != ''">
            and m.member_name like #{memberName} || '%'
        </if>

        <if test="vertexId != null">
            and m.PK_VERTEX=#{vertexId}
        </if>

        <if test="teamId != null">
            and m.pk_team_code=#{teamId}
        </if>
        <if test="memberCode != null and memberCode != ''">
            and m.member_code like #{memberCode} || '%'
        </if>
        <if test="pkAwards != null">
            and m.pk_awards=#{pkAwards}
        </if>
        order by c.creation_time desc
    </select>


    <update id="deleteTransferWhiteByIds">
        UPDATE cu_member_transfer_white tw
        <set>
            <if test="pkCreator != null">
                pk_modified = #{pkCreator},
            </if>
            modified_time = SYSDATE,
            del_flag = 1
        </set>
        WHERE tw.pk_id IN
        <foreach collection="pkIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </update>

    <select id="selectTransferWhiteById" resultType="com.hzs.common.domain.system.config.ext.CuMemberTransferWhiteExt">
        SELECT c.pk_id            pkId,
               c.pk_member        pkMember,
               m.member_code      memberCode,
               m.member_name      memberName,
               c.pk_account       pkAccount,
               c.creation_time    creationTime,
               awa.PK_TRANSACTION pkAwards
        FROM cu_member_transfer_white c,
             cu_member m
                 LEFT JOIN bd_awards awa
                           ON awa.pk_id = m.pk_awards
        WHERE c.pk_member = m.pk_id
          AND c.del_flag = 0
          AND c.pk_id = #{pkId}
    </select>

    <select id="selectTransferWhiteByPkMember" resultType="int">
        SELECT tw.pk_account
        FROM cu_member_transfer_white tw
        WHERE tw.del_flag = 0
          AND tw.pk_country = #{pkCountry}
          AND tw.pk_member = #{pkMember}
    </select>


</mapper>
