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
package com.qianwen.smartman.modules.sync.service.impl;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.XmlUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jeecg.qywx.api.department.vo.Department;
import java.lang.invoke.SerializedLambda;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.jeewx.api.mp.aes.AesException;
import org.jeewx.api.mp.aes.WXBizMsgCrypt;
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.enums.CommonGroupTypeEnum;
import com.qianwen.smartman.modules.cps.entity.CommonGroup;
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.IEmployeePostService;
import com.qianwen.smartman.modules.cps.service.impl.CommonGroupOfItemServiceImpl;
import com.qianwen.smartman.modules.cps.service.impl.CommonGroupServiceImpl;
import com.qianwen.smartman.modules.cps.service.impl.EmployeeServiceImpl;
import com.qianwen.smartman.modules.sync.api.QyWechatApi;
import com.qianwen.smartman.modules.sync.constant.OuterAppConfigConstant;
import com.qianwen.smartman.modules.sync.constant.QyWechatConstant;
import com.qianwen.smartman.modules.sync.entity.OuterAppConfig;
import com.qianwen.smartman.modules.sync.entity.QyTag;
import com.qianwen.smartman.modules.sync.entity.QyUser;
import com.qianwen.smartman.modules.sync.enums.WechatEventEnum;
import com.qianwen.smartman.modules.sync.service.IOuterAppConfigService;
import com.qianwen.smartman.modules.sync.service.IWechatCallbackService;
import com.qianwen.smartman.modules.sync.vo.WechatCallbackVO;
import com.qianwen.smartman.modules.system.entity.Post;
import com.qianwen.smartman.modules.system.entity.UserOauth;
import com.qianwen.smartman.modules.system.service.impl.PostServiceImpl;
import com.qianwen.smartman.modules.system.service.impl.UserOauthServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/sync/service/impl/WechatCallbackServiceImpl.class */
public class WechatCallbackServiceImpl implements IWechatCallbackService {
    private static final Logger log = LoggerFactory.getLogger(WechatCallbackServiceImpl.class);
    private final Map<WechatEventEnum, Consumer<String>> xmlParseMap = new HashMap();
    private final WechatSyncServiceImpl wechatSyncService;
    private final PostServiceImpl postService;
    private final IEmployeePostService employeePostService;
    private final UserOauthServiceImpl userOauthService;
    private final CommonGroupServiceImpl commonGroupService;
    private final CommonGroupOfItemServiceImpl commonGroupOfItemService;
    private final EmployeeServiceImpl employeeService;
    private final CommonGroupMapper commonGroupMapper;
    private final IOuterAppConfigService outerAppConfigService;
 
    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 -1219083612:
                if (implMethodName.equals("getOrganizationId")) {
                    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 517353092:
                if (implMethodName.equals("getItemId")) {
                    z = false;
                    break;
                }
                break;
            case 713563345:
                if (implMethodName.equals("getPostId")) {
                    z = true;
                    break;
                }
                break;
            case 799509265:
                if (implMethodName.equals("getSource")) {
                    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();
                    };
                }
                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.getOrganizationId();
                    };
                }
                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.getSource();
                    };
                }
                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();
                    };
                }
                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 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/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/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/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 WechatCallbackServiceImpl(final WechatSyncServiceImpl wechatSyncService, final PostServiceImpl postService, final IEmployeePostService employeePostService, final UserOauthServiceImpl userOauthService, final CommonGroupServiceImpl commonGroupService, final CommonGroupOfItemServiceImpl commonGroupOfItemService, final EmployeeServiceImpl employeeService, final CommonGroupMapper commonGroupMapper, final IOuterAppConfigService outerAppConfigService) {
        this.xmlParseMap.put(WechatEventEnum.USER_ADD_EVENT, this::parseUserAddEvent);
        this.xmlParseMap.put(WechatEventEnum.USER_REMOVE_EVENT, this::parseUserRemoveEvent);
        this.xmlParseMap.put(WechatEventEnum.DEPT_ADD_EVENT, this::parseDeptAddEvent);
        this.xmlParseMap.put(WechatEventEnum.DEPT_REMOVE_EVENT, this::parseDeptRemoveEvent);
        this.xmlParseMap.put(WechatEventEnum.TAG_UPDATE_EVENT, this::parseTagModifyEvent);
        this.wechatSyncService = wechatSyncService;
        this.postService = postService;
        this.employeePostService = employeePostService;
        this.userOauthService = userOauthService;
        this.commonGroupService = commonGroupService;
        this.commonGroupOfItemService = commonGroupOfItemService;
        this.employeeService = employeeService;
        this.commonGroupMapper = commonGroupMapper;
        this.outerAppConfigService = outerAppConfigService;
    }
 
    @Override // org.springblade.modules.sync.service.IWechatCallbackService
    public String callbackVerifyUrl(WechatCallbackVO callbackVO) {
        OuterAppConfig appConfig = this.outerAppConfigService.getAppConfig(OuterAppConfigConstant.QY_WECHAT);
        if (Objects.isNull(appConfig) || !appConfig.getStatus().equals(CommonConstant.ENABLE)) {
            log.info("[企业微信回调事件].[callbackVerifyUrl 配置为空或未启用配置]");
            return QyWechatConstant.CALLBACK_RESULT_NULL;
        }
        try {
            WXBizMsgCrypt wxBizMsgCrypt = new WXBizMsgCrypt(appConfig.getWxCallbackToken(), appConfig.getWxAesKey(), appConfig.getWxCorpId());
            return wxBizMsgCrypt.verifyUrl(callbackVO.getMsg_signature(), callbackVO.getTimestamp(), callbackVO.getNonce(), callbackVO.getEchostr());
        } catch (AesException e) {
            log.error("[企业微信回调配置校验].[callbackVerifyUrl params={}]", callbackVO, e);
            return QyWechatConstant.CALLBACK_ERROR;
        }
    }
 
    @Override // org.springblade.modules.sync.service.IWechatCallbackService
    @Transactional(rollbackFor = {Exception.class})
    public String callbackEvent(WechatCallbackVO callbackVO, String xmlData) {
        OuterAppConfig appConfig = this.outerAppConfigService.getAppConfig(OuterAppConfigConstant.QY_WECHAT);
        if (Objects.isNull(appConfig) || !appConfig.getStatus().equals(CommonConstant.ENABLE)) {
            log.info("[企业微信回调事件].[callbackEvent 配置为空或未启用配置]");
            return QyWechatConstant.CALLBACK_RESULT_NULL;
        }
        try {
            WXBizMsgCrypt wxBizMsgCrypt = new WXBizMsgCrypt(appConfig.getWxCallbackToken(), appConfig.getWxAesKey(), appConfig.getWxCorpId());
            String msg = wxBizMsgCrypt.decryptMsg(callbackVO.getMsg_signature(), callbackVO.getTimestamp(), callbackVO.getNonce(), xmlData);
            WechatEventEnum eventType = getEventType(msg);
            execSyncCallback(eventType, msg);
            return QyWechatConstant.CALLBACK_RESULT;
        } catch (Exception e) {
            log.error("[企业微信回调事件].[WechatCallbackVO error params={}]", callbackVO, e);
            return QyWechatConstant.CALLBACK_RESULT;
        }
    }
 
    private WechatEventEnum getEventType(String xmlData) {
        Document document = XmlUtil.parseXml(xmlData);
        Element root = document.getDocumentElement();
        String type = XmlUtil.elementText(root, QyWechatConstant.EVENT_TYPE);
        if (StrUtil.isNotEmpty(type)) {
            return WechatEventEnum.getWechatEventType(type);
        }
        return WechatEventEnum.DEFAULT;
    }
 
    private String getUserId(String xmlData) {
        Document document = XmlUtil.parseXml(xmlData);
        Element root = document.getDocumentElement();
        String userId = XmlUtil.elementText(root, QyWechatConstant.USER_ID);
        if (StrUtil.isEmpty(userId)) {
            return "";
        }
        return userId;
    }
 
    private String getDeptId(String xmlData) {
        Document document = XmlUtil.parseXml(xmlData);
        Element root = document.getDocumentElement();
        String deptId = XmlUtil.elementText(root, QyWechatConstant.DEPT_ID);
        if (StrUtil.isEmpty(deptId)) {
            return "";
        }
        return deptId;
    }
 
    private TagModifyBody getTagBody(String xmlData) {
        Document document = XmlUtil.parseXml(xmlData);
        Element root = document.getDocumentElement();
        String tagId = XmlUtil.elementText(root, QyWechatConstant.TAG_ID);
        String addUserList = XmlUtil.elementText(root, QyWechatConstant.TAG_ADD_USER);
        List<String> addUserIds = parseCallbackStr(addUserList);
        String deleteUserList = XmlUtil.elementText(root, QyWechatConstant.TAG_DELETE_USER);
        List<String> delUserIds = parseCallbackStr(deleteUserList);
        String tagName = getTagName(tagId);
        return TagModifyBody.builder().tagId(tagId).addUserList(addUserIds).deleteList(delUserIds).tagName(tagName).build();
    }
 
    private List<String> parseCallbackStr(String callbackData) {
        if (StrUtil.isEmpty(callbackData)) {
            return new ArrayList();
        }
        String[] dataArr = callbackData.split(",");
        return ListUtil.toList(dataArr);
    }
 
    private String getTagName(String tagId) {
        List<QyTag> tags = QyWechatApi.getTags();
        for (QyTag tag : tags) {
            if (tag.getTagid().equals(tagId)) {
                return tag.getTagname();
            }
        }
        return "";
    }
 
    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/sync/service/impl/WechatCallbackServiceImpl$TagModifyBody.class */
    public static class TagModifyBody {
        String tagId;
        String tagName;
        List<String> addUserList;
        List<String> deleteList;
 
        public void setTagId(final String tagId) {
            this.tagId = tagId;
        }
 
        public void setTagName(final String tagName) {
            this.tagName = tagName;
        }
 
        public void setAddUserList(final List<String> addUserList) {
            this.addUserList = addUserList;
        }
 
        public void setDeleteList(final List<String> deleteList) {
            this.deleteList = deleteList;
        }
 
        public TagModifyBody(final String tagId, final String tagName, final List<String> addUserList, final List<String> deleteList) {
            this.tagId = tagId;
            this.tagName = tagName;
            this.addUserList = addUserList;
            this.deleteList = deleteList;
        }
 
        /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/sync/service/impl/WechatCallbackServiceImpl$TagModifyBody$TagModifyBodyBuilder.class */
        public static class TagModifyBodyBuilder {
            private String tagId;
            private String tagName;
            private List<String> addUserList;
            private List<String> deleteList;
 
            TagModifyBodyBuilder() {
            }
 
            public TagModifyBodyBuilder tagId(final String tagId) {
                this.tagId = tagId;
                return this;
            }
 
            public TagModifyBodyBuilder tagName(final String tagName) {
                this.tagName = tagName;
                return this;
            }
 
            public TagModifyBodyBuilder addUserList(final List<String> addUserList) {
                this.addUserList = addUserList;
                return this;
            }
 
            public TagModifyBodyBuilder deleteList(final List<String> deleteList) {
                this.deleteList = deleteList;
                return this;
            }
 
            public TagModifyBody build() {
                return new TagModifyBody(this.tagId, this.tagName, this.addUserList, this.deleteList);
            }
 
            public String toString() {
                return "WechatCallbackServiceImpl.TagModifyBody.TagModifyBodyBuilder(tagId=" + this.tagId + ", tagName=" + this.tagName + ", addUserList=" + this.addUserList + ", deleteList=" + this.deleteList + ")";
            }
        }
 
        public TagModifyBody() {
        }
 
        public static TagModifyBodyBuilder builder() {
            return new TagModifyBodyBuilder();
        }
 
        public String getTagId() {
            return this.tagId;
        }
 
        public String getTagName() {
            return this.tagName;
        }
 
        public List<String> getAddUserList() {
            return this.addUserList;
        }
 
        public List<String> getDeleteList() {
            return this.deleteList;
        }
    }
 
    private void parseUserAddEvent(String xmlData) {
        String userId = getUserId(xmlData);
        if (StrUtil.isEmpty(userId)) {
            return;
        }
        QyUser qyUser = QyWechatApi.getUserById(userId);
        UserOauth userOauth = (UserOauth) this.userOauthService.getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getUuid();
        }, userId)).eq((v0) -> {
            return v0.getSource();
        }, QyWechatConstant.QY_SOURCE), Boolean.TRUE.booleanValue());
        this.wechatSyncService.createOrModifyEmployee(qyUser, userOauth);
    }
 
    private void parseUserRemoveEvent(String xmlData) {
        String userId = getUserId(xmlData);
        if (StrUtil.isEmpty(userId)) {
            return;
        }
        UserOauth userOauth = (UserOauth) this.userOauthService.getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getUuid();
        }, userId));
        if (Objects.isNull(userOauth)) {
            return;
        }
        this.userOauthService.removeById(userOauth.getId());
        Employee employee = (Employee) this.employeeService.getById(userOauth.getUserId());
        if (Objects.isNull(employee)) {
            return;
        }
        this.employeeService.removeById(employee);
        this.commonGroupOfItemService.remove((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getGroupId();
        }, employee.getOrganizationId())).eq((v0) -> {
            return v0.getItemId();
        }, employee.getId()));
        this.employeePostService.remove((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getPostId();
        }, employee.getPostId())).eq((v0) -> {
            return v0.getEmployeeId();
        }, employee.getId()));
    }
 
    private void parseDeptAddEvent(String xmlBody) {
        String deptId = getDeptId(xmlBody);
        if (StrUtil.isEmpty(deptId)) {
            return;
        }
        saveCommonGroup(deptId);
    }
 
    private void saveCommonGroup(String deptId) {
        Department department = QyWechatApi.getDeptById(deptId);
        CommonGroup commonGroup = this.wechatSyncService.setCommonGroup(department);
        this.commonGroupService.insert(commonGroup);
    }
 
    private void parseDeptRemoveEvent(String xmlBody) {
        String deptId = getDeptId(xmlBody);
        if (StrUtil.isEmpty(deptId)) {
            return;
        }
        String localDeptId = QyWechatConstant.ID_SALT + deptId;
        long count = this.employeeService.count((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getOrganizationId();
        }, localDeptId));
        if (count > 0) {
            log.warn("[部门删除回调事件].[当前部门下有{}个员工,无法删除]", Long.valueOf(count));
            return;
        }
        this.commonGroupMapper.removeOrgByIds(ListUtil.of(new String[]{localDeptId}));
        this.commonGroupOfItemService.remove((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getGroupId();
        }, localDeptId)).eq((v0) -> {
            return v0.getGroupType();
        }, CommonGroupTypeEnum.ORGANIZATION.getName()));
    }
 
    private void parseTagModifyEvent(String xmlBody) {
        TagModifyBody tagBody = getTagBody(xmlBody);
        Post post = (Post) this.postService.getById(tagBody.getTagId());
        if (Objects.isNull(post)) {
            this.postService.save(this.wechatSyncService.setPost(tagBody.getTagName(), tagBody.getTagId()));
        }
        addUsersByTag(tagBody);
        delUsersByTag(tagBody);
    }
 
    private void delUsersByTag(TagModifyBody tagBody) {
        if (CollectionUtil.isNotEmpty(tagBody.getDeleteList())) {
            log.info("[企业微信标签回调事件].[标签删除用户 userList={}]", tagBody.getDeleteList());
            List<Employee> employees = getEmpList(tagBody.getDeleteList());
            employees.forEach(emp -> {
                String handlerPostId = handlerPostId(Boolean.TRUE, emp.getPostId(), tagBody.getTagId());
                this.employeePostService.remove((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
                    return v0.getPostId();
                }, tagBody.getTagId())).eq((v0) -> {
                    return v0.getEmployeeId();
                }, emp.getId()));
                emp.setPostId(handlerPostId);
            });
            this.employeeService.updateBatchById(employees);
        }
    }
 
    private String handlerPostId(Boolean isDel, String sourcePostId, String tagPostId) {
        ArrayList<String> postList;
        if (StrUtil.isEmpty(sourcePostId)) {
            postList = new ArrayList<>();
        } else {
            String[] postIds = sourcePostId.split(",");
            postList = ListUtil.toList(postIds);
        }
        if (isDel.booleanValue()) {
            postList.removeIf(id -> {
                return id.equals(tagPostId);
            });
        } else {
            postList.add(tagPostId);
        }
        return CollectionUtil.join(postList, ",");
    }
 
    private void addUsersByTag(TagModifyBody tagBody) {
        if (CollectionUtil.isNotEmpty(tagBody.getAddUserList())) {
            log.info("[企业微信标签回调事件].[标签新增用户 userList={}]", tagBody.getAddUserList());
            List<Employee> employees = getEmpList(tagBody.getAddUserList());
            List<EmployeePost> employeePosts = new ArrayList<>();
            employees.forEach(emp -> {
                String handlerPostId = handlerPostId(Boolean.FALSE, emp.getPostId(), tagBody.getTagId());
                employeePosts.add(this.wechatSyncService.setEmployeePost(tagBody.getTagId(), String.valueOf(emp.getId())));
                emp.setPostId(handlerPostId);
            });
            if (CollectionUtil.isNotEmpty(employeePosts)) {
                this.employeePostService.saveBatch(employeePosts);
            }
            this.employeeService.updateBatchById(employees);
        }
    }
 
    private List<Employee> getEmpList(List<String> userIds) {
        List<UserOauth> auths = this.userOauthService.list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
            return v0.getUuid();
        }, userIds));
        if (CollectionUtil.isEmpty(auths)) {
            return new ArrayList();
        }
        List<Long> empIds = (List) auths.parallelStream().map((v0) -> {
            return v0.getUserId();
        }).collect(Collectors.toList());
        return this.employeeService.listByIds(empIds);
    }
 
    private void execSyncCallback(WechatEventEnum wechatEventEnum, String xmlData) {
        Consumer<String> parseMethod = this.xmlParseMap.get(wechatEventEnum);
        if (parseMethod != null) {
            parseMethod.accept(xmlData);
            log.info("[企业微信{}回调事件].[execSyncCallback 解析回调数据,进行同步]", wechatEventEnum.getDesc());
        }
    }
}