1.为关注业务添加必要的日志
Showing
3 changed files
with
54 additions
and
10 deletions
| ... | @@ -334,56 +334,70 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -334,56 +334,70 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 334 | 334 | ||
| 335 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) | 335 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) |
| 336 | public void asyncSubscribe(MemberAndWeixinUserDTO memberAndWeixinUserDTO) { | 336 | public void asyncSubscribe(MemberAndWeixinUserDTO memberAndWeixinUserDTO) { |
| 337 | log.info("微信关注业务开始"); | ||
| 337 | UserWeixinDTO userWeixinDTO = memberAndWeixinUserDTO.getUserWeixinDTO(); | 338 | UserWeixinDTO userWeixinDTO = memberAndWeixinUserDTO.getUserWeixinDTO(); |
| 339 | log.info("小屏侧传过来的微信账号信息 ==>> userWeixinDTO ==>> {}", userWeixinDTO); | ||
| 338 | String openid = userWeixinDTO.getOpenid(); | 340 | String openid = userWeixinDTO.getOpenid(); |
| 339 | String unionid = userWeixinDTO.getUnionid(); | 341 | String unionid = userWeixinDTO.getUnionid(); |
| 340 | String appid = userWeixinDTO.getAppid(); | 342 | String appid = userWeixinDTO.getAppid(); |
| 341 | MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO(); | 343 | MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO(); |
| 344 | log.info("小屏侧传过来的会员信息 ==>> memberDTO ==>> {}", memberDTO); | ||
| 342 | 345 | ||
| 343 | UserWeixinDTO _userWeixinDTO = this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionid, appid, openid); | 346 | UserWeixinDTO _userWeixinDTO = this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionid, appid, openid); |
| 344 | // 有账号 | 347 | // 有账号 |
| 345 | if (Objects.nonNull(_userWeixinDTO.getId())) { | 348 | if (Objects.nonNull(_userWeixinDTO.getId())) { |
| 346 | 349 | log.info("账号存在,检查会员是否存在"); | |
| 347 | UserWeixinDTO _userWeixinDTO0 = this.userWeixinService.findFirstByAppIdAndOpenId(appid, openid); | 350 | UserWeixinDTO _userWeixinDTO0 = this.userWeixinService.findFirstByAppIdAndOpenId(appid, openid); |
| 348 | // 会员存在 | 351 | // 会员存在 |
| 349 | if(Objects.nonNull(_userWeixinDTO0.getMemberId())) { | 352 | if(Objects.nonNull(_userWeixinDTO0.getMemberId())) { |
| 353 | log.info("会员存在,修改账号的关注状态, 关注状态 status ==>> {}", userWeixinDTO.getStatus()); | ||
| 350 | // 账号存在,修改账号和会员 | 354 | // 账号存在,修改账号和会员 |
| 351 | this.updateWeixin(_userWeixinDTO, userWeixinDTO); | 355 | this.updateWeixin(_userWeixinDTO, userWeixinDTO); |
| 352 | MemberDTO _memberDTO = this.memberService.findById(_userWeixinDTO.getMemberId()); | 356 | MemberDTO _memberDTO = this.memberService.findById(_userWeixinDTO.getMemberId()); |
| 353 | 357 | ||
| 354 | MemberDTO memberDTO0 = memberAndWeixinUserDTO.getMemberDTO(); | 358 | MemberDTO memberDTO0 = memberAndWeixinUserDTO.getMemberDTO(); |
| 355 | memberDTO0.setUserIptvId(_memberDTO.getUserIptvId()); | 359 | memberDTO0.setUserIptvId(_memberDTO.getUserIptvId()); |
| 360 | |||
| 361 | log.info("会员存在,修改会员的绑定和vip标识", userWeixinDTO.getStatus()); | ||
| 356 | this.updateMember(_memberDTO, memberDTO0); | 362 | this.updateMember(_memberDTO, memberDTO0); |
| 357 | 363 | ||
| 358 | // 有账号无会员 | 364 | // 有账号无会员 |
| 359 | } else { | 365 | } else { |
| 360 | 366 | ||
| 367 | log.info("当前账号会员不存在"); | ||
| 361 | // 是否存在会员 | 368 | // 是否存在会员 |
| 362 | UserWeixinDTO userWeixinDTO1 = this.userWeixinService.findFirstByUnionId(unionid); | 369 | UserWeixinDTO userWeixinDTO1 = this.userWeixinService.findFirstByUnionId(unionid); |
| 363 | 370 | log.info("检查是否有其他账号存在, 其他账号信息 ==>> {}", userWeixinDTO1); | |
| 364 | // 有其他账号 | 371 | // 有其他账号 |
| 365 | if (Objects.nonNull(userWeixinDTO1.getId())) { | 372 | if (Objects.nonNull(userWeixinDTO1.getId())) { |
| 366 | 373 | log.info("存在其他账号,检查其他账号是否有会员"); | |
| 367 | Long memberId = userWeixinDTO1.getMemberId(); | 374 | Long memberId = userWeixinDTO1.getMemberId(); |
| 368 | if (Objects.nonNull(memberId)) { | 375 | if (Objects.nonNull(memberId)) { |
| 369 | 376 | ||
| 370 | userWeixinDTO.setMemberId(memberId); | 377 | userWeixinDTO.setMemberId(memberId); |
| 371 | MemberDTO memberDTO0 = this.memberService.findById(memberId); | 378 | MemberDTO memberDTO0 = this.memberService.findById(memberId); |
| 379 | log.info("其他账号有会员,会员信息 ==>> {}", memberDTO0); | ||
| 380 | |||
| 372 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); | 381 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); |
| 382 | |||
| 383 | log.info("开始同步会员信息"); | ||
| 373 | this.updateMember(memberDTO0, memberDTO1); | 384 | this.updateMember(memberDTO0, memberDTO1); |
| 374 | 385 | ||
| 375 | } else { | 386 | } else { |
| 376 | 387 | log.info("其他账号无会员"); | |
| 377 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); | 388 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); |
| 378 | Member member = new Member(); | 389 | Member member = new Member(); |
| 379 | BeanUtils.copyProperties(memberDTO1, member); | 390 | BeanUtils.copyProperties(memberDTO1, member); |
| 380 | member.setId(null); | 391 | member.setId(null); |
| 392 | |||
| 393 | log.info("为当前账号创建会员,会员信息 ==>> {}", member); | ||
| 381 | MemberDTO _memberDTO1 = this.memberService.create(member); | 394 | MemberDTO _memberDTO1 = this.memberService.create(member); |
| 382 | userWeixinDTO.setMemberId(_memberDTO1.getId()); | 395 | userWeixinDTO.setMemberId(_memberDTO1.getId()); |
| 383 | 396 | ||
| 384 | } | 397 | } |
| 385 | } | 398 | } |
| 386 | 399 | ||
| 400 | log.info("开始修改账号信息"); | ||
| 387 | this.updateWeixin(_userWeixinDTO, userWeixinDTO); | 401 | this.updateWeixin(_userWeixinDTO, userWeixinDTO); |
| 388 | 402 | ||
| 389 | } | 403 | } |
| ... | @@ -391,41 +405,56 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -391,41 +405,56 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 391 | // 无账号 | 405 | // 无账号 |
| 392 | } else { | 406 | } else { |
| 393 | 407 | ||
| 408 | log.info("当前账号不存在,检查其他账号是否存在"); | ||
| 394 | // 是否存在会员 | 409 | // 是否存在会员 |
| 395 | UserWeixinDTO userWeixinDTO1 = this.userWeixinService.findFirstByUnionId(unionid); | 410 | UserWeixinDTO userWeixinDTO1 = this.userWeixinService.findFirstByUnionId(unionid); |
| 396 | 411 | ||
| 397 | // 有其他账号 | 412 | // 有其他账号 |
| 398 | if (Objects.nonNull(userWeixinDTO1.getId())) { | 413 | if (Objects.nonNull(userWeixinDTO1.getId())) { |
| 399 | 414 | ||
| 415 | log.info("其他账号存在, 其他账号信息 ==>> {}", userWeixinDTO1); | ||
| 416 | |||
| 417 | log.info("检查其他账号是否有会员"); | ||
| 400 | Long memberId = userWeixinDTO1.getMemberId(); | 418 | Long memberId = userWeixinDTO1.getMemberId(); |
| 401 | if (Objects.nonNull(memberId)) { | 419 | if (Objects.nonNull(memberId)) { |
| 402 | 420 | ||
| 403 | userWeixinDTO.setMemberId(memberId); | 421 | userWeixinDTO.setMemberId(memberId); |
| 404 | MemberDTO memberDTO0 = this.memberService.findById(memberId); | 422 | MemberDTO memberDTO0 = this.memberService.findById(memberId); |
| 423 | log.info("其他账号有会员,会员信息 ==>> {}", memberDTO0); | ||
| 424 | |||
| 405 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); | 425 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); |
| 426 | |||
| 427 | log.info("开始同步会员信息"); | ||
| 406 | this.updateMember(memberDTO0, memberDTO1); | 428 | this.updateMember(memberDTO0, memberDTO1); |
| 407 | 429 | ||
| 408 | } else { | 430 | } else { |
| 409 | 431 | log.info("其他账号无会员"); | |
| 410 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); | 432 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); |
| 411 | Member member = new Member(); | 433 | Member member = new Member(); |
| 412 | BeanUtils.copyProperties(memberDTO1, member); | 434 | BeanUtils.copyProperties(memberDTO1, member); |
| 413 | member.setId(null); | 435 | member.setId(null); |
| 436 | |||
| 437 | log.info("为当前账号创建会员,会员信息 ==>> {}", member); | ||
| 414 | MemberDTO _memberDTO1 = this.memberService.create(member); | 438 | MemberDTO _memberDTO1 = this.memberService.create(member); |
| 415 | userWeixinDTO.setMemberId(_memberDTO1.getId()); | 439 | userWeixinDTO.setMemberId(_memberDTO1.getId()); |
| 416 | 440 | ||
| 417 | } | 441 | } |
| 442 | |||
| 418 | } else { | 443 | } else { |
| 419 | 444 | ||
| 445 | log.info("无其他账号存在"); | ||
| 420 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); | 446 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); |
| 421 | Member member = new Member(); | 447 | Member member = new Member(); |
| 422 | BeanUtils.copyProperties(memberDTO1, member); | 448 | BeanUtils.copyProperties(memberDTO1, member); |
| 423 | member.setId(null); | 449 | member.setId(null); |
| 450 | |||
| 451 | log.info("为当前账号创建会员,会员信息 ==>> {}", member); | ||
| 424 | MemberDTO _memberDTO1 = this.memberService.create(member); | 452 | MemberDTO _memberDTO1 = this.memberService.create(member); |
| 425 | userWeixinDTO.setMemberId(_memberDTO1.getId()); | 453 | userWeixinDTO.setMemberId(_memberDTO1.getId()); |
| 426 | 454 | ||
| 427 | } | 455 | } |
| 428 | 456 | ||
| 457 | log.info("开始创建微信账号"); | ||
| 429 | this.createWeixin(userWeixinDTO); | 458 | this.createWeixin(userWeixinDTO); |
| 430 | 459 | ||
| 431 | } | 460 | } |
| ... | @@ -478,6 +507,7 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -478,6 +507,7 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 478 | 507 | ||
| 479 | Member member = new Member(); | 508 | Member member = new Member(); |
| 480 | BeanUtils.copyProperties(memberDTO, member); | 509 | BeanUtils.copyProperties(memberDTO, member); |
| 510 | log.info("会员入库结果 ==>> member ==>> {}", member); | ||
| 481 | return this.memberService.update(member); | 511 | return this.memberService.update(member); |
| 482 | } | 512 | } |
| 483 | 513 | ||
| ... | @@ -504,6 +534,8 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -504,6 +534,8 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 504 | 534 | ||
| 505 | UserWeixin userWeixin = new UserWeixin(); | 535 | UserWeixin userWeixin = new UserWeixin(); |
| 506 | BeanUtils.copyProperties(weixinDTO, userWeixin); | 536 | BeanUtils.copyProperties(weixinDTO, userWeixin); |
| 537 | |||
| 538 | log.info("账号入库结果 ==>> userWeixin ==>> {}", userWeixin); | ||
| 507 | this.userWeixinService.update(userWeixin); | 539 | this.userWeixinService.update(userWeixin); |
| 508 | } | 540 | } |
| 509 | 541 | ... | ... |
| ... | @@ -47,7 +47,7 @@ public class WeiXinEventConsumer { | ... | @@ -47,7 +47,7 @@ public class WeiXinEventConsumer { |
| 47 | @RabbitHandler | 47 | @RabbitHandler |
| 48 | @RabbitListener(queues = "#{rabbitMqSourceConfig.getWechatQueue()}", | 48 | @RabbitListener(queues = "#{rabbitMqSourceConfig.getWechatQueue()}", |
| 49 | containerFactory = "#{rabbitMqSourceConfig.getWechatSource()}", | 49 | containerFactory = "#{rabbitMqSourceConfig.getWechatSource()}", |
| 50 | autoStartup = "#{rabbitMqSourceConfig.getWechatStartUp()}", ackMode = "MANUAL") | 50 | autoStartup = "#{rabbitMqSourceConfig.getWechatStartUp()}", ackMode = "AUTO") |
| 51 | @Transactional | 51 | @Transactional |
| 52 | public void subOrUnSubEvent(Channel channel, Message message, String content) throws IOException { | 52 | public void subOrUnSubEvent(Channel channel, Message message, String content) throws IOException { |
| 53 | try { | 53 | try { |
| ... | @@ -61,23 +61,32 @@ public class WeiXinEventConsumer { | ... | @@ -61,23 +61,32 @@ public class WeiXinEventConsumer { |
| 61 | 61 | ||
| 62 | String openid = wechatMsg.getString("FromUserName"); | 62 | String openid = wechatMsg.getString("FromUserName"); |
| 63 | String msgType = wechatMsg.getString("MsgType"); | 63 | String msgType = wechatMsg.getString("MsgType"); |
| 64 | |||
| 64 | if ("event".equals(msgType)) { | 65 | if ("event".equals(msgType)) { |
| 65 | String event = wechatMsg.getString("Event"); | 66 | String event = wechatMsg.getString("Event"); |
| 66 | String eventKey = wechatMsg.getString("EventKey"); | 67 | String eventKey = wechatMsg.getString("EventKey"); |
| 67 | 68 | ||
| 69 | log.info("event ==>> {}", event); | ||
| 70 | |||
| 68 | SubscribeBean subscribeBean = new SubscribeBean(); | 71 | SubscribeBean subscribeBean = new SubscribeBean(); |
| 69 | subscribeBean.setAppid(appid); | 72 | subscribeBean.setAppid(appid); |
| 70 | subscribeBean.setOpenid(openid); | 73 | subscribeBean.setOpenid(openid); |
| 71 | subscribeBean.setUnionid(unionid); | 74 | subscribeBean.setUnionid(unionid); |
| 72 | subscribeBean.setEventKey(eventKey); | 75 | subscribeBean.setEventKey(eventKey); |
| 73 | 76 | ||
| 74 | if (event.equals("subscribe")) | 77 | if (event.equals("subscribe")) { |
| 78 | log.info("send subscribe request start"); | ||
| 75 | this.restTemplateClient.subscribe(subscribeBean); | 79 | this.restTemplateClient.subscribe(subscribeBean); |
| 80 | log.info("send subscribe request end "); | ||
| 81 | } | ||
| 76 | 82 | ||
| 77 | if (event.equals("unsubscribe")) | 83 | if (event.equals("unsubscribe")) { |
| 84 | log.info("send unsubscribe request start"); | ||
| 78 | this.restTemplateClient.unsubscribe(subscribeBean); | 85 | this.restTemplateClient.unsubscribe(subscribeBean); |
| 86 | log.info("send unsubscribe request end"); | ||
| 87 | } | ||
| 79 | 88 | ||
| 80 | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); | 89 | // channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); |
| 81 | } | 90 | } |
| 82 | 91 | ||
| 83 | } catch (Exception e) { | 92 | } catch (Exception e) { | ... | ... |
| ... | @@ -97,7 +97,9 @@ public class RestTemplateClient { | ... | @@ -97,7 +97,9 @@ public class RestTemplateClient { |
| 97 | 97 | ||
| 98 | HashMap<Object, Object> objectObjectHashMap = new HashMap<>(); | 98 | HashMap<Object, Object> objectObjectHashMap = new HashMap<>(); |
| 99 | objectObjectHashMap.put("content", content); | 99 | objectObjectHashMap.put("content", content); |
| 100 | log.info("reobjectObjectHashMap ===>> [{}]",objectObjectHashMap); | ||
| 100 | restTemplate.postForEntity(url, objectObjectHashMap, String.class); | 101 | restTemplate.postForEntity(url, objectObjectHashMap, String.class); |
| 102 | log.info("unsubscribe ===>> success"); | ||
| 101 | /*ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, subscribeBean, String.class); | 103 | /*ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, subscribeBean, String.class); |
| 102 | String entityBody = ""; | 104 | String entityBody = ""; |
| 103 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | 105 | if (responseEntity.getStatusCode().is2xxSuccessful()) { |
| ... | @@ -113,8 +115,9 @@ public class RestTemplateClient { | ... | @@ -113,8 +115,9 @@ public class RestTemplateClient { |
| 113 | 115 | ||
| 114 | HashMap<String, String> objectObjectHashMap = new HashMap<>(); | 116 | HashMap<String, String> objectObjectHashMap = new HashMap<>(); |
| 115 | objectObjectHashMap.put("content", content); | 117 | objectObjectHashMap.put("content", content); |
| 116 | log.info("objectObjectHashMap ===>> [{}]",objectObjectHashMap); | 118 | log.info("reobjectObjectHashMap ===>> [{}]",objectObjectHashMap); |
| 117 | restTemplate.postForEntity(url, objectObjectHashMap, String.class); | 119 | restTemplate.postForEntity(url, objectObjectHashMap, String.class); |
| 120 | log.info("send subscribe request ===>> success"); | ||
| 118 | /*ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, subscribeBean, String.class); | 121 | /*ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, subscribeBean, String.class); |
| 119 | String entityBody = ""; | 122 | String entityBody = ""; |
| 120 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | 123 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ... | ... |
-
Please register or sign in to post a comment