Browse Source

Merge branch 'dev-xym-guarantees' of Server/we-com-manage into master

xueyiming 4 months ago
parent
commit
9769617168

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

@@ -154,7 +154,7 @@ public class WeComMessageDataJob {
                 MessageAttachment messageAttachment = messageAttachmentList.get(0);
                 if (messageAttachment.getSendTime() != null
                         && DateUtil.dateDifference(new Date(), messageAttachment.getSendTime()) < 90 * MILLISECOND_DAY) {
-                    LarkRobotUtil.sendMessage("保底视频半年内已发送,请查看videoId=" + videoId);
+                    LarkRobotUtil.sendMessage("保底视频90天内已发送,请查看videoId=" + videoId);
                 }
             }
             //重新组合视频id

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

@@ -9,6 +9,8 @@ public class VideoParam {
 
     private Long staffId;
 
+    private List<Long> staffIds;
+
     private List<Long> videoIds;
 
 }

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

@@ -84,44 +84,79 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
         }
     }
 
-    @Override
+
     public CommonResponse<Void> createGuaranteedMiniProgram(GuaranteedParam guaranteedParam) {
-        if (guaranteedParam == null
-                || StringUtils.isEmpty(guaranteedParam.getDate())
-                || CollectionUtils.isEmpty(guaranteedParam.getVideoParamList())) {
+        if (isInvalidGuaranteedParam(guaranteedParam)) {
             return CommonResponse.create(500, "参数错误");
         }
+
         Set<Long> videoIds = new HashSet<>();
         for (VideoParam videoParam : guaranteedParam.getVideoParamList()) {
-            if (CollectionUtils.isEmpty(videoParam.getVideoIds()) || videoParam.getVideoIds().size() < MAX_VIDEO_NUM) {
-                LarkRobotUtil.sendMessage("保底视频数量异常,请查看" + guaranteedParam.getDate());
-            }
-            for (Long videoId : videoParam.getVideoIds()) {
-                MessageAttachmentExample example = new MessageAttachmentExample();
-                example.createCriteria().andMiniprogramVideoIdEqualTo(videoId).andStaffIdEqualTo(videoParam.getStaffId());
-                List<MessageAttachment> messageAttachmentList = messageAttachmentMapper.selectByExample(example);
-                if (CollectionUtils.isEmpty(messageAttachmentList)) {
-                    continue;
-                }
-                MessageAttachment messageAttachment = messageAttachmentList.get(0);
-                if (messageAttachment.getSendTime() != null
-                        && DateUtil.dateDifference(new Date(), messageAttachment.getSendTime()) < 90 * MILLISECOND_DAY) {
-                    LarkRobotUtil.sendMessage("保底视频半年内已发送,请查看videoId=" + videoId);
-                    return CommonResponse.create(500, "保底视频半年内已发送,请查看videoId=" + videoId);
-                }
+            processVideoParam(videoParam, guaranteedParam.getDate(), videoIds);
+        }
+
+        Map<Long, VideoDetail> coverMap = getVideoDetail(videoIds);
+        Map<Long, MessageAttachment> messageAttachmentMap = createMessageAttachmentMap(videoIds, coverMap);
+
+        List<MessageAttachment> messageAttachmentList = new ArrayList<>();
+        for (VideoParam videoParam : guaranteedParam.getVideoParamList()) {
+            addMessageAttachments(videoParam, messageAttachmentMap, guaranteedParam.getDate(), messageAttachmentList);
+        }
+
+        addMiniProgram(messageAttachmentList, null);
+        return CommonResponse.success();
+    }
+
+    private boolean isInvalidGuaranteedParam(GuaranteedParam guaranteedParam) {
+        return guaranteedParam == null ||
+                StringUtils.isEmpty(guaranteedParam.getDate()) ||
+                CollectionUtils.isEmpty(guaranteedParam.getVideoParamList());
+    }
+
+
+    private void processVideoParam(VideoParam videoParam, String date, Set<Long> videoIds) {
+        if (CollectionUtils.isEmpty(videoParam.getVideoIds()) || videoParam.getVideoIds().size() < MAX_VIDEO_NUM) {
+            LarkRobotUtil.sendMessage("保底视频数量异常,请查看" + date);
+        }
+        List<Long> staffIds = Optional.ofNullable(videoParam.getStaffIds()).orElseGet(() -> {
+            List<Long> newStaffIds = new ArrayList<>();
+            if (videoParam.getStaffId() != null) {
+                newStaffIds.add(videoParam.getStaffId());
             }
+            return newStaffIds;
+        });
+        for (Long staffId : staffIds) {
+            checkVideoSendTime(videoParam, staffId);
             videoIds.addAll(videoParam.getVideoIds());
         }
-        Map<Long, VideoDetail> coverMap = getVideoDetail(videoIds);
-        Map<Long, MessageAttachment> messageAttachmentMap = new HashMap<>();
+    }
 
+    private void checkVideoSendTime(VideoParam videoParam, Long staffId) {
+        for (Long videoId : videoParam.getVideoIds()) {
+            MessageAttachmentExample example = new MessageAttachmentExample();
+            example.createCriteria().andMiniprogramVideoIdEqualTo(videoId).andStaffIdEqualTo(staffId);
+            List<MessageAttachment> messageAttachmentList = messageAttachmentMapper.selectByExample(example);
+            if (CollectionUtils.isEmpty(messageAttachmentList)) {
+                continue;
+            }
+            MessageAttachment messageAttachment = messageAttachmentList.get(0);
+            if (messageAttachment.getSendTime() != null &&
+                    DateUtil.dateDifference(new Date(), messageAttachment.getSendTime()) < 90 * MILLISECOND_DAY) {
+                LarkRobotUtil.sendMessage("保底视频90天内已发送,请查看videoId=" + videoId);
+                throw new RuntimeException("保底视频90天内已发送,请查看videoId=" + videoId);
+            }
+        }
+    }
+
+    private Map<Long, MessageAttachment> createMessageAttachmentMap(Set<Long> videoIds, Map<Long, VideoDetail> coverMap) {
+        Map<Long, MessageAttachment> messageAttachmentMap = new HashMap<>();
         for (Long videoId : videoIds) {
-            MessageAttachment messageAttachment = new MessageAttachment();
             VideoDetail videoDetail = coverMap.get(videoId);
             if (videoDetail == null || StringUtils.isEmpty(videoDetail.getCover()) || StringUtils.isEmpty(videoDetail.getTitle())) {
                 LarkRobotUtil.sendMessage("获取视频详情异常,请查看" + videoId);
                 throw new RuntimeException("获取视频详情异常");
             }
+            MessageAttachment messageAttachment = new MessageAttachment();
             messageAttachment.setMiniprogramVideoId(videoId);
             messageAttachment.setType(MessageAttachmentTypeEnum.MINI_PROGRAM.getType());
             messageAttachment.setCover(videoDetail.getCover());
@@ -129,37 +164,58 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
             messageAttachment.setAppid(appid);
             messageAttachmentMap.put(videoId, messageAttachment);
         }
-        List<MessageAttachment> messageAttachmentList = new ArrayList<>();
-        for (VideoParam videoParam : guaranteedParam.getVideoParamList()) {
-            if (videoParam.getStaffId() == 0) {
+        return messageAttachmentMap;
+    }
+
+    private void addMessageAttachments(VideoParam videoParam, Map<Long, MessageAttachment> messageAttachmentMap, String date, List<MessageAttachment> messageAttachmentList) {
+        List<Long> staffIds = Optional.ofNullable(videoParam.getStaffIds()).orElseGet(() -> {
+            List<Long> newStaffIds = new ArrayList<>();
+            if (videoParam.getStaffId() != null) {
+                newStaffIds.add(videoParam.getStaffId());
+            }
+            return newStaffIds;
+        });
+
+        for (Long staffId : staffIds) {
+            if (staffId == 0) {
+                addGuaranteesVideo(date, staffId, videoParam.getVideoIds());
                 continue;
             }
+
             for (Long videoId : videoParam.getVideoIds()) {
                 MessageAttachment messageAttachment = messageAttachmentMap.get(videoId);
                 if (messageAttachment == null) {
                     continue;
                 }
+
                 MessageAttachment newMessageAttachment = new MessageAttachment();
                 BeanUtils.copyProperties(messageAttachment, newMessageAttachment);
-                newMessageAttachment.setStaffId(videoParam.getStaffId());
+                newMessageAttachment.setStaffId(staffId);
                 messageAttachmentList.add(newMessageAttachment);
             }
+            addGuaranteesVideo(date, staffId, videoParam.getVideoIds());
         }
-        addMiniProgram(messageAttachmentList, null);
-        for (VideoParam videoParam : guaranteedParam.getVideoParamList()) {
-            GuaranteesVideo guaranteesVideo = new GuaranteesVideo();
-            guaranteesVideo.setDate(guaranteedParam.getDate());
-            guaranteesVideo.setStaffId(videoParam.getStaffId());
-            guaranteesVideo.setVideoIds(JSONObject.toJSONString(videoParam.getVideoIds()));
-            guaranteesVideoMapper.insertSelective(guaranteesVideo);
+    }
+
+    private void addGuaranteesVideo(String date, Long staffId, List<Long> videoIds) {
+        GuaranteesVideoExample example = new GuaranteesVideoExample();
+        example.createCriteria().andIsDeleteEqualTo(0).andDateEqualTo(date).andStaffIdEqualTo(staffId);
+        List<GuaranteesVideo> guaranteesVideos = guaranteesVideoMapper.selectByExample(example);
+        for (GuaranteesVideo guaranteesVideo : guaranteesVideos) {
+            guaranteesVideo.setIsDelete(1);
+            guaranteesVideoMapper.updateByPrimaryKeySelective(guaranteesVideo);
         }
-        return CommonResponse.success();
+        GuaranteesVideo guaranteesVideo = new GuaranteesVideo();
+        guaranteesVideo.setDate(date);
+        guaranteesVideo.setStaffId(staffId);
+        guaranteesVideo.setVideoIds(JSONObject.toJSONString(videoIds));
+        guaranteesVideoMapper.insertSelective(guaranteesVideo);
     }
 
     @Override
     public GuaranteedParam getGuaranteedVideo(String date) {
         GuaranteesVideoExample example = new GuaranteesVideoExample();
-        example.createCriteria().andDateEqualTo(date);
+        example.createCriteria().andDateEqualTo(date).andIsDeleteEqualTo(0);
         List<GuaranteesVideo> guaranteesVideos = guaranteesVideoMapper.selectByExample(example);
         if (CollectionUtils.isEmpty(guaranteesVideos)) {
             LarkRobotUtil.sendMessage("获保底视频空,@薛一鸣");