| | |
| | | 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.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.dto.mq.order.body.OrderMQMsg;
|
| | | 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.Constant;
|
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName;
|
| | |
| | | @Resource
|
| | | private UserSystemCouponService userSystemCouponService;
|
| | |
|
| | | @Resource
|
| | | private RedPackWinInviteService redPackWinInviteService;
|
| | |
|
| | | @Resource
|
| | | private RedPackGiveRecordService redPackGiveRecordService;
|
| | |
|
| | | @Resource(name = "producer")
|
| | | private Producer producer;
|
| | |
|
| | | @Override
|
| | | public Action consume(Message message, ConsumeContext context) {
|
| | | LogHelper.mqInfo("consumer-RedPackMessageListener", message.getTopic(), message.getTag(),
|
| | | LogHelper.mqInfo("consumer-RedPackMessageListener", message.getMsgID(), 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())) {// 返利到账
|
| | | if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderStatistic.name())) {// 订单统
|
| | | OrderMQMsg mqMsg = new Gson().fromJson(new String(message.getBody()), OrderMQMsg.class);
|
| | | |
| | | try {// 邀请奖励
|
| | | redPackWinInviteService.winRedPackByOrder(mqMsg.getUid(), mqMsg.getOrderId(), mqMsg.getType(), mqMsg.getPlaceTime());
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | |
| | | boolean verifyOrder = redPackWinInviteService.verifyOrder(mqMsg.getUid(), mqMsg.getOrderId(), mqMsg.getType(), mqMsg.getPlaceTime());
|
| | | if (verifyOrder) {
|
| | | // 发送48小时延时消息
|
| | | int hour = 48;
|
| | | if (Constant.IS_TEST) {
|
| | | hour = 1;
|
| | | }
|
| | | mqMsg.setDelayHour(hour);
|
| | | Message msg = new Message(message.getTopic(), OrderTopicTagEnum.orderStatisticDelay.name(),
|
| | | new Gson().toJson(mqMsg).getBytes());
|
| | | if (mqMsg.getStaticticDate().getTime() + 1000 * 60 * 60L * hour > System.currentTimeMillis())// 时间是否已经过了
|
| | | msg.setStartDeliverTime(mqMsg.getStaticticDate().getTime() + 1000 * 60 * 60L * hour);
|
| | | else
|
| | | msg.setStartDeliverTime(System.currentTimeMillis() + 1000 * 60);
|
| | | producer.send(msg);
|
| | | }
|
| | | return Action.CommitMessage;
|
| | | } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderStatisticDelay.name())) {// 订单统计
|
| | | OrderMQMsg mqMsg = new Gson().fromJson(new String(message.getBody()), OrderMQMsg.class);
|
| | | int hour = 48;
|
| | | if (Constant.IS_TEST) {
|
| | | hour = 1;
|
| | | }
|
| | |
|
| | | } 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);
|
| | | if (mqMsg.getDelayHour() == hour) {
|
| | | try {
|
| | | redPackWinInviteService.winFreeCoupon(mqMsg.getUid(), mqMsg.getOrderId(), mqMsg.getType(), mqMsg.getPlaceTime());
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | return Action.ReconsumeLater;
|
| | | }
|
| | | }
|
| | | return Action.CommitMessage;
|
| | | }
|
| | | }
|
| | | return Action.CommitMessage;
|