admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/util/rocketmq/order/MQLocalUserCouponUsedTransactionChecker.java
@@ -1,54 +1,54 @@
package com.yeshi.fanli.util.rocketmq.order;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.transaction.TransactionStatus;
import com.google.gson.Gson;
import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum;
import com.yeshi.fanli.dto.mq.user.body.UserSystemCouponUseMQMsg;
import com.yeshi.fanli.entity.bus.user.UserSystemCouponRecord;
import com.yeshi.fanli.entity.system.SystemCoupon;
import com.yeshi.fanli.service.inter.user.UserSystemCouponRecordService;
import com.yeshi.fanli.util.rocketmq.MQTopicName;
/**
 * 券使用事务检查
 *
 * @author Administrator
 *
 */
@Component
public class MQLocalUserCouponUsedTransactionChecker {
   @Resource
   private UserSystemCouponRecordService userSystemCouponRecordService;
   public MQLocalUserCouponUsedTransactionChecker() {
   }
   public TransactionStatus check(Message msg) {
      if (msg.getTopic().equalsIgnoreCase(MQTopicName.TOPIC_USER.name())) {
         if (msg.getTag().equalsIgnoreCase(UserTopicTagEnum.useSystemCoupon.name())) {// 返利奖励券
            // 查询是否使用成功
            UserSystemCouponUseMQMsg dto = new Gson().fromJson(new String(msg.getBody()),
                  UserSystemCouponUseMQMsg.class);
            if (SystemCoupon.CouponTypeEnum.rebatePercentCoupon.name().equalsIgnoreCase(dto.getCouponType())) {
               UserSystemCouponRecord record = userSystemCouponRecordService
                     .getNearByUserCouponId(dto.getUserSystemCouponId());
               if (record != null) {
                  if (record.getOrderNo().equalsIgnoreCase(dto.getOrderId())
                        && dto.getSourceType().intValue() == record.getGoodSource()) {
                     return TransactionStatus.CommitTransaction;
                  }
               }
               return TransactionStatus.RollbackTransaction;
            }
         }
      }
      return TransactionStatus.Unknow;
   }
}
package com.yeshi.fanli.util.rocketmq.order;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.transaction.TransactionStatus;
import com.google.gson.Gson;
import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum;
import com.yeshi.fanli.dto.mq.user.body.UserSystemCouponUseMQMsg;
import com.yeshi.fanli.entity.bus.user.UserSystemCouponRecord;
import com.yeshi.fanli.entity.system.SystemCoupon;
import com.yeshi.fanli.service.inter.user.UserSystemCouponRecordService;
import com.yeshi.fanli.util.rocketmq.MQTopicName;
/**
 * 券使用事务检查
 *
 * @author Administrator
 *
 */
@Component
public class MQLocalUserCouponUsedTransactionChecker {
   @Resource
   private UserSystemCouponRecordService userSystemCouponRecordService;
   public MQLocalUserCouponUsedTransactionChecker() {
   }
   public TransactionStatus check(Message msg) {
      if (msg.getTopic().equalsIgnoreCase(MQTopicName.TOPIC_USER.name())) {
         if (msg.getTag().equalsIgnoreCase(UserTopicTagEnum.useSystemCoupon.name())) {// 返利奖励券
            // 查询是否使用成功
            UserSystemCouponUseMQMsg dto = new Gson().fromJson(new String(msg.getBody()),
                  UserSystemCouponUseMQMsg.class);
            if (SystemCoupon.CouponTypeEnum.rebatePercentCoupon.name().equalsIgnoreCase(dto.getCouponType())) {
               UserSystemCouponRecord record = userSystemCouponRecordService
                     .getNearByUserCouponId(dto.getUserSystemCouponId());
               if (record != null) {
                  if (record.getOrderNo().equalsIgnoreCase(dto.getOrderId())
                        && dto.getSourceType().intValue() == record.getGoodSource()) {
                     return TransactionStatus.CommitTransaction;
                  }
               }
               return TransactionStatus.RollbackTransaction;
            }
         }
      }
      return TransactionStatus.Unknow;
   }
}