| | |
| | | package com.yeshi.fanli.util.rocketmq.consumer.user;
|
| | |
|
| | | 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.BeComeValidUserMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.user.body.TaoBaoBindSuccessMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.user.body.UserAccountBindingMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.user.body.UserActiveMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.user.body.UserInfoUpdateMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.user.body.UserInfoUpdateMQMsg.UserInfoUpdateTypeEnum;
|
| | | import com.yeshi.fanli.dto.mq.user.body.UserInviteMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.user.body.UserLevelChangedMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.user.body.UserMoneyChangeMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.user.body.UserPhoneOpenMQMsg;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.user.invite.TeamFansInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.invite.ThreeSaleDetailService;
|
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | /**
|
| | | * 用户粉丝消息
|
| | | * |
| | | * @author Administrator
|
| | | *
|
| | | */
|
| | | @Component
|
| | | public class UserTeamMessageListener implements MessageListener {
|
| | |
|
| | | @Resource
|
| | | private TeamFansInfoService teamFansInfoService;
|
| | |
|
| | | @Resource
|
| | | private ThreeSaleDetailService threeSaleDetailService;
|
| | |
|
| | | @Override
|
| | | public Action consume(Message message, ConsumeContext context) {
|
| | |
|
| | | LogHelper.mqInfo("consumer-UserTeamMessageListener", 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())) {// 用户活跃
|
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody()));
|
| | | UserActiveMQMsg userActiveMQMsg = new Gson().fromJson(json.toString(), UserActiveMQMsg.class);
|
| | | if (userActiveMQMsg != null) {
|
| | | // 更改用户活跃时间
|
| | | teamFansInfoService.updateActiveTime(userActiveMQMsg.getUid(), userActiveMQMsg.getCreateTime());
|
| | | }
|
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.userInfoUpdate.name())) {// 用户信息更新
|
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody()));
|
| | | UserInfoUpdateMQMsg mqMsg = new Gson().fromJson(json.toString(), UserInfoUpdateMQMsg.class);
|
| | | if (mqMsg != null) {
|
| | | if (UserInfoUpdateTypeEnum.nickName == mqMsg.getType()) { // 更改昵称
|
| | | teamFansInfoService.updateNickName(mqMsg.getUid(), mqMsg.getValue());
|
| | | } else if (UserInfoUpdateTypeEnum.wxId == mqMsg.getType()) { // 微信号绑定
|
| | | teamFansInfoService.updateWeixinId(mqMsg.getUid(), mqMsg.getValue());
|
| | | } else if (UserInfoUpdateTypeEnum.inviteCode == mqMsg.getType()) { // 邀请码更改
|
| | | teamFansInfoService.updateInviteCode(mqMsg.getUid(), mqMsg.getValue());
|
| | | }
|
| | | }
|
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.taobaoBindSuccess.name())) {// 淘宝绑定成功
|
| | | // 更改淘宝绑定状态与原用户淘宝绑定状态
|
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody()));
|
| | | TaoBaoBindSuccessMQMsg mqMsg = new Gson().fromJson(json.toString(), TaoBaoBindSuccessMQMsg.class);
|
| | | if (mqMsg != null) {
|
| | | teamFansInfoService.updateTaobaoBind(mqMsg.getUid(), true);
|
| | | Long fromUid = mqMsg.getFromUid();
|
| | | if (fromUid != null) { // 淘宝被解绑
|
| | | teamFansInfoService.updateTaobaoBind(fromUid, false);
|
| | | }
|
| | | }
|
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.inviteSuccess.name())) {// 邀请成功
|
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody()));
|
| | | UserInviteMQMsg mqMsg = new Gson().fromJson(json.toString(), UserInviteMQMsg.class);
|
| | | if (mqMsg != null) {
|
| | | // 更新上级的粉丝数量
|
| | | teamFansInfoService.updateFansNum(mqMsg.getBossId());
|
| | | // 添加粉丝信息
|
| | | teamFansInfoService.addFansInfo(mqMsg.getWorkerId(), mqMsg.getBossId());
|
| | |
|
| | | threeSaleDetailService.addByWorkerUid(mqMsg.getWorkerId());
|
| | | }
|
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.userMoneyAdd.name())) {// 资金到账
|
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody()));
|
| | | UserMoneyChangeMQMsg mqMsg = new Gson().fromJson(json.toString(), UserMoneyChangeMQMsg.class);
|
| | | if (mqMsg != null) {
|
| | | // 更新近60天到账
|
| | | teamFansInfoService.updateIncome(mqMsg.getUid(), mqMsg.getChangeMoney());
|
| | | }
|
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.becomeValidUser.name())) {// 成为有效用户
|
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody()));
|
| | | BeComeValidUserMQMsg mqMsg = new Gson().fromJson(json.toString(), BeComeValidUserMQMsg.class);
|
| | | if (mqMsg != null) {
|
| | | // 更新成为有效粉丝
|
| | | teamFansInfoService.updateStateValid(mqMsg.getUid(), true);
|
| | | }
|
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.userAccountBinding.name())) {// 绑定信息
|
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody()));
|
| | | UserAccountBindingMQMsg mqMsg = new Gson().fromJson(json.toString(), UserAccountBindingMQMsg.class);
|
| | | if (mqMsg != null) {
|
| | | if (mqMsg.getType() == UserAccountBindingMQMsg.TYPE_PHONE) { // 绑定电话号码
|
| | | teamFansInfoService.updatePhone(mqMsg.getUid(), mqMsg.getValue());
|
| | | }
|
| | | }
|
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.userLevelChanged.name())) {// 等级变化
|
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody()));
|
| | | UserLevelChangedMQMsg mqMsg = new Gson().fromJson(json.toString(), UserLevelChangedMQMsg.class);
|
| | | if (mqMsg != null) {
|
| | | teamFansInfoService.updateLevel(mqMsg.getUid(), mqMsg.getToLevel());
|
| | | }
|
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.userPhoneOpen.name())) {// 电话号码公开
|
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody()));
|
| | | UserPhoneOpenMQMsg mqMsg = new Gson().fromJson(json.toString(), UserPhoneOpenMQMsg.class);
|
| | | if (mqMsg != null) {
|
| | | teamFansInfoService.updatePhoneOpen(mqMsg.getUid(), mqMsg.isState());
|
| | | }
|
| | | }
|
| | | }
|
| | | return Action.CommitMessage;
|
| | | }
|
| | | }
|
| | | package com.yeshi.fanli.util.rocketmq.consumer.user; |
| | | |
| | | 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.BeComeValidUserMQMsg; |
| | | import com.yeshi.fanli.dto.mq.user.body.TaoBaoBindSuccessMQMsg; |
| | | import com.yeshi.fanli.dto.mq.user.body.UserAccountBindingMQMsg; |
| | | import com.yeshi.fanli.dto.mq.user.body.UserActiveMQMsg; |
| | | import com.yeshi.fanli.dto.mq.user.body.UserInfoUpdateMQMsg; |
| | | import com.yeshi.fanli.dto.mq.user.body.UserInfoUpdateMQMsg.UserInfoUpdateTypeEnum; |
| | | import com.yeshi.fanli.dto.mq.user.body.UserInviteMQMsg; |
| | | import com.yeshi.fanli.dto.mq.user.body.UserLevelChangedMQMsg; |
| | | import com.yeshi.fanli.dto.mq.user.body.UserMoneyChangeMQMsg; |
| | | import com.yeshi.fanli.dto.mq.user.body.UserPhoneOpenMQMsg; |
| | | import com.yeshi.fanli.entity.bus.user.ThreeSale; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo; |
| | | import com.yeshi.fanli.log.LogHelper; |
| | | import com.yeshi.fanli.service.inter.user.invite.TeamFansInfoService; |
| | | import com.yeshi.fanli.service.inter.user.invite.ThreeSaleDetailService; |
| | | import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce; |
| | | import com.yeshi.fanli.service.inter.user.vip.TeamUserLevelStatisticService; |
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName; |
| | | |
| | | import net.sf.json.JSONObject; |
| | | |
| | | /** |
| | | * 用户粉丝消息 |
| | | * |
| | | * @author Administrator |
| | | * |
| | | */ |
| | | @Component |
| | | public class UserTeamMessageListener implements MessageListener { |
| | | |
| | | @Resource |
| | | private TeamFansInfoService teamFansInfoService; |
| | | |
| | | @Resource |
| | | private ThreeSaleDetailService threeSaleDetailService; |
| | | |
| | | @Resource |
| | | private ThreeSaleSerivce threeSaleSerivce; |
| | | |
| | | @Resource |
| | | private TeamUserLevelStatisticService teamUserLevelStatisticService; |
| | | |
| | | @Override |
| | | public Action consume(Message message, ConsumeContext context) { |
| | | |
| | | LogHelper.mqInfo("consumer-UserTeamMessageListener", 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())) {// 用户活跃 |
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody())); |
| | | UserActiveMQMsg userActiveMQMsg = new Gson().fromJson(json.toString(), UserActiveMQMsg.class); |
| | | if (userActiveMQMsg != null) { |
| | | // 更改用户活跃时间 |
| | | teamFansInfoService.updateActiveTime(userActiveMQMsg.getUid(), userActiveMQMsg.getCreateTime()); |
| | | } |
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.userInfoUpdate.name())) {// 用户信息更新 |
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody())); |
| | | UserInfoUpdateMQMsg mqMsg = new Gson().fromJson(json.toString(), UserInfoUpdateMQMsg.class); |
| | | if (mqMsg != null) { |
| | | if (UserInfoUpdateTypeEnum.nickName == mqMsg.getType()) { // 更改昵称 |
| | | teamFansInfoService.updateNickName(mqMsg.getUid(), mqMsg.getValue()); |
| | | } else if (UserInfoUpdateTypeEnum.wxId == mqMsg.getType()) { // 微信号绑定 |
| | | teamFansInfoService.updateWeixinId(mqMsg.getUid(), mqMsg.getValue()); |
| | | } else if (UserInfoUpdateTypeEnum.inviteCode == mqMsg.getType()) { // 邀请码更改 |
| | | teamFansInfoService.updateInviteCode(mqMsg.getUid(), mqMsg.getValue()); |
| | | } |
| | | } |
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.taobaoBindSuccess.name())) {// 淘宝绑定成功 |
| | | // 更改淘宝绑定状态与原用户淘宝绑定状态 |
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody())); |
| | | TaoBaoBindSuccessMQMsg mqMsg = new Gson().fromJson(json.toString(), TaoBaoBindSuccessMQMsg.class); |
| | | if (mqMsg != null) { |
| | | teamFansInfoService.updateTaobaoBind(mqMsg.getUid(), true); |
| | | Long fromUid = mqMsg.getFromUid(); |
| | | if (fromUid != null) { // 淘宝被解绑 |
| | | teamFansInfoService.updateTaobaoBind(fromUid, false); |
| | | } |
| | | } |
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.inviteSuccess.name())) {// 邀请成功 |
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody())); |
| | | UserInviteMQMsg mqMsg = new Gson().fromJson(json.toString(), UserInviteMQMsg.class); |
| | | if (mqMsg != null) { |
| | | ThreeSale ts = threeSaleSerivce.selectByWorkerId(mqMsg.getWorkerId()); |
| | | if (ts == null) |
| | | return Action.ReconsumeLater; |
| | | |
| | | // 更新上级的粉丝数量 |
| | | teamFansInfoService.updateFansNum(mqMsg.getBossId()); |
| | | |
| | | threeSaleDetailService.addByWorkerUid(mqMsg.getWorkerId()); |
| | | |
| | | // 更新队员统计信息 |
| | | teamUserLevelStatisticService.initData(mqMsg.getBossId()); |
| | | UserInfo boss = threeSaleSerivce.getBoss(mqMsg.getBossId()); |
| | | if (boss != null) { |
| | | teamUserLevelStatisticService.initData(boss.getId()); |
| | | } |
| | | |
| | | } |
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.userMoneyAdd.name())) {// 资金到账 |
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody())); |
| | | UserMoneyChangeMQMsg mqMsg = new Gson().fromJson(json.toString(), UserMoneyChangeMQMsg.class); |
| | | if (mqMsg != null) { |
| | | // 更新近60天到账 |
| | | teamFansInfoService.updateIncome(mqMsg.getUid(), mqMsg.getChangeMoney()); |
| | | } |
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.becomeValidUser.name())) {// 成为有效用户 |
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody())); |
| | | BeComeValidUserMQMsg mqMsg = new Gson().fromJson(json.toString(), BeComeValidUserMQMsg.class); |
| | | if (mqMsg != null) { |
| | | // 更新成为有效粉丝 |
| | | teamFansInfoService.updateStateValid(mqMsg.getUid(), true); |
| | | } |
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.userAccountBinding.name())) {// 绑定信息 |
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody())); |
| | | UserAccountBindingMQMsg mqMsg = new Gson().fromJson(json.toString(), UserAccountBindingMQMsg.class); |
| | | if (mqMsg != null) { |
| | | if (mqMsg.getType() == UserAccountBindingMQMsg.TYPE_PHONE) { // 绑定电话号码 |
| | | teamFansInfoService.updatePhone(mqMsg.getUid(), mqMsg.getValue()); |
| | | } |
| | | } |
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.userLevelChanged.name())) {// 等级变化 |
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody())); |
| | | UserLevelChangedMQMsg mqMsg = new Gson().fromJson(json.toString(), UserLevelChangedMQMsg.class); |
| | | if (mqMsg != null) { |
| | | teamFansInfoService.updateLevel(mqMsg.getUid(), mqMsg.getToLevel()); |
| | | } |
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.userPhoneOpen.name())) {// 电话号码公开 |
| | | JSONObject json = JSONObject.fromObject(new String(message.getBody())); |
| | | UserPhoneOpenMQMsg mqMsg = new Gson().fromJson(json.toString(), UserPhoneOpenMQMsg.class); |
| | | if (mqMsg != null) { |
| | | teamFansInfoService.updatePhoneOpen(mqMsg.getUid(), mqMsg.isState()); |
| | | } |
| | | } |
| | | } |
| | | return Action.CommitMessage; |
| | | } |
| | | } |