<?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.purchase.mapper.arrival.ArrivalDetailMapper">
    <select id="getPage" resultType="com.fjhx.purchase.entity.arrival.vo.ArrivalDetailVo">
        SELECT t1.*,
               t2.`code`,
               t2.supply_id,
               IFNULL(SUM(t3.qualified_count), 0)    AS qualifiedCount,
               IFNULL(SUM(t3.no_qualified_count), 0) AS noQualifiedCount
        FROM arrival_detail t1
                 LEFT JOIN arrival t2 ON t1.arrival_id = t2.id
                 LEFT JOIN quality_detail t3 ON t1.id = t3.arrival_detail_id
                 LEFT JOIN purchase_detail pd ON t1.purchase_detail_id = pd.id
                 LEFT JOIN purchase p ON pd.purchase_id = p.id
            ${ew.customSqlSegment}
    </select>

    <select id="getSumCount" resultType="java.math.BigDecimal">
        SELECT
            IFNULL(SUM( count ) ,0) AS sumArrivalCount
        FROM
            arrival_detail
        WHERE
            purchase_detail_id = #{purchaseDetailId}
          AND bussiness_id = #{businessId}
    </select>
    <select id="getArrivalDetail" resultType="com.fjhx.purchase.entity.arrival.vo.ArrivalDetailVo">
        SELECT
            a.purchase_id,
            ad.*
        FROM
            arrival a
                JOIN arrival_detail ad ON ad.arrival_id = a.id
            ${ew.customSqlSegment}
    </select>
</mapper>
