张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
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
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
<?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.staff.modules.biz.platuser.mapper.PlatUserMapper">
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        t.user_id as userId,
        t.job_num as jobNum,
        t.real_name as realName,
        t.phone as phone,
        t.sex as sex,
        t.id_no as idNo,
        t.has_cert as hasCert,
        t.zzmm as zzmm,
        t.employed_time as employedTime,
        t.come_factory_time as comeFactoryTime,
        t.leave_factory_time as leaveFactoryTime,
        t.jg as jg,
        t.is_use as isUse,
        t.status as status,
        t.is_login as isLogin,
        t.user_type as userType,
        t.create_time as createTime,
        t.create_user as createUser,
        t.update_time as updateTime,
        t.update_user as updateUser
    </sql>
 
    <sql id="condition_query">
        <where>
            <trim suffixOverrides=" AND ">
                <if test="jobNum!=null and jobNum!=''">
                    t.job_num = #{jobNum} AND
                </if>
                <if test="realName!=null and realName!=''">
                    t.real_name = #{realName} AND
                </if>
                <if test="sex!=null">
                    t.sex = #{sex} AND
                </if>
                <if test="idNo!=null and idNo!=''">
                    t.id_no = #{idNo} AND
                </if>
                <if test="hasCert!=null">
                    t.has_cert = #{hasCert} AND
                </if>
                <if test="zzmm!=null and zzmm!=''">
                    t.zzmm = #{zzmm} AND
                </if>
                <if test="employedTime!=null">
                    t.employed_time = #{employedTime} AND
                </if>
                <if test="comeFactoryTime!=null">
                    t.come_factory_time = #{comeFactoryTime} AND
                </if>
                <if test="leaveFactoryTime!=null">
                    t.leave_factory_time = #{leaveFactoryTime} AND
                </if>
                <if test="jg!=null and jg!=''">
                    t.jg = #{jg} AND
                </if>
                <if test="isUse!=null">
                    t.is_use = #{isUse} AND
                </if>
                <if test="status!=null and status!=''">
                    t.status = #{status} AND
                </if>
                <if test="userType!=null">
                    t.user_type = #{userType} AND
                </if>
                <if test="createTime!=null">
                    t.create_time = #{createTime} AND
                </if>
                <if test="createUser!=null and createUser!=''">
                    t.create_user = #{createUser} AND
                </if>
                <if test="updateTime!=null">
                    t.update_time = #{updateTime} AND
                </if>
                <if test="updateUser!=null">
                    t.update_user = #{updateUser} AND
                </if>
            </trim>
        </where>
    </sql>
 
    <select id="queryById" resultType="com.thhy.staff.modules.biz.platuser.entity.PlatUser">
        select <include refid="Base_Column_List" />
        from sys_plat_user t
        where t.user_id=#{userId}
    </select>
    
    <select id="queryPhoneAndIsLogin" resultType="com.thhy.staff.modules.biz.platuser.entity.PlatUser">
        select t.user_id as userId,t.phone,t.is_login as isLogin
        from sys_plat_user t
        where t.user_id=#{userId}
    </select>
 
    <select id="queryForPullDown" resultType="com.thhy.staff.modules.biz.platuser.entity.PlatUserPullDown">
        select spu.user_id as userId,spu.real_name as realName,spu.phone from sys_plat_user spu
        left join sys_depart_user sdu on sdu.user_id = spu.user_id
        left join sys_com_depart smt on smt.depart_id = sdu.depart_id
        <where>
            <trim suffixOverrides=" AND ">
                spu.is_use= 1 and smt.company_id = #{companyId} AND
                <if test="realName !=null and realName !=''">
                    spu.real_name LIKE concat('%',#{realName},'%') AND
                </if>
                <if test="userId !=null and userId !=''">
                    sdu.user_id=#{userId} AND
                </if>
            </trim>
        </where>
 
    </select>
 
    <select id="queryForPullDownDorm" resultType="com.thhy.staff.modules.biz.platuser.entity.PlatUserPullDown">
        SELECT a.* from (
        select spu.user_id as userId,spu.real_name as realName,spu.phone,
               (select count(id) from sys_dorm_user where user_id = spu.user_id and is_use = 1) as count,
        sdm.dorm_id
        from sys_plat_user spu
        left join sys_depart_user sdu on sdu.user_id = spu.user_id
        left join sys_com_depart smt on smt.depart_id = sdu.depart_id
        left join sys_dorm_user sdm on sdm.user_id = spu.user_id
        where spu.is_use= 1 and smt.company_id = #{companyId}
        <if test="realName !=null and realName !=''">
            AND spu.real_name LIKE concat('%',#{realName},'%')
        </if>
        ) a
           <if test="dormId !=null and dormId !=''">
               where (a.count &lt; 1 or a.dorm_id = #{dormId})
           </if>
        <if test="dormId ==null or dormId ==''">
            where a.count &lt; 1
        </if>
 
    </select>
 
    <select id="queryVersionById" resultType="integer">
        select version from sys_plat_user
        where user_id=#{userId}
    </select>
 
    <!--查询列表-->
    <select id="findList" resultType="com.thhy.staff.modules.biz.platuser.entity.PlatUserListVo">
        SELECT a.*,
        (select GROUP_CONCAT(sgu.group_id) as groupIds
        from sys_group_user sgu
        left join sys_group sg on sg.group_id = sgu.group_id
        where sgu.user_id = a.userId
        group by sgu.user_id) as groupIds,
        (select GROUP_CONCAT(sg.group_name) as groupNames
        from sys_group_user sgu
        left join sys_group sg on sg.group_id = sgu.group_id
        where sgu.user_id = a.userId
        group by sgu.user_id) as groupNames,
        (select CONCAT(sc2.name,'-',sc1.name)
        from sys_city sc1
        left join sys_city sc2 on sc1.parentid = sc2.id
        where sc1.id = a.jgs) as jg
        from
        (SELECT
        t.user_id as userId,
        t.job_num as jobNum,
        t.real_name as realName,
        t.phone as phone,
        t.sex as sex,
        t.id_no as idNo,
        t.has_cert as hasCert,
        t.zzmm as zzmm,
        t.employed_time as employedTime,
        t.come_factory_time as comeFactoryTime,
        t.leave_factory_time as leaveFactoryTime,
        t.jg as jgs,
        t.is_use as isUse,
        t.status as status,
        t.user_type as userType,
        t.is_login as isLogin,
        t.create_time as createTime,
        t.create_user as createUser,
        t.update_time as updateTime,
        t.update_user as updateUser,
        t.photo as photo,
        t.sync_to_device as syncToDevice,
        sd.depart_id as departId,
        sd.depart_name as departName,
        sp.pos_name as posName,
        sp.pos_id as posId,
        dict.dict_name as zzmmValue
        from sys_plat_user t
 
        left join sys_depart_user sdu on sdu.user_id = t.user_id
        left join sys_depart sd on sd.depart_id = sdu.depart_id
        left join sys_plat_position_user spu on spu.user_id = t.user_id
        left join sys_position sp on sp.pos_id = spu.position_id
        left join sys_dict dict on dict.dict_id = t.zzmm
        left join sys_com_depart scd on scd.depart_id = sdu.depart_id
        <where>
            <trim suffixOverrides=" AND ">
                t.is_use = 1 AND (scd.company_id = #{companyId} or sp.company_id = #{companyId}) AND
                <if test="userType!=null and userType !=''">
                    t.user_type = #{userType} AND
                </if>
                <if test="realName!=null and realName!=''">
                    t.real_name LIKE concat('%',#{realName},'%') AND
                </if>
                <if test="departId!=null and departId!=''">
                    sd.depart_id = #{departId} AND
                </if>
                <if test="posId!=null and posId!=''">
                    sp.pos_id LIKE concat('%',#{posId},'%') AND
                </if>
                <if test="status!=null and status !=''">
                    t.status = #{status} AND
                </if>
            </trim>
        </where>
        order by t.create_time desc
        ) a
 
    </select>
 
    <!--查询列表-->
    <select id="findAll" resultType="com.thhy.staff.modules.biz.platuser.entity.PlatUser">
        SELECT
        <include refid="Base_Column_List" />
        from sys_plat_user t
    </select>
 
    <select id="queryIdByPhone" resultType="string">
        select user_id from sys_plat_user where phone = #{phone} and is_use = 1
    </select>
 
    <select id="querySysUserIdByPhone" resultType="String">
        select user_id from sys_users where telphone = #{phone} and is_use = 1
    </select>
 
    <select id="queryIdByIdno" resultType="string">
        select user_id from sys_plat_user where id_no = #{idNo} and is_use = 1
    </select>
 
    <!--插入操作-->
    <insert id="insert" useGeneratedKeys="true" keyProperty="userId">
        insert into sys_plat_user
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="userId != null">
                user_id,
            </if>
            <if test="jobNum != null">
                job_num,
            </if>
            <if test="realName != null">
                real_name,
            </if>
            <if test="phone != null">
                phone,
            </if>
            <if test="sex != null">
                sex,
            </if>
            <if test="idNo != null">
                id_no,
            </if>
            <if test="hasCert != null">
                has_cert,
            </if>
            <if test="zzmm != null">
                zzmm,
            </if>
            <if test="employedTime != null">
                employed_time,
            </if>
            <if test="comeFactoryTime != null">
                come_factory_time,
            </if>
            <if test="leaveFactoryTime != null">
                leave_factory_time,
            </if>
            <if test="jg != null">
                jg,
            </if>
            <if test="isUse != null">
                is_use,
            </if>
            <if test="status != null">
                status,
            </if>
            <if test="userType != null">
                user_type,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="createUser != null">
                create_user,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="updateUser != null">
                update_user,
            </if>
            <if test="isLogin != null">
                is_login,
            </if>
            <if test="openId != null">
                open_id,
            </if>
            <if test="applyFlag != null">
                apply_flag,
            </if>
            <if test="photoUrl != null">
                photo,
            </if>
            <if test="fromPlat != null">
                from_plat,
            </if>
            <if test="remark != null">
                remark,
            </if>
        </trim>
 
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="userId != null">
                #{userId},
            </if>
            <if test="jobNum != null">
                #{jobNum},
            </if>
            <if test="realName != null">
                #{realName},
            </if>
            <if test="phone != null">
                #{phone},
            </if>
            <if test="sex != null">
                #{sex},
            </if>
            <if test="idNo != null">
                #{idNo},
            </if>
            <if test="hasCert != null">
                #{hasCert},
            </if>
            <if test="zzmm != null">
                #{zzmm},
            </if>
            <if test="employedTime != null">
                #{employedTime},
            </if>
            <if test="comeFactoryTime != null">
                #{comeFactoryTime},
            </if>
            <if test="leaveFactoryTime != null">
                #{leaveFactoryTime},
            </if>
            <if test="jg != null">
                #{jg},
            </if>
            <if test="isUse != null">
                #{isUse},
            </if>
            <if test="status != null">
                #{status},
            </if>
            <if test="userType != null">
                #{userType},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="createUser != null">
                #{createUser},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="updateUser != null">
                #{updateUser},
            </if>
            <if test="isLogin != null">
                #{isLogin},
            </if>
            <if test="openId != null">
                #{openId},
            </if>
            <if test="applyFlag != null">
                #{applyFlag},
            </if>
            <if test="photoUrl != null">
                #{photoUrl},
            </if>
            <if test="fromPlat != null">
                #{fromPlat},
            </if>
            <if test="remark != null">
                #{remark},
            </if>
        </trim>
    </insert>
 
 
    <!--更新操作-->
    <update id="update">
        update sys_plat_user
        <set>
            <if test="jobNum != null">
                job_num=#{jobNum},
            </if>
            <if test="phone != null">
                phone=#{phone},
            </if>
            <if test="realName != null">
                real_name=#{realName},
            </if>
            <if test="sex != null">
                sex=#{sex},
            </if>
            <if test="idNo != null">
                id_no=#{idNo},
            </if>
            <if test="hasCert != null">
                has_cert=#{hasCert},
            </if>
            <if test="zzmm != null">
                zzmm=#{zzmm},
            </if>
            <if test="employedTime != null">
                employed_time=#{employedTime},
            </if>
            <if test="comeFactoryTime != null">
                come_factory_time=#{comeFactoryTime},
            </if>
            <if test="leaveFactoryTime != null">
                leave_factory_time=#{leaveFactoryTime},
            </if>
            <if test="jg != null">
                jg=#{jg},
            </if>
            <if test="isUse != null">
                is_use=#{isUse},
            </if>
            <if test="status != null">
                status=#{status},
            </if>
            <if test="userType != null">
                user_type=#{userType},
            </if>
            <if test="createTime != null">
                create_time=#{createTime},
            </if>
            <if test="createUser != null">
                create_user=#{createUser},
            </if>
            <if test="updateTime != null">
                update_time=#{updateTime},
            </if>
            <if test="updateUser != null">
                update_user=#{updateUser},
            </if>
            <if test="isLogin != null">
                is_login=#{isLogin},
            </if>
            <if test="applyFlag != null">
                apply_flag=#{applyFlag},
            </if>
            <if test="remark != null">
                remark=#{remark},
            </if>
            <if test="photoUrl != null">
                photo=#{photoUrl},
            </if>
        </set>
        where user_id=#{userId}
    </update>
 
    <!--逻辑删除-->
    <update id="deletelogic">
        update sys_plat_user
        SET is_use = 0
        where user_id=#{userId}
    </update>
 
    <!--根据ID删除-->
    <delete id="deleteById">
        delete from sys_plat_user
        where user_id=#{userId}
    </delete>
 
    <select id="queryMaxJobNum" resultType="int">
        select case when max(a.maxNo) is NULL then 0 else max(a.maxNo) end as maxNo from (select SUBSTR(job_num,2,LENGTH(job_num))+0 as maxNo from sys_plat_user where user_type = #{userType}) a
 
    </select>
 
    <!--插入操作-->
    <insert id="insertSysUser">
        insert into sys_users
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="userId != null">
                user_id,
            </if>
            <if test="username != null">
                username,
            </if>
            <if test="password != null">
                password,
            </if>
            <if test="realName != null">
                real_name,
            </if>
            <if test="telphone != null">
                telphone,
            </if>
            <if test="photoUrl != null">
                photo_url,
            </if>
            <if test="createUser != null">
                create_user,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="isUse != null">
                is_use,
            </if>
            <if test="sex != null">
                sex,
            </if>
            <if test="email != null">
                email,
            </if>
            <if test="isPlat != null">
                is_plat,
            </if>
            <if test="platId != null">
                plat_id,
            </if>
        </trim>
 
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="userId != null">
                #{userId},
            </if>
            <if test="username != null">
                #{username},
            </if>
            <if test="password != null">
                #{password},
            </if>
            <if test="realName != null">
                #{realName},
            </if>
            <if test="telphone != null">
                #{telphone},
            </if>
            <if test="photoUrl != null">
                #{photoUrl},
            </if>
            <if test="createUser != null">
                #{createUser},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="isUse != null">
                #{isUse},
            </if>
            <if test="sex != null">
                #{sex},
            </if>
            <if test="email != null">
                #{email},
            </if>
            <if test="isPlat != null">
                #{isPlat},
            </if>
            <if test="platId != null">
                #{platId},
            </if>
        </trim>
    </insert>
 
    <update id="syncDelete">
        update sys_users set is_use=0 where username = #{jobNum}
    </update>
 
    <insert id="insertDepartUser" parameterType="com.thhy.staff.modules.biz.depart.entity.OtherUser">
        insert into sys_depart_user (id,depart_id,user_id) values (#{id},#{otherId},#{userId});
    </insert>
 
    <insert id="insertPositionUser" parameterType="com.thhy.staff.modules.biz.depart.entity.OtherUser">
        insert into sys_plat_position_user (id,position_id,user_id) values (#{id},#{otherId},#{userId});
    </insert>
 
    <insert id="insertGroupUser" parameterType="com.thhy.staff.modules.biz.depart.entity.OtherUser">
        insert into sys_group_user (id,group_id,user_id) values (#{id},#{groupId},#{userId});
    </insert>
 
    <delete id="deleteGroupUserByUser">
        delete from sys_group_user where user_id = #{userId}
    </delete>
 
    <delete id="deletePositionUserByUser">
        delete from sys_plat_position_user where user_id = #{userId}
    </delete>
 
    <delete id="deleteDepartUserByUser">
        delete from sys_depart_user where user_id = #{userId}
    </delete>
 
    <select id="queryByOpenId" resultType="com.thhy.staff.modules.biz.platuser.entity.MpRegisterInfoVo">
        select t.user_id as userId,
               t.real_name as realName,
               t.phone as phone,
               t.sex as sex,
               t.id_no as idNo,
               t.photo as photoUrl,
               t.remark,
               t.apply_flag as applyFlag,
               t.is_login as isLogin,
               ppu.position_id as posId,
               sp.pos_name as posName,
               sp.company_id as companyId,
               sc.company_name as companyName
        from sys_plat_user t
        left join sys_plat_position_user ppu on ppu.user_id = t.user_id
        left join sys_position sp on sp.pos_id = ppu.position_id
        left join sys_company sc on sc.company_id = sp.company_id
        where t.open_id = #{openId} and t.is_use = 1
    </select>
 
    <select id="queryByUserId" resultType="com.thhy.staff.modules.biz.platuser.entity.MpRegisterInfoVo">
        select t.user_id as userId,
               t.real_name as realName,
               t.phone as phone,
               t.sex as sex,
               t.id_no as idNo,
               t.photo as photoUrl,
               t.remark,
               t.apply_flag as applyFlag,
               ppu.position_id as posId,
               sp.pos_name as posName,
               sp.company_id as companyId,
               sc.company_name as companyName
        from sys_plat_user t
        left join sys_plat_position_user ppu on ppu.user_id = t.user_id
        left join sys_position sp on sp.pos_id = ppu.position_id
        left join sys_company sc on sc.company_id = sp.company_id
        where t.user_id = #{userId} and t.is_use = 1
    </select>
 
    <select id="queryForDtoByUserId" resultType="com.thhy.staff.modules.biz.platuser.entity.PlatUserDto">
        select t.user_id as userId,
               t.real_name as realName,
               t.sex as sex,
               t.job_num as jobNum,
               t.phone as phone,
               t.id_no as idNo,
               t.photo as photoUrl
        from sys_plat_user t
        where t.user_id = #{userId}
    </select>
 
    <select id="queryHistoryByUserId" resultType="com.thhy.staff.modules.biz.platuser.entity.ApplyHistory">
        select ah.create_time as createTime,case when ah.process_flag = 1 then spu.real_name else su.real_name end as realName,
               ah.apply_desc as applyDesc,ah.process_flag as processFlag
        from t_user_apply_history ah
                 left join sys_users su on su.user_id = ah.create_user
                 left join sys_plat_user spu on spu.user_id = ah.plat_user_id
        where ah.plat_user_id = #{userId} or ah.user_id = #{userId}
        order by ah.create_time
    </select>
 
    <select id="queryApplyList" resultType="com.thhy.staff.modules.biz.platuser.entity.ApplyListVo">
        select spu.user_id as userId,spu.real_name as realName,spu.sex,sp.pos_name as posName,spu.create_time as createTime,spu.apply_flag as applyFlag
        from sys_plat_user spu
                 left join sys_plat_position_user sppu on sppu.user_id = spu.user_id
                 left join sys_position sp on sp.pos_id = sppu.position_id
        where spu.user_type = 2 and sp.company_id = #{companyId}
        <if test="realName != null and realName !=''">
            and spu.real_name LIKE concat('%',#{realName},'%')
        </if>
    </select>
 
    <update id="updateApplyStatus">
        update sys_plat_user set apply_flag = #{applyFlag} where user_id = #{userId}
    </update>
    
    <update id="deleteSysUserByPlat">
        update sys_users set is_use = 0 where plat_id = #{userId}
    </update>
 
    <select id="queryJobNumByUserId" resultType="com.thhy.staff.modules.biz.platuser.entity.FaceDto">
        select job_num as jobNum,photo,real_name as realName from sys_plat_user where user_id = #{userId}
    </select>
 
    <update id="updateFace">
        update sys_plat_user set photo = #{photo},sync_to_device = #{syncToDevice} where user_id = #{userId}
    </update>
 
    <update id="updateDelFace">
        update sys_plat_user set sync_to_device = #{syncToDevice} where user_id = #{userId}
    </update>
 
    <update id="updateFaceStatus">
        update sys_plat_user set add_face_status = #{addFaceStatus} where user_id = #{userId}
    </update>
 
    <insert id="addDoorHis">
        insert into t_face_record (id,ori_str) values (REPLACE(UUID(),'-',''),#{oriStr})
    </insert>
 
    <insert id="insertDoorLis">
        insert into t_face_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            id,
            <if test="ipAddress!=null and ipAddress !=''">
                ip_address,
            </if>
            <if test="macAddress!=null and macAddress !=''">
                mac_address,
            </if>
            <if test="noticeType!=null">
                notice_type,
            </if>
            <if test="employeeNoString!=null and employeeNoString !=''">
                employee_no_string,
            </if>
            <if test="name!=null and name !=''">
                name,
            </if>
            <if test="verify!=null">
                verify,
            </if>
            <if test="oriStr!=null and oriStr !=''">
                ori_str,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{id},
            <if test="ipAddress!=null and ipAddress !=''">
                #{ipAddress},
            </if>
            <if test="macAddress!=null and macAddress !=''">
                #{macAddress},
            </if>
            <if test="noticeType!=null">
                #{noticeType},
            </if>
            <if test="employeeNoString!=null and employeeNoString !=''">
                #{employeeNoString},
            </if>
            <if test="name!=null and name !=''">
                #{name},
            </if>
            <if test="verify!=null">
                #{verify},
            </if>
            <if test="oriStr!=null and oriStr !=''">
                #{oriStr},
            </if>
        </trim>
 
    </insert>
 
    <insert id="insertDoorListener">
        insert into t_face_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            id,
            <if test="ip!=null and ip !=''">
                ip_address,
            </if>
            <if test="macAddress!=null and macAddress !=''">
                mac_address,
            </if>
            <if test="firstType!=null">
                notice_type,
            </if>
            <if test="secType!=null">
                notice_sec,
            </if>
            <if test="jobNum!=null and jobNum !=''">
                employee_no_string,
            </if>
            <if test="name!=null and name !=''">
                name,
            </if>
            <if test="verify!=null">
                verify,
            </if>
            <if test="pic!=null">
                pic,
            </if>
            <if test="lockOp!=null">
                lock_op,
            </if>
            <if test="apiFlag!=null">
                api_flag,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{id},
            <if test="ip!=null and ip !=''">
                #{ip},
            </if>
            <if test="macAddress!=null and macAddress !=''">
                #{macAddress},
            </if>
            <if test="firstType!=null and firstType!=''">
                #{firstType},
            </if>
            <if test="secType!=null">
                #{secType},
            </if>
            <if test="jobNum!=null and jobNum !=''">
                #{jobNum},
            </if>
            <if test="name!=null and name !=''">
                #{name},
            </if>
            <if test="verify!=null">
                #{verify},
            </if>
            <if test="pic!=null">
                #{pic},
            </if>
            <if test="lockOp!=null">
                #{lockOp},
            </if>
            <if test="apiFlag!=null">
                #{apiFlag},
            </if>
        </trim>
 
    </insert>
 
    <select id="queryPlatUser" resultType="int">
        select count(DISTINCT spu.user_id) as userCount from sys_plat_user spu
             left join sys_depart_user sdu on spu.user_id = sdu.user_id
             left join sys_com_depart scd on scd.depart_id = sdu.depart_id
             left join sys_plat_position_user pu on pu.user_id = spu.user_id
             left join sys_position sp on sp.pos_id = pu.position_id
        where spu.is_use = 1 and user_type=2 and (scd.company_id = #{companyId} or sp.company_id = #{companyId})
    </select>
 
 
    <select id="queryDoorUser" resultType="com.thhy.staff.modules.biz.platuser.entity.DoorUserVo">
        select fr.create_time,fr.employee_no_string as jobNum,spu.real_name as realName,sg.group_name as groupName,1 as staffStatus
        from t_face_record fr
                 left join sys_plat_user spu on spu.job_num = fr.employee_no_string
                 left join sys_group_user sgu on spu.user_id = sgu.user_id
                 left join sys_group sg on sg.group_id = sgu.group_id
        where fr.notice_type = 5 and fr.verify = 1 and (fr.mac_address='e0:ca:3c:f0:d9:3a' or fr.mac_address = 'e0:ca:3c:f0:a7:34' or fr.mac_address = 'e0:ca:3c:f0:d9:3b')
        order by fr.create_time desc
        limit 10
    </select>
 
    <select id="countInDoorUserToday" resultType="int">
        select count(distinct fr.employee_no_string)
        from t_face_record fr
        left join sys_plat_user spu on spu.job_num = fr.employee_no_string
        where fr.notice_type = 5 and fr.verify = 1 and spu.user_id is not null and (fr.mac_address='e0:ca:3c:f0:d9:3a' or fr.mac_address = 'e0:ca:3c:f0:a7:34' or fr.mac_address = 'e0:ca:3c:f0:d9:3b')
        and DATE_FORMAT(sysdate(),'%Y-%m-%d') = DATE_FORMAT(fr.create_time,'%Y-%m-%d')
    </select>
 
    <select id="groupUserWorking" resultType="com.thhy.staff.modules.biz.platuser.entity.GroupWorking">
        select sg.group_id as groupId,sg.group_name as groupName,
               (select count(user_id) from sys_group_user where group_id = sg.group_id) as groupUserCount
        from sys_group sg
                 left join sys_com_depart sd on sg.depart_id = sd.depart_id
        where sg.is_use = 1 and sd.company_id = #{companyId}
    </select>
 
    <select id="countFaceRecordByGroup" resultType="int">
        select count(DISTINCT fr.employee_no_string) as count
        from t_face_record fr
            left join sys_plat_user spu on spu.job_num = fr.employee_no_string
            left join sys_group_user sgu on sgu.user_id = spu.user_id and sgu.is_use = 1
        where sgu.group_id = #{groupId} and fr.notice_type = 5 and fr.verify = 1 and DATE_FORMAT(sysdate(),'%Y-%m-%d') = DATE_FORMAT(fr.create_time,'%Y-%m-%d') and (fr.mac_address='e0:ca:3c:f0:d9:3a' or fr.mac_address = 'e0:ca:3c:f0:a7:34' or fr.mac_address = 'e0:ca:3c:f0:d9:3b')
    </select>
 
    <select id="queryFaceUserByJobNum" resultType="com.thhy.staff.modules.biz.platuser.entity.PlatUserFace">
        select spu.real_name as realName,spu.phone,sp.pos_name as posName,spu.photo
        from sys_plat_user spu
         left join sys_plat_position_user sppu on spu.user_id = sppu.user_id
         left join sys_position sp on sp.pos_id = sppu.position_id
        where spu.job_num = #{jobNum}
    </select>
 
</mapper>