| | |
| | | package com.yeshi.fanli.util.rocketmq.consumer.user;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | import com.aliyun.openservices.ons.api.Action;
|
| | | import com.aliyun.openservices.ons.api.ConsumeContext;
|
| | | import com.aliyun.openservices.ons.api.Message;
|
| | | import com.aliyun.openservices.ons.api.MessageListener;
|
| | | import com.google.gson.Gson;
|
| | | import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum;
|
| | | import com.yeshi.fanli.dto.mq.user.body.UserActiveMQMsg;
|
| | | import com.yeshi.fanli.entity.bus.user.UserActiveLog;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoRegister;
|
| | | import com.yeshi.fanli.entity.bus.user.vip.UserVIPPreInfo;
|
| | | import com.yeshi.fanli.exception.user.vip.UserVIPPreInfoException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.user.UserActiveLogService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoModifyRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoRegisterService;
|
| | | import com.yeshi.fanli.service.inter.user.vip.TeamUserLevelStatisticService;
|
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.VersionUtil;
|
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName;
|
| | |
|
| | | /**
|
| | | * 同步消息
|
| | | * |
| | | * @author Administrator
|
| | | *
|
| | | */
|
| | | @Component
|
| | | public class SyncBeforeInfoMessageListener implements MessageListener {
|
| | |
|
| | | @Resource
|
| | | private UserInfoModifyRecordService userInfoModifyRecordService;
|
| | |
|
| | | @Resource
|
| | | private TeamUserLevelStatisticService teamUserLevelStatisticService;
|
| | |
|
| | | @Resource
|
| | | private UserActiveLogService userActiveLogService;
|
| | |
|
| | | @Resource
|
| | | private UserInfoRegisterService userInfoRegisterService;
|
| | |
|
| | | @Resource
|
| | | private UserVIPPreInfoService userVIPPreInfoService;
|
| | |
|
| | | @Override
|
| | | public Action consume(Message message, ConsumeContext context) {
|
| | |
|
| | | LogHelper.mqInfo("consumer-SyncBeforeInfoMessageListener", message.getMsgID(), message.getTopic(),
|
| | | message.getTag(), new String(message.getBody()));
|
| | | String tag = message.getTag();
|
| | | if (tag == null)
|
| | | tag = "";
|
| | |
|
| | | // 邀请相关
|
| | | if (MQTopicName.TOPIC_USER.name().equalsIgnoreCase(message.getTopic())) {
|
| | | // 用户活跃
|
| | | if (tag.equalsIgnoreCase(UserTopicTagEnum.userActve.name())) {
|
| | | UserActiveMQMsg msg = new Gson().fromJson(new String(message.getBody()), UserActiveMQMsg.class);
|
| | | Long uid = msg.getUid();
|
| | |
|
| | | // 老用户同步绑定信息
|
| | | userInfoModifyRecordService.syncBeforeInfo(uid);
|
| | |
|
| | | //同步老用户等级
|
| | | UserActiveLog log = userActiveLogService.getUserLatestActiveInfo(uid);
|
| | | if (log != null && VersionUtil.greaterThan_2_1(
|
| | | "appstore".equalsIgnoreCase(log.getChannel()) ? "ios" : "android", log.getVersionCode())) {
|
| | | //线上老用户升级到2.1,自动计算等级
|
| | | |
| | | List<Long> uids = new ArrayList<>();
|
| | | uids.add(uid);
|
| | | List<UserInfoRegister> list = userInfoRegisterService.listByMultipleUids(uids);
|
| | | if (list != null && list.size() > 0)// 有注册信息
|
| | | {
|
| | | if (list.get(0).getCreateTime().getTime() < Constant.NEW_ORDER_FANLI_RULE_TIME) {// 老用户
|
| | | // 同步用户等级
|
| | | UserVIPPreInfo vipInfo = userVIPPreInfoService.getLatestProcessInfo(uid);
|
| | | if (vipInfo == null) {
|
| | | // 计算等级
|
| | | userVIPPreInfoService.upgradeVipByMyOrder(uid);
|
| | | userVIPPreInfoService.upgradeVipByTeamNum(uid);
|
| | | vipInfo = userVIPPreInfoService.getLatestProcessInfo(uid);
|
| | | if (vipInfo == null) {// 没有生成高级及以上会员
|
| | | // 老用户生成普通会员
|
| | | UserVIPPreInfo vip = new UserVIPPreInfo();
|
| | | vip.setCreateTime(new Date());
|
| | | vip.setProcess(UserVIPPreInfo.PROCESS_1);
|
| | | vip.setUid(uid);
|
| | | try {
|
| | | userVIPPreInfoService.addUserVIPPreInfo(vip);
|
| | | } catch (UserVIPPreInfoException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | return Action.CommitMessage;
|
| | | }
|
| | | }
|
| | | package com.yeshi.fanli.util.rocketmq.consumer.user; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.exception.user.vip.UserVIPUpgradeException; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import com.aliyun.openservices.ons.api.Action; |
| | | import com.aliyun.openservices.ons.api.ConsumeContext; |
| | | import com.aliyun.openservices.ons.api.Message; |
| | | import com.aliyun.openservices.ons.api.MessageListener; |
| | | import com.google.gson.Gson; |
| | | import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum; |
| | | import com.yeshi.fanli.dto.mq.user.body.UserActiveMQMsg; |
| | | import com.yeshi.fanli.entity.bus.user.ThreeSale; |
| | | import com.yeshi.fanli.entity.bus.user.UserActiveLog; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfoRegister; |
| | | import com.yeshi.fanli.entity.bus.user.vip.UserVIPPreInfo; |
| | | import com.yeshi.fanli.exception.user.vip.UserVIPPreInfoException; |
| | | import com.yeshi.fanli.log.LogHelper; |
| | | import com.yeshi.fanli.service.inter.user.UserActiveLogService; |
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService; |
| | | import com.yeshi.fanli.service.inter.user.UserInfoModifyRecordService; |
| | | import com.yeshi.fanli.service.inter.user.UserInfoRegisterService; |
| | | import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce; |
| | | import com.yeshi.fanli.service.inter.user.vip.TeamUserLevelStatisticService; |
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import com.yeshi.fanli.util.VersionUtil; |
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName; |
| | | |
| | | /** |
| | | * 同步消息 |
| | | * |
| | | * @author Administrator |
| | | * |
| | | */ |
| | | @Component |
| | | public class SyncBeforeInfoMessageListener implements MessageListener { |
| | | |
| | | @Resource |
| | | private UserInfoModifyRecordService userInfoModifyRecordService; |
| | | |
| | | @Resource |
| | | private TeamUserLevelStatisticService teamUserLevelStatisticService; |
| | | |
| | | @Resource |
| | | private UserActiveLogService userActiveLogService; |
| | | |
| | | @Resource |
| | | private UserInfoRegisterService userInfoRegisterService; |
| | | |
| | | @Resource |
| | | private UserVIPPreInfoService userVIPPreInfoService; |
| | | |
| | | @Resource |
| | | private UserInfoExtraService userInfoExtraService; |
| | | |
| | | @Resource |
| | | private ThreeSaleSerivce threeSaleSerivce; |
| | | |
| | | @Override |
| | | public Action consume(Message message, ConsumeContext context) { |
| | | |
| | | LogHelper.mqInfo("consumer-SyncBeforeInfoMessageListener", message.getMsgID(), message.getTopic(), |
| | | message.getTag(), new String(message.getBody())); |
| | | String tag = message.getTag(); |
| | | if (tag == null) |
| | | tag = ""; |
| | | |
| | | // 邀请相关 |
| | | if (MQTopicName.TOPIC_USER.name().equalsIgnoreCase(message.getTopic())) { |
| | | // 用户活跃 |
| | | if (tag.equalsIgnoreCase(UserTopicTagEnum.userActve.name())) { |
| | | UserActiveMQMsg msg = new Gson().fromJson(new String(message.getBody()), UserActiveMQMsg.class); |
| | | Long uid = msg.getUid(); |
| | | // 老用户同步绑定信息 |
| | | |
| | | userInfoModifyRecordService.syncBeforeInfo(uid); |
| | | // 低版本全部升级普通会员 |
| | | |
| | | List<ThreeSale> threeSaleList = threeSaleSerivce.getMyBossDeepList(uid, 2); |
| | | List<Long> uidList = new ArrayList<>(); |
| | | uidList.add(uid); |
| | | |
| | | if (threeSaleList != null) { |
| | | for (ThreeSale ts : threeSaleList) { |
| | | uidList.add(ts.getBoss().getId()); |
| | | } |
| | | } |
| | | upgradeOldUser(uidList); |
| | | } |
| | | } |
| | | return Action.CommitMessage; |
| | | } |
| | | |
| | | private void upgradeOldUser(List<Long> uidList) { |
| | | for (Long uid : uidList) { |
| | | // 同步老用户等级 |
| | | UserActiveLog log = userActiveLogService.getUserLatestActiveInfo(uid); |
| | | |
| | | // 低版本全部升级普通会员 |
| | | if (log != null |
| | | && !VersionUtil.greaterThan_2_1("appstore".equalsIgnoreCase(log.getChannel()) ? "ios" : "android", |
| | | log.getVersionCode())) { |
| | | UserVIPPreInfo vipInfo = userVIPPreInfoService.getLatestProcessInfo(uid); |
| | | if (vipInfo == null) { |
| | | vipInfo = userVIPPreInfoService.getLatestProcessInfo(uid); |
| | | if (vipInfo == null) {// 没有生成高级及以上会员 |
| | | UserInfoExtra extra = userInfoExtraService.getUserInfoExtra(uid); |
| | | if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode())) { |
| | | |
| | | List<Long> uids = new ArrayList<>(); |
| | | uids.add(uid); |
| | | List<UserInfoRegister> list = userInfoRegisterService.listByMultipleUids(uids); |
| | | if (list != null && list.size() > 0)// 有注册信息 |
| | | { |
| | | if (list.get(0).getCreateTime().getTime() < Constant.NEW_ORDER_FANLI_RULE_TIME) {// 增加注册时间限制 |
| | | // 老用户生成普通会员 |
| | | UserVIPPreInfo vip = new UserVIPPreInfo(); |
| | | vip.setCreateTime(new Date()); |
| | | vip.setProcess(UserVIPPreInfo.PROCESS_1); |
| | | vip.setUid(uid); |
| | | vip.setSourceType(UserVIPPreInfo.SOURCE_TYPE_ORDER); |
| | | try { |
| | | userVIPPreInfoService.addUserVIPPreInfo(vip); |
| | | } catch (UserVIPPreInfoException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } else if (log != null && VersionUtil.greaterThan_2_1( |
| | | "appstore".equalsIgnoreCase(log.getChannel()) ? "ios" : "android", log.getVersionCode())) {// 2.1后升级其他等级 |
| | | // 线上老用户升级到2.1,自动计算等级 |
| | | List<Long> uids = new ArrayList<>(); |
| | | uids.add(uid); |
| | | List<UserInfoRegister> list = userInfoRegisterService.listByMultipleUids(uids); |
| | | if (list != null && list.size() > 0)// 有注册信息 |
| | | { |
| | | if (list.get(0).getCreateTime().getTime() < Constant.NEW_ORDER_FANLI_RULE_TIME) {// 老用户 |
| | | // 同步用户等级 |
| | | UserVIPPreInfo vipInfo = userVIPPreInfoService.getLatestProcessInfo(uid); |
| | | if (vipInfo == null) { |
| | | // 计算等级 |
| | | try { |
| | | userVIPPreInfoService.upgradeVipByMyOrder(uid); |
| | | } catch (UserVIPUpgradeException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | try { |
| | | userVIPPreInfoService.upgradeVipByTeamNum(uid); |
| | | } catch (UserVIPUpgradeException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | vipInfo = userVIPPreInfoService.getLatestProcessInfo(uid); |
| | | if (vipInfo == null) {// 没有生成高级及以上会员 |
| | | UserInfoExtra extra = userInfoExtraService.getUserInfoExtra(uid); |
| | | if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode())) { |
| | | // 老用户生成普通会员 |
| | | UserVIPPreInfo vip = new UserVIPPreInfo(); |
| | | vip.setCreateTime(new Date()); |
| | | vip.setProcess(UserVIPPreInfo.PROCESS_1); |
| | | vip.setUid(uid); |
| | | vip.setSourceType(UserVIPPreInfo.SOURCE_TYPE_ORDER); |
| | | try { |
| | | userVIPPreInfoService.addUserVIPPreInfo(vip); |
| | | } catch (UserVIPPreInfoException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } else {// 之前老版本处理为普通会员的用户升级新版本 |
| | | if (vipInfo.getProcess() == UserVIPPreInfo.PROCESS_1 |
| | | && vipInfo.getCreateTime().getTime() < TimeUtil |
| | | .convertToTimeTemp("2020-04-30 14:10:00", "yyyy-MM-dd HH:mm:ss")) { |
| | | // 计算等级 |
| | | try { |
| | | userVIPPreInfoService.upgradeVipByMyOrder(uid); |
| | | } catch (UserVIPUpgradeException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | try { |
| | | userVIPPreInfoService.upgradeVipByTeamNum(uid); |
| | | } catch (UserVIPUpgradeException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |