<?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.canteen.core.supply.purchase.mapper.DrpPurchaseInquirySupplierMapper">

    <select id="selectByBidStatusAndSupplierIds" resultType="com.bonus.canteen.core.supply.purchase.domain.bo.DrpInquirySupplier">
        select *
        from drp_inquiry_supplier A
        where
        A.bid_status != 5
        <if test="bidStatus != null and bidStatus != 0">
            and A.bid_status = #{bidStatus}
        </if>
        <if test="supplierIds != null and supplierIds.size()>0">
            A.supplier_id in
            <foreach collection="supplierIds" item="supplierId" separator="," open="(" close=")">
                #{supplierId}
            </foreach>
        </if>
    </select>
    <select id="getMinQuoteSupplier" resultType="com.bonus.canteen.core.supply.purchase.domain.bo.MinQuoteSupplierModel">
        SELECT
            a.supplier_id,
            b.supplier_name,
            a.quote_amount
        FROM
            drp_inquiry_supplier a
            LEFT JOIN drp_supplier b ON b.supplier_id = a.supplier_id
        WHERE
            a.inquiry_id = #{inquiryId}
            AND a.quote_time IS NOT NULL
        ORDER BY
            quote_amount
            LIMIT 1
    </select>
    <select id="listSupplierQuote" resultType="com.bonus.canteen.core.supply.purchase.domain.vo.DrpSupplierQuoteVO">
        SELECT
            a.inquiry_supplier_id,
            a.supplier_id,
            b.supplier_name,
            b.supplier_score,
            a.quote_amount,
            a.quote_time,
            a.arrival_time,
            a.bid_status
        FROM
            drp_inquiry_supplier a
            LEFT JOIN drp_supplier b ON b.supplier_id = a.supplier_id
        WHERE
            a.inquiry_id = #{inquiryId} and bid_status <![CDATA[ <> ]]> 2
        order by a.quote_time
    </select>
    <select id="querySupplierQuote" resultType="com.bonus.canteen.core.supply.purchase.domain.vo.QuerySupplierQuoteVO">
        SELECT
            a.supplier_id,
            b.supplier_name,
            a.quote_amount,
            a.quote_time,
            a.arrival_time
        FROM
            drp_inquiry_supplier a
            LEFT JOIN drp_supplier b ON b.supplier_id = a.supplier_id
        WHERE
            a.inquiry_supplier_id = #{inquirySupplierId}
    </select>
    <select id="listSupplierQuoteStatusAmount"
            resultType="com.bonus.canteen.core.supply.purchase.domain.bo.SupplierQuoteStatusAmountModel">
        SELECT
        a.bid_status quoteStatus,
        a.quote_amount
        FROM
        drp_inquiry_supplier a
        LEFT JOIN drp_inquiry b ON b.inquiry_id = a.inquiry_id
        WHERE
        b.`status` IN
        <foreach collection="bidStatusList" item="bidStatus" separator="," open="(" close=")">
            #{bidStatus}
        </foreach>
        AND b.create_time <![CDATA[ >= ]]>  CONCAT(#{content.startTime},' 0:00:00')
        AND b.create_time <![CDATA[ <= ]]>  CONCAT(#{content.endTime},' 23:59:59')
        <if test="supplierAuthority != null">
            AND a.supplier_id = #{supplierAuthority}
        </if>
    </select>
    <select id="listSupplierQuoteAll" resultType="com.bonus.canteen.core.supply.purchase.domain.vo.DrpSupplierQuoteVO">
        SELECT
            a.inquiry_supplier_id,
            a.supplier_id,
            b.supplier_name,
            b.supplier_score,
            a.quote_amount,
            a.quote_time,
            a.arrival_time,
            a.bid_status
        FROM
            drp_inquiry_supplier a
                LEFT JOIN drp_supplier b ON b.supplier_id = a.supplier_id
        WHERE
            a.inquiry_id = #{inquiryId}
        order by a.quote_time
    </select>
</mapper>


