admin
2020-12-25 25680e135b5bdc15658622cbfde74bab73cfee77
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package com.ks.daylucky.util.mq.consumer;
 
import com.ks.daylucky.pojo.DO.ActivityDrawnRecieveNotifyInfo;
import com.ks.daylucky.service.ActivityDrawnRecieveNotifyInfoService;
import com.ks.daylucky.util.mq.CMQManager;
import com.ks.lucky.pojo.DO.LuckyActivityAwardResult;
import com.ks.lucky.pojo.DO.LuckyActivityAwards;
import com.ks.lucky.pojo.DTO.mq.ActivityDrawnMsgDTO;
import com.ks.lucky.remote.service.LuckyActivityAwardResultService;
import com.ks.lucky.remote.service.LuckyActivityAwardService;
import com.ks.lucky.utils.LuckyCMQConstant;
import com.ks.lucky.utils.mq.CMQConsumeRunner;
import com.qcloud.cmq.Message;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.mq.JobThreadExecutorServiceImpl;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.Vector;
 
public class ActivityDrawnNotifyConsumer implements CMQConsumeRunner {
 
    Logger logger = LoggerFactory.getLogger(ActivityDrawnNotifyConsumer.class);
 
    @Reference(version = "1.0.0")
    private LuckyActivityAwardResultService luckyActivityAwardResultService;
 
    @Reference(version = "1.0.0")
    private LuckyActivityAwardService luckyActivityAwardService;
 
    @Resource
    private ActivityDrawnRecieveNotifyInfoService activityDrawnRecieveNotifyInfoService;
 
    @Override
    public void start() {
        new JobThreadExecutorServiceImpl().run(new Runnable() {
            @Override
            public void run() {
                List<Message> messageList = CMQManager.getInstance().consumeMsgMsg(16);
                if (messageList != null) {
                    for (Message message : messageList) {
                        Vector<String> vectors = message.msgTag;
                        if (vectors.contains(LuckyCMQConstant.TAG_ACTIVITY_DRAWN)) {
 
                            try {
                                //活动状态改变
                                ActivityDrawnMsgDTO dto = JsonUtil.getSimpleGson().fromJson(message.msgBody, ActivityDrawnMsgDTO.class);
                                //获取详情
 
                                LuckyActivityAwardResult result = luckyActivityAwardResultService.getDetail(dto.getAwardResultId());
                                LuckyActivityAwards award = luckyActivityAwardService.getAwardDetail(result.getAwardId());
 
                                String id = null;
                                switch (dto.getAwardResultState()) {
                                    case LuckyActivityAwardResult.STATE_NOT_RECIEVE:
                                        //插入待领取通知
                                        activityDrawnRecieveNotifyInfoService.addNotify(ActivityDrawnRecieveNotifyInfo.create(award, result, ActivityDrawnRecieveNotifyInfo.TYPE_UNRECIEVE));
 
                                        break;
                                    case LuckyActivityAwardResult.STATE_OUT_OF_DATE:
                                        id = ActivityDrawnRecieveNotifyInfo.createId(result.getId(), ActivityDrawnRecieveNotifyInfo.TYPE_UNRECIEVE);
                                        //删除待领取通知
                                        activityDrawnRecieveNotifyInfoService.setNotifyShown(id);
                                        //添加过期通知
                                        activityDrawnRecieveNotifyInfoService.addNotify(ActivityDrawnRecieveNotifyInfo.create(award, result, ActivityDrawnRecieveNotifyInfo.TYPE_OUTDATE));
                                        break;
                                    case LuckyActivityAwardResult.STATE_RECIEVED:
                                        //删除待领取通知
                                        id = ActivityDrawnRecieveNotifyInfo.createId(result.getId(), ActivityDrawnRecieveNotifyInfo.TYPE_UNRECIEVE);
                                        activityDrawnRecieveNotifyInfoService.setNotifyShown(id);
                                        //删除过期通知
                                        id = ActivityDrawnRecieveNotifyInfo.createId(result.getId(), ActivityDrawnRecieveNotifyInfo.TYPE_OUTDATE);
                                        activityDrawnRecieveNotifyInfoService.setNotifyShown(id);
                                        break;
                                    default:
                                        break;
                                }
                                CMQManager.getInstance().deleteMsgMsg(message.receiptHandle);
                            } catch (Exception e) {
                                logger.error("通知消费出错:" + e.getMessage());
                            }
                        } else {
 
                        }
                    }
                }
            }
        });
    }
 
    @Override
    public void destroy() {
 
    }
}