<?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.third.pay.mapper.TOnlineRefundMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.third.pay.TOnlineRefund">
        <id column="PK_ID" property="pkId"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="REFUND_CODE" property="refundCode"/>
        <result column="PK_ONLINE_PAYMENT" property="pkOnlinePayment"/>
        <result column="BUSINESS_CODE" property="businessCode"/>
        <result column="REFUND_MONEY" property="refundMoney"/>
        <result column="REFUND_CHANNEL" property="refundChannel"/>
        <result column="REFUND_STATUS" property="refundStatus"/>
        <result column="REFUND_NUMBER" property="refundNumber"/>
        <result column="FINISH_TIME" property="finishTime"/>
        <result column="FINISH_MONEY" property="finishMoney"/>
        <result column="ERROR_MSG" property="errorMsg"/>
        <result column="CALLBACK_STATUS" property="callbackStatus"/>
        <result column="CALLBACK_INFO" property="callbackInfo"/>
    </resultMap>

    <!-- 查询列表 -->
    <select id="queryList" resultType="com.hzs.common.domain.third.pay.ext.TOnlineRefundExt">
        select cm.member_code,
        cm.member_name,
        top.business_type pay_business_type,
        top.business_code pay_business_code,
        tor.pk_id,
        tor.business_code,
        tor.refund_status,
        tor.refund_money,
        tor.finish_money,
        tor.creation_time,
        tor.finish_time,
        tor.refund_channel,
        tor.refund_code,
        tor.error_msg
        from T_ONLINE_REFUND tor
        inner join T_ONLINE_PAYMENT top
        on top.pk_id = tor.pk_online_payment
        left join cu_member cm
        on cm.pk_id = top.pk_creator
        where tor.del_flag = 0
        and tor.pk_country = #{pkCountry}
        and cm.system_type = #{param.systemType}
        <if test="param.memberCode != null and param.memberCode != ''">
            and cm.member_code like #{param.memberCode} || '%'
        </if>
        <if test="param.memberName != null and param.memberName != ''">
            and cm.member_name like #{param.memberName} || '%'
        </if>
        <if test="param.businessType != null">
            and top.business_type = #{param.businessType}
        </if>
        <if test="param.refundChannel != null">
            and tor.refund_channel = #{param.refundChannel}
        </if>
        <if test="param.refundStatus != null">
            and tor.refund_status = #{param.refundStatus}
        </if>
        <if test="param.creationTime != null">
            and tor.creation_time >= #{param.creationTime[0]}
            and #{param.creationTime[1]} >= tor.creation_time
        </if>
        <if test="param.finishTime != null">
            and tor.finish_time >= #{param.finishTime[0]}
            and #{param.finishTime[1]} >= tor.finish_time
        </if>
        <if test="param.businessCode != null and param.businessCode != ''">
            and top.business_code like #{param.businessCode} || '%'
        </if>
        order by tor.creation_time desc
    </select>

    <!-- 查询退款以及支付 -->
    <select id="queryRefundAndPay" resultType="com.hzs.common.domain.third.pay.ext.TOnlineRefundExt">
        select tor.*, top.business_type pay_business_type, top.business_code pay_business_code
        from T_ONLINE_REFUND tor
        left join T_ONLINE_PAYMENT top
        on tor.pk_online_payment = top.pk_id
        where tor.del_flag = 0
        <if test="refundCode != null and refundCode != ''">
            and tor.refund_code = #{refundCode}
        </if>
        <if test="refundChannel != null and refundNumber != null and refundNumber != ''">
            and (tor.refund_channel = #{refundChannel} and
            tor.refund_number = #{refundNumber})
        </if>
    </select>

</mapper>
