<?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.supplier.TradeSupplierOrderMapper">

    <select id="selectSupplierOrderSuccessCount" resultType="java.util.Map">
        select count(*) totalCount,count(if(tso.order_status=6,1,null)) successCount
        from trade_supplier_order tso
        where tso.order_id=#{orderId}
    </select>

    <select id="selectSupplierOrderNoCheckCount" resultType="java.lang.Integer">
        select count(1) num from trade_detail_base where plat_supplier_order_id=#{platSupplierOrderId} and  use_status = 1
    </select>

    <select id="getPlatformOrderList" resultType="java.util.Map">
        SELECT
            t1.order_id orderId,t2.id platformOrderId,t2.order_no platformOrderNo,t2.external_order_no externalOrderNo
        FROM trade_supplier_order t1
            INNER JOIN trade_order t2 ON t1.trade_no = t2.external_order_no
        WHERE t1.order_id = #{orderId}
    </select>

    <update id="deleteOrderById">
        delete from trade_supplier_order where id = #{id}
    </update>

    <select id="selectSupplierByUserId" resultType="com.yc.ship.module.trade.controller.admin.supplier.vo.SupplierRespVO">
        select t1.* from product_supplier t1 inner join product_supplier_user t2 on t1.id = t2.supplier_id where t2.user_id = #{userId} and t2.deleted=0 and t1.deleted=0
    </select>
</mapper>
