|
|
|
|
@ -43,9 +43,23 @@ namespace CncRepository.Impl
|
|
|
|
|
seg.program_name AS ProgramName,
|
|
|
|
|
SUM(CASE WHEN seg.is_settled=1 THEN seg.quantity
|
|
|
|
|
ELSE COALESCE(seg.end_part_count, seg.start_part_count) - seg.start_part_count END) AS TotalQuantity,
|
|
|
|
|
COUNT(*) AS SegmentCount, NULL AS TotalRunTime, NULL AS TotalCuttingTime, NULL AS TotalCycleTime
|
|
|
|
|
COUNT(*) AS SegmentCount,
|
|
|
|
|
cr_runtime.run_hours AS TotalRunTime,
|
|
|
|
|
cr_runtime.cut_hours AS TotalCuttingTime,
|
|
|
|
|
NULL AS TotalCycleTime
|
|
|
|
|
FROM cnc_production_segment seg
|
|
|
|
|
LEFT JOIN cnc_machine m ON seg.machine_id = m.id
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT cr.machine_id, DATE(cr.collect_time) AS d,
|
|
|
|
|
COALESCE(ROUND(SUM(max_min.delta)/3600,1), 0) AS run_hours,
|
|
|
|
|
COALESCE(ROUND(SUM(max_min.delta)/3600,1), 0) AS cut_hours
|
|
|
|
|
FROM cnc_collect_record cr
|
|
|
|
|
JOIN (
|
|
|
|
|
SELECT machine_id, DATE(collect_time) AS dd, MAX(cutting_time)-MIN(cutting_time) AS delta
|
|
|
|
|
FROM cnc_collect_record GROUP BY machine_id, DATE(collect_time)
|
|
|
|
|
) max_min ON cr.machine_id = max_min.machine_id AND DATE(cr.collect_time) = max_min.dd
|
|
|
|
|
GROUP BY cr.machine_id, DATE(cr.collect_time)
|
|
|
|
|
) cr_runtime ON cr_runtime.machine_id = seg.machine_id AND cr_runtime.d = seg.production_date
|
|
|
|
|
WHERE NOT EXISTS (
|
|
|
|
|
SELECT 1 FROM cnc_daily_production dp
|
|
|
|
|
WHERE dp.machine_id = seg.machine_id AND dp.production_date = seg.production_date
|
|
|
|
|
|