RIGHT('00' + CAST(DATEPART(HOUR, t.create_time) AS VARCHAR(2)), 2) + ':00' AS hourSlot,
CAST(COUNT(1) AS DECIMAL(18,4)) AS productionQuantity,
CAST(SUM(CASE WHEN (UPPER(t.scan_result) IN ('OK','PASS') OR t.scan_result IN (N'通过')) THEN 1 ELSE 0 END) AS DECIMAL(18,4)) AS qualifiedQuantity,
CAST(SUM(CASE WHEN t.scan_result IS NULL THEN 0 WHEN (UPPER(t.scan_result) IN ('OK','PASS') OR t.scan_result IN (N'通过')) THEN 0 ELSE 1 END) AS DECIMAL(18,4)) AS unqualifiedQuantity
FROM prod_output_scan_info t
LEFT JOIN ${planTableName} ppi
ON ppi.process_id = t.process_id
AND ppi.release_id = t.machine_id
AND t.create_time >= COALESCE(ppi.real_begin_time, ppi.plan_begin_time)
AND t.create_time < COALESCE(ppi.real_end_time, ppi.plan_end_time, DATEADD(day, 1, COALESCE(ppi.real_begin_time, ppi.plan_begin_time)))
LEFT JOIN base_material_info bmi ON bmi.material_id = t.materiel_id
<where>
<iftest="map.beginDate != null and map.beginDate != '' and map.endDate != null and map.endDate != ''">
AND t.create_time >= CAST(#{map.beginDate} AS DATETIME)
AND t.create_time < DATEADD(day, 1, CAST(#{map.endDate} AS DATETIME))
</if>
<iftest="map.processId != null and map.processId != ''">
AND t.process_id = #{map.processId}
</if>
<iftest="map.machineId != null and map.machineId != ''">
AND t.machine_id = #{map.machineId}
</if>
<iftest="map.shiftId != null and map.shiftId != ''">
AND ppi.shift_id = #{map.shiftId}
</if>
<iftest="map.classTeamId != null and map.classTeamId != ''">
AND ppi.class_team_id = #{map.classTeamId}
</if>
<iftest="map.materialName != null and map.materialName != ''">
AND bmi.material_name LIKE CONCAT('%', #{map.materialName}, '%')
</if>
</where>
GROUP BY CONVERT(DATE, t.create_time), DATEPART(HOUR, t.create_time)
ORDER BY productionDate, DATEPART(HOUR, t.create_time)