From 80e73d98a876af4b6c9efff7c74e908b056d8f4e Mon Sep 17 00:00:00 2001
From: chenlu <1320612696@qq.com>
Date: 星期三, 26 十一月 2025 11:28:39 +0800
Subject: [PATCH] 添加生产报表默认查询时间相关配置部分代码

---
 north-glass-erp/src/main/resources/mapper/pp/Report.xml |  210 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 171 insertions(+), 39 deletions(-)

diff --git a/north-glass-erp/src/main/resources/mapper/pp/Report.xml b/north-glass-erp/src/main/resources/mapper/pp/Report.xml
index 7099592..acd6a17 100644
--- a/north-glass-erp/src/main/resources/mapper/pp/Report.xml
+++ b/north-glass-erp/src/main/resources/mapper/pp/Report.xml
@@ -132,6 +132,8 @@
         <result column="workProcessName" property="workProcessName"/>
         <result column="device_name" property="deviceName"/>
         <result column="order_type" property="orderType"/>
+        <result column="thicknessSum" property="thicknessSum"/>
+        <result column="thicknessArea" property="thicknessArea"/>
     </resultMap>
 
     <resultMap id="scheduleProductionScheduleMap" type="com.example.erp.dto.pp.ScheduleProductionScheduleDTO">
@@ -1669,7 +1671,25 @@
 
     <select id="teamOutputMp" resultMap="teamOutputMap">
         SELECT
-        *
+        t.*,
+        -- 鐜荤拑鎬诲帤搴︼紙mm锛�
+        (
+        SELECT SUM(CAST(REGEXP_SUBSTR(seg, '^[0-9]+') AS UNSIGNED))
+        FROM JSON_TABLE(
+        CONCAT('["', REPLACE(t.workProcessName, '+', '","'), '"]'),
+        '$[*]' COLUMNS (seg VARCHAR(100) PATH '$')
+        ) jt
+        ) AS thicknessSum,
+        ROUND(
+        (
+        SELECT SUM(CAST(REGEXP_SUBSTR(seg, '^[0-9]+') AS UNSIGNED))
+        FROM JSON_TABLE(
+        CONCAT('["', REPLACE(t.workProcessName, '+', '","'), '"]'),
+        '$[*]' COLUMNS (seg VARCHAR(100) PATH '$')
+        ) jt2
+        ) * t.area,
+        2
+        ) AS thicknessArea
         FROM
         (
         SELECT
@@ -1778,6 +1798,10 @@
         <if test="teamOutputDTO.workProcessName != null and teamOutputDTO.workProcessName != ''">
             AND t.workProcessName REGEXP #{teamOutputDTO.workProcessName}
         </if>
+        HAVING 1 = 1
+        <if test="teamOutputDTO.thicknessSum != null and teamOutputDTO.thicknessSum != ''">
+            AND thicknessSum REGEXP #{teamOutputDTO.thicknessSum}
+        </if>
         ORDER BY
         t.this_process,
         t.process_id,
@@ -1854,52 +1878,116 @@
 
     <select id="teamOutputPageTotal">
         SELECT
-        CEILING(count(*)/#{pageSize}) as 'pageTotal',
-        count(*) as 'total'
-        FROM
+        CEILING(COUNT(*) / #{pageSize}) AS pageTotal,
+        COUNT(*) AS total
+        FROM (
+
+        SELECT
+        t.*,
+
+        CASE
+        WHEN t.workProcessName IS NULL OR t.workProcessName = '' THEN 0
+        ELSE (
+        SELECT SUM(CAST(REGEXP_SUBSTR(seg, '^[0-9]+') AS UNSIGNED))
+        FROM JSON_TABLE(
+        CONCAT('["', REPLACE(t.workProcessName, '+', '","'), '"]'),
+        '$[*]' COLUMNS (seg VARCHAR(100) PATH '$')
+        ) jt
+        )
+        END AS thicknessSum,
+        CASE
+        WHEN t.workProcessName IS NULL OR t.workProcessName = '' THEN 0
+        ELSE ROUND(
         (
+        SELECT SUM(CAST(REGEXP_SUBSTR(seg2, '^[0-9]+') AS UNSIGNED))
+        FROM JSON_TABLE(
+        CONCAT('["', REPLACE(t.workProcessName, '+', '","'), '"]'),
+        '$[*]' COLUMNS (seg2 VARCHAR(100) PATH '$')
+        ) jt2
+        ) * t.area,
+        2
+        )
+        END AS thicknessArea
+        FROM (
         SELECT
         rw.reporting_work_time,
         rw.this_process,
         rw.teams_groups_name,
         o.project,
+        o.order_id,
         rw.process_id,
         fc.order_number,
-        MAX( ogd.child_width ) as width,
-        MAX( ogd.child_height ) as height,
+        MAX(ogd.child_width)  AS width,
+        MAX(ogd.child_height) AS height,
         od.edging_type,
-        rwd.completed_quantity as completed_quantity,
-        ROUND(MAX( ogd.child_width )*MAX( ogd.child_height )*rwd.completed_quantity/1000000,2) as area,
+        rwd.completed_quantity AS completed_quantity,
+        ROUND(MAX(ogd.child_width) * MAX(ogd.child_height) * rwd.completed_quantity / 1000000, 2) AS area,
         od.product_name,
-        JSON_UNQUOTE( JSON_EXTRACT( od.other_columns, '$.S01' )) AS code
+        JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS code,
+        rw.reviewed,
+        rw.examine_time,
+        rw.device_name,
+        o.order_type,
+        CASE
+        WHEN LOCATE('step', #{laminating}) > 0 THEN GROUP_CONCAT(ogd.glass_child SEPARATOR '+')
+        ELSE MAX(ogd.glass_child)
+        END AS workProcessName,
+        o.batch
         FROM
-        pp.reporting_work as rw left join pp.reporting_work_detail as rwd on rwd.reporting_work_id=rw.reporting_work_id
-        left join pp.flow_card as fc on fc.order_id=rw.order_id and fc.process_id=rw.process_id  and fc.order_number=rwd.order_number and fc.technology_number=rwd.technology_number
-        left join sd.order_glass_detail as ogd on ogd.order_id=fc.order_id and ogd.order_number=fc.order_number and ogd.technology_number=fc.technology_number
-        left join sd.order_detail as od  on od.order_id=ogd.order_id and od.order_number=ogd.order_number
-        left join sd.`order` as o on o.order_id=od.order_id
-        where o.create_order>0 and rw.reviewed_state>=0 and rwd.completed_quantity>0 and
-        rw.reporting_work_time >= #{selectTime1}
+        pp.reporting_work AS rw
+        LEFT JOIN pp.reporting_work_detail AS rwd
+        ON rwd.reporting_work_id = rw.reporting_work_id
+        LEFT JOIN pp.flow_card AS fc
+        ON fc.order_id = rw.order_id
+        AND fc.process_id = rw.process_id
+        AND fc.order_number = rwd.order_number
+        AND fc.technology_number = rwd.technology_number
+        LEFT JOIN sd.order_glass_detail AS ogd
+        ON ogd.order_id = fc.order_id
+        AND ogd.order_number = fc.order_number
+        AND ogd.technology_number = fc.technology_number
+        LEFT JOIN sd.order_detail AS od
+        ON od.order_id = ogd.order_id
+        AND od.order_number = ogd.order_number
+        LEFT JOIN sd.`order` AS o
+        ON o.order_id = od.order_id
+        WHERE
+        o.create_order > 0
+        AND rw.reviewed_state >= 0
+        AND rwd.completed_quantity > 0
+        AND rw.reporting_work_time &gt;= #{selectTime1}
         AND rw.reporting_work_time &lt;  #{selectTime2}
-        and position(#{selectProcesses} in rw.this_process)
+        <choose>
+            <!-- 鏈変紶宸ュ簭锛氱簿纭尮閰� -->
+            <when test="selectProcesses != null and selectProcesses != ''">
+                AND rw.this_process = #{selectProcesses}
+            </when>
+            <!-- 鏈紶宸ュ簭锛氫笉鍔犻檺鍒� -->
+            <otherwise>
+            </otherwise>
+        </choose>
         <if test="teamOutputDTO.thisProcess != null and teamOutputDTO.thisProcess != ''">
-            and rw.this_process regexp #{teamOutputDTO.thisProcess}
+            AND rw.this_process REGEXP #{teamOutputDTO.thisProcess}
         </if>
         <if test="teamOutputDTO.teamsGroupsName != null and teamOutputDTO.teamsGroupsName != ''">
-            and rw.teams_groups_name like concat('%', #{teamOutputDTO.teamsGroupsName}, '%')
+            AND rw.teams_groups_name LIKE CONCAT('%', #{teamOutputDTO.teamsGroupsName}, '%')
         </if>
         <if test="teamOutputDTO.project != null and teamOutputDTO.project != ''">
-            and o.project regexp #{teamOutputDTO.project}
+            AND o.project REGEXP #{teamOutputDTO.project}
         </if>
         <if test="teamOutputDTO.processId != null and teamOutputDTO.processId != ''">
-            and rw.process_id regexp #{teamOutputDTO.processId}
+            AND rw.process_id REGEXP #{teamOutputDTO.processId}
         </if>
         <if test="teamOutputDTO.edgingType != null and teamOutputDTO.edgingType != ''">
-            and od.edging_type regexp #{teamOutputDTO.edgingType}
+            AND od.edging_type REGEXP #{teamOutputDTO.edgingType}
+        </if>
+        <if test="teamOutputDTO.deviceName != null and teamOutputDTO.deviceName != ''">
+            AND rw.device_name REGEXP #{teamOutputDTO.deviceName}
         </if>
         <if test="teamOutputDTO.batch != null and teamOutputDTO.batch != ''">
             AND o.batch REGEXP #{teamOutputDTO.batch}
         </if>
+
         <choose>
             <when test="laminating == ''">
                 GROUP BY
@@ -1919,13 +2007,19 @@
                 rwd.order_number
             </otherwise>
         </choose>
-        ORDER BY
-        rw.this_process,
-        rw.process_id,
-        rwd.order_number,
-        rw.reporting_work_time,
-        rw.teams_groups_name
-        ) as page_toal
+        ) t
+        WHERE 1 = 1
+        <if test="teamOutputDTO.workProcessName != null and teamOutputDTO.workProcessName != ''">
+            AND t.workProcessName REGEXP #{teamOutputDTO.workProcessName}
+        </if>
+        ) x
+        WHERE 1 = 1
+        <if test="teamOutputDTO.thicknessSum != null and teamOutputDTO.thicknessSum != ''">
+            AND x.thicknessSum REGEXP #{teamOutputDTO.thicknessSum}
+        </if>
+        <if test="teamOutputDTO.thicknessArea != null and teamOutputDTO.thicknessArea != ''">
+            AND x.thicknessArea REGEXP #{teamOutputDTO.thicknessArea}
+        </if>
         limit #{offset},#{pageSize}
     </select>
 
@@ -2506,10 +2600,43 @@
 
     <select id="teamOutputFootSum">
         SELECT
-        SUM(completed_quantity) as completedQuantity,
-        ifnull(SUM(ROUND(width * height * completed_quantity / 1000000, 2)),0) AS area
-        FROM
+        -- 鏁伴噺鍚堣
+        SUM(x.completed_quantity)              AS completedQuantity,
+        -- 闈㈢Н鍚堣
+        IFNULL(SUM(x.area), 0)                 AS area,
+        -- 鍘氬害脳闈㈢Н鍚堣
+        IFNULL(SUM(x.thicknessArea), 0)        AS thicknessArea
+        FROM (
+        /* 绗� 2 灞傦細鍦ㄨ繖閲屾牴鎹� workProcessName 璁$畻 thicknessSum / thicknessArea */
+        SELECT
+        t.*,
+        /* 鐜荤拑鎬诲帤搴︼細鍙彇姣忔鍓嶉潰鐨勬暟瀛楃浉鍔� */
+        CASE
+        WHEN t.workProcessName IS NULL OR t.workProcessName = '' THEN 0
+        ELSE (
+        SELECT SUM(CAST(REGEXP_SUBSTR(seg, '^[0-9]+') AS UNSIGNED))
+        FROM JSON_TABLE(
+        CAST(CONCAT('["', REPLACE(t.workProcessName, '+', '","'), '"]') AS JSON),
+        '$[*]' COLUMNS (seg VARCHAR(100) PATH '$')
+        ) jt
+        )
+        END AS thicknessSum,
+        /* 鍘氬害 脳 闈㈢Н */
+        CASE
+        WHEN t.workProcessName IS NULL OR t.workProcessName = '' THEN 0
+        ELSE ROUND(
         (
+        SELECT SUM(CAST(REGEXP_SUBSTR(seg2, '^[0-9]+') AS UNSIGNED))
+        FROM JSON_TABLE(
+        CAST(CONCAT('["', REPLACE(t.workProcessName, '+', '","'), '"]') AS JSON),
+        '$[*]' COLUMNS (seg2 VARCHAR(100) PATH '$')
+        ) jt2
+        ) * t.area,
+        2
+        )
+        END AS thicknessArea
+        FROM (
+        /* 绗� 1 灞傦細鍙礋璐g畻濂� workProcessName銆乤rea 绛夊熀纭�瀛楁 */
         SELECT
         rw.reporting_work_time,
         rw.this_process,
@@ -2570,7 +2697,7 @@
             AND rw.this_process REGEXP #{teamOutputDTO.thisProcess}
         </if>
         <if test="teamOutputDTO.teamsGroupsName != null and teamOutputDTO.teamsGroupsName != ''">
-            and rw.teams_groups_name like concat('%', #{teamOutputDTO.teamsGroupsName}, '%')
+            AND rw.teams_groups_name LIKE CONCAT('%', #{teamOutputDTO.teamsGroupsName}, '%')
         </if>
         <if test="teamOutputDTO.project != null and teamOutputDTO.project != ''">
             AND o.project REGEXP #{teamOutputDTO.project}
@@ -2614,12 +2741,17 @@
         <if test="teamOutputDTO.workProcessName != null and teamOutputDTO.workProcessName != ''">
             AND t.workProcessName REGEXP #{teamOutputDTO.workProcessName}
         </if>
-        ORDER BY
-        t.this_process,
-        t.process_id,
-        t.order_number,
-        t.reporting_work_time,
-        t.teams_groups_name
+        ) x
+        WHERE 1 = 1
+        <if test="teamOutputDTO.thicknessSum != null and teamOutputDTO.thicknessSum != ''">
+            AND x.thicknessSum REGEXP #{teamOutputDTO.thicknessSum}
+        </if>
+        <if test="teamOutputDTO.thicknessArea != null and teamOutputDTO.thicknessArea != ''">
+            AND x.thicknessArea REGEXP #{teamOutputDTO.thicknessArea}
+        </if>
+        ;
+
+
     </select>
 
     <select id="getLaminating">

--
Gitblit v1.8.0