lyhzzz 3 mesi fa
parent
commit
8ee82e1a59

+ 1 - 0
src/main/java/com/fdkankan/fusion/common/OssPath.java

@@ -8,6 +8,7 @@ public class OssPath {
     public final static String MANAGE_FILE_PATH = "fusion/media-library/file/%s";
     public final static String MANAGE_MODEL_FILE_PATH = "fusion/media-library/model/%s";
 
+    public final static String MANAGE_FILE_DOWN_PATH = "fusion/media-library/down/%s";
 
 
 }

+ 2 - 1
src/main/java/com/fdkankan/fusion/common/util/ShellUtil.java

@@ -31,7 +31,8 @@ public class ShellUtil {
         try {
             // 执行命令, 返回一个子进程对象(命令在子进程中执行)
             log.info("执行cmd:{}",cmd);
-            process = Runtime.getRuntime().exec(cmd);
+            String[] cmds = new String[]{"/bin/sh", "-c", cmd};
+            process = Runtime.getRuntime().exec(cmds);
             // 获取命令执行结果, 有两个结果: 正常的输出 和 错误的输出(PS: 子进程的输出就是主进程的输入)
             //处理InputStream的线程
             threadRun(process);

+ 103 - 0
src/main/java/com/fdkankan/fusion/controller/DictFileController.java

@@ -1,13 +1,35 @@
 package com.fdkankan.fusion.controller;
 
 
+import cn.hutool.core.io.FileUtil;
+import com.fdkankan.fusion.common.FilePath;
+import com.fdkankan.fusion.common.OssPath;
+import com.fdkankan.fusion.common.ResultCode;
 import com.fdkankan.fusion.common.ResultData;
+import com.fdkankan.fusion.common.util.ShellUtil;
+import com.fdkankan.fusion.common.util.UploadToOssUtil;
+import com.fdkankan.fusion.config.CacheUtil;
+import com.fdkankan.fusion.entity.CommonUpload;
+import com.fdkankan.fusion.entity.Dict;
 import com.fdkankan.fusion.entity.DictFile;
+import com.fdkankan.fusion.entity.Model;
+import com.fdkankan.fusion.exception.BusinessException;
 import com.fdkankan.fusion.request.DictFileParam;
+import com.fdkankan.fusion.response.FileInfoVo;
+import com.fdkankan.fusion.service.ICommonUploadService;
 import com.fdkankan.fusion.service.IDictFileService;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+
 /**
  * <p>
  *  前端控制器
@@ -22,6 +44,12 @@ public class DictFileController extends BaseController{
 
     @Autowired
     IDictFileService dictFileService;
+    @Autowired
+    ICommonUploadService commonUploadService;
+    @Autowired
+    UploadToOssUtil uploadToOssUtil;
+    @Value("${upload.query-path}")
+    private String queryPath;
 
     @PostMapping("/pageList/{typeKey}")
     public ResultData pageList(@RequestBody DictFileParam param, @PathVariable String typeKey){
@@ -41,5 +69,80 @@ public class DictFileController extends BaseController{
         dictFileService.del(dictFile);
         return ResultData.ok();
     }
+
+    @GetMapping("/downFile")
+    public ResultData downFile(@RequestParam(required = false) Integer dictFileId)  {
+        if(dictFileId == null){
+            throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
+        }
+        DictFile dictFile = dictFileService.getById(dictFileId);
+        if(dictFile == null){
+            throw new BusinessException(ResultCode.FILE_NOT_EXIST);
+        }
+        CommonUpload commonUpload = commonUploadService.getById(dictFile.getUploadId());
+        if(commonUpload == null){
+            throw new BusinessException(ResultCode.FILE_NOT_EXIST);
+        }
+
+        if(StringUtils.isBlank(commonUpload.getFileUrl())){
+            throw new BusinessException(ResultCode.FILE_NOT_EXIST);
+        }
+        String sceneObjPath = commonUpload.getFileUrl().replace(queryPath,"");
+        String filePath = String.format(CacheUtil.basePath+"/" +OssPath.MANAGE_FILE_DOWN_PATH ,dictFileId) ;
+        String ossPath = String.format(OssPath.MANAGE_FILE_DOWN_PATH ,dictFileId) ;
+
+        if(!"las".equals(commonUpload.getFileFormat()) && !"laz".equals(commonUpload.getFileFormat()) && !"ply".equals(commonUpload.getFileFormat())
+        && !"obj".equals(commonUpload.getFileFormat()) && !"osgb".equals(commonUpload.getFileFormat()) && !"b3dm".equals(commonUpload.getFileFormat())){
+            return ResultData.ok(commonUpload.getFileUrl());
+        }
+        if("obj".equals(commonUpload.getFileFormat()) || "osgb".equals(commonUpload.getFileFormat()) || "b3dm".equals(commonUpload.getFileFormat())){
+            sceneObjPath = new File(sceneObjPath).getParentFile().getPath();
+        }
+        ShellUtil.yunDownload(sceneObjPath,filePath);
+        ShellUtil.zip(dictFileId+".zip",filePath);
+        ShellUtil.yunDownload(filePath +"/"+dictFileId +"zip",ossPath);
+        FileUtil.del(filePath);
+        return ResultData.ok(queryPath + ossPath);
+    }
+
+    @GetMapping("/downMD5")
+    public ResultData downMD5(@RequestParam(required = false) Integer dictFileId) {
+        if(dictFileId == null){
+            throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
+        }
+        DictFile dictFile = dictFileService.getById(dictFileId);
+        if(dictFile == null){
+            throw new BusinessException(ResultCode.FILE_NOT_EXIST);
+        }
+        CommonUpload commonUpload = commonUploadService.getById(dictFile.getUploadId());
+        if(commonUpload == null){
+            throw new BusinessException(ResultCode.FILE_NOT_EXIST);
+        }
+
+        if(StringUtils.isBlank(commonUpload.getFileUrl())){
+            throw new BusinessException(ResultCode.FILE_NOT_EXIST);
+        }
+        String sceneObjPath = commonUpload.getFileUrl().replace(queryPath,"");
+        if("las".equals(commonUpload.getFileFormat()) || "laz".equals(commonUpload.getFileFormat()) || "ply".equals(commonUpload.getFileFormat())){
+            sceneObjPath = sceneObjPath+"/cloud.js";
+        }
+        FileInfoVo fileInfo = uploadToOssUtil.getFileInfo(sceneObjPath);
+        if(fileInfo == null){
+            throw new BusinessException(ResultCode.FILE_NOT_EXIST);
+        }
+        fileInfo.setSize(Long.valueOf(commonUpload.getFileSize()));
+        String filePath = String.format(CacheUtil.basePath+"/" +OssPath.MANAGE_FILE_DOWN_PATH ,dictFileId) ;
+        String ossPath = String.format(OssPath.MANAGE_FILE_DOWN_PATH ,dictFileId) ;
+
+        File file = new File(filePath +"/"+dictFileId + "_hash.txt");
+
+        FileUtil.writeString(fileInfo.toString(),file,"UTF-8");
+
+        ShellUtil.yunUpload(file.getPath(),ossPath);
+
+        FileUtil.del(file);
+
+        return ResultData.ok(queryPath + ossPath);
+    }
 }
 

+ 1 - 1
src/main/java/com/fdkankan/fusion/controller/UploadController.java

@@ -39,7 +39,7 @@ public class UploadController {
      * 文件上传
      */
     @RequestMapping(value = "/fileNew", method = RequestMethod.POST)
-    public ResultData uploadNew(@RequestParam(required = false) MultipartFile file,
+    public ResultData uploadNew(@RequestParam(value = "file") MultipartFile file,
             @RequestParam(value = "dictId",required = false) Integer dictId) {
 
         return commonUploadService.uploadFileNew(dictId,file);

+ 1 - 1
src/main/java/com/fdkankan/fusion/service/impl/CommonUploadServiceImpl.java

@@ -61,7 +61,7 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
 
     @Override
     public ResultData uploadFileNew( Integer dictId,MultipartFile file) {
-        if(file.isEmpty() ){
+        if(file == null || file.isEmpty() ){
             throw new BusinessException(ResultCode.UPLOAD_ERROR);
         }
         File  tempFile = null;