<?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.activity.people.mapper.AcPeopleServiceMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.activity.people.AcPeopleService">
        <id column="PK_ID" property="pkId"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_MEMBER" property="pkMember"/>
        <result column="PK_BASE_ID" property="pkBaseId"/>
        <result column="PK_NEW_PEOPLE" property="pkNewPeople"/>
        <result column="PLAN_STATE" property="planState"/>

    </resultMap>

    <!-- 通用查询映射结果 -->
    <resultMap id="AcPeopleServiceVO" type="com.hzs.activity.people.vo.AcPeopleServiceVO">
        <id column="PK_ID" property="pkId"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_MEMBER" property="pkMember"/>
        <result column="PK_BASE_ID" property="pkBaseId"/>
        <result column="PK_NEW_PEOPLE" property="pkNewPeople"/>
        <result column="PLAN_STATE" property="planState"/>
        <result column="ACT_COVER" property="actCover"/>
        <result column="ACT_TYPE" property="actType"/>
        <result column="ACT_EXPLAIN" property="actExplain"/>
        <result column="ACT_START_DATE" property="actStartDate"/>
        <result column="ACT_END_DATE" property="actEndDate"/>



    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        DEL_FLAG,
        CREATION_TIME,
        PK_CREATOR,
        MODIFIED_TIME,
        PK_MODIFIED,
        PK_COUNTRY,
        PK_ID, PK_MEMBER, PK_BASE_ID, PK_NEW_PEOPLE
    </sql>
    <!--查询当前新人礼包活动-->
    <select id="peopleActivityList" parameterType="com.hzs.activity.people.vo.AcPeopleServiceVO"
            resultMap="AcPeopleServiceVO">
        select a.ACT_NAME,
        a.ACT_COVER,
        a.ACT_TYPE,
        a.ACT_EXPLAIN,
        a.ACT_START_DATE,
        a.ACT_END_DATE,
        b.PK_ID,
        b.PK_BASE_ID,
        b.PK_GRADE,
        b.PLAN
        from  ac_base_config a
        LEFT JOIN AC_NEW_PEOPLE_RULE_CONFIG b on a.PK_ID=b.PK_BASE_ID
        WHERE
        a.DEL_FLAG = 0
        AND b.DEL_FLAG =0
        <if test="pkCountry != null ">
          and  a.PK_COUNTRY = #{pkCountry}
        </if>
        <if test="payTime != null ">
            and a.act_start_date &lt;= #{payTime}
        </if>
        <if test="payTime != null ">
            and a.act_end_date &gt; =#{payTime}
        </if>
        <if test="pkRegisterGrade != null ">
            and b.PK_GRADE=#{pkRegisterGrade}
        </if>

    </select>
    <!--查询新人礼包活动方案-->
    <select id="getGiftPackList" parameterType="com.hzs.activity.people.vo.AcPeopleGiftPackVO"
            resultType="com.hzs.activity.people.vo.AcPeopleGiftPackVO">
        select  npr.PK_ID pkNewPeople,
        npr.PK_BASE_ID pkBaseId,
        npr.PK_GRADE pkGrade,
        npr.PLAN plan,
        npr.PRICE price,
        bas.ACT_NAME actName
        from AC_NEW_PEOPLE_RULE_CONFIG npr
        LEFT JOIN AC_BASE_CONFIG bas on bas.PK_ID=npr.PK_BASE_ID
        where  npr.DEL_FLAG = 0 and bas.DEL_FLAG =0
        <if test="pkNewPeople != null ">
            and npr.PK_ID= #{pkNewPeople}
        </if>
        <if test="pkBaseId != null ">
            and npr.PK_BASE_ID= #{pkBaseId}
        </if>
        <if test="pkGrade != null ">
            and npr.PK_GRADE= #{pkGrade}
        </if>


    </select>

    <!--礼包查询信息-->
    <select id="getGiftPackProductList"
            resultType="com.hzs.activity.people.vo.AcPeopleGiftProductVO">
        select ac.pk_base_id,ac.price receivePrice,bt.COVER cover,ag.pk_product pkProductId,ag.specs_name specsName,ag.specs_name_id specsNameId,
        ag.PRICE price,
        ag.QUANTITY quantity,
        bt.PRODUCT_NAME productName  from
        AC_GIFT_CONFIG ag
        inner join AC_NEW_PEOPLE_RULE_CONFIG ac
        on ag.PK_RULE_ID = ac.pk_id
        LEFT JOIN BD_PRODUCT bt on bt.PK_ID=ag.PK_PRODUCT
        where  ag.DEL_FLAG = 0 and ac.del_flag=0
        <if test="pkNewPeople != null ">
            and ag.PK_RULE_ID= #{pkNewPeople}
        </if>
    </select>



</mapper>
