<?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.tree.mapper.SaTreeOrderMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.activity.tree.SaTreeOrder">
        <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="ORDER_CODE" property="orderCode" />
        <result column="PK_MEMBER" property="pkMember" />
        <result column="PK_BASE_ID" property="pkBaseId" />
        <result column="PK_TREE_RULE" property="pkTreeRule" />
        <result column="ORDER_AMOUNT" property="orderAmount" />
        <result column="QUANTITY" property="quantity" />
        <result column="ORDER_STATUS" property="orderStatus" />
        <result column="PAY_TIME" property="payTime" />
    </resultMap>
    <resultMap id="resultMap" type="com.hzs.common.domain.activity.ext.SaTreeOrderExt">
        <id column="PK_ID" property="pkId" />

        <result column="ORDER_CODE" property="orderCode" />
        <result column="PK_MEMBER" property="pkMember" />
        <result column="PK_BASE_ID" property="pkBaseId" />
        <result column="PK_TREE_RULE" property="pkTreeRule" />
        <result column="ORDER_AMOUNT" property="orderAmount" />
        <result column="QUANTITY" property="quantity" />
        <result column="ORDER_STATUS" property="orderStatus" />
        <result column="PAY_TIME" property="payTime" />
        <result column="MEMBER_NAME" property="memberName" />
        <result column="MEMBER_CODE" property="memberCode" />
        <result column="PHONE" property="phone" />
        <result column="PK_SETTLE_GRADE" property="pkSettleGrade" />
        <result column="PK_AWARDS" property="pkAwards" />
        <result column="PRICE" property="price" />
    </resultMap>
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        DEL_FLAG,
        CREATION_TIME,
        PK_CREATOR,
        MODIFIED_TIME,
        PK_MODIFIED,
        PK_COUNTRY,
        PK_ID, ORDER_CODE, PK_MEMBER, PK_BASE_ID, PK_TREE_RULE, ORDER_AMOUNT, QUANTITY, ORDER_STATUS, PAY_TIME
    </sql>


    <!--   查询有效的沙棘树活动-->
    <select id="queryTreeActivity" parameterType="com.hzs.activity.tree.vo.SaTreeOrderVO"
            resultType="com.hzs.activity.tree.vo.SaTreeOrderVO">
select *  from(
    select

            abc.ACT_NAME actName,
            abc.ACT_EXPLAIN actExplain,
            atr.PK_ID pkTreeRule,
            atr.PK_BASE_ID pkBaseId,
            atr.COVER cover,
            atr.NAME name,
            atr.PRICE price,
            atr.QUANTITY quantity
            from  AC_TREE_RULE_CONFIG atr
            INNER JOIN AC_BASE_CONFIG abc on abc.PK_ID=atr.PK_BASE_ID
            WHERE
            atr.DEL_FLAG = 0
            AND abc.DEL_FLAG =0
            and atr.PK_AWARDS=#{pkAwards}
            and atr.PK_COUNTRY=#{pkCountry}
            and abc.PK_COUNTRY=#{pkCountry}
            and abc.ACT_START_DATE &lt;= sysdate
            and abc.ACT_END_DATE &gt;= sysdate
             ORDER BY atr.CREATION_TIME DESC
)  where rownum = 1

    </select>

    <select id="selectByList" resultMap="resultMap" >
        select st.*,cm.MEMBER_NAME ,cm.MEMBER_CODE,cm.PHONE,cm.PK_SETTLE_GRADE,cm.PK_AWARDS,trc.PRICE
        from  SA_TREE_ORDER st
        left join CU_MEMBER cm on cm.PK_ID = st.PK_MEMBER
        left join AC_TREE_RULE_CONFIG trc on trc.PK_ID = st.PK_TREE_RULE
        where 1 =1
        <if test="memberName != null and memberName != ''">
            and cm.MEMBER_NAME = #{memberName}
        </if>
        <if test="memberCode != null and memberCode != ''">
            and cm.MEMBER_CODE = #{memberCode}
        </if>
        <if test="phone != null and phone != ''">
            and cm.PHONE = #{phone}
        </if>
        <if test="pkGrade != null">
            and cm.PK_SETTLE_GRADE = #{pkGrade}
        </if>
        <if test="pkAwards != null">
            and cm.PK_AWARDS = #{pkAwards}
        </if>
        <if test="startPayDate != null">
            and st.PAY_TIME &gt;= #{startPayDate}
        </if>
        <if test="endPayDate != null">
            and st.PAY_TIME &lt;= #{endPayDate}
        </if>
        ORDER BY st.PAY_TIME desc
    </select>

</mapper>
