邱宇豪
2023-11-03 2896d6fa447cf6a678ba27ba2e19224379f14dd4
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
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
<?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.thhy.mobile.modules.biz.pipeinfo.mapper.PipeInfoMapper">
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        t.pipe_id as pipeId,
        t.block_num as blockNum,
        t.check_result as checkResult,
        t.check_time as checkTime,
        t.grouting_holes as groutingHoles,
        t.into_mod_time as intoModTime,
        t.into_mod_user as intoModUser,
        t.mod_id as modId,
        t.pipe_num as pipeNum,
        t.pouring_time as pouringTime,
        t.pro_id as proId,
        t.reinforcement as reinforcement,
        t.ring_num as ringNum,
        t.turn as turn,
        t.go_in as goIn,
        t.size,
        t.in_repo_time as inRepoTime,
        t.out_repo_time as outRepoTime,
        t.produce_number as produceNumber,
        t.out_mod as outMod
    </sql>
 
    <sql id="condition_query">
        <where>
            <trim suffixOverrides=" AND ">
                <if test="blockNum!=null and blockNum!=''">
                    t.block_num = #{blockNum} AND
                </if>
                <if test="checkResult!=null">
                    t.check_result = #{checkResult} AND
                </if>
                <if test="checkTime!=null">
                    t.check_time = #{checkTime} AND
                </if>
                <if test="groutingHoles!=null and groutingHoles!=''">
                    t.grouting_holes = #{groutingHoles} AND
                </if>
                <if test="intoModTime!=null">
                    t.into_mod_time = #{intoModTime} AND
                </if>
                <if test="intoModUser!=null and intoModUser!=''">
                    t.into_mod_user = #{intoModUser} AND
                </if>
                <if test="modId!=null and modId!=''">
                    t.mod_id = #{modId} AND
                </if>
                <if test="pipeNum!=null and pipeNum!=''">
                    t.pipe_num = #{pipeNum} AND
                </if>
                <if test="pouringTime!=null">
                    t.pouring_time = #{pouringTime} AND
                </if>
                <if test="proId!=null and proId!=''">
                    t.pro_id = #{proId} AND
                </if>
                <if test="reinforcement!=null and reinforcement!=''">
                    t.reinforcement = #{reinforcement} AND
                </if>
                <if test="ringNum!=null and ringNum!=''">
                    t.ring_num = #{ringNum} AND
                </if>
                <if test="turn!=null and turn!=''">
                    t.turn = #{turn} AND
                </if>
            </trim>
        </where>
    </sql>
 
    <select id="queryById" resultType="com.thhy.mobile.modules.biz.pipeinfo.entity.PipeInfo">
        select <include refid="Base_Column_List" />
        from t_pipe_info t
        where t.pipe_id=#{pipeId}
    </select>
 
    <select id="queryByPipeNum" resultType="com.thhy.mobile.modules.biz.pipeinfo.entity.PipeInfo">
        select <include refid="Base_Column_List" />
        from t_pipe_info t
        where t.pipe_num=#{pipeNum}
    </select>
 
    <select id="countByPipeInfo" resultType="int">
        select count(pipe_id) from t_pipe_info where pro_id = #{proId}
    </select>
 
    <select id="queryMaxPipeNumByProId" resultType="int">
        select case when b.maxNum is null then 0 else b.maxNum end as maxNum from
            (select max(a.num) as maxNum from (
              select CONVERT(SUBSTR(pipe_num from LENGTH(pipe_num)-4 for LENGTH(pipe_num)),SIGNED) as num from t_pipe_info where pro_id = #{proId}
          ) a ) b
    </select>
 
    <select id="queryVersionById" resultType="integer">
        select version from t_pipe_info
        where pipe_id=#{pipeId}
    </select>
 
    <!--查询列表-->
    <select id="findList" resultType="com.thhy.mobile.modules.biz.pipeinfo.entity.PipeInfo">
        SELECT
        <include refid="Base_Column_List" />
        from t_pipe_info t
        <include refid="condition_query" />
    </select>
 
    <select id="screenFindList" resultType="com.thhy.mobile.modules.biz.pipeinfo.entity.PipeInfo">
        SELECT
        <include refid="Base_Column_List" />
        from t_pipe_info t
        <include refid="condition_query" />
        order by t.into_mod_time desc limit 1
    </select>
 
     <select id="pipelist" resultType="com.thhy.mobile.modules.biz.pipeinfo.entity.PipeListVo">
         select a.* from (select tpi.pipe_id as pipeId,tpi.ring_num as ringNum,tpi.pipe_num as pipeNum,sd1.dict_name as
         turnName,sd2.dict_name as reinforcementName,
         sd3.dict_name as groutingHolesName,sd4.dict_name as blockNumName,sd5.dict_name as sizeName,sm.mould_num as mouldNum,
         tpi.into_mod_time as intoModTime,    su.real_name AS intoModUser,
         tpi.pouring_time as pouringTime,tpi.check_time as checkTime,su1.real_name AS checkName,
         sp.pro_name as proName,tpi.check_result as checkResult,
         (select GROUP_CONCAT(sg.group_name) from sys_group_user sgu left join sys_group sg on sg.group_id =
         sgu.group_id
         where sgu.user_id = spu.user_id group by sgu.user_id) as groupName,
         (select GROUP_CONCAT(sg.group_id) from sys_group_user sgu left join sys_group sg on sg.group_id = sgu.group_id
         where sgu.user_id = spu.user_id group by sgu.user_id) as groupIds
         from t_pipe_info tpi
         left join sys_dict sd1 on sd1.dict_id = tpi.turn
         left join sys_dict sd2 on sd2.dict_id = tpi.reinforcement
         left join sys_dict sd3 on sd3.dict_id = tpi.grouting_holes
         left join sys_dict sd4 on sd4.dict_id = tpi.block_num
         left join sys_dict sd5 on sd5.dict_id = tpi.size
         left join sys_mould sm on sm.mould_id = tpi.mod_id
         left join sys_project sp on sp.pro_id = tpi.pro_id
         left join sys_users su on su.user_id = tpi.into_mod_user
         LEFT JOIN sys_users su1 ON su1.user_id = tpi.check_user
         left join sys_plat_user spu on spu.user_id = su.plat_id
         <where>
             <trim suffixOverrides=" AND ">
 
                 <if test="companyId!=null and companyId!=''">
                     sp.company_id = #{companyId} AND
                 </if>
                 <if test="ringNum!=null and ringNum!=''">
                    tpi.ring_num LIKE concat('%',#{ringNum},'%') AND
                 </if>
                 <if test="checkResult!=null">
                    tpi.check_result = #{checkResult} AND
                 </if>
                 <if test="proId!=null and proId!=''">
                    tpi.pro_id = #{proId} AND
                 </if>
                <if test="reinforcement !=null and reinforcement !=''">
                    tpi.reinforcement = #{reinforcement} AND
                </if>
 
                <if test="groutingHoles !=null and groutingHoles !=''">
                    tpi.grouting_holes = #{groutingHoles} AND
                </if>
 
                <if test="blockNum!=null and blockNum!=''">
                    tpi.block_num = #{blockNum} AND
                </if>
 
                <if test="inModStartTime!=null">
                    tpi.into_mod_time &gt;= #{inModStartTime} AND
                </if>
 
                <if test="inModEndTime!=null">
                    tpi.into_mod_time &lt;= #{inModEndTime} AND
                </if>
 
                <if test="pouringStartTime!=null">
                    tpi.pouring_time &gt; #{pouringStartTime} AND
                </if>
 
                <if test="pouringEndTime!=null">
                    tpi.pouring_time &lt; #{pouringEndTime} AND
                </if>
 
                <if test="checkStartTime!=null">
                    tpi.check_time &gt; #{checkStartTime} AND
                </if>
 
                <if test="checkEndTime!=null">
                    tpi.check_time &lt; #{checkEndTime} AND
                </if>
                 <if test="num!=null">
                     tpi.pipe_num = #{num} AND
                 </if>
                 <if test="segmentId!=null">
                     tpi.segment_id = #{segmentId} AND
                 </if>
                 <if test="yearMonth!=null">
                     tpi.out_mod_time like CONCAT(#{yearMonth},'%') AND
                 </if>
                 <if test="goIn!=null">
                     tpi.go_in = 2 AND
                 </if>
             </trim>
         </where>
         order by tpi.check_time desc
         ) a
         <if test="groupId != null and groupId !=''">
             where #{groupId} in (a.groupIds)
         </if>
    </select>
     <select id="pipeThingJsInfo" resultType="com.thhy.mobile.modules.biz.pipeinfo.entity.PipeListVo">
         select a.* from (select tpi.pipe_id as pipeId,tpi.ring_num as ringNum,tpi.pipe_num as pipeNum,sd1.dict_name as
         turnName,sd2.dict_name as reinforcementName,tpi.mod_id AS modId,
         tpi.produce_number AS produceNumber,
         sd3.dict_name as groutingHolesName,sd4.dict_name as blockNumName,sd5.dict_name as sizeName,sm.mould_num as mouldNum,
         tpi.into_mod_time as intoModTime,    su.real_name AS intoModUser,
         tpi.pouring_time as pouringTime,tpi.check_time as checkTime,su1.real_name AS checkName,
         sp.pro_name as proName,tpi.check_result as checkResult,
         (select GROUP_CONCAT(sg.group_name) from sys_group_user sgu left join sys_group sg on sg.group_id =
         sgu.group_id
         where sgu.user_id = spu.user_id group by sgu.user_id) as groupName,
         (select GROUP_CONCAT(sg.group_id) from sys_group_user sgu left join sys_group sg on sg.group_id = sgu.group_id
         where sgu.user_id = spu.user_id group by sgu.user_id) as groupIds
         from t_pipe_info tpi
         left join sys_dict sd1 on sd1.dict_id = tpi.turn
         left join sys_dict sd2 on sd2.dict_id = tpi.reinforcement
         left join sys_dict sd3 on sd3.dict_id = tpi.grouting_holes
         left join sys_dict sd4 on sd4.dict_id = tpi.block_num
         left join sys_dict sd5 on sd5.dict_id = tpi.size
         left join sys_mould sm on sm.mould_id = tpi.mod_id
         left join sys_project sp on sp.pro_id = tpi.pro_id
         left join sys_users su on su.user_id = tpi.into_mod_user
         LEFT JOIN sys_users su1 ON su1.user_id = tpi.check_user
         left join sys_plat_user spu on spu.user_id = su.plat_id
         <where>
             <trim suffixOverrides=" AND ">
                   tpi.check_result != 0 AND
                 <if test="companyId!=null and companyId!=''">
                     sp.company_id = #{companyId} AND
                 </if>
            </trim>
        </where>
         order by tpi.into_mod_time desc limit 0,1
         ) a
    </select>
 
    <select id="queryPipeInfoByPipeId" resultType="com.thhy.mobile.modules.biz.pipeinfo.entity.PipeInfoVo">
        select tsp.produce_number as produceNumber,sp.pro_name as proName,su1.real_name as createUserName,su2.real_name as steelCheckUserName,tsp.quality_time as steelCheckTime,tsp.is_qualified as steelCheckResult,tsp.print_time as printTime,
 
               sm.mould_num as mouldNum,sm.current_cycle_time as currentCycleTime,sm.max_cycle_time as maxCycleTime,sm.mould_code as mouldCode,
 
               tpi.ring_num as ringNum,tpi.pipe_num as pipeNum,tpi.into_mod_time as intoModTime,
               tpi.check_user as checkUser,su.real_name as pipeCheckUserName,tpi.check_time as pipeCheckTime,
               sd1.dict_name as turnName,
               sd2.dict_name as reinforcementName,
               sd3.dict_name as groutingHolesName,
               sd4.dict_name as blockNumName,
               sd5.dict_name as sizeName,
               sd6.dict_name as mouldTypeName
 
        from t_pipe_info tpi
                 left join sys_dict sd1 on sd1.dict_id = tpi.turn
                 left join sys_dict sd2 on sd2.dict_id = tpi.reinforcement
                 left join sys_dict sd3 on sd3.dict_id = tpi.grouting_holes
                 left join sys_dict sd4 on sd4.dict_id = tpi.block_num
                 left join sys_dict sd5 on sd5.dict_id = tpi.size
                 left join sys_mould sm on sm.mould_id = tpi.mod_id
                 left join sys_dict sd6 on sd6.dict_id = sm.mould_type
                 left join t_steel_produce tsp on tsp.produce_number = tpi.produce_number
                 left join sys_project sp on sp.pro_id = tpi.pro_id
                 left join sys_users su on su.user_id = tpi.check_user
                 left join sys_users su1 on su1.user_id = tsp.create_user
                 left join sys_users su2 on su2.user_id = tsp.quality_user
        where 1=1
        <if test="pipeId != null">
           and tpi.pipe_id = #{pipeId}
        </if>
        <if test="num != null">
            and tpi.pipe_num = #{num}
        </if>
    </select>
 
    <select id="queryByRingNum" resultType="com.thhy.mobile.modules.biz.cultivated.entity.PipeIntoListVo">
        select t.ring_num as ringNum,t.pipe_num as pipeNum,t.check_time as checkTime,sd.dict_name as blockNum
            from t_pipe_info t
            left join sys_dict sd on sd.dict_id = t.block_num
        where t.ring_num = #{ringNum}
    </select>
 
    <!--查询列表-->
    <select id="findAll" resultType="com.thhy.mobile.modules.biz.pipeinfo.entity.PipeInfo">
        SELECT
        <include refid="Base_Column_List" />
        from t_pipe_info t
    </select>
 
    <!--插入操作-->
    <insert id="insert">
        insert into t_pipe_info
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="blockNum != null">
                block_num,
            </if>
            <if test="checkResult != null">
                check_result,
            </if>
            <if test="checkTime != null">
                check_time,
            </if>
            <if test="groutingHoles != null">
                grouting_holes,
            </if>
            <if test="intoModTime != null">
                into_mod_time,
            </if>
            <if test="intoModUser != null">
                into_mod_user,
            </if>
            <if test="modId != null">
                mod_id,
            </if>
            <if test="pipeId != null">
                pipe_id,
            </if>
            <if test="pipeNum != null">
                pipe_num,
            </if>
            <if test="pouringTime != null">
                pouring_time,
            </if>
            <if test="proId != null">
                pro_id,
            </if>
            <if test="reinforcement != null">
                reinforcement,
            </if>
            <if test="ringNum != null">
                ring_num,
            </if>
            <if test="turn != null">
                turn,
            </if>
            <if test="size != null">
                `size`,
            </if>
            <if test="produceNumber != null and produceNumber!=''">
                produce_number,
            </if>
 
            <if test="outMod != null">
                out_mod,
            </if>
            <if test="createFlag != null">
                create_flag,
            </if>
        </trim>
 
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="blockNum != null">
                #{blockNum},
            </if>
            <if test="checkResult != null">
                #{checkResult},
            </if>
            <if test="checkTime != null">
                #{checkTime},
            </if>
            <if test="groutingHoles != null">
                #{groutingHoles},
            </if>
            <if test="intoModTime != null">
                #{intoModTime},
            </if>
            <if test="intoModUser != null">
                #{intoModUser},
            </if>
            <if test="modId != null">
                #{modId},
            </if>
            <if test="pipeId != null">
                #{pipeId},
            </if>
            <if test="pipeNum != null">
                #{pipeNum},
            </if>
            <if test="pouringTime != null">
                #{pouringTime},
            </if>
            <if test="proId != null">
                #{proId},
            </if>
            <if test="reinforcement != null">
                #{reinforcement},
            </if>
            <if test="ringNum != null">
                #{ringNum},
            </if>
            <if test="turn != null">
                #{turn},
            </if>
            <if test="size != null">
                #{size},
            </if>
            <if test="produceNumber != null">
                #{produceNumber},
            </if>
            <if test="outMod != null">
                #{outMod},
            </if>
            <if test="createFlag != null">
                #{createFlag},
            </if>
        </trim>
    </insert>
 
 
    <!--更新操作-->
    <update id="update">
        update t_pipe_info
        <set>
            <if test="blockNum != null">
                block_num=#{blockNum},
            </if>
            <if test="checkResult != null">
                check_result=#{checkResult},
            </if>
            <if test="checkTime != null">
                check_time=#{checkTime},
            </if>
            <if test="groutingHoles != null">
                grouting_holes=#{groutingHoles},
            </if>
            <if test="intoModTime != null">
                into_mod_time=#{intoModTime},
            </if>
            <if test="intoModUser != null">
                into_mod_user=#{intoModUser},
            </if>
            <if test="modId != null">
                mod_id=#{modId},
            </if>
            <if test="pipeNum != null">
                pipe_num=#{pipeNum},
            </if>
            <if test="pouringTime != null">
                pouring_time=#{pouringTime},
            </if>
            <if test="proId != null">
                pro_id=#{proId},
            </if>
            <if test="reinforcement != null">
                reinforcement=#{reinforcement},
            </if>
            <if test="ringNum != null">
                ring_num=#{ringNum},
            </if>
            <if test="turn != null">
                turn=#{turn},
            </if>
        </set>
        where pipe_id=#{pipeId}
    </update>
 
    <!--逻辑删除-->
    <update id="deletelogic">
        update t_pipe_info
        SET is_use = 0
        where pipe_id=#{pipeId}
    </update>
 
    <!--根据ID删除-->
    <delete id="deleteById">
        delete from t_pipe_info
        where pipe_id=#{pipeId}
    </delete>
 
    <select id="queryRingComplete" resultType="com.thhy.mobile.modules.biz.mouldcheck.entity.RingCompleteCheck">
        select * from (SELECT a.ringnum,a.pipecount,(select count(pipe_id) from t_pipe_info where ring_num = a.ringnum and block_num = #{blockNum}) as isExist from
            (select ring_num as ringnum,count(block_num) as pipecount from t_pipe_info
             where create_flag = 1 and pro_id=#{proId}
               and size=#{size} and reinforcement=#{reinforcement} GROUP BY ring_num) a
                      )c where c.isExist = 0 order by c.ringnum limit 1
    </select>
 
    <select id="queryMaxRingNum" resultType="int">
        select case when a.maxRingNum is null then 1 else a.maxRingNum end as maxRingNum
        from
            (
                SELECT ( max(tpi.ring_num + 0 )) AS maxRingNum FROM t_pipe_info tpi left join sys_project sp on sp.pro_id = tpi.pro_id where sp.company_id = #{companyId}
            ) a
    </select>
 
    <update id="updateCheckResult">
        update t_pipe_info set check_result = #{checkResult},check_user = #{checkUser},check_time = sysdate() where pipe_id=#{pipeId}
    </update>
 
    <select id="pipeMonthData" resultType="com.thhy.mobile.modules.biz.steelproduce.entity.ProduceMonthVo">
        select DATE_FORMAT(a.`month`,'%Y-%m') as `month`, case when b.count is NULL then 0 else b.count end as count from
        (SELECT @s := DATE_ADD(@s,INTERVAL 1 MONTH) as `month` FROM mysql.help_topic,(SELECT @s := DATE_ADD(#{startTime},INTERVAL -2 MONTH)) temp WHERE @s &lt; #{endTime}) a
        left join
        (select DATE_FORMAT(tpi.check_time,'%Y-%m') as `month`,count(tpi.pipe_id) as count from t_pipe_info tpi
        left join sys_project sp on sp.pro_id = tpi.pro_id
        where tpi.check_result = 1 and sp.company_id = #{companyId} group by DATE_FORMAT(check_time,'%Y-%m')
        ) b on DATE_FORMAT(a.`month`,'%Y-%m') = b.`month`
    </select>
 
    <select id="pipeCompare" resultType="com.thhy.mobile.modules.biz.steelproduce.entity.ProduceMonthVo">
        select DATE_FORMAT(a.`month`,'%Y-%m') as `month`, case when b.count is NULL then 0 else b.count end as count,c.plan_product as planProduct from
        (SELECT @s := DATE_ADD(@s,INTERVAL 1 MONTH) as `month` FROM mysql.help_topic,(SELECT @s := DATE_ADD(#{startTime},INTERVAL -2 MONTH)) temp WHERE @s &lt; #{endTime}) a
        left join
        (select DATE_FORMAT(tpi.check_time,'%Y-%m') as `month`,count(tpi.pipe_id) as count from t_pipe_info tpi
            left join sys_project sp1 on sp1.pro_id = tpi.pro_id
            where tpi.check_result = 1 and sp1.company_id = #{companyId} group by DATE_FORMAT(tpi.check_time,'%Y-%m')
 
        ) b on DATE_FORMAT(a.`month`,'%Y-%m') = b.`month`
        left join
        (select DATE_FORMAT(DATE(CONCAT(pp.plan_year,'-',ppm.`month`,'-01')),'%Y-%m') as `month`,sum(ppm.plan_product) as plan_product
        from t_pipe_plan_month ppm
        left join t_pipe_plan pp on ppm.pipe_plan_id = pp.plan_id
        left join sys_project sp on sp.pro_id = pp.pro_id
        where sp.company_id = #{companyId} AND (DATE(CONCAT(pp.plan_year,'-',ppm.`month`,'-01')) between #{startTime} and #{endTime}) group by DATE_FORMAT(DATE(CONCAT(pp.plan_year,'-',ppm.`month`,'-01')),'%Y-%m')) c on DATE_FORMAT(a.`month`,'%Y-%m') = c.`month`
    </select>
 
    <select id="pipeCompareByPro" resultType="com.thhy.mobile.modules.biz.steelproduce.entity.ProduceMonthVo">
        select DATE_FORMAT(a.`month`,'%Y-%m') as `month`, case when b.count is NULL then 0 else b.count end as count,
                    case when c.plan_product is NULL then 0 else c.plan_product end as planProduct from
            (SELECT @s := DATE_ADD(@s,INTERVAL 1 MONTH) as `month` FROM mysql.help_topic,(SELECT @s := DATE_ADD(#{startTime},INTERVAL -2 MONTH)) temp WHERE @s &lt; #{endTime}) a
            left join
            (select DATE_FORMAT(tpi.check_time,'%Y-%m') as `month`,count(tpi.pipe_id) as count from t_pipe_info tpi
            left join sys_project sp1 on sp1.pro_id = tpi.pro_id
            where tpi.check_result = 1 and sp1.company_id = #{companyId} and sp1.pro_id = #{proId} group by DATE_FORMAT(tpi.check_time,'%Y-%m')
 
            ) b on DATE_FORMAT(a.`month`,'%Y-%m') = b.`month`
            left join
            (select DATE_FORMAT(DATE(CONCAT(pp.plan_year,'-',ppm.`month`,'-01')),'%Y-%m') as `month`,sum(ppm.plan_product) as plan_product
            from t_pipe_plan_month ppm
            left join t_pipe_plan pp on ppm.pipe_plan_id = pp.plan_id
            left join sys_project sp on sp.pro_id = pp.pro_id
            where sp.company_id = #{companyId} AND sp.pro_id = #{proId} AND (DATE(CONCAT(pp.plan_year,'-',ppm.`month`,'-01')) between #{startTime} and #{endTime}) group by DATE_FORMAT(DATE(CONCAT(pp.plan_year,'-',ppm.`month`,'-01')),'%Y-%m')) c on DATE_FORMAT(a.`month`,'%Y-%m') = c.`month`
    </select>
 
    <select id="checkHistoryList" resultType="com.thhy.mobile.modules.biz.pipeinfo.entity.PipeCheckHistoryListVo">
        select tpi.ring_num as ringNum,sp.pro_name as proName,tpi.pipe_num as pipeNum,sd1.dict_name as turnName,sd2.dict_name as sizeName,sd3.dict_name as blockNumName,
               sd4.dict_name as reinforcementName,sd5.dict_name as groutingHolesName,sm.mould_num as mouldNum,tpi.into_mod_time as intoModTime,
               tpi.check_time as checkTime
        from t_pipe_info tpi
                 left join sys_project sp on sp.pro_id = tpi.pro_id
                 left join sys_mould sm on sm.mould_id = tpi.mod_id
                 left join sys_dict sd1 on sd1.dict_id = tpi.turn
                 left join sys_dict sd2 on sd2.dict_id = tpi.size
                 left join sys_dict sd3 on sd3.dict_id = tpi.block_num
                 left join sys_dict sd4 on sd4.dict_id = tpi.reinforcement
                 left join sys_dict sd5 on sd5.dict_id = tpi.grouting_holes
        <where>
            <trim suffixOverrides=" AND ">
                tpi.ring_num = #{ringNum}
            </trim>
        </where>
    </select>
    
    <delete id="deleteBySteelProNum">
        delete from t_pipe_info where produce_number = #{produceNumber}
    </delete>
 
    <select id="queryIsCheckBySteelNum" resultType="int">
        select check_result from t_pipe_info where produce_number = #{produceNumber}
    </select>
 
    <select id="hisSteelInfo" resultType="com.thhy.mobile.modules.biz.checkhistory.entity.SteelInfoVo">
        select tsp.produce_number as produceNumber,sd2.dict_name as sizeName,sd3.dict_name as blockNumName,
               sd4.dict_name as reinforcementName,tsp.print_time as printTime,tsp.quality_time as qualityTime
        from t_steel_produce tsp
                 left join sys_dict sd2 on sd2.dict_id = tsp.size_id
                 left join sys_dict sd3 on sd3.dict_id = tsp.block_num
                 left join sys_dict sd4 on sd4.dict_id = tsp.reinforcement_id
        where tsp.produce_number = #{produceNumber}
    </select>
 
    <select id="leastMixStation" resultType="com.thhy.mobile.modules.biz.checkhistory.entity.MixStation">
        select sd.dict_name as materialName,mmi.material_value as materialValue
        from t_mix_material_info mmi
                 left join t_mix_material mm on mmi.mix_material_id = mm.id
                 left join sys_dict sd on sd.dict_id = mmi.material_name
        where mm.id = (select id from t_mix_material order by create_time desc limit 1)
    </select>
 
    <select id="queryWaterByRingNum" resultType="com.thhy.mobile.modules.biz.checkhistory.entity.WaterCulInfoVo">
        select wc.water_cultivated_name as waterCultivatedName,tpc.create_time as createTime,case when out_water = 1 then TIMESTAMPDIFF(MINUTE,tpc.create_time,SYSDATE()) else TIMESTAMPDIFF(MINUTE,tpc.create_time,tpc.out_time) end as times,tpc.out_time as outTime
        from t_pipe_cultivated tpc
        left join t_water_cultivated wc on wc.water_cultivated_id = tpc.water_cultivated_id
        where tpc.ring_num = #{ringNum}
    </select>
 
    <update id="updatePipeOutMod">
        update t_pipe_info set out_mod = 2,out_mod_time = sysdate() where pipe_num = #{pipeNum}
    </update>
 
    <update id="updatePipeInRepo">
        update t_pipe_info set go_in = 1,in_repo_time = sysdate() where pipe_num = #{pipeNum}
    </update>
 
    <update id="updateModCheck">
        update t_mould_check set status = 2 where mod_id = #{modId} and match_status = 2 and is_use = 1
    </update>
 
    <update id="updateSysMouldFree">
        update sys_mould set free = #{free} where mould_id = #{modId}
    </update>
 
    <select id="RepoRecordCountByPipeNum" resultType="int">
        select count(id) from t_repo_record_pipe where pipe_num = #{pipeNum}
    </select>
 
 
 
    <select id="RepoRecordByPipeNum" resultType="com.thhy.mobile.modules.biz.checkhistory.entity.RepoInfoVo">
        select r.repo_name as repoName,tru.unit_name as unitName,rrp.create_time as createTime,rrp.out_repo as outRepo,rrp.out_repo_time as outRepoTime
        from t_repo_record_pipe rrp
        left join t_repo_record trr on trr.record_id = rrp.record_id
        left join t_repo r on r.repo_id = trr.repo_id
        left join t_repo_unit tru on trr.repo_unit_id = tru.unit_id
        where rrp.pipe_num = #{pipeNum}
    </select>
 
    <select id="PipeOutInfo" resultType="com.thhy.mobile.modules.biz.checkhistory.entity.OutInfoVo">
        select su.real_name as sendUserName,sc.car_brand as carBrand,sc.car_driver as carDriver,sr.reciver_name as reciverName,po.str_time as startTime,po.end_time as endTime
        from t_pipe_out_pipe pop
                 left join t_pipe_out po on po.pipe_out_id = pop.pipe_out_id
                 left join sys_users su on su.user_id = po.out_user_id
                 left join sys_car sc on sc.car_id = po.car_id
                 left join sys_reciver sr on sr.id = po.in_user_id
        where pop.pipe_id = #{pipeId}
    </select>
 
    <select id="ringCompleteByRingNum" resultType="int">
        select count(a.ring_num) as ringCount from
            (
                select tpi.ring_num,GROUP_CONCAT(sd.dict_name order by sd.dict_value) as blockName,
                       (select GROUP_CONCAT(sd1.dict_name order by sd1.dict_value) from sys_pro_blok spb left join sys_dict sd1 on sd1.dict_id = spb.block_num where spb.pro_id = max(tpi.pro_id) group by spb.pro_id) as proBlock
                from t_pipe_info tpi
                         left join sys_dict sd on sd.dict_id = tpi.block_num
                where tpi.check_result = 1 and tpi.ring_num = #{ringNum}
                group by tpi.ring_num
            ) a  where a.blockName = a.proBlock
    </select>
 
    <select id="problemInfo" resultType="com.thhy.mobile.modules.biz.pipeinfo.entity.ProblemInfoVo">
        select pipe_check_id as pipeCheckId,check_result as checkResult,check_reason as existProblem,exe_pro_result as exeProResult,remark,exe_pro_note as exeProNote
        from t_pipe_check_record where pipe_id = #{pipeId}
        order by check_time desc limit 1
    </select>
 
    <select id="checkfiles" resultType="string">
        select check_file from t_pipe_check_file
        where pipe_check_id = #{pipeCheckId}
    </select>
 
    <select id="queryReasons" resultType="string">
        select GROUP_CONCAT(reason_name) as reasonName from t_check_reason
        <where>
            <foreach collection="idList" item="id" index="index" open="id in (" separator="," close=")" nullable="false">
                #{id}
            </foreach>
        </where>
        GROUP BY reason_type
    </select>
 
    <update id="updateProblem">
        update t_pipe_check_record
        <set>
            <trim suffixOverrides=",">
                exec_finish = 1,
                <if test="exeProResult !=null and exeProResult!=''">
                    exe_pro_result = #{exeProResult},
                </if>
                <if test="exeProNote !=null and exeProNote!=''">
                    exe_pro_note = #{exeProNote},
                </if>
            </trim>
        </set>
        where pipe_check_id = #{pipeCheckId}
    </update>
 
    <select id="querySteelByPRSB" resultType="com.thhy.mobile.modules.biz.checkhistory.entity.SteelVo">
        select sn.steel_id as steelId,ste.steel_name as steelName,sc.create_time as createTime,ste.steel_model as steelModel
        from t_steel_need sn
                 left join t_steel_consumption sc on sn.consumption_id = sc.consumption_id
                 left join sys_steel ste on ste.steel_id = sn.steel_id
        where sc.pro_id = #{proId} and sc.size_id = #{size} and sc.reinforcement_id = #{reinforcement} and sc.block_id = #{blockNum} and sc.is_use = 1
    </select>
    <select id="modIdlThing" parameterType="java.lang.String" resultType="com.thhy.mobile.modules.biz.pipeinfo.entity.ModIdlThing">
        SELECT
    sm.mould_id AS mouldId,
    sm.mould_num AS mouldNum,
    sm.mould_code AS mouldCode,
    sd.dict_name AS mouldType,
    sd1.dict_name AS mouldSize,
    sd2.dict_name AS mouldTurn,
    sm.mould_mn AS mouldMn,
    sm.current_cycle_time AS currentCycleTime
FROM
    sys_mould sm
    LEFT JOIN sys_dict sd ON sm.mould_type = sd.dict_id
    LEFT JOIN sys_dict sd1 ON sm.mould_size = sd1.dict_id
    LEFT JOIN sys_dict sd2 ON sm.mould_turn = sd2.dict_id
    where sm.mould_id=#{modId}
    </select>
    <select id="steelProduceThing" parameterType="java.lang.String"
            resultType="com.thhy.mobile.modules.biz.pipeinfo.entity.SteelProduceThing">
        SELECT tsp.steel_produce_id AS steelProduceId,
               tsp.produce_number   AS produceNumber,
               sp.pro_id            AS proId,
               sp.pro_name          AS proName,
               sd.dict_name         AS sizeName,
               sd1.dict_name        AS reinforcementName,
               sd2.dict_name        AS blockName,
               su.real_name         AS realName,
               sg.group_name        AS groupName,
               su1.real_name        AS qualityUserName,
               tsp.quality_time     AS qualityTime,
               tsp.is_qualified     AS isQualified,
               tsp.is_model         AS isModel,
               tsp.print_time       AS printTime
        FROM t_steel_produce tsp
                 LEFT JOIN sys_project sp ON tsp.pro_id = sp.pro_id
                 LEFT JOIN sys_dict sd ON tsp.size_id = sd.dict_id
                 LEFT JOIN sys_dict sd1 ON tsp.reinforcement_id = sd1.dict_id
                 LEFT JOIN sys_dict sd2 ON tsp.block_num = sd2.dict_id
                 LEFT JOIN sys_users su ON tsp.create_user = su.user_id
                 LEFT JOIN sys_group_user sgu ON su.plat_id = sgu.user_id
                 LEFT JOIN sys_group sg ON sgu.group_id = sg.group_id
                 LEFT JOIN sys_users su1 ON tsp.quality_user = su1.user_id
        WHERE tsp.is_use = 1
          AND tsp.produce_number = #{produceNumber}
    </select>
 
    <update id="pipeIdOutUpdate">
        update t_pipe_info
        set  placing_type=2,
             placing_out_time=sysdate()
        where pipe_id=#{pipeId}
    </update>
 
    <select id="queryAllProject" resultType="com.thhy.mobile.modules.biz.pipeinfo.entity.ScreenPipeCompare">
        select pro_id as proId,pro_name as proName from sys_project where is_use = 1
    </select>
    
    
    <select id="queryPipeDeplete" resultType="com.thhy.mobile.modules.biz.pipeinfo.entity.MaterialInfo">
        SELECT rm.material_name as materialName,sd.dict_name as materialCName,rm.material_value as materialValue
        from t_rsb_materials rm
                 left join t_rsb_material_plan rmp on rm.rsb_id = rmp.id
                 left join sys_dict sd on sd.dict_id = rm.material_name
        where rmp.pro_id = #{proId} and rmp.block_num = #{blockNum} and rmp.reinforcement = #{reinforcement} and rmp.size = #{size}
 
    </select>
 
    <select id="queryMaterStock" resultType="com.thhy.mobile.modules.biz.pipeinfo.entity.MaterialInfo">
        select material_name as materialName,material_value as materialValue from t_material_stock where material_name = #{materialName} and company_id = #{companyId}
    </select>
 
    <update id="updateMaterStock">
        update t_material_stock set material_value = #{materialValue} where material_name = #{materialName} and company_id = #{companyId}
    </update>
 
    <insert id="updateMaterStockRecord">
        insert into t_material_stock_record (id,type,op_type,material_name,material_value,before_stock,after_stock,company_id,pipe_id,pipe_num)
        values (REPLACE(UUID(),'-',''),#{type},#{opType},#{materialName},#{materialValue},#{beforeStock},#{afterStock},#{companyId},#{pipeId},#{pipeNum})
    </insert>
 
    <select id="materialTotalStock" resultType="com.thhy.mobile.modules.biz.pipeinfo.entity.MaterialInfo">
        select ms.material_name as materialName,sd.dict_name as materialCName,ms.material_value as materialValue
        from t_material_stock ms
        left join sys_dict sd on sd.dict_id = ms.material_name
        where ms.company_id = #{companyId}
    </select>
 
    <select id="TableHeader" resultType="java.util.HashMap">
        select dict_name as headName,dict_id as dictId
        from sys_dict  sd
        where sd.dict_type='pipe_materials' and sd.is_use = 1 order by sd.dict_value
    </select>
 
    <select id="queryMaterias" resultType="hashmap">
        select msr.create_date as createDate,GROUP_CONCAT(CONCAT(msr.material_name,':',msr.material_value)) as namevalue
        from t_material_stock_record msr
        where msr.company_id = #{companyId} and msr.type = 2 and DATE_FORMAT(sysdate(),'%Y-%m-%d') = DATE_FORMAT(msr.create_date,'%Y-%m-%d')
        group by msr.create_date
        order by msr.create_date desc
    </select>
 
    <select id="queryDeviceBySn" resultType="com.thhy.mobile.modules.biz.temdevice.entity.DeviceInfo">
        select device_id as deviceId,produce_order as produceOrder,device_status as deviceStatus,node from sys_device where sn_code = #{snCode}
    </select>
 
    <update id="updateDeviceStatus">
        update sys_device set device_status = #{deviceStatus} where sn_code = #{snCode}
    </update>
    
    <insert id="insertRestData">
        insert into t_rest_data (id,device_id,tem,hum,check_time) values (REPLACE(UUID(),'-',''),#{deviceId},#{tem},#{hum},#{checkTime})
    </insert>
 
    <insert id="insertWaterData">
        insert into t_water_cultivated_device_data (id,device_id,temperature,ph_value,release_time) values (REPLACE(UUID(),'-',''),#{deviceId},#{tem},#{phValue},#{checkTime})
    </insert>
 
    <update id="updateRingNum">
        update t_pipe_info set ring_num = #{newRingNum} where ring_num = #{ringNum}
    </update>
 
    <select id="queryBlockByPro" resultType="string">
        select block_num from sys_pro_blok where pro_id = #{proId}
    </select>
 
    <select id="queryMouldTypeByPro" resultType="com.thhy.mobile.modules.biz.mouldcheck.entity.Mould">
        select m.mould_type as mouldType,max(mould_id) as mouldId from sys_mould m
        where m.pro_id = #{proId}
        group by m.mould_type
    </select>
 
    <select id="queryMaxNumBySteelProduce" resultType="int">
        select
            max(a.number)
        FROM
            (
                select produce_number,SUBSTR(produce_number from LENGTH(produce_number)-4 for 5) as number
                FROM t_steel_produce
            ) a
    </select>
 
    <select id="countByRingNum" resultType="int">
        select count(pipe_id) from t_pipe_info where ring_num = #{ringNum}
    </select>
</mapper>