EntmicroStaffMapper.xml
42.7 KB
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
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
<?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="cn.com.glsx.entmicro.mapper.EntmicroStaffMapper">
<!--员工resultMap-->
<resultMap id="resultMap" type="cn.com.glsx.entmicro.model.response.EntmicroStaffResponse">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="staff_name" jdbcType="VARCHAR" property="staffName"/>
<result column="staff_email" jdbcType="VARCHAR" property="staffEmail"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
<result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
<result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
<result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="staff_phone" jdbcType="VARCHAR" property="staffPhone"/>
<result column="is_add_outsider" jdbcType="TINYINT" property="isAddOutsider"/>
<result column="user_id" jdbcType="VARCHAR" property="userId"/>
<result column="open_userid" jdbcType="VARCHAR" property="openUserid"/>
<result column="entmicroName" jdbcType="VARCHAR" property="entmicroName"/>
<result column="follower_type_id" jdbcType="INTEGER" property="followerTypeId"/>
<result column="staff_title" jdbcType="VARCHAR" property="staffTitle"/>
<result column="follower_created_time" jdbcType="TIMESTAMP" property="followerCreatedTime"/>
<result column="merchantId" jdbcType="INTEGER" property="merchantId"/>
<result column="merchant_id" jdbcType="INTEGER" property="merchantId"/>
<result column="status" javaType="INTEGER" property="status"/>
<result column="department_name" jdbcType="VARCHAR" property="departmentName"/>
<result column="qr_code" jdbcType="VARCHAR" property="qrCode"/>
<result column="thumb_avatar" jdbcType="VARCHAR" property="thumbAvatar"/>
<result column="departmentId" jdbcType="VARCHAR" property="departmentId"/>
<result column="user_oneid" jdbcType="VARCHAR" property="userOneid"/>
<result column="followerTypeName" jdbcType="VARCHAR" property="followerTypeName"/>
<result column="follow_name" jdbcType="VARCHAR" property="followerName"/>
<result column="chatCount" jdbcType="VARCHAR" property="chatCount"/>
<result column="customerId" jdbcType="VARCHAR" property="customerId"/>
<result column="business_type" jdbcType="VARCHAR" property="businessType"/>
<result column="merchantIds" jdbcType="VARCHAR" property="merchantIds"/>
<result column="last_login_time" jdbcType="TIMESTAMP" property="lastLoginTime"/>
<result column="login_Status" jdbcType="INTEGER" property="loginStatus"/>
<result column="id_Bef_Encryption" jdbcType="VARCHAR" property="idBefEncryption"/>
<result column="staff_uuid" jdbcType="VARCHAR" property="uuid"/>
</resultMap>
<resultMap id="baseResultMap" type="cn.com.glsx.entmicro.entity.EntmicroStaff">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="staff_name" jdbcType="VARCHAR" property="staffName"/>
<result column="staff_email" jdbcType="VARCHAR" property="staffEmail"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
<result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
<result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
<result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="staff_phone" jdbcType="VARCHAR" property="staffPhone"/>
<result column="is_add_outsider" jdbcType="TINYINT" property="isAddOutsider"/>
<result column="user_id" jdbcType="VARCHAR" property="userId"/>
<result column="open_userid" jdbcType="VARCHAR" property="openUserid"/>
<result column="entmicroName" jdbcType="VARCHAR" property="entmicroName"/>
<result column="follower_type_id" jdbcType="INTEGER" property="followerTypeId"/>
<result column="staff_title" jdbcType="VARCHAR" property="staffTitle"/>
<result column="follower_created_time" jdbcType="TIMESTAMP" property="followerCreatedTime"/>
<result column="status" javaType="INTEGER" property="status"/>
<result column="qr_code" jdbcType="VARCHAR" property="qrCode"/>
<result column="thumb_avatar" jdbcType="VARCHAR" property="thumbAvatar"/>
<result column="departmentId" jdbcType="VARCHAR" property="departmentId"/>
<result column="last_login_time" jdbcType="TIMESTAMP" property="lastLoginTime"/>
<result column="login_Status" jdbcType="INTEGER" property="loginStatus"/>
<result column="id_Bef_Encryption" jdbcType="VARCHAR" property="idBefEncryption"/>
</resultMap>
<!--员工resultMap-->
<resultMap id="resultFollowMap" type="cn.com.glsx.entmicro.model.response.EntmicroStaffFollowResponse">
<result column="follow_id" jdbcType="INTEGER" property="followId"/>
<result column="id" jdbcType="INTEGER" property="id"/>
<result column="staff_name" jdbcType="VARCHAR" property="staffName"/>
<result column="department_id" jdbcType="CHAR" property="departmentId"/>
<result column="staff_email" jdbcType="VARCHAR" property="staffEmail"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
<result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
<result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
<result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="staff_phone" jdbcType="VARCHAR" property="staffPhone"/>
<result column="is_add_outsider" jdbcType="TINYINT" property="isAddOutsider"/>
<result column="user_id" jdbcType="VARCHAR" property="userId"/>
<result column="open_userid" jdbcType="VARCHAR" property="openUserid"/>
<result column="entmicro_name" jdbcType="VARCHAR" property="entmicroName"/>
<result column="follower_type_id" jdbcType="INTEGER" property="followerTypeId"/>
<result column="staff_title" jdbcType="VARCHAR" property="staffTitle"/>
<result column="follower_created_time" jdbcType="TIMESTAMP" property="followerCreatedTime"/>
<result column="merchantId" jdbcType="INTEGER" property="merchantId"/>
<result column="status" javaType="INTEGER" property="status"/>
<result column="department_name" jdbcType="VARCHAR" property="departmentName"/>
</resultMap>
<!--跟进员工resultMap-->
<resultMap id="followerStaffResultMap" type="cn.com.glsx.entmicro.model.response.EntmicroFollowerStaffResponse">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="staff_name" jdbcType="VARCHAR" property="staffName"/>
<result column="department_name" jdbcType="VARCHAR" property="departmentName"/>
<result column="staff_phone" jdbcType="VARCHAR" property="staffPhone"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="is_add_outsider" jdbcType="INTEGER" property="isAddOutsider"/>
<result column="follower_created_time" jdbcType="TIMESTAMP" property="followerCreatedTime"/>
<result column="follow_name" jdbcType="VARCHAR" property="followerTypeName"/>
<result column="merchantId" jdbcType="VARCHAR" property="merchantId"/>
<result column="user_id" jdbcType="VARCHAR" property="userId"/>
<result column="relation_id" jdbcType="INTEGER" property="relationId"/>
<result column="user_oneid" jdbcType="VARCHAR" property="userOneId"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, staff_name, staff_email, created_by, created_time, updated_by,
updated_time, del_flag, staff_phone, is_add_outsider, user_id, open_userid, entmicro_name,
follower_type_id, staff_title, follower_created_time,merchantId, status,thumb_avatar,
staff_sex, staff_uuid,qr_code ,business_type,last_login_time,login_Status,id_Bef_Encryption
</sql>
<sql id="follower_staff_list">
id
, staff_name, department_id,
del_flag, staff_phone, is_add_outsider,
follower_type_id, follower_created_time, merchantId, status
</sql>
<select id="listStaffByFollowerTypeId" resultMap="resultMap">
select t1.id,
t1.staff_name
from entmicro_staff t1
left join entmicro_follower_type t2 on t1.follower_type_id = t2.id and t2.del_flag = 0
where t1.del_flag = 0
and t1.follower_type_id = #{followerTypeId}
and t2.merchantId = #{merchantId}
</select>
<update id="deleteEntmicroStaff"
parameterType="cn.com.glsx.entmicro.entity.EntmicroStaff">
update entmicro_staff
set del_flag = -1
where id = #{entmicroStaff.id}
</update>
<select id="listByStaffPhone" parameterType="cn.com.glsx.entmicro.entity.EntmicroStaff" resultMap="resultMap">
select
<include refid="Base_Column_List"/>
from entmicro_staff
where del_flag = 0
and staff_phone = #{entmicroStaff.staffPhone}
and merchantId=#{entmicroStaff.merchantid}
<if test="entmicroStaff.userId != null and entmicroStaff.userId != ''">
and user_id = #{entmicroStaff.userId}
</if>
</select>
<select id="listEntmicroFollowerStaffByPage"
parameterType="cn.com.glsx.entmicro.model.request.EntmicroFollowerStaffRequest"
resultMap="followerStaffResultMap">
select t1.id,
t1.staff_name,
t3.follow_name,
t1.staff_phone,
t1.follower_created_time,
t1.del_flag,
t1.is_add_outsider,
t4.relevance_merchant,
t1.user_id,
t4.user_oneid,
t4.id relation_id
from entmicro_staff t1
left join entmicro_staff_depart_relation t4
ON t1.id = t4.staff_id AND t4.del_flag = 0
left join entmicro_department t2
ON t4.department_id = t2.id AND t2.del_flag = 0
inner join entmicro_follower_type t3
ON t1.follower_type_id = t3.id AND t3.del_flag= 0
where t1.follower_type_id is not null
and t1.del_flag = 0
<if test="entmicroFollowerStaffRequest.staffName != null and entmicroFollowerStaffRequest.staffName != ''">
and t1.staff_name like concat('%',#{entmicroFollowerStaffRequest.staffName},'%')
</if>
<if test="entmicroFollowerStaffRequest.followerTypeId != null">
and t1.follower_type_id = #{entmicroFollowerStaffRequest.followerTypeId}
</if>
<if test="entmicroFollowerStaffRequest.userId != null and entmicroFollowerStaffRequest.userId != ''">
and t1.user_id = #{entmicroFollowerStaffRequest.userId}
</if>
and t4.relevance_merchant = #{entmicroFollowerStaffRequest.merchantId}
group by t1.id
order by t1.created_time desc
</select>
<update id="deleteEntmicroFollowerStaff" parameterType="cn.com.glsx.entmicro.entity.EntmicroStaff">
update entmicro_staff t1
inner join entmicro_staff_depart_relation t2
on t1.id = t2.staff_id
set t1.follower_type_id = null,
t1.updated_time = NOW()
where t1.user_id = #{entmicroFollowerStaffRequest.userId}
and t2.relevance_merchant = #{entmicroFollowerStaffRequest.merchantId}
</update>
<update id="saveEntmicroFollowerStaff"
parameterType="cn.com.glsx.entmicro.model.request.EntmicroFollowerStaffRequest">
<if test="entmicroFollowerStaffRequest.userIds.size() > 0 and entmicroFollowerStaffRequest.userIds != null">
update entmicro_staff t1
inner join entmicro_staff_depart_relation t2 on t1.id = t2.staff_id
set t1.follower_type_id = #{entmicroFollowerStaffRequest.followerTypeId},
t1.follower_created_time = #{entmicroFollowerStaffRequest.followerCreatedTime}
<if test="entmicroFollowerStaffRequest.businessTypeId != null">
,t1.business_type = #{entmicroFollowerStaffRequest.businessTypeId}
</if>
where t1.user_id in
<foreach collection="entmicroFollowerStaffRequest.userIds" item="item" separator="," open="(" close=")">
#{item}
</foreach>
and t2.relevance_merchant = #{entmicroFollowerStaffRequest.merchantId}
</if>
</update>
<!--找出关联商户号的门店
找出这个门店id的所有子id
找出所有子id的关联商户号
找出当前商户所有员工
-->
<select id="findStaffByMerchantId" resultMap="resultMap">
SELECT es.*,
esdr.user_oneid
FROM entmicro_staff es
LEFT JOIN `entmicro_staff_depart_relation` esdr ON es.id = esdr.staff_id AND esdr.del_flag = 0
WHERE esdr.relevance_merchant IN
(SELECT merchantId
FROM entmicro_department
WHERE id IN
(SELECT sub_id
FROM entmicro_department_path
WHERE superior_id = (SELECT MIN(id)
FROM entmicro_department
WHERE relevance_merchant =#{merchantId}
AND del_flag = 0)
)
AND del_flag = 0)
AND es.del_flag != -1
<if test="staffName != null and staffName != ''">
and es.staff_name like concat('%', #{staffName}, '%')
</if>
<if test="staffPhone != null and staffPhone != ''">
and es.staff_Phone=#{staffPhone}
</if>
<if test="id != null ">
and es.id=#{id}
</if>
GROUP BY es.id
</select>
<update id="updateAddOutsider">
update entmicro_staff t1
left join entmicro_staff_depart_relation t2 on t1.id = t2.staff_id
set t1.is_add_outsider = #{isAddOutsider}
where t1.user_id in
<foreach collection="userId" separator="," item="item" open="(" close=")">
#{item}
</foreach>
and t1.del_flag != -1
and t2.relevance_merchant = #{merchantId}
</update>
<update id="updateStaffDepart">
update entmicro_staff_depart_relation set relevance_merchant=#{merchantId} where
staff_id in
<foreach collection="ids" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
and
department_id in
<foreach collection="departIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</update>
<update id="updateUUID">
<foreach collection="dictDataResponseList" item="item" index="index" open="" close="" separator=";">
update entmicro_staff_depart_relation t1,entmicro_staff t2
<set>
t1.user_oneid = #{item.uuid},
</set>
where t1.staff_id=t2.id and t1.relevance_merchant=#{item.merchantId} and t2.staff_phone =#{item.staffPhone}
</foreach>
</update>
<update id="automaticOffline">
UPDATE entmicro_staff
SET login_status=0
WHERE last_login_time IS NOT NULL
AND last_login_time<![CDATA[ < ]]> date_sub(NOW(),
INTERVAL +1 MINUTE)
AND login_status = 1
</update>
<select id="findStaffMapByUserIds" resultMap="resultMap">
SELECT
t1.id, t1.staff_name, t1.staff_email, t1.updated_by,
t1. updated_time, t1.del_flag, t1.staff_phone, t1.is_add_outsider, t1.user_id, t1.open_userid, t1.entmicro_name,
t1.follower_type_id, t1.staff_title, t1.follower_created_time, t1.status
,t2.relevance_merchant as merchantId
FROM
entmicro_staff t1
left join entmicro_staff_depart_relation t2 on t1.id=t2.staff_id
WHERE
t1.del_flag != - 1
AND user_id IN
<foreach collection="userids" item="userid" open="(" close=")" separator=",">
#{userid}
</foreach>
AND t2.relevance_merchant in
(select relevance_merchant from entmicro_department
where id in
(select sub_id from entmicro_department_path
where superior_id =(SELECT min(id) from entmicro_department
where relevance_merchant =#{merchantId} and del_flag = 0))
and relevance_merchant is not null group by relevance_merchant)
group by t1.id
</select>
<select id="findStaffListByUserIds" resultMap="resultMap">
SELECT
t1.id,
t1.staff_name,
t1.staff_email,
t1.updated_by,
t1. updated_time,
t1.del_flag,
t1.staff_phone,
t1.is_add_outsider,
t1.user_id,
t1.open_userid,
t1.entmicro_name,
t1.follower_type_id,
t1.staff_title,
t1.follower_created_time,
t1.status,
t2.relevance_merchant as merchantId,
t2.user_oneid,
t1.thumb_Avatar as thumbAvatar
FROM
entmicro_staff t1
left join entmicro_staff_depart_relation t2 on t1.id=t2.staff_id
WHERE
t1.del_flag != - 1
AND user_id IN
<foreach collection="userids" item="userid" open="(" close=")" separator=",">
#{userid}
</foreach>
AND t2.relevance_merchant in
(select relevance_merchant from entmicro_department
where id in
(select sub_id from entmicro_department_path
where superior_id =(SELECT min(id) from entmicro_department
where relevance_merchant =#{merchantId} and del_flag = 0))
and relevance_merchant is not null group by relevance_merchant)
group by t1.id
</select>
<select id="findStaffByFollowIds" resultMap="resultFollowMap">
select es.*,ecf.id follow_id
from entmicro_staff es
left join entmicro_customer_follow ecf on ecf.staff_id = es.id
where es.del_flag = 0 and ecf.id in
<foreach collection="followIds" item="followId" open="(" close=")" separator=",">
#{followId}
</foreach>
</select>
<select id="findMerchantIdsByStaffIds" resultType="java.lang.String">
select esdr.relevance_merchant
from entmicro_staff es
left join entmicro_staff_depart_relation esdr on esdr.staff_id = es.id
where es.del_flag = 0
and esdr.del_flag = 0
and es.id in
<foreach collection="staffIds" item="staffId" open="(" close=")" separator=",">
#{staffId}
</foreach>
</select>
<select id="listIsAddOutSiderStaff"
resultMap="resultMap"
parameterType="cn.com.glsx.entmicro.model.request.EntmicroStaffRequest">
select t1.id, t1.staff_name,
t1.user_id, t1.staff_title,
t1.merchantId, t1.follower_type_id,
t2.department_id
from entmicro_staff t1
left join entmicro_staff_depart_relation t2
on t1.id = t2.staff_id and t2.del_flag = 0
left join entmicro_department t3
on t3.id = t2.department_id and t3.del_flag = 0
where t1.del_flag = 0
and t1.is_add_outsider = 0
and t1.follower_type_id is null
and t2.relevance_merchant = #{entmicroStaffRequest.merchantId}
<if test="entmicroStaffRequest.staffName != null and entmicroStaffRequest.staffName != ''">
and (FIND_IN_SET(#{entmicroStaffRequest.staffName},t1.staff_name))
</if>
<if test="entmicroStaffRequest.departmentId != null">
and t2.department_id in (select * from
(select #{entmicroStaffRequest.departmentId}
union all
(select sub_id from entmicro_department_path where superior_id = #{entmicroStaffRequest.departmentId} and
superior_id != sub_id and del_flag = 0 order by depth)) as t3)
</if>
group by t1.id
</select>
<select id="findStaffByDepartment" resultMap="resultMap">
select *
from entmicro_staff t1
left join entmicro_staff_depart_relation t2 on t1.id=t2.staff_id
where t2.relevance_merchant in
(SELECT merchantId from entmicro_department where id in(select sub_id from entmicro_department_path where
superior_id=(select min(superior_id) from entmicro_department_path where sub_id =(SELECT min(id) from
entmicro_department where merchantId =#{merchantId} and del_flag = 0))))
<if test="departmentId != null and departmentId.size>0">
and t2.department_id in
<foreach collection="departmentId" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
and t1.del_flag != -1
and t2.del_flag != -1
GROUP BY
t1.id
</select>
<select id="findByMerchantIdAndUserId" resultMap="resultMap">
select * from entmicro_staff t1
left join entmicro_staff_depart_relation t2 on t1.id=t2.staff_id
where t1.user_id=#{entmicroStaff.userId}
and t1.del_flag != -1
<if test="list != null">
and t2.relevance_merchant in
<foreach collection="list" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
group by staff_id
</select>
<!--根据关联表Id获取员工信息-->
<select id="getStaffById" resultMap="resultMap">
select t1.id,
t2.staff_name,
t2.user_id
from entmicro_staff_depart_relation t1
left join entmicro_staff t2 on t1.staff_id = t2.id
where t1.del_flag != -1
and t1.id in
<foreach collection="staffIdList" open="(" separator="," close=")" item="item">
#{item}
</foreach>
</select>
<select id="findFollowStaff" resultMap="resultMap">
select * from entmicro_staff t1
left join entmicro_follower_type t2 on t1.follower_type_id=t2.id
left join entmicro_staff_depart_relation t3 ON t1.id=t3.staff_id
where
t3.relevance_merchant=#{staffRequestDTO.merchantId}
and t3.del_flag=0
<if test="staffRequestDTO.followTypes != null and staffRequestDTO.followTypes.size>0">
and t2.defalut_code in
<foreach collection="staffRequestDTO.followTypes" open="(" separator="," close=")" item="item">
#{item}
</foreach>
</if>
<if test="staffRequestDTO.userUuid != null and staffRequestDTO.userUuid != ''">
and t3.user_oneid = #{staffRequestDTO.userUuid}
</if>
group by t3.staff_id
</select>
<select id="findStaffDetail" resultMap="resultMap">
select t1.`id` AS id,
t1.`staff_name` AS staffName,
t3.`department_id` AS departmentId,
t1.`staff_email` AS staffEmial,
t1.`created_by` AS createdBy,
t1.`created_time` AS createdTime,
t1.`updated_by` AS updatedBy,
t1.`updated_time` AS updatedTime,
t1.`del_flag` AS delFlag,
t1.`staff_phone` AS staffPhone,
t1.`is_add_outsider` AS isAddOutsider,
t1.`user_id` AS userId,
t1.`open_userid` AS openUserid,
t1.`entmicro_name` AS entmicroName,
t1.`follower_type_id` AS followerTypeId,
t1.`staff_title` AS staffTitle,
t1.`follower_created_time` AS followerCreatedTime,
t1.`merchantId` AS merchantId,
t1.`status` AS `status`,
t3.`relevance_merchant` AS relevanceMerchant,
t1.`qr_code` AS qrCode,
t1.`thumb_avatar` AS thumbAvatar,
t3.`staff_id` AS staffId,
t3.`user_oneid` AS userOneid
from entmicro_staff t1
left join entmicro_staff_depart_relation t3 on t1.id = t3.staff_id
where t3.user_oneid = #{userUuid}
AND t1.del_flag = 0
group by t3.staff_id
</select>
<select id="findStaffDetailByRelationId" resultType="cn.com.glsx.entmicro.model.response.EntmicroStaffResponse">
select t3.id,t1.user_id as userId,t3.relevance_merchant as merchantId from entmicro_staff t1
left join entmicro_staff_depart_relation t3 on t1.id=t3.staff_id
where t3.id in
<foreach collection="integerList" open="(" separator="," close=")" item="item">
#{item}
</foreach>
</select>
<select id="findStaffByDepartmentIds"
resultMap="resultMap">
select t1.*,t3.department_id as departmentId,t2.follow_name,t4.department_name
from entmicro_staff t1
left join entmicro_staff_depart_relation t3 on t1.id=t3.staff_id
left join entmicro_department t4 on t4.id=t3.department_id
left join entmicro_follower_type t2 on t1.follower_type_id=t2.id
where t3.del_flag=0
and t3.department_id in
<foreach collection="list" open="(" separator="," close=")" item="item">
#{item}
</foreach>
<if test="isfollower != null and isfollower">
and t1.follower_type_id is not null
</if>
</select>
<select id="findStaffDetailById" resultMap="resultMap">
select * from entmicro_staff
where 1=1
<if test="list != null and list.size>0">
and id in
<foreach collection="list" open="(" separator="," close=")" item="item">
#{item}
</foreach>
</if>
<if test="staffName != null and staffName!=''">
and staff_Name like concat('%',#{staffName},'%')
</if>
</select>
<select id="findStaffByuuid" resultMap="resultMap">
select t1.*
from entmicro_staff t1
left join entmicro_staff_depart_relation t3 on t1.id = t3.staff_id
where user_oneid = #{uuid}
group by t1.id
</select>
<select id="findlistEntmicroStaff" resultMap="resultMap">
select t1.*, t3.user_oneid
from entmicro_staff t1
left join entmicro_staff_depart_relation t3 on t1.id = t3.staff_id
where relevance_merchant = #{entmicroStaffRequest.merchantId}
and is_add_outsider = 0
</select>
<!--根据Id获取员工信息-->
<select id="getStaffByIds" resultMap="resultMap">
select
<include refid="Base_Column_List"/>
from entmicro_staff
where id in
<foreach collection="staffIdList" open="(" separator="," close=")" item="item">
#{item}
</foreach>
</select>
<select id="findHavingCustomer" resultType="java.lang.String">
select t1.user_id from entmicro_staff t1
left join entmicro_customer_follow t2 on t1.id=t2.staff_id
left join scrm_customer t4 on t2.customer_id=t4.id
left join entmicro_staff_depart_relation t3 on t1.id=t3.staff_id
where t2.id is not null and t3.relevance_merchant=#{merchantId} and t3.del_flag=0
<if test="flag != null and flag">
and t4.type=1
</if>
group by t1.user_id
</select>
<select id="findLordGroup" resultMap="resultMap">
SELECT *,count(t.id) AS chatCount FROM
(SELECT
t3.`id` AS id,
t3.staff_name AS staff_name,
t3.department_id AS department_id,
t3.staff_email AS staff_email,
t3.created_by AS created_by,
t3.created_time AS created_time,
t3.updated_by AS updated_by,
t3.updated_time AS updated_time,
t3.del_flag AS del_flag,
t3.staff_phone AS staff_phone,
t3.is_add_outsider AS is_add_outsider,
t3.user_id AS user_id,
t3.open_userid AS open_userid,
t3.entmicro_name AS entmicro_name,
t3.follower_type_id AS follower_type_id,
t3.staff_title AS staff_title,
t3.follower_created_time AS follower_created_time,
t3.merchantId AS merchantId,
t3.status AS STATUS,
t3.staff_sex AS staff_sex,
t3.staff_uuid AS staff_uuid,
t3.qr_code AS qr_code,
t3.thumb_avatar AS thumb_avatar,
t6.department_name AS department_name,
t5.`follow_name` AS followerTypeName
FROM `scrm_customer_base` t1
LEFT JOIN `scrm_customer_base_relation` t2 ON t2.`customer_base_id`=t1.`id` AND t2.`del_flag`=0
LEFT JOIN `entmicro_staff` t3 ON t3.`id`=t2.`customer_id` AND t3.`del_flag`=0
LEFT JOIN `entmicro_staff_depart_relation` t4 ON t4.`staff_id`=t3.`id` AND t4.`del_flag`=0
LEFT JOIN `entmicro_follower_type` t5 ON t5.`id`=t3.`follower_type_id` AND t5.`del_flag`=0
LEFT JOIN `entmicro_department` t6 ON t6.`id`=t4.`department_id` AND t6.`del_flag`=0
WHERE t2.`type`=1 AND t1.`lord`=t3.`user_id` AND t1.`del_flag`=0
AND t4.`relevance_merchant`=#{obj.merchantId}
<if test="obj.chatName != null and obj.chatName != ''">
and t1.chat_name like concat('%',#{obj.chatName},'%')
</if>
<if test="obj.lordName != null and obj.lordName != ''">
and t3.staff_name like concat('%',#{obj.lordName},'%')
</if>
<if test="obj.departmentId != null ">
and t4.department_id=#{obj.departmentId}
</if>
<if test="obj.followerId != null ">
and t5.id=#{obj.followerId}
</if>
GROUP BY t1.`chat_id`) AS t
GROUP BY t.id
</select>
<select id="findStaffByEntDepartment"
resultMap="resultMap">
select *
from entmicro_staff t1
left join entmicro_staff_depart_relation t2 on t1.id=t2.staff_id
LEFT JOIN entmicro_department t3 ON t2.department_id=t3.id
where 1=1
<if test="list != null and list.size>0">
and t2.relevance_merchant in
<foreach collection="list" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="departmentIds != null and departmentIds.size>0">
AND t3.id in
<foreach collection="departmentIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
AND t3.del_flag=0
and t1.del_flag != -1
and t2.del_flag != -1
GROUP BY
t1.id
</select>
<select id="listStaffByDefalutCode" resultType="cn.com.glsx.entmicro.model.response.EntmicroStaffResponse">
SELECT t1.id,
t1.staff_name
FROM entmicro_staff t1
LEFT JOIN entmicro_follower_type t2 ON t1.follower_type_id = t2.id AND t2.del_flag = 0
LEFT JOIN `entmicro_staff_depart_relation` esdr ON t1.id = esdr.staff_id
WHERE t1.del_flag = 0
AND esdr.del_flag = 0
AND t2.defalut_code = #{defalutCode}
AND esdr.relevance_merchant = #{merchantId}
</select>
<select id="findStaffIdByCustomerIds"
resultMap="resultMap">
select es.id as id,es.staff_name,es.staff_phone,es.user_id,scm.id as customerId,er.relevance_merchant as
merchantId,
er.user_oneid,ef.created_time follower_created_time,es.business_type, es.follower_type_id, t2.follow_name
followerTypeName
from
scrm_customer_merge scm
left join scrm_customer sc on scm.one_id=sc.one_id
left join entmicro_customer_follow ef on ef.customer_id=sc.id
left join entmicro_staff es on ef.staff_id=es.id
left join entmicro_staff_depart_relation er on er.staff_id=es.id
LEFT JOIN entmicro_follower_type t2 ON es.follower_type_id = t2.id AND t2.del_flag = 0
where sc.del_flag=0 and ef.del_flag=0 and es.del_flag=0 and er.del_flag=0
and scm.id in
<foreach collection="mergeId" open="(" separator="," close=")" item="item">
#{item}
</foreach>
</select>
<select id="findStaffDetailByUserIds" resultMap="resultMap">
select t1.* from entmicro_staff t1
left join entmicro_staff_depart_relation t3 on t1.id=t3.staff_id
where t3.relevance_merchant=#{merchantId}
and t1.user_id in
<foreach collection="userIds" open="(" separator="," close=")" item="item">
#{item}
</foreach>
group by t1.user_id
</select>
<select id="getFollowerByCusUserId" resultMap="resultMap">
SELECT es.user_id,
esdr.relevance_merchant merchantId
FROM `entmicro_staff` es
LEFT JOIN `entmicro_staff_depart_relation` esdr ON (esdr.staff_id = es.id AND esdr.del_flag = 0)
LEFT JOIN `entmicro_customer_follow` ecf ON ecf.staff_id = es.id
LEFT JOIN `scrm_customer` sc ON sc.id = ecf.customer_id
WHERE sc.user_id = #{userId}
AND ecf.del_flag = 0
GROUP BY es.id
</select>
<select id="getEntmicroByBusinessType" resultMap="resultMap">
select
t1.`id` AS id,
t1.user_id AS user_id,
t1.staff_uuid AS user_oneid
from entmicro_staff t1
left join entmicro_staff_depart_relation t2 on t1.id = t2.staff_id
where t2.relevance_merchant=#{merchantId}
and
<foreach collection="typeArray" separator="or" item="item">
FIND_IN_SET(#{item}, t1.business_type)
</foreach>
and t1.del_flag = 0
group by t1.id
</select>
<select id="filterFollowerListByCondition"
resultType="cn.com.glsx.entmicro.model.response.StaffFollowResponse">
SELECT DISTINCT c.`id` customerId,c.`one_id` oneId,c.`customer_name` customerName,s.`id` staffId,s.`staff_name`
staffName
FROM `scrm_customer` c
LEFT JOIN `entmicro_customer_follow` f ON f.`customer_id`=c.`id`
LEFT JOIN `entmicro_staff` s ON s.`id`=f.`staff_id`
LEFT JOIN `entmicro_staff_depart_relation` r ON r.`staff_id`=s.`id`
WHERE r.`relevance_merchant`=#{merchantId}
AND c.`one_id` IN
<foreach collection="oneIds" open="(" separator="," close=")" item="oneId">
#{oneId}
</foreach>
AND c.`del_flag`=0
AND f.`del_flag`=0
AND s.`del_flag`=0
AND r.`del_flag`=0
</select>
<select id="findMerchantStartStaff" resultMap="resultMap">
SELECT t1.*,GROUP_CONCAT(t3.department_name) departmentName FROM entmicro_staff t1
left join entmicro_staff_depart_relation t2
ON t1.id = t2.staff_id AND t2.del_flag = 0
left join entmicro_department t3
ON t3.id = t2.department_id AND t3.del_flag = 0
WHERE t1.CREATED_BY=#{merchantStartStaffRequest.merchantId} and t1.del_flag != -1
<if test="merchantStartStaffRequest.staffName != null and merchantStartStaffRequest.staffName!=''">
and t1.staff_Name like concat('%',#{merchantStartStaffRequest.staffName},'%')
</if>
GROUP BY t1.user_id
</select>
<select id="findDepartByMerIdAndId" resultType="java.util.Map">
select t1.staff_id,GROUP_CONCAT(t2.department_name) department_name
from entmicro_staff_depart_relation t1
LEFT JOIN entmicro_department t2
ON t1.department_id = t2.id AND t2.del_flag = 0
where t1.staff_id in
<foreach collection="staffIds" open="(" separator="," close=")" item="item">
#{item}
</foreach>
and t1.relevance_merchant=#{merchantId} and t1.del_flag=0
group by t1.staff_id
</select>
<select id="wechatDepositList" resultMap="resultMap">
SELECT t1.*,t2.entmicro_name as entmicroName,t3.relevance_merchant
FROM entmicro_staff t1
left join entmicro_authorize t2 ON t1.created_by = t2.merchant_id
left join entmicro_staff_depart_relation t3 on t1.id=t3.staff_id
WHERE t1.del_flag=0 and status=1 and t3.del_flag=0 and t3.relevance_merchant is not null and t1.login_status is
not null and t1.entmicro_id is null
<if test="condition.staffName != null and condition.staffName!=''">
and t1.staff_Name like concat('%',#{condition.staffName},'%')
</if>
<if test="condition.staffPhone != null and condition.staffPhone!=''">
and t1.staff_phone like concat('%',#{condition.staffPhone},'%')
</if>
<if test="condition.entmicroName != null and condition.entmicroName!=''">
and t2.entmicro_name like concat('%',#{condition.entmicroName},'%')
</if>
<if test="condition.loginStatus != null">
and t1.login_status=#{condition.loginStatus}
</if>
GROUP BY t1.created_by,t1.user_id
order by t1.last_login_time desc
</select>
<select id="findStaffByPhoneAndMerchantNo" resultMap="baseResultMap">
select * from entmicro_staff
where del_flag=0
<if test="loginCallBackModel.mobile != null and loginCallBackModel.mobile!=''">
and staff_phone=#{loginCallBackModel.mobile}
</if>
<if test="loginCallBackModel.merchantNo != null ">
and created_by=#{loginCallBackModel.merchantNo}
</if>
<if test="loginCallBackModel.userId != null and loginCallBackModel.userId!=''">
and id_Bef_Encryption=#{loginCallBackModel.userId}
</if>
<if test="loginCallBackModel.entmicroId != null and loginCallBackModel.entmicroId!=''">
and entmicro_id=#{loginCallBackModel.entmicroId}
</if>
</select>
<select id="findMerchantListByStaffIds" resultType="java.util.Map">
select distinct esdr.relevance_merchant
from entmicro_staff es
left join entmicro_staff_depart_relation esdr on esdr.staff_id = es.id
where es.del_flag = 0
and esdr.del_flag = 0 and esdr.relevance_merchant is not null
and es.id in
<foreach collection="staffIds" item="staffId" open="(" close=")" separator=",">
#{staffId}
</foreach>
</select>
<select id="findMerchantListByUserIds" resultMap="resultMap">
select es.id,group_concat(distinct esdr.relevance_merchant) as merchantIds
from entmicro_staff es
left join entmicro_staff_depart_relation esdr on esdr.staff_id = es.id
where es.del_flag = 0
and esdr.del_flag = 0 and esdr.relevance_merchant is not null and esdr.relevance_merchant!=''
and es.id in
<foreach collection="staffIds" item="staffid" open="(" close=")" separator=",">
#{staffid}
</foreach>
group by es.id,es.created_by
</select>
<select id="listEntmicroFollower"
parameterType="cn.com.glsx.entmicro.model.request.EntmicroFollowerStaffRequest"
resultMap="followerStaffResultMap">
SELECT
t1.id,
t1.staff_name,
t3.follow_name,
t1.staff_phone,
t1.follower_created_time,
t1.del_flag,
t1.is_add_outsider,
t1.user_id
FROM
entmicro_staff t1
INNER JOIN entmicro_follower_type t3
ON t1.follower_type_id = t3.id
AND t3.del_flag = 0
WHERE t1.follower_type_id IS NOT NULL
AND t1.del_flag = 0
<if test=" userId != null and userId != ''">
and t1.user_id = #{userId}
AND t1.created_by = #{merchantId}
</if>
<if test="merchantIds != null and merchantIds.size > 0">
and t1.created_by in
<foreach collection="merchantIds" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="followerTypeNameList != null and followerTypeNameList.size > 0">
and t3.follow_name in
<foreach collection="followerTypeNameList" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
GROUP BY t1.id
</select>
<select id="wechatDepositNotAccessList" resultMap="resultMap">
SELECT t1.*,t2.entmicro_name as entmicroName
FROM entmicro_staff t1
left join entmicro_authorize t2 ON t1.entmicro_id = t2.id
WHERE t1.entmicro_id is not null
<if test="condition.staffName != null and condition.staffName!=''">
and t1.staff_Name like concat('%',#{condition.staffName},'%')
</if>
<if test="condition.staffPhone != null and condition.staffPhone!=''">
and t1.staff_phone like concat('%',#{condition.staffPhone},'%')
</if>
<if test="condition.entmicroName != null and condition.entmicroName!=''">
and t2.entmicro_name like concat('%',#{condition.entmicroName},'%')
</if>
<if test="condition.loginStatus != null">
and t1.login_status=#{condition.loginStatus}
</if>
order by t1.last_login_time desc
</select>
<select id="findStaffByEncryptionIds" resultMap="baseResultMap">
select * from entmicro_staff t1
left join scrm_subscribe_merchant t2 on t1.id=t2.welfare_man_id
where t1.del_flag=0 and t2.del_flag=0
and id_Bef_Encryption in
<foreach collection="list" item="userid" open="(" close=")" separator=",">
#{userid}
</foreach>
</select>
<select id="findFollowNameByIds" resultType="java.util.Map">
select id,follow_name from entmicro_follower_type where del_flag = 0
and id in
<foreach collection="list" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="findStaffByPhoneListAndMerchantNo" resultMap="baseResultMap">
select * from entmicro_staff
where del_flag=0
<if test="phoneList != null and phoneList.size>0">
and staff_phone in
<foreach collection="phoneList" item="phone" open="(" close=")" separator=",">
#{phone}
</foreach>
</if>
<if test="merchantNo != null ">
and created_by=#{merchantNo}
</if>
</select>
<select id="findStaffListByPhone" resultMap="resultMap">
select t1.*, t3.user_oneid
from entmicro_staff t1
left join entmicro_staff_depart_relation t3 on t1.id = t3.staff_id
where relevance_merchant = #{entmicroStaffRequest.merchantId}
<if test="entmicroStaffRequest.staffPhone != null and entmicroStaffRequest.staffPhone!=''">
and t1.staff_phone=#{entmicroStaffRequest.staffPhone}
</if>
and is_add_outsider = 0
group by t1.id
</select>
<select id="findStaffListByMerchantIdList" resultMap="resultMap">
select
t1.id, t1.staff_name, t1.staff_email, t1.staff_phone, t1.user_id, t1.open_userid, t1.created_by merchantId, t1.staff_uuid,
ed.department_name, t1.created_by merchant_id
from entmicro_staff t1
left join entmicro_department ed on t1.created_by = ed.relevance_merchant and ed.del_flag = 0
where t1.del_flag = 0
and t1.created_by in
<foreach collection="entmicroStaffRequest.merchantIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
group by t1.created_by,t1.staff_uuid
</select>
<select id="findMerchantstaffDetail" resultMap="resultMap">
select * from entmicro_staff where del_flag = 0 and
<foreach collection="list" item="item" index="index" open="(" close=")" separator="or">
(created_by = #{item.merchantId} and staff_phone = #{item.staffPhone})
</foreach>
</select>
</mapper>