From 0be02df3d287f802c76e5738916301a877dfaa0e Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期一, 27 四月 2026 16:56:12 +0800
Subject: [PATCH] feat: 生产报工与报工台账功能更改完成

---
 src/main/resources/mapper/production/ProductionProductMainMapper.xml |  206 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 193 insertions(+), 13 deletions(-)

diff --git a/src/main/resources/mapper/production/ProductionProductMainMapper.xml b/src/main/resources/mapper/production/ProductionProductMainMapper.xml
index a122e90..3c3dbca 100644
--- a/src/main/resources/mapper/production/ProductionProductMainMapper.xml
+++ b/src/main/resources/mapper/production/ProductionProductMainMapper.xml
@@ -10,20 +10,55 @@
         <result property="tenantId" column="tenant_id"/>
         <result property="createTime" column="create_time"/>
         <result property="status" column="status"/>
+        <result property="reportStartTime" column="report_start_time"/>
+        <result property="reportEndTime" column="report_end_time"/>
+        <result property="reportDurationMinutes" column="report_duration_minutes"/>
     </resultMap>
 
     <select id="listPageProductionProductMainDto" resultType="com.ruoyi.production.dto.ProductionProductMainDto">
-        select ppm.*,
-        pwo.work_order_no as workOrderNo,
-        pwo.status as workOrderStatus,
-        u.nick_name as nickName,
-        p.product_name as productName,
-        pp.name as process,
-        pm.model as productModelName,
-        ppo.quantity,
-        ppo.scrap_qty,
-        pm.unit,
-        sl.sales_contract_no salesContractNo
+        select
+        min(ppm.id) as id,
+        null as productNo,
+        min(ppm.user_id) as userId,
+        min(ppm.work_order_id) as workOrderId,
+        min(ppm.status) as status,
+        min(ppm.report_start_time) as reportStartTime,
+        max(ppm.report_end_time) as reportEndTime,
+        sum(ifnull(ppm.report_duration_minutes, 0)) as reportDurationMinutes,
+        max(pwo.work_order_no) as workOrderNo,
+        max(po.nps_no) as productOrderNpsNo,
+        max(pwo.status) as workOrderStatus,
+        max(u.nick_name) as nickName,
+        max(p.product_name) as productName,
+        max(CASE pp.type
+            WHEN 1 THEN '鍔犲伐'
+            WHEN 2 THEN '鍒澘鍐疯姱鍒朵綔'
+            WHEN 3 THEN '绠¤矾缁勫'
+            WHEN 4 THEN '缃愪綋杩炴帴鍙婅皟璇�'
+            WHEN 5 THEN '娴嬭瘯鎵撳帇'
+            WHEN 6 THEN '鍏朵粬'
+            ELSE pp.name
+        END) as process,
+        max(pm.model) as productModelName,
+        sum(ifnull(ppo.quantity, 0)) as quantity,
+        sum(ifnull(ppo.scrap_qty, 0)) as scrapQty,
+        sum(ifnull(ppo.quantity, 0)) as outputTotalQuantity,
+        sum(ifnull(ppo.scrap_qty, 0)) as scrapTotalQuantity,
+        round(ifnull((
+            select sum(ifnull(pri.planned_work_hours, 0))
+            from product_process_route_item pri
+            where pri.product_order_id = po.id
+        ), 0), 2) as projectTotalHours,
+        ifnull(max(pp.salary_quota), 0) as processStandardHours,
+        round(sum(ifnull(ppm.report_duration_minutes, 0)) / 60, 2) as actualReportHours,
+        round(ifnull((
+            select sum(d.duration_minutes)
+            from production_product_report_daily d
+            where d.user_id = ppm.user_id
+              and d.report_date = curdate()
+        ), 0) / 60, 2) as dailyPersonHours,
+        max(pm.unit) as unit,
+        max(sl.sales_contract_no) as salesContractNo
         from
         production_product_main ppm
         left join product_work_order pwo on pwo.id = ppm.work_order_id
@@ -48,10 +83,155 @@
             <if test="c.status != null and c.status != ''">
                 and ppm.status = #{c.status}
             </if>
+            <if test="c.userId != null">
+                and ppm.user_id = #{c.userId}
+            </if>
         </where>
-        order by ppm.id
-
+        group by ppm.work_order_id, po.sales_ledger_id, po.sale_ledger_product_id, ppm.user_id
+        order by max(ppm.id) desc
     </select>
+
+    <select id="listPageProductionProductMainDailyDto" resultType="com.ruoyi.production.dto.ProductionProductMainDto">
+        select
+        min(ppm.id) as id,
+        min(ppm.product_no) as productNo,
+        d.user_id as userId,
+        d.work_order_id as workOrderId,
+        max(pwo.work_order_no) as workOrderNo,
+        max(po.nps_no) as productOrderNpsNo,
+        max(pwo.status) as workOrderStatus,
+        max(u.nick_name) as nickName,
+        max(p.product_name) as productName,
+        max(CASE pp.type
+            WHEN 1 THEN '鍔犲伐'
+            WHEN 2 THEN '鍒澘鍐疯姱鍒朵綔'
+            WHEN 3 THEN '绠¤矾缁勫'
+            WHEN 4 THEN '缃愪綋杩炴帴鍙婅皟璇�'
+            WHEN 5 THEN '娴嬭瘯鎵撳帇'
+            WHEN 6 THEN '鍏朵粬'
+            ELSE pp.name
+        END) as process,
+        max(pm.model) as productModelName,
+        max(pm.unit) as unit,
+        max(sl.sales_contract_no) as salesContractNo,
+        d.report_date as schedulingDate,
+        sum(d.duration_minutes) as reportDurationMinutes,
+        round(sum(d.duration_minutes) / 60, 2) as dailyPersonHours,
+        round(sum(d.duration_minutes) / 60, 2) as actualReportHours,
+        sum(ifnull(ppo.quantity, 0)) as quantity,
+        sum(ifnull(ppo.scrap_qty, 0)) as scrapQty,
+        sum(ifnull(ppo.quantity, 0)) as outputTotalQuantity,
+        sum(ifnull(ppo.scrap_qty, 0)) as scrapTotalQuantity,
+        round(ifnull((
+            select sum(ifnull(pri.planned_work_hours, 0))
+            from product_process_route_item pri
+            where pri.product_order_id = po.id
+        ), 0), 2) as projectTotalHours,
+        ifnull(max(pp.salary_quota), 0) as processStandardHours
+        from production_product_report_daily d
+        left join production_product_main ppm on ppm.id = d.product_main_id
+        left join product_work_order pwo on pwo.id = d.work_order_id
+        left join product_process_route_item ppri on ppri.id = pwo.product_process_route_item_id
+        left join product_process pp on pp.id = ppri.process_id
+        left join product_order po on po.id = pwo.product_order_id
+        left join production_product_output ppo
+            on ppm.id = ppo.product_main_id
+           and date(ppm.report_end_time) = d.report_date
+        left join product_model pm on pm.id = ppo.product_model_id
+        left join product p on p.id = pm.product_id
+        left join sales_ledger sl on sl.id = po.sales_ledger_id
+        left join sys_user u on u.user_id = d.user_id
+        <where>
+            <if test="c.workOrderId != null">
+                and d.work_order_id = #{c.workOrderId}
+            </if>
+            <if test="c.nickName != null and c.nickName != ''">
+                and u.nick_name like concat('%',#{c.nickName},'%')
+            </if>
+            <if test="c.workOrderNo != null and c.workOrderNo != ''">
+                and pwo.work_order_no like concat('%',#{c.workOrderNo},'%')
+            </if>
+            <if test="c.workOrderStatus != null and c.workOrderStatus != ''">
+                and pwo.status = #{c.workOrderStatus}
+            </if>
+            <if test="c.userId != null">
+                and d.user_id = #{c.userId}
+            </if>
+            <if test="c.startDate != null">
+                and d.report_date <![CDATA[ >= ]]> #{c.startDate}
+            </if>
+            <if test="c.endDate != null">
+                and d.report_date <![CDATA[ <= ]]> #{c.endDate}
+            </if>
+        </where>
+        group by d.work_order_id, d.user_id, d.report_date, po.sales_ledger_id, po.sale_ledger_product_id
+        order by d.report_date desc, d.user_id
+    </select>
+
+    <select id="listPageProductionProductMainDetailDto" resultType="com.ruoyi.production.dto.ProductionProductMainDto">
+        select
+        ppm.*,
+        pwo.work_order_no as workOrderNo,
+        po.nps_no as productOrderNpsNo,
+        pwo.status as workOrderStatus,
+        u.nick_name as nickName,
+        p.product_name as productName,
+        CASE pp.type
+            WHEN 1 THEN '鍔犲伐'
+            WHEN 2 THEN '鍒澘鍐疯姱鍒朵綔'
+            WHEN 3 THEN '绠¤矾缁勫'
+            WHEN 4 THEN '缃愪綋杩炴帴鍙婅皟璇�'
+            WHEN 5 THEN '娴嬭瘯鎵撳帇'
+            WHEN 6 THEN '鍏朵粬'
+            ELSE pp.name
+        END as process,
+        pm.model as productModelName,
+        ppo.quantity,
+        ppo.scrap_qty as scrapQty,
+        ppo.quantity as outputTotalQuantity,
+        ppo.scrap_qty as scrapTotalQuantity,
+        pm.unit,
+        sl.sales_contract_no salesContractNo,
+        round(ifnull((
+            select sum(ifnull(pri.planned_work_hours, 0))
+            from product_process_route_item pri
+            where pri.product_order_id = po.id
+        ), 0), 2) as projectTotalHours,
+        ifnull(pp.salary_quota, 0) as processStandardHours,
+        round(ifnull(ppm.report_duration_minutes, 0) / 60, 2) as actualReportHours,
+        round(ifnull((
+            select sum(d.duration_minutes)
+            from production_product_report_daily d
+            where d.user_id = ppm.user_id
+              and d.report_date = curdate()
+        ), 0) / 60, 2) as dailyPersonHours
+        from production_product_main ppm
+        left join product_work_order pwo on pwo.id = ppm.work_order_id
+        left join product_process_route_item ppri on ppri.id = pwo.product_process_route_item_id
+        left join product_process pp on pp.id = ppri.process_id
+        left join product_order po on po.id = pwo.product_order_id
+        left join production_product_output ppo on ppm.id = ppo.product_main_id
+        left join product_model pm on pm.id = ppo.product_model_id
+        left join product p on p.id = pm.product_id
+        left join sales_ledger sl on sl.id = po.sales_ledger_id
+        left join sys_user u on u.user_id = ppm.user_id
+        <where>
+            <if test="c.workOrderId != null">
+                and ppm.work_order_id = #{c.workOrderId}
+            </if>
+            <if test="c.userId != null">
+                and ppm.user_id = #{c.userId}
+            </if>
+            <if test="c.startDate != null">
+                and date(ppm.report_end_time) <![CDATA[ >= ]]> #{c.startDate}
+            </if>
+            <if test="c.endDate != null">
+                and date(ppm.report_end_time) <![CDATA[ <= ]]> #{c.endDate}
+            </if>
+        </where>
+        order by ppm.id desc
+    </select>
+
     <select id="getOrderByMainId" resultType="com.ruoyi.production.pojo.ProductOrder">
         select po.*
         from product_order po

--
Gitblit v1.9.3