|
@@ -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);
|
|
|
+ }
|
|
|
}
|
|
|
|