| | |
| | | package com.yeshi.fanli.util.rocketmq.consumer.redpack;
|
| | |
|
| | | 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.BaseMQMsgBody;
|
| | | import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
|
| | | import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum;
|
| | | import com.yeshi.fanli.dto.mq.user.body.IntegralTaskMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.user.body.UserAccountBindingMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.user.body.UserInviteMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.user.body.UserRegisterMQMsg;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName;
|
| | |
|
| | | /**
|
| | | * 红包消费
|
| | | * |
| | | * @author Administrator
|
| | | *
|
| | | */
|
| | | @Component
|
| | | public class RedPackMessageListener implements MessageListener {
|
| | |
|
| | | @Resource
|
| | | private UserSystemCouponService userSystemCouponService;
|
| | |
|
| | | @Override
|
| | | public Action consume(Message message, ConsumeContext context) {
|
| | | LogHelper.mqInfo("consumer-RedPackMessageListener", message.getTopic(), message.getTag(),
|
| | | new String(message.getBody()));
|
| | | String tag = message.getTag();
|
| | | if (tag == null)
|
| | | tag = "";
|
| | | BaseMQMsgBody baseBody = new Gson().fromJson(new String(message.getBody()), BaseMQMsgBody.class);
|
| | | if (baseBody.isTest() != Constant.IS_TEST)
|
| | | return Action.ReconsumeLater;
|
| | |
|
| | | if (MQTopicName.TOPIC_ORDER.name().equalsIgnoreCase(message.getTopic())) {
|
| | | if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderFanLiActual.name())) {// 返利到账
|
| | |
|
| | | } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderStatistic.name())) {// 订单统计
|
| | |
|
| | | }
|
| | | } else if (MQTopicName.TOPIC_USER.name().equalsIgnoreCase(message.getTopic())) {
|
| | | if (tag.equalsIgnoreCase(UserTopicTagEnum.userAccountBinding.name())) {// 账号绑定
|
| | | UserAccountBindingMQMsg userAccountBindingMQMsg = new Gson().fromJson(new String(message.getBody()),
|
| | | UserAccountBindingMQMsg.class);
|
| | |
|
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.inviteSuccess.name())) {// 邀请成功
|
| | | UserInviteMQMsg userInviteMQMsg = new Gson().fromJson(new String(message.getBody()),
|
| | | UserInviteMQMsg.class);
|
| | |
|
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.integralTaskFinish.name())) {// 金币任务完成
|
| | | IntegralTaskMQMsg integralTaskMQMsg = new Gson().fromJson(new String(message.getBody()),
|
| | | IntegralTaskMQMsg.class);
|
| | | }
|
| | | }
|
| | | return Action.CommitMessage;
|
| | | }
|
| | | }
|
| | | package com.yeshi.fanli.util.rocketmq.consumer.redpack; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.entity.SystemFunction; |
| | | import com.yeshi.fanli.service.inter.user.UserInfoService; |
| | | import com.yeshi.fanli.service.manger.msg.RocketMQManager; |
| | | 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.aliyun.openservices.ons.api.Producer; |
| | | import com.google.gson.Gson; |
| | | import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum; |
| | | import com.yeshi.fanli.dto.mq.order.body.OrderConfirmMQMsg; |
| | | import com.yeshi.fanli.log.LogHelper; |
| | | import com.yeshi.fanli.service.inter.redpack.RedPackGiveRecordService; |
| | | import com.yeshi.fanli.service.inter.redpack.RedPackWinInviteService; |
| | | import com.yeshi.fanli.service.inter.user.UserSystemCouponService; |
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName; |
| | | |
| | | /** |
| | | * 红包消费 |
| | | * |
| | | * @author Administrator |
| | | */ |
| | | @Component |
| | | public class RedPackMessageListener implements MessageListener { |
| | | |
| | | @Resource |
| | | private UserSystemCouponService userSystemCouponService; |
| | | |
| | | @Resource |
| | | private RedPackWinInviteService redPackWinInviteService; |
| | | |
| | | @Resource |
| | | private RedPackGiveRecordService redPackGiveRecordService; |
| | | |
| | | @Resource |
| | | private RocketMQManager rocketMQManager; |
| | | |
| | | @Resource |
| | | private UserInfoService userInfoService; |
| | | |
| | | @Override |
| | | public Action consume(Message message, ConsumeContext context) { |
| | | LogHelper.mqInfo("consumer-RedPackMessageListener", message.getMsgID(), message.getTopic(), message.getTag(), |
| | | new String(message.getBody())); |
| | | String tag = message.getTag(); |
| | | if (tag == null) |
| | | tag = ""; |
| | | |
| | | if (MQTopicName.TOPIC_ORDER.name().equalsIgnoreCase(message.getTopic())) { |
| | | // 订单确认收货 |
| | | if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderConfirm.name())) { |
| | | OrderConfirmMQMsg mqMsg = new Gson().fromJson(new String(message.getBody()), OrderConfirmMQMsg.class); |
| | | //判断系统是否包含红包功能 |
| | | Long sourceUid = mqMsg.getSourceUid(); |
| | | SystemEnum system = userInfoService.getUserSystem(sourceUid); |
| | | if (!system.getFunctionSet().contains(SystemFunction.redPack)) |
| | | return Action.CommitMessage; |
| | | try {// 邀请奖励 |
| | | redPackWinInviteService.winRedPackByOrder(mqMsg.getSourceUid(), mqMsg.getOrderNo(), mqMsg.getSourceType()); |
| | | } catch (Exception e) { |
| | | LogHelper.errorDetailInfo(e); |
| | | } |
| | | } |
| | | } |
| | | return Action.CommitMessage; |
| | | } |
| | | } |