dengsixing 8 hónapja
szülő
commit
2a4d68cd29

+ 10 - 2
src/main/java/com/fdkankan/contro/mq/service/impl/BuildReverseE57SceneServiceImpl.java

@@ -2,6 +2,7 @@ package com.fdkankan.contro.mq.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.CharsetUtil;
 import cn.hutool.core.util.ZipUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
@@ -14,6 +15,7 @@ import com.fdkankan.contro.entity.*;
 import com.fdkankan.contro.mq.service.IBuildSceneService;
 import com.fdkankan.contro.service.*;
 import com.fdkankan.contro.service.impl.CommonServiceImpl;
+import com.fdkankan.contro.util.FyunUtil;
 import com.fdkankan.fyun.config.FYunFileConfig;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.model.constants.ConstantFileName;
@@ -74,6 +76,8 @@ public class BuildReverseE57SceneServiceImpl implements IBuildSceneService {
     private IFdkkLaserService fdkkLaserService;
     @Autowired
     private ISceneEditControlsService sceneEditControlsService;
+    @Resource
+    private FyunUtil fyunUtil;
 
     @Override
     public void buildScenePre(BuildSceneCallMessage message) throws Exception{
@@ -84,10 +88,14 @@ public class BuildReverseE57SceneServiceImpl implements IBuildSceneService {
             String dataSource = scenePlusExt.getDataSource();
             message.setPath(dataSource);
 
-            String e57Path = (String)message.getExt().get("path");
+            String zipPath = (String)message.getExt().get("path");
+            String fyunType = (String)message.getExt().get("fyunType");
+            String bucket = (String)message.getExt().get("bucket");
 
             //下载资源到本地
-            fYunFileService.downloadFile(e57Path, dataSource + "/capture");
+            String destPath = dataSource + "/capture/" + FileUtil.getName(zipPath);
+            fyunUtil.yunDownloadSs(fyunType, bucket, zipPath, destPath);
+            ZipUtil.unzip(destPath, dataSource + "/capture/", CharsetUtil.CHARSET_GBK);
 
             //发送mq,就进行计算
 //            message.setPath(path);

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

@@ -0,0 +1,38 @@
+package com.fdkankan.contro.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);
+        }
+    }
+
+}