| | |
| | | package com.yeshi.fanli.util.rocketmq.order;
|
| | |
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | import com.aliyun.openservices.ons.api.Message;
|
| | | import com.aliyun.openservices.ons.api.transaction.LocalTransactionChecker;
|
| | | import com.aliyun.openservices.ons.api.transaction.TransactionStatus;
|
| | | import com.google.gson.Gson;
|
| | | 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.entity.bus.user.HongBaoV2;
|
| | | import com.yeshi.fanli.entity.order.CommonOrder;
|
| | | import com.yeshi.fanli.entity.order.HongBaoOrder;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoV2SettleTempService;
|
| | | import com.yeshi.fanli.service.inter.order.CommonOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
|
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName;
|
| | |
|
| | | @Component
|
| | | public class MQLocalTransactionChecker implements LocalTransactionChecker {
|
| | |
|
| | | @Resource
|
| | | private MQLocalUserCouponUsedTransactionChecker mqLocalUserCouponUsedTransactionChecker;
|
| | |
|
| | | @Resource
|
| | | private HongBaoV2SettleTempService hongBaoV2SettleTempService;
|
| | |
|
| | | @Resource
|
| | | private CommonOrderService commonOrderService;
|
| | |
|
| | | @Resource
|
| | | private HongBaoOrderService hongBaoOrderService;
|
| | |
|
| | | public MQLocalTransactionChecker() {
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public TransactionStatus check(Message msg) {
|
| | |
|
| | | String tag = msg.getTag();
|
| | | if (msg.getTopic().equalsIgnoreCase(MQTopicName.TOPIC_ORDER.name())) {
|
| | | if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderFanLiActual.name())) {
|
| | | if (hongBaoV2SettleTempService.countByKey(msg.getKey()) > 0)
|
| | | return TransactionStatus.CommitTransaction;
|
| | | else
|
| | | return TransactionStatus.RollbackTransaction;
|
| | | } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderFanLiDelay.name())) {
|
| | | OrderMoneyRecievedMQMsg dto = new Gson().fromJson(new String(msg.getBody()),
|
| | | OrderMoneyRecievedMQMsg.class);
|
| | | if (dto != null) {
|
| | | if (dto.getType() == OrderMoneyRecievedMQMsg.TYPE_ZIGOU) {
|
| | | // TODO 尚未处理一个订单部分到账的状况
|
| | | // 返利是否到账
|
| | | List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(dto.getSourceType(),
|
| | | dto.getOrderId());
|
| | | for (CommonOrder order : orderList) {
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderService.selectDetailByCommonOrderId(order.getId());
|
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null
|
| | | && hongBaoOrder.getHongBaoV2().getState() == HongBaoV2.STATE_YILINGQU) {
|
| | | return TransactionStatus.CommitTransaction;
|
| | | }
|
| | | }
|
| | | return TransactionStatus.RollbackTransaction;
|
| | | }
|
| | | }
|
| | | // 其他未知条件暂时处理为回滚
|
| | | return TransactionStatus.RollbackTransaction;
|
| | | }
|
| | |
|
| | | } else if (msg.getTopic().equalsIgnoreCase(MQTopicName.TOPIC_USER.name())) {
|
| | | if (tag.equalsIgnoreCase(UserTopicTagEnum.useSystemCoupon.name()))// 系统券使用
|
| | | return mqLocalUserCouponUsedTransactionChecker.check(msg);
|
| | | }
|
| | |
|
| | | return TransactionStatus.Unknow;
|
| | | }
|
| | | }
|
| | | package com.yeshi.fanli.util.rocketmq.order; |
| | | |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import com.aliyun.openservices.ons.api.Message; |
| | | import com.aliyun.openservices.ons.api.transaction.LocalTransactionChecker; |
| | | import com.aliyun.openservices.ons.api.transaction.TransactionStatus; |
| | | import com.google.gson.Gson; |
| | | 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.entity.bus.user.HongBaoV2; |
| | | import com.yeshi.fanli.entity.order.CommonOrder; |
| | | import com.yeshi.fanli.entity.order.HongBaoOrder; |
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoV2SettleTempService; |
| | | import com.yeshi.fanli.service.inter.order.CommonOrderService; |
| | | import com.yeshi.fanli.service.inter.order.HongBaoOrderService; |
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName; |
| | | |
| | | @Component |
| | | public class MQLocalTransactionChecker implements LocalTransactionChecker { |
| | | |
| | | @Resource |
| | | private MQLocalUserCouponUsedTransactionChecker mqLocalUserCouponUsedTransactionChecker; |
| | | |
| | | @Resource |
| | | private HongBaoV2SettleTempService hongBaoV2SettleTempService; |
| | | |
| | | @Resource |
| | | private CommonOrderService commonOrderService; |
| | | |
| | | @Resource |
| | | private HongBaoOrderService hongBaoOrderService; |
| | | |
| | | public MQLocalTransactionChecker() { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public TransactionStatus check(Message msg) { |
| | | |
| | | String tag = msg.getTag(); |
| | | if (msg.getTopic().equalsIgnoreCase(MQTopicName.TOPIC_ORDER.name())) { |
| | | if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderFanLiActual.name())) { |
| | | if (hongBaoV2SettleTempService.countByKey(msg.getKey()) > 0) |
| | | return TransactionStatus.CommitTransaction; |
| | | else |
| | | return TransactionStatus.RollbackTransaction; |
| | | } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.teamRewardPreRecieved.name())) { |
| | | if (hongBaoV2SettleTempService.countByKey(msg.getKey()) > 0) |
| | | return TransactionStatus.CommitTransaction; |
| | | else |
| | | return TransactionStatus.RollbackTransaction; |
| | | }else if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderFanLiDelay.name())) { |
| | | OrderMoneyRecievedMQMsg dto = new Gson().fromJson(new String(msg.getBody()), |
| | | OrderMoneyRecievedMQMsg.class); |
| | | if (dto != null) { |
| | | if (dto.getType() == OrderMoneyRecievedMQMsg.TYPE_ZIGOU) { |
| | | // TODO 尚未处理一个订单部分到账的状况 |
| | | // 返利是否到账 |
| | | List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(dto.getSourceType(), |
| | | dto.getOrderId()); |
| | | for (CommonOrder order : orderList) { |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderService.selectDetailByCommonOrderId(order.getId()); |
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null |
| | | && hongBaoOrder.getHongBaoV2().getState() == HongBaoV2.STATE_YILINGQU) { |
| | | return TransactionStatus.CommitTransaction; |
| | | } |
| | | } |
| | | return TransactionStatus.RollbackTransaction; |
| | | } |
| | | } |
| | | // 其他未知条件暂时处理为回滚 |
| | | return TransactionStatus.RollbackTransaction; |
| | | } |
| | | |
| | | } else if (msg.getTopic().equalsIgnoreCase(MQTopicName.TOPIC_USER.name())) { |
| | | if (tag.equalsIgnoreCase(UserTopicTagEnum.useSystemCoupon.name()))// 系统券使用 |
| | | return mqLocalUserCouponUsedTransactionChecker.check(msg); |
| | | } |
| | | |
| | | return TransactionStatus.Unknow; |
| | | } |
| | | } |