<?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.account.mapper.CuMemberRechargeApplicationMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.member.account.CuMemberRechargeApplication">
        <result column="DEL_FLAG" property="delFlag"/>
        <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_ID" property="pkId"/>
        <result column="PK_MEMBER" property="pkMember"/>
        <result column="REMITTER" property="remitter"/>
        <result column="REMITTANCE_AMOUNT" property="remittanceAmount"/>
        <result column="REMITTANCE_DATE" property="remittanceDate"/>
        <result column="REMITTANCE_INSTRUCTIONS" property="remittanceInstructions"/>
        <result column="APPLICATION_STATUS" property="applicationStatus"/>
        <result column="REJECTION_STATEMENT" property="rejectionStatement"/>
        <result column="APPROVE_TIME" property="approveTime"/>
        <result column="APPROVER" property="approver"/>
    </resultMap>


    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMapExt" type="com.hzs.common.domain.member.account.CuMemberRechargeApplicationExt">
        <result column="DEL_FLAG" property="delFlag"/>
        <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_ID" property="pkId"/>
        <result column="PK_MEMBER" property="pkMember"/>
        <result column="REMITTER" property="remitter"/>
        <result column="REMITTANCE_AMOUNT" property="remittanceAmount"/>
        <result column="REMITTANCE_DATE" property="remittanceDate"/>
        <result column="REMITTANCE_INSTRUCTIONS" property="remittanceInstructions"/>
        <result column="APPLICATION_STATUS" property="applicationStatus"/>
        <result column="REJECTION_STATEMENT" property="rejectionStatement"/>
        <result column="APPROVE_TIME" property="approveTime"/>
        <result column="APPROVER" property="approver"/>
        <result column="MEMBER_CODE" property="memberCode"/>
        <result column="MEMBER_NAME" property="memberName"/>
        <result column="NICK_NAME" property="approveName"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        DEL_FLAG
        ,
        PK_COUNTRY,
        CREATION_TIME,
        MODIFIED_TIME,
        PK_CREATOR,
        PK_MODIFIED,
        PK_ID, PK_MEMBER, REMITTER, REMITTANCE_AMOUNT, REMITTANCE_DATE, REMITTANCE_INSTRUCTIONS, APPLICATION_STATUS, REJECTION_STATEMENT, APPROVE_TIME, APPROVER
    </sql>


    <select id="findRechargeApplicationList" resultMap="BaseResultMapExt">
        SELECT ra.*, m.member_code, m.member_name, su.nick_name
        FROM cu_member_recharge_application ra
        LEFT JOIN cu_member m
            ON ra.pk_member = m.pk_id
            AND m.del_flag = 0
        LEFT JOIN Sys_User su
            ON ra.approver = su.user_id
            AND su.del_flag = 0
        WHERE ra.del_flag = 0
        <if test="memberName != null and memberName != ''">
            and m.member_name like '%' || #{memberName} || '%'
        </if>
        <if test="memberCode != null and memberCode != ''">
            and m.member_code like  #{memberCode} || '%'
        </if>
        <if test="remitter != null and remitter != ''">
            and ra.REMITTER like '%' || #{remitter} || '%'
        </if>

        <if test="remittanceInstructions != null and remittanceInstructions != ''">
            and ra.remittance_instructions like '%' || #{remittanceInstructions} || '%'
        </if>

        <if test="approveName != null and approveName != ''">
            and su.nick_name like '%' || #{approveName} || '%'
        </if>

        <if test="applicationStatus != null">
            AND ra.application_status = #{applicationStatus}
        </if>
        <if test="pkMember != null">
            AND ra.pk_creator = #{pkMember}
        </if>
        <if test="pkCountry != null">
            AND ra.pk_country = #{pkCountry}
        </if>
        <if test="startDate != null and startDate != ''">
            and ra.creation_time >= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate != ''">
            and ra.creation_time &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        <if test="remittanceStartDate != null and remittanceStartDate != ''">
            and ra.remittance_date >= to_date(#{remittanceStartDate}, 'yyyy-mm-dd')
        </if>
        <if test="remittanceEndDate != null and remittanceEndDate != ''">
            and ra.remittance_date &lt;= to_date(#{remittanceEndDate}, 'yyyy-mm-dd')
        </if>

        <if test="approveStartDate != null and approveStartDate != ''">
            and ra.approve_time >= to_date(#{approveStartDate}, 'yyyy-mm-dd')
        </if>
        <if test="approveEndDate != null and approveEndDate != ''">
            and ra.approve_time &lt;= to_date(#{approveEndDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        ORDER BY  ra.creation_time DESC
    </select>


</mapper>
