select po.id as productionOrderId,
po.nps_no as npsNo,
po.is_end_order as endOrder,
p.product_name as productName,
pm.model as model,
pm.unit as unit,
group_concat(distinct poro.operation_name order by poro.drag_sort, poro.operation_name separator ',') as operationName,
count(distinct pot.id) as productionTaskCount,
sum(ifnull(pot.plan_quantity, 0)) as planQuantity,
sum(ifnull(pot.complete_quantity, 0)) as completeQuantity,
sum(ifnull(pot.complete_quantity, 0)) as goodQuantity,
sum(ifnull(scrapStat.scrapQty, 0)) as scrapQty,
round(sum(ifnull(pot.complete_quantity, 0)) / nullif(sum(ifnull(pot.plan_quantity, 0)), 0) * 100, 2) as completionStatus,
max(poro.type) as type,
case when sum(case when pot.work_order_no like 'FG%' then 1 else 0 end) > 0
then '返工返修' else '正常' end as workOrderType,
group_concat(distinct pot.work_order_no order by pot.work_order_no separator ',') as workOrderNo,
min(pot.plan_start_time) as planStartTime,
max(pot.plan_end_time) as planEndTime,
min(pot.actual_start_time) as actualStartTime,
max(pot.actual_end_time) as actualEndTime,
max(pot.status) as status
from production_operation_task pot
left join production_order po on pot.production_order_id = po.id
left join production_order_routing_operation poro on pot.production_order_routing_operation_id = poro.id
left join product_model pm on pm.id = ifnull(poro.product_model_id, po.product_model_id)
left join product p on pm.product_id = p.id
left join (
select ppm.production_operation_task_id as taskId,
sum(ifnull(ppo.scrap_qty, 0)) as scrapQty
from production_product_main ppm
left join production_product_output ppo on ppo.production_product_main_id = ppm.id
group by ppm.production_operation_task_id
) scrapStat on scrapStat.taskId = pot.id
select po.id as productionOrderId,
po.nps_no as npsNo,
po.is_end_order as endOrder,
p.product_name as productName,
pm.model as model,
pm.unit as unit,
group_concat(distinct poro.operation_name order by poro.drag_sort, poro.operation_name separator ',') as operationName,
count(distinct pot.id) as productionTaskCount,
po.quantity as planQuantity,
po.complete_quantity as completeQuantity,
po.complete_quantity as goodQuantity,
sum(ifnull(scrapStat.scrapQty, 0)) as scrapQty,
round(ifnull(po.complete_quantity, 0) / nullif(po.quantity, 0) * 100, 2) as completionStatus,
max(poro.type) as type,
case when sum(case when pot.work_order_no like 'FG%' then 1 else 0 end) > 0
then '返工返修' else '正常' end as workOrderType,
group_concat(distinct pot.work_order_no order by pot.work_order_no separator ',') as workOrderNo,
min(pot.plan_start_time) as planStartTime,
max(pot.plan_end_time) as planEndTime,
min(pot.actual_start_time) as actualStartTime,
max(pot.actual_end_time) as actualEndTime,
max(pot.status) as status
from production_operation_task pot
left join production_order po on pot.production_order_id = po.id
left join production_order_routing_operation poro on pot.production_order_routing_operation_id = poro.id
left join product_model pm on pm.id = po.product_model_id
left join product p on pm.product_id = p.id
left join (
select ppm.production_operation_task_id as taskId,
sum(ifnull(ppo.scrap_qty, 0)) as scrapQty
from production_product_main ppm
left join production_product_output ppo on ppo.production_product_main_id = ppm.id
group by ppm.production_operation_task_id
) scrapStat on scrapStat.taskId = pot.id
and po.nps_no like concat('%', #{c.npsNo}, '%')
and pot.production_order_id = #{c.productionOrderId}
group by po.id
order by po.id desc
and po.nps_no like concat('%', #{c.npsNo}, '%')
and pot.production_order_id = #{c.productionOrderId}
group by po.id, po.nps_no, po.is_end_order, p.product_name, pm.model, pm.unit
order by po.id desc
select pot.id,
pot.work_order_no,
pot.plan_start_time as planStartTime,
pot.plan_end_time as planEndTime,
pot.actual_start_time as actualStartTime,
pot.actual_end_time as actualEndTime,
pot.plan_quantity as planQuantity,
ifnull(pot.complete_quantity, 0) as completeQuantity,
poro.operation_name as processName,
p.product_name as productName,
pm.model,
pm.unit,
po.nps_no as productOrderNpsNo
from production_operation_task pot
left join production_order po on pot.production_order_id = po.id
left join production_order_routing_operation poro on pot.production_order_routing_operation_id = poro.id
left join product_model pm on pm.id = ifnull(poro.product_model_id, po.product_model_id)
left join product p on pm.product_id = p.id
where date(pot.create_time) between #{startDate} and #{endDate}
order by pot.create_time desc
select id,
actual_start_time as actualStartTime,
plan_quantity as planQuantity
from production_operation_task
where actual_start_time >= #{startDateTime}
and actual_start_time <= #{endDateTime}
select poro.operation_name as processName,
sum(ifnull(ppi.input_quantity, 0)) as totalInput,
sum(ifnull(ppo.scrap_qty, 0)) as totalScrap,
sum(greatest(ifnull(ppo.quantity, 0) - ifnull(ppo.scrap_qty, 0), 0)) as totalOutput
from production_product_output ppo
inner join production_product_main ppm on ppo.production_product_main_id = ppm.id
inner join production_operation_task pot on ppm.production_operation_task_id = pot.id
left join production_order_routing_operation poro on pot.production_order_routing_operation_id = poro.id
left join production_product_input ppi on ppi.production_product_main_id = ppm.id
and ppo.create_time >= #{startDateTime}
and ppo.create_time <= #{endDateTime}
and ppm.create_user = #{userId}
and poro.technology_operation_id in
#{id}
group by poro.technology_operation_id, poro.operation_name
SELECT pot.*,
poro.operation_name AS processName,
pm.model AS model,
pm.unit AS unit,
p.product_name AS productName,
po.nps_no AS productOrderNpsNo,
ROUND(IFNULL(pot.complete_quantity, 0) / NULLIF(pot.plan_quantity, 0) * 100, 2) AS completionStatus,
IFNULL(scrapStat.scrapQty, 0) AS scrapQty
FROM production_operation_task pot
LEFT JOIN production_order po ON pot.production_order_id = po.id
LEFT JOIN production_order_routing_operation poro ON pot.production_order_routing_operation_id = poro.id
LEFT JOIN product_model pm ON pm.id = ifnull(poro.product_model_id, po.product_model_id)
LEFT JOIN product p ON p.id = pm.product_id
LEFT JOIN (
SELECT ppm.production_operation_task_id AS taskId,
SUM(IFNULL(ppo.scrap_qty, 0)) AS scrapQty
FROM production_product_main ppm
LEFT JOIN production_product_output ppo ON ppo.production_product_main_id = ppm.id
GROUP BY ppm.production_operation_task_id
) scrapStat ON scrapStat.taskId = pot.id
WHERE pot.id = #{id}
select poro.operation_name as operationName,
max(poro.type) as type,
count(pot.id) as productionTaskCount,
sum(ifnull(pot.plan_quantity, 0)) as planQuantity,
sum(ifnull(pot.complete_quantity, 0)) as completeQuantity,
sum(ifnull(pot.complete_quantity, 0)) as goodQuantity,
sum(ifnull(outputStat.scrapQty, 0)) as scrapQty,
round(
case
when sum(ifnull(pot.plan_quantity, 0)) = 0 then 0
else (sum(ifnull(pot.complete_quantity, 0)) + sum(ifnull(outputStat.scrapQty, 0)))
/ sum(ifnull(pot.plan_quantity, 0)) * 100
end,
2
) as completionStatus
from production_operation_task pot
left join production_order_routing_operation poro on pot.production_order_routing_operation_id = poro.id
left join (
select ppm.production_operation_task_id as taskId,
sum(ifnull(ppo.scrap_qty, 0)) as scrapQty
from production_product_main ppm
left join production_product_output ppo on ppo.production_product_main_id = ppm.id
group by ppm.production_operation_task_id
) outputStat on outputStat.taskId = pot.id
and date(pot.create_time) >= #{c.startDate}
and date(pot.create_time) <= #{c.endDate}
and pot.plan_start_time >= #{c.planStartTime}
and pot.plan_end_time <= #{c.planEndTime}
and pot.production_order_id = #{c.productionOrderId}
and pot.production_order_routing_operation_id = #{c.productionOrderRoutingOperationId}
and pot.status = #{c.status}
and poro.operation_name like concat('%', #{c.processName}, '%')
group by poro.operation_name
order by min(poro.drag_sort), poro.operation_name
select pot.id,
pot.work_order_no,
pot.plan_start_time as planStartTime,
pot.plan_end_time as planEndTime,
pot.actual_start_time as actualStartTime,
pot.actual_end_time as actualEndTime,
pot.status,
pot.production_order_id as productionOrderId,
pot.plan_quantity as planQuantity,
pot.complete_quantity as completeQuantity,
po.nps_no as npsNo,
po.is_end_order as endOrder,
p.product_name as productName,
pm.model as model,
pm.unit as unit,
poro.operation_name as operationName,
poro.type as type,
case when pot.work_order_no like 'FG%' then '返工返修' else '正常' end as workOrderType,
ifnull(scrapStat.scrapQty, 0) as scrapQty,
round(ifnull(pot.complete_quantity, 0) / nullif(pot.plan_quantity, 0) * 100, 2) as completionStatus
from production_operation_task pot
left join production_order po on pot.production_order_id = po.id
left join production_order_routing_operation poro on pot.production_order_routing_operation_id = poro.id
left join product_model pm on pm.id = ifnull(poro.product_model_id, po.product_model_id)
left join product p on pm.product_id = p.id
left join (
select ppm.production_operation_task_id as taskId,
sum(ifnull(ppo.scrap_qty, 0)) as scrapQty
from production_product_main ppm
left join production_product_output ppo on ppo.production_product_main_id = ppm.id
group by ppm.production_operation_task_id
) scrapStat on scrapStat.taskId = pot.id
where pot.production_order_id = #{orderId}
order by pot.id desc