admin
2020-05-06 24a8d17e007545f7426c48352109aa1a9c6587ee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
    }
}