李林
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
<?xml version="1.0" encoding="UTF-8"?>
 
<!--
  ~
  ~      Copyright (c) 2018-2025, ztt All rights reserved.
  ~
  ~  Redistribution and use in source and binary forms, with or without
  ~  modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~  this list of conditions and the following disclaimer.
  ~  Redistributions in binary form must reproduce the above copyright
  ~  notice, this list of conditions and the following disclaimer in the
  ~  documentation and/or other materials provided with the distribution.
  ~  Neither the name of the pig4cloud.com developer nor the names of its
  ~  contributors may be used to endorse or promote products derived from
  ~  this software without specific prior written permission.
  ~  Author: ztt
  ~
  -->
 
<!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.OperationTaskMapper">
 
    <resultMap id="operationTaskDtoMap" type="com.chinaztt.mes.production.dto.OperationTaskDTO">
        <id property="id" column="id"/>
        <result property="optaskNo" column="optask_no"/>
        <result property="createTime" column="create_time"/>
        <result property="routingId" column="routing_id"/>
        <result property="moRoutingId" column="mo_routing_id"/>
        <result property="moRoutingOperationId" column="mo_routing_operation_id"/>
        <result property="routingOperationId" column="routing_operation_id"/>
        <result property="state" column="state"/>
        <result property="splannedQuantity" column="splanned_quantity"/>
        <result property="plannedQuantity" column="planned_quantity"/>
        <result property="completedQuantity" column="completed_quantity"/>
        <result property="plannedStartDate" column="planned_start_date"/>
        <result property="plannedFinishDate" column="planned_finish_date"/>
        <result property="actualStartDate" column="actual_start_date"/>
        <result property="actualFinishDate" column="actual_finish_date"/>
        <result property="remark" column="remark"/>
        <result property="partNo" column="part_no"/>
        <result property="partName" column="part_name"/>
        <result property="unit" column="unit"/>
        <result property="operationNo" column="operation_no"/>
        <result property="operationName" column="operation_name"/>
        <result property="operationTaskType" column="operation_task_type"/>
        <result property="workstationId" column="workstation_id"/>
        <result property="technologyName" column="technology_name"/>
        <result property="technologyRequirement" column="technology_requirement"/>
        <result property="manufacturingOrder" column="manufacturing_order"/>
        <result property="salesOrder" column="sales_order"/>
        <result property="customer" column="customer"/>
        <result property="priority" column="priority"/>
        <result property="workstationName" column="workstation_name"/>
        <result property="routingNo" column="routing_no"/>
        <result property="workstationNo" column="workstation_no"/>
        <result property="moNo" column="mo_no"/>
        <result property="mpsNo" column="mps_no"/>
        <result property="customerOrderNo" column="customer_order_no"/>
        <result property="customerName" column="customer_name"/>
        <result property="quantitySupply" column="quantity_supply"/>
        <result property="reservedQuantity" column="reserved_quantity"/>
        <result property="discNum" column="disc_num"/>
        <result property="bomId" column="bom_id"/>
        <result property="moId" column="mo_id"/>
        <result property="combineState" column="combine_state"/>
        <result property="locationId" column="location_id"/>
        <result property="locationNo" column="location_no"/>
        <result property="locationName" column="location_name"/>
        <result property="hourQuota" column="hour_quota"/>
        <result property="routingOperationRemark" column="routing_operation_remark"/>
        <result property="workCenter" column="work_center"/>
        <result property="manufactureAttr" column="manufacture_attr"/>
        <result property="productName" column="product_name"/>
        <result property="insulationColor" column="insulation_color"/>
        <result property="outerColor" column="outer_color"/>
        <result property="reelSpec" column="reel_spec"/>
        <result property="pcoId" column="pco_id"/>
        <result property="ratio" column="ratio"/>
        <result property="mpsId" column="mps_id"/>
        <result property="isSubmit" column="is_submit"/>
    </resultMap>
 
    <resultMap id="applyType" type="com.chinaztt.mes.production.dto.ApplyReportTypeDetailDTO">
        <result property="typeCode" column="value"/>
        <result property="typeName" column="label"/>
    </resultMap>
 
    <resultMap id="operationTaskFromMoMap" type="com.chinaztt.mes.production.dto.OperationTaskDTO">
        <result property="operationId" column="operation_id"></result>
        <result property="operationNo" column="operation_no"></result>
        <result property="operationName" column="operation_name"></result>
        <result property="workCenter" column="work_center"></result>
        <result property="workstationId" column="workstation_id"></result>
        <result property="operationTaskType" column="operation_task_type"/>
        <result property="workstationNo" column="workstation_no"></result>
        <result property="workstationName" column="workstation_name"></result>
        <result property="partId" column="part_id"></result>
        <result property="partNo" column="part_no"></result>
        <result property="partName" column="part_name"></result>
        <result property="plannedQuantity" column="planned_quantity"></result>
        <result property="locationId" column="location_id"></result>
        <result property="locationNo" column="location_no"></result>
        <result property="locationName" column="location_name"></result>
        <result property="moRoutingOperationId" column="mo_routing_operation_id"></result>
        <result property="routingOperationId" column="routing_operation_id"></result>
        <result property="moId" column="mo_id"></result>
        <result property="moNo" column="mo_no"></result>
        <result property="plannedStartDate" column="planned_start_date"></result>
        <result property="plannedFinishDate" column="planned_finish_date"></result>
        <result property="manufactureAttr" column="manufacture_attr"/>
        <result property="reelSpec" column="reel_spec"/>
        <collection property="workstations" ofType="com.chinaztt.mes.basic.entity.Workstation"
                    column="work_center" select="com.chinaztt.mes.basic.mapper.WorkstationMapper.selectByWorkcenter">
        </collection>
    </resultMap>
 
    <resultMap id="basicLocationMap" type="com.chinaztt.mes.basic.entity.Location">
        <id property="id" column="id"/>
        <result property="locNo" column="loc_no"/>
        <result property="locName" column="loc_name"/>
        <result property="locDesc" column="loc_desc"/>
        <result property="locStatus" column="loc_status"/>
        <result property="active" column="active"/>
        <result property="ifsLocation" column="ifs_location"/>
    </resultMap>
 
    <select id="getFromMoOptionByMoId" resultMap="operationTaskFromMoMap">
        SELECT
            pmo."id"                              AS mo_id,
            pmo.mo_no                             AS mo_no,
            pmoro.operation_id,
            pmoro.ID                              AS mo_routing_operation_id,
            pmoro.technology_routing_operation_id AS routing_operation_id,
            bto.operation_no,
            bto."name"                            AS operation_name,
            pmo.technology_routing_id             AS routing_id,
            pmoro.work_center,
            pmoro.part_id,
            bp.part_no,
            bp.part_name,
            bp.unit,
            bp.sunit,
            pmo.manufacture_attr,
            CASE
                WHEN pmso.qpa IS NULL THEN
                    pmo.qty_required
                ELSE pmo.qty_required * pmso.qpa
                END                               AS planned_quantity,
            pmo.required_date                     AS planned_finish_date,
            timezone('UTC' :: TEXT, now())        AS planned_start_date
        FROM
            plan_manufacturing_order_routing_operation pmoro
                LEFT JOIN plan_manufacturing_order pmo ON pmoro.mo_id = pmo."id"
                LEFT JOIN technology_operation bto ON bto."id" = pmoro.operation_id
                LEFT JOIN basic_part bp ON bp."id" = pmoro.part_id
                LEFT JOIN (SELECT * FROM plan_mo_structure_component WHERE plan_manufacturing_order_id = #{moId}) pmso
                          ON pmso.part_id = pmoro.part_id and  pmso.operation_id = pmoro.operation_id
        WHERE
            pmoro.mo_id = #{moId}
    </select>
 
    <sql id="pageSql">
        SELECT
            P.part_name,
            P.part_no,
            P.unit,
            o.NAME operation_name,
            T.*,
            G.mo_no,
            w.name as workstation_name
        FROM
            production_operation_task T
                LEFT JOIN basic_part P ON T.part_id = P.ID
                LEFT JOIN plan_manufacturing_order_routing_operation ro ON ro.ID = T.mo_routing_operation_id
                LEFT JOIN technology_operation o ON o.ID = ro.operation_id
                LEFT JOIN production_operation_task_supply F ON f.operation_task_id = T."id"
                LEFT JOIN plan_manufacturing_order G ON G."id" = F.mo_id
                LEFT JOIN basic_workstation w on T.workstation_id = w.id
    </sql>
 
    <select id="getByPalletTransId" resultMap="operationTaskDtoMap">
        SELECT
            pot.*,
            bp.part_name,
            part_no,
            bw."name" AS workstation_name
        FROM
            production_operation_task pot
                LEFT JOIN basic_part bp ON bp."id" = pot.part_id
                LEFT JOIN basic_workstation bw ON pot.workstation_id = bw."id"
                LEFT JOIN warehouse_pallet_transports_optask wpto ON wpto.operation_task_id = pot."id"
        WHERE wpto.transports_id = #{palletId}
    </select>
 
    <delete id="deleteOperationById">
        DELETE
        FROM production_operation_task
             A
        WHERE A."id" = #{id};
        DELETE
        FROM production_operation_task_material
             B
        WHERE B.operation_task_id = #{id};
        DELETE
        FROM production_operation_task_supply
             D
        WHERE D.operation_task_id = #{id};
        UPDATE production_operation_task_produce
        SET operation_task_id = NULL
        WHERE
            operation_task_id = #{id}
    </delete>
 
    <select id="queryPage" resultMap="operationTaskDtoMap">
        select temp.*
        from
            (SELECT
                 P.part_name,
                 P.part_no,
                 P.unit,
                 o.NAME operation_name,
                 T.*,
                 G.mo_no,
                 w.name workstation_name,
                 pmps.mps_no,
                 pco.customer_name,
                 pco.customer_order_no,
                 round( T.completed_quantity / T.planned_quantity * 100, 2 ) AS ratio
             FROM
                 production_operation_task T
                     LEFT JOIN basic_part P ON T.part_id = P.ID
                     LEFT JOIN plan_manufacturing_order_routing_operation ro ON ro.ID = T.mo_routing_operation_id
                     LEFT JOIN technology_operation o ON o.ID = ro.operation_id
                     LEFT JOIN production_operation_task_supply F ON f.operation_task_id = T."id"
                     LEFT JOIN plan_manufacturing_order G ON G."id" = F.mo_id
                     LEFT JOIN plan_master_production_schedule pmps ON pmps."id" = G.mps_id
                     LEFT JOIN plan_join_model_customer pjmc ON pjmc.model_id = pmps."id"
                     AND pjmc.model = 'plan_master_production_schedule'
                     LEFT JOIN plan_customer_order pco ON pco."id" = pjmc.customer_order_id
                     LEFT JOIN basic_workstation w on T.workstation_id = w.id
            ) temp
        <if test="ew.emptyOfWhere == false">
            ${ew.customSqlSegment}
        </if>
    </select>
 
 
    <select id="getListByWorkstationId" resultMap="operationTaskDtoMap">
        <include refid="pageSql"/>
        where t.workstation_id =#{workstationId} and t.state!='04completed' order by id desc limit 3
    </select>
 
    <select id="getOperationTask" resultMap="operationTaskDtoMap">
        select oot."id",
               oot.optask_no,
               oot."state",
               oot.planned_quantity,
               oot.completed_quantity,
               oot.priority,
               oot.planned_start_date,
               oot.planned_finish_date,
               oot.actual_start_date,
               oot.actual_finish_date,
               oot.remark,
               oot.workstation_id,
               bp.part_no,
               bp.part_name,
               bp.unit,
               oot.part_id,
               oot.routing_id,
               oot.mo_routing_operation_id,
               pmo.mo_no,
               pmo.mps_id,
               top."name"    operation_name,
               oot.create_time,
               oot.disc_num,
               oot.sunit,
               oot.splanned_quantity,
               oot.manufacture_attr,
               oot.reel_spec,
               tr.id         mo_routing_id,
               tr.routing_no technology_name,
               tro.operation_id,
               tro.remark    routing_operation_remark,
               pmps.mps_no,
               pco.customer_name,
               pco.id as pco_id,
               pco.customer_order_no,
               pbp.part_name product_name,
               oot.reel_spec
        from production_operation_task oot
                 LEFT JOIN basic_part bp on bp."id" = oot.part_id
                 LEFT JOIN plan_manufacturing_order_routing_operation tro on tro."id" = oot.mo_routing_operation_id
                 LEFT JOIN plan_manufacturing_order_routing tr on tr."id" = tro.mo_routing_id
                 LEFT JOIN technology_operation top on top."id" = tro.operation_id
                 LEFT JOIN production_operation_task_supply pots on pots.operation_task_id = oot."id"
                 LEFT JOIN plan_manufacturing_order pmo on pmo."id" = pots.mo_id
                 LEFT JOIN plan_master_production_schedule pmps ON pmps.ID = pmo.mps_id
                 LEFT JOIN plan_join_model_customer pjmc
                           ON pjmc.model_id = pmps."id" AND pjmc.model = 'plan_master_production_schedule'
                 LEFT JOIN plan_customer_order pco ON pco."id" = pjmc.customer_order_id
                 LEFT JOIN basic_part pbp ON pbp."id" = pmps.part_id
        <where>
            <if test="stateLimit == true">
                oot.state != '04completed' and oot.state != '05canceled' and oot.state != '06combined' and oot.state != '07unsubmit' and oot.state IS NOT NULL
            </if>
            <if test="ew.emptyOfWhere == false">
                AND ${ew.SqlSegment}
            </if>
            <if test="productSn != null">
                AND pmo.id IN (SELECT DISTINCT current_mo_id  FROM plan_manufacturing_order_sn_generate WHERE product_sn = #{productSn} AND current_mo_id IS NOT null)
            </if>
            <if test="salesOrder != null">
                <bind name="salesOrder" value="'%' + salesOrder + '%'"/>
                AND pco.customer_order_no like #{salesOrder}
            </if>
            <if test="productName != null">
                <bind name="productName" value="'%' + productName + '%'"/>
                AND pbp.part_name like #{productName}
            </if>
            <if test="outBatchNo != null and operationStockStatus == true ">
                AND pmo.mo_no = (select distinct pmo.mo_no
                from production_operation_task pot
                left join production_operation_task_supply pots on pots.operation_task_id = pot.id
                left join plan_manufacturing_order pmo on pmo.id = pots.mo_id
                left join production_product_main ppm on ppm.operation_task_id = pot.id
                left join production_product_output ppo on ppo.product_main_id = ppm.id
                where ppo.out_batch_no  =#{outBatchNo} )
            </if>
            <if test="outBatchNo != null and operationStockStatus == false ">
                AND pmps.mps_no = (select distinct pmps.mps_no
                from production_operation_task pot
                left join production_operation_task_supply pots on pots.operation_task_id = pot.id
                left join plan_manufacturing_order pmo on pmo.id = pots.mo_id
                left join plan_master_production_schedule pmps on pmo.mps_id = pmps.id
                left join production_product_main ppm on ppm.operation_task_id = pot.id
                left join production_product_output ppo on ppo.product_main_id = ppm.id
                where ppo.out_batch_no  =#{outBatchNo} )
            </if>
            <if test="mpsNo != null and mpsNo != ''">
                <bind name="mpsNo" value="'%' + mpsNo + '%'"/>
                AND pmps.mps_no like #{mpsNo}
            </if>
        </where>
        order by oot.priority, oot.planned_finish_date:: date
    </select>
 
 
    <select id="getOperationTaskDTO" resultMap="operationTaskDtoMap">
        SELECT
            pot.*,
            bp.part_name,
            bp.part_no,
            bp.unit,
            ar.resource_name,
            bw."name"                                             workstation_name,
            pmor.routing_no,
            bto."name"                                            operation_name,
            pots.quantity_supply,
            pmo.mo_no,
            pmo.ID                                                mo_id,
            pmoro.operation_id,
            to_char(planned_start_date, 'yyyy-MM-dd hh24:mi:ss') || ',' ||
            to_char(planned_finish_date, 'yyyy-MM-dd hh24:mi:ss') planed_start_end_time
        FROM
            production_operation_task pot
                LEFT JOIN basic_part bp ON pot.part_id = bp."id"
                LEFT JOIN aps_resource ar ON ar."id" = pot.resource_id
                LEFT JOIN basic_workstation bw ON bw."id" = pot.workstation_id
                LEFT JOIN plan_manufacturing_order_routing_operation pmoro ON pmoro.ID = pot.mo_routing_operation_id
                LEFT JOIN plan_manufacturing_order_routing pmor ON pmoro.mo_routing_id = pmor."id"
                LEFT JOIN technology_operation bto ON bto.ID = pmoro.operation_id
                LEFT JOIN production_operation_task_supply pots ON pots.operation_task_id = pot."id"
                LEFT JOIN plan_manufacturing_order pmo ON pmo."id" = pots.mo_id
        WHERE pot."id" = #{id}
    </select>
 
    <update id="updateCompletedQuantity">
        UPDATE production_operation_task
        SET completed_quantity = completed_quantity + #{diffQuantity}
        WHERE id = #{id}
    </update>
 
    <select id="pdaPage" resultMap="operationTaskDtoMap">
        SELECT id,
               optask_no,
               "state",
               priority,
               planned_quantity,
               sunit,
               splanned_quantity,
               completed_quantity,
               part_no,
               part_name,
               workstation_no,
               workstation_name,
               operation_no,
               operation_name,
               manufacture_attr
        FROM (
                 SELECT pot.optask_no,
                        pot.priority,
                        pot.planned_quantity,
                        pot.completed_quantity,
                        pot."id",
                        pot.sunit,
                        pot.splanned_quantity,
                        pot.manufacture_attr,
                        bp.part_no,
                        bp.part_name,
                        bw.workstation_no,
                        bw."name"  workstation_name,
                        top.operation_no,
                        top."name" operation_name,
                        pot."state"
                 FROM production_operation_task pot
                          LEFT JOIN basic_part bp on bp."id" = pot.part_id
                          LEFT JOIN basic_workstation bw on bw."id" = pot.workstation_id
                          LEFT JOIN plan_manufacturing_order_routing_operation tro on tro."id" = pot.mo_routing_operation_id
                          LEFT JOIN technology_operation top on top."id" = tro.operation_id
             ) tempA
        <if test="ew.emptyOfWhere == false">
            <where>
                ${ew.SqlSegment}
            </where>
        </if>
        order by "id" desc
    </select>
 
    <select id="getLastOperationTask" resultMap="operationTaskDtoMap">
        SELECT
            pot.*
        FROM
            production_operation_task pot
                LEFT JOIN production_operation_task_supply pots ON pots.operation_task_id = pot."id"
        WHERE pot.routing_operation_id = (SELECT trof.to_id
                                          FROM technology_routing_operation_ref trof
                                                   LEFT JOIN technology_routing_operation tro ON trof.from_id = tro."id"
                                                   LEFT JOIN production_operation_task pots ON tro."id" = pots.routing_operation_id
                                          WHERE pots."id" = #{operationTaskId})
          AND pots.mo_id = (SELECT apots.mo_id
                            FROM production_operation_task_supply apots
                                     LEFT JOIN production_operation_task apot ON apots.operation_task_id = apot."id"
                            WHERE apot."id" = #{operationTaskId})
    </select>
 
    <select id="selectByIds" resultMap="operationTaskDtoMap">
        SELECT
            ot.*,
            mo.bom_id,
            ro.operation_id
        FROM production_operation_task ot
                 LEFT JOIN production_operation_task_supply ts ON ts.operation_task_id = ot."id"
                 LEFT JOIN technology_routing_operation ro ON ro.ID = ot.routing_operation_id
                 LEFT JOIN plan_manufacturing_order mo ON mo."id" = ts.mo_id
        where ot.id IN
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </select>
 
    <select id="getCombinedOperationTaskInfo" resultMap="operationTaskDtoMap">
        SELECT
            P.part_name,
            P.part_no,
            P.unit,
            o.NAME operation_name,
            T.*,
            G.mo_no,
            w.name workstation_name
        FROM
            production_operation_task T
                LEFT JOIN basic_part P ON T.part_id = P.ID
                LEFT JOIN plan_manufacturing_order_routing_operation ro ON ro.ID = T.mo_routing_operation_id
                LEFT JOIN technology_operation o ON o.ID = ro.operation_id
                LEFT JOIN production_operation_task_supply F ON f.operation_task_id = T."id"
                LEFT JOIN plan_manufacturing_order G ON G."id" = F.mo_id
                LEFT JOIN basic_workstation w ON T.workstation_id = w.id
        WHERE
            T.combine_task_id = #{id}
    </select>
 
    <select id="getApplyReportType" resultMap="applyType">
        SELECT DISTINCT value,label
        FROM sys_dict_item
        WHERE type = 'apply_report_type'
    </select>
 
    <select id="getPalletOptaskCode" resultType="java.lang.String">
        SELECT pot.optask_no
        FROM warehouse_pallet_transports_optask wpto
                 LEFT JOIN production_operation_task pot ON pot."id" = wpto.operation_task_id
        WHERE wpto.operation_task_id IN
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </select>
 
    <select id="getFeedLocationListByWorkstationNo" resultMap="basicLocationMap">
        SELECT bl.*
        FROM (SELECT * FROM basic_workstation_location WHERE location_type = 1) bwl --库位类型为投料库位
                 INNER JOIN (SELECT * FROM basic_workstation WHERE workstation_no = #{workstationNo}) bw ON bwl.workstation_id = bw."id"
                 INNER JOIN (SELECT * FROM basic_location WHERE active = 't' AND loc_status = 1) bl ON bwl.location_id = bl."id" --有效且状态为使用
    </select>
 
    <select id="getActiveOperationTaskListByWorkstationNo" resultMap="operationTaskDtoMap">
        SELECT pot.*,bp.part_no,bp.part_name
        FROM (SELECT * FROM production_operation_task WHERE "state" = '02inProgress' OR "state" = '01pending') pot --工单状态为进行中或等待中
                 INNER JOIN (SELECT * FROM basic_workstation WHERE workstation_no = #{workstationNo}) bw ON pot.workstation_id = bw."id"
                 INNER JOIN basic_part bp ON pot.part_id = bp."id"
    </select>
 
    <select id="getActiveOperationTaskListUnPointWorkstationByWorkstationNo" resultMap="operationTaskDtoMap">
        SELECT pot.*,bp.part_no,bp.part_name
        FROM (SELECT * FROM production_operation_task WHERE workstation_id IS NULL AND work_center IS NOT NULL AND ("state" = '02inProgress' OR "state" = '01pending')) pot --工单状态为进行中或等待中
                 INNER JOIN (SELECT * FROM basic_workstation WHERE work_center IS NOT NULL AND workstation_no = #{workstationNo}) bw ON pot.work_center = bw.work_center
                 INNER JOIN basic_part bp ON pot.part_id = bp."id"
    </select>
<!--支持-->
    <select id="getOperationInfoById" resultMap="operationTaskDtoMap">
        SELECT
            pot.*,
            bp.part_name,
            bp.part_no,
            bp.unit,
            ar.resource_name,
            bw."name"  workstation_name,
            pmor.routing_no,
            bto."name" operation_name,
            pots.quantity_supply,
            pmo.mo_no,
            pmo.ID     mo_id,
            pmoro.operation_id,
            pmo.outer_color,
            pmo.insulation_color,
            pmps.mps_no,
            pco.customer_order_no
        FROM
            production_operation_task pot
                LEFT JOIN basic_part bp ON pot.part_id = bp."id"
                LEFT JOIN aps_resource ar ON ar."id" = pot.resource_id
                LEFT JOIN basic_workstation bw ON bw."id" = pot.workstation_id
                LEFT JOIN plan_manufacturing_order_routing_operation pmoro ON pmoro.ID = pot.mo_routing_operation_id
                LEFT JOIN plan_manufacturing_order_routing pmor ON pmoro.mo_routing_id = pmor."id"
                LEFT JOIN technology_operation bto ON bto.ID = pmoro.operation_id
                LEFT JOIN production_operation_task_supply pots ON pots.operation_task_id = pot."id"
                LEFT JOIN plan_manufacturing_order pmo ON pmo."id" = pots.mo_id
                LEFT JOIN plan_master_production_schedule pmps ON pmps."id" = pmo.mps_id
                LEFT JOIN plan_join_model_customer pjmc
                          ON pjmc.model_id = pmps."id" AND pjmc.model = 'plan_master_production_schedule'
                LEFT JOIN plan_customer_order pco ON pco."id" = pjmc.customer_order_id
        WHERE pot."id" = #{id}
    </select>
 
    <update id="updateNextPriority">
        update
        production_operation_task
        set
        priority = (
        COALESCE ( (SELECT MAX ( priority ) FROM production_operation_task), 0 )
        ) + 1
        where
        id = #{id}
    </update>
 
    <update id="removeActualFinishDateById">
        update
        production_operation_task
        set actual_finish_date = null
        where
        id = #{id}
    </update>
 
    <select id="getProdOutQtyByBatchNo" resultType="java.math.BigDecimal">
        SELECT COALESCE(SUM(product_qty),0) product_qty FROM production_product_output WHERE out_batch_no = #{batchNo}
    </select>
 
    <select id="getOperationId" resultType="java.lang.Long">
        SELECT pmoro.operation_id FROM
        (SELECT * FROM production_product_output WHERE out_batch_no = #{batchNo}) ppo
        INNER JOIN
        production_product_main ppm ON ppo.product_main_id = ppm."id"
        INNER JOIN
        production_operation_task pot ON ppm.operation_task_id = pot."id"
        INNER JOIN
        plan_manufacturing_order_routing_operation pmoro ON pot.mo_routing_operation_id = pmoro."id"
    </select>
 
    <select id="getTaskMoNo" resultType="java.lang.String">
        select pmo.mo_no
        from production_operation_task pot
                 left join production_operation_task_supply pots on pots.operation_task_id = pot.id
                 left join plan_manufacturing_order pmo on pmo.id = pots.mo_id
        where pot.id = #{id};
    </select>
 
    <select id="getAllTaskStateByTaskId" resultType="java.lang.String">
        SELECT
            pot.state
        FROM production_operation_task pot
                 LEFT JOIN production_operation_task_supply pots on pots.operation_task_id = pot.id
        WHERE pots.mo_id = (SELECT mo_id
                            FROM production_operation_task_supply
                            WHERE operation_task_id = #{id})
    </select>
 
    <select id="validateIsLastOperation" resultType="java.lang.Boolean">
        SELECT
            pmoro.is_last
        FROM (SELECT * FROM production_operation_task WHERE id = #{id}) pot
                 INNER JOIN production_operation_task_supply pots ON pot."id" = pots.operation_task_id
                 INNER JOIN plan_manufacturing_order_routing_operation pmoro
                            ON pots.mo_id = pmoro.mo_id AND
                               pot.routing_operation_id = pmoro.technology_routing_operation_id;
    </select>
 
    <select id="getFirstOperationId" resultType="java.lang.Long">
        SELECT pmoro.operation_id
        FROM plan_manufacturing_order_routing_operation pmoro
                 LEFT JOIN production_operation_task_supply pots on pmoro.mo_id = pots.mo_id
                 LEFT JOIN production_operation_task pot
                           on pot.id = pots.operation_task_id
        WHERE pot.id = #{operationTaskId}
        ORDER BY pmoro.operation_order ASC
        limit 1
    </select>
 
    <select id="getOperationIdByTaskId" resultType="java.lang.Long">
        SELECT pmoro.operation_id
        FROM plan_manufacturing_order_routing_operation pmoro
                 left join production_operation_task pot on pmoro.id = pot.mo_routing_operation_id
        WHERE pot.id = #{operationTaskId}
    </select>
 
    <resultMap id="OperationTaskScreenVoMap" type="com.chinaztt.mes.production.vo.OperationTaskScreenVO">
        <result property="workCenter" column="work_center"></result>
        <result property="workstationName" column="workstation_name"></result>
        <result property="operationName" column="operation_name"></result>
        <result property="id" column="id"></result>
        <result property="optaskNo" column="optask_no"></result>
        <result property="state" column="state"></result>
        <result property="plannedStartDate" column="planned_start_date"></result>
        <result property="plannedFinishDate" column="planned_finish_date"></result>
        <result property="actualStartDate" column="actual_start_date"></result>
        <result property="actualFinishDate" column="actual_finish_date"></result>
        <result property="partNo" column="part_no"></result>
        <result property="partName" column="part_name"></result>
        <result property="unit" column="unit"></result>
        <result property="moNo" column="mo_no"></result>
        <result property="mpsNo" column="mps_no"></result>
        <result property="customerName" column="customer_name"></result>
        <result property="customerOrderNo" column="customer_order_no"></result>
        <result property="ratio" column="ratio"></result>
        <result property="plannedQuantity" column="planned_quantity"></result>
        <result property="completedQuantity" column="completed_quantity"></result>
    </resultMap>
 
    <select id="getByCustomerOrderId" resultMap="OperationTaskScreenVoMap">
        SELECT
            pot.work_center,
            bw."name"                                                        workstation_name,
            too."name"                                                       operation_name,
            pot."id",
            pot.optask_no,
            pot."state",
            pot.planned_start_date,
            pot.planned_finish_date,
            pot.actual_start_date,
            pot.actual_finish_date,
            bp.part_name,
            bp.part_no,
            bp.unit,
            pmo.mo_no,
            pmps.mps_no,
            pco.customer_name,
            pco.customer_order_no,
            pot.completed_quantity                                           completed_quantity,
            pot.planned_quantity                                             planned_quantity,
            round(pot.completed_quantity / pot.planned_quantity * 100, 2) AS ratio
        FROM
            production_operation_task pot
                LEFT JOIN basic_part bp ON pot.part_id = bp."id"
                LEFT JOIN plan_manufacturing_order_routing_operation ro ON ro.ID = pot.mo_routing_operation_id
                LEFT JOIN technology_operation too ON too.ID = ro.operation_id
                LEFT JOIN production_operation_task_supply pots ON pots.operation_task_id = pot."id"
                LEFT JOIN plan_manufacturing_order pmo ON pmo."id" = pots.mo_id
                LEFT JOIN plan_master_production_schedule pmps ON pmps."id" = pmo.mps_id
                LEFT JOIN plan_join_model_customer pjmc ON pjmc.model_id = pmps."id"
                AND pjmc.model = 'plan_master_production_schedule'
                LEFT JOIN plan_customer_order pco ON pco."id" = pjmc.customer_order_id
                LEFT JOIN basic_workstation bw ON pot.workstation_id = bw.ID
        <if test="customerOrderId != null">
            WHERE pco."id" = #{customerOrderId}
        </if>
        ORDER BY pmo.schedule_theory_quantity_id ASC
    </select>
</mapper>