1.关注时增加关注缓存数据
Showing
8 changed files
with
90 additions
and
64 deletions
... | @@ -54,14 +54,22 @@ public class WechatSubscribeRecord implements Serializable { | ... | @@ -54,14 +54,22 @@ public class WechatSubscribeRecord implements Serializable { |
54 | @Column(name = "entity_type") | 54 | @Column(name = "entity_type") |
55 | private Integer entityType; | 55 | private Integer entityType; |
56 | 56 | ||
57 | // 来源类型 1:大屏;2:营销活动;3:其他; | 57 | // 业务场景 0:分享;1:大屏扫码免费看;2:大屏线上活动扫码引导关注;3:小屏线上活动长按二维码引导关注;4:线下活动海报;5:线下机构/渠道引流;99:其他; |
58 | @Column(name = "source_type") | 58 | @Column(name = "source_scence") |
59 | private Integer sourceType; | 59 | private Integer sourceScence; |
60 | 60 | ||
61 | // 来源描述 | 61 | // 来源描述,前端参数源 |
62 | @Column(name = "source_info") | 62 | @Column(name = "source_info") |
63 | private String sourceInfo; | 63 | private String sourceInfo; |
64 | 64 | ||
65 | // 来源描述,系统/运营手动维护 | ||
66 | @Column(name = "source_desc") | ||
67 | private String sourceDesc; | ||
68 | |||
69 | // 微信场景值 1007:单人聊天会话中的小程序消息卡片;1047:扫描小程序码;详见:https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html | ||
70 | @Column(name = "wx_scence") | ||
71 | private Integer wxScence; | ||
72 | |||
65 | // 创建时间 | 73 | // 创建时间 |
66 | @CreatedDate | 74 | @CreatedDate |
67 | @Column(name = "create_time") | 75 | @Column(name = "create_time") | ... | ... |
... | @@ -13,4 +13,6 @@ import java.util.Optional; | ... | @@ -13,4 +13,6 @@ import java.util.Optional; |
13 | public interface WechatSubscribeRecordRepository extends JpaRepository<WechatSubscribeRecord, Long>, JpaSpecificationExecutor<WechatSubscribeRecord> { | 13 | public interface WechatSubscribeRecordRepository extends JpaRepository<WechatSubscribeRecord, Long>, JpaSpecificationExecutor<WechatSubscribeRecord> { |
14 | 14 | ||
15 | Optional<WechatSubscribeRecord> findFirstByCode(String code); | 15 | Optional<WechatSubscribeRecord> findFirstByCode(String code); |
16 | |||
17 | Optional<WechatSubscribeRecord> findFirstByMemberId(Long memberId); | ||
16 | } | 18 | } | ... | ... |
... | @@ -2,6 +2,7 @@ package com.topdraw.business.module.user.weixin.subscribe.service.dto; | ... | @@ -2,6 +2,7 @@ package com.topdraw.business.module.user.weixin.subscribe.service.dto; |
2 | 2 | ||
3 | import lombok.Data; | 3 | import lombok.Data; |
4 | 4 | ||
5 | import javax.persistence.Column; | ||
5 | import java.io.Serializable; | 6 | import java.io.Serializable; |
6 | import java.sql.Timestamp; | 7 | import java.sql.Timestamp; |
7 | 8 | ||
... | @@ -34,12 +35,20 @@ public class WechatSubscribeRecordDTO implements Serializable { | ... | @@ -34,12 +35,20 @@ public class WechatSubscribeRecordDTO implements Serializable { |
34 | // 实例类型 1:大屏扫码;2:营销活动; | 35 | // 实例类型 1:大屏扫码;2:营销活动; |
35 | private Integer entityType; | 36 | private Integer entityType; |
36 | 37 | ||
37 | // 来源类型 1:大屏;2:营销活动;3:其他; | 38 | // 业务场景 0:分享;1:大屏扫码免费看;2:大屏线上活动扫码引导关注;3:小屏线上活动长按二维码引导关注;4:线下活动海报;5:线下机构/渠道引流;99:其他; |
38 | private Integer sourceType; | 39 | private Integer sourceType; |
39 | 40 | ||
40 | // 来源描述 | 41 | private Integer sourceScence; |
42 | |||
43 | // 来源描述,前端参数源 | ||
41 | private String sourceInfo; | 44 | private String sourceInfo; |
42 | 45 | ||
46 | // 来源描述,系统/运营手动维护 | ||
47 | private String sourceDesc; | ||
48 | |||
49 | // 微信场景值 1007:单人聊天会话中的小程序消息卡片;1047:扫描小程序码;详见:https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html | ||
50 | private Integer wxScence; | ||
51 | |||
43 | // 创建时间 | 52 | // 创建时间 |
44 | private Timestamp createTime; | 53 | private Timestamp createTime; |
45 | 54 | ... | ... |
... | @@ -3,12 +3,14 @@ package com.topdraw.business.module.user.weixin.subscribe.service.impl; | ... | @@ -3,12 +3,14 @@ package com.topdraw.business.module.user.weixin.subscribe.service.impl; |
3 | import com.topdraw.business.module.user.weixin.subscribe.domain.WechatSubscribeRecord; | 3 | import com.topdraw.business.module.user.weixin.subscribe.domain.WechatSubscribeRecord; |
4 | import com.topdraw.business.module.user.weixin.subscribe.repository.WechatSubscribeRecordRepository; | 4 | import com.topdraw.business.module.user.weixin.subscribe.repository.WechatSubscribeRecordRepository; |
5 | import com.topdraw.business.module.user.weixin.subscribe.service.WechatSubscribeRecordService; | 5 | import com.topdraw.business.module.user.weixin.subscribe.service.WechatSubscribeRecordService; |
6 | import com.topdraw.business.module.user.weixin.subscribe.service.mapper.WechatSubscribeRecordMapper; | 6 | import com.topdraw.util.TimestampUtil; |
7 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
8 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
9 | import org.springframework.transaction.annotation.Propagation; | 9 | import org.springframework.transaction.annotation.Propagation; |
10 | import org.springframework.transaction.annotation.Transactional; | 10 | import org.springframework.transaction.annotation.Transactional; |
11 | 11 | ||
12 | import java.util.Optional; | ||
13 | |||
12 | /** | 14 | /** |
13 | * @author XiangHan | 15 | * @author XiangHan |
14 | * @date 2022-05-21 | 16 | * @date 2022-05-21 |
... | @@ -20,12 +22,18 @@ public class WechatSubscribeRecordServiceImpl implements WechatSubscribeRecordSe | ... | @@ -20,12 +22,18 @@ public class WechatSubscribeRecordServiceImpl implements WechatSubscribeRecordSe |
20 | @Autowired | 22 | @Autowired |
21 | private WechatSubscribeRecordRepository wechatSubscribeRecordRepository; | 23 | private WechatSubscribeRecordRepository wechatSubscribeRecordRepository; |
22 | 24 | ||
23 | @Autowired | ||
24 | private WechatSubscribeRecordMapper wechatSubscribeRecordMapper; | ||
25 | |||
26 | @Override | 25 | @Override |
27 | @Transactional(rollbackFor = Exception.class) | 26 | @Transactional(rollbackFor = Exception.class) |
28 | public void create(WechatSubscribeRecord resources) { | 27 | public void create(WechatSubscribeRecord resources) { |
29 | this.wechatSubscribeRecordRepository.save(resources); | 28 | this.wechatSubscribeRecordRepository.save(resources); |
29 | /* Optional<WechatSubscribeRecord> wechatSubscribeRecordOptional = this.wechatSubscribeRecordRepository.findFirstByMemberId(resources.getMemberId()); | ||
30 | if (!wechatSubscribeRecordOptional.isPresent()) { | ||
31 | this.wechatSubscribeRecordRepository.save(resources); | ||
32 | } else { | ||
33 | WechatSubscribeRecord wechatSubscribeRecord = wechatSubscribeRecordOptional.get(); | ||
34 | wechatSubscribeRecord.copy(wechatSubscribeRecord); | ||
35 | wechatSubscribeRecord.setUpdateTime(TimestampUtil.now()); | ||
36 | this.wechatSubscribeRecordRepository.save(resources); | ||
37 | }*/ | ||
30 | } | 38 | } |
31 | } | 39 | } | ... | ... |
... | @@ -7,26 +7,23 @@ import lombok.Data; | ... | @@ -7,26 +7,23 @@ import lombok.Data; |
7 | @Data | 7 | @Data |
8 | public class SubscribeBean extends WeiXinUserBean { | 8 | public class SubscribeBean extends WeiXinUserBean { |
9 | 9 | ||
10 | private JSONObject userInfoJson; | 10 | /** |
11 | 11 | * 大屏账号信息 | |
12 | */ | ||
12 | private JSONObject iptvUserInfo; | 13 | private JSONObject iptvUserInfo; |
13 | 14 | ||
14 | private String msgType; | 15 | /** |
15 | 16 | * 昵称 | |
16 | private String event; | 17 | */ |
17 | |||
18 | |||
19 | /** */ | ||
20 | private String openId; | ||
21 | |||
22 | /** */ | ||
23 | private String appId; | ||
24 | |||
25 | /** */ | ||
26 | private String eventKey; | ||
27 | |||
28 | private String nickname; | 18 | private String nickname; |
19 | |||
20 | /** | ||
21 | * 头像 | ||
22 | */ | ||
29 | private String headimgurl; | 23 | private String headimgurl; |
30 | 24 | ||
25 | /** | ||
26 | * 来源描述 | ||
27 | */ | ||
31 | private JSONObject sourceInfo; | 28 | private JSONObject sourceInfo; |
32 | } | 29 | } | ... | ... |
... | @@ -324,7 +324,7 @@ public class UserOperationController { | ... | @@ -324,7 +324,7 @@ public class UserOperationController { |
324 | 324 | ||
325 | // appId | 325 | // appId |
326 | String appId = subscribeBean.getAppid(); | 326 | String appId = subscribeBean.getAppid(); |
327 | Assert.notNull(appId, GlobeExceptionMsg.APP_ID_IS_NULL); | 327 | // Assert.notNull(appId, GlobeExceptionMsg.APP_ID_IS_NULL); |
328 | // openId | 328 | // openId |
329 | String openId = subscribeBean.getOpenid(); | 329 | String openId = subscribeBean.getOpenid(); |
330 | Assert.notNull(openId, GlobeExceptionMsg.OPEN_ID_IS_NULL); | 330 | Assert.notNull(openId, GlobeExceptionMsg.OPEN_ID_IS_NULL); |
... | @@ -335,14 +335,12 @@ public class UserOperationController { | ... | @@ -335,14 +335,12 @@ public class UserOperationController { |
335 | // 匹配配置文件中的微信列表信息 | 335 | // 匹配配置文件中的微信列表信息 |
336 | Map<String, String> wxInfoMap = WeixinUtil.getWeixinInfoByAppid(appId); | 336 | Map<String, String> wxInfoMap = WeixinUtil.getWeixinInfoByAppid(appId); |
337 | 337 | ||
338 | if (Objects.nonNull(wxInfoMap)) { | ||
339 | // 程序类型 | 338 | // 程序类型 |
340 | String appType = wxInfoMap.get("appType"); | 339 | String appType = wxInfoMap.get("appType"); |
341 | // 非订阅号,暂不处理。返回暂不支持 | 340 | // 非订阅号,暂不处理。返回暂不支持 |
342 | if (ObjectUtil.notEqual(appType, WeChatConstants.WX_SUBSCRIPTION)) | 341 | if (ObjectUtil.notEqual(appType, WeChatConstants.WX_SUBSCRIPTION)) |
343 | throw new BadRequestException("非订阅号"); | 342 | throw new BadRequestException("非订阅号"); |
344 | 343 | ||
345 | } | ||
346 | 344 | ||
347 | // 大屏账户信息 | 345 | // 大屏账户信息 |
348 | JSONObject redisInfo = null; | 346 | JSONObject redisInfo = null; |
... | @@ -359,11 +357,8 @@ public class UserOperationController { | ... | @@ -359,11 +357,8 @@ public class UserOperationController { |
359 | 357 | ||
360 | subscribeBean.setIptvUserInfo(redisInfo); | 358 | subscribeBean.setIptvUserInfo(redisInfo); |
361 | // 关注来源信息 | 359 | // 关注来源信息 |
362 | JSONObject sourceInfo = JSONObject.parseObject(redisInfo.get("sourceInfo").toString(), JSONObject.class); | 360 | log.info("关注来源信息,[subscribe#{}]", redisInfo); |
363 | log.info("关注来源信息,[subscribe#{}]", sourceInfo); | 361 | subscribeBean.setSourceInfo(redisInfo); |
364 | if (Objects.nonNull(sourceInfo)) { | ||
365 | subscribeBean.setSourceInfo(sourceInfo); | ||
366 | } | ||
367 | 362 | ||
368 | String nickname = redisInfo.get("nickname").toString(); | 363 | String nickname = redisInfo.get("nickname").toString(); |
369 | if (StringUtils.isNotBlank(nickname)) { | 364 | if (StringUtils.isNotBlank(nickname)) { | ... | ... |
... | @@ -541,13 +541,20 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -541,13 +541,20 @@ public class UserOperationServiceImpl implements UserOperationService { |
541 | if (Objects.nonNull(iptvUserInfo)) { | 541 | if (Objects.nonNull(iptvUserInfo)) { |
542 | // 大屏账户 | 542 | // 大屏账户 |
543 | String platformAccount = iptvUserInfo.getString("platformAccount"); | 543 | String platformAccount = iptvUserInfo.getString("platformAccount"); |
544 | log.info("存储的大屏账号信息 platformAccount ==>> {}" , platformAccount); | ||
545 | 544 | ||
546 | if (StringUtils.isBlank(platformAccount)) { | 545 | if (StringUtils.isBlank(platformAccount)) { |
546 | |||
547 | platformAccount = iptvUserInfo.getString("platformUserId"); | ||
548 | |||
549 | if (StringUtils.isBlank(platformAccount)) { | ||
550 | platformAccount = iptvUserInfo.getString("nNO"); | ||
551 | } | ||
552 | |||
547 | log.error("关注后绑定失败,platformAccount is null "); | 553 | log.error("关注后绑定失败,platformAccount is null "); |
548 | return false; | 554 | return false; |
549 | } | 555 | } |
550 | 556 | ||
557 | log.info("存储的大屏账号信息 platformAccount ==>> {}" , platformAccount); | ||
551 | // 绑定 | 558 | // 绑定 |
552 | this.bind(memberDTO, platformAccount); | 559 | this.bind(memberDTO, platformAccount); |
553 | log.info("绑定结束"); | 560 | log.info("绑定结束"); |
... | @@ -570,45 +577,44 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -570,45 +577,44 @@ public class UserOperationServiceImpl implements UserOperationService { |
570 | private void saveWechatSubscribeRecord(MemberDTO memberDTO, JSONObject sourceInfo, int subscribe) { | 577 | private void saveWechatSubscribeRecord(MemberDTO memberDTO, JSONObject sourceInfo, int subscribe) { |
571 | 578 | ||
572 | WechatSubscribeRecord wechatSubscribeRecord = new WechatSubscribeRecord(); | 579 | WechatSubscribeRecord wechatSubscribeRecord = new WechatSubscribeRecord(); |
573 | wechatSubscribeRecord.setCode(IdWorker.generatorString()); | 580 | wechatSubscribeRecord.setCode("subscribe_"+UUID.randomUUID().toString()); |
574 | wechatSubscribeRecord.setMemberId(memberDTO.getId()); | 581 | wechatSubscribeRecord.setMemberId(memberDTO.getId()); |
575 | wechatSubscribeRecord.setOperationFlag(subscribe); | 582 | wechatSubscribeRecord.setOperationFlag(subscribe); |
576 | if (Objects.isNull(sourceInfo)) { | 583 | if (Objects.nonNull(sourceInfo)) { |
577 | 584 | ||
578 | wechatSubscribeRecord.setEntityType(3); | 585 | // wechatSubscribeRecord.setSourceInfo(JSONObject.toJSONString(sourceInfo)); |
579 | 586 | ||
580 | } else { | 587 | // 内容ID,entityId:实体ID |
581 | 588 | Object entityId = sourceInfo.get("entityId"); | |
582 | Object activityId = sourceInfo.get("sourceId"); | 589 | if (Objects.nonNull(entityId)) { |
583 | Object activityCode = sourceInfo.get("sourceCode"); | 590 | wechatSubscribeRecord.setEntityId(Long.parseLong(entityId.toString())); |
584 | Object entityType = sourceInfo.get("sourceType"); | 591 | } |
592 | // 内容Code, entityCode: 实体Code | ||
593 | Object entityCode = sourceInfo.get("entityCode"); | ||
594 | if (Objects.nonNull(entityCode)) { | ||
595 | wechatSubscribeRecord.setEntityCode(entityCode.toString()); | ||
596 | } | ||
597 | // 内容类型,entityType:不填/空:首页;1:分类列表;2:商品;3:活动;4:投票对象;5:证书;6:用户上传内容;99:其他; | ||
598 | Object entityType = sourceInfo.get("entityType"); | ||
585 | if (Objects.nonNull(entityType)) { | 599 | if (Objects.nonNull(entityType)) { |
586 | Integer s = Integer.parseInt(entityType.toString()); | 600 | wechatSubscribeRecord.setEntityType(Integer.parseInt(entityType.toString())); |
587 | switch (s) { | ||
588 | case SubscribeSourceTypeConstant.type1: | ||
589 | wechatSubscribeRecord.setSourceType(SubscribeSourceTypeConstant.type1); | ||
590 | wechatSubscribeRecord.setEntityType(SubscribeSourceTypeConstant.type1); | ||
591 | break; | ||
592 | case SubscribeSourceTypeConstant.type2: | ||
593 | if (Objects.nonNull(activityId)) { | ||
594 | wechatSubscribeRecord.setEntityId(Long.valueOf(activityId.toString())); | ||
595 | } | 601 | } |
596 | if (Objects.nonNull(activityCode)) { | 602 | // 微信场景类型,sourceType |
597 | wechatSubscribeRecord.setEntityCode(activityCode.toString()); | 603 | Object sourceType = sourceInfo.get("sourceType"); |
604 | if (Objects.nonNull(sourceType)) { | ||
605 | wechatSubscribeRecord.setWxScence(Integer.parseInt(sourceType.toString())); | ||
598 | } | 606 | } |
599 | 607 | // 来源描述,sourceDesc:系统/运营手动维护 | |
600 | wechatSubscribeRecord.setSourceType(SubscribeSourceTypeConstant.type2); | 608 | Object sourceDesc = sourceInfo.get("sourceDesc"); |
601 | wechatSubscribeRecord.setEntityType(SubscribeSourceTypeConstant.type2); | 609 | if (Objects.nonNull(sourceType)) { |
602 | break; | 610 | wechatSubscribeRecord.setSourceDesc(sourceDesc.toString()); |
603 | default: | ||
604 | wechatSubscribeRecord.setSourceType(3); | ||
605 | wechatSubscribeRecord.setEntityType(3); | ||
606 | break; | ||
607 | } | 611 | } |
612 | // 业务场景,0-分享 1-大屏扫码免费看 2-大屏线上活动扫码引导关注 3-小屏线上活动长按二维码引导关注 4-线下活动海报 5-线下机构/渠道引流 99-其他 | ||
613 | Object sourceScence = sourceInfo.get("sourceScence"); | ||
614 | if (Objects.nonNull(sourceScence)) { | ||
615 | wechatSubscribeRecord.setSourceScence(Integer.parseInt(sourceScence.toString())); | ||
608 | } | 616 | } |
609 | 617 | ||
610 | wechatSubscribeRecord.setSourceInfo(JSONObject.toJSONString(sourceInfo)); | ||
611 | |||
612 | } | 618 | } |
613 | 619 | ||
614 | this.wechatSubscribeRecordService.create(wechatSubscribeRecord); | 620 | this.wechatSubscribeRecordService.create(wechatSubscribeRecord); | ... | ... |
-
Please register or sign in to post a comment