From 54a351c35dd08521efcd71d7c846478deb46c888 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 08 六月 2026 18:09:53 +0800
Subject: [PATCH] feat(production): 添加生产作业任务分页查询功能

---
 src/main/resources/mapper/production/ProductionOperationTaskMapper.xml |  144 +++++++++++++++++++++++++++++++++++++----------
 1 files changed, 113 insertions(+), 31 deletions(-)

diff --git a/src/main/resources/mapper/production/ProductionOperationTaskMapper.xml b/src/main/resources/mapper/production/ProductionOperationTaskMapper.xml
index 199eb21..58c9f5a 100644
--- a/src/main/resources/mapper/production/ProductionOperationTaskMapper.xml
+++ b/src/main/resources/mapper/production/ProductionOperationTaskMapper.xml
@@ -21,21 +21,29 @@
         <result column="dept_id" property="deptId" />
     </resultMap>
 
-    <select id="pageProductionOperationTask" resultType="com.ruoyi.production.bean.vo.ProductionOperationTaskVo">
-        select pot.*,
-               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,
-               IFNULL(scrapStat.scrapQty, 0) AS scrapQty,
-        ROUND(IFNULL(pot.complete_quantity, 0) / NULLIF(pot.plan_quantity, 0) * 100, 2) AS completionStatus,
-        CASE
-            WHEN pot.work_order_no LIKE 'FG%' THEN '杩斿伐杩斾慨'
-            ELSE '姝e父'
-            END AS work_order_type
+    <sql id="groupedProductionOperationTaskSelect">
+        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 '姝e父' 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
@@ -48,30 +56,67 @@
                      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
+    </sql>
+
+    <select id="pageProductionOperationTask" resultType="com.ruoyi.production.bean.vo.ProductionOperationTaskVo">
+        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 '姝e父' 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
         <where>
-            <if test="c != null and c.id != null">
-                and pot.id = #{c.id}
-            </if>
-            <if test="c != null and c.npsNo != null">
+            <if test="c != null and c.npsNo != null and c.npsNo != ''">
                 and po.nps_no like concat('%', #{c.npsNo}, '%')
             </if>
             <if test="c != null and c.productionOrderId != null">
                 and pot.production_order_id = #{c.productionOrderId}
             </if>
-            <if test="c != null and c.productionOrderRoutingOperationId != null">
-                and pot.production_order_routing_operation_id = #{c.productionOrderRoutingOperationId}
+        </where>
+        group by po.id
+        order by po.id desc
+    </select>
+
+    <select id="listGroupedProductionOperationTask" resultType="com.ruoyi.production.bean.vo.ProductionOperationTaskVo">
+        <include refid="groupedProductionOperationTaskSelect"/>
+        <where>
+            <if test="c != null and c.npsNo != null and c.npsNo != ''">
+                and po.nps_no like concat('%', #{c.npsNo}, '%')
             </if>
-            <if test="c != null and c.status != null">
-                and pot.status = #{c.status}
-            </if>
-            <if test="c != null and c.isProduction != null">
-                and poro.is_production = #{c.isProduction}
-            </if>
-            <if test="c != null and c.workOrderNo != null and c.workOrderNo != ''">
-                and pot.work_order_no like concat('%', #{c.workOrderNo}, '%')
+            <if test="c != null and c.productionOrderId != null">
+                and pot.production_order_id = #{c.productionOrderId}
             </if>
         </where>
-        order by pot.id desc
+        group by po.id, po.nps_no, po.is_end_order, p.product_name, pm.model, pm.unit
+        order by po.id desc
     </select>
 
     <select id="selectTaskStatisticsByDate" resultType="com.ruoyi.home.dto.ProductionTaskStatisticsDto">
@@ -110,7 +155,7 @@
         select poro.operation_name as processName,
                sum(ifnull(ppi.input_quantity, 0)) as totalInput,
                sum(ifnull(ppo.scrap_qty, 0)) as totalScrap,
-               sum(ifnull(ppo.quantity, 0) - ifnull(ppo.scrap_qty, 0)) as totalOutput
+               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
@@ -215,4 +260,41 @@
         order by min(poro.drag_sort), poro.operation_name
     </select>
 
+    <select id="listByOrderId" resultType="com.ruoyi.production.bean.vo.ProductionOperationTaskVo">
+        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 '姝e父' 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
+    </select>
+
 </mapper>

--
Gitblit v1.9.3