| | |
| | | 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.user.coupon.UserSystemCouponUseMQMsgDTO;
|
| | | 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_SYSTEM_COUPON_USE.name())) {
|
| | | if (msg.getTag().equalsIgnoreCase(SystemCoupon.CouponTypeEnum.rebatePercentCoupon.name())) {// 返利奖励券
|
| | | // 查询是否使用成功
|
| | | UserSystemCouponUseMQMsgDTO dto = new Gson().fromJson(new String(msg.getBody()),
|
| | | UserSystemCouponUseMQMsgDTO.class);
|
| | | 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; |
| | | } |
| | | } |