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

    <!-- 通用查询映射结果 -->
    <resultMap id="CuMemberSwingNetExt" type="com.hzs.common.domain.member.swing.ext.CuMemberSwingNetExt">
        <id column="PK_ID" property="pkId" />
        <result column="DEL_FLAG" property="delFlag" />
        <result column="CREATION_TIME" property="creationTime" />
        <result column="MODIFIED_TIME" property="modifiedTime" />
        <result column="PK_COUNTRY" property="pkCountry" />
        <result column="PK_CREATOR" property="pkCreator" />
        <result column="PK_MODIFIED" property="pkModified" />
        <result column="PK_SOURCE_MEMBER" property="pkSourceMember" />
        <result column="PK_TARGET_MEMBER" property="pkTargetMember" />
        <result column="source_member_code" property="sourceMemberCode" />
        <result column="source_member_name" property="sourceMemberName" />
        <result column="target_member_code" property="targetMemberCode" />
        <result column="target_member_name" property="targetMemberName" />

        <collection property="cuMemberSwingNetDetailExtList" ofType="com.hzs.common.domain.member.swing.ext.CuMemberSwingNetDetailExt">
        <result column="PK_DETAIL_ID" property="pkId" />
        <result column="PK_SWING_NET" property="pkSwingNet" />
        <result column="PK_MEMBER" property="pkMember" />
        <result column="FIRST_ACHIEVE_RATIO" property="firstAchieveRatio" />
        <result column="REPURCHASE_ACHIEVE_RATIO" property="repurchaseAchieveRatio" />
        <result column="FIRST_CALCULATE" property="firstCalculate" />
        <result column="REPURCHASE_CALCULATE" property="repurchaseCalculate" />
        <result column="member_code" property="memberCode" />
        <result column="member_name" property="memberName" />
        </collection>
    </resultMap>
    <select id="queryCuMemberSwingNetExt" resultMap="CuMemberSwingNetExt">
        select cn.pk_id,cn.pk_target_member,cn.pk_source_member,cd.pk_id pk_detail_id,cd.pk_member,cd.first_achieve_ratio,cd.first_calculate,cd.repurchase_achieve_ratio,
               cd.repurchase_calculate,sou.member_code source_member_code,sou.member_name source_member_name,
               par.member_code target_member_code,par.member_name target_member_name,cm.member_code,cm.member_name from CU_MEMBER_SWING_NET cn
        inner join CU_MEMBER_SWING_NET_detail cd
                   on cn.pk_id=cd.pk_swing_net
        left join cu_member sou
                  on cn.pk_source_member=sou.pk_id
        left join cu_member par
                  on cn.pk_target_member=par.pk_id
        left join cu_member cm
                  on cd.pk_member=cm.pk_id
        where cn.del_flag=0 and cd.del_flag=0
        <if test="pkId != null">
            and cn.pk_id= #{pkId}
        </if>
        <if test="sourceMemberCode != null">
            and sou.member_code = #{sourceMemberCode}
        </if>
        <if test="sourceMemberName != null">
            and sou.member_name = #{sourceMemberName}
        </if>
        <if test="targetMemberCode != null">
            and par.member_code = #{targetMemberCode}
        </if>
        <if test="targetMemberName != null">
            and par.member_name = #{targetMemberName}
        </if>
        <if test="memberCode != null">
            and cm.member_code = #{memberCode}
        </if>
        <if test="memberName != null">
            and cm.member_name = #{memberName}
        </if>
        order by cn.pk_id
    </select>


</mapper>
