Преглед изворни кода

增加历史数据区分数据源

xueyiming пре 6 месеци
родитељ
комит
4dcd896913

+ 19 - 0
we-com-server/src/main/java/com/tzld/piaoquan/wecom/common/enums/SourceEnum.java

@@ -0,0 +1,19 @@
+package com.tzld.piaoquan.wecom.common.enums;
+
+import lombok.Getter;
+
+@Getter
+public enum SourceEnum {
+
+    MANUAL("manual", "保底记录"),
+    HISTORICAL_TOP("historical_top", "优质记录");
+
+    final String name;
+    final String desc;
+
+    SourceEnum(String name, String desc) {
+        this.name = name;
+        this.desc = desc;
+    }
+
+}

+ 26 - 5
we-com-server/src/main/java/com/tzld/piaoquan/wecom/job/WeComHistoryDataJob.java

@@ -15,10 +15,12 @@ import com.tzld.piaoquan.wecom.model.bo.MiniprogramRecord;
 import com.tzld.piaoquan.wecom.model.bo.SendDetail;
 import com.tzld.piaoquan.wecom.model.bo.SendDetail;
 import com.tzld.piaoquan.wecom.model.bo.XxlJobParam;
 import com.tzld.piaoquan.wecom.model.bo.XxlJobParam;
 import com.tzld.piaoquan.wecom.model.po.*;
 import com.tzld.piaoquan.wecom.model.po.*;
+import com.tzld.piaoquan.wecom.model.vo.GuaranteedParam;
 import com.tzld.piaoquan.wecom.service.AccessTokenService;
 import com.tzld.piaoquan.wecom.service.AccessTokenService;
 import com.tzld.piaoquan.wecom.service.HistoryMessageService;
 import com.tzld.piaoquan.wecom.service.HistoryMessageService;
 import com.tzld.piaoquan.wecom.service.MessageAttachmentService;
 import com.tzld.piaoquan.wecom.service.MessageAttachmentService;
 import com.tzld.piaoquan.wecom.service.UserService;
 import com.tzld.piaoquan.wecom.service.UserService;
+import com.tzld.piaoquan.wecom.utils.DateUtil;
 import com.tzld.piaoquan.wecom.utils.LarkRobotUtil;
 import com.tzld.piaoquan.wecom.utils.LarkRobotUtil;
 import com.tzld.piaoquan.wecom.utils.MessageUtil;
 import com.tzld.piaoquan.wecom.utils.MessageUtil;
 import com.tzld.piaoquan.wecom.utils.page.Page;
 import com.tzld.piaoquan.wecom.utils.page.Page;
@@ -27,18 +29,20 @@ import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 
 
 import java.io.IOException;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
 import static com.tzld.piaoquan.wecom.common.constant.MessageConstant.MAX_VIDEO_NUM;
 import static com.tzld.piaoquan.wecom.common.constant.MessageConstant.MAX_VIDEO_NUM;
+import static com.tzld.piaoquan.wecom.common.constant.RedisConstant.GUARANTEED_MINI_PROGRAM_KEY;
+import static com.tzld.piaoquan.wecom.common.constant.RedisConstant.GUARANTEED_MINI_PROGRAM_SET_KEY;
 import static com.tzld.piaoquan.wecom.common.constant.WeComConstant.*;
 import static com.tzld.piaoquan.wecom.common.constant.WeComConstant.*;
+import static com.tzld.piaoquan.wecom.common.enums.SourceEnum.HISTORICAL_TOP;
+import static com.tzld.piaoquan.wecom.common.enums.SourceEnum.MANUAL;
 
 
 @Slf4j
 @Slf4j
 @Component
 @Component
@@ -71,6 +75,9 @@ public class WeComHistoryDataJob {
     @Autowired
     @Autowired
     private CorpMapper corpMapper;
     private CorpMapper corpMapper;
 
 
+    @Autowired
+    private RedisTemplate<String, Object> redisTemplate;
+
 
 
     @XxlJob("saveHistoryMessageJob")
     @XxlJob("saveHistoryMessageJob")
     public ReturnT<String> selectHistoryMessageByDay(String param) {
     public ReturnT<String> selectHistoryMessageByDay(String param) {
@@ -111,6 +118,8 @@ public class WeComHistoryDataJob {
         for (Corp corp : corps) {
         for (Corp corp : corps) {
             selectAlertHistoryMessage(xxlJobParam.getStartTime(), xxlJobParam.getEndTime(), corp.getId(), corp.getName());
             selectAlertHistoryMessage(xxlJobParam.getStartTime(), xxlJobParam.getEndTime(), corp.getId(), corp.getName());
         }
         }
+        String key = String.format(GUARANTEED_MINI_PROGRAM_SET_KEY, DateUtil.getThatDayDateString());
+        redisTemplate.delete(key);
         return ReturnT.SUCCESS;
         return ReturnT.SUCCESS;
     }
     }
 
 
@@ -339,6 +348,12 @@ public class WeComHistoryDataJob {
         if (CollectionUtils.isEmpty(externalUsers) || CollectionUtils.isEmpty(miniprogramRecordList)) {
         if (CollectionUtils.isEmpty(externalUsers) || CollectionUtils.isEmpty(miniprogramRecordList)) {
             return;
             return;
         }
         }
+        String key = String.format(GUARANTEED_MINI_PROGRAM_SET_KEY, DateUtil.getThatDayDateString());
+        Set<Long> guaranteedSet = (Set<Long>) redisTemplate.opsForValue().get(key);
+        if (CollectionUtils.isEmpty(guaranteedSet)) {
+            LarkRobotUtil.sendMessage("获取保底set失败");
+            return;
+        }
         Long sendTime = externalUsers.stream().map(ExternalUser::getSendTime).filter(Objects::nonNull).findFirst().orElse(null);
         Long sendTime = externalUsers.stream().map(ExternalUser::getSendTime).filter(Objects::nonNull).findFirst().orElse(null);
         List<HistoryMessage> historyMessageList = new ArrayList<>();
         List<HistoryMessage> historyMessageList = new ArrayList<>();
         for (ExternalUser externalUser : externalUsers) {
         for (ExternalUser externalUser : externalUsers) {
@@ -358,12 +373,18 @@ public class WeComHistoryDataJob {
                         historyMessage.setSendTime(new Date(createTime));
                         historyMessage.setSendTime(new Date(createTime));
                     }
                     }
                 }
                 }
+                Long videoId = miniprogramRecord.getVideoId();
                 historyMessage.setAttachmentIdx(miniprogramRecord.getAttachmentIdx());
                 historyMessage.setAttachmentIdx(miniprogramRecord.getAttachmentIdx());
-                historyMessage.setVideoId(miniprogramRecord.getVideoId());
+                historyMessage.setVideoId(videoId);
                 historyMessage.setUserId(userId);
                 historyMessage.setUserId(userId);
                 historyMessage.setStaffId(staff.getId());
                 historyMessage.setStaffId(staff.getId());
                 historyMessage.setStatus(status);
                 historyMessage.setStatus(status);
                 historyMessage.setCorpId(corpId);
                 historyMessage.setCorpId(corpId);
+                if (guaranteedSet.contains(videoId)) {
+                    historyMessage.setSource(MANUAL.getName());
+                } else {
+                    historyMessage.setSource(HISTORICAL_TOP.getName());
+                }
                 historyMessageList.add(historyMessage);
                 historyMessageList.add(historyMessage);
                 if (status == 2) {
                 if (status == 2) {
                     userService.delStaffWithUser(userId, staff.getId(), sendTime);
                     userService.delStaffWithUser(userId, staff.getId(), sendTime);

+ 4 - 2
we-com-server/src/main/java/com/tzld/piaoquan/wecom/service/Impl/MessageAttachmentServiceImpl.java

@@ -40,6 +40,7 @@ import static com.tzld.piaoquan.wecom.common.constant.MessageConstant.appid;
 import static com.tzld.piaoquan.wecom.common.constant.OtherServerURL.POST_ADD_TENCENT;
 import static com.tzld.piaoquan.wecom.common.constant.OtherServerURL.POST_ADD_TENCENT;
 import static com.tzld.piaoquan.wecom.common.constant.OtherServerURL.POST_VIDEO_DETAIL_URL;
 import static com.tzld.piaoquan.wecom.common.constant.OtherServerURL.POST_VIDEO_DETAIL_URL;
 import static com.tzld.piaoquan.wecom.common.constant.RedisConstant.GUARANTEED_MINI_PROGRAM_KEY;
 import static com.tzld.piaoquan.wecom.common.constant.RedisConstant.GUARANTEED_MINI_PROGRAM_KEY;
+import static com.tzld.piaoquan.wecom.common.constant.RedisConstant.GUARANTEED_MINI_PROGRAM_SET_KEY;
 import static com.tzld.piaoquan.wecom.common.constant.WeComConstant.POST_WE_COM_MEDIA_UPLOAD;
 import static com.tzld.piaoquan.wecom.common.constant.WeComConstant.POST_WE_COM_MEDIA_UPLOAD;
 
 
 
 
@@ -83,7 +84,7 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
                 || CollectionUtils.isEmpty(guaranteedParam.getVideoParamList())) {
                 || CollectionUtils.isEmpty(guaranteedParam.getVideoParamList())) {
             return CommonResponse.create(500, "参数错误");
             return CommonResponse.create(500, "参数错误");
         }
         }
-        List<Long> videoIds = new ArrayList<>();
+        Set<Long> videoIds = new HashSet<>();
         for (VideoParam videoParam : guaranteedParam.getVideoParamList()) {
         for (VideoParam videoParam : guaranteedParam.getVideoParamList()) {
             if (CollectionUtils.isEmpty(videoParam.getVideoIds()) || videoParam.getVideoIds().size() < MAX_VIDEO_NUM) {
             if (CollectionUtils.isEmpty(videoParam.getVideoIds()) || videoParam.getVideoIds().size() < MAX_VIDEO_NUM) {
                 LarkRobotUtil.sendMessage("保底视频数量异常,请查看" + guaranteedParam.getDate());
                 LarkRobotUtil.sendMessage("保底视频数量异常,请查看" + guaranteedParam.getDate());
@@ -110,10 +111,11 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
         String date = guaranteedParam.getDate();
         String date = guaranteedParam.getDate();
         String key = String.format(GUARANTEED_MINI_PROGRAM_KEY, date);
         String key = String.format(GUARANTEED_MINI_PROGRAM_KEY, date);
         redisTemplate.opsForValue().set(key, guaranteedParam);
         redisTemplate.opsForValue().set(key, guaranteedParam);
+        redisTemplate.opsForValue().set(String.format(GUARANTEED_MINI_PROGRAM_SET_KEY, date), videoIds);
         return CommonResponse.success();
         return CommonResponse.success();
     }
     }
 
 
-    public Map<Long, VideoDetail> getVideoDetail(List<Long> videoIdList) {
+    public Map<Long, VideoDetail> getVideoDetail(Set<Long> videoIdList) {
         try {
         try {
             Map<Long, VideoDetail> map = new HashMap<>();
             Map<Long, VideoDetail> map = new HashMap<>();
             JSONObject params = new JSONObject();
             JSONObject params = new JSONObject();