UserOperationServiceImpl.java
32.8 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
package com.topdraw.business.process.service.impl;
import com.topdraw.business.module.member.domain.Member;
import com.topdraw.business.module.member.domain.MemberBuilder;
import com.topdraw.business.module.member.domain.MemberTypeConstant;
import com.topdraw.business.module.member.profile.domain.MemberProfile;
import com.topdraw.business.module.member.profile.service.MemberProfileService;
import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO;
import com.topdraw.business.module.member.service.MemberService;
import com.topdraw.business.module.member.service.dto.MemberDTO;
import com.topdraw.business.module.user.app.domain.UserApp;
import com.topdraw.business.module.user.app.domain.UserAppBind;
import com.topdraw.business.module.user.app.domain.UserAppBindBuilder;
import com.topdraw.business.module.user.app.domain.UserAppBuilder;
import com.topdraw.business.module.user.app.service.UserAppBindService;
import com.topdraw.business.module.user.app.service.UserAppService;
import com.topdraw.business.module.user.app.service.dto.AppRegisterDTO;
import com.topdraw.business.module.user.app.service.dto.UserAppBindDTO;
import com.topdraw.business.module.user.app.service.dto.UserAppDTO;
import com.topdraw.business.module.user.app.service.dto.UserAppSimpleDTO;
import com.topdraw.business.module.user.iptv.domain.UserTv;
import com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport;
import com.topdraw.business.module.user.iptv.growreport.service.GrowthReportService;
import com.topdraw.business.module.user.iptv.growreport.service.dto.GrowthReportDTO;
import com.topdraw.business.module.user.iptv.service.UserTvService;
import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
import com.topdraw.business.module.user.weixin.domain.UserWeixin;
import com.topdraw.business.module.user.weixin.service.UserWeixinService;
import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO;
import com.topdraw.business.process.service.UserOperationService;
import com.topdraw.business.process.service.dto.MemberAndUserTvDTO;
import com.topdraw.business.process.service.dto.MemberAndWeixinUserDTO;
import com.topdraw.exception.EntityNotFoundException;
import com.topdraw.exception.GlobeExceptionMsg;
import com.topdraw.util.TimestampUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.Objects;
@Service
@Slf4j
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class UserOperationServiceImpl implements UserOperationService {
@Autowired
private MemberService memberService;
@Autowired
private UserTvService userTvService;
@Autowired
private UserWeixinService userWeixinService;
@Autowired
private MemberProfileService memberProfileService;
@Autowired
private GrowthReportService growthReportService;
@Autowired
private UserAppService userAppService;
@Autowired
private UserAppBindService userAppBindService;
public void asyncUpdateAppLastActiveTimeAndNicknameAndHeadImg(UserAppDTO resources) {
UserAppDTO userAppDTO = this.userAppService.findByUsername(resources.getUsername());
if (Objects.isNull(userAppDTO.getId())) {
UserApp userApp = new UserApp();
userApp.setId(userAppDTO.getId());
userApp.setUsername(userAppDTO.getUsername());
userApp.setNickname(resources.getNickname());
userApp.setHeadimgurl(resources.getHeadimgurl());
this.userAppService.updateAppLastActiveTimeAndNicknameAndHeadImg(userApp);
}
}
public void asyncCancelUserAppBind(UserAppBindDTO resources) {
}
public void asyncUpdatePasswordByUsername(UserAppDTO resources) {
UserAppDTO userAppDTO = this.userAppService.findByUsername(resources.getUsername());
if (Objects.isNull(userAppDTO.getId())) {
UserApp userApp = new UserApp();
userApp.setId(userAppDTO.getId());
userApp.setPassword(resources.getPassword());
this.userAppService.updatePasswordById(userApp);
}
}
public void asyncUpdateAppInfo(UserAppDTO resources) {
UserAppDTO userAppDTO = this.userAppService.findByUsername(resources.getUsername());
if (Objects.nonNull(userAppDTO.getId())) {
UserApp userApp = new UserApp();
BeanUtils.copyProperties(resources, userApp);
userApp.setId(userAppDTO.getId());
this.userAppService.updateAppInfo(userApp);
}
}
public void asyncAppCancellation(UserAppDTO resources) {
UserAppDTO userAppDTO = this.userAppService.findByUsername(resources.getUsername());
if (Objects.nonNull(userAppDTO.getId())) {
this.userAppService.appCancellation(userAppDTO.getId());
}
}
public void asyncAppRegister(AppRegisterDTO appRegisterDTO) {
UserAppDTO userAppDTOResources = appRegisterDTO.getUserAppDTO();
MemberDTO memberDTOResources = appRegisterDTO.getMemberDTO();
UserAppDTO userAppDTO = this.userAppService.findByUsername(userAppDTOResources.getUsername());
if (Objects.isNull(userAppDTO.getId())) {
// 先创建会员
// Member member = MemberBuilder.build(MemberTypeConstant.app, userAppDTOResources.getHeadimgurl(), userAppDTOResources.getNickname(), 0);
Member member = new Member();
BeanUtils.copyProperties(memberDTOResources, member);
member.setId(null);
MemberDTO _memberDTO = this.memberService.create(member);
if (Objects.nonNull(_memberDTO.getId())) {
UserApp userApp = new UserApp();
BeanUtils.copyProperties(userAppDTOResources, userApp);
userApp.setId(null);
// 保存app账号
UserAppDTO _userAppDTO = this.userAppService.create(UserAppBuilder.build(_memberDTO.getId(), userApp));
if (Objects.nonNull(_userAppDTO.getId()) && StringUtils.isNotBlank(userAppDTO.getAccount())) {
UserAppBindDTO userAppBindDTO = this.userAppBindService.findFirstByAccount(userAppDTO.getAccount());
if (Objects.isNull(userAppBindDTO.getId())) {
// 保存绑定关系
UserAppBind userAppBind = UserAppBindBuilder.build(_userAppDTO.getId(), userAppDTO.getAccount(), userAppDTO.getAccountType());
this.userAppBindService.create(userAppBind);
}
}
}
}
}
public void asyncsaveGrowthReport(GrowthReport growthReport) {
String platformAccount = growthReport.getPlatformAccount();
UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
if (Objects.isNull(userTvDTO.getId())){
log.error("保存成长报告失败,大屏信息不存在[asyncsaveGrowthReport#]");
return;
}
String weekFirstDay = com.topdraw.util.DateUtil.getWeekFirstDay();
String weekLastDay = com.topdraw.util.DateUtil.getWeekLastDay();
GrowthReportDTO growthReportDTO = this.growthReportService.findByPlatformAccountAndStartDateAndEndDate(platformAccount, weekFirstDay, weekLastDay);
if (Objects.isNull(growthReportDTO.getId())) {
Long id = userTvDTO.getId();
Long memberId = userTvDTO.getMemberId();
growthReport.setUserId(id);
growthReport.setMemberId(memberId);
growthReport.setStartDate(weekFirstDay);
growthReport.setEndDate(weekLastDay);
this.growthReportService.create(growthReport);
} else {
this.growthReportService.updateGrowthReportData(growthReportDTO.getId(), growthReport.getData());
}
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncMemberAndUserWeixin4Iptv(MemberAndWeixinUserDTO memberAndWeixinUserDTO) {
log.info("保存微信账号并同时创建会员信息 ==>> {}", memberAndWeixinUserDTO);
UserWeixinDTO userWeixinDTO = memberAndWeixinUserDTO.getUserWeixinDTO();
String openid = userWeixinDTO.getOpenid();
String unionid = userWeixinDTO.getUnionid();
String appid = userWeixinDTO.getAppid();
UserWeixinDTO _userWeixinDTO = this.userWeixinService.findFirstByAppIdAndOpenId(appid, openid);
log.info("通过appid ==>> {} 和openId ==>> {},检查微信账号是否存在 ==>> {}",appid, openid, _userWeixinDTO);
// 无账号
if (Objects.isNull(_userWeixinDTO.getId())) {
// 其他账号
UserWeixinDTO userWeixinDTO1 = this.userWeixinService.findFirstByUnionId(unionid);
log.info("账号不存在通过unionid ==>> {},检查其他微信账号是否存在 ==>> {}",unionid, userWeixinDTO1);
if (Objects.nonNull(userWeixinDTO1.getId())) {
Long memberId = userWeixinDTO1.getMemberId();
if (Objects.nonNull(memberId)) {
userWeixinDTO.setMemberId(memberId);
MemberDTO memberDTO = this.memberService.findById(memberId);
log.info("其他账号的会员信息 ==>> {},memberId ==>> {}",memberDTO, memberId);
if (Objects.nonNull(memberDTO.getId())) {
MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO();
this.updateMember(memberDTO, memberDTO1);
}
} else {
MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO();
log.info("其他账号的无会员信息,创建会员 memberDTO1 ==>> {}",memberDTO1);
String memberCode = memberDTO1.getCode();
if (StringUtils.isNotBlank(memberCode)) {
Member member = new Member();
member.setCode(memberCode);
MemberDTO _memberDTO1 = this.memberService.create(member);
userWeixinDTO.setMemberId(_memberDTO1.getId());
}
}
// 无其他账号
} else {
MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO();
log.info("无其他账号的无会员信息,创建会员 memberDTO ==>> {}",memberDTO);
Member member = new Member();
BeanUtils.copyProperties(memberDTO, member);
member.setId(null);
MemberDTO memberDTO1 = this.memberService.create(member);
userWeixinDTO.setMemberId(memberDTO1.getId());
}
userWeixinDTO.setId(null);
log.info("保存微信账号,userWeixinDTO ==>> {}",userWeixinDTO);
this.createWeixin(userWeixinDTO);
} else {
// 账号存在,会员也存在
// 会员存在
if(Objects.nonNull(_userWeixinDTO.getMemberId())) {
// 账号存在,修改账号和会员
this.updateWeixin(_userWeixinDTO, userWeixinDTO);
MemberDTO _memberDTO = this.memberService.findById(_userWeixinDTO.getMemberId());
if (Objects.nonNull(_memberDTO.getId())){
MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO();
this.updateMember(_memberDTO, memberDTO);
}
// 有账号无会员
} else {
// 是否存在会员
UserWeixinDTO userWeixinDTO1 = this.userWeixinService.findFirstByUnionId(unionid);
// 有其他账号
if (Objects.nonNull(userWeixinDTO1.getId())) {
Long memberId = userWeixinDTO1.getMemberId();
if (Objects.nonNull(memberId)) {
userWeixinDTO.setMemberId(memberId);
MemberDTO memberDTO = this.memberService.findById(memberId);
MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO();
this.updateMember(memberDTO, memberDTO1);
} else {
MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO();
Member member = new Member();
BeanUtils.copyProperties(memberDTO1, member);
member.setId(null);
MemberDTO _memberDTO1 = this.memberService.create(member);
userWeixinDTO.setMemberId(_memberDTO1.getId());
}
}
this.updateWeixin(_userWeixinDTO, userWeixinDTO);
}
}
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncMemberAndUserTv4Iptv(MemberAndUserTvDTO memberAndUserTvDTO) {
log.info("同步小屏侧过来的大屏账号和会员, memberAndUserTvDTO ==>> {}", memberAndUserTvDTO);
UserTvDTO userTvDTO = memberAndUserTvDTO.getUserTvDTO();
MemberDTO memberDTO = memberAndUserTvDTO.getMemberDTO();
String platformAccount = userTvDTO.getPlatformAccount();
log.info("同步小屏侧过来的大屏账号, platformAccount ==>> {}", platformAccount);
UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
// log.info("查询数据对应的大屏账号信息, _userTvDTO ==>> {}", _userTvDTO);
if (Objects.isNull(_userTvDTO)) {
log.info("大屏账号不存在, 创建会员并新增账号");
memberDTO.setId(null);
// 创建大屏会员
MemberDTO _memberDTO = this.createMember(memberDTO);
userTvDTO.setMemberId(_memberDTO.getId());
// 创建大屏账号
this.createUserTv(userTvDTO);
} else {
Long memberId = _userTvDTO.getMemberId();
if (Objects.isNull(memberId)) {
memberDTO.setId(null);
// 创建大屏会员
MemberDTO _memberDTO = this.createMember(memberDTO);
userTvDTO.setMemberId(_memberDTO.getId());
log.info("大屏账号存在, 但无会员信息,新增会员信息并修改大屏账号");
// this.userTvService.updateMemberId(platformAccount, _memberDTO.getId());
} else {
MemberProfileDTO memberProfileDTO = this.memberProfileService.findByMemberId(memberId);
if (Objects.isNull(memberProfileDTO)) {
MemberDTO memberDTO1 = this.memberService.findById(memberId);
Member member = new Member();
BeanUtils.copyProperties(memberDTO1, member);
this.memberProfileService.createDefault(member);
}
}
UserTv userTv = new UserTv();
BeanUtils.copyProperties(_userTvDTO, userTv);
this.userTvService.updateUserTvByPlatformAccount(userTv);
}
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncMinaBind(MemberAndUserTvDTO memberAndUserTvDTO) {
log.info("asyncAppletBind ==>> 小程序绑定大屏,参数 memberAndUserTvDTO ==>> {}", memberAndUserTvDTO);
UserTvDTO userTvDTO = memberAndUserTvDTO.getUserTvDTO();
MemberDTO memberDTO = memberAndUserTvDTO.getMemberDTO();
String platformAccount = userTvDTO.getPlatformAccount();
UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
if (Objects.nonNull(_userTvDTO.getId())) {
//
// userTvDTO.getPriorityMemberCode();
// this.updateUserTv(_userTvDTO, userTvDTO);
// 修改大屏账号的主会员
String priorityMemberCode = userTvDTO.getPriorityMemberCode();
log.info("修改大屏账号的主会员, 主会员priorityMemberCode ==>> {}", priorityMemberCode);
if (StringUtils.isNotBlank(priorityMemberCode)) {
this.userTvService.updatePriorityMemberCode(platformAccount, priorityMemberCode);
}
String code = memberDTO.getCode();
MemberDTO _memberDTO = this.memberService.findByCode(code);
memberDTO.setUserIptvId(_userTvDTO.getId());
log.info("修改会员对应绑定的大屏账号id, memberId ==>> {} || userTvId ==>> {}", _memberDTO.getId(), _userTvDTO.getId());
this.memberService.updateUserIptvIdById(_memberDTO.getId(), _userTvDTO.getId(), LocalDateTime.now());
} else {
log.error("asyncAppletBind ==>> 小程序绑定大屏异常,大屏账号不存在, platformAccount ==>> {}", platformAccount);
}
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncUnbind(MemberAndUserTvDTO memberAndUserTvDTO) {
UserTvDTO userTvDTO = memberAndUserTvDTO.getUserTvDTO();
MemberDTO memberDTO = memberAndUserTvDTO.getMemberDTO();
String platformAccount = userTvDTO.getPlatformAccount();
UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
if (Objects.nonNull(_userTvDTO.getId())) {
//
UserTv userTv = new UserTv();
userTv.setPriorityMemberCode(userTvDTO.getPriorityMemberCode());
userTv.setId(_userTvDTO.getId());
userTv.setPlatformAccount(_userTvDTO.getPlatformAccount());
this.userTvService.doUpdatePriorityMemberCode(userTv);
}
String code = memberDTO.getCode();
MemberDTO _memberDTO = this.memberService.findByCode(code);
if (Objects.nonNull(_memberDTO.getId())) {
Member member = new Member();
member.setId(_memberDTO.getId());
member.setUserIptvId(null);
member.setBindIptvPlatformType(null);
member.setBindIptvTime(null);
this.memberService.doUpdateMemberUserIptvIdAndBindPlatformTypeAndBingTime(member);
}
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncWeixin(UserWeixinDTO userWeixinDTO) {
String openid = userWeixinDTO.getOpenid();
String unionid = userWeixinDTO.getUnionid();
String appid = userWeixinDTO.getAppid();
UserWeixinDTO _userWeixinDTO = this.userWeixinService.findFirstByAppIdAndOpenId(appid, openid);
if (Objects.nonNull(_userWeixinDTO.getId())) {
if(Objects.nonNull(_userWeixinDTO.getMemberId())) {
if (StringUtils.isNotBlank(_userWeixinDTO.getUnionid())) {
UserWeixinDTO userWeixinDTO1 = this.userWeixinService.findFirstByUnionId(_userWeixinDTO.getUnionid());
if (Objects.nonNull(userWeixinDTO1)) {
Long memberId = userWeixinDTO1.getMemberId();
if (Objects.nonNull(memberId)) {
userWeixinDTO.setMemberId(memberId);
} else {
String memberCode = userWeixinDTO.getMemberCode();
if (StringUtils.isNotBlank(memberCode)) {
Member member = new Member();
member.setCode(memberCode);
MemberDTO memberDTO1 = this.memberService.create(member);
userWeixinDTO.setMemberId(memberDTO1.getId());
}
}
}
} else {
String memberCode = userWeixinDTO.getMemberCode();
if (StringUtils.isNotBlank(memberCode)) {
Member member = new Member();
member.setCode(memberCode);
MemberDTO memberDTO1 = this.memberService.create(member);
userWeixinDTO.setMemberId(memberDTO1.getId());
}
}
} else {
String memberCode = userWeixinDTO.getMemberCode();
if (StringUtils.isNotBlank(memberCode)) {
Member member = new Member();
member.setCode(memberCode);
MemberDTO memberDTO1 = this.memberService.create(member);
userWeixinDTO.setMemberId(memberDTO1.getId());
}
}
userWeixinDTO.setId(_userWeixinDTO.getId());
this.updateWeixin(_userWeixinDTO, userWeixinDTO);
} else {
userWeixinDTO.setId(null);
String memberCode = userWeixinDTO.getMemberCode();
Long memberId = null;
if (StringUtils.isNotBlank(memberCode)) {
MemberDTO memberDTO = this.memberService.findByCode(memberCode);
if (Objects.isNull(memberDTO.getId())) {
Member member = new Member();
member.setCode(memberCode);
MemberDTO memberDTO1 = this.memberService.create(member);
memberId = memberDTO1.getId();
} else {
memberId = memberDTO.getId();
}
userWeixinDTO.setMemberId(memberId);
this.createWeixin(userWeixinDTO);
}
}
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncUserTvChangeMainAccount(UserTvDTO userTvDTO) {
log.info("asyncUserTv ==>> userTvDTO ==>> {}", userTvDTO);
String priorityMemberCode = userTvDTO.getPriorityMemberCode();
if (StringUtils.isBlank(priorityMemberCode)) {
log.error("大屏账号设置主会员异常,主会员code不存在");
return;
}
String platformAccount = userTvDTO.getPlatformAccount();
UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
log.info("从数据库中获取大屏信息, _userTvDTO ==>> {}", _userTvDTO);
if (Objects.isNull(_userTvDTO.getId())) {
log.error("大屏账号设置主会员异常,大屏账号不存在");
return;
}
UserTv userTv = new UserTv();
userTv.setId(_userTvDTO.getId());
userTv.setPlatformAccount(platformAccount);
userTv.setPriorityMemberCode(priorityMemberCode);
log.info("开始修改大屏数据,userTv ==>>{}", userTv);
this.userTvService.doUpdatePriorityMemberCode(userTv);
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncUserTv(UserTvDTO userTvDTO) {
log.info("asyncUserTv ==>> userTvDTO ==>> {}", userTvDTO);
String platformAccount = userTvDTO.getPlatformAccount();
UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
log.info("db result ==>> _userTvDTO ==>> {}", _userTvDTO);
// this.updateUserTv(_userTvDTO, userTvDTO);
UserTv userTv = new UserTv();
BeanUtils.copyProperties(userTvDTO, userTv);
this.userTvService.updateUserTvByPlatformAccount(userTv);
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncMember(MemberDTO memberDTO) {
String code = memberDTO.getCode();
if (StringUtils.isNotBlank(code)) {
MemberDTO _memberDTO = this.memberService.findByCode(code);
if (Objects.nonNull(_memberDTO)) {
Long id = _memberDTO.getId();
memberDTO.setId(id);
this.updateMember(_memberDTO, memberDTO);
}
}
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncSubscribe(MemberAndWeixinUserDTO memberAndWeixinUserDTO) {
log.info("微信关注业务开始");
UserWeixinDTO userWeixinDTO = memberAndWeixinUserDTO.getUserWeixinDTO();
log.info("小屏侧传过来的微信账号信息 ==>> userWeixinDTO ==>> {}", userWeixinDTO);
String openid = userWeixinDTO.getOpenid();
String unionid = userWeixinDTO.getUnionid();
String appid = userWeixinDTO.getAppid();
MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO();
log.info("小屏侧传过来的会员信息 ==>> memberDTO ==>> {}", memberDTO);
UserWeixinDTO _userWeixinDTO = this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionid, appid, openid);
// 有账号
if (Objects.nonNull(_userWeixinDTO.getId())) {
log.info("账号存在,检查会员是否存在");
UserWeixinDTO _userWeixinDTO0 = this.userWeixinService.findFirstByAppIdAndOpenId(appid, openid);
// 会员存在
if(Objects.nonNull(_userWeixinDTO0.getMemberId())) {
log.info("会员存在,修改账号的关注状态, 关注状态 status ==>> {}", userWeixinDTO.getStatus());
// 账号存在,修改账号和会员
this.updateWeixin(_userWeixinDTO, userWeixinDTO);
MemberDTO _memberDTO = this.memberService.findById(_userWeixinDTO.getMemberId());
MemberDTO memberDTO0 = memberAndWeixinUserDTO.getMemberDTO();
memberDTO0.setUserIptvId(_memberDTO.getUserIptvId());
log.info("会员存在,修改会员的绑定和vip标识", userWeixinDTO.getStatus());
this.updateMember(_memberDTO, memberDTO0);
// 有账号无会员
} else {
log.info("当前账号会员不存在");
// 是否存在会员
UserWeixinDTO userWeixinDTO1 = this.userWeixinService.findFirstByUnionId(unionid);
log.info("检查是否有其他账号存在, 其他账号信息 ==>> {}", userWeixinDTO1);
// 有其他账号
if (Objects.nonNull(userWeixinDTO1.getId())) {
log.info("存在其他账号,检查其他账号是否有会员");
Long memberId = userWeixinDTO1.getMemberId();
if (Objects.nonNull(memberId)) {
userWeixinDTO.setMemberId(memberId);
MemberDTO memberDTO0 = this.memberService.findById(memberId);
log.info("其他账号有会员,会员信息 ==>> {}", memberDTO0);
MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO();
log.info("开始同步会员信息");
this.updateMember(memberDTO0, memberDTO1);
} else {
log.info("其他账号无会员");
MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO();
Member member = new Member();
BeanUtils.copyProperties(memberDTO1, member);
member.setId(null);
log.info("为当前账号创建会员,会员信息 ==>> {}", member);
MemberDTO _memberDTO1 = this.memberService.create(member);
userWeixinDTO.setMemberId(_memberDTO1.getId());
}
}
log.info("开始修改账号信息");
this.updateWeixin(_userWeixinDTO, userWeixinDTO);
}
// 无账号
} else {
log.info("当前账号不存在,检查其他账号是否存在");
// 是否存在会员
UserWeixinDTO userWeixinDTO1 = this.userWeixinService.findFirstByUnionId(unionid);
// 有其他账号
if (Objects.nonNull(userWeixinDTO1.getId())) {
log.info("其他账号存在, 其他账号信息 ==>> {}", userWeixinDTO1);
log.info("检查其他账号是否有会员");
Long memberId = userWeixinDTO1.getMemberId();
if (Objects.nonNull(memberId)) {
userWeixinDTO.setMemberId(memberId);
MemberDTO memberDTO0 = this.memberService.findById(memberId);
log.info("其他账号有会员,会员信息 ==>> {}", memberDTO0);
MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO();
log.info("开始同步会员信息");
this.updateMember(memberDTO0, memberDTO1);
} else {
log.info("其他账号无会员");
MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO();
Member member = new Member();
BeanUtils.copyProperties(memberDTO1, member);
member.setId(null);
log.info("为当前账号创建会员,会员信息 ==>> {}", member);
MemberDTO _memberDTO1 = this.memberService.create(member);
userWeixinDTO.setMemberId(_memberDTO1.getId());
}
} else {
log.info("无其他账号存在");
MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO();
Member member = new Member();
BeanUtils.copyProperties(memberDTO1, member);
member.setId(null);
log.info("为当前账号创建会员,会员信息 ==>> {}", member);
MemberDTO _memberDTO1 = this.memberService.create(member);
userWeixinDTO.setMemberId(_memberDTO1.getId());
}
log.info("开始创建微信账号");
this.createWeixin(userWeixinDTO);
}
}
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public void asyncUnsubscribe(MemberAndWeixinUserDTO memberAndWeixinUserDTO) {
UserWeixinDTO userWeixinDTO = memberAndWeixinUserDTO.getUserWeixinDTO();
String openid = userWeixinDTO.getOpenid();
String unionid = userWeixinDTO.getUnionid();
String appid = userWeixinDTO.getAppid();
MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO();
UserWeixinDTO _userWeixinDTO = this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionid, appid, openid);
if (Objects.nonNull(_userWeixinDTO)) {
// 账号存在,修改账号和会员
this.updateWeixin(_userWeixinDTO, userWeixinDTO);
MemberDTO _memberDTO = this.memberService.findById(_userWeixinDTO.getMemberId());
if (Objects.nonNull(_memberDTO)) {
memberDTO.setUserIptvId(_memberDTO.getUserIptvId());
this.updateMember(_memberDTO, memberDTO);
} else {
throw new EntityNotFoundException(MemberDTO.class, "id", GlobeExceptionMsg.MEMBER_ID_IS_NULL);
}
} else {
throw new EntityNotFoundException(UserWeixinDTO.class, "id", GlobeExceptionMsg.WEIXIN_IS_NULL);
}
}
private MemberDTO createMember(MemberDTO memberDTO){
Member member = new Member();
BeanUtils.copyProperties(memberDTO, member);
return this.memberService.create(member);
}
private MemberDTO updateMember(MemberDTO _memberDTO, MemberDTO memberDTO){
memberDTO.setId(_memberDTO.getId());
memberDTO.setCode(_memberDTO.getCode());
Member member = new Member();
BeanUtils.copyProperties(memberDTO, member);
log.info("会员入库结果 ==>> member ==>> {}", member);
return this.memberService.update(member);
}
private void createWeixin(UserWeixinDTO weixinDTO){
UserWeixin userWeixin = new UserWeixin();
BeanUtils.copyProperties(weixinDTO, userWeixin);
this.userWeixinService.create(userWeixin);
}
private void updateWeixin(UserWeixinDTO _userWeixinDTO, UserWeixinDTO weixinDTO){
weixinDTO.setId(_userWeixinDTO.getId());
if (Objects.nonNull(_userWeixinDTO.getMemberId())) {
weixinDTO.setMemberId(_userWeixinDTO.getMemberId());
}
if (StringUtils.isNotBlank(_userWeixinDTO.getUnionid())){
weixinDTO.setUnionid(_userWeixinDTO.getUnionid());
}
if (StringUtils.isNotBlank(_userWeixinDTO.getAppid())) {
weixinDTO.setAppid(_userWeixinDTO.getAppid());
}
if (StringUtils.isNotBlank(_userWeixinDTO.getOpenid())) {
weixinDTO.setOpenid(_userWeixinDTO.getOpenid());
}
UserWeixin userWeixin = new UserWeixin();
BeanUtils.copyProperties(weixinDTO, userWeixin);
log.info("账号入库结果 ==>> userWeixin ==>> {}", userWeixin);
this.userWeixinService.update(userWeixin);
}
private void createUserTv(UserTvDTO userTvDTO){
UserTv userTv = new UserTv();
BeanUtils.copyProperties(userTvDTO, userTv);
this.userTvService.create(userTv);
}
}