<?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.bonus.bonus.mapper.CuMemberShareBonusMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="CuMemberShareBonusExt" type="com.hzs.common.domain.member.ext.CuMemberShareBonusExt">
        <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="PERIOD" property="period" />
        <result column="PK_RATE" property="pkRate" />
        <result column="SETTLE_MONTH" property="settleMonth" />
        <result column="EXPECT_SHARE_TOTAL" property="expectShareTotal" />
        <result column="REAL_SHARE_TOTAL" property="realShareTotal" />
        <collection property="cuMemberShareDetailList" ofType="com.hzs.common.domain.member.ext.CuMemberShareDetailExt">
            <result column="PK_DETAIL_ID" property="pkId" />
            <result column="PK_SHARE_BONUS" property="pkShareBonus" />
            <result column="PK_AWARDS" property="pkAwards" />
            <result column="pk_awards_val" property="pkAwardsVal" />
            <result column="PROMOTE_TOTAL" property="promoteTotal" />
            <result column="REACH_TOTAL" property="reachTotal" />
            <result column="EXPECT_SHARE_INCOME" property="expectShareIncome" />
            <result column="EXPECT_SHARE_SUBTOTAL" property="expectShareSubtotal" />
            <result column="REAL_SHARE_INCOME" property="realShareIncome" />
            <result column="REAL_SHARE_SUBTOTAL" property="realShareSubtotal" />
        </collection>
     </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        DEL_FLAG,
        CREATION_TIME,
        MODIFIED_TIME,
        PK_COUNTRY,
        PK_CREATOR,
        PK_MODIFIED,
        PK_ID, PERIOD, PK_RATE, SETTLE_MONTH, EXPECT_SHARE_TOTAL, REAL_SHARE_TOTAL
    </sql>
    <select id="queryCuMemberShareBonus" resultMap="CuMemberShareBonusExt">
        select cb.*,cb.pk_id pk_detail_id,cd.pk_awards,pk_share_bonus,promote_total,reach_total,expect_share_income,
               expect_share_subtotal,real_share_income,real_share_subtotal,ba.awards_name pk_awards_val from cu_member_share_bonus cb
        inner join cu_member_share_detail cd
        on cb.pk_id = cd.pk_share_bonus
        left join bd_awards ba
        on cd.pk_awards = ba.pk_id
        where cb.del_flag=0 and cd.del_flag=0 and
        cb.settle_month = #{settleMonth} and cb.pk_country = #{pkCountry}
        order by pk_awards
    </select>

</mapper>
