فهرست منبع

增加临时文件删除

xueyiming 6 ماه پیش
والد
کامیت
938b854ce9

+ 11 - 13
we-com-server/src/main/java/com/tzld/piaoquan/wecom/job/WeComMessageDataJob1.java

@@ -71,7 +71,7 @@ public class WeComMessageDataJob1 {
     List<PushMessage> goodHistoryPushList = new ArrayList<>();
 
     //保底视频列表
-    Map<String, List<Long>> guaranteedVideoMap = new HashMap<>();
+    Map<Long, List<Long>> guaranteedVideoMap = new HashMap<>();
     Map<String, String> pageMap = new HashMap<>();
 
     //初始化操作
@@ -97,21 +97,20 @@ public class WeComMessageDataJob1 {
         //保底视频获取
 
         String key = String.format(GUARANTEED_MINI_PROGRAM_KEY, DateUtil.getThatDayDateString());
-        String value = (String) redisTemplate.opsForValue().get(key);
-        GuaranteedParam guaranteedParam = JSONObject.parseObject(value, GuaranteedParam.class);
+        GuaranteedParam guaranteedParam = (GuaranteedParam) redisTemplate.opsForValue().get(key);
         if (guaranteedParam == null
                 || CollectionUtils.isEmpty(guaranteedParam.getVideoParamList())) {
             LarkRobotUtil.sendMessage("保底视频获取异常,请检查" + DateUtil.getThatDayDateString());
             throw new RuntimeException();
         }
-        Map<String, List<Long>> videoMap = new HashMap<>();
+        Map<Long, List<Long>> videoMap = new HashMap<>();
         for (VideoParam videoParam : guaranteedParam.getVideoParamList()) {
-            if (StringUtils.isEmpty(videoParam.getCarrierId())) {
-                LarkRobotUtil.sendMessage("保底视频获取异常,CarrierId为空" + DateUtil.getThatDayDateString());
+            if (videoParam.getStaffId() == null) {
+                LarkRobotUtil.sendMessage("保底视频获取异常,StaffId为空" + DateUtil.getThatDayDateString());
                 throw new RuntimeException();
             }
             if (CollectionUtils.isEmpty(videoParam.getVideoIds()) || videoParam.getVideoIds().size() < MAX_VIDEO_NUM) {
-                LarkRobotUtil.sendMessage("保底视频数量异常,请查看" + guaranteedParam.getDate() + videoParam.getCarrierId());
+                LarkRobotUtil.sendMessage("保底视频数量异常,请查看" + guaranteedParam.getDate() + videoParam.getStaffId());
                 throw new RuntimeException();
             }
             for (Long videoId : videoParam.getVideoIds()) {
@@ -129,9 +128,9 @@ public class WeComMessageDataJob1 {
                     throw new RuntimeException();
                 }
             }
-            videoMap.put(videoParam.getCarrierId(), videoParam.getVideoIds());
+            videoMap.put(videoParam.getStaffId(), videoParam.getVideoIds());
         }
-        if (!videoMap.containsKey("default")) {
+        if (!videoMap.containsKey(0L)) {
             LarkRobotUtil.sendMessage("保底视频没有默认组,请查看" + guaranteedParam.getDate());
             throw new RuntimeException();
         }
@@ -183,8 +182,7 @@ public class WeComMessageDataJob1 {
 
     public void saveGuaranteedVideoIdList() {
         String key = String.format(GUARANTEED_MINI_PROGRAM_KEY, DateUtil.getThatDayDateString());
-        String value = (String) redisTemplate.opsForValue().get(key);
-        GuaranteedParam guaranteedParam = JSONObject.parseObject(value, GuaranteedParam.class);
+        GuaranteedParam guaranteedParam = (GuaranteedParam) redisTemplate.opsForValue().get(key);
         if (guaranteedParam == null || CollectionUtils.isEmpty(guaranteedParam.getVideoParamList())) {
             return;
         }
@@ -243,9 +241,9 @@ public class WeComMessageDataJob1 {
                 }
             }
             //保底数据
-            List<Long> guaranteedVideoIdList = guaranteedVideoMap.get(String.valueOf(staffWithUser.getStaffId()));
+            List<Long> guaranteedVideoIdList = guaranteedVideoMap.get(staffWithUser.getStaffId());
             if (CollectionUtils.isEmpty(guaranteedVideoIdList)) {
-                guaranteedVideoIdList = guaranteedVideoMap.get("default");
+                guaranteedVideoIdList = guaranteedVideoMap.get(0L);
             }
             if (CollectionUtils.isEmpty(guaranteedVideoIdList)) {
                 LarkRobotUtil.sendMessage("组装数据时,保底数据获取异常");

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

@@ -7,7 +7,7 @@ import java.util.List;
 @Data
 public class VideoParam {
 
-    private String carrierId;
+    private Long staffId;
 
     private List<Long> videoIds;
 

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

@@ -33,6 +33,7 @@ import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
@@ -144,17 +145,17 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
 
     @Override
     public String getPicMediaId(String cover) {
+        String mediaId = (String) redisTemplate.opsForValue().get(cover);
+        if (StringUtils.isNotEmpty(mediaId)) {
+            return mediaId;
+        }
+        String filePath = UUID.randomUUID() + ".jpg"; // 临时文件路径
         try {
-            String mediaId = (String) redisTemplate.opsForValue().get(cover);
-            if (StringUtils.isNotEmpty(mediaId)) {
-                return mediaId;
-            }
             HttpURLConnection httpUrl = (HttpURLConnection) new URL(cover).openConnection();
             httpUrl.connect();
             InputStream inputStream = httpUrl.getInputStream();
 
             // 将文件内容写入临时文件
-            String filePath = UUID.randomUUID() + ".jpg"; // 临时文件路径
             try (OutputStream outputStream = Files.newOutputStream(Paths.get(filePath))) {
                 byte[] buffer = new byte[4096];
                 int bytesRead;
@@ -172,13 +173,12 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
             if (jsonObject != null && jsonObject.getInteger("errcode") == 0) {
                 mediaId = jsonObject.getString("media_id");
                 redisTemplate.opsForValue().set(cover, mediaId, 2, TimeUnit.DAYS);
-                return mediaId;
             }
+            Files.delete(Paths.get(filePath));
         } catch (Exception e) {
             log.error("getPicMediaId error", e);
         }
-
-        return null;
+        return mediaId;
     }