廖井涛
2024-09-06 10a26b9b670efef0a2adba675c794c539846aa3c
north-glass-erp/src/main/resources/mapper/pp/FolwCard.xml
@@ -195,15 +195,17 @@
               ogd.production_id,
               od.product_id,
               od.product_name,
               SUM(od.quantity)            as quantity,
               ROUND(SUM(od.quantity)-IFNULL(sum(fc.quantity)/count(fc.technology_number),0))            as quantity,
               SUM(od.compute_gross_area)  as compute_gross_area,
               round(sum(od.perimeter), 2) as perimeter
        from sd.order_detail as od
                 left join
             (select order_id, order_number, production_id, splitting_status
             (select order_id, order_number,technology_number, production_id, splitting_status
              from sd.order_glass_detail
              GROUP BY order_id, order_number) 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 = od.order_id and fc.order_number = od.order_number
            and fc.technology_number=ogd.technology_number
        where od.order_id = #{orderId}
          and ogd.splitting_status = 0
@@ -217,7 +219,7 @@
            sd.order_glass_detail as ogd left join flow_card as fc
                on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number
        set ogd.splitting_status=0
        where ogd.order_id = #{orderId}
        where fc.process_id = #{processId}
    </update>
@@ -225,7 +227,7 @@
    <update id="deleteFlowCardMp">
        delete
        from flow_card as fc
        where fc.order_id = left(#{processId}, 10)
        where fc.process_id = #{processId}
    </update>
    <!--    分架新增明细查询-->
@@ -241,12 +243,13 @@
               od.quantity,
               od.compute_gross_area,
               p.total_thickness,
               od.quantity           as baiscQuantity,
               ROUND(od.quantity-IFNULL(sum(fc.quantity)/count(fc.technology_number),0))           as baiscQuantity,
               od.compute_gross_area as 'computeGrossArea',
               p.total_thickness     AS 'totalThickness',
               p.thickness,
               od.weight,
               od.remarks,
               od.bend_radius,
               ods.S01,
               ods.S02,
               ods.S03,
@@ -266,6 +269,8 @@
                            FROM sd.order_detail
                            WHERE order_id = #{orderId}) as ods
                           on ods.order_id = od.order_id and ods.order_number = od.order_number
                 left join flow_card as fc on fc.order_id = od.order_id and fc.order_number = od.order_number
                           and fc.technology_number=ogd.technology_number
        where od.order_id = #{orderId}
          and ogd.production_id = #{productionId}
          and ogd.splitting_status = 0
@@ -442,7 +447,7 @@
    <delete id="deleteReportingWork">
        delete
        from sd.order_process_detail
        where order_id = left(#{processId}, 10)
        where process_id = #{processId}
    </delete>
    <select id="selectPrintFlowCardMp">
@@ -478,10 +483,10 @@
                      o.customer_name,
                      o.project,
                      ogdss.technology_number,
                      ogdss.concatenated_glass_child,
                      ogd.glass_address,
                      ROUND(sum(fc.quantity) / (count(DISTINCT fc.technology_number))) as quantity,
                      sum(ogd.total_area)                                              as total_area,
                      # SUM(ogd.child_width*child_height*fc.quantity/(count(DISTINCT ogd.technology_number))) as total_area,
                      # sum(ogd.total_area)                                              as total_area,
                      ROUND(SUM(ogd.child_width*ogd.child_height*fc.quantity)/1000000/(count(DISTINCT fc.technology_number)),2) as total_area,
                      od.product_name,
                      ogdss.concatenated_glass_child                                   as glass_child,
                      fc.founder,
@@ -500,13 +505,15 @@
                                          ogds.order_number,
                                          GROUP_CONCAT(ogds.technology_number SEPARATOR '') AS technology_number,
                                          ogds.glass_child                                  AS concatenated_glass_child,
                                          process                                           AS processed_part
                                          process                                           AS processed_part,
                                          ogds.child_width,
                                          ogds.child_height
                                   from sd.order_glass_detail as ogds
                                   where ogds.order_id = #{orderId}
                                   GROUP BY order_id, order_number, ogds.glass_child) as ogdss
                                   GROUP BY order_id, order_number, ogds.glass_child, process) as ogdss
                                  on fc.order_id = ogdss.order_id and ogdss.order_number = fc.order_number
               where fc.order_id = #{orderId}
               GROUP BY fc.process_id, ogdss.concatenated_glass_child
               GROUP BY fc.process_id, ogdss.concatenated_glass_child, ogdss.processed_part
               order by fc.process_id, ogdss.technology_number)
              UNION
@@ -519,8 +526,8 @@
                      ogdss.technology_number,
                      ogd.glass_address,
                      ROUND(sum(fc.quantity) / (count(DISTINCT fc.technology_number))) as quantity,
                      sum(ogd.total_area)                                              as total_area,
                      # SUM(ogd.child_width*child_height*fc.quantity/(count(DISTINCT ogd.technology_number))) as total_area,
                     #  sum(ogd.total_area)                                              as total_area,
                      ROUND(SUM(ogd.child_width*ogd.child_height*fc.quantity)/1000000/(count(DISTINCT fc.technology_number)),2) as total_area,
                      od.product_name,
                      ogdss.concatenated_glass_child                                   as glass_child,
                      fc.founder,
@@ -539,7 +546,7 @@
                                          ogds.order_number,
                                          GROUP_CONCAT(ogds.technology_number SEPARATOR '') AS technology_number,
                                          ogds.glass_child,
                                          GROUP_CONCAT(ogds.glass_child SEPARATOR ' ')      AS concatenated_glass_child,
                                          GROUP_CONCAT(ogds.glass_child SEPARATOR '+')      AS concatenated_glass_child,
                                          SUBSTRING(process, LOCATE('夹胶', process))       AS processed_part
                                   from sd.order_glass_detail as ogds
                                   where ogds.order_id = #{orderId}
@@ -558,7 +565,7 @@
                      ogdss.technology_number,
                      ogd.glass_address,
                      ROUND(sum(fc.quantity) / (count(DISTINCT fc.technology_number))) as quantity,
                      sum(ogd.total_area)                                              as total_area,
                      ROUND(SUM(ogd.child_width*ogd.child_height*fc.quantity)/1000000/(count(DISTINCT fc.technology_number)),2) as total_area,
                      od.product_name,
                      ogdss.concatenated_glass_child                                   as glass_child,
                      fc.founder,
@@ -577,7 +584,7 @@
                                          ogds.order_number,
                                          GROUP_CONCAT(pds.glass_sort SEPARATOR '')           AS technology_number,
                                          ogds.glass_child,
                                          GROUP_CONCAT(ogds.glass_child SEPARATOR ' ')        AS concatenated_glass_child,
                                          GROUP_CONCAT(ogds.glass_child SEPARATOR '+')        AS concatenated_glass_child,
                                          SUBSTRING(pds.process, LOCATE('中空', pds.process)) AS processed_part
                                   from sd.order_glass_detail as ogds
                                            left join sd.order_detail as ods
@@ -593,7 +600,8 @@
               order by fc.process_id)) AS combined_results
        where process is not null
          and process != ""
        GROUP BY order_id, process_id, technology_number, process
        order by order_id, process_id, length(technology_number)
    </select>
    <select id="getPrimaryList">
@@ -610,12 +618,8 @@
               sum(od.weight)                                  as weight,
               #{technologyNumber}                             as technologyNumber,
               concat(fc.process_id, '/', #{technologyNumber}) as processIdNumber,
               concat("对应我司", TRIM(
                       SUBSTRING(
                               o.processing_note,
                               LOCATE('对应我司', o.processing_note) + CHAR_LENGTH('对应我司')
                           ))
                   )                                           AS otherRemarks
               concat('对应我司单号', o.batch)                 AS otherRemarks,
               ''                                              as qrcode
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
@@ -641,15 +645,15 @@
    <select id="getDetailList">
        select fc.order_number,
               concat(round(ogd.child_width), "*", round(ogd.child_height)) as child_width,
               od.quantity,
               round(ogd.total_area, 2)                                     as total_area,
               concat(round(ogd.child_width), "*", round(ogd.child_height))   as child_width,
               fc.quantity,
               round(ogd.total_area, 2)                                       as total_area,
               od.perimeter,
               od.bend_radius,
               concat(IFNULL(od.processing_note,''), IFNULL(od.remarks,''))                       as remarks,
               concat(IFNULL(od.processing_note, ''), IFNULL(od.remarks, '')) as remarks,
               od.other_columns,
               round(ogd.child_width)                                       as width,
               round(ogd.child_height)                                      as height,
               round(ogd.child_width)                                         as width,
               round(ogd.child_height)                                        as height,
               pd.separation,
               fc.technology_number
        from flow_card as fc
@@ -659,10 +663,14 @@
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.product_detail as pd
                           on pd.prod_id = od.product_id and pd.glass_sort = ogd.technology_number
                 left join flow_card_sort as fcs
                           on fcs.process_id = fc.process_id and fcs.order_number = fc.order_number and
                              fcs.technology_number = fc.technology_number
                               and fcs.process = #{process}
        where fc.process_id = #{processId}
          and position(fc.technology_number in #{technologyNumber})
        group by fc.process_id, fc.order_number
        order by IF(sort != NULL || sort != '', sort, fc.order_number)
        order by IF(fcs.sort != NULL or fcs.sort != '', fcs.sort, fc.order_number)
    </select>
    <select id="getProcessList">
@@ -717,13 +725,44 @@
        order by opd.stock_id
    </select>
    <select id="getPrintLabel2">
        select o.order_id,
               c.customer_abbreviation as customer_name,
               o.project,
               od.building_number,
               od.processing_note,
               ogd.child_width         as width,
               ogd.child_height        as height,
               ogd.glass_child,
               ogd.process,
               e.type_name,
               opd.stock_id,
               od.quantity,
               od.other_columns,
               od.bend_radius,
               opd.heat_layout_id,
               opd.heat_layout_sort
        from pp.optimize_detail opd
                 left join sd.`order` o on SUBSTR(opd.process_id, 1, 10) = o.order_id
                 left join sd.order_detail od
                           on SUBSTR(opd.process_id, 1, 10) = od.order_id and opd.order_sort = od.order_number
                 left join sd.order_glass_detail ogd
                           on SUBSTR(opd.process_id, 1, 10) = ogd.order_id and opd.order_sort = ogd.order_number and
                              opd.layer = ogd.technology_number
                 left join sd.product p on od.product_id = p.id
                 left join sd.basic_glass_type e on e.type_id = p.type_id
                 left join sd.customer c on c.id = o.customer_id
        where opd.project_no = #{projectNo}
        order by opd.heat_layout_id, opd.heat_layout_sort desc
    </select>
    <select id="getPrintLabel1">
        select o.order_id,
               o.project,
               o.customer_id,
               ogd.child_width                as width,
               ogd.child_height               as height,
               od.quantity,
               fc.quantity,
               od.order_number                as orderNumber,
               fc.technology_number           as technologyNumber,
               ogd.glass_child,
@@ -758,15 +797,23 @@
               ogd.child_height,
               fc.quantity,
               ROUND(ogd.child_width * ogd.child_height * fc.quantity / 1000000, 2) as area,
               fc.sort,
               ogd.glass_child
               ifnull(fcs.sort, '')                                                 as sort,
               ogd.glass_child,
               #{process}                                                           as process,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01'))                AS glassNumber
        FROM flow_card AS fc
                 LEFT JOIN sd.order_glass_detail AS ogd ON fc.order_id = ogd.order_id
            AND fc.order_number = ogd.order_number
            AND fc.technology_number = ogd.technology_number
                 left join flow_card_sort as fcs
                           on fcs.process_id = fc.process_id and fcs.order_number = fc.order_number and
                              fcs.technology_number = fc.technology_number
                               and fcs.process = #{process}
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
        where fc.process_id = #{processId}
          and position(fc.technology_number in #{technologyNumber})
        order by IF(fc.sort != NULL || fc.sort != '', fc.sort, fc.order_number)
        GROUP BY fc.process_id,fc.order_number,fc.technology_number
        order by IF(fcs.sort != NULL or fcs.sort != '', fcs.sort, fc.order_number)
    </select>
    <update id="printSortMp">
@@ -839,13 +886,13 @@
               od.processing_note                                    as processingNote,
               width,
               height,
               od.quantity,
               fc.quantity,
               od.order_number                                       as orderNumber,
               fc.technology_number                                  as technologyNumber,
               od.building_number                                    as buildingNumber,
               od.product_name                                       as productName,
               od.edging_type                                        as edgingType,
               p.remarks,
               od.remarks,
               c.customer_abbreviation                               as customerAbbreviation,
               p.product_abbreviation                                as productAbbreviation,
               fc.process_id                                         as processId,
@@ -878,7 +925,7 @@
        where fc.process_id = #{processId}
          and fc.technology_number = #{technologyNumber}
        group by od.order_number, width, height
        order by IF(fc.sort != NULL || fc.sort != '', fc.sort, fc.order_number)
        order by fc.process_id
    </select>
    <select id="selectReplenishPrintMp">
@@ -901,7 +948,9 @@
               od.product_name,
               ogd.glass_child,
               fc.print_status,
               pl.reporting_work_id
               pl.reporting_work_id,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01'))                AS glassNumber
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
@@ -971,7 +1020,7 @@
          and pl.technology_number = #{technologyNumber}
          and pl.reporting_work_id = #{reportingWorkId}
        group by od.order_number, width, height
        order by IF(fc.sort != NULL || fc.sort != '', fc.sort, pl.order_sort)
        order by IF(fc.sort != NULL or fc.sort != '', fc.sort, pl.order_sort)
    </select>
    <select id="getGlassNumber">
@@ -979,8 +1028,9 @@
        from sd.order_detail as od
                 left join flow_card as fc on od.order_id = fc.order_id and od.order_number = fc.order_number
        where fc.process_id = #{processId}
          and fc.technology_number = #{technologyNumber}
        order by IF(fc.sort != NULL || fc.sort != '', fc.sort, fc.order_number)
          and POSITION(fc.technology_number in #{technologyNumber})
        GROUP BY other_columns
        order by IF(fc.sort != NULL or fc.sort != '', fc.sort, fc.order_number)
    </select>
    <update id="updatePrintStateMp">
@@ -1000,13 +1050,15 @@
               fc.quantity,
               ROUND(ogd.child_width * ogd.child_height * fc.quantity / 1000000, 2) as area,
               fc.sort,
               ogd.process
               ogd.process,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01'))                AS glassNumber
        FROM flow_card AS fc
                 LEFT JOIN sd.order_glass_detail AS ogd ON fc.order_id = ogd.order_id
            AND fc.order_number = ogd.order_number
            AND fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on fc.order_id = od.order_id and fc.order_number = od.order_number
        where fc.order_id = #{orderId}
        order by IF(fc.sort != NULL || fc.sort != '', fc.sort, fc.technology_number)
        order by IF(fc.sort != NULL or fc.sort != '', fc.sort, fc.technology_number)
    </select>
    <update id="printOrderSortMp">
@@ -1030,7 +1082,8 @@
               round(SUM(ogd.total_area), 2)                   as gross_area,
               sum(od.weight)                                  as weight,
               #{technologyNumber}                             as technologyNumber,
               concat(fc.process_id, '/', #{technologyNumber}) as processIdNumber
               concat(fc.process_id, '/', #{technologyNumber}) as processIdNumber,
               concat('对应我司单号', o.batch)                 AS otherRemarks
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
@@ -1080,7 +1133,8 @@
               pl.rework_processes,
               od.product_name,
               ogd.glass_child,
               pl.reporting_work_id
               pl.reporting_work_id,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS glassNumber
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
@@ -1091,21 +1145,21 @@
                                           pl.order_sort = fc.order_number and
                                           pl.technology_number = fc.technology_number
        where pl.create_time between #{selectTime1} and #{selectTime2}
        GROUP BY fc.process_id, ogd.technology_number, pl.reporting_work_id
        GROUP BY fc.process_id,fc.order_number, ogd.technology_number, pl.reporting_work_id
        order by pl.id desc, fc.process_id, ogd.technology_number
    </select>
    <select id="getDetailListLike">
        select fc.order_number,
               concat(round(ogd.child_width), "*", round(ogd.child_height)) as child_width,
               od.quantity,
               round(ogd.total_area, 2)                                     as total_area,
               concat(round(ogd.child_width), "*", round(ogd.child_height))   as child_width,
               fc.quantity,
               round(ogd.total_area, 2)                                       as total_area,
               od.perimeter,
               od.bend_radius,
               concat(IFNULL(od.processing_note,''), IFNULL(od.remarks,''))                       as remarks,
               concat(IFNULL(od.processing_note, ''), IFNULL(od.remarks, '')) as remarks,
               od.other_columns,
               round(ogd.child_width)                                       as width,
               round(ogd.child_height)                                      as height,
               round(ogd.child_width)                                         as width,
               round(ogd.child_height)                                        as height,
               pd.separation,
               fc.technology_number
        from flow_card as fc
@@ -1115,10 +1169,14 @@
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.product_detail as pd
                           on pd.prod_id = od.product_id and pd.glass_sort = ogd.technology_number
                 left join flow_card_sort as fcs
                           on fcs.process_id = fc.process_id and fcs.order_number = fc.order_number and
                              fcs.technology_number = fc.technology_number
                               and fcs.process = #{process}
        where fc.process_id = #{processId}
          and position(fc.technology_number in #{technologyNumber})
        group by fc.process_id, fc.order_number, fc.technology_number
        order by IF(sort != NULL || sort != '', sort, fc.order_number)
        order by IF(fcs.sort != NULL or fcs.sort != '', fcs.sort, fc.order_number)
    </select>
    <select id="getPrimaryListMergeRefund">
@@ -1165,15 +1223,15 @@
    <select id="getDetailListRefund">
        select fc.order_number,
               concat(round(ogd.child_width), "*", round(ogd.child_height)) as child_width,
               (pl.patch_num)                                               as quantity,
               round(ogd.total_area, 2)                                     as total_area,
               concat(round(ogd.child_width), "*", round(ogd.child_height))   as child_width,
               sum(pl.patch_num)                                                 as quantity,
               round(ogd.total_area, 2)                                       as total_area,
               od.perimeter,
               od.bend_radius,
               concat(IFNULL(od.processing_note,''), IFNULL(od.remarks,''))                       as remarks,
               concat(IFNULL(od.processing_note, ''), IFNULL(od.remarks, '')) as remarks,
               od.other_columns,
               round(ogd.child_width)                                       as width,
               round(ogd.child_height)                                      as height,
               round(ogd.child_width)                                         as width,
               round(ogd.child_height)                                        as height,
               pd.separation,
               fc.technology_number
        from flow_card as fc
@@ -1190,7 +1248,7 @@
          and position(fc.technology_number in #{technologyNumber})
          and pl.reporting_work_id = #{reportingWorkId}
        group by fc.process_id, fc.order_number, fc.technology_number
        order by IF(sort != NULL || sort != '', sort, fc.order_number)
        order by IF(sort != NULL and sort != '', sort, fc.order_number)
    </select>
    <select id="getPrimaryListRefund">
@@ -1210,7 +1268,10 @@
               dd.breakage_type,
               dd.breakage_reason,
               dd.responsible_process,
               dd.responsible_team
               dd.responsible_team,
               concat('对应我司单号', o.batch)                 AS otherRemarks,
               dd.responsible_personnel,
               #{mergeTechnologyNumber} as  mergeTechnologyNumber
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
@@ -1245,15 +1306,15 @@
    <select id="getDetailListLikeRefund">
        select fc.order_number,
               concat(round(ogd.child_width), "*", round(ogd.child_height)) as child_width,
               pl.patch_num                                                 as quantity,
               round(ogd.total_area, 2)                                     as total_area,
               concat(round(ogd.child_width), "*", round(ogd.child_height))   as child_width,
               pl.patch_num                                                   as quantity,
               round(ogd.total_area, 2)                                       as total_area,
               od.perimeter,
               od.bend_radius,
               concat(IFNULL(od.processing_note,''), IFNULL(od.remarks,''))                       as remarks,
               concat(IFNULL(od.processing_note, ''), IFNULL(od.remarks, '')) as remarks,
               od.other_columns,
               round(ogd.child_width)                                       as width,
               round(ogd.child_height)                                      as height,
               round(ogd.child_width)                                         as width,
               round(ogd.child_height)                                        as height,
               pd.separation,
               fc.technology_number
        from flow_card as fc
@@ -1270,7 +1331,7 @@
          and position(fc.technology_number in #{technologyNumber})
          and pl.reporting_work_id = #{reportingWorkId}
        group by fc.process_id, fc.order_number, fc.technology_number
        order by IF(sort != NULL || sort != '', sort, fc.order_number)
        order by IF(sort != NULL and sort != '', sort, fc.order_number)
    </select>
    <select id="getPrimaryListRework">
@@ -1286,7 +1347,13 @@
               round(SUM(ogd.total_area), 2)                   as gross_area,
               sum(od.weight)                                  as weight,
               #{technologyNumber}                             as technologyNumber,
               concat(fc.process_id, '/', #{technologyNumber}) as processIdNumber
               concat(fc.process_id, '/', #{technologyNumber}) as processIdNumber,
               dd.breakage_type,
               dd.breakage_reason,
               dd.responsible_process,
               dd.responsible_team,
               concat('对应我司单号', o.batch)                 AS otherRemarks,
               dd.responsible_personnel
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
@@ -1308,9 +1375,14 @@
                              ogdc.technology_number = ogd.technology_number
                 left join rework as pl on pl.process_id = fc.process_id and pl.order_sort = fc.order_number and
                                           pl.technology_number = fc.technology_number
                 left join pp.reporting_work as rw on rw.order_id = fc.order_id and rw.process_id = fc.process_id
                 left join pp.damage_details as dd
                           on rw.reporting_work_id = dd.reporting_work_id and dd.order_number = fc.order_number and
                              dd.technology_number = fc.technology_number
        where fc.process_id = #{processId}
          and fc.order_number = #{orderNumber}
          and fc.technology_number = #{technologyNumber}
          and rw.reporting_work_id = #{reportingWorkId}
        group by fc.process_id, fc.technology_number
    </select>
@@ -1341,7 +1413,7 @@
          and position(fc.technology_number in #{technologyNumber})
          and pl.reporting_work_id = #{reportingWorkId}
        group by fc.process_id, fc.order_number, fc.technology_number
        order by IF(sort != NULL || sort != '', sort, fc.order_number)
        order by IF(sort != NULL and sort != '', sort, fc.order_number)
    </select>
    <select id="getPrimaryListMergeRework">
@@ -1413,7 +1485,7 @@
          and position(fc.technology_number in #{technologyNumber})
          and pl.reporting_work_id = #{reportingWorkId}
        group by fc.process_id, fc.order_number, fc.technology_number
        order by IF(sort != NULL || sort != '', sort, fc.order_number)
        order by IF(sort != NULL or sort != '', sort, fc.order_number)
    </select>
    <select id="getPrintCustomDataSemi">
@@ -1436,13 +1508,13 @@
               od.processing_note                                    as processingNote,
               round(ogd.child_width)                                as width,
               round(ogd.child_height)                               as height,
               od.quantity,
               fc.quantity,
               od.order_number                                       as orderNumber,
               fc.technology_number                                  as technologyNumber,
               od.building_number                                    as buildingNumber,
               od.product_name                                       as productName,
               od.edging_type                                        as edgingType,
               p.remarks,
               od.remarks,
               c.customer_abbreviation                               as customerAbbreviation,
               p.product_abbreviation                                as productAbbreviation,
               CONCAT(fc.process_id, '/', fc.technology_number)      as processId,
@@ -1470,10 +1542,14 @@
                 left join sd.order_glass_detail ogd
                           on ogd.order_id = o.order_id and ogd.order_number = od.order_number and
                              ogd.technology_number = fc.technology_number
                 left join flow_card_sort as fcs
                           on fcs.process_id = fc.process_id and fcs.order_number = fc.order_number and
                              fcs.technology_number = fc.technology_number
                               and fcs.process = #{process}
        where fc.process_id = #{processId}
          and fc.technology_number = #{technologyNumber}
        group by od.order_number, ogd.technology_number, ogd.child_width, ogd.child_height
        order by IF(fc.sort != NULL || fc.sort != '', fc.sort, fc.order_number)
          and position(fc.technology_number in #{technologyNumber})
        group by fc.process_id,od.order_number, ogd.technology_number, ogd.child_width, ogd.child_height
        order by IF(fcs.sort != NULL or fcs.sort != '', fcs.sort, fc.order_number)
    </select>
    <select id="selectPrintNotMp">
@@ -1485,8 +1561,8 @@
               fc.order_number,
               ogd.technology_number,
               ogd.glass_address,
               sum(od.quantity)         as quantity,
               sum(ogd.total_area)      as total_area,
               sum(fc.quantity)                                                          as quantity,
               round(sum(ogd.child_width * ogd.child_height * fc.quantity / 1000000), 2) as total_area,
               od.product_name,
               ogd.glass_child,
               fc.founder,
@@ -1681,6 +1757,353 @@
          and pl.technology_number = #{technologyNumber}
          and pl.reporting_work_id = #{reportingWorkId}
        group by od.order_number, width, height
        order by IF(fc.sort != NULL || fc.sort != '', fc.sort, pl.order_sort)
        order by IF(fc.sort != NULL or fc.sort != '', fc.sort, pl.order_sort)
    </select>
    <select id="selectPrintAllMp">
        select *
        from ((select fc.id,
                      fc.order_id,
                      fc.process_id,
                      o.customer_name,
                      o.project,
                      ogd.technology_number,
                      ogd.glass_address,
                      sum(fc.quantity)                                                          as quantity,
                      round(sum(ogd.child_width * ogd.child_height * fc.quantity / 1000000), 2) as total_area,
                      od.product_name,
                      ogd.glass_child,
                      fc.founder,
                      date(fc.splitFrame_time)                                                  as splitFrame_time,
                   /* if(fc.print_status=0,'未打印','已打印') as  print_status*/
                      fc.print_status,
                      ogd.process
               from flow_card as fc
                        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 = fc.order_id and od.order_number = fc.order_number
                        left join sd.`order` as o on o.order_id = fc.order_id
               where fc.order_id = #{orderId}
               GROUP BY fc.process_id, ogd.technology_number
               order by fc.process_id, ogd.technology_number)
              UNION
              (select fc.id,
                      fc.order_id,
                      fc.process_id,
                      o.customer_name,
                      o.project,
                      ogdss.technology_number,
                      ogd.glass_address,
                      ROUND(sum(fc.quantity) / (count(DISTINCT fc.technology_number))) as quantity,
                      sum(ogd.total_area)                                              as total_area,
                      # SUM(ogd.child_width*child_height*fc.quantity/(count(DISTINCT ogd.technology_number))) as total_area,
                      od.product_name,
                      ogdss.concatenated_glass_child                                   as glass_child,
                      fc.founder,
                      date(fc.splitFrame_time)                                         as splitFrame_time,
                      fc.print_status,
                      processed_part                                                   as process
               from flow_card as fc
                        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 = fc.order_id and od.order_number = fc.order_number
                        left join sd.`order` as o on o.order_id = fc.order_id
                        left join (select ogds.order_id,
                                          ogds.order_number,
                                          GROUP_CONCAT(ogds.technology_number SEPARATOR '') AS technology_number,
                                          ogds.glass_child,
                                          GROUP_CONCAT(ogds.glass_child SEPARATOR '+')      AS concatenated_glass_child,
                                          SUBSTRING(process, LOCATE('夹胶', process))       AS processed_part
                                   from sd.order_glass_detail as ogds
                                   where ogds.order_id = #{orderId}
                                     and LOCATE('夹胶', ogds.process) > 0
                                   GROUP BY order_id, order_number, ogds.group) as ogdss
                                  on fc.order_id = ogdss.order_id and ogdss.order_number = fc.order_number
               where fc.order_id = #{orderId}
               GROUP BY fc.process_id, ogdss.technology_number
               order by fc.process_id)
              UNION
              (select fc.id,
                      fc.order_id,
                      fc.process_id,
                      o.customer_name,
                      o.project,
                      ogdss.technology_number,
                      ogd.glass_address,
                      ROUND(sum(fc.quantity) / (count(DISTINCT fc.technology_number))) as quantity,
                      sum(ogd.total_area)                                              as total_area,
                      od.product_name,
                      ogdss.concatenated_glass_child                                   as glass_child,
                      fc.founder,
                      date(fc.splitFrame_time)                                         as splitFrame_time,
                      fc.print_status,
                      processed_part                                                   as process
               from flow_card as fc
                        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 = fc.order_id and od.order_number = fc.order_number
                        left join sd.`order` as o on o.order_id = fc.order_id
                        left join (select ogds.order_id,
                                          ogds.order_number,
                                          GROUP_CONCAT(pds.glass_sort SEPARATOR '')           AS technology_number,
                                          ogds.glass_child,
                                          GROUP_CONCAT(ogds.glass_child SEPARATOR '+')        AS concatenated_glass_child,
                                          SUBSTRING(pds.process, LOCATE('中空', pds.process)) AS processed_part
                                   from sd.order_glass_detail as ogds
                                            left join sd.order_detail as ods
                                                      on ods.order_id = ogds.order_id and ods.order_number = ogds.order_number
                                            left join sd.product_detail as pds on pds.prod_id = ods.product_id and
                                                                                  pds.glass_sort =
                                                                                  ogds.technology_number
                                   where ogds.order_id = #{orderId}
                                   GROUP BY order_id, order_number) as ogdss
                                  on fc.order_id = ogdss.order_id and ogdss.order_number = fc.order_number
               where fc.order_id = #{orderId}
               GROUP BY fc.process_id
               order by fc.process_id)) AS combined_results
        where process is not null
          and process != ""
        GROUP BY order_id, process_id, technology_number, process
        order by order_id, process_id, length(technology_number)
    </select>
    <insert id="printAddSortMp">
        insert into flow_card_sort (process_id, order_number, technology_number, process, sort, create_time)
        values (#{processId}, #{orderNumber}, #{technologyNumber}, #{process}, #{sort}, now())
    </insert>
    <select id="printAddSortCountMp">
        select count(*)
        from flow_card_sort
        where process_id = #{processId}
          and order_number = #{orderNumber}
          and technology_number = #{technologyNumber}
          and process = #{process}
    </select>
    <update id="printUpdateSortMp">
        update flow_card_sort
        set sort = #{sort}
        where process_id = #{processId}
          and order_number = #{orderNumber}
          and technology_number = #{technologyNumber}
          and process = #{process}
    </update>
    <select id="getPrimaryListLimt">
        select o.customer_name,
               o.project,
               #{process}                                         process,
               od.edging_type,
               #{glassChild}                                   as glass_child,
               od.product_name,
               o.processing_note,
               fc.process_id,
               SUM(od.quantity)                                as quantity,
               round(SUM(ogd.total_area), 2)                   as gross_area,
               sum(od.weight)                                  as weight,
               #{technologyNumber}                             as technologyNumber,
               concat(fc.process_id, '/', #{technologyNumber}) as processIdNumber,
               concat('对应我司单号', o.batch)                 AS otherRemarks,
               fc.technology_number                            as qrcode
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
                 left join sd.product as p on p.id = od.product_id
                 left join (select ogd.order_id,
                                   ogd.order_number,
                                   ogd.technology_number,
                                   ogd.glass_child,
                                   GROUP_CONCAT(glass_child SEPARATOR ' ') AS concatenated_glass_child
                            from sd.order_glass_detail as ogd
                            where ogd.order_id = left(#{processId}, 10)
                              and position(ogd.technology_number in #{technologyNumber})
                            GROUP BY order_id, order_number) as ogdc
                           on ogdc.order_id = ogd.order_id and ogdc.order_number = ogd.order_number and
                              ogdc.technology_number = ogd.technology_number
        where fc.process_id = #{processId}
          and position(fc.technology_number in #{technologyNumber})
        group by fc.process_id
        limit 1
    </select>
    <select id="selectPrintDetailsMp">
        select fc.id,
               fc.order_id,
               fc.process_id,
               o.customer_name,
               o.project,
               ogd.technology_number,
               ogd.glass_address,
               (fc.quantity)                                                          as quantity,
               round((ogd.child_width * ogd.child_height * fc.quantity / 1000000), 2) as total_area,
               od.product_name,
               ogd.glass_child,
               fc.founder,
               date(fc.splitFrame_time)                                               as splitFrame_time,
            /* if(fc.print_status=0,'未打印','已打印') as  print_status*/
               fc.print_status,
               ogd.process,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01'))                  AS glassNumber,
               od.order_number
        from flow_card as fc
                 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 = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
        where fc.order_id = #{orderId}
        GROUP BY fc.process_id, od.order_number
        order by fc.process_id, od.order_number
    </select>
    <select id="getPrintCustomDataDetails">
        select o.order_id                                            as orderId,
               project,
               customer_id                                           as customerId,
               o.customer_name                                       as customerName,
               order_type                                            as orderType,
               order_classify                                        as orderClassify,
               batch,
               o.icon,
               pack_type                                             as packType,
               delivery_date                                         as deliveryDate,
               al_type                                               as alType,
               money,
               contract_id                                           as contractId,
               customer_batch                                           customerBatch,
               contacts,
               delivery_address                                      as deliveryAddress,
               od.processing_note                                    as processingNote,
               width,
               height,
               fc.quantity,
               od.order_number                                       as orderNumber,
               fc.technology_number                                  as technologyNumber,
               od.building_number                                    as buildingNumber,
               od.product_name                                       as productName,
               od.edging_type                                        as edgingType,
               od.remarks,
               c.customer_abbreviation                               as customerAbbreviation,
               p.product_abbreviation                                as productAbbreviation,
               fc.process_id                                         as processId,
               o.create_time                                         as createTime,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS glassNumber,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')) AS figureNumber,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S03')) AS colourCeramicGlaze,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')) AS remarks1,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S05')) AS remarks2,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S06')) AS remarks3,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S07')) AS remarks4,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S08')) AS remarks5,
               p.remarks                                             as filmNumber,
               od.bend_radius                                        as bendRadius,
               od.other_columns,
               ogd.glass_child                                       as glassChild,
               ogd.glass_address                                     as glassAddress,
               JSON_UNQUOTE(JSON_EXTRACT(pd.separation, '$.color'))  AS color
        from sd.order as o
                 left join sd.order_detail as od on o.order_id = od.order_id
                 left join flow_card as fc on o.order_id = fc.order_id and
                                              od.order_number = fc.order_number
                 left join sd.product as p on p.id = od.product_id
                 left join sd.customer as c on c.id = o.customer_id
                 left join sd.product_detail as pd on pd.prod_id = p.id and pd.sort_num = od.order_number and
                                                      pd.glass_sort = fc.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
        where fc.process_id = #{processId}
          and fc.order_number = #{orderNumber}
        group by od.order_number, width, height
        order by fc.process_id
    </select>
    <select id="selectUserMp">
        select role_id
        from erp_user_info.`user` as u
                 left join erp_user_info.user_role as ur on u.id = ur.user_id
        where u.login_name = #{userId}
    </select>
    <select id="selectSortTableMp">
        select fcs.sort,
               process_id,
               fcs.order_number,
               fcs.technology_number,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS glassNumber,
               fcs.process
        from flow_card_sort as fcs
                 left join sd.order_detail as od
                           on od.order_id = left(fcs.process_id, 10) and od.order_number = fcs.order_number
        where LEFT(fcs.process_id, 10) = #{orderId}
        GROUP BY process_id,
                 fcs.order_number,
                 fcs.technology_number,
                 fcs.process
        ORDER BY fcs.sort,process_id,
                 fcs.order_number,
                 fcs.technology_number
    </select>
    <select id="countFlowCard">
        select count(distinct process_id) from flow_card where order_id = #{orderId}
    </select>
    <select id="remakList">
        SELECT
            JSON_UNQUOTE(JSON_EXTRACT(other_columns, '$.S01')) AS S01,
            JSON_UNQUOTE(JSON_EXTRACT(other_columns, '$.S04')) AS S02,
            JSON_UNQUOTE(JSON_EXTRACT(other_columns, '$.S05')) AS S03,
            JSON_UNQUOTE(JSON_EXTRACT(other_columns, '$.S06')) AS S04,
            JSON_UNQUOTE(JSON_EXTRACT(other_columns, '$.S07')) AS S05
        FROM flow_card as fc left join sd.order_detail as od on  fc.order_id = od.order_id
        and fc.order_number = od.order_number
        WHERE fc.process_id=#{processId}
        GROUP BY fc.order_number
    </select>
    <select id="selectMaxFlowCard">
        select ifnull((select fc.process_id
                       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=od.order_id and fc.order_number=od.order_number and fc.technology_number=ogd.technology_number
                       where od.order_id = #{orderId}
                         and ogd.production_id = #{productionId}
                       GROUP BY od.order_number
                       order by fc.process_id desc LIMIT 1),'') as process_id
    </select>
    <select id="selectFlowCardMerge">
        select *
        from pp.flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = ogd.order_id and od.order_number = ogd.order_number
        where fc.process_id = #{processId}
        GROUP BY fc.order_id, fc.process_id, ogd.glass_child
    </select>
    <update id="updateFlowCardMerge">
        update  pp.flow_card fc set fc.merge=1
        where fc.process_id = #{processId}
    </update>
    <delete id="deleteflowCardSort">
        delete from flow_card_sort where process_id = #{processId}
    </delete>
</mapper>