<?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.bonus.core.pay.common.mapper.TradeOrderRechargeMapper">

    <!--批量保存-->
    <insert id="batchInsert">
        INSERT INTO trade_order_recharge(trade_id, order_recharge_id, mac_order_id) VALUES
        <foreach collection="tradeOrderRechargeList" item="item" separator=",">
            (#{item.tradeId}, #{item.orderRechargeId}, #{item.macOrderId})
        </foreach>
    </insert>

    <select id="listSuccessByOrderIds" resultType="com.bonus.core.pay.common.model.TradeOrderRecharge">
        SELECT tor.trade_id, tor.order_recharge_id, tor.mac_order_id
        FROM trade_order_recharge tor
        LEFT JOIN trade_record tr ON tor.trade_id = tr.id
        WHERE tr.trade_state IN (3,6)
        AND tor.order_recharge_id IN
        <foreach collection="orderIds" item="orderId" open="(" separator="," close=")">
            #{orderId}
        </foreach>
        <if test="stratTime != null">
            AND tr.create_time <![CDATA[ >= ]]> #{stratTime}
        </if>
        <if test="endTime != null">
            AND tr.create_time <![CDATA[ <= ]]> #{endTime}
        </if>
    </select>

</mapper>
