From 5405154d6979f1b50ce2d881bb164b1acca80b6d Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 15 一月 2021 18:58:18 +0800
Subject: [PATCH] 修改相关bug

---
 service-daylucky/src/main/java/com/ks/daylucky/util/mq/consumer/MsgConsumer.java |  116 +++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 74 insertions(+), 42 deletions(-)

diff --git a/service-daylucky/src/main/java/com/ks/daylucky/util/mq/consumer/MsgConsumer.java b/service-daylucky/src/main/java/com/ks/daylucky/util/mq/consumer/MsgConsumer.java
index c48cf29..dc7aade 100644
--- a/service-daylucky/src/main/java/com/ks/daylucky/util/mq/consumer/MsgConsumer.java
+++ b/service-daylucky/src/main/java/com/ks/daylucky/util/mq/consumer/MsgConsumer.java
@@ -1,24 +1,30 @@
 package com.ks.daylucky.util.mq.consumer;
 
+import com.alipay.api.AlipayApiException;
+import com.ks.app.entity.AppInfo;
+import com.ks.app.util.AlipayAppUtil;
 import com.ks.daylucky.exception.UserMsgException;
+import com.ks.daylucky.pojo.DO.UserInfo;
+import com.ks.daylucky.pojo.DO.UserMsg;
 import com.ks.daylucky.pojo.DTO.UserMsgSettings;
+import com.ks.daylucky.pojo.DTO.msg.LuckyMsgContent;
 import com.ks.daylucky.pojo.VO.SimpleUser;
 import com.ks.daylucky.service.UserInfoExtraService;
 import com.ks.daylucky.service.UserInfoService;
 import com.ks.daylucky.service.UserMsgService;
+import com.ks.daylucky.service.impl.AlipayTemplateMsgManager;
+import com.ks.daylucky.service.impl.AppManager;
+import com.ks.daylucky.util.UserInfoUtil;
+import com.ks.daylucky.util.activity.ActivityUtil;
 import com.ks.daylucky.util.factory.LuckyMsgContentFactory;
 import com.ks.daylucky.util.factory.UserMsgFactory;
 import com.ks.daylucky.util.mq.CMQManager;
+import com.ks.lucky.exception.LuckyActivityException;
+import com.ks.lucky.exception.LuckyActivityJoinAssistException;
 import com.ks.lucky.pojo.DO.*;
 import com.ks.lucky.pojo.DTO.ActivitySimpleUser;
-import com.ks.lucky.pojo.DTO.mq.ActivityAssistMsgDTO;
-import com.ks.lucky.pojo.DTO.mq.ActivityDrawnMsgDTO;
-import com.ks.lucky.pojo.DTO.mq.ActivityJoinMsgDTO;
-import com.ks.lucky.pojo.DTO.mq.ActivityStateChangeMsgDTO;
-import com.ks.lucky.remote.service.LuckyActivityAwardResultService;
-import com.ks.lucky.remote.service.LuckyActivityAwardService;
-import com.ks.lucky.remote.service.LuckyActivityJoinAssistService;
-import com.ks.lucky.remote.service.LuckyActivityJoinService;
+import com.ks.lucky.pojo.DTO.mq.*;
+import com.ks.lucky.remote.service.*;
 import com.ks.lucky.utils.LuckyCMQConstant;
 import com.ks.lucky.utils.mq.CMQConsumeRunner;
 import com.qcloud.cmq.Message;
@@ -26,12 +32,13 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.yeshi.utils.JsonUtil;
+import org.yeshi.utils.alipay.AlipayXcxUtil;
+import org.yeshi.utils.exception.AlipayXcxException;
 import org.yeshi.utils.mq.JobThreadExecutorServiceImpl;
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Vector;
 
 public class MsgConsumer implements CMQConsumeRunner {
 
@@ -43,17 +50,26 @@
     @Resource
     private UserInfoService userInfoService;
 
-    @Reference(version = "1.0.0")
+    @Reference(version = "1.0.0", check = false)
     private LuckyActivityJoinAssistService luckyActivityJoinAssistService;
 
-    @Reference(version = "1.0.0")
+    @Reference(version = "1.0.0", check = false)
     private LuckyActivityJoinService luckyActivityJoinService;
 
-    @Reference(version = "1.0.0")
+    @Reference(version = "1.0.0", check = false)
     private LuckyActivityAwardResultService luckyActivityAwardResultService;
 
-    @Reference(version = "1.0.0")
+    @Reference(version = "1.0.0", check = false)
     private LuckyActivityAwardService luckyActivityAwardService;
+
+    @Reference(version = "1.0.0", check = false)
+    private LuckyActivityService luckyActivityService;
+
+    @Resource
+    private AppManager appManager;
+
+    @Resource
+    private AlipayTemplateMsgManager alipayTemplateMsgManager;
 
     @Resource
     private UserMsgService userMsgService;
@@ -86,11 +102,14 @@
         new JobThreadExecutorServiceImpl().run(new Runnable() {
             @Override
             public void run() {
+                logger.info("璇诲彇娑堟伅闃熷垪鏁版嵁");
                 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_STATE_CHANGE)) {
+                        BaseMQMsg baseMQMsg = JsonUtil.getSimpleGson().fromJson(message.msgBody, BaseMQMsg.class);
+                        String tag = baseMQMsg.getCmqMsgTag();
+
+                        if (tag.equalsIgnoreCase(LuckyCMQConstant.TAG_ACTIVITY_STATE_CHANGE)) {
                             //娲诲姩鐘舵�佹敼鍙�
                             ActivityStateChangeMsgDTO dto = JsonUtil.getSimpleGson().fromJson(message.msgBody, ActivityStateChangeMsgDTO.class);
                             List<ActivitySimpleUser> userList;
@@ -102,25 +121,32 @@
                                     for (ActivitySimpleUser user : userList) {
                                         //鍒ゆ柇鏄惁涓
                                         UserMsgSettings settings = getUserMsgSetting(Long.parseLong(user.getUid()));
+                                        LuckyActivity activity = luckyActivityService.getActivity(dto.getActivityId());
 
                                         LuckyActivityAwardResult result = luckyActivityAwardResultService.getResult(user.getAppId(), user.getUid(), dto.getActivityId());
                                         if (result != null) {
-                                            if (settings.getDrawnMsg()) {
+                                            if (settings.getDrawnMsg() != null && settings.getDrawnMsg()) {
                                                 LuckyActivityAwards awards = luckyActivityAwardService.getAwardDetail(result.getAwardId());
 
                                                 try {
-                                                    userMsgService.addMsg(UserMsgFactory.createLuckyMsg(Long.parseLong(result.getUid()), LuckyMsgContentFactory.createDrawn(dto.getActivityId(), awards.getAwardName())));
+                                                    userMsgService.addMsg(UserMsgFactory.createLuckyMsg(Long.parseLong(result.getUid()), LuckyMsgContentFactory.createDrawn(dto.getActivityId(), activity.getCreateTime(), awards.getAwardName())));
                                                 } catch (UserMsgException e) {
                                                     logger.error("娣诲姞涓娑堟伅鍑洪敊", e.getMessage(), result.getId());
                                                 }
+
+                                                //鍙戦�佷腑濂栨ā鏉挎秷鎭�
+                                                alipayTemplateMsgManager.sendDrawnMsg(activity, Long.parseLong(result.getUid()));
                                             }
                                         } else {
-                                            if (settings.getNotDrawnMsg()) {
+                                            if (settings.getNotDrawnMsg() != null && settings.getNotDrawnMsg()) {
                                                 try {
-                                                    userMsgService.addMsg(UserMsgFactory.createLuckyMsg(Long.parseLong(user.getUid()), LuckyMsgContentFactory.createNotDrawn(dto.getActivityId())));
+                                                    userMsgService.addMsg(UserMsgFactory.createLuckyMsg(Long.parseLong(user.getUid()), LuckyMsgContentFactory.createNotDrawn(dto.getActivityId(), activity.getCreateTime())));
                                                 } catch (UserMsgException e) {
                                                     logger.error("娣诲姞鏈腑濂栨秷鎭嚭閿�", e.getMessage(), user.getUid(), dto.getActivityId());
                                                 }
+
+                                                //鍙戦�佹湭涓妯℃澘娑堟伅
+                                                alipayTemplateMsgManager.sendUnDrawnMsg(activity, Long.parseLong(result.getUid()));
                                             }
                                         }
                                     }
@@ -128,12 +154,13 @@
 
                                 case LuckyActivity.STATE_OPEN_FAIL:
                                     userList = getValidJoinerList(dto.getActivityId());
+                                    LuckyActivity activity = luckyActivityService.getActivity(dto.getActivityId());
                                     for (ActivitySimpleUser user : userList) {
                                         //鍒ゆ柇鏄惁涓
                                         UserMsgSettings settings = getUserMsgSetting(Long.parseLong(user.getUid()));
-                                        if (settings.getNotOpenActivityMsg()) {
+                                        if (settings.getNotOpenActivityMsg() != null && settings.getNotOpenActivityMsg()) {
                                             try {
-                                                userMsgService.addMsg(UserMsgFactory.createLuckyMsg(Long.parseLong(user.getUid()), LuckyMsgContentFactory.createOpenFail(dto.getActivityId())));
+                                                userMsgService.addMsg(UserMsgFactory.createLuckyMsg(Long.parseLong(user.getUid()), LuckyMsgContentFactory.createOpenFail(dto.getActivityId(), activity.getCreateTime())));
                                             } catch (UserMsgException e) {
                                                 logger.error("娣诲姞鏈紑濂栨秷鎭嚭閿�", e.getMessage(), user.getUid(), dto.getActivityId());
                                             }
@@ -145,60 +172,65 @@
                             }
 
 
-                        } else if (vectors.contains(LuckyCMQConstant.TAG_ACTIVITY_JOIN)) {
+                        } else if (tag.equalsIgnoreCase(LuckyCMQConstant.TAG_ACTIVITY_JOIN)) {
                             ActivityJoinMsgDTO dto = JsonUtil.getSimpleGson().fromJson(message.msgBody, ActivityJoinMsgDTO.class);
+                            LuckyActivity activity = luckyActivityService.getActivity(dto.getActivityId());
                             UserMsgSettings settings = getUserMsgSetting(Long.parseLong(dto.getUid()));
-                            if (settings.getJoinActivityMsg()) {
+                            if (settings.getJoinActivityMsg() != null && settings.getJoinActivityMsg()) {
                                 try {
-                                    userMsgService.addMsg(UserMsgFactory.createLuckyMsg(Long.parseLong(dto.getUid()), LuckyMsgContentFactory.createJoinSuccess(dto.getActivityId())));
+                                    userMsgService.addMsg(UserMsgFactory.createLuckyMsg(Long.parseLong(dto.getUid()), LuckyMsgContentFactory.createJoinSuccess(dto.getActivityId(), activity.getCreateTime())));
                                 } catch (UserMsgException e) {
                                     logger.error("娣诲姞鍙備笌鎴愬姛娑堟伅鍑洪敊", e.getMessage(), dto.getUid(), dto.getActivityId());
                                 }
                             }
 
-                            //鏌ヨ鏄惁鏈夊姪鍔涘埆浜�
-                            LuckyActivityJoinAssist assist = luckyActivityJoinAssistService.getRecord(dto.getJoinId(), dto.getAppId(), dto.getUid(), ActivityJoinAssistEvent.assistJoin);
+                            //鏌ヨ鏈椿鍔ㄦ槸鍚︽湁鍔╁姏鍒汉
+                            LuckyActivityJoinAssist assist = luckyActivityJoinAssistService.getRecord(null, dto.getActivityId(), dto.getAppId(), dto.getUid(), ActivityJoinAssistEvent.assist);
                             if (assist != null) {
                                 //鏄惁鍔╁姏杩囧埆浜�
                                 LuckyActivityJoinRecord joinRecord = luckyActivityJoinService.getJoinRecord(assist.getJoinId());
                                 if (joinRecord != null) {
-                                    settings = getUserMsgSetting(Long.parseLong(joinRecord.getUid()));
-                                    if (settings.getAssistSuccessMsg()) {
-                                        SimpleUser user = userInfoService.getSimpleUser(Long.parseLong(dto.getUid()));
-                                        try {
-                                            userMsgService.addMsg(UserMsgFactory.createLuckyMsg(Long.parseLong(joinRecord.getUid()), LuckyMsgContentFactory.createAssistAndJoin(dto.getActivityId(), user, assist.getWeight())));
-                                        } catch (UserMsgException e) {
-                                            logger.error("娣诲姞鍔╁姏鎴愬姛涓旇嚜宸卞弬鍔犳秷鎭嚭閿�", e.getMessage(), dto.getUid(), dto.getActivityId());
-                                        }
-
+                                    //寰楀垢杩愬埜
+                                    try {
+                                        luckyActivityJoinAssistService.assist(activity.getId(), dto.getAppId(), dto.getUid(), joinRecord.getUid(), ActivityJoinAssistEvent.assistJoin, 1);
+                                    } catch (LuckyActivityException e) {
+                                        e.printStackTrace();
+                                    } catch (LuckyActivityJoinAssistException e) {
+                                        e.printStackTrace();
                                     }
                                 }
                             }
 
 
-                        } else if (vectors.contains(LuckyCMQConstant.TAG_ASSIST)) {
+                        } else if (tag.equalsIgnoreCase(LuckyCMQConstant.TAG_ASSIST)) {
                             //鍔╁姏
                             ActivityAssistMsgDTO dto = JsonUtil.getSimpleGson().fromJson(message.msgBody, ActivityAssistMsgDTO.class);
-                            UserMsgSettings settings = getUserMsgSetting(Long.parseLong(dto.getUid()));
-                            if (settings.getAssistSuccessMsg()) {
+                            LuckyActivity activity = luckyActivityService.getActivity(dto.getActivityId());
+                            UserMsgSettings settings = getUserMsgSetting(Long.parseLong(dto.getTargetUid()));
+                            if (settings.getAssistSuccessMsg() != null && settings.getAssistSuccessMsg()) {
                                 LuckyActivityJoinRecord record = luckyActivityJoinService.getJoinInfo(dto.getActivityId(), dto.getAppId(), dto.getTargetUid());
                                 if (record != null) {
-                                    LuckyActivityJoinAssist assist = luckyActivityJoinAssistService.getRecord(record.getId(), dto.getAppId(), dto.getUid(), ActivityJoinAssistEvent.assist);
+                                    LuckyActivityJoinAssist assist = luckyActivityJoinAssistService.getRecord(record.getId(), null, dto.getAppId(), dto.getUid(), dto.getAssistEvent());
                                     SimpleUser user = userInfoService.getSimpleUser(Long.parseLong(dto.getUid()));
                                     try {
-                                        userMsgService.addMsg(UserMsgFactory.createLuckyMsg(Long.parseLong(dto.getTargetUid()), LuckyMsgContentFactory.createAssist(dto.getActivityId(), user, assist.getWeight())));
+                                        if (dto.getAssistEvent() == ActivityJoinAssistEvent.assist) {
+                                            userMsgService.addMsg(UserMsgFactory.createLuckyMsg(Long.parseLong(dto.getTargetUid()), LuckyMsgContentFactory.createAssist(dto.getActivityId(), activity.getCreateTime(), user, assist.getWeight())));
+                                        } else if (dto.getAssistEvent() == ActivityJoinAssistEvent.assistJoin) {
+                                            userMsgService.addMsg(UserMsgFactory.createLuckyMsg(Long.parseLong(dto.getTargetUid()), LuckyMsgContentFactory.createAssistAndJoin(dto.getActivityId(), activity.getCreateTime(), user, assist.getWeight())));
+                                        }
                                     } catch (UserMsgException e) {
                                         logger.error("娣诲姞鍔╁姏鎴愬姛娑堟伅鍑洪敊", e.getMessage(), dto.getUid(), dto.getActivityId());
                                     }
                                 }
                             }
 
-                        } else if (vectors.contains(LuckyCMQConstant.TAG_ACTIVITY_DRAWN)) {
+                        } else if (tag.equalsIgnoreCase(LuckyCMQConstant.TAG_ACTIVITY_DRAWN)) {
                             ActivityDrawnMsgDTO dto = JsonUtil.getSimpleGson().fromJson(message.msgBody, ActivityDrawnMsgDTO.class);
+                            LuckyActivity activity = luckyActivityService.getActivity(dto.getActivityId());
                             switch (dto.getAwardResultState()) {
                                 case LuckyActivityAwardResult.STATE_OUT_OF_DATE:
                                     try {
-                                        userMsgService.addMsg(UserMsgFactory.createLuckyMsg(Long.parseLong(dto.getUid()), LuckyMsgContentFactory.createReceiveOutDate(dto.getActivityId())));
+                                        userMsgService.addMsg(UserMsgFactory.createLuckyMsg(Long.parseLong(dto.getUid()), LuckyMsgContentFactory.createReceiveOutDate(dto.getActivityId(), activity.getCreateTime())));
                                     } catch (UserMsgException e) {
                                         logger.error("娣诲姞杩囨湡鏈娑堟伅鍑洪敊", e.getMessage(), dto.getUid(), dto.getActivityId());
                                     }

--
Gitblit v1.8.0