<?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.TOnlinePaymentMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.third.pay.TOnlinePayment">
        <id column="PK_ID" property="pkId"/>
        <result column="PAYMENT_CODE" property="paymentCode"/>
        <result column="BUSINESS_TYPE" property="businessType"/>
        <result column="BUSINESS_CODE" property="businessCode"/>
        <result column="BUSINESS_MONEY" property="businessMoney"/>
        <result column="PAY_CHANNEL" property="payChannel"/>
        <result column="PAY_TYPE" property="payType"/>
        <result column="PAY_STATUS" property="payStatus"/>
        <result column="PAY_NUMBER" property="payNumber"/>
        <result column="PAY_TIME" property="payTime"/>
        <result column="PAY_MONEY" property="payMoney"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="CALLBACK_STATUS" property="callbackStatus"/>
        <result column="CALLBACK_INFO" property="callbackInfo"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="ORIGINAL_ORDER" property="originalOrder"/>
        <result column="CHANNEL_NUMBER" property="channelNumber"/>
        <result column="PAY_SOURCE" property="paySource"/>
    </resultMap>

    <!-- 查询列表 -->
    <select id="queryList" resultType="com.hzs.common.domain.third.pay.ext.TOnlinePaymentExt">
        select top.*, cm.member_code, cm.member_name,smr.Pk_id as rechargeId,
        so.order_type orderType,
        bv.VERTEX_NAME,
        bv.pk_id VERTEX_id
        from T_ONLINE_PAYMENT top
        left join cu_member cm
        on cm.pk_id = top.pk_creator
        left join sa_order so on so.ORDER_CODE = top.business_code
        left join cu_member_recharge smr on smr.RECHARGE_CODE = top.business_code
        left join BD_VERTEX bv on bv.pk_id = cm.PK_VERTEX
        where top.del_flag = 0
        and top.pk_country = #{pkCountry}
        <if test="param.vertexId != null">
            and bv.pk_id = ${param.vertexId}
        </if>
        <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.businessMoney != null">
            and top.business_money = #{param.businessMoney}
        </if>
        <if test="param.businessType != null">
            and top.business_type = #{param.businessType}
        </if>
        <if test="param.payChannel != null">
            and top.pay_channel = #{param.payChannel}
        </if>
        <if test="param.payType != null">
            and top.pay_type = #{param.payType}
        </if>
        <if test="param.payStatus != null">
            and top.pay_status = #{param.payStatus}
        </if>
        <if test="param.creationTime != null">
            and top.creation_time >= #{param.creationTime[0]}
            and #{param.creationTime[1]} >= top.creation_time
        </if>
        <if test="param.payTime != null">
            and top.pay_time >= #{param.payTime[0]}
            and #{param.payTime[1]} >= top.pay_time
        </if>
        <if test="param.businessCode != null and param.businessCode != ''">
            and top.business_code like #{param.businessCode} || '%'
        </if>
        <if test="param.payNumber != null">
            and top.pay_number like #{param.payNumber} || '%'
        </if>
        <if test="param.orderType != null and param.orderType > 0">
            and so.order_type = #{param.orderType}
        </if>
        <if test="param.orderType != null and param.orderType == -1">
            and so.order_type is null
        </if>
        order by top.creation_time desc
    </select>

</mapper>
