yangys
2024-03-27 e48aa2ac8dea1be5db11c63edf0b912c4ad5ce65
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
package com.qianwen.smartman.modules.sync.service.impl;
 
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.request.OapiRoleGetroleRequest;
import com.dingtalk.api.request.OapiV2DepartmentGetRequest;
import com.dingtalk.api.request.OapiV2UserGetRequest;
import com.dingtalk.api.response.OapiGettokenResponse;
import com.dingtalk.api.response.OapiRoleGetroleResponse;
import com.dingtalk.api.response.OapiV2DepartmentGetResponse;
import com.dingtalk.api.response.OapiV2UserGetResponse;
import java.lang.invoke.SerializedLambda;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.qianwen.smartman.common.cache.RegionCache;
import com.qianwen.smartman.common.constant.CommonConstant;
import com.qianwen.smartman.common.constant.CommonGroupConstant;
import com.qianwen.smartman.common.constant.DncConstant;
import com.qianwen.smartman.common.enums.CommonGroupTypeEnum;
import com.qianwen.core.redis.cache.BladeRedis;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.cps.entity.CommonGroup;
import com.qianwen.smartman.modules.cps.entity.CommonGroupOfItem;
import com.qianwen.smartman.modules.cps.entity.Employee;
import com.qianwen.smartman.modules.cps.entity.EmployeePost;
import com.qianwen.smartman.modules.cps.mapper.CommonGroupMapper;
import com.qianwen.smartman.modules.cps.service.ICommonGroupOfItemService;
import com.qianwen.smartman.modules.cps.service.ICommonGroupService;
import com.qianwen.smartman.modules.cps.service.IEmployeePostService;
import com.qianwen.smartman.modules.cps.service.IEmployeeService;
import com.qianwen.smartman.modules.sync.constant.DingConstant;
import com.qianwen.smartman.modules.sync.constant.QyWechatConstant;
import com.qianwen.smartman.modules.sync.entity.DingUserInnerRole;
import com.qianwen.smartman.modules.sync.entity.OuterAppConfig;
import com.qianwen.smartman.modules.sync.enums.DingEventEnum;
import com.qianwen.smartman.modules.sync.service.IDingEventService;
import com.qianwen.smartman.modules.sync.util.DingCallbackCrypto;
import com.qianwen.smartman.modules.system.entity.Post;
import com.qianwen.smartman.modules.system.entity.UserOauth;
import com.qianwen.smartman.modules.system.mapper.PostMapper;
import com.qianwen.smartman.modules.system.service.IParamService;
import com.qianwen.smartman.modules.system.service.IPostService;
import com.qianwen.smartman.modules.system.service.IUserOauthService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/sync/service/impl/DingEventServiceImpl.class */
public class DingEventServiceImpl implements IDingEventService {
    private static final Logger log = LoggerFactory.getLogger(DingEventServiceImpl.class);
    private final IUserOauthService userOauthService;
    private final IEmployeeService employeeService;
    private final ICommonGroupService groupService;
    private final CommonGroupMapper commonGroupMapper;
    private final BladeRedis bladeRedis;
    private final IEmployeePostService employeePostService;
    private final ICommonGroupOfItemService commonGroupOfItemService;
    private final IPostService postService;
    private final PostMapper postMapper;
    private final IParamService paramService;
 
    private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
        String implMethodName = lambda.getImplMethodName();
        boolean z = true;
        switch (implMethodName.hashCode()) {
            case -1492577373:
                if (implMethodName.equals("getGroupType")) {
                    z = true;
                    break;
                }
                break;
            case -1249349403:
                if (implMethodName.equals("getTel")) {
                    z = true;
                    break;
                }
                break;
            case -129715105:
                if (implMethodName.equals("getEmployeeId")) {
                    z = true;
                    break;
                }
                break;
            case -75080655:
                if (implMethodName.equals("getUuid")) {
                    z = true;
                    break;
                }
                break;
            case 98245393:
                if (implMethodName.equals("getId")) {
                    z = true;
                    break;
                }
                break;
            case 517353092:
                if (implMethodName.equals("getItemId")) {
                    z = false;
                    break;
                }
                break;
            case 713563345:
                if (implMethodName.equals("getPostId")) {
                    z = true;
                    break;
                }
                break;
            case 1330288580:
                if (implMethodName.equals("getGroupId")) {
                    z = true;
                    break;
                }
                break;
        }
        switch (z) {
            case false:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/CommonGroupOfItem") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getItemId();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/CommonGroupOfItem") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getItemId();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/UserOauth") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getUuid();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/UserOauth") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getUuid();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/UserOauth") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getUuid();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/EmployeePost") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getPostId();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/CommonGroupOfItem") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getGroupType();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/CommonGroupOfItem") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getGroupType();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/CommonGroupOfItem") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getGroupType();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/CommonGroupOfItem") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getGroupType();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getId();
                    };
                }
                break;
            case RegionCache.VILLAGE_LEVEL /* 5 */:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/EmployeePost") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getEmployeeId();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/EmployeePost") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getEmployeeId();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/EmployeePost") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getEmployeeId();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/Employee") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getTel();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/Employee") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getTel();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/Employee") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getTel();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/CommonGroupOfItem") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getGroupId();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/CommonGroupOfItem") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getGroupId();
                    };
                }
                break;
        }
        throw new IllegalArgumentException("Invalid lambda deserialization");
    }
 
    public DingEventServiceImpl(final IUserOauthService userOauthService, final IEmployeeService employeeService, final ICommonGroupService groupService, final CommonGroupMapper commonGroupMapper, final BladeRedis bladeRedis, final IEmployeePostService employeePostService, final ICommonGroupOfItemService commonGroupOfItemService, final IPostService postService, final PostMapper postMapper, final IParamService paramService) {
        this.userOauthService = userOauthService;
        this.employeeService = employeeService;
        this.groupService = groupService;
        this.commonGroupMapper = commonGroupMapper;
        this.bladeRedis = bladeRedis;
        this.employeePostService = employeePostService;
        this.commonGroupOfItemService = commonGroupOfItemService;
        this.postService = postService;
        this.postMapper = postMapper;
        this.paramService = paramService;
    }
 
    @Override // org.springblade.modules.sync.service.IDingEventService
    @Async
    @Transactional
    public void handleEvent(DingCallbackCrypto callbackCrypto, String decryptMsg, OuterAppConfig outerAppConfig) {
        JSONObject eventJson = JSON.parseObject(decryptMsg);
        String eventType = eventJson.getString("EventType");
        String appKey = outerAppConfig.getDingAppKey();
        String appSecret = outerAppConfig.getDingAppSecret();
        switch (AnonymousClass1.$SwitchMap$org$springblade$modules$sync$enums$DingEventEnum[DingEventEnum.getValue(eventType).ordinal()]) {
            case 1:
                log.info("测试回调url的正确性");
                return;
            case 2:
                userAdd(eventJson, appKey, appSecret);
                return;
            case 3:
                userModify(eventJson, appKey, appSecret);
                return;
            case 4:
                userLeave(eventJson);
                return;
            case RegionCache.VILLAGE_LEVEL /* 5 */:
                deptCreate(eventJson, appKey, appSecret);
                return;
            case 6:
                deptModify(eventJson, appKey, appSecret);
                return;
            case 7:
                deptRemove(eventJson);
                return;
            case 8:
                labelUserChange(eventJson, appKey, appSecret);
                return;
            case 9:
                labelAdd(eventJson, appKey, appSecret);
                return;
            case 10:
                lableDel(eventJson);
                return;
            case 11:
                lableModify(eventJson, appKey, appSecret);
                return;
            default:
                return;
        }
    }
 
    /* renamed from: org.springblade.modules.sync.service.impl.DingEventServiceImpl$1  reason: invalid class name */
    /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/sync/service/impl/DingEventServiceImpl$1.class */
    static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] $SwitchMap$org$springblade$modules$sync$enums$DingEventEnum = new int[DingEventEnum.values().length];
 
        static {
            try {
                $SwitchMap$org$springblade$modules$sync$enums$DingEventEnum[DingEventEnum.CHECK_URL.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
            try {
                $SwitchMap$org$springblade$modules$sync$enums$DingEventEnum[DingEventEnum.USER_ADD_ORG.ordinal()] = 2;
            } catch (NoSuchFieldError e2) {
            }
            try {
                $SwitchMap$org$springblade$modules$sync$enums$DingEventEnum[DingEventEnum.USER_MODIFY_ORG.ordinal()] = 3;
            } catch (NoSuchFieldError e3) {
            }
            try {
                $SwitchMap$org$springblade$modules$sync$enums$DingEventEnum[DingEventEnum.USER_LEAVE_ORG.ordinal()] = 4;
            } catch (NoSuchFieldError e4) {
            }
            try {
                $SwitchMap$org$springblade$modules$sync$enums$DingEventEnum[DingEventEnum.ORG_DEPT_CREATE.ordinal()] = 5;
            } catch (NoSuchFieldError e5) {
            }
            try {
                $SwitchMap$org$springblade$modules$sync$enums$DingEventEnum[DingEventEnum.ORG_DEPT_MODIFY.ordinal()] = 6;
            } catch (NoSuchFieldError e6) {
            }
            try {
                $SwitchMap$org$springblade$modules$sync$enums$DingEventEnum[DingEventEnum.ORG_DEPT_REMOVE.ordinal()] = 7;
            } catch (NoSuchFieldError e7) {
            }
            try {
                $SwitchMap$org$springblade$modules$sync$enums$DingEventEnum[DingEventEnum.LABEL_USER_CHANGE.ordinal()] = 8;
            } catch (NoSuchFieldError e8) {
            }
            try {
                $SwitchMap$org$springblade$modules$sync$enums$DingEventEnum[DingEventEnum.LABEL_CONF_ADD.ordinal()] = 9;
            } catch (NoSuchFieldError e9) {
            }
            try {
                $SwitchMap$org$springblade$modules$sync$enums$DingEventEnum[DingEventEnum.LABEL_CONF_DEL.ordinal()] = 10;
            } catch (NoSuchFieldError e10) {
            }
            try {
                $SwitchMap$org$springblade$modules$sync$enums$DingEventEnum[DingEventEnum.LABEL_CONF_MODIFY.ordinal()] = 11;
            } catch (NoSuchFieldError e11) {
            }
        }
    }
 
    @Override // org.springblade.modules.sync.service.IDingEventService
    public void addNewEmployee(JSONObject userObject, UserOauth userOauth, Snowflake snowflake) {
        Employee newEmployee = new Employee();
        String pinValue = this.paramService.getValue("employee.default.pin");
        newEmployee.setPinCode(pinValue);
        newEmployee.setId(Long.valueOf(snowflake.nextId()));
        newEmployee.setName(userObject.getString("name"));
        newEmployee.setCode(IdUtil.randomUUID());
        newEmployee.setEmail(userObject.getString("email"));
        newEmployee.setTel(userObject.getString("mobile"));
        if (Func.isNotEmpty(userObject.get("hired_date"))) {
            newEmployee.setHireDate(new Date(userObject.getLong("hired_date").longValue()));
        }
        newEmployee.setJobNumber(userObject.getString("job_number"));
        newEmployee.setStatus(CommonConstant.ENABLE);
        newEmployee.setAvatar(userObject.getString("avatar"));
        newEmployee.setOrganizationId("1".equals(String.valueOf(userObject.getJSONArray("dept_id_list").get(0))) ? "3" : String.valueOf(userObject.getJSONArray("dept_id_list").get(0)));
        JSONArray roleList = userObject.getJSONArray("role_list");
        List<EmployeePost> employeePosts = new ArrayList<>();
        if (Func.isNotEmpty(roleList)) {
            List<DingUserInnerRole> innerRoles = roleList.toJavaList(DingUserInnerRole.class);
            String postStr = (String) innerRoles.stream().map(o -> {
                return String.valueOf(o.getId());
            }).collect(Collectors.joining(","));
            newEmployee.setPostId(postStr);
            for (DingUserInnerRole role : innerRoles) {
                EmployeePost employeePost = new EmployeePost();
                employeePost.setEmployeeId(newEmployee.getId());
                employeePost.setPostId(role.getId());
                employeePosts.add(employeePost);
            }
            this.employeePostService.saveBatch(employeePosts);
        }
        this.commonGroupOfItemService.save(CommonGroupOfItem.builder().groupId(Long.valueOf(newEmployee.getOrganizationId())).itemId(newEmployee.getId()).groupType(CommonGroupTypeEnum.ORGANIZATION.getName()).groupCategory(CommonGroupConstant.DEFAULT_CATEGORY).build());
        this.employeeService.save(newEmployee);
        userOauth.setUserId(newEmployee.getId());
    }
 
    private void userAdd(JSONObject eventJson, String appKey, String appSecret) {
        try {
            DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
            OapiV2UserGetRequest req = new OapiV2UserGetRequest();
            List<String> userIdList = eventJson.getJSONArray("UserId").toJavaList(String.class);
            Snowflake snowflake = IdUtil.createSnowflake(1L, 1L);
            for (String id : userIdList) {
                req.setUserid(id);
                OapiV2UserGetResponse rsp = defaultDingTalkClient.execute(req, getDingAccessToken(appKey, appSecret));
                JSONObject jsonObject = JSONObject.parseObject(rsp.getBody());
                if (jsonObject.getInteger(QyWechatConstant.ERROR_CODE_KEY).equals(DingConstant.SUCCESS)) {
                    JSONObject userObject = jsonObject.getJSONObject("result");
                    UserOauth newAuth = new UserOauth();
                    newAuth.setUuid(id);
                    newAuth.setUsername(userObject.getString("name"));
                    newAuth.setAvatar(userObject.getString("avatar"));
                    newAuth.setSource(DingConstant.DING_AUTH_KEY);
                    Employee employee = (Employee) this.employeeService.getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                        return v0.getTel();
                    }, userObject.getString("mobile")), false);
                    if (Func.isNotEmpty(employee)) {
                        updateEmployee(userObject, employee);
                        newAuth.setUserId(employee.getId());
                    } else {
                        addNewEmployee(userObject, newAuth, snowflake);
                    }
                    this.userOauthService.save(newAuth);
                }
            }
        } catch (Exception e) {
            log.error("通讯录用户增加异常,异常信息为:", e);
        }
    }
 
    private void userModify(JSONObject eventJson, String appKey, String appSecret) {
        try {
            DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
            OapiV2UserGetRequest req = new OapiV2UserGetRequest();
            List<String> userIdList = eventJson.getJSONArray("UserId").toJavaList(String.class);
            for (String id : userIdList) {
                req.setUserid(id);
                OapiV2UserGetResponse rsp = defaultDingTalkClient.execute(req, getDingAccessToken(appKey, appSecret));
                JSONObject jsonObject = JSONObject.parseObject(rsp.getBody());
                if (jsonObject.getInteger(QyWechatConstant.ERROR_CODE_KEY).equals(DingConstant.SUCCESS)) {
                    JSONObject userObject = jsonObject.getJSONObject("result");
                    UserOauth userOauth = (UserOauth) this.userOauthService.getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                        return v0.getUuid();
                    }, id), false);
                    Employee employee = (Employee) this.employeeService.getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                        return v0.getTel();
                    }, userObject.getString("mobile")), false);
                    userOauth.setUsername(userObject.getString("name"));
                    userOauth.setAvatar(userObject.getString("avatar"));
                    this.userOauthService.updateById(userOauth);
                    updateEmployee(userObject, employee);
                }
            }
        } catch (Exception e) {
            log.error("通讯录用户更改,异常信息为:", e);
        }
    }
 
    private void updateEmployee(JSONObject userObject, Employee employee) {
        if (Func.isEmpty(employee.getPinCode())) {
            String pinValue = this.paramService.getValue("employee.default.pin");
            employee.setPinCode(pinValue);
        }
        employee.setName(userObject.getString("name"));
        if (Func.isNotEmpty(userObject.getString("email"))) {
            employee.setEmail(userObject.getString("email"));
        }
        if (Func.isNotEmpty(userObject.get("hired_date"))) {
            employee.setHireDate(new Date(userObject.getLong("hired_date").longValue()));
        }
        if (Func.isNotEmpty(userObject.getString("job_number"))) {
            employee.setJobNumber(userObject.getString("job_number"));
        }
        if (Func.isNotEmpty(userObject.getString("avatar"))) {
            employee.setAvatar(userObject.getString("avatar"));
        }
        employee.setStatus(CommonConstant.ENABLE);
        employee.setOrganizationId("1".equals(String.valueOf(userObject.getJSONArray("dept_id_list").get(0))) ? "3" : String.valueOf(userObject.getJSONArray("dept_id_list").get(0)));
        JSONArray roleList = userObject.getJSONArray("role_list");
        List<EmployeePost> employeePosts = new ArrayList<>();
        if (Func.isNotEmpty(roleList)) {
            List<DingUserInnerRole> innerRoles = roleList.toJavaList(DingUserInnerRole.class);
            String postStr = (String) innerRoles.stream().map(o -> {
                return String.valueOf(o.getId());
            }).collect(Collectors.joining(","));
            employee.setPostId(postStr);
            for (DingUserInnerRole role : innerRoles) {
                EmployeePost employeePost = new EmployeePost();
                employeePost.setEmployeeId(employee.getId());
                employeePost.setPostId(role.getId());
                employeePosts.add(employeePost);
            }
            this.employeePostService.remove((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                return v0.getEmployeeId();
            }, employee.getId()));
            this.employeePostService.saveBatch(employeePosts);
        }
        this.commonGroupOfItemService.remove((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getItemId();
        }, employee.getId())).eq((v0) -> {
            return v0.getGroupType();
        }, CommonGroupTypeEnum.ORGANIZATION.getName()));
        this.commonGroupOfItemService.save(CommonGroupOfItem.builder().groupId(Long.valueOf(employee.getOrganizationId())).itemId(employee.getId()).groupType(CommonGroupTypeEnum.ORGANIZATION.getName()).groupCategory(CommonGroupConstant.DEFAULT_CATEGORY).build());
        this.employeeService.updateById(employee);
    }
 
    private void userLeave(JSONObject eventJson) {
        try {
            List<String> userIdList = eventJson.getJSONArray("UserId").toJavaList(String.class);
            List<UserOauth> userOauths = this.userOauthService.list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
                return v0.getUuid();
            }, userIdList));
            List<Long> empIds = (List) userOauths.stream().map((v0) -> {
                return v0.getUserId();
            }).collect(Collectors.toList());
            this.userOauthService.remove((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
                return v0.getUuid();
            }, userIdList));
            this.employeeService.remove((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
                return v0.getId();
            }, empIds));
            this.employeePostService.remove((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
                return v0.getEmployeeId();
            }, empIds));
            this.commonGroupOfItemService.remove((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().in((v0) -> {
                return v0.getItemId();
            }, empIds)).eq((v0) -> {
                return v0.getGroupType();
            }, CommonGroupTypeEnum.ORGANIZATION.getName()));
        } catch (Exception e) {
            log.error("通讯录用户离职,异常信息为:", e);
        }
    }
 
    private void deptCreate(JSONObject eventJson, String appKey, String appSecret) {
        try {
            List<String> deptIds = eventJson.getJSONArray("DeptId").toJavaList(String.class);
            for (String deptId : deptIds) {
                DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/get");
                OapiV2DepartmentGetRequest req = new OapiV2DepartmentGetRequest();
                req.setDeptId(Long.valueOf(deptId));
                OapiV2DepartmentGetResponse rsp = defaultDingTalkClient.execute(req, getDingAccessToken(appKey, appSecret));
                JSONObject jsonObject = JSONObject.parseObject(rsp.getBody());
                if (jsonObject.getInteger(QyWechatConstant.ERROR_CODE_KEY).equals(DingConstant.SUCCESS)) {
                    Map<String, Object> deptMap = (Map) jsonObject.get("result");
                    Long parentId = Long.valueOf(String.valueOf(deptMap.get("parent_id")));
                    this.groupService.insert(CommonGroup.builder().groupCategory(1).groupType(DingConstant.GROUPTYPE).parentId(Long.valueOf(parentId.equals(1L) ? 3L : parentId.longValue())).name(String.valueOf(deptMap.get("name"))).status(1).id(Long.valueOf(deptId)).build());
                }
            }
        } catch (Exception e) {
            log.error("通讯录企业部门创建,异常信息为:", e);
        }
    }
 
    public static void main(String[] args) {
        JSONObject jsonObject = JSONObject.parseObject("{\"errcode\":0,\"role\":{\"groupId\":2907093702,\"name\":\"角色222\"},\"errmsg\":\"ok\",\"request_id\":\"16mni2qt143fv\"}");
        Map<String, Object> roleMap = (Map) jsonObject.get("role");
        System.out.println(roleMap.get("groupId"));
    }
 
    private void deptModify(JSONObject eventJson, String appKey, String appSecret) {
        try {
            List<String> deptIds = eventJson.getJSONArray("DeptId").toJavaList(String.class);
            this.commonGroupMapper.removeOrgByIds(deptIds);
            this.commonGroupOfItemService.remove((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().in((v0) -> {
                return v0.getGroupId();
            }, deptIds)).eq((v0) -> {
                return v0.getGroupType();
            }, CommonGroupTypeEnum.ORGANIZATION.getName()));
            for (String deptId : deptIds) {
                DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/get");
                OapiV2DepartmentGetRequest req = new OapiV2DepartmentGetRequest();
                req.setDeptId(Long.valueOf(deptId));
                OapiV2DepartmentGetResponse rsp = defaultDingTalkClient.execute(req, getDingAccessToken(appKey, appSecret));
                JSONObject jsonObject = JSONObject.parseObject(rsp.getBody());
                if (jsonObject.getInteger(QyWechatConstant.ERROR_CODE_KEY).equals(DingConstant.SUCCESS)) {
                    Map<String, Object> deptMap = (Map) jsonObject.get("result");
                    Long parentId = Long.valueOf(String.valueOf(deptMap.get("parent_id")));
                    this.groupService.insert(CommonGroup.builder().groupCategory(1).groupType(DingConstant.GROUPTYPE).parentId(Long.valueOf(parentId.equals(1L) ? 3L : parentId.longValue())).name(String.valueOf(deptMap.get("name"))).status(1).id(Long.valueOf(deptId)).build());
                }
            }
        } catch (Exception e) {
            log.error("通讯录企业部门创建,异常信息为:", e);
        }
    }
 
    private void deptRemove(JSONObject eventJson) {
        try {
            List<String> deptIds = eventJson.getJSONArray("DeptId").toJavaList(String.class);
            this.commonGroupMapper.removeOrgByIds(deptIds);
            this.commonGroupOfItemService.remove((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().in((v0) -> {
                return v0.getGroupId();
            }, deptIds)).eq((v0) -> {
                return v0.getGroupType();
            }, CommonGroupTypeEnum.ORGANIZATION.getName()));
        } catch (Exception e) {
            log.error("通讯录用户离职,异常信息为:", e);
        }
    }
 
    private void labelUserChange(JSONObject eventJson, String appKey, String appSecret) {
        try {
            DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
            OapiV2UserGetRequest req = new OapiV2UserGetRequest();
            List<String> userIdList = eventJson.getJSONArray("UserIdList").toJavaList(String.class);
            List<Employee> employeesUpdate = new ArrayList<>();
            List<EmployeePost> employeePostsNew = new ArrayList<>();
            for (String id : userIdList) {
                req.setUserid(id);
                OapiV2UserGetResponse rsp = defaultDingTalkClient.execute(req, getDingAccessToken(appKey, appSecret));
                JSONObject jsonObject = JSONObject.parseObject(rsp.getBody());
                if (jsonObject.getInteger(QyWechatConstant.ERROR_CODE_KEY).equals(DingConstant.SUCCESS)) {
                    JSONObject userObject = jsonObject.getJSONObject("result");
                    Employee employee = (Employee) this.employeeService.getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                        return v0.getTel();
                    }, userObject.getString("mobile")), false);
                    JSONArray roleList = userObject.getJSONArray("role_list");
                    if (Func.isNotEmpty(roleList)) {
                        List<DingUserInnerRole> innerRoles = roleList.toJavaList(DingUserInnerRole.class);
                        String postStr = (String) innerRoles.stream().map(o -> {
                            return String.valueOf(o.getId());
                        }).collect(Collectors.joining(","));
                        employee.setPostId(postStr);
                        employeesUpdate.add(employee);
                        for (DingUserInnerRole role : innerRoles) {
                            EmployeePost employeePost = new EmployeePost();
                            employeePost.setEmployeeId(employee.getId());
                            employeePost.setPostId(role.getId());
                            employeePostsNew.add(employeePost);
                        }
                    }
                }
            }
            this.employeePostService.remove((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
                return v0.getEmployeeId();
            }, userIdList));
            if (Func.isNotEmpty(employeesUpdate)) {
                this.employeeService.updateBatchById(employeesUpdate);
            }
            if (Func.isNotEmpty(employeePostsNew)) {
                this.employeePostService.saveBatch(employeePostsNew);
            }
        } catch (Exception e) {
            log.error("员工角色信息发生变更,异常信息为:", e);
        }
    }
 
    private void labelAdd(JSONObject eventJson, String appKey, String appSecret) {
        try {
            List<String> roleIds = eventJson.getJSONArray("LabelIdList").toJavaList(String.class);
            List<Post> postList = new ArrayList<>();
            for (String roleId : roleIds) {
                getRoleDetail(roleId, postList, appKey, appSecret);
            }
            this.postService.saveBatch(postList);
        } catch (Exception e) {
            log.error("增加角色或者角色组,异常信息为:", e);
        }
    }
 
    private void lableModify(JSONObject eventJson, String appKey, String appSecret) {
        try {
            List<String> roleIds = eventJson.getJSONArray("LabelIdList").toJavaList(String.class);
            List<Post> postList = new ArrayList<>();
            for (String roleId : roleIds) {
                getRoleDetail(roleId, postList, appKey, appSecret);
            }
            this.postService.updateBatchById(postList);
        } catch (Exception e) {
            log.error("修改角色或者角色组,异常信息为:", e);
        }
    }
 
    private void getRoleDetail(String roleId, List<Post> postList, String appKey, String appSecret) throws Exception {
        DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/getrole");
        OapiRoleGetroleRequest req = new OapiRoleGetroleRequest();
        req.setRoleId(Long.valueOf(roleId));
        OapiRoleGetroleResponse rsp = defaultDingTalkClient.execute(req, getDingAccessToken(appKey, appSecret));
        JSONObject jsonObject = JSONObject.parseObject(rsp.getBody());
        if (jsonObject.getInteger(QyWechatConstant.ERROR_CODE_KEY).equals(DingConstant.SUCCESS) && Func.isNotEmpty(jsonObject.get("role"))) {
            Map<String, Object> roleMap = (Map) jsonObject.get("role");
            if (!DncConstant.DNC_DEFAULT_PARENT_ID.equals(String.valueOf(roleMap.get("groupId")))) {
                Post post = new Post();
                post.setPostCode(roleId);
                post.setId(Long.valueOf(roleId));
                post.setPostName(String.valueOf(roleMap.get("name")));
                post.setStatus(CommonConstant.ENABLE);
                postList.add(post);
            }
        }
    }
 
    private void lableDel(JSONObject eventJson) {
        try {
            List<String> roleIds = eventJson.getJSONArray("LabelIdList").toJavaList(String.class);
            this.postMapper.removePostByIds(roleIds);
            this.employeePostService.remove((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
                return v0.getPostId();
            }, roleIds));
        } catch (Exception e) {
            log.error("删除角色或者角色组,异常信息为:", e);
        }
    }
 
    @Override // org.springblade.modules.sync.service.IDingEventService
    public String getDingAccessToken(String appKey, String appSecret) throws Exception {
        String cacheToken = (String) this.bladeRedis.get(DingConstant.DING_ACCESSTOKEN_REDIS_CACHE);
        if (Func.isNotEmpty(cacheToken)) {
            return cacheToken;
        }
        DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
        OapiGettokenRequest req = new OapiGettokenRequest();
        req.setAppkey(appKey);
        req.setAppsecret(appSecret);
        req.setHttpMethod("GET");
        OapiGettokenResponse rsp = defaultDingTalkClient.execute(req);
        JSONObject jsonObject = JSONObject.parseObject(rsp.getBody());
        if (jsonObject.getInteger(QyWechatConstant.ERROR_CODE_KEY).equals(DingConstant.SUCCESS)) {
            this.bladeRedis.setEx(DingConstant.DING_ACCESSTOKEN_REDIS_CACHE, String.valueOf(jsonObject.get("access_token")), Duration.ofHours(2L));
            return String.valueOf(jsonObject.get("access_token"));
        }
        log.error("获取钉钉应用accessToken异常,结果为:" + jsonObject);
        return null;
    }
}