Commit b2c77c39 b2c77c396e976dcd859eff40d0529d17ad466c6d by xianghan

1.关注时增加关注缓存数据

1 parent b6b0161f
......@@ -54,14 +54,22 @@ public class WechatSubscribeRecord implements Serializable {
@Column(name = "entity_type")
private Integer entityType;
// 来源类型 1:大屏;2:营销活动;3:其他;
@Column(name = "source_type")
private Integer sourceType;
// 业务场景 0:分享;1:大屏扫码免费看;2:大屏线上活动扫码引导关注;3:小屏线上活动长按二维码引导关注;4:线下活动海报;5:线下机构/渠道引流;99:其他;
@Column(name = "source_scence")
private Integer sourceScence;
// 来源描述
// 来源描述,前端参数源
@Column(name = "source_info")
private String sourceInfo;
// 来源描述,系统/运营手动维护
@Column(name = "source_desc")
private String sourceDesc;
// 微信场景值 1007:单人聊天会话中的小程序消息卡片;1047:扫描小程序码;详见:https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html
@Column(name = "wx_scence")
private Integer wxScence;
// 创建时间
@CreatedDate
@Column(name = "create_time")
......
......@@ -13,4 +13,6 @@ import java.util.Optional;
public interface WechatSubscribeRecordRepository extends JpaRepository<WechatSubscribeRecord, Long>, JpaSpecificationExecutor<WechatSubscribeRecord> {
Optional<WechatSubscribeRecord> findFirstByCode(String code);
Optional<WechatSubscribeRecord> findFirstByMemberId(Long memberId);
}
......
......@@ -2,6 +2,7 @@ package com.topdraw.business.module.user.weixin.subscribe.service.dto;
import lombok.Data;
import javax.persistence.Column;
import java.io.Serializable;
import java.sql.Timestamp;
......@@ -34,12 +35,20 @@ public class WechatSubscribeRecordDTO implements Serializable {
// 实例类型 1:大屏扫码;2:营销活动;
private Integer entityType;
// 来源类型 1:大屏;2:营销活动;3:其他;
// 业务场景 0:分享;1:大屏扫码免费看;2:大屏线上活动扫码引导关注;3:小屏线上活动长按二维码引导关注;4:线下活动海报;5:线下机构/渠道引流;99:其他;
private Integer sourceType;
// 来源描述
private Integer sourceScence;
// 来源描述,前端参数源
private String sourceInfo;
// 来源描述,系统/运营手动维护
private String sourceDesc;
// 微信场景值 1007:单人聊天会话中的小程序消息卡片;1047:扫描小程序码;详见:https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html
private Integer wxScence;
// 创建时间
private Timestamp createTime;
......
......@@ -3,12 +3,14 @@ package com.topdraw.business.module.user.weixin.subscribe.service.impl;
import com.topdraw.business.module.user.weixin.subscribe.domain.WechatSubscribeRecord;
import com.topdraw.business.module.user.weixin.subscribe.repository.WechatSubscribeRecordRepository;
import com.topdraw.business.module.user.weixin.subscribe.service.WechatSubscribeRecordService;
import com.topdraw.business.module.user.weixin.subscribe.service.mapper.WechatSubscribeRecordMapper;
import com.topdraw.util.TimestampUtil;
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.util.Optional;
/**
* @author XiangHan
* @date 2022-05-21
......@@ -20,12 +22,18 @@ public class WechatSubscribeRecordServiceImpl implements WechatSubscribeRecordSe
@Autowired
private WechatSubscribeRecordRepository wechatSubscribeRecordRepository;
@Autowired
private WechatSubscribeRecordMapper wechatSubscribeRecordMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public void create(WechatSubscribeRecord resources) {
this.wechatSubscribeRecordRepository.save(resources);
/* Optional<WechatSubscribeRecord> wechatSubscribeRecordOptional = this.wechatSubscribeRecordRepository.findFirstByMemberId(resources.getMemberId());
if (!wechatSubscribeRecordOptional.isPresent()) {
this.wechatSubscribeRecordRepository.save(resources);
} else {
WechatSubscribeRecord wechatSubscribeRecord = wechatSubscribeRecordOptional.get();
wechatSubscribeRecord.copy(wechatSubscribeRecord);
wechatSubscribeRecord.setUpdateTime(TimestampUtil.now());
this.wechatSubscribeRecordRepository.save(resources);
}*/
}
}
......
......@@ -7,26 +7,23 @@ import lombok.Data;
@Data
public class SubscribeBean extends WeiXinUserBean {
private JSONObject userInfoJson;
/**
* 大屏账号信息
*/
private JSONObject iptvUserInfo;
private String msgType;
private String event;
/** */
private String openId;
/** */
private String appId;
/** */
private String eventKey;
/**
* 昵称
*/
private String nickname;
/**
* 头像
*/
private String headimgurl;
/**
* 来源描述
*/
private JSONObject sourceInfo;
}
......
......@@ -324,7 +324,7 @@ public class UserOperationController {
// appId
String appId = subscribeBean.getAppid();
Assert.notNull(appId, GlobeExceptionMsg.APP_ID_IS_NULL);
// Assert.notNull(appId, GlobeExceptionMsg.APP_ID_IS_NULL);
// openId
String openId = subscribeBean.getOpenid();
Assert.notNull(openId, GlobeExceptionMsg.OPEN_ID_IS_NULL);
......@@ -335,14 +335,12 @@ public class UserOperationController {
// 匹配配置文件中的微信列表信息
Map<String, String> wxInfoMap = WeixinUtil.getWeixinInfoByAppid(appId);
if (Objects.nonNull(wxInfoMap)) {
// 程序类型
String appType = wxInfoMap.get("appType");
// 非订阅号,暂不处理。返回暂不支持
if (ObjectUtil.notEqual(appType, WeChatConstants.WX_SUBSCRIPTION))
throw new BadRequestException("非订阅号");
// 程序类型
String appType = wxInfoMap.get("appType");
// 非订阅号,暂不处理。返回暂不支持
if (ObjectUtil.notEqual(appType, WeChatConstants.WX_SUBSCRIPTION))
throw new BadRequestException("非订阅号");
}
// 大屏账户信息
JSONObject redisInfo = null;
......@@ -359,11 +357,8 @@ public class UserOperationController {
subscribeBean.setIptvUserInfo(redisInfo);
// 关注来源信息
JSONObject sourceInfo = JSONObject.parseObject(redisInfo.get("sourceInfo").toString(), JSONObject.class);
log.info("关注来源信息,[subscribe#{}]", sourceInfo);
if (Objects.nonNull(sourceInfo)) {
subscribeBean.setSourceInfo(sourceInfo);
}
log.info("关注来源信息,[subscribe#{}]", redisInfo);
subscribeBean.setSourceInfo(redisInfo);
String nickname = redisInfo.get("nickname").toString();
if (StringUtils.isNotBlank(nickname)) {
......
......@@ -541,13 +541,20 @@ public class UserOperationServiceImpl implements UserOperationService {
if (Objects.nonNull(iptvUserInfo)) {
// 大屏账户
String platformAccount = iptvUserInfo.getString("platformAccount");
log.info("存储的大屏账号信息 platformAccount ==>> {}" , platformAccount);
if (StringUtils.isBlank(platformAccount)) {
platformAccount = iptvUserInfo.getString("platformUserId");
if (StringUtils.isBlank(platformAccount)) {
platformAccount = iptvUserInfo.getString("nNO");
}
log.error("关注后绑定失败,platformAccount is null ");
return false;
}
log.info("存储的大屏账号信息 platformAccount ==>> {}" , platformAccount);
// 绑定
this.bind(memberDTO, platformAccount);
log.info("绑定结束");
......@@ -570,44 +577,43 @@ public class UserOperationServiceImpl implements UserOperationService {
private void saveWechatSubscribeRecord(MemberDTO memberDTO, JSONObject sourceInfo, int subscribe) {
WechatSubscribeRecord wechatSubscribeRecord = new WechatSubscribeRecord();
wechatSubscribeRecord.setCode(IdWorker.generatorString());
wechatSubscribeRecord.setCode("subscribe_"+UUID.randomUUID().toString());
wechatSubscribeRecord.setMemberId(memberDTO.getId());
wechatSubscribeRecord.setOperationFlag(subscribe);
if (Objects.isNull(sourceInfo)) {
wechatSubscribeRecord.setEntityType(3);
if (Objects.nonNull(sourceInfo)) {
} else {
// wechatSubscribeRecord.setSourceInfo(JSONObject.toJSONString(sourceInfo));
Object activityId = sourceInfo.get("sourceId");
Object activityCode = sourceInfo.get("sourceCode");
Object entityType = sourceInfo.get("sourceType");
// 内容ID,entityId:实体ID
Object entityId = sourceInfo.get("entityId");
if (Objects.nonNull(entityId)) {
wechatSubscribeRecord.setEntityId(Long.parseLong(entityId.toString()));
}
// 内容Code, entityCode: 实体Code
Object entityCode = sourceInfo.get("entityCode");
if (Objects.nonNull(entityCode)) {
wechatSubscribeRecord.setEntityCode(entityCode.toString());
}
// 内容类型,entityType:不填/空:首页;1:分类列表;2:商品;3:活动;4:投票对象;5:证书;6:用户上传内容;99:其他;
Object entityType = sourceInfo.get("entityType");
if (Objects.nonNull(entityType)) {
Integer s = Integer.parseInt(entityType.toString());
switch (s) {
case SubscribeSourceTypeConstant.type1:
wechatSubscribeRecord.setSourceType(SubscribeSourceTypeConstant.type1);
wechatSubscribeRecord.setEntityType(SubscribeSourceTypeConstant.type1);
break;
case SubscribeSourceTypeConstant.type2:
if (Objects.nonNull(activityId)) {
wechatSubscribeRecord.setEntityId(Long.valueOf(activityId.toString()));
}
if (Objects.nonNull(activityCode)) {
wechatSubscribeRecord.setEntityCode(activityCode.toString());
}
wechatSubscribeRecord.setSourceType(SubscribeSourceTypeConstant.type2);
wechatSubscribeRecord.setEntityType(SubscribeSourceTypeConstant.type2);
break;
default:
wechatSubscribeRecord.setSourceType(3);
wechatSubscribeRecord.setEntityType(3);
break;
}
wechatSubscribeRecord.setEntityType(Integer.parseInt(entityType.toString()));
}
// 微信场景类型,sourceType
Object sourceType = sourceInfo.get("sourceType");
if (Objects.nonNull(sourceType)) {
wechatSubscribeRecord.setWxScence(Integer.parseInt(sourceType.toString()));
}
// 来源描述,sourceDesc:系统/运营手动维护
Object sourceDesc = sourceInfo.get("sourceDesc");
if (Objects.nonNull(sourceType)) {
wechatSubscribeRecord.setSourceDesc(sourceDesc.toString());
}
// 业务场景,0-分享 1-大屏扫码免费看 2-大屏线上活动扫码引导关注 3-小屏线上活动长按二维码引导关注 4-线下活动海报 5-线下机构/渠道引流 99-其他
Object sourceScence = sourceInfo.get("sourceScence");
if (Objects.nonNull(sourceScence)) {
wechatSubscribeRecord.setSourceScence(Integer.parseInt(sourceScence.toString()));
}
wechatSubscribeRecord.setSourceInfo(JSONObject.toJSONString(sourceInfo));
}
......
......@@ -29,4 +29,5 @@ public class RegexUtil {
Matcher m = r.matcher(password);
return m.find();
}
}
......