yujian
2020-01-18 f4a0f2acc63d7785eab108419a4e16f5f688cb95
fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/coupon/SystemCouponMessageListener.java
@@ -1,5 +1,7 @@
package com.yeshi.fanli.util.rocketmq.consumer.coupon;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import com.aliyun.openservices.ons.api.Action;
@@ -7,29 +9,57 @@
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageListener;
import com.google.gson.Gson;
import com.yeshi.fanli.dto.order.OrderMoneyRecievedMQMsgDTO;
import com.yeshi.fanli.dto.mq.BaseMQMsgBody;
import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg;
import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum;
import com.yeshi.fanli.dto.mq.user.body.UserSystemCouponUseMQMsg;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.util.rocketmq.MQTopicName;
@Component
public class SystemCouponMessageListener implements MessageListener {
   @Resource
   private UserSystemCouponService userSystemCouponService;
   @Override
   public Action consume(Message message, ConsumeContext context) {
      LogHelper.mqInfo("consumer-SystemCouponMessageListener", message.getTopic(), message.getTag(),
            new String(message.getBody()));
      if (MQTopicName.TOPIC_FANLI.name().equalsIgnoreCase(message.getTopic())) {
         OrderMoneyRecievedMQMsgDTO orderMoneyRecievedMQMsgDTO = new Gson().fromJson(new String(message.getBody()),
               OrderMoneyRecievedMQMsgDTO.class);
         if (orderMoneyRecievedMQMsgDTO != null) {
            if (orderMoneyRecievedMQMsgDTO.getOrderFirst() != null
                  && orderMoneyRecievedMQMsgDTO.getOrderFirst() == true) {
               // 首次到账返利
               // TODO 业务代码添加
      LogHelper.mqInfo("consumer-SystemCouponMessageListener", message.getMsgID(), message.getTopic(),
            message.getTag(), new String(message.getBody()));
      String tag = message.getTag();
      BaseMQMsgBody baseBody = new Gson().fromJson(new String(message.getBody()), BaseMQMsgBody.class);
               // 业务代码执行成功后返回
               return Action.CommitMessage;
      if (MQTopicName.TOPIC_ORDER.name().equalsIgnoreCase(message.getTopic())) {
         if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderFanLiActual.name()))// 实时到账
         {
            OrderMoneyRecievedMQMsg orderMoneyRecievedMQMsgDTO = new Gson().fromJson(new String(message.getBody()),
                  OrderMoneyRecievedMQMsg.class);
            if (orderMoneyRecievedMQMsgDTO != null) {
               if (orderMoneyRecievedMQMsgDTO.getOrderFirst() != null
                     && orderMoneyRecievedMQMsgDTO.getOrderFirst() == true) {
                  // 首次到账返利
                  // 激活免单券
                  userSystemCouponService.triggerFreeCouponActivate(orderMoneyRecievedMQMsgDTO.getUid(),
                        orderMoneyRecievedMQMsgDTO.getOrderId(), orderMoneyRecievedMQMsgDTO.getSourceType());
                  // 业务代码执行成功后返回
                  return Action.CommitMessage;
               }
            }
         }
      } else if (MQTopicName.TOPIC_USER.name().equalsIgnoreCase(message.getTopic())) {
         if (UserTopicTagEnum.systemCouponDrawback.name().equalsIgnoreCase(tag)) {// 券退回
            UserSystemCouponUseMQMsg userSystemCouponUseMQMsg = new Gson().fromJson(new String(message.getBody()),
                  UserSystemCouponUseMQMsg.class);
            //处理券退回
            userSystemCouponService.sendBackByGiveId(userSystemCouponUseMQMsg.getUserSystemCouponId());
            // 业务代码执行成功后返回
            return Action.CommitMessage;
         }
      }
      return Action.CommitMessage;
   }