<?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.mapper.quality.QualityTestingMapper">

    <select id="getPage" resultType="java.util.Map">
        select qt.id,
               wb.contract_code    contractCode,
               s.name              supplierName,
               m.name              materialName,
               m.spec              materialSpec,
               qt.create_time      arrivalTime,
               wb.tag_quantity_sum arrivalQuantity,
               cd.quantity         purchaseQuantity
        from quality_testing qt
                 left join water_batch wb on qt.water_batch_id = qt.id
                 left join contract_details cd on wb.contract_details_id = cd.id
                 left join supplier s on wb.supplier_id = s.id
                 left join material m on wb.material_id = m.id
            ${ew.customSqlSegment}
    </select>

    <select id="recordStatistics" resultType="java.util.Map">
        select count(0)                                                    count,
               ifnull(sum(qt.check_area), 0)                               sumArea,
               ifnull(round(sum(qt.check_invalid_ratio) / count(0), 2), 0) invalidRatio,
               ifnull(sum(if(qt.check_judgment = 1, 1, 0)), 0)             qualifiedCount,
               ifnull(sum(if(qt.check_judgment = 2, 1, 0)), 0)             unqualifiedCount
        from quality_testing qt
            ${ew.customSqlSegment}
    </select>

    <select id="recordPage" resultType="java.util.LinkedHashMap">
        select qt.id,
               wb.contract_code,
               wb.code        batchCode,
               m.code         materialCode,
               m.name         materialName,
               wb.tag_quantity_sum,
               wb.create_time arrivalTime,
               qt.check_user_id,
               qt.check_time,
               qt.check_area,
               qt.check_judgment,
               qt.check_invalid_ratio
        from quality_testing qt
                 left join water_batch wb on qt.water_batch_id = wb.id
                 left join material m on qt.material_id = m.id
            ${ew.customSqlSegment}
    </select>

</mapper>
