dengsixing 8 ماه پیش
والد
کامیت
47facd51f0

+ 7 - 3
src/main/java/com/fdkankan/scene/service/impl/ReverseSceneServiceImpl.java

@@ -20,6 +20,7 @@ import com.fdkankan.model.utils.CreateObjUtil;
 import com.fdkankan.scene.bean.SceneJsonBean;
 import com.fdkankan.scene.entity.*;
 import com.fdkankan.scene.service.*;
+import com.fdkankan.scene.util.FyunUtil;
 import com.fdkankan.scene.vo.SceneEditControlsVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -51,21 +52,24 @@ public class ReverseSceneServiceImpl implements IReverseSceneService {
     @Autowired
     private ISceneEditControlsService sceneEditControlsService;
     @Resource
-    private FYunFileServiceInterface fYunFileService;
+    private FyunUtil fyunUtil;
 
     @Override
     public void reverseScene(JSONObject jsonObject) throws Exception {
 
         String num = jsonObject.getString("num");
         String zipPath = jsonObject.getString("path");
+        String fyunType = jsonObject.getString("fyunType");
+        String bucket = jsonObject.getString("bucket");
         ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
         ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
 
         String dataSource = scenePlusExt.getDataSource();
 
         //解压
-        fYunFileService.downloadFile(zipPath, dataSource + "/" + FileUtil.getName(zipPath));
-        ZipUtil.unzip(zipPath, dataSource, CharsetUtil.CHARSET_GBK);
+        String destPath = dataSource + "/" + FileUtil.getName(zipPath);
+        fyunUtil.yunDownloadSs(fyunType, bucket, zipPath, destPath);
+        ZipUtil.unzip(destPath, dataSource, CharsetUtil.CHARSET_GBK);
 
         //生成vision.txt
         int shootCount = this.genVisionTxt(num, dataSource);

+ 38 - 0
src/main/java/com/fdkankan/scene/util/FyunUtil.java

@@ -0,0 +1,38 @@
+package com.fdkankan.scene.util;
+
+import com.fdkankan.fyun.constant.FYunConstants;
+import com.fdkankan.fyun.model.StreamGobbler;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+
+@Slf4j
+@Component
+public class FyunUtil {
+
+    @Resource
+    FYunConstants fYunConstants;
+
+    public void yunDownloadSs(String fyunType, String bucket, String srcPath, String destPath){
+        String opType = srcPath.contains(".")? "file":"folder" ;
+        String cmd = String.format(fYunConstants.DOWNLOAD_SH, bucket, srcPath, destPath, fyunType, opType);
+        callshell(cmd);
+    }
+
+    public void callshell(String command){
+        try {
+            Long start = System.currentTimeMillis();
+            Process process = Runtime.getRuntime().exec(command);
+            StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR");
+            errorGobbler.start();
+            StreamGobbler outGobbler = new StreamGobbler(process.getInputStream(), "STDOUT");
+            outGobbler.start();
+            process.waitFor();
+            log.info("脚本{}执行完毕,用时:{}ms",command,System.currentTimeMillis()-start);
+        } catch (Exception e) {
+            log.error("调用脚本文件上传下载失败, command : " + command, e);
+        }
+    }
+
+}