guoyujie
2025-10-09 c1c7cae9ebaa7f743e51660265c8dfa6ac52f10d
north-glass-erp/src/main/resources/mapper/pp/Report.xml
@@ -169,6 +169,7 @@
               b.glass_child,
               d.order_type,
               concat(c.process_id, '/', c.technology_number) as process_id,
               c.process_id as 'processId',
               c.order_id,
               c.order_number,
               c.technology_number,
@@ -185,15 +186,17 @@
               c.quantity-ifnull(c.termination_quantity,0) as glassQuantity,
               c.quantity-ifnull(c.termination_quantity,0) as quantityShow,
               (c.quantity-ifnull(c.termination_quantity,0))*a.area as grossAreaShow,
               ifnull(f.inventory, 0) as inventoryShow,
               round(ifnull(f.inventory, 0) * a.area, 2) as inventoryAreaShow,
               ifnull(dd.quantity, 0) as shippedQuantityShow,
               round( (c.quantity-ifnull(c.termination_quantity,0))*a.compute_area,2) as grossAreaShow,
               ifnull(c.received_quantity, 0) as StorageShow,
               ifnull(dd.quantity, 0) as shippedQuantityShow, -- 发货数量
               round(ifnull(dd.quantity, 0)*a.compute_area,2) as shippedAreaShow, -- 发货面积
               round((ifnull(c.received_quantity, 0))*a.compute_area,2)  as StorageAreaShow,-- 入库面积
               if(c.technology_number=1,c.quantity*a.area,0) as grossArea,
               if(c.technology_number=1,ifnull(f.inventory, 0) ,0)                        as inventory,
               if(c.technology_number=1,round(ifnull(f.inventory, 0) * a.area, 2),0)      as inventoryArea,
               if(c.technology_number=1, round((c.quantity-ifnull(c.termination_quantity,0))*a.compute_area,2),0) as grossArea,
               if(c.technology_number=1,ifnull(c.received_quantity, 0) ,0)                        as Storage,
               if(c.technology_number=1,ifnull(dd.quantity, 0) ,0)                          as shippedQuantity,
               if(c.technology_number=1,round(ifnull(dd.quantity, 0)*a.compute_area,2),0)         as shippedArea,
               if(c.technology_number=1, round((ifnull(c.received_quantity, 0))*a.compute_area,2),0)  as StorageArea,
               ifnull(JSON_UNQUOTE(JSON_EXTRACT(a.other_columns, '$.S01')),'') AS glassNumber,
@@ -210,8 +213,8 @@
                               and c.technology_number = b.technology_number
                 left join sd.`order` as d
                           on c.order_id = d.order_id
                 left join mm.finished_goods_inventory as f
                           on c.order_id = f.order_id and f.order_number = c.order_number
#                  left join mm.finished_goods_inventory as f
#                            on c.order_id = f.order_id and f.order_number = c.order_number
                 left join sd.delivery_detail as dd on dd.order_id = a.order_id and dd.order_number = a.order_number
                 left join (SELECT process_id,
                                   order_number,
@@ -785,32 +788,77 @@
    </select>
    <select id="yieldMp">
        SELECT opd.process,
               o.order_id,
               o.customer_name,
               o.project,
               od.product_name,
               ROUND(SUM(distinct opd.reporting_work_num) * od.area, 2)                               as finishedArea
                ,
               ROUND(SUM(distinct opd.broken_num) * od.area, 2)                                       as brokenArea,
               (ROUND(SUM(distinct opd.reporting_work_num) * od.area, 2) +
                ROUND(SUM(distinct opd.broken_num) * od.area, 2))                                     as area,
               CONCAT(ROUND(ROUND(ROUND(SUM(distinct opd.reporting_work_num) * od.area, 2) /
                                  (ROUND(SUM(distinct opd.reporting_work_num) * od.area, 2) +
                                   ROUND(SUM(distinct opd.broken_num) * od.area, 2)), 2) * 100), '%') as finished
        FROM sd.`order` AS o
                 LEFT JOIN sd.order_detail AS od ON od.order_id = o.order_id
                 LEFT JOIN flow_card AS fc ON fc.order_id = od.order_id
            AND fc.order_number = fc.order_number
                 LEFT JOIN sd.order_process_detail AS opd ON opd.order_id = fc.order_id
            AND opd.process_id = fc.process_id
            AND opd.order_number = fc.order_number
            AND opd.technology_number = fc.technology_number
        WHERE opd.reporting_work_num > 0
          and o.create_order>0
          and  DATE_FORMAT((o.create_time), '%Y-%m-%d') BETWEEN #{selectTime1} and #{selectTime2}
          AND position(#{selectProcesses} IN opd.process)
        GROUP BY opd.process, o.order_id
        SELECT
        t.reporting_work_time,
        t.this_process as process,
        t.process_id,
        t.project,
        t.batch,
        SUM(t.completed_quantity) as completedQuantity,
        SUM(t.area) as completedArea,
        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,
        t.product_name
        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}
        AND rw.this_process = #{selectProcesses}
        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.reporting_work_time,
        t.this_process,
        t.process_id,
        t.responsibleTeam
        ORDER BY
        t.this_process,
        t.process_id,
        t.reporting_work_time
    </select>
    <select id="productionScheduleMp">
@@ -1364,56 +1412,82 @@
    <select id="teamOutputMp" resultMap="teamOutputMap">
        SELECT
        *
        FROM
        (
        SELECT
        rw.reporting_work_time,
        rw.this_process,
        rw.teams_groups_name,
        o.project,
        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,
--         GROUP_CONCAT(ogd.glass_child SEPARATOR '+') as workProcessName
        CASE
        WHEN LOCATE('step',#{laminating})>0 THEN GROUP_CONCAT(ogd.glass_child SEPARATOR '+')
        ELSE MAX( ogd.glass_child )
        WHEN LOCATE('step', #{laminating}) > 0 THEN GROUP_CONCAT(ogd.glass_child SEPARATOR '+')
        ELSE MAX(ogd.glass_child)
        END AS workProcessName,
            o.batch
        o.batch
        FROM
        reporting_work as rw left join reporting_work_detail as rwd on rwd.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>0 and
        rw.reporting_work_time >= #{selectTime1}
        reporting_work AS rw
        LEFT JOIN reporting_work_detail AS rwd
        ON rwd.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 > 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 REGEXP #{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}
            AND rw.device_name REGEXP #{teamOutputDTO.deviceName}
        </if>
        <choose>
@@ -1428,7 +1502,7 @@
            </when>
            <otherwise>
                GROUP BY
                <if test="laminating == 'stepA' || laminating == 'stepC'" >
                <if test="laminating == 'stepA' || laminating == 'stepC'">
                    ogd.`group`,
                </if>
                rw.reporting_work_id,
@@ -1436,16 +1510,20 @@
                rw.this_process,
                rw.teams_groups_name,
                rwd.order_number
            </otherwise>
        </choose>
        ) t
        WHERE 1 = 1
        <if test="teamOutputDTO.workProcessName != null and teamOutputDTO.workProcessName != ''">
            AND t.workProcessName REGEXP #{teamOutputDTO.workProcessName}
        </if>
        ORDER BY
        rw.this_process,
        rw.process_id,
        rwd.order_number,
        rw.reporting_work_time,
        rw.teams_groups_name
        limit #{offset},#{pageSize};
        t.this_process,
        t.process_id,
        t.order_number,
        t.reporting_work_time,
        t.teams_groups_name
        LIMIT #{offset}, #{pageSize};
    </select>
    <select id="exportTeamOutputMp">
@@ -2161,43 +2239,86 @@
    </select>
    <select id="teamOutputFootSum">
        select SUM(completed_quantity) as completedQuantity,
        ifnull(SUM(ROUND(width * height * completed_quantity / 1000000, 2)),0) AS area
        from (
        SELECT
        SUM(completed_quantity) as completedQuantity,
        ifnull(SUM(ROUND(width * height * completed_quantity / 1000000, 2)),0) AS area
        FROM
        (
        SELECT
        rw.reporting_work_time,
        rw.this_process,
        rw.teams_groups_name,
        o.project,
        rw.process_id,
        fc.order_number,
        MAX( ogd.child_width ) as width,
        MAX( ogd.child_height ) as height,
        rwd.completed_quantity as completed_quantity
        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,
        od.product_name,
        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
        reporting_work as rw left join reporting_work_detail as rwd on rwd.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>0
        AND rw.reporting_work_time >= #{selectTime1}
        reporting_work AS rw
        LEFT JOIN reporting_work_detail AS rwd
        ON rwd.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 > 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 REGEXP #{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>
        <choose>
            <when test="laminating == ''">
                GROUP BY
@@ -2210,6 +2331,9 @@
            </when>
            <otherwise>
                GROUP BY
                <if test="laminating == 'stepA' || laminating == 'stepC'">
                    ogd.`group`,
                </if>
                rw.reporting_work_id,
                rw.process_id,
                rw.this_process,
@@ -2217,13 +2341,17 @@
                rwd.order_number
            </otherwise>
        </choose>
        ) t
        WHERE 1 = 1
        <if test="teamOutputDTO.workProcessName != null and teamOutputDTO.workProcessName != ''">
            AND t.workProcessName REGEXP #{teamOutputDTO.workProcessName}
        </if>
        ORDER BY
        rw.this_process,
        rw.process_id,
        rwd.order_number,
        rw.reporting_work_time,
        rw.teams_groups_name
        ) as subquery
        t.this_process,
        t.process_id,
        t.order_number,
        t.reporting_work_time,
        t.teams_groups_name
    </select>
    <select id="getLaminating">
@@ -2334,6 +2462,22 @@
        </if>
        <if test="workInProgressDTO.technologyNumber != null and workInProgressDTO.technologyNumber != ''">
            and ogd.technology_number regexp #{workInProgressDTO.technologyNumber}
        </if>
        <if test="workInProgressDTO.quantity != null and workInProgressDTO.quantity != ''">
            and od.quantity regexp #{workInProgressDTO.quantity}
        </if>
        <if test="workInProgressDTO.childWidth != null and workInProgressDTO.childWidth != ''">
            and ogd.child_width regexp #{workInProgressDTO.childWidth}
        </if>
        <if test="workInProgressDTO.childHeight != null and workInProgressDTO.childHeight != ''">
            and ogd.child_height regexp #{workInProgressDTO.childHeight}
        </if>
        <if test="workInProgressDTO.stockNum != null and workInProgressDTO.stockNum != ''">
            and (d.numCounts + d.patchNumSum - d.numCount -d.broken_num) regexp #{workInProgressDTO.stockNum}
        </if>
        <if test="workInProgressDTO.stockArea != null and workInProgressDTO.stockArea != ''">
            and ROUND(ogd.child_width * ogd.child_height * (d.numCounts + d.patchNumSum - d.numCount -
            d.broken_num) / 1000000, 2) regexp #{workInProgressDTO.stockArea}
        </if>
        <if test="workInProgressDTO.glassNumber != null and workInProgressDTO.glassNumber != ''">
            and ifnull(JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')),'') regexp #{workInProgressDTO.glassNumber}
@@ -2760,6 +2904,7 @@
                       where
                           e.id is not null
                         and (e.reporting_work_num_count+f.patchNumSum-f.reporting_work_num_count-f.broken_num)>0 group by f.process_id, f.order_number,
        f.technology_number ORDER BY f.process_id, f.order_number,
        f.technology_number) as g
                            <choose>
                                <when test="laminating == 'stepC' and process == '预压'">
@@ -2966,37 +3111,230 @@
    
    
    <select id="processCardProgressCollectMp">
       select * from (select b.product_name,
            c.detail as 'glassName',
       select * from (select
              a.order_id,
              a.order_number,
              c.glass_group as 'group',
              a.technology_number,
            b.product_name,
            c.detail as glass_child,
            d.order_type,
            concat(a.process_id,'/',a.technology_number)  as processID,
            a.process_id,
            a.quantity,
            a.received_quantity,
            round(sum(a.received_quantity*b.area),2) as received_area,
            if(a.technology_number=1,sum(a.quantity-ifnull(a.termination_quantity,0)),0) as quantity,
            sum(a.quantity)-ifnull(a.termination_quantity,0) as thisQuantity,/*用于判断是否改变颜色*/
            if(a.technology_number=1, round(sum((a.quantity-ifnull(a.termination_quantity,0))*b.compute_area),2),0) as gross_area,
            if(a.technology_number=1, sum(a.received_quantity),0) as inventory,
            if(a.technology_number=1, round(sum(a.received_quantity*b.area),2),0) as inventoryArea,
            a.technology_number
            -- show
            sum(a.quantity-ifnull(a.termination_quantity,0)) as quantityShow ,
            round(sum((a.quantity-ifnull(a.termination_quantity,0)*b.compute_area)),2) as gross_areaShow,
            sum(a.received_quantity) as inventoryShow,
            round(sum(a.received_quantity*b.area),2) as inventoryAreaShow
            from pp.flow_card as a
            left join sd.order_detail as b
            on a.order_id = b.order_id and a.order_number = b.order_number
            left join sd.product_detail as c
            on c.prod_id = b.product_id and c.glass_sort = a.technology_number
            LEFT JOIN sd.`order` as d
            on a.order_id = d.order_id
            where a.order_id = #{orderId} group by processID
            ) as a
       left join (SELECT process_id,
                         technology_number,
                         sum(broken_num) as broken_num,
                         concat('{',GROUP_CONCAT(reporting_work_nums),'}') as reporting_work_num
                         concat('{',GROUP_CONCAT(reporting_work_nums),'}') as reportWorkQuantity,
                         concat('{',GROUP_CONCAT(reporting_work_counts),'}') as reportWorkQuantityCount
                  from (select
                            opd.process_id,
                            opd.technology_number,
                            concat("\"", process, "\":\"", SUM(reporting_work_num), "\"") as  reporting_work_nums,
                            concat("\"", process, "\":\"", SUM(reporting_work_num_count), "\"") as  reporting_work_counts,
                            sum(broken_num) as broken_num
                        from sd.order_process_detail as opd
                        where opd.order_id = #{orderId}
                        group by opd.process_id,opd.technology_number,opd.process) as bb
                  GROUP BY bb.process_id,bb.technology_number) as b
       on a.process_id = b.process_id and a.technology_number = b.technology_number
       order by a.process_id
       order by a.process_id,a.order_number,a.technology_number
    </select>
    <select id="processCardProgressReportMp">
        select a.product_name,
               b.glass_child,
               d.order_type,
               concat(c.process_id, '/', c.technology_number) as process_id,
               c.process_id as 'processId',
                c.order_id,
               c.order_number,
               c.technology_number,
               b.child_width,
               b.child_height,
               c.quantity,
               c.quantity-ifnull(c.termination_quantity,0) as thisQuantity,/*用于判断是否改变颜色*/
               e.reportWorkQuantity,
               e.reportWorkQuantityShow,
               e.reportWorkQuantityCount,
               e.reportWorkTime,
               e.broken_num,
               c.quantity-ifnull(c.termination_quantity,0) as glassQuantity,
               c.quantity-ifnull(c.termination_quantity,0) as quantityShow,
               round( (c.quantity-ifnull(c.termination_quantity,0))*a.compute_area,2) as grossAreaShow,
               ifnull(c.received_quantity, 0) as StorageShow,
               ifnull(dd.quantity, 0) as shippedQuantityShow, -- 发货数量
               round(ifnull(dd.quantity, 0)*a.compute_area,2) as shippedAreaShow, -- 发货面积
               round((ifnull(c.received_quantity, 0))*a.compute_area,2)  as StorageAreaShow,-- 入库面积
                round((c.quantity-ifnull(c.termination_quantity,0))*a.compute_area,2)as grossArea,
               ifnull(c.received_quantity, 0)                       as Storage,
               ifnull(dd.quantity, 0)                        as shippedQuantity,
               round(ifnull(dd.quantity, 0)*a.compute_area,2)        as shippedArea,
               round((ifnull(c.received_quantity, 0))*a.compute_area,2) as StorageArea,
               ifnull(JSON_UNQUOTE(JSON_EXTRACT(a.other_columns, '$.S01')),'') AS glassNumber,
               b.`group`
        from pp.flow_card as c
                 left join
             sd.order_detail as a
             on c.order_id = a.order_id
                 and c.order_number = a.order_number
                 left join sd.order_glass_detail as b
                           on c.order_id = b.order_id
                               and b.order_number = c.order_number
                               and c.technology_number = b.technology_number
                 left join sd.`order` as d
                           on c.order_id = d.order_id
            #                  left join mm.finished_goods_inventory as f
#                            on c.order_id = f.order_id and f.order_number = c.order_number
            left join sd.delivery_detail as dd on dd.order_id = a.order_id and dd.order_number = a.order_number
            left join (SELECT process_id,
            order_number,
            technology_number,
            sum(a.broken_num) as broken_num,
            concat('{',
            GROUP_CONCAT(concat("\"", process, "\":\"", if(technology_number!=1 and (bd.nickname='stepD' || bd.nickname='stepB' ) ,0,reporting_work_num), "\"")),
            '}'
            )             as reportWorkQuantity,
            concat('{',
            GROUP_CONCAT(concat("\"", process, "\":\"", reporting_work_num, "\"")),
            '}'
            )             as reportWorkQuantityShow,
            concat('{',
            GROUP_CONCAT(concat("\"", process, "\":\"", reporting_work_num_count, "\"")),
            '}'
            )             as reportWorkQuantityCount,
            concat('{',
            GROUP_CONCAT(concat("\"", process, "\":\"", IFNULL(date(update_time),''), "\"")),
            '}'
            )             as reportWorkTime
            FROM sd.order_process_detail as a
            left join (SELECT DISTINCT basic_name,nickname from sd.basic_data as bd where  bd.basic_category = 'process') as bd
            on a.process = bd.basic_name
            where a.order_id = #{orderId}
            GROUP BY process_id, a.order_number, a.technology_number
            ) as e
            on e.process_id = c.process_id
            and e.technology_number = c.technology_number
            and e.order_number = c.order_number
        where a.order_id = #{orderId} and d.create_order>0 and c.quantity-ifnull(c.termination_quantity,0)>0
        group by c.order_number,
            c.technology_number,
            c.process_id
        order by c.process_id, c.order_number, c.technology_number
    </select>
    <select id="selectProcessCompletedMp">
        SELECT
            #{selectProcesses} as process,
        hz.project,hz.batch,
        SUM(quantity) as quantity,
        SUM(childArea)as childArea,
        SUM(actualArea) as actualArea,
        SUM(completeNum) as completeNum,
        SUM(completeArea) as completeArea,
        SUM(incompleteNum) as incompleteNum,
        SUM(incompleteArea) as incompleteArea,
        hz.product_name
        from (
        select DATE(o.create_time)                                                  as create_time,
        DATE(o.delivery_date)                                                as delivery_date,
        o.order_id,
        fc.process_id,
        o.customer_name,
        o.project,
        o.batch,
        od.order_number,
        ogd.technology_number,
        ogd.glass_child,
        ogd.child_width,
        ogd.child_height,
        fc.quantity - ifnull(fc.termination_quantity,0) as quantity,
        ROUND(ogd.child_width * ogd.child_height / 1000000, 2)               as childArea,
        ROUND(ogd.child_width * ogd.child_height * (fc.quantity- ifnull(fc.termination_quantity,0)) / 1000000, 2) as actualArea,
        odpd.reporting_work_num                                              as completeNum,
        ROUND(ogd.child_width * ogd.child_height * odpd.reporting_work_num / 1000000,
        2)                                                             as completeArea,
        fc.quantity - odpd.reporting_work_num - ifnull(fc.termination_quantity,0)      as incompleteNum,
        ROUND(ogd.child_width * ogd.child_height * (fc.quantity - odpd.reporting_work_num- ifnull(fc.termination_quantity,0)) / 1000000,
        2)                                                             as incompleteArea,
        od.product_name
        from sd.order_detail AS od
        LEFT JOIN sd.order_glass_detail AS ogd
        ON od.order_id = ogd.order_id
        AND od.order_number = ogd.order_number
        LEFT JOIN flow_card AS fc
        ON fc.order_id = ogd.order_id
        and fc.production_id = ogd.production_id
        AND fc.order_number = ogd.order_number
        AND fc.technology_number = ogd.technology_number
        left join sd.order_process_detail as odpd
        ON odpd.order_id = fc.order_id
        AND odpd.order_number = fc.order_number
        AND odpd.technology_number = fc.technology_number
        and odpd.process_id = fc.process_id
        left join sd.`order` as o
        on o.order_id = od.order_id
        where  o.create_order>0
          and odpd.process = #{selectProcesses}
          and  o.create_time >= #{selectTime1}
          AND o.create_time &lt;  #{selectTime2}
          and position(#{orderId} in od.order_id)
          and position(#{inputProject} in o.project)
        and GREATEST(fc.quantity - odpd.reporting_work_num, 0)>0
        and fc.quantity-ifnull(fc.termination_quantity,0)>0
        <choose>
            <when test="laminating != null and laminating == 'stepC'">
                GROUP BY fc.process_id, fc.order_number, ogd.`group`
            </when>
            <when test="laminating != null and laminating == 'stepD'">
                GROUP BY fc.process_id, fc.order_number
            </when>
            <when test="laminating != null and laminating == 'stepB'">
                GROUP BY fc.process_id, fc.order_number
            </when>
            <otherwise>
                GROUP BY fc.process_id, fc.order_number, fc.technology_number
            </otherwise>
        </choose>
        order by fc.process_id, fc.order_number, fc.technology_number
        ) as hz
        GROUP BY hz.project,hz.batch,product_name
    </select>
</mapper>