李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
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
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
<?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.chinaztt.mes.production.mapper.ProductOutputMapper">
 
    <resultMap id="productOutputMap" type="com.chinaztt.mes.production.dto.ProductOutputDTO">
        <id property="id" column="id"/>
        <result property="partId" column="part_id"/>
        <result property="productQty" column="product_qty"/>
        <result property="sproductQty" column="sproduct_qty"/>
        <result property="productNo" column="product_no"/>
        <result property="partNo" column="part_no"/>
        <result property="partName" column="part_name"/>
        <result property="partDescription" column="part_description"/>
        <result property="unit" column="unit"/>
        <result property="sunit" column="sunit"/>
        <result property="operationNo" column="operation_no"/>
        <result property="operationName" column="operation_name"/>
        <result property="optaskNo" column="optask_no"/>
        <result property="specs" column="specs"/>
        <result property="plannedQuantity" column="planned_quantity"/>
        <result property="completedQuantity" column="completed_quantity"/>
        <result property="progress" column="progress"/>
        <result property="productMainId" column="product_main_id"/>
        <result property="outBatchNo" column="out_batch_no"/>
        <result property="systemNo" column="system_no"/>
        <result property="staffNo" column="staff_no"/>
        <result property="staffId" column="staff_id"/>
        <result property="staffName" column="staff_name"/>
        <result property="systemNo" column="system_no"/>
        <result property="date" column="date"/>
        <result property="quantity" column="quantity"/>
        <result property="dutyRecordId" column="duty_record_id"/>
        <result property="isQualified" column="is_qualified"/>
        <result property="isUsed" column="is_used"/>
        <result property="remark" column="remark"/>
        <result property="workstationId" column="workstation_id"/>
        <result property="workstationName" column="workstation_name"/>
        <result property="checkStatus" column="check_status"/>
        <result property="isSelfQualified" column="is_self_qualified"/>
        <result property="state" column="state"/>
        <result property="sortNo" column="sort_no"/>
        <result property="startMeterMark" column="start_meter_mark"/>
        <result property="endMeterMark" column="end_meter_mark"/>
        <result property="reelNumber" column="reel_number"/>
        <result property="segmentDesc" column="segment_desc"/>
        <result property="scrapQty" column="scrap_qty"/>
        <result property="operationId" column="operation_id"/>
        <result property="planningMethod" column="planning_method"/>
        <result property="ifsOpfeedId" column="ifs_opfeed_id"/>
        <result property="ifsLaborId" column="ifs_labor_id"/>
        <result property="createTime" column="create_time"/>
        <result property="ifsBatchNo" column="ifs_batch_no"/>
        <result property="shiftOutputId" column="shift_output_id"/>
        <result property="ifsSync" column="ifs_sync"/>
        <result property="reelWeight" column="reel_weight"/>
        <result property="grossWeight" column="gross_weight"/>
        <result property="netWeight" column="net_weight"/>
        <result property="theoryWeight" column="theory_weight"/>
        <result property="mainId" column="main_id"/>
        <result property="origPartId" column="orig_part_id"/>
        <result property="partId" column="part_id"/>
        <result property="printNum" column="print_num"/>
        <result property="artificialType" column="artificial_type"/>
        <result property="nowDutyDate" column="now_duty_date"/>
        <result property="shiftName" column="shift_name"/>
        <result property="dutyNo" column="duty_no"/>
    </resultMap>
 
    <resultMap id="productOutputLabel" type="com.chinaztt.mes.production.dto.ProductOutputLabelDTO">
        <result property="customerOrderNo" column="customer_order_no"/>
        <result property="customerName" column="customer_name"/>
        <result property="operationName" column="operation_name"/>
        <result property="workstationName" column="workstation_name"/>
        <result property="partName" column="part_name"/>
        <result property="partNo" column="part_no"/>
        <result property="outBatchNo" column="out_batch_no"/>
        <result property="productQty" column="product_qty"/>
        <result property="reelNumber" column="reel_number"/>
        <result property="nowTime" column="now_time"/>
        <result property="remark" column="remark"/>
        <result property="reelWeight" column="reel_weight"/>
        <result property="grossWeight" column="gross_weight"/>
        <result property="netWeight" column="net_weight"/>
        <result property="theoryWeight" column="theory_weight"/>
        <result property="segmentDesc" column="segment_desc"/>
        <result property="productionTime" column="production_time"/>
        <result property="productionPerson" column="production_person"/>
        <result property="unit" column="unit" />
        <result property="lotTrackingIfs" column="lot_tracking_ifs"/>
        <result property="cusMaterialCode" column="cus_material_code" />
        <result property="ifsBatchNo" column="ifs_batch_no" />
        <result property="startMeterMark" column="start_meter_mark" />
        <result property="endMeterMark" column="end_meter_mark" />
        <result property="partPitch" column="part_pitch" />
        <result property="endProduct" column="end_product" />
        <result property="discToolMeasurement" column="disc_tool_measurement" />
    </resultMap>
 
    <select id="getByMainId" resultMap="productOutputMap">
        SELECT opo."id",
               opo.part_id,
               opo.out_batch_no,
               opo.reel_number,
               opo.system_no,
               opo.ifs_opfeed_id,
               opo.ifs_labor_id,
               bp.part_no,
               bp.part_name,
               bp.description part_description,
               top.operation_no,
               top."name"     operation_name,
               opo.product_main_id,
               opo.product_qty,
               bp.unit,
               opo.sproduct_qty,
               bp.sunit,
               opm.product_no,
               opo.state,
               opo.start_meter_mark,
               opo.end_meter_mark,
               opo.scrap_qty,
               tro.operation_id,
               bp.planning_method,
               opo.ifs_batch_no,
               opo.segment_desc,
               opo.scrap_qty,
               opo.remark,
               opo.shift_output_id,
               opo.ifs_sync
        FROM production_product_output opo
                 LEFT JOIN basic_part bp ON bp."id" = opo.part_id
                 LEFT JOIN production_product_main opm ON opm."id" = opo.product_main_id
                 LEFT JOIN production_operation_task oot ON oot."id" = opm.operation_task_id
                 LEFT JOIN plan_manufacturing_order_routing_operation tro ON tro."id" = oot.mo_routing_operation_id
                 LEFT JOIN technology_operation top ON top."id" = tro.operation_id
        WHERE opo.product_main_id = #{mainId}
        ORDER BY opo.system_no
    </select>
 
    <select id="getProductionProgress" resultMap="productOutputMap">
        select temp.*
        from
        (select
        opm.product_no,
        oot.optask_no,
        opo.reel_number,
        top."name" operation_name,
        bp.part_no,
        bp.part_name,
        bp.description part_description,
        bp.specs,
        oot.planned_quantity,
        opo.product_qty,
        round(opo.product_qty / oot.planned_quantity * 100, 2) progress,
        opo.create_time
        from production_product_output opo
        left join basic_part bp on bp."id" = opo.part_id
        left join production_product_main opm on opm."id" = opo.product_main_id
        left join production_operation_task oot on oot."id" = opm.operation_task_id
        LEFT JOIN plan_manufacturing_order_routing_operation tro ON tro."id" = oot.mo_routing_operation_id
        left join technology_operation top on top."id" = tro.operation_id
        WHERE opm."state" = '02submitted'
        ) temp
        <if test="ew.emptyOfWhere == false">
            ${ew.customSqlSegment}
        </if>
    </select>
 
    <select id="getProductOutPutById" resultMap="productOutputMap">
        SELECT s.staff_no,
               bs.staff_name,
               bs.id || ''       staff_id,
               s.duty_record_id,
               s.quantity,
               s.system_no,
               s.date,
               s.artificial_type status,
               opo."id",
               opo.part_id,
               opo.out_batch_no,
               bp.part_no,
               bp.part_name,
               bp.description    part_description,
               top.operation_no,
               top."name"        operation_name,
               opo.product_main_id,
               opo.product_qty,
               opo.sproduct_qty,
               bp.unit,
               opm.product_no,
               opo.reel_number,
               opo.start_meter_mark,
               opo.end_meter_mark,
               opo.ifs_batch_no,
               opo.segment_desc,
               opo.scrap_qty,
               opo.remark,
               opo.create_time
        FROM production_product_output_staff s
                 LEFT JOIN production_product_output opo ON opo.id = s.product_out_id
                 LEFT JOIN basic_part bp ON bp."id" = opo.part_id
                 LEFT JOIN production_product_main opm ON opm."id" = opo.product_main_id
                 LEFT JOIN production_operation_task oot ON oot."id" = opm.operation_task_id
                 LEFT JOIN plan_manufacturing_order_routing_operation tro ON tro."id" = oot.mo_routing_operation_id
                 LEFT JOIN technology_operation top ON top."id" = tro.operation_id
                 LEFT JOIN basic_staff bs ON bs.staff_no = s.staff_no
        WHERE opo.id = #{id}
          AND s.artificial_type = TRUE
        UNION ALL
        SELECT array_to_string(array_agg(s.staff_no), ',')    AS staff_no,
               array_to_string(array_agg(bs.staff_name), ',') AS staff_name,
               array_to_string(array_agg(bs.id), ',')         AS staff_id,
               s.duty_record_id,
               s.quantity,
               s.system_no,
               s.date,
               s.artificial_type                                 status,
               opo."id",
               opo.part_id,
               opo.out_batch_no,
               bp.part_no,
               bp.part_name,
               bp.description                                    part_description,
               top.operation_no,
               top."name"                                        operation_name,
               opo.product_main_id,
               opo.product_qty,
               opo.sproduct_qty,
               bp.unit,
               opm.product_no,
               opo.reel_number,
               opo.start_meter_mark,
               opo.end_meter_mark,
               opo.ifs_batch_no,
               opo.segment_desc,
               opo.scrap_qty,
               opo.remark,
               opo.create_time
        FROM production_product_output_staff s
                 LEFT JOIN production_product_output opo ON opo.id = s.product_out_id
                 LEFT JOIN basic_part bp ON bp."id" = opo.part_id
                 LEFT JOIN production_product_main opm ON opm."id" = opo.product_main_id
                 LEFT JOIN production_operation_task oot ON oot."id" = opm.operation_task_id
                 LEFT JOIN plan_manufacturing_order_routing_operation tro ON tro."id" = oot.mo_routing_operation_id
                 LEFT JOIN technology_operation top ON top."id" = tro.operation_id
                 LEFT JOIN basic_staff bs ON bs.staff_no = s.staff_no
        WHERE opo.id = #{id}
          AND s.artificial_type = FALSE
        GROUP BY s.system_no,
                 s.date,
                 s.artificial_type,
                 s.duty_record_id,
                 s.quantity,
                 opo."id",
                 opo.part_id,
                 opo.out_batch_no,
                 bp.part_no,
                 bp.part_name,
                 bp.description,
                 top.operation_no,
                 top."name",
                 opo.product_main_id,
                 opo.product_qty,
                 opo.sproduct_qty,
                 bp.unit,
                 opm.product_no,
                 opo.start_meter_mark,
                 opo.end_meter_mark,
                 opo.ifs_batch_no,
                 opo.segment_desc,
                 opo.scrap_qty,
                 opo.remark,
                 opo.reel_number,
                 opo.create_time
    </select>
 
    <select id="getOutputByDutyRecordId" resultMap="productOutputMap">
        SELECT
            ppo."id",
            ppo.system_no,
            ppo.out_batch_no,
            ppo.product_qty,
            ppo.sproduct_qty,
            bp.unit,
            bp.sunit,
            bp.part_no,
            bp.specs,
            pot.optask_no,
            ppo.reel_number,
            puw.unit_work_factor,
            round(ppo.product_qty * puw.unit_work_factor * 88,2) as qty_salary
        FROM
            production_product_output ppo
                LEFT JOIN basic_part bp ON bp."id" = ppo.part_id
                LEFT JOIN production_product_main ppm ON ppm."id" = ppo.product_main_id
                LEFT JOIN production_operation_task pot ON pot."id" = ppm.operation_task_id
                LEFT JOIN technology_routing_operation tro ON pot.routing_operation_id = tro."id"
                LEFT JOIN production_unit_work puw ON puw.part_id = ppo.part_id
                AND puw.operation_id = tro.operation_id
                AND puw.workstation_id = ppm.workstation_id
        WHERE exists(SELECT 1
                     FROM production_product_output_staff ppos
                     WHERE ppos.duty_record_id = #{dutyRecordId}
                       AND ppo."id" = ppos.product_out_id)
    </select>
 
 
 
    <select id="getOutputByDutyRecordIdList" resultMap="productOutputMap">
        SELECT
            distinct ppo."id",
            ppo.system_no,
            ppo.out_batch_no,
            ppo.product_qty,
            ppo.sproduct_qty,
            bp.unit,
            bp.sunit,
            bp.part_no,
            bp.specs,
            pot.optask_no,
            ppo.reel_number,
            puw.unit_work_factor,
            pdr.duty_no,
            pdr.now_duty_date,
            bst.name as shift_name,
            round(ppo.product_qty * puw.unit_work_factor * 88,2) as qty_salary
        FROM
            production_product_output ppo
                LEFT JOIN basic_part bp ON bp."id" = ppo.part_id
                LEFT JOIN production_product_main ppm ON ppm."id" = ppo.product_main_id
                LEFT JOIN production_operation_task pot ON pot."id" = ppm.operation_task_id
                LEFT JOIN technology_routing_operation tro ON pot.routing_operation_id = tro."id"
                LEFT JOIN production_unit_work puw ON puw.part_id = ppo.part_id
                AND puw.operation_id = tro.operation_id
                AND puw.workstation_id = ppm.workstation_id
                LEFT JOIN production_product_output_staff ppos on ppo."id" = ppos.product_out_id
                LEFT JOIN production_duty_record pdr on pdr."id"=ppos.duty_record_id
                LEFT JOIN basic_shift bst on bst.id = pdr.shift_id
                WHERE ppos.duty_record_id in
                <foreach collection="dutyRecordIdList" item="dutyRecordId" index="index" open="(" close=")" separator=",">
                #{dutyRecordId}
                </foreach>
    </select>
 
 
 
 
    <delete id="deleteStaffOutByMainId">
        DELETE
        FROM production_product_output_staff
        WHERE product_out_id IN (SELECT id FROM production_product_output WHERE product_main_id = #{mainId})
    </delete>
 
    <delete id="deleteArtificialInformationByMainId">
        DELETE
        FROM production_artificial_information
        WHERE output_id IN (SELECT id FROM production_product_output WHERE product_main_id = #{mainId})
    </delete>
 
    <select id="getOutputList" resultMap="productOutputMap">
        select temp.*
        from
        (select
        ppo."id",
        pot.optask_no,
        ppo.system_no,
        ppo.out_batch_no,
        ppo.part_id,
        bp.part_no,
        bp.part_name,
        ppo.product_qty,
        ppo.sproduct_qty,
        ppo.reel_number,
        ppo.create_time,
        bp.unit,
        bp.sunit,
        ppm.workstation_id,
        ppm.product_no,
        qr.is_qualified,
        qr.is_used,
        qr.remark,
        qr.check_status,
        qr.is_self_qualified,
        pos.staff_name,
        ppo.start_meter_mark,
        ppo.end_meter_mark,
        ppo.scrap_qty,
        ppo.segment_desc,
        ppo.remark
        from production_product_output ppo
        left join basic_part bp on bp."id" = ppo.part_id
        left join production_product_main ppm on ppm."id" = ppo.product_main_id
        left join production_operation_task pot on pot."id" = ppm.operation_task_id
        left join
        (select
        system_no,
        bool_and(is_qualified)is_qualified,
        bool_and(is_used)is_used,
        "max"(remark) remark,
        "max"(check_status) check_status,
        bool_and(is_self_qualified) is_self_qualified,
        bool_and(is_erp) is_erp
        from quality_result group by system_no) qr on qr.system_no = ppo.system_no and qr.is_erp = false
        LEFT JOIN (
        SELECT
        ARRAY_AGG(s.staff_name) staff_name,
        product_out_id
        FROM
        production_product_output_staff pos
        LEFT JOIN basic_staff s ON pos.staff_id = s."id"
        GROUP BY
        product_out_id
        ) pos ON pos.product_out_id = ppo."id"
        <where>
            <if test="dto.startTime != null and dto.endTime != ''">
                AND to_char( ppo.create_time, 'YYYYMMDD' ) between #{dto.startTime} and #{dto.endTime}
            </if>
        </where>
        ) temp
        <if test="ew.emptyOfWhere == false">
            ${ew.customSqlSegment}
        </if>
    </select>
 
 
 
    <select id="getOutputListByScan" resultMap="productOutputMap">
        select
        ppo."id",
        ppo.out_batch_no
        from production_product_output ppo
        where ppo.out_batch_no = #{dto.outBatchNo}
        AND to_char( ppo.create_time, 'YYYYMMDD' ) between #{dto.startTime} and #{dto.endTime}
    </select>
 
    <select id="getProductOut" resultMap="productOutputMap">
        SELECT E.*
        FROM (SELECT A.*,C.part_no,C.part_name,B.product_no,C.unit,c.sunit,D.id workstation_id,D.name workstation_name
        FROM production_product_output A
        LEFT JOIN production_product_main B ON B."id" = A.product_main_id
        LEFT JOIN basic_workstation D ON D."id" = B.workstation_id
        LEFT JOIN basic_part C ON C."id" = A.part_id
        WHERE B.workstation_id = #{id}) E
        <if test="ew.emptyOfWhere == false">
            ${ew.customSqlSegment}
        </if>
    </select>
 
 
    <delete id="deleteProductOutPutById">
        DELETE
        FROM production_product_output_staff
        WHERE product_out_id IN (SELECT id FROM production_product_output WHERE product_main_id = #{mainId})
    </delete>
 
 
    <select id="getShiftProductOutByOpIdAndWsId" resultType="com.chinaztt.mes.production.dto.ProductOutputDTO">
        select t1.*
        from (SELECT ppo.*, ppos.duty_record_id
              FROM production_product_output ppo
                       LEFT JOIN production_product_main ppm ON ppo.product_main_id = ppm."id"
                       LEFT JOIN (SELECT DISTINCT product_out_id, duty_record_id
                                  FROM production_product_output_staff) ppos
                                 ON ppos.product_out_id = ppo.ID
              where ppo."state" = '03changeshift'
                AND ppm.workstation_id = #{workstationId}
                AND ppm.operation_task_id = #{opeartionTaskId}) t1
        where not exists(select 1
                         FROM production_product_output ppo
                                  LEFT JOIN production_product_main ppm ON ppo.product_main_id = ppm."id"
                         WHERE ppo."state" IN ('02submitted', '01draft')
                           AND ppm.workstation_id = #{workstationId}
                           AND ppm.operation_task_id = #{opeartionTaskId}
                           and t1.out_batch_no = ppo.out_batch_no)
        ORDER BY t1."id" DESC
    </select>
 
    <select id="getProductOutDetailsBySN" resultMap="productOutputMap">
        SELECT *
        FROM production_product_output
        WHERE out_batch_no = #{sn}
    </select>
 
    <select id="getShiftedNumberByOutputIds" resultType="java.lang.Integer">
        SELECT
        COUNT(*)
        FROM
        production_product_output ppo
        WHERE
        ppo.shift_output_id in
        <foreach collection="outputIds" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
        AND ppo.state = '02submitted'
    </select>
 
    <update id="clearShiftOutputId">
        update
            production_product_output
        set shift_output_id = null
        where shift_output_id = #{id}
    </update>
 
    <select id="getSumProductQty" resultType="java.math.BigDecimal">
        SELECT
        "sum"(temp.product_qty)
        FROM
        (
        SELECT
        ppo."id",
        pot.optask_no,
        ppo.system_no,
        ppo.out_batch_no,
        ppo.part_id,
        bp.part_no,
        bp.part_name,
        ppo.product_qty,
        ppo.sproduct_qty,
        ppo.reel_number,
        ppo.create_time,
        bp.unit,
        bp.sunit,
        ppm.workstation_id,
        ppm.product_no,
        qr.is_qualified,
        qr.is_used,
        qr.remark,
        qr.check_status,
        qr.is_self_qualified,
        pos.staff_name,
        ppo.start_meter_mark,
        ppo.end_meter_mark,
        ppo.scrap_qty,
        ppo.segment_desc,
        ppo.remark
        FROM
        production_product_output ppo
        LEFT JOIN basic_part bp ON bp."id" = ppo.part_id
        LEFT JOIN production_product_main ppm ON ppm."id" = ppo.product_main_id
        LEFT JOIN production_operation_task pot ON pot."id" = ppm.operation_task_id
        LEFT JOIN quality_result qr ON qr.system_no = ppo.system_no
        AND qr.is_erp = FALSE
        AND qr.apply_type = '01output'
        LEFT JOIN (
        SELECT ARRAY_AGG( s.staff_name ) staff_name,
        product_out_id
        FROM
        production_product_output_staff pos
        LEFT JOIN basic_staff s ON pos.staff_id = s."id"
        GROUP BY
        product_out_id
        ) pos ON pos.product_out_id = ppo."id"
        <where>
            <if test="dto.startTime != null and dto.endTime != ''">
                AND to_char( ppo.create_time, 'YYYYMMDD' ) between #{dto.startTime} and #{dto.endTime}
            </if>
        </where>
        ) temp
        <if test="ew.emptyOfWhere == false">
            ${ew.customSqlSegment}
        </if>
    </select>
 
    <insert id="batchInsert" parameterType="map" useGeneratedKeys="true" keyProperty="id">
        <!--@mbg.generated-->
        insert into production_product_output
        (part_id, product_qty, create_time, create_user, product_main_id, out_batch_no,
        system_no, sort_no, start_meter_mark, end_meter_mark,
        reel_number, ifs_batch_no, segment_desc, scrap_qty, ifs_opfeed_id, ifs_labor_id,
        remark, shift_output_id, sproduct_qty, reel_weight, gross_weight, net_weight, is_sn_generate_output,disc_tool_measurement )
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.partId,jdbcType=BIGINT}, #{item.productQty,jdbcType=NUMERIC},
            #{item.createTime,jdbcType=TIMESTAMP}, #{item.createUser,jdbcType=VARCHAR},
            #{item.productMainId,jdbcType=BIGINT},
            #{item.outBatchNo,jdbcType=VARCHAR}, #{item.systemNo,jdbcType=VARCHAR},
            #{item.sortNo,jdbcType=BIGINT}, #{item.startMeterMark,jdbcType=NUMERIC},
            #{item.endMeterMark,jdbcType=NUMERIC}, #{item.reelNumber,jdbcType=VARCHAR},
            #{item.ifsBatchNo,jdbcType=VARCHAR}, #{item.segmentDesc,jdbcType=VARCHAR},
            #{item.scrapQty,jdbcType=NUMERIC}, #{item.ifsOpfeedId,jdbcType=BIGINT}, #{item.ifsLaborId,jdbcType=BIGINT},
            #{item.remark,jdbcType=VARCHAR}, #{item.shiftOutputId,jdbcType=BIGINT},
            #{item.sproductQty,jdbcType=NUMERIC},
            #{item.reelWeight,jdbcType=NUMERIC}, #{item.grossWeight,jdbcType=NUMERIC},
            #{item.netWeight,jdbcType=NUMERIC}, #{item.isSnGenerateOutput,jdbcType=BOOLEAN}, #{item.discToolMeasurement,jdbcType=VARCHAR}
            )
        </foreach>
    </insert>
 
    <select id="exportList" resultType="com.chinaztt.mes.production.excel.ProductOutPutData">
        SELECT ppo.out_batch_no,
               "replace"(bp.part_name, '馈线跳线 ', '') AS part_name
        FROM production_product_output ppo
                 LEFT JOIN basic_part bp ON bp."id" = ppo.part_id
                 LEFT JOIN production_product_main ppm ON ppm."id" = ppo.product_main_id
        WHERE ppm.operation_task_id = #{operationTaskId}
          and ppm.workstation_id = #{workstationId}
        order by ppo.out_batch_no asc
    </select>
<!--    支持-->
    <select id="batchLabelPrint" resultMap="productOutputLabel">
        SELECT pco.customer_order_no,
        pco.customer_name,
        top.name operation_name,
        bw.name as workstation_name,
        bp.part_name,
        bp.part_no,
        bp.part_pitch,
        bp.unit,
        bp.lot_tracking_ifs,
        bp2.part_name as end_product,
        ppo.out_batch_no,
        <!--根据同一SN取和(考虑到交接班的情况)-->
        (SELECT sum(product_qty) FROM production_product_output WHERE out_batch_no = ppo.out_batch_no GROUP BY out_batch_no) AS product_qty,
        ppo.reel_number,
        to_char(NOW(), 'yyyy-mm-dd hh24:mi:ss') now_time,
        ppo.remark,
        ppo.reel_weight || 'kg' AS reel_weight,
        ppo.gross_weight || 'kg' AS gross_weight,
        ppo.net_weight || 'kg' AS net_weight,
        ppo.theory_weight || 'kg' AS theory_weight,
        ppo.segment_desc,
        to_char(ppo.create_time, 'yyyy-mm-dd hh24:mi:ss') production_time,
        ppos.production_person,
        bcprm.cus_material_code,
        ppo.ifs_batch_no as ifs_batch_no,
        ppo.start_meter_mark,
        ppo.end_meter_mark,
        ppo.disc_tool_measurement
        FROM production_product_output ppo
        LEFT JOIN production_product_main ppm ON ppm.ID = ppo.product_main_id
        LEFT JOIN production_operation_task ppt ON ppt.ID = ppm.operation_task_id
        LEFT JOIN production_operation_task_supply pots ON ppt.ID = pots.operation_task_id
        LEFT JOIN plan_manufacturing_order pmo ON pmo.ID = pots.mo_id
        LEFT JOIN basic_part bp ON bp.ID = ppo.part_id
        LEFT JOIN plan_join_model_customer pjmc ON pjmc.model_id = pmo.ID
        AND pjmc.model = 'plan_manufacturing_order'
        LEFT JOIN plan_customer_order pco ON pco.ID = pjmc.customer_order_id
        LEFT JOIN basic_part bp2 ON bp2.part_no = pco.part_no
        LEFT JOIN technology_routing_operation tro ON tro.ID = ppt.routing_operation_id
        LEFT JOIN technology_operation top ON top.id = tro.operation_id
        LEFT JOIN basic_workstation bw ON bw.ID = ppm.workstation_id
        LEFT JOIN basic_customer_part_relation_map bcprm on bcprm.part_no = bp.part_no
        LEFT JOIN (SELECT string_agg(bs.staff_name, ',') production_person,
        ppos.product_out_id
        FROM production_product_output_staff ppos
        LEFT JOIN basic_staff bs ON ppos.staff_id = bs."id"
        WHERE ppos.product_out_id in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
        GROUP BY ppos.product_out_id) ppos ON ppos.product_out_id = ppo.id
        WHERE ppo.ID in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </select>
 
    <select id="sumProdOutQtyByBatchNo" resultType="java.math.BigDecimal">
        SELECT COALESCE(SUM(product_qty),0) product_qty FROM production_product_output WHERE out_batch_no = #{batchNo}
    </select>
    <select id="selectByTaskId" resultType="com.chinaztt.mes.production.dto.ProductOutputDTO">
        select ppo.*
        from production_product_output ppo
                 left join production_product_main ppm on ppo.product_main_id = ppm.id
                 left join production_operation_task pot on pot.id = ppm.operation_task_id
        where pot.id = #{id} and ppo.state = '01draft';
    </select>
    <select id="getDraftProductOut" resultType="com.chinaztt.mes.production.dto.ProductOutputDTO">
        select ppo.*, ppm.product_no as product_no, ppm.id as main_id
        from production_product_output ppo
                 left join production_product_main ppm on ppo.product_main_id = ppm.id
                 left join production_operation_task pot on ppm.operation_task_id = pot.id
        where pot.id = #{id}
          and ppm.state = '01draft';
    </select>
 
    <select id="getStaffProductionWage" resultMap="productOutputMap">
        SELECT DISTINCT
            ppo."id",
            ppos.staff_id,
            ppos.artificial_type,
            ppo.part_id,
            ppo.system_no,
            ppo.out_batch_no,
            ppo.product_qty,
            ppo.sproduct_qty,
            bp.unit,
            bp.sunit,
            bp.part_no,
            bp.specs,
            bp.part_name,
            pot.optask_no,
            ppo.reel_number,
            puw.unit_work_factor,
            bw.name as workstation_name,
            too.name as operation_name,
            round(ppos.quantity * puw.unit_work_factor * 88,2) as qty_salary
        FROM
          (SELECT * FROM production_product_output_staff WHERE duty_record_id = #{dutyRecordId}) ppos
          INNER JOIN production_product_output ppo ON ppo."id" = ppos.product_out_id
          LEFT JOIN basic_part bp ON bp."id" = ppo.part_id
          LEFT JOIN production_product_main ppm ON ppm."id" = ppo.product_main_id
          LEFT JOIN production_operation_task pot ON pot."id" = ppm.operation_task_id
          LEFT JOIN technology_routing_operation tro ON pot.routing_operation_id = tro."id"
          LEFT JOIN production_unit_work puw ON puw.part_id = ppo.part_id AND puw.operation_id = tro.operation_id AND puw.workstation_id = ppm.workstation_id
          LEFT JOIN basic_workstation bw ON bw."id" = ppm.workstation_id
          LEFT JOIN technology_operation too ON too."id" = tro.operation_id
    </select>
 
 
 
 
    <select id="judgeChangeshift" resultType="java.lang.String">
        SELECT state FROM production_product_output
        WHERE ID IN ( SELECT MIN ( "id" ) FROM production_product_output GROUP BY product_main_id )
        AND product_main_id = #{productMainId}
    </select>
 
 
    <select id="countChangeshiftByList" resultType="java.lang.Integer">
        select count(*) FROM production_product_output
        WHERE ID IN ( SELECT MIN ( "id" ) FROM production_product_output GROUP BY product_main_id )
        AND state = '03changeshift'
        AND product_main_id in
        <foreach collection="productMainIdList" item="productMainId" separator="," open="(" close=")">
            #{productMainId}
        </foreach>
    </select>
 
 
 
    <select id="selectCheckOverProduction" resultMap="productOutputMap">
        select ppo.*,pot.completed_quantity,pot.planned_quantity FROM production_product_output ppo
        left join  production_product_main ppm on ppo.product_main_id = ppm.id
        left join  production_operation_task pot on pot.id = ppm.operation_task_id
        where pot.id = #{id}
    </select>
 
 
    <select id="getStateByDutyRecordId" resultType="java.lang.String">
        select ppo.state from production_product_output ppo
        left join production_product_output_staff ppos on ppo.id = ppos.product_out_id
        where ppos.duty_record_id = #{dutyRecordId}
    </select>
 
 
    <select id="getDutyRecordByOutputId" resultMap="productOutputMap">
        select ppo.id,now_duty_date,bs.name as shift_name
        from production_product_output ppo
        left join
        (select max(product_out_id) product_out_id,max(duty_record_id) duty_record_id
        from  production_product_output_staff group by product_out_id, duty_record_id
        ) T ON T.product_out_id = ppo.id
        left join production_duty_record pdr on T.duty_record_id = pdr.id
        left join basic_shift bs on bs."id"=pdr.shift_id
        where ppo.id = #{productOutId}
    </select>
 
    <select id="getEmsMachineYield"
            resultType="com.chinaztt.mes.production.dto.EmsMachineYieldDTO$MachineYieldDetailInfo">
        SELECT
            bs."name" shift_type,
            bw.workstation_no machine_code,
            bw."name" machine_name,
            bp.unit,
            SUM (ppo.product_qty) yield,
            TO_CHAR(ppo.create_time, ${showDateFormat}) time_particle_value
        FROM
            production_product_main ppm
            LEFT JOIN production_product_output ppo ON ppm."id" = ppo.product_main_id
            LEFT JOIN basic_part bp ON ppo.part_id = bp."id"
            LEFT JOIN basic_workstation bw ON ppm.workstation_id = bw."id"
            LEFT JOIN ( SELECT product_out_id, duty_record_id FROM production_product_output_staff GROUP BY product_out_id, duty_record_id ) ppos ON ppos.product_out_id = ppo."id"
            LEFT JOIN production_duty_record pdr ON pdr."id" = ppos.duty_record_id
            LEFT JOIN basic_shift bs ON pdr.shift_id = bs."id"
        WHERE
        bw.workstation_no = #{machineCode}
        AND TO_CHAR(ppo.create_time, #{sqlDateFormat}) &gt;= #{beginDate}
        AND TO_CHAR(ppo.create_time, #{sqlDateFormat}) &lt;= #{endDate}
        GROUP BY
        bs."name",
        bw.workstation_no,
        bw."name",
        bp.unit,
        TO_CHAR( ppo.create_time, ${showDateFormat} );
    </select>
</mapper>