Browse Source

四川日报压缩包推送

dengsixing 10 months ago
parent
commit
9aea56d4c9

+ 2 - 0
src/main/java/com/fdkankan/external/consumer/RabbitMqListener.java

@@ -43,8 +43,10 @@ public class RabbitMqListener {
         long deliveryTag = message.getMessageProperties().getDeliveryTag();
         String msg = new String(message.getBody(), StandardCharsets.UTF_8);
         JSONObject jsonObject = JSON.parseObject(msg);
+        log.info("四川日报打包开始, msg:{}", jsonObject);
         scrbService.packageScene(jsonObject);
         channel.basicAck(deliveryTag, false);
+        log.info("四川日报打包结束, msg:{}", jsonObject);
     }
 
 }

+ 4 - 0
src/main/java/com/fdkankan/external/httpclient/HttpClient.java

@@ -1,5 +1,6 @@
 package com.fdkankan.external.httpclient;
 
+import com.alibaba.fastjson.JSONObject;
 import com.dtflys.forest.annotation.*;
 import com.dtflys.forest.callback.OnError;
 import com.dtflys.forest.callback.OnSuccess;
@@ -52,4 +53,7 @@ public interface HttpClient {
     @Retry(maxRetryCount = "3", maxRetryInterval = "100")
     Result<LaserDownloadBean> downOfflineScene(@Var("url") String url, @JSONBody Object param, OnSuccess<ResultData> onSuccess, OnError onError);
 
+    @Post(url = "{url}", connectTimeout = 30000,  readTimeout = 30000, maxRetryInterval = 3)
+    JSONObject postJson(@Var("url") String url, @JSONBody Object object);
+
 }

+ 34 - 3
src/main/java/com/fdkankan/external/service/impl/ScrbServiceImpl.java

@@ -2,18 +2,23 @@ package com.fdkankan.external.service.impl;
 
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.ZipUtil;
+import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.external.entity.*;
+import com.fdkankan.external.httpclient.HttpClient;
 import com.fdkankan.external.service.*;
+import com.fdkankan.external.util.ScrbObsUtil;
+import com.fdkankan.fyun.config.FYunFileConfig;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.io.File;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @Service
 public class ScrbServiceImpl implements IScrbService {
@@ -22,6 +27,12 @@ public class ScrbServiceImpl implements IScrbService {
 
     @Resource
     private FYunFileServiceInterface fYunFileService;
+    @Resource
+    private FYunFileConfig fYunFileConfig;
+    @Resource
+    private ScrbObsUtil scrbObsUtil;
+    @Resource
+    private HttpClient httpClient;
 
     @Autowired
     private IScenePlusService scenePlusService;
@@ -33,13 +44,15 @@ public class ScrbServiceImpl implements IScrbService {
     private ISceneEditInfoExtService sceneEditInfoExtService;
     @Autowired
     private ISceneEditControlsService sceneEditControlsService;
+    @Autowired
+    private IDepartmentService departmentService;
 
     @Override
     public void packageScene(JSONObject jsonObject) {
 
         String num = jsonObject.getString("num");
         String path = basePath + num + "/";
-        String sourcePath = path + "source/";
+        String sourcePath = path + num + "/";
         String zipPath = path + num + ".zip";
         FileUtil.mkdir(sourcePath);
 
@@ -50,7 +63,9 @@ public class ScrbServiceImpl implements IScrbService {
         SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
         SceneEditControls sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
         FileUtil.writeUtf8String(JSON.toJSONString(scenePlus), sourcePath + "scenePlus.txt");
-        FileUtil.writeUtf8String(JSON.toJSONString(scenePlusExt), sourcePath + "scenePlusExt.txt");
+        String scenePlusExtStr = JSON.toJSONString(scenePlusExt);
+        scenePlusExtStr.replace(fYunFileConfig.getHost(), scrbObsUtil.getHost());
+        FileUtil.writeUtf8String(scenePlusExtStr, sourcePath + "scenePlusExt.txt");
         FileUtil.writeUtf8String(JSON.toJSONString(sceneEditInfo), sourcePath + "sceneEditInfo.txt");
         FileUtil.writeUtf8String(JSON.toJSONString(sceneEditInfoExt), sourcePath + "sceneEditInfoExt.txt");
         FileUtil.writeUtf8String(JSON.toJSONString(sceneEditControls), sourcePath + "sceneEditControls.txt");
@@ -76,6 +91,22 @@ public class ScrbServiceImpl implements IScrbService {
         }
 
         //上传obs
+        String key = "scene/zip/" + num + ".zip";
+        scrbObsUtil.uploadFile(zipPath, key, null);
+
+        FileUtil.del(sourcePath);
+        FileUtil.del(zipPath);
+
+        Department department = departmentService.getByCode("scrb");
+        String url = department.getDestUrl();
+        Map<String, Object> param = new HashMap<>();
+        param.put("num", num);
+        param.put("key", key);
+//        JSONObject result = httpClient.postJson(url, param);
+//        result.getInteger("code");
+//        if(){
+//
+//        }
 
 
     }

+ 43 - 5
src/main/java/com/fdkankan/external/util/ScrbObsUtil.java

@@ -1,7 +1,10 @@
 package com.fdkankan.external.util;
 
+import cn.hutool.core.collection.CollUtil;
 import com.obs.services.ObsClient;
+import com.obs.services.model.ObjectMetadata;
 import com.obs.services.model.ObsObject;
+import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -9,19 +12,25 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.io.*;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 @Slf4j
+@Data
 @Configuration
 @ConditionalOnProperty(name = "scrb.obs.use", havingValue = "true")
 public class ScrbObsUtil {
 
+    @Value("${scrb.obs.bucket:#{null}}")
+    private String bucket;
+
     @Value("${scrb.obs.endPoint:#{null}}")
     private String endPoint;
 
+    @Value("${scrb.obs.host:#{null}}")
+    private String host;
+
     @Value("${scrb.obs.ak:#{null}}")
     private String ak;
 
@@ -36,7 +45,7 @@ public class ScrbObsUtil {
         return new ObsClient(ak, sk, endPoint);
     }
 
-    public String getFileContent(String bucket, String objectname){
+    public String getFileContent(String objectname){
         try {
             ObsObject object = obsClient.getObject(bucket, objectname);
             InputStream inputStream = object.getObjectContent();
@@ -57,4 +66,33 @@ public class ScrbObsUtil {
         }
     }
 
+    public String uploadFile(String filePath, String remoteFilePath, Map<String, String> headers) {
+        try {
+            File file = new File(filePath);
+            if (!file.exists()) {
+                log.warn("要上传的文件不存在,filePath" + filePath);
+                return null;
+            }
+            ObjectMetadata metadata = new ObjectMetadata();
+            if (filePath.contains(".jpg")) {
+                metadata.setContentType("image/jpeg");
+            }
+            if (filePath.contains(".mp4")) {
+                metadata.setContentType("video/mp4");
+            }
+            if (filePath.contains(".mp3")) {
+                metadata.setContentType("audio/mp3");
+            }
+            if (CollUtil.isNotEmpty(headers)) {
+                Map<String, Object> collect = headers.keySet().stream().collect(Collectors.toMap(v -> v, v -> headers.get(v)));
+                metadata.setMetadata(collect);
+            }
+            obsClient.putObject(bucket, remoteFilePath, file, metadata);
+            log.info("文件上传成功,path:{}", filePath);
+        } catch (Exception e) {
+            log.error("oss上传文件失败,filePath:"+filePath, e);
+        }
+        return null;
+    }
+
 }

+ 9 - 1
src/main/resources/application-dev.yml

@@ -95,13 +95,21 @@ fyun:
   secret: meDy7VYAWbg8kZCKsoUZcIYQxigWOy
   bucket: 4dkankan
   coldBucket: 4dkk-bak  ##冷归档bucket
-  endPoint: http://oss-cn-shenzhen-internal.aliyuncs.com
+  endPoint: http://oss-cn-shenzhen.aliyuncs.com
   host: https://4dkk.4dage.com/
 
 file:
   offlineZip:
     dir: /mnt/external/temp/
 
+scrb:
+  obs:
+    use: true
+    bucket: djqk-vr
+    endPoint: obsv3.scrb-cd-1.sichuandaily.com.cn
+    ak: AFMVGM5CPSHHQ7UPG3DO
+    sk: IUYocj8qgixoDxhj3JIVKXtyBV3lGDJBDFgRhO21
+    host: http://djqk-vr.obsv3.scrb-cd-1.sichuandaily.com.cn/
 
 
 

+ 10 - 0
src/main/resources/application-prod.yml

@@ -103,6 +103,16 @@ file:
   offlineZip:
     dir: /mnt/external/temp/
 
+scrb:
+  obs:
+    use: true
+    bucket: djqk-vr
+    endPoint: obsv3.scrb-cd-1.sichuandaily.com.cn
+    ak: AFMVGM5CPSHHQ7UPG3DO
+    sk: IUYocj8qgixoDxhj3JIVKXtyBV3lGDJBDFgRhO21
+    host: http://djqk-vr.obsv3.scrb-cd-1.sichuandaily.com.cn/
+
+
 
 
 

+ 11 - 1
src/main/resources/application-test.yml

@@ -4,7 +4,7 @@ spring:
   application:
     name: 4dkankan-center-external
   redis:
-    host: 120.24.144.164
+    host: 172.18.156.39
     port: 6379
     timeout: 6000ms
     password: bgh0cae240
@@ -102,6 +102,16 @@ file:
   offlineZip:
     dir: /mnt/external/temp/
 
+scrb:
+  obs:
+    use: true
+    bucket: djqk-vr
+    endPoint: obsv3.scrb-cd-1.sichuandaily.com.cn
+    ak: AFMVGM5CPSHHQ7UPG3DO
+    sk: IUYocj8qgixoDxhj3JIVKXtyBV3lGDJBDFgRhO21
+    host: http://djqk-vr.obsv3.scrb-cd-1.sichuandaily.com.cn/
+
+