chenlu
2024-06-07 2f640b1038fa331954f78ed1f4317212cf5bb34d
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
<?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.FlowCardMapper">
    <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>
    <!--    流程卡管理查询-->
    <select id="selectFlowCard" resultMap="flowCardMap">
        select
        a.order_Id,
        a.process_Id,
        c.product_id,
        c.product_name,
        b.project,
        sum(a.quantity) as quantity,
        sum(c.compute_gross_area) as compute_gross_area,
        a.founder,
        c.processing_note,
        if(a.layout_status=0,'不可排版',if(a.layout_status=1,'可排版','已排版')) as layout_status
        from (select  id,order_id,process_id,order_number, quantity,founder,layout_status,create_time from flow_card group by process_Id,order_number) as a left join sd.`order` as b on a.order_Id=b.order_id
        left join sd.order_detail as c on a.order_Id=c.order_id and a.order_Number=c.order_number
        where a.create_time between #{selectTime1} and #{selectTime2}
        <if test="flowCard.orderId != null and flowCard.orderId != ''">
            and a.order_id regexp #{flowCard.orderId}
        </if>
        <if test="flowCard.processId != null and flowCard.processId != ''">
            and a.process_Id regexp #{flowCard.processId}
        </if>
        <if test="flowCard.orderDetail.productId != null and flowCard.orderDetail.productId != ''">
            and c.product_id regexp #{flowCard.orderDetail.productId}
        </if>
        <if test="flowCard.orderDetail.productName != null and flowCard.orderDetail.productName!= ''">
            and c.product_name regexp #{flowCard.orderDetail.productName}
        </if>
 
        <if test="flowCard.order.project != null and flowCard.order.project!= ''">
            and b.project regexp #{flowCard.order.project}
        </if>
        <if test="flowCard.layoutStatus != null and flowCard.layoutStatus != '' and  flowCard.layoutStatus == '不可排版'">
            and a.layout_status regexp 0
        </if>
        <if test="flowCard.layoutStatus != null and flowCard.layoutStatus != '' and  flowCard.layoutStatus == '可排版'">
            and a.layout_status regexp 1
        </if>
        <if test="flowCard.layoutStatus != null and flowCard.layoutStatus != '' and  flowCard.layoutStatus == '已排版'">
            and a.layout_status regexp 2
        </if>
 
        group by a.process_Id
        ORDER BY a.id desc
        limit #{offset},#{pageSize};
    </select>
 
 
    <select id="getPageTotal">
        select
        CEILING(count(a.process_Id)/#{pageSize}) as 'pageTotal',
        count(distinct a.process_Id) as 'total'
        from flow_card as a left join sd.`order` as b on a.order_Id=b.order_id
        left join sd.order_detail as c on a.order_Id=c.order_id and a.order_Number=c.order_number
        where a.create_time between #{selectTime1} and #{selectTime2}
        <if test="flowCard.orderId != null and flowCard.orderId != ''">
            and a.order_id regexp #{flowCard.orderId}
        </if>
        <if test="flowCard.processId != null and flowCard.processId != ''">
            and a.process_Id regexp #{flowCard.processId}
        </if>
        <if test="flowCard.orderDetail.productId != null and flowCard.orderDetail.productId != ''">
            and c.product_id regexp #{flowCard.orderDetail.productId}
        </if>
        <if test="flowCard.orderDetail.productName != null and flowCard.orderDetail.productName!= ''">
            and c.product_name regexp #{flowCard.orderDetail.productName}
        </if>
 
        <if test="flowCard.order.project != null and flowCard.order.project!= ''">
            and b.project regexp #{flowCard.order.project}
        </if>
        <if test="flowCard.layoutStatus != null and flowCard.layoutStatus != '' and  flowCard.layoutStatus == '不可排版'">
            and a.layout_status regexp 0
        </if>
        <if test="flowCard.layoutStatus != null and flowCard.layoutStatus != '' and  flowCard.layoutStatus == '可排版'">
            and a.layout_status regexp 1
        </if>
        <if test="flowCard.layoutStatus != null and flowCard.layoutStatus != '' and  flowCard.layoutStatus == '已排版'">
            and a.layout_status regexp 2
        </if>
 
        ORDER BY a.id desc
        limit #{offset},#{pageSize};
    </select>
 
    <!--分架查询-->
    <select id="selectFlowCardMp" resultMap="flowCardMap">
        select o.order_id,
        o.customer_name,
        o.project,
        o.batch,
        o.other_remarks,
        o.icon,
        o.order_type,
        o.salesman,
        o.processing_note,
        o.delivery_address
        from sd.`order` as o
        left join sd.order_glass_detail ogd on o.order_id = ogd.order_id
        where o.production_order=2 and ogd.splitting_status=0 and o.create_time between #{selectTime1} and
        #{selectTime2}
 
        <if test="flowCard.order.orderId != null and flowCard.order.orderId != ''">
            and o.order_id regexp #{flowCard.order.orderId}
        </if>
        <if test="flowCard.order.customerName != null and flowCard.order.customerName != ''">
            and o.customer_name regexp #{flowCard.order.customerName}
        </if>
        <if test="flowCard.order.project != null and flowCard.order.project != ''">
            and o.project regexp #{flowCard.order.project}
        </if>
        <if test="flowCard.order.batch != null and flowCard.order.batch!= ''">
            and o.batch regexp #{flowCard.order.batch}
        </if>
 
        <if test="flowCard.order.otherRemarks != null and flowCard.order.otherRemarks!= ''">
            and o.other_remarks regexp #{flowCard.order.otherRemarks}
        </if>
 
        <if test="flowCard.order.icon != null and flowCard.order.icon!= ''">
            and o.icon regexp #{flowCard.order.icon}
        </if>
        <if test="flowCard.order.orderType != null and flowCard.order.orderType!= ''">
            and o.order_type regexp #{flowCard.order.orderType}
        </if>
        <if test="flowCard.order.salesman != null and flowCard.order.salesman!= ''">
            and o.salesman regexp #{flowCard.order.salesman}
        </if>
        group by o.order_id
        order by o.id desc
 
        ;
    </select>
 
    <!--    分架明细查询-->
    <select id="detailsSelectMp">
        select od.order_id,
        ogd.production_id,
        od.product_id,
        od.product_name,
        SUM( od.quantity) as quantity,
        SUM(od.compute_gross_area) as compute_gross_area,
        round(sum(od.perimeter),2) as perimeter
        from sd.order_detail as od left join
        (select order_id,order_number,production_id,splitting_status from sd.order_glass_detail
        GROUP BY order_id,order_number
        ) as ogd on od.order_id=ogd.order_id and od.order_number=ogd.order_number
        where od.order_id = #{orderId} and ogd.splitting_status=0
 
        group by od.order_id, ogd.production_id
        order by od.id desc
    </select>
 
    <!--    更新分架状态-->
    <update id="updateDeleteState">
        update
            sd.order_glass_detail as ogd left join flow_card as fc
                on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number
        set ogd.splitting_status=0
        where ogd.order_id = #{orderId}
          and ogd.production_id = left(#{processId},11)
 
    </update>
 
    <!--    删除流程卡-->
    <update id="deleteFlowCardMp">
        delete
        from flow_card as fc
        where fc.production_id = left(#{processId},11)
    </update>
 
    <!--    分架新增明细查询-->
 
    <!--resultMap="flowCardMap"-->
    <select id="selectNoCardMp">
 
        select od.order_number,
               od.order_number       AS 'orderNumber',
               od.width,
               od.height,
               od.shape,
               od.quantity,
               od.compute_gross_area,
               p.total_thickness,
               od.quantity           as baiscQuantity,
               od.compute_gross_area as 'computeGrossArea',
               p.total_thickness     AS 'totalThickness',
               p.thickness,
               od.weight
        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 sd.product as p on od.product_name = p.product_name
        where od.order_id = #{orderId}
          and ogd.production_id = #{productionId}
          and ogd.splitting_status = 0
        GROUP BY od.order_number
        order by od.id
 
    </select>
 
    <!--修改排版状态-->
    <update id="updateLayoutStatusMp">
        update flow_card as fc
        set fc.layout_status=#{state}
        where fc.process_id = #{processId}
    </update>
 
    <!--    查询对应流程卡号排版状态-->
    <select id="selectLayoutStatus">
        select fc.layout_status
        from flow_card as fc
        where fc.process_id = #{processId}
        LIMIT 1
    </select>
 
    <!--    查询报工表内是否有对应流程卡-->
    <select id="reportingWorkCount">
        select COUNT(rw.process_id)
        from reporting_work as rw
        where rw.process_id = #{processId}
    </select>
    <!--    插入Flow_card表-->
    <insert id="addFlowCardMp">
        insert into flow_card (order_id,
                               production_id,
                               process_id,
                               landing_sequence,
                               order_number,
                               technology_number,
                               quantity,
                               founder,
                               layers_number,
                               splitFrame_time,
                               create_time)
        select ogd.order_id,
               ogd.production_id,
               #{processId},
               #{landingSequence},
               ogd.order_number,
               ogd.technology_number,
               #{quantity},
               #{userName},
               #{layer},
               NOW(),
               NOW()
 
 
        from sd.order_glass_detail as ogd
        where ogd.production_id = #{productionId}
          and ogd.order_number = #{orderNumber}
        GROUP BY ogd.technology_number
    </insert>
 
    <!--    更新分架状态-->
    <update id="updateFlowState">
        update sd.order_glass_detail as ogd
        set ogd.splitting_status=1
        where ogd.production_id = #{productionId}
          and ogd.order_number = #{orderNumber}
    </update>
    <!--    查询未分架的条数-->
    <select id="selectFlowCount">
        select COUNT(*)
        from sd.order_glass_detail as ogd
        where ogd.order_id = left(#{productionId}, 10)
          and ogd.splitting_status = 0
    </select>
    <!--   修改订单表分架状态-->
    <update id="updateProcessingCard">
        update sd.`order` as o
        set o.processing_card=#{state}
        where o.order_id = left(#{productionId}, 10)
    </update>
 
    <!--    查询已排版数据-->
    <select id="selectOkSchedulingMp">
        select od.order_id,
               o.customer_name,
               o.project,
               od.order_number,
               od.width,
               od.height,
               od.quantity,
               round(od.width * od.height * od.quantity / 1000000, 2),
               (od.quantity - IFNULL(ps.scheduling_quantity, 0)),
               round(od.width * od.height * (od.quantity - IFNULL(ps.scheduling_quantity, 0)) / 1000000, 2),
               IFNULL(ps.scheduling_quantity, 0),
               round(od.width * od.height * (IFNULL(ps.scheduling_quantity, 0)) / 1000000, 2),
               od.product_name,
               od.shape
        from sd.order_detail as od
                 left join sd.order as o on od.order_id = o.order_id
                 left join production_scheduling as ps
                           on ps.order_id = od.order_id and ps.order_number = od.order_number
        where od.order_id = #{orderId}
          and ps.processes = #{processes}
          and ps.scheduling_id IS NOT NULL
        order by ps.id desc
    </select>
    <!--    查询未排版数据-->
    <select id="selectNoSchedulingMp">
 
    </select>
    <!--    首次查询排版数据-->
    <select id="selectLastSchedulingMp">
        select od.order_id,
               o.customer_name,
               o.project,
               od.order_number,
               od.width,
               od.height,
               od.quantity,
               round(od.width * od.height * od.quantity / 1000000, 2)                                       as area,
               (od.quantity - IFNULL(ps.scheduling_quantity, 0))                                            as pendingProductionQuantity,
               round(od.width * od.height * (od.quantity - IFNULL(ps.scheduling_quantity, 0)) / 1000000,
                     2)                                                                                     as pendingProductionArea,
               IFNULL(ps.scheduling_quantity, 0)                                                            as productionScheduledQuantity,
               round(od.width * od.height * (IFNULL(ps.scheduling_quantity, 0)) / 1000000,
                     2)                                                                                     as productionScheduledArea,
               od.product_name,
               od.shape
        from sd.order_detail as od
                 left join sd.order as o on od.order_id = o.order_id
                 left join production_scheduling as ps
                           on ps.order_id = od.order_id and ps.order_number = od.order_number
        where od.create_time between #{selectTime1} and #{selectTime2}
    </select>
 
    <!--   查询对应序号的层数-->
    <select id="selectLayer">
        select COUNT(ogd.order_number)
        from sd.order_glass_detail as ogd
        where ogd.production_id = #{productionId}
          and ogd.order_number = #{orderNumber}
    </select>
    <!--  查询该订单流程卡条数  -->
    <select id="selectFlowCardCount">
        select COUNT(*)
        from flow_card
        where order_id = #{orderId}
    </select>
 
    <select id="flowCardDetailMp">
        select fc.order_id,
               fc.process_id,
               fc.order_number,
               fc.technology_number,
               fc.quantity,
               ogd.child_width,
               ogd.child_height,
               round(ogd.child_width * ogd.child_height * fc.quantity / 1000000, 2) as area,
               od.product_name,
               ogd.glass_child,
               fc.founder,
               date(fc.splitFrame_time) as splitFrame_time
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = ogd.order_id and od.order_number = ogd.order_number
        where fc.process_id = #{processId}
        GROUP BY fc.order_id, fc.process_id, fc.order_number,fc.technology_number
        order by fc.order_number,fc.technology_number
    </select>
 
    <delete id="deleteReportingWork">
        delete from sd.order_process_detail
        where  left(process_id,11) = left(#{processId},11)
    </delete>
 
    <select id="selectPrintFlowCardMp">
        select * from  sd.order where create_time between #{selectTime1} and #{selectTime2} and
                                      position(#{orderId} in order_id ) and position(#{project} in project)
        and processing_card=2
        order by create_time desc
    </select>
 
    <select id="selectPrintMp">
        select fc.id,
               fc.order_id,
               fc.process_id,
               o.customer_name,
               o.project,
               ogd.technology_number,
               ogd.glass_address,
               sum(od.quantity) as quantity,
               sum(ogd.total_area) as total_area,
               od.product_name,
               ogd.glass_child,
               fc.founder,
               date(fc.splitFrame_time) as splitFrame_time
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                              ogd.technology_number = fc.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
        where fc.order_id = #{orderId}
        GROUP BY fc.process_id, ogd.technology_number
        order by fc.process_id, ogd.technology_number
 
    </select>
 
    <select id="getPrimaryList">
        select o.customer_name,
               o.project,
               ogd.process,
               od.edging_type,
               ogd.glass_child,
               od.product_name,
               o.processing_note,
               fc.process_id,
               SUM( od.quantity) as quantity,
               SUM(ogd.total_area) as gross_area,
               SUM(od.weight) as weight,
               #{technologyNumber} as technologyNumber,
               concat(fc.process_id,'/',#{technologyNumber}) as  processIdNumber
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
        where fc.process_id = #{processId}
          and fc.technology_number = #{technologyNumber}
        group by fc.process_id, fc.technology_number
    </select>
 
    <select id="getDetailList">
        select fc.order_number,
               concat(ogd.child_width, "*", ogd.child_height) as child_width,
               od.quantity,
               round(ogd.total_area,2) as total_area,
               od.perimeter,
               od.bend_radius,
               od.remarks
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
        where fc.process_id = #{processId}
          and fc.technology_number = #{technologyNumber}
        group by fc.process_id, fc.order_number
        order by fc.order_number
    </select>
 
    <select id="getProcessList">
        select *
        from sd.order_process_detail
        where process_id = #{processId}
          and technology_number = #{technologyNumber}
        group by process
    </select>
 
    <update id="updateInventory">
        update flow_card set inventory_quantity=#{completedQuantity}
        where process_id = #{processId} and  order_number = #{orderNumber} and technology_number = #{technologyNumber}
    </update>
 
<!--    复选框修改排版状态-->
    <update id="updateComposing">
        update flow_card as fc
        set fc.layout_status=1
        where fc.process_id = #{processId}
    </update>
 
    <select id="getPrintLabel">
        select c.customer_name,
               c.order_id,
               e.type_name,
               b.remarks,
               c.project,
                a.child_width,
               a.child_height,
               sum(b.quantity) as quantity,
               a.glass_child,
               b.processing_note
        from sd.order_glass_detail as a
                 left join sd.order_detail as b
                           on a.order_id = b.order_id
                               and a.order_number = b.order_number
                 left join sd.`order` as c
                           on c.order_id = a.order_id
                 left join flow_card as d
                           on d.order_id = a.order_id and d.order_number = a.order_number and
                              d.technology_number = a.technology_number
                 left join sd.basic_glass_type e
                           on e.type_id = b.product_id
        where d.process_id = #{processId}
          and d.technology_number = #{technologyNumber}
        group by a.glass_child, a.child_width, a.child_height
        order by d.technology_number
    </select>
</mapper>