<?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.yc.ship.module.trade.dal.mysql.refund.RefundDetailBaseMapper">

    <resultMap id="otaInnerRefundVoucherMap" type="com.yc.ship.module.trade.controller.app.ota.vo.OtaInnerRefundVoucherVO">
        <result property="voucherCode" column="supplier_voucher_code"/>
        <collection property="productBaseList" ofType="java.lang.Long" javaType="java.util.List">
            <result column="product_base_id"/>
        </collection>
    </resultMap>
    <update id="recoveryStatusByRefundId">
        update trade_detail_base tdb,trade_refund_detail_base rdb
        set tdb.use_status = rdb.use_status
        where tdb.id = rdb.trade_detail_base_id and rdb.refund_id=#{refundId}
    </update>

    <update id="updateStatusByRefundId">
        update trade_detail_base tdb,trade_refund_detail_base rdb
        set tdb.use_status = #{refundStatus}
        where tdb.id = rdb.trade_detail_base_id and rdb.refund_id=#{refundId}
    </update>
    <select id="selectRefundDetailBaseBOList"
            resultType="com.yc.ship.module.trade.service.refund.bo.TradeSupplierRefundBaseBO">
        SELECT tr.*,td.spec_type
        FROM trade_refund_detail_base tr
        inner join trade_detail_base td on tr.trade_detail_base_id = td.id
        where tr.plat_supplier_refund_id = #{supplierRefundId}
    </select>

    <select id="selectDetailBaseList"
            resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.DetailBaseRespVO">
        SELECT td.*,tr.id refundDetailBaseId
        FROM trade_refund_detail_base tr
        inner join trade_detail_base td on tr.trade_detail_base_id = td.id
        where 1= 1
        <if test="supplierRefundId != null and supplierRefundId != ''">
            AND tr.plat_supplier_refund_id = #{supplierRefundId}
        </if>
    </select>
    <select id="selectPlatSupplierRefundVoucherList" resultMap="otaInnerRefundVoucherMap">
        select rdb.supplier_voucher_code,tdb.product_base_id
        from trade_refund_detail_base rdb
        inner join trade_detail_base tdb on rdb.trade_detail_base_id = tdb.id
        where rdb.plat_supplier_refund_id = #{supplierRefundId}
    </select>

</mapper>