<?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.detail.mapper.CuMemberAssessMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="CuMemberAssess" type="com.hzs.common.domain.member.ext.CuMemberAssessExt">
        <id column="PK_ID" property="pkId"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <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="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_MEMBER" property="pkMember"/>
        <result column="PERIOD" property="period"/>
        <result column="SETTLE_MONTH" property="settleMonth"/>
        <result column="ASSESS_TYPE" property="assessType"/>
        <result column="PK_ORIGINAL_AWARDS" property="pkOriginalAwards"/>
        <result column="PK_AWARDS" property="pkAwards"/>
        <result column="ASSESS_TARGET" property="assessTarget"/>
        <result column="IS_EXAMINE" property="isExamine"/>
        <result column="ASSESS_STATUS" property="assessStatus"/>
        <result column="MONTH_BALANCE" property="monthBalance"/>
        <result column="MONTH_ADD" property="monthAdd"/>
        <result column="CUR_MONTH_ADD" property="curMonthAdd"/>
        <result column="MONTH_USED" property="monthUsed"/>
        <result column="MONTH_SURPLUS" property="monthSurplus"/>
    </resultMap>

    <select id="queryCuMemberAssTotal" resultType="com.hzs.common.domain.member.detail.CuMemberAssess">
        select cm.pk_awards pkAwards, count(cm.pk_id) assessStatus
        from ${settleTable} cm
                 inner join bd_awards ba
                            on cm.pk_awards = ba.pk_id
        where period = #{period}
          and cm.pk_country = #{pkCountry}
          and ASSESS_TYPE = 1
          and ASSESS_STATUS in (0, 1)
          and ba.awards_value > 0
        group by cm.pk_awards
        order by pk_awards
    </select>

</mapper>
