chenlu
2025-11-26 53bc276bdc4aaefc2a2ecadc472f2c2f18e93490
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">
@@ -970,7 +972,7 @@
        SUM(t.breakageQuantity) as breakageQuantity,
        SUM(t.breakageArea) as breakageArea,
        t.responsibleTeam,
        CONCAT(ROUND(ROUND(SUM(t.area)/(SUM(t.area) + SUM(t.breakageArea)),2)*100), '%') as finished,
        CONCAT(ROUND(TRUNCATE(SUM(t.area)/(SUM(t.area) + SUM(t.breakageArea)),2)*100), '%') as finished,
        t.product_name
        FROM
        (
@@ -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
@@ -1733,7 +1753,7 @@
            AND rw.this_process REGEXP #{teamOutputDTO.thisProcess}
        </if>
        <if test="teamOutputDTO.teamsGroupsName != null and teamOutputDTO.teamsGroupsName != ''">
            AND rw.teams_groups_name REGEXP #{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}
@@ -1777,6 +1797,10 @@
        WHERE 1 = 1
        <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,
@@ -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 regexp #{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 层:只负责算好 workProcessName、area 等基础字段 */
        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 REGEXP #{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">
@@ -3607,5 +3739,63 @@
        GROUP BY hz.project,hz.batch,glass_child
    </select>
    <select id="yieldProcessMp">
        SELECT
            t.this_process as process,
            SUM(t.completed_quantity) as completedQuantity,
            SUM(t.area) as completedArea,
            SUM(t.breakageQuantity) as breakageQuantity,
            SUM(t.breakageArea) as breakageArea,
            CONCAT(ROUND(TRUNCATE(SUM(t.area)/(SUM(t.area) + SUM(t.breakageArea)),2)*100), '%') as finished
        FROM
            (
                SELECT
                    rw.reporting_work_time,
                    rw.this_process,
                    o.project,
                    o.batch,
                    rw.process_id,
                    rwd.completed_quantity AS completed_quantity,
                    ROUND(MAX(ogd.child_width) * MAX(ogd.child_height) * rwd.completed_quantity / 1000000, 2) AS area,
                    IFNULL(dd.breakage_quantity,0) as breakageQuantity,
                    IFNULL(ROUND(MAX(ogd.child_width) * MAX(ogd.child_height) * dd.breakage_quantity / 1000000, 2),0) AS breakageArea,
                    IFNULL(dd.responsible_team,'') as responsibleTeam,
                    od.product_name
                FROM
                    reporting_work AS rw
                        LEFT JOIN reporting_work_detail AS rwd
                                  ON rwd.reporting_work_id = rw.reporting_work_id
                        LEFT JOIN damage_details as dd on dd.reporting_work_id = rw.reporting_work_id
                        LEFT JOIN 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 + IFNULL(dd.breakage_quantity,0)> 0
                  AND rw.reporting_work_time &gt;= #{selectTime1}
                  AND rw.reporting_work_time &lt;= #{selectTime2}
                GROUP BY
                    rw.reporting_work_id,
                    rw.process_id,
                    rw.this_process,
                    rw.teams_groups_name,
                    rwd.order_number,
                    rwd.technology_number
            ) t
        GROUP BY
            t.this_process
    </select>
</mapper>