<?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.CuMemberSpeRetailMapper">

    <!-- 查询单条新零售注水信息-->
    <select id="getCuMemberSpeRetail" resultType="com.hzs.bonus.bonus.param.RetailAreaParam">
        SELECT cmsr.pk_id pkId,
        cmsr.member_code memberCode,
        cmsr.team_box_num teamBoxNum,
        cmsr.small_box_num smallBoxNum,
        cmsr.total_team_pv totalTeamPv,
        cmsr.small_area_pv smallAreaPv,
        cmsp.SETTLE_DATE settleDate
        FROM CU_MEMBER_SPE_RETAIL cmsr
        INNER JOIN CU_MEMBER_SETTLE_PERIOD cmsp ON cmsp.pk_id = cmsr.period
        where cmsr.DEL_FLAG = 0
        <if test="pkId!=null">
            and cmsr.pk_id=#{pkId}
        </if>
        <if test="systemType!=null">
            and cmsr.SYSTEM_TYPE=#{systemType}
        </if>
        <if test="pkCountry!=null">
            and cmsr.pk_Country=#{pkCountry}
        </if>
        <if test="memberCode != null and memberCode != '' ">
            and cmsr.member_code like #{memberCode} || '%'
        </if>
        <if test="startDate != null and startDate != '' ">
            and cmsp.SETTLE_DATE >= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endtDate != null and endtDate != '' ">
            and cmsp.SETTLE_DATE &lt;= to_date(#{endtDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        order by cmsr.CREATION_TIME desc
    </select>

    <!-- 校验会员是否激活-->
    <select id="checkCuMemberActivate" resultType="java.lang.Integer">
        SELECT count(1)
        FROM CU_MEMBER cm
        where cm.DEL_FLAG = 0
        AND cm.IS_ACTIVATE = 0
        <if test="memberCode != null and memberCode != '' ">
            and cm.member_code = #{memberCode}
        </if>
    </select>

</mapper>
