<?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.member.annuity.mapper.CuMemberAnnuityMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.member.annuity.CuMemberAnnuity">
        <id column="PK_ID" property="pkId" />
    <result column="PK_COUNTRY" property="pkCountry" />
    <result column="CREATION_TIME" property="creationTime" />
    <result column="MODIFIED_TIME" property="modifiedTime" />
    <result column="PK_CREATOR" property="pkCreator" />
    <result column="PK_MODIFIED" property="pkModified" />
        <result column="PK_MEMBER" property="pkMember" />
        <result column="UNIT_PRICE" property="unitPrice" />
        <result column="QUANTITY" property="quantity" />
        <result column="TOTAL_PRICE" property="totalPrice" />
    </resultMap>
    <resultMap id="extResultMap" type="com.hzs.member.base.ext.CuMemberAnnuityExt">
        <id column="PK_ID" property="pkId" />
        <result column="PK_COUNTRY" property="pkCountry" />
        <result column="CREATION_TIME" property="creationTime" />
        <result column="MODIFIED_TIME" property="modifiedTime" />
        <result column="PK_CREATOR" property="pkCreator" />
        <result column="PK_MODIFIED" property="pkModified" />
        <result column="PK_MEMBER" property="pkMember" />
        <result column="UNIT_PRICE" property="unitPrice" />
        <result column="QUANTITY" property="quantity" />
        <result column="TOTAL_PRICE" property="totalPrice" />
        <result column="MEMBER_CODE" property="memberCode" />
        <result column="MEMBER_NAME" property="memberName" />
        <result column="EXPIRE_DATE" property="expireDate" />
        <result column="BEFORE_RESIDUE" property="beforeResidue" />
        <result column="AFTER_RESIDUE" property="afterResidue" />
        <result column="GRADE_NAME" property="gradeName" />
        <result column="AWARDS_NAME" property="awardsName" />
    </resultMap>
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        PK_COUNTRY,
        CREATION_TIME,
        MODIFIED_TIME,
        PK_CREATOR,
        PK_MODIFIED,
        PK_ID, PK_MEMBER, UNIT_PRICE, QUANTITY, TOTAL_PRICE
    </sql>

    <select id="selectByList" resultMap="extResultMap">
      select ma.*,cm.MEMBER_CODE,cm.MEMBER_NAME,bg.GRADE_NAME,ba.AWARDS_NAME    from CU_MEMBER_ANNUITY ma
      left join CU_MEMBER cm on cm.PK_ID = ma.PK_MEMBER
      left join bd_grade bg on bg.PK_ID = cm.PK_SETTLE_GRADE
      left join bd_awards ba  on  ba.PK_ID = cm.PK_AWARDS
        where 1 = 1
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code=#{memberCode}
        </if>
        <if test="memberName != null and memberName != ''">
            and cm.member_name=#{memberName}
        </if>
        <if test="pkAwards != null">
            and cm.PK_AWARDS=#{pkAwards}
        </if>
        <if test="pkGrade != null">
            and cm.PK_SETTLE_GRADE=#{pkGrade}
        </if>
        <if test="startDate != null">
            and ma.CREATION_TIME &gt;= #{startDate}
        </if>
        <if test="endDate != null">
            and ma.CREATION_TIME &lt;= #{endDate}
        </if>
        <if test="pkCountry != null">
            and ma.PK_COUNTRY = #{pkCountry}
        </if>

order by ma.CREATION_TIME desc
    </select>
</mapper>
