yujian
2019-10-28 bf5c02aaecb3f7a42daa4fa356c62a2e6bca0db5
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
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;
    }
}