<?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.fjhx.victoriatourist.mapper.deliver.DeliverGoodsMapper">
    <select id="getPage" resultType="com.fjhx.victoriatourist.entity.deliver.vo.DeliverGoodsVo">
        select
            dg.id,
            dg.logistics_company_code,
            dg.code,
            dg.purchase_id,
            dg.status,
            dg.create_user,
            dg.create_time,
            dg.update_user,
            dg.update_time
        from deliver_goods dg
            ${ew.customSqlSegment}
    </select>
    <select id="listDeliverGoodsDetails"
            resultType="com.fjhx.victoriatourist.entity.deliver.vo.DeliverGoodsDetailsVo">
        SELECT
            dg.code logisticsCode,
            dg.purchase_id,
            dgd.*
        FROM
            deliver_goods dg
                JOIN deliver_goods_details dgd ON dgd.deliver_goods_id = dg.id
            ${ew.customSqlSegment}
    </select>
    <select id="getQualityInfoByPurchaseId" resultType="com.fjhx.purchase.entity.quality.po.QualityDetail">
        SELECT qd.product_info_id                bussiness_id,
               sum(qd.qualified_quantity)        qualifiedCount,
               sum(qd.disqualification_quantity) noQualifiedCount
        FROM stock_wait sw
                 JOIN arrival_stock_records asr ON asr.stock_wait_id = sw.id
                 JOIN arrival_stock_records_details asrd ON asrd.arrival_stock_records_id = asr.id
                 JOIN quality_details qd ON qd.arrival_stock_records_details_id = asrd.id
        WHERE sw.business_id = #{id}
        GROUP BY qd.product_info_id
    </select>

</mapper>
