chenlu
2024-05-16 6edc05acd8bb1de3bedbf093c618d429c62d446b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.erp.mapper.pp.ReportMapper">
    <resultMap id="flowCardMap" type="com.example.erp.entity.pp.FlowCard">
        <result column="order_id" property="orderId"/>
        <result column="process_Id" property="processId"/>
        <result column="quantity" property="quantity"/>
        <result column="founder" property="founder"/>
        <result column="create_time" property="createTime"/>
        <result column="layout_status" property="layoutStatus"/>
        <!--接收其他外键实体类数据-->
        <association property="order" javaType="com.example.erp.entity.sd.Order">
            <result column="project" property="project"/>
            <result column="order_id" property="orderId"/>
            <result column="customer_name" property="customerName"/>
            <result column="batch" property="batch"/>
            <result column="other_remarks" property="otherRemarks"/>
            <result column="icon" property="icon"/>
            <result column="order_type" property="orderType"/>
            <result column="salesman" property="salesman"/>
            <result column="processing_note" property="processingNote"/>
            <result column="delivery_address" property="deliveryAddress"/>
        </association>
        <association property="orderDetail" javaType="com.example.erp.entity.sd.OrderDetail">
            <result column="product_id" property="productId"/>
            <result column="product_name" property="productName"/>
            <result column="compute_gross_area" property="computeGrossArea"/>
            <result column="processing_note" property="processingNote"/>
            <result column="quantity" property="quantity"/>
            <result column="compute_gross_area" property="computeGrossArea"/>
            <result column="perimeter" property="perimeter"/>
            <result column="order_number" property="orderNumber"/>
            <result column="width" property="width"/>
            <result column="height" property="height"/>
            <result column="shape" property="shape"/>
            <result column="weight" property="weight"/>
        </association>
        <association property="orderGlassDetail" javaType="com.example.erp.entity.sd.OrderGlassDetail">
            <result column="production_id" property="productionId"/>
        </association>
        <association property="product" javaType="com.example.erp.entity.sd.Product">
            <result column="total_thickness" property="totalThickness"/>
            <result column="thickness" property="thickness"/>
        </association>
 
        <!--<result column="g_typeId" property="glassTypes.typeId"/>
        <result column="g_type" property="glassTypes.type"/>-->
 
    </resultMap>
 
    <resultMap id="damageDetailsTableMap" type="com.example.erp.entity.pp.DamageDetails">
        <result column="responsible_process" property="responsibleProcess"/>
        <result column="responsible_team" property="responsibleTeam"/>
        <result column="breakage_type" property="breakageType"/>
        <result column="breakage_reason" property="breakageReason"/>
        <result column="breakage_quantity" property="breakageQuantity"/>
        <result column="area" property="area"/>
            <result column="reporting_work_id" property="reportingWork.reportingWorkId"/>
            <result column="reporting_work_time" property="reportingWork.reportingWorkTime"/>
            <result column="this_process" property="reportingWork.thisProcess"/>
            <result column="project" property="order.project"/>
            <result column="order_id" property="order.orderId"/>
            <result column="glass_child" property="orderGlassDetail.glassChild"/>
    </resultMap>
 
 
    <resultMap id="reportMap" type="com.example.erp.entity.pp.Report">
        <result column="process_id" property="processId"/>
        <result column="customer_name" property="customerName"/>
        <result column="project" property="project"/>
        <result column="order_id" property="orderId"/>
        <result column="batch" property="batch"/>
        <result column="shape" property="shape"/>
        <result column="order_number" property="orderNumber"/>
        <result column="technology_number" property="technologyNumber"/>
        <result column="process" property="technologyFlow"/>
        <result column="quantity" property="orderNum"/>
        <result column="child_width" property="childWidth"/>
        <result column="child_height" property="childHeight"/>
        <result column="stockNum" property="stockNum"/>
        <result column="stockArea" property="stockArea"/>
        <result column="product_name" property="productName"/>
        <result column="bend_radius" property="bendRadius"/>
    </resultMap>
 
 
<!--    流程卡进度-->
    <select id="processCardProgressMp">
        select
            a.product_name,
            b.glass_child,
            d.order_type,
            concat(c.process_id,'/',c.technology_number) as process_id,
            c.technology_number,
            c.quantity,
            e.reportWorkQuantity,
            e.reportWorkQuantityCount,
            e.broken_num,
            round(ifnull(f.inventory,0)*a.area,2) as  inventoryArea
 
        from
            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 (
                SELECT process_id,
                       technology_number,
                       sum(a.broken_num) as broken_num,
                       concat('{',
                              GROUP_CONCAT(concat("\"",process,"\":\"",reporting_work_num,"\"")),
                              '}'
                           ) as reportWorkQuantity,
                       concat('{',
                              GROUP_CONCAT(concat("\"",process,"\":\"",reporting_work_num_count,"\"")),
                              '}'
                           ) as  reportWorkQuantityCount
                FROM sd.order_process_detail as a
                where a.order_id=#{orderId}
                GROUP BY process_id,a.technology_number
            ) as e
        on e.process_id = c.process_id
            and e.technology_number = c.technology_number
 
        where a.order_id = #{orderId}
 
    </select>
 
    <select id="getProcessBreaking" resultMap="damageDetailsTableMap">
        select rw.reporting_work_id,rw.reporting_work_time,dd.responsible_process,dd.responsible_team,
               dd.breakage_type,dd.breakage_reason,ROUND((dd.breakage_quantity)) as breakage_quantity,
               round(ogd.child_width*ogd.child_height*(dd.breakage_quantity)/1000000,2) as area,rw.this_process,
               o.project,o.order_id,ogd.glass_child
        from
            damage_details as dd
                left join reporting_work as rw
                    on rw.reporting_work_id=dd.reporting_work_id
                left join sd.order as o
                    on rw.order_id=o.order_id
                left join sd.order_glass_detail as ogd
                          on ogd.order_id=o.order_id and ogd.order_number=dd.order_number
                                 and ogd.technology_number and dd.technology_number
        where date(rw.reporting_work_time)>=#{startDate} and date(rw.reporting_work_time) &lt;= #{endDate}
          and rw.this_worn_quantity>0 and dd.available=0
          and reviewed_state!=2
            and rw.this_process!=dd.responsible_process
        GROUP BY dd.id
        order by dd.id desc
        limit #{offset},#{pageSize}
    </select>
 
    <select id="getProcessBreakingTotal">
        select
            CEILING(count(dd.id)/#{pageSize}) as 'pageTotal',
            count(distinct dd.id) as 'total'
        from
            damage_details as dd
                left join reporting_work as rw
                          on rw.reporting_work_id=dd.reporting_work_id
                left join sd.order as o
                          on rw.order_id=o.order_id
                left join sd.order_glass_detail as ogd
                          on ogd.order_id=o.order_id and ogd.order_number=dd.order_number
                              and ogd.technology_number and dd.technology_number
        where date(rw.reporting_work_time)>=#{startDate} and date(rw.reporting_work_time) &lt;= #{endDate}
          and rw.this_worn_quantity>0 and dd.available=0
          and reviewed_state!=2
          and rw.this_process!=dd.responsible_process
        order by dd.id desc
    </select>
 
    <select id="workInProgressMp">
        select #{selectProcesses} as thisProcess,
               fc.process_id,
               o.customer_name,
               o.project,
               o.order_id,
               o.batch,
               od.shape,
               ogd.order_number,
               ogd.technology_number,
               ogd.process,
               od.quantity,
               ogd.child_width,
               ogd.child_height,
               odpds.reporting_work_num_count + ifnull(c.patchNumSum, 0) - odpd.reporting_work_num_count -
               odpd.broken_num as stockNum,
               ROUND(ogd.child_width * ogd.child_height *
                     (odpds.reporting_work_num_count + ifnull(c.patchNumSum, 0) - odpd.reporting_work_num_count -
                      odpd.broken_num) / 1000000, 2) as stockArea,
               od.product_name,
               od.bend_radius
 
        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_process_detail as odpds
                           ON odpds.id = odpd.id - 1
                 left join
             (SELECT sum(rw.rework_num) as 'patchNumSum',
                     rw.process_id,
                     rw.order_sort,
                     rw.technology_number,
                     rwk.this_process
              from rework as rw
                       LEFT JOIN
                   reporting_work as rwk
                   on rw.reporting_work_id = rwk.reporting_work_id
              where rwk.this_process = #{selectProcesses}
                and rw.review_status = 1
              GROUP BY rw.process_id, rw.order_sort, rw.technology_number) as c
             on c.process_id = fc.process_id
                 and c.order_sort = fc.order_number
                 and c.technology_number = fc.technology_number
                 left join sd.`order` as o
                           on o.order_id = od.order_id
        where LENGTH(fc.process_id) = 14
          and odpds.reporting_work_num_count + ifnull(c.patchNumSum, 0) - odpd.reporting_work_num_count -
              odpd.broken_num != 0
          and odpd.process = #{selectProcesses} and o.create_time between #{selectTime1} and #{selectTime2}
          and position(#{orderId} in od.order_id) and position(#{inputProject} in o.project)
 
        group by fc.process_id, fc.order_number, fc.technology_number
        order by fc.process_id, fc.order_number, fc.technology_number
    </select>
 
    <!--
    <if test="Report.processId != null and Report.processId != ''">
            and fc.process_id regexp #{Report.processId}
        </if>
        <if test="Report.customerName != null and Report.customerName != ''">
            and o.customer_name regexp #{Report.customerName}
        </if>
        <if test="Report.project != null and Report.project != ''">
            and o.project regexp #{Report.project}
        </if>
        <if test="Report.batch != null and Report.batch != ''">
            and o.batch regexp #{Report.batch}
        </if>
        <if test="Report.shape != null and Report.shape != ''">
            and od.shape regexp #{Report.shape}
        </if>
    -->
 
<!--     <select id="getWorkInProgressTotal">-->
<!--        select CEILING(count(fc.id) / #{pageSize}) as 'pageTotal',-->
<!--               count(distinct fc.id)               as 'total'-->
 
<!--        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_process_detail as odpds-->
<!--                           ON odpds.id = odpd.id - 1-->
<!--                 left join-->
<!--             (SELECT sum(rw.rework_num) as 'patchNumSum',-->
<!--                     rw.process_id,-->
<!--                     rw.order_sort,-->
<!--                     rw.technology_number,-->
<!--                     rwk.this_process-->
<!--              from rework as rw-->
<!--                       LEFT JOIN-->
<!--                   reporting_work as rwk-->
<!--                   on rw.reporting_work_id = rwk.reporting_work_id-->
<!--              where rwk.this_process = #{selectProcesses}-->
<!--                and rw.review_status = 1-->
<!--              GROUP BY rw.process_id, rw.order_sort, rw.technology_number) as c-->
<!--             on c.process_id = fc.process_id-->
<!--                 and c.order_sort = fc.order_number-->
<!--                 and c.technology_number = fc.technology_number-->
<!--                 left join sd.`order` as o-->
<!--                           on o.order_id = od.order_id-->
<!--        where LENGTH(fc.process_id) = 14-->
<!--          and odpds.reporting_work_num_count + ifnull(c.patchNumSum, 0) - odpd.reporting_work_num_count - -->
<!--              odpd.broken_num != 0-->
<!--          and odpd.process = #{selectProcesses}-->
<!--          and o.create_time between #{selectTime1} and #{selectTime2}-->
<!--          and position(#{orderId} in od.order_id)-->
<!--          and position(#{inputProject} in o.project)-->
<!--        group by fc.process_id, fc.order_number, fc.technology_number-->
<!--        order by fc.process_id, fc.order_number, fc.technology_number-->
<!--        limit #{offset},#{pageSize};-->
<!--    </select>-->
 
    <select id="processToBeCompletedMp">
        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,
               od.quantity,
               ROUND(ogd.child_width * ogd.child_height / 1000000, 2)                 as childArea,
               ROUND(ogd.child_width * ogd.child_height * od.quantity / 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,
               od.quantity - odpd.reporting_work_num                                  as incompleteNum,
               ROUND(ogd.child_width * ogd.child_height * (od.quantity - odpd.reporting_work_num) / 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 LENGTH(fc.process_id) = 14
          and odpd.process = #{selectProcesses}
          and o.create_time between #{selectTime1} and #{selectTime2}
          and position(#{orderId} in od.order_id)
          and position(#{inputProject} in o.project)
          and od.quantity > odpd.reporting_work_num
 
        group by fc.process_id, fc.order_number, fc.technology_number
        order by fc.process_id, fc.order_number, fc.technology_number
    </select>
 
    <select id="selectDamageReportMp">
        SELECT
            o.order_id,
            o.project,
            rw.process_id,
            dd.order_number,
            dd.technology_number,
            date(rw.reporting_work_time) as reporting_work_time,
            dd.responsible_process,
            dd.responsible_team,
            dd.responsible_equipment,
            dd.breakage_type,
            dd.breakage_reason,
            dd.breakage_quantity,
            round( ogd.child_width * ogd.child_height * dd.breakage_quantity / 1000000, 2 ) as area,
            IFNULL(dd.responsible_personnel,'') as personnel,
            ogd.glass_child
        FROM
            sd.ORDER AS o
                LEFT JOIN sd.order_glass_detail AS ogd ON ogd.order_id = o.order_id
                LEFT JOIN reporting_work AS rw ON rw.order_id = o.order_id
                LEFT JOIN damage_details AS dd ON dd.reporting_work_id = rw.reporting_work_id
                AND dd.order_number = ogd.order_number
                AND dd.technology_number = ogd.technology_number
        WHERE
            rw.reporting_work_time between #{selectTime1} and #{selectTime2}
          AND dd.available = 0
          AND LENGTH( rw.process_id )= 14
        GROUP BY
            dd.id
    </select>
 
    <select id="splittingDetailsOutsideMp">
        SELECT
            fc.process_id,
            fc.order_number,
            fc.technology_number,
            o.project,
            o.batch,
            ogd.child_width,
            ogd.child_height,
            fc.quantity,
            round( ogd.child_width * ogd.child_height * fc.quantity / 1000000, 2 ) as area,
            od.shape,
            od.remarks
        FROM
            sd.ORDER AS o
                LEFT JOIN sd.order_detail AS od ON od.order_id = od.order_id
                LEFT JOIN sd.order_glass_detail AS ogd ON o.order_id = ogd.order_id
                AND ogd.order_number = od.order_number
                LEFT JOIN flow_card AS fc ON fc.order_id = ogd.order_id
                AND fc.order_number
                AND fc.technology_number = ogd.technology_number
        WHERE
            fc.order_id = #{orderId}
        GROUP BY
            fc.id
    </select>
 
    <select id="qualityReportMp">
        SELECT o.order_id,
               o.customer_name,
               o.project,
               fc.order_number,
               fc.technology_number,
               od.product_name,
               od.quantity,
               MAX(opd.reporting_work_num_count)                                                   as quantityMax,
               IFNULL(SUM(distinct dd.breakage_quantity), 0)                                       as breakage_quantity,
               IFNULL(sum(distinct pl.patch_num), 0)                                               as patch_num,
               fc.received_quantity,
               CONCAT(ROUND(ROUND(od.quantity / MAX(opd.reporting_work_num_count), 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 o.order_id = fc.order_id
            AND fc.order_number = od.order_number
 
                 LEFT JOIN damage_details AS dd ON dd.process_id = fc.process_id
            AND dd.order_number = fc.order_number
            AND dd.technology_number = fc.technology_number
            and dd.available != 1
 
                 LEFT JOIN patch_log AS pl ON pl.order_id = fc.order_id
            AND pl.process_id = fc.process_id
            AND pl.order_sort = fc.order_number
            AND pl.technology_number = fc.technology_number
 
                 LEFT JOIN sd.order_process_detail AS opd ON opd.order_id = fc.order_id
            AND opd.order_number = fc.order_number
            AND opd.technology_number = fc.technology_number
 
        WHERE o.create_time BETWEEN #{selectTime1} and #{selectTime2}
 
        GROUP BY o.order_id,
                 fc.order_number,
                 fc.technology_number
        ORDER BY fc.order_number
    </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_time BETWEEN #{selectTime1} and #{selectTime2}
          AND position(#{selectProcesses} IN opd.process)
        GROUP BY opd.process, o.order_id
    </select>
 
    <select id="productionScheduleMp">
        select
            a.order_number,
            a.shape,
            a.product_name,
            b.child_width,
            b.child_height,
            c.quantity,
            c.technology_number,
            b.glass_child,
            e.reportWorkQuantity,
            e.reportWorkQuantityCount,
            ifnull(f.inventory,0) as inventoryNum,
            round(ifnull(f.inventory,0)*a.area,2) as  inventoryArea,
                dd.quantity as shippedQuantity,
            dd.area
 
        from
            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 (
                SELECT process_id,
                       technology_number,
                       sum(a.broken_num) as broken_num,
                       concat('{',
                              GROUP_CONCAT(concat("\"",process,"\":\"",reporting_work_num,"\"")),
                              '}'
                           ) as reportWorkQuantity,
                       concat('{',
                              GROUP_CONCAT(concat("\"",process,"\":\"",reporting_work_num,"\"")),
                              '}'
                           ) as  reportWorkQuantityCount
                FROM sd.order_process_detail as a
                where a.order_id=#{orderId}
                GROUP BY process_id,a.technology_number
            ) as e
                          on e.process_id = c.process_id
                              and e.technology_number = c.technology_number
                left join sd.delivery_detail as dd on dd.order_id=a.order_id and dd.order_number=a.order_number
        where a.order_id = #{orderId}
        ORDER BY a.order_number
    </select>
 
    <select id="taskCompletionStatusMp">
        select d.customer_name,
               d.project,
               d.batch,
               c.order_id,
               d.quantity,
               d.area,
               dd.quantity as shippedQuantity,
               dd.area     as shippedArea,
               e.reportWorkQuantity,
               e.reportWorkQuantityCount
 
        from sd.`order` as d
                 left join flow_card as c on c.order_id = d.order_id
                 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 mm.finished_goods_inventory as f
                           on c.order_id = f.order_id and f.order_number = c.order_number
                 left join (SELECT process_id,
                                   technology_number,
                                   sum(a.broken_num) as broken_num,
                                   concat('{',
                                          GROUP_CONCAT(concat("\"", process, "\":\"", ifnull(reporting_work_num,0), "\"")),
                                          '}'
                                       )             as reportWorkQuantity,
                                   concat('{',
                                          GROUP_CONCAT(concat("\"", process, "\":\"", ifnull(reporting_work_num,0), "\"")),
                                          '}'
                                       )             as reportWorkQuantityCount
                            FROM sd.order_process_detail as a
                                     left join sd.`order` as o on o.order_id = a.order_id
                            where o.create_time BETWEEN #{selectTime1} and #{selectTime2}
                            GROUP BY process_id,a.technology_number
                            ) as e
                           on e.process_id = c.process_id
                               and e.technology_number = c.technology_number
                 left join sd.delivery_detail as dd on dd.order_id = a.order_id and dd.order_number = a.order_number
        where d.create_time BETWEEN #{selectTime1} and #{selectTime2} and reportWorkQuantity is not null
        GROUP BY a.order_id
        ORDER BY a.order_id
    </select>
 
    <select id="orderPlanDecompositionMp">
        SELECT
            o.order_id,
            o.customer_name,
            o.project,
            o.batch,
            o.quantity,
            o.area,
            date(fc.create_time) as create_time,
            date(orw.startTime) as startTime,
            oopd.completionsNum,
            sum( DISTINCT fc.received_quantity ) AS received_quantity,
            sum( DISTINCT fc.quantity - fc.received_quantity ) AS receivedNo,
            IF(fc.quantity=fc.received_quantity,'已清单','') as accomplish,
            DATEDIFF(
                    MAX( rw.reporting_work_time ),
                    min( rw.reporting_work_time ))+1 AS daysDifference
        FROM
            sd.`order` AS o
                LEFT JOIN flow_card AS fc ON fc.order_id = o.order_id
                LEFT JOIN (
                SELECT
                    a.order_id,
                    MIN( b.reporting_work_time ) AS startTime
                FROM
                    sd.`order` AS a
                        LEFT JOIN reporting_work AS b ON a.order_id = b.order_id
                WHERE
                    b.this_process = '切割'
                  AND a.create_time BETWEEN #{selectTime1} and #{selectTime2}
                GROUP BY
                    a.order_id
            ) AS orw ON orw.order_id = o.order_id
                LEFT JOIN (
                SELECT
                    a.order_id,
                    SUM( b.reporting_work_num ) AS completionsNum
                FROM
                    sd.`order` AS a
                        LEFT JOIN sd.order_process_detail AS b ON a.order_id = b.order_id
                WHERE
                    b.process = '包装'
                  AND a.create_time BETWEEN #{selectTime1} and #{selectTime2}
                GROUP BY
                    a.order_id
            ) AS oopd ON oopd.order_id = o.order_id
                LEFT JOIN reporting_work AS rw ON rw.order_id = fc.order_id
                AND rw.process_id = fc.process_id
        WHERE
            o.create_time BETWEEN #{selectTime1} and #{selectTime2}
          AND fc.create_time IS NOT NULL
        GROUP BY
            o.order_id
    </select>
 
    <select id="rawMaterialRequisitionMp">
        SELECT
            fc.project_no,
            modl.material_name,
            modl.producer,
            ou.width,
            ou.height,
            modl.date_of_manufacture,
            SUM(distinct modl.outbound_quantity) as quantity,
            ROUND(SUM(modl.outbound_quantity)*SUM(modl.single_piece_area),2) as area,
            date(mo.material_requisition_date) as date
        FROM
            mm.material_outbound_detail AS modl
                left join mm.material_outbound as mo on mo.material_outbound_id=modl.material_outbound_id
                LEFT JOIN optimize_use AS ou ON modl.use_id = ou.id and ou.raw_stock_code=modl.inventory_id
                LEFT JOIN flow_card AS fc ON ou.project_no = fc.project_no
        where  modl.use_id IS NOT NULL and mo.material_requisition_date BETWEEN #{selectTime1} and #{selectTime2}
        GROUP BY
            ou.width,ou.height,material_code
    </select>
</mapper>