Browse Source

文件转换工具类完善

tags/正式3.9.0
雍文秀 1 year ago
parent
commit
a7a308ab48
1 changed files with 25 additions and 1 deletions
  1. 25
    1
      sstudy/src/main/java/com/xhkjedu/sstudy/utils/ConvertUtil.java

+ 25
- 1
sstudy/src/main/java/com/xhkjedu/sstudy/utils/ConvertUtil.java View File

@@ -5,6 +5,8 @@ import com.xhkjedu.sstudy.listener.MessageSender;
5 5
 import com.xhkjedu.sstudy.mapper.resource.ResourceFileMapper;
6 6
 import com.xhkjedu.sstudy.model.resource.TResource;
7 7
 import com.xhkjedu.sstudy.vo.resource.ResourceVo;
8
+import com.xhkjedu.utils.JedisUtil;
9
+import com.xhkjedu.utils.N_Utils;
8 10
 import org.springframework.beans.factory.annotation.Autowired;
9 11
 import org.springframework.stereotype.Component;
10 12
 
@@ -20,12 +22,13 @@ import java.util.Map;
20 22
  * @date 2021/10/27 9:32
21 23
  **/
22 24
 @Component
23
-public class ConvertUtil {
25
+public class ConvertUtil extends JedisUtil {
24 26
     @Resource
25 27
     private ResourceFileMapper resourceFileMapper;
26 28
     @Autowired
27 29
     private MessageSender messageSender;
28 30
     private static Integer[] CLASS = {1,2,5,7};//资源分类1word,2ppt,3pdf,4图片,5视频,6音频,7压缩包,10其他
31
+    private static Integer redisdatatime = 180;//有效期3分钟
29 32
 
30 33
     //资源转换(word或ppt转为pdf,视频非h264编码转码,压缩包解压)
31 34
     public void convertResource(TResource model) {
@@ -33,6 +36,7 @@ public class ConvertUtil {
33 36
         //flv的视频不转换
34 37
         if ("flv".equals(model.getSuffix())) return;
35 38
         if (Arrays.asList(CLASS).contains(resourceclass) && model.getConverted() == 0) {
39
+            if (redisHandle(model.getResourceurl(), model.getResourceid())) return;
36 40
             ResourceVo resource = new ResourceVo();
37 41
             resource.setResourceid(model.getResourceid());
38 42
             resource.setResourceclass(resourceclass);
@@ -42,12 +46,30 @@ public class ConvertUtil {
42 46
         }
43 47
     }
44 48
 
49
+    //redis操作
50
+    private boolean redisHandle(String resourceurl, String resourceid) {
51
+        String[] strings = resourceurl.split("/");
52
+        String str1 = strings[0];
53
+        String cloudcode;
54
+        if (str1.startsWith("node")) {
55
+            cloudcode = strings[1];
56
+        } else {
57
+            cloudcode = str1;
58
+        }
59
+        String key = cloudcode + "_" + resourceid;
60
+        String redis_value = get(key);
61
+        if (N_Utils.isNotEmpty(redis_value)) return true;
62
+        set(key, resourceurl, redisdatatime);
63
+        return false;
64
+    }
65
+
45 66
     //获取资源预览路径
46 67
     public String getResourceUrl(ResourceVo resource) {
47 68
         String pdfurl = resource.getPdfurl();
48 69
         Integer resourceclass = resource.getResourceclass();
49 70
         Integer converted = resource.getConverted();
50 71
         if ((resourceclass == 1 || resourceclass == 2) && converted == 0) {
72
+            if (redisHandle(resource.getResourceurl(), resource.getResourceid())) return null;
51 73
             //需要把word或ppt转为pdf
52 74
             pdfurl = messageSender.convertResource(resource);
53 75
         } else if (resourceclass == 5) {
@@ -64,6 +86,7 @@ public class ConvertUtil {
64 86
         String resourceurl = resource.getResourceurl();
65 87
         String suffix = resource.getSuffix();
66 88
         if (suffix.equals("mp4") && !resource.getMp4code().equals("h264")) {
89
+            if (redisHandle(resource.getResourceurl(), resource.getResourceid())) return null;
67 90
             resourceurl = messageSender.convertResource(resource);
68 91
         }
69 92
         return resourceurl;
@@ -75,6 +98,7 @@ public class ConvertUtil {
75 98
         String pdfurl = null;
76 99
         Integer converted = resource.getConverted();
77 100
         if (converted == 0) {
101
+            if (redisHandle(resource.getResourceurl(), resourceid)) return null;
78 102
             //获取压缩包文件
79 103
             pdfurl = messageSender.convertResource(resource);
80 104
         } else {

Loading…
Cancel
Save