xueyiming пре 5 месеци
родитељ
комит
233bd50c0f

+ 2 - 0
we-com-server/src/main/java/com/tzld/piaoquan/wecom/common/constant/MessageConstant.java

@@ -8,6 +8,8 @@ public interface MessageConstant {
     //推送保底内容
     String guaranteedText = "- 晚上好!愿这宁静的夜晚带给你心灵的放松与安宁,以下是大家都在看的爆款视频!";
 
+    String morningText = "早安,新的一天,愿你拥有最好的心情去迎接一切美好!爆款视频抢先观看,点击下方精彩不断~";
+
     //小程序id
     String appid = "wx7187c217efef24a7";
 

+ 41 - 24
we-com-server/src/main/java/com/tzld/piaoquan/wecom/job/WeComMessageDataJob.java

@@ -206,11 +206,14 @@ public class WeComMessageDataJob {
         if (CollectionUtils.isEmpty(corps)) {
             return ReturnT.SUCCESS;
         }
+        List<Long> staffIds = new ArrayList<>();
+        if (xxlJobParam.getStaffId() != null) {
+            staffIds.add(xxlJobParam.getStaffId());
+        }
+        if (!CollectionUtils.isEmpty(xxlJobParam.getStaffIds())) {
+            staffIds.addAll(xxlJobParam.getStaffIds());
+        }
         for (Corp corp : corps) {
-            Long staffId = null;
-            if (xxlJobParam.getStaffId() != null) {
-                staffId = xxlJobParam.getStaffId();
-            }
             UserExample userExample = new UserExample();
             userExample.createCriteria().andExternalUserIdIsNotNull().andCorpIdEqualTo(corp.getId());
             if (xxlJobParam.getUserId() != null) {
@@ -229,7 +232,7 @@ public class WeComMessageDataJob {
                 //落库逻辑
                 List<SendMessage> allSeneMessageList = new ArrayList<>();
                 for (User user : userList) {
-                    List<SendMessage> sendMessageList = getSendMessage(user, staffId, corp.getId());
+                    List<SendMessage> sendMessageList = getSendMessage(user, staffIds, corp.getId());
                     if (CollectionUtils.isEmpty(sendMessageList)) {
                         continue;
                     }
@@ -241,40 +244,54 @@ public class WeComMessageDataJob {
                 sendMessageMapper.insertList(allSeneMessageList);
             }
         }
-        //组装好当天要发送的消息后  记录时间  删除保底数据
-        saveGuaranteedVideoIdList();
+        //组装好当天要发送的消息后  记录时间
+        saveGuaranteedVideoIdList(staffIds);
         return ReturnT.SUCCESS;
     }
 
-    private void saveGuaranteedVideoIdList() {
+    private void saveGuaranteedVideoIdList(List<Long> staffIds) {
         String key = String.format(GUARANTEED_MINI_PROGRAM_KEY, DateUtil.getThatDayDateString());
         GuaranteedParam guaranteedParam = (GuaranteedParam) redisTemplate.opsForValue().get(key);
         if (guaranteedParam == null || CollectionUtils.isEmpty(guaranteedParam.getVideoParamList())) {
             return;
         }
-        Set<Long> videoIdSet = new HashSet<>();
-        for (VideoParam videoParam : guaranteedParam.getVideoParamList()) {
-            if (CollectionUtils.isEmpty(videoParam.getVideoIds())) {
-                continue;
+        if (CollectionUtils.isEmpty(staffIds)) {
+            Set<Long> videoIdSet = new HashSet<>();
+            for (VideoParam videoParam : guaranteedParam.getVideoParamList()) {
+                if (CollectionUtils.isEmpty(videoParam.getVideoIds())) {
+                    continue;
+                }
+                videoIdSet.addAll(videoParam.getVideoIds());
             }
-            videoIdSet.addAll(videoParam.getVideoIds());
-        }
-        List<Long> videoIdList = new ArrayList<>(videoIdSet);
-        MessageAttachmentExample example = new MessageAttachmentExample();
-        example.createCriteria().andMiniprogramVideoIdIn(videoIdList);
-        MessageAttachment updateMessageAttachment = new MessageAttachment();
-        updateMessageAttachment.setSendTime(new Date());
-        messageAttachmentMapper.updateByExampleSelective(updateMessageAttachment, example);
-        redisTemplate.delete(key);
+            List<Long> videoIdList = new ArrayList<>(videoIdSet);
+            MessageAttachmentExample example = new MessageAttachmentExample();
+            example.createCriteria().andMiniprogramVideoIdIn(videoIdList).andSendTimeIsNull();
+            MessageAttachment updateMessageAttachment = new MessageAttachment();
+            updateMessageAttachment.setSendTime(new Date());
+            messageAttachmentMapper.updateByExampleSelective(updateMessageAttachment, example);
+        } else {
+            for (VideoParam videoParam : guaranteedParam.getVideoParamList()) {
+                if (!CollectionUtils.isEmpty(staffIds) && staffIds.contains(videoParam.getStaffId())) {
+                    if (CollectionUtils.isEmpty(videoParam.getVideoIds())) {
+                        continue;
+                    }
+                    MessageAttachmentExample example = new MessageAttachmentExample();
+                    example.createCriteria().andMiniprogramVideoIdIn(videoParam.getVideoIds()).andStaffIdEqualTo(videoParam.getStaffId());
+                    MessageAttachment updateMessageAttachment = new MessageAttachment();
+                    updateMessageAttachment.setSendTime(new Date());
+                    messageAttachmentMapper.updateByExampleSelective(updateMessageAttachment, example);
+                }
+            }
+        }
     }
 
-    private List<SendMessage> getSendMessage(User user, Long staffId, Long corpId) {
+    private List<SendMessage> getSendMessage(User user, List<Long> staffIds, Long corpId) {
         StaffWithUserExample example = new StaffWithUserExample();
         StaffWithUserExample.Criteria criteria = example.createCriteria();
         criteria.andUserIdEqualTo(user.getId());
         criteria.andIsDeleteEqualTo(0);
-        if (staffId != null) {
-            criteria.andStaffIdEqualTo(staffId);
+        if (!CollectionUtils.isEmpty(staffIds)) {
+            criteria.andStaffIdIn(staffIds);
         }
         List<StaffWithUser> staffWithUserList = staffWithUserMapper.selectByExample(example);
         if (CollectionUtils.isEmpty(staffWithUserList)) {

+ 4 - 0
we-com-server/src/main/java/com/tzld/piaoquan/wecom/model/bo/XxlJobParam.java

@@ -2,6 +2,8 @@ package com.tzld.piaoquan.wecom.model.bo;
 
 import lombok.Data;
 
+import java.util.List;
+
 @Data
 public class XxlJobParam {
 
@@ -13,5 +15,7 @@ public class XxlJobParam {
 
     private Long staffId;
 
+    private List<Long> staffIds;
+
     private Long userId;
 }

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

@@ -133,7 +133,7 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
         addMiniProgram(messageAttachmentList, null);
         String date = guaranteedParam.getDate();
         String key = String.format(GUARANTEED_MINI_PROGRAM_KEY, date);
-        redisTemplate.opsForValue().set(key, guaranteedParam);
+        redisTemplate.opsForValue().set(key, guaranteedParam, 14, TimeUnit.DAYS);
         return CommonResponse.success();
     }
 

+ 5 - 3
we-com-server/src/main/java/com/tzld/piaoquan/wecom/service/Impl/MessageServiceImpl.java

@@ -7,6 +7,7 @@ import com.tzld.piaoquan.wecom.component.HttpPoolClient;
 import com.tzld.piaoquan.wecom.model.vo.MessageTextParam;
 import com.tzld.piaoquan.wecom.service.AccessTokenService;
 import com.tzld.piaoquan.wecom.service.MessageService;
+import com.tzld.piaoquan.wecom.utils.DateUtil;
 import com.tzld.piaoquan.wecom.utils.HttpClientUtil;
 import com.tzld.piaoquan.wecom.utils.LarkRobotUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -72,10 +73,11 @@ public class MessageServiceImpl implements MessageService {
 
     @Override
     public String getMessageText() {
-        String text = (String) redisTemplate.opsForValue().get(PUSH_MESSAGE_TEXT);
-        if (StringUtils.isEmpty(text)) {
+        Integer timeOfDay = DateUtil.getTimeOfDay();
+        if(timeOfDay == 1){
+            return MessageConstant.morningText;
+        }else {
             return MessageConstant.guaranteedText;
         }
-        return text;
     }
 }

+ 14 - 4
we-com-server/src/main/java/com/tzld/piaoquan/wecom/utils/DateUtil.java

@@ -1,10 +1,7 @@
 package com.tzld.piaoquan.wecom.utils;
 
 
-import java.time.Instant;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
+import java.time.*;
 import java.time.format.DateTimeFormatter;
 import java.util.Calendar;
 import java.util.Date;
@@ -54,5 +51,18 @@ public class DateUtil {
         return Math.abs(date1.getTime() - date2.getTime());
     }
 
+    public static Integer getTimeOfDay() {
+        LocalTime now = LocalTime.now(); // 获取当前时间
+
+        if (now.isBefore(LocalTime.NOON)) {
+            return 1; // 中午12点之前
+        } else if (now.isBefore(LocalTime.of(18, 0))) {
+            return 2; // 下午6点之前
+        } else if (now.isBefore(LocalTime.of(24, 0))) {
+            return 3; // 晚上12点之前
+        } else {
+            return 0; // 不应该出现的情况
+        }
+    }
 
 }