浏览代码

修改文件上传逻辑

tianboguang 2 年之前
父节点
当前提交
5b80a9ba5f

+ 0 - 13
src/main/java/com/fdkankan/ucenter/common/constants/ShellCmd.java

@@ -1,13 +0,0 @@
-package com.fdkankan.ucenter.common.constants;
-
-public class ShellCmd {
-
-	/**
-	 * oss文件上传命令 bash /opt/ossutil/fyun-upload.sh {bucket} {srcPath} {destPath} {fyunType} {opType}
-	 * opType: file or folder
-	 * fyunType : oss ,aws
-	 */
-	public static final String FYUN_UPLOAD = "sudo bash /opt/ossutil/fyun-upload.sh %s %s /%s %s %s";
-	public static final String FYUN_DOWN = "sudo bash /opt/ossutil/fyun-download.sh %s /%s %s %s %s";
-
-}

+ 13 - 12
src/main/java/com/fdkankan/ucenter/common/utils/ShellUtil.java

@@ -1,10 +1,9 @@
 package com.fdkankan.ucenter.common.utils;
 
-import cn.hutool.core.io.file.FileReader;
-import com.alibaba.fastjson.JSONObject;
-import com.fdkankan.ucenter.common.constants.NacosProperty;
-import com.fdkankan.ucenter.common.constants.ShellCmd;
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
 
 import java.io.BufferedReader;
 import java.io.Closeable;
@@ -12,8 +11,14 @@ import java.io.IOException;
 import java.io.InputStreamReader;
 
 @Slf4j
+@Component
 public class ShellUtil {
 
+    @Autowired
+    private FYunFileServiceInterface fYunFileService;
+
+
+
     /**
      * 执行系统命令, 返回执行结果
      * @param cmd 需要执行的命令
@@ -117,15 +122,11 @@ public class ShellUtil {
      * @param destPath   目标文件路径
      *  //@param fyunType   oss or aws
      */
-    public static void yunUpload(String srcPath,String destPath){
-        String opType = srcPath.contains(".")? "file":"folder" ;
-        String cmd = String.format(ShellCmd.FYUN_UPLOAD, NacosProperty.bucket,srcPath,destPath,NacosProperty.uploadType,opType);
-        execCmd(cmd);
+    public void yunUpload(String srcPath,String destPath){
+        fYunFileService.uploadFileByCommand(srcPath,destPath);
     }
-    public static void yunDownload(String srcPath,String destPath){
-        String opType = srcPath.contains(".")? "file":"folder" ;
-        String cmd = String.format(ShellCmd.FYUN_DOWN,NacosProperty.bucket,srcPath,destPath,NacosProperty.uploadType,opType);
-        execCmd(cmd);
+    public void yunDownload(String srcPath,String destPath){
+        fYunFileService.downloadFileByCommand(destPath,srcPath);
     }
 
 }

+ 20 - 12
src/main/java/com/fdkankan/ucenter/service/impl/SceneProServiceImpl.java

@@ -115,6 +115,9 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
     private IInnerService innerService;
     @Autowired
     LaserService laserService;
+    
+    @Autowired
+    private ShellUtil shellUtil;
 
     @Value("${scene.pro.url}")
     private String sceneProUrl;
@@ -840,10 +843,10 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
      * @throws Exception
      */
     private void downloadFromOldNumFromOss(String sceneNum, String newNum) {
-        ShellUtil.yunDownload("images/images" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "images/images" + newNum);
-        ShellUtil.yunDownload("data/data" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "data/data" + newNum);
-        ShellUtil.yunDownload("voice/voice" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "voice/voice" + newNum);
-        ShellUtil.yunDownload("video/video" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "video/video" + newNum);
+        shellUtil.yunDownload("images/images" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "images/images" + newNum);
+        shellUtil.yunDownload("data/data" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "data/data" + newNum);
+        shellUtil.yunDownload("voice/voice" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "voice/voice" + newNum);
+        shellUtil.yunDownload("video/video" + sceneNum + "/", ConstantFilePath.SCENE_PATH + "video/video" + newNum);
     }
 
     /**
@@ -861,7 +864,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
 
     public void copyFdage(String oldDataSource,String newDataSource,String buildModelPath,String time) throws Exception {
 
-        ShellUtil.yunDownload(ConstantFilePath.OSS_PREFIX + oldDataSource.replace(buildModelPath, "")+"/", newDataSource);
+        shellUtil.yunDownload(ConstantFilePath.OSS_PREFIX + oldDataSource.replace(buildModelPath, "")+"/", newDataSource);
         // 修改data.fdage
         String data = FileUtils.readFile(newDataSource + "/data.fdage");
         JSONObject jsonObject = JSONObject.parseObject(data);
@@ -871,22 +874,27 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         }
         jsonObject.put("uuidtime",time);
         FileUtils.writeFile(newDataSource + "/data.fdage", jsonObject.toJSONString());
-        ShellUtil.yunUpload(newDataSource,  ConstantFilePath.OSS_PREFIX + newDataSource.replace(buildModelPath, ""));
+        shellUtil.yunUpload(newDataSource,  ConstantFilePath.OSS_PREFIX + newDataSource.replace(buildModelPath, ""));
 
         // 复制计算结果
-        ShellUtil.yunDownload(ConstantFilePath.OSS_PREFIX + oldDataSource.concat("_results/").replace(buildModelPath, ""), newDataSource.concat("_results"));
+        log.info("开始复制计算结果");
+        shellUtil.yunDownload(ConstantFilePath.OSS_PREFIX + oldDataSource.concat("_results/").replace(buildModelPath, ""), newDataSource.concat("_results"));
         if(new File(newDataSource.concat("_results")).exists()){
-            ShellUtil.yunUpload(newDataSource.concat("_results"), ConstantFilePath.OSS_PREFIX + newDataSource.concat("_results").replace(buildModelPath, ""));
+            shellUtil.yunUpload(newDataSource.concat("_results"), ConstantFilePath.OSS_PREFIX + newDataSource.concat("_results").replace(buildModelPath, ""));
             FileUtils.delAllFile(newDataSource.concat("_results"));
         }
+        log.info("开始删除本地资源");
         FileUtils.delAllFile(newDataSource);
 
         try {
+            log.info("开始复制本地资源");
             FileUtils.copyFolderAllFiles(oldDataSource+"/",newDataSource+"/", true);
         }catch (Exception e){
             log.error("dataSource复制失败,{}不存在",oldDataSource);
         }
 
+        log.info("copy Fdage finished");
+
     }
     @Override
     public String setDataSource(String preDataSource,String time) throws Exception {
@@ -927,10 +935,10 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
      * @param newNum
      */
     private void uploadNewSceneToOss(String newNum) {
-        ShellUtil.yunUpload("/mnt/4Dkankan/scene/images/images" + newNum, "images/images" + newNum);
-        ShellUtil.yunUpload("/mnt/4Dkankan/scene/data/data" + newNum, "data/data" + newNum);
-        ShellUtil.yunUpload("/mnt/4Dkankan/scene/voice/voice" + newNum, "voice/voice" + newNum);
-        ShellUtil.yunUpload("/mnt/4Dkankan/scene/video/video" + newNum, "video/video" + newNum);
+        shellUtil.yunUpload("/mnt/4Dkankan/scene/images/images" + newNum, "images/images" + newNum);
+        shellUtil.yunUpload("/mnt/4Dkankan/scene/data/data" + newNum, "data/data" + newNum);
+        shellUtil.yunUpload("/mnt/4Dkankan/scene/voice/voice" + newNum, "voice/voice" + newNum);
+        shellUtil.yunUpload("/mnt/4Dkankan/scene/video/video" + newNum, "video/video" + newNum);
     }
 
     @Override