|
@@ -1,19 +1,25 @@
|
|
|
package com.fd.controller;
|
|
|
|
|
|
import com.fd.constant.Command;
|
|
|
+import com.fd.constant.MsgCode;
|
|
|
import com.fd.constant.TypeCode;
|
|
|
import com.fd.dto.PageDto;
|
|
|
import com.fd.entity.FileEntity;
|
|
|
import com.fd.server.CmdServer;
|
|
|
import com.fd.server.FileServer;
|
|
|
+import com.fd.util.FileUtils;
|
|
|
import com.fd.util.R;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
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 org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
/**
|
|
|
* Created by Owen on 2019/11/12 0012 9:40
|
|
|
*
|
|
@@ -24,6 +30,9 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
@RestController
|
|
|
public class FdModelController {
|
|
|
|
|
|
+ @Value("${input.file.path}")
|
|
|
+ private String INPUT_FILE_PATH;
|
|
|
+
|
|
|
@Autowired
|
|
|
private FileServer fileServer;
|
|
|
|
|
@@ -31,62 +40,47 @@ public class FdModelController {
|
|
|
private CmdServer cmdServer;
|
|
|
|
|
|
|
|
|
- @ApiOperation("倾斜摄影数据切片")
|
|
|
- @GetMapping("command/osgb/{fileId}/")
|
|
|
- private R cmdOsgb(@PathVariable("fileId") Long fileId) {
|
|
|
- log.info("run cmdOsgb: {}", fileId);
|
|
|
- FileEntity entity = fileServer.findById(fileId);
|
|
|
|
|
|
-// String fileName = entity.getFileName();
|
|
|
-// fileName = StringUtils.substring(fileName, fileName.lastIndexOf("/")+1, fileName.length());
|
|
|
- String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
|
|
|
- String cmd = Command.MODEL_OSGB;
|
|
|
- cmd = cmd.replace("@fileName",fileName);
|
|
|
- log.info("cmd: {}", cmd);
|
|
|
+ @ApiOperation("上传3D模型数据")
|
|
|
+ @PostMapping(value = "upload", consumes = { "multipart/form-data" })
|
|
|
+ private R upload(@RequestParam("file") MultipartFile file){
|
|
|
+ log.info("run upload");
|
|
|
+
|
|
|
+ // 文件名全名
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ String s = StringUtils.substringAfter(fileName, ".");
|
|
|
+ if (!"zip".equals(s)) {
|
|
|
+ return new R(50007,MsgCode.E50007);
|
|
|
+ }
|
|
|
|
|
|
- return cmdServer.exeCmdOsgb(cmd, fileName);
|
|
|
+ return fileServer.uploadBigFile(file, TypeCode.FILE_TYPE_MODEL_OSGB);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@ApiOperation("解压zip文件")
|
|
|
- @GetMapping("command/unzip/{fileId}/")
|
|
|
- private R cmdUnzip(@PathVariable("fileId") Long fileId) {
|
|
|
- log.info("run cmdUnzip: {}", fileId);
|
|
|
+ @GetMapping("unzip/{fileId}/")
|
|
|
+ private R fileUnzip(@PathVariable("fileId") Long fileId) {
|
|
|
+ log.info("run fileUnzip: {}", fileId);
|
|
|
FileEntity entity = fileServer.findById(fileId);
|
|
|
|
|
|
- String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
|
|
|
- String path = StringUtils.substringBeforeLast(entity.getFileUrl(),"/");
|
|
|
+ boolean unzip = FileUtils.unzip(entity.getFileUrl(), INPUT_FILE_PATH);
|
|
|
|
|
|
- String cmd = Command.CMD_ZIP;
|
|
|
- cmd = cmd.replace("@fileName",fileName);
|
|
|
- cmd = cmd.replace("@path", path);
|
|
|
- log.info("cmd: {}", cmd);
|
|
|
-
|
|
|
- return cmdServer.exeCmdUnzip(cmd);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation("移动切片数据到服务器")
|
|
|
- @GetMapping("command/move/{fileId}/")
|
|
|
- private R cmdMv(@PathVariable("fileId") Long fileId) {
|
|
|
- log.info("run cmdUnzip: {}", fileId);
|
|
|
- FileEntity entity = fileServer.findById(fileId);
|
|
|
+ if (!unzip) {
|
|
|
+ return new R(50006, MsgCode.E50006);
|
|
|
+ }
|
|
|
|
|
|
String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
|
|
|
- String path = StringUtils.substringBeforeLast(entity.getFileUrl(),"/");
|
|
|
|
|
|
- String cmd = Command.CMD_MV;
|
|
|
- cmd = cmd.replace("@fileName",fileName);
|
|
|
- cmd = cmd.replace("@path", path);
|
|
|
- log.info("cmd: {}", cmd);
|
|
|
+ FileEntity fileEntity = new FileEntity();
|
|
|
|
|
|
- return cmdServer.exeCmd(cmd);
|
|
|
- }
|
|
|
+ fileEntity.setFileName(fileName);
|
|
|
+ fileEntity.setFileUrl(INPUT_FILE_PATH + File.separator + fileName);
|
|
|
+ fileEntity.setCreateTime(new Date());
|
|
|
+ fileEntity.setUpdateTime(new Date());
|
|
|
+ fileEntity.setType(TypeCode.FILE_TYPE_MODEL_OSGB);
|
|
|
+ fileEntity = fileServer.save(fileEntity);
|
|
|
|
|
|
-
|
|
|
- @ApiOperation("上传3D模型数据")
|
|
|
- @PostMapping(value = "upload", consumes = { "multipart/form-data" })
|
|
|
- private R upload(@RequestParam("file") MultipartFile file){
|
|
|
- log.info("run upload");
|
|
|
- return fileServer.uploadBigFile(file, TypeCode.FILE_TYPE_MODEL_OSGB);
|
|
|
+ return new R(200, fileEntity);
|
|
|
}
|
|
|
|
|
|
@ApiOperation("获取3D模型数据列表")
|
|
@@ -107,5 +101,39 @@ public class FdModelController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @ApiOperation("倾斜摄影数据切片")
|
|
|
+ @GetMapping("command/osgb/{fileId}/")
|
|
|
+ private R cmdOsgb(@PathVariable("fileId") Long fileId) {
|
|
|
+ log.info("run cmdOsgb: {}", fileId);
|
|
|
+ FileEntity entity = fileServer.findById(fileId);
|
|
|
+ // 传入的是目录
|
|
|
+ String cmd = Command.MODEL_OSGB;
|
|
|
+ cmd = cmd.replace("@fileName",entity.getFileName());
|
|
|
+ log.info("cmd: {}", cmd);
|
|
|
+
|
|
|
+ return cmdServer.exeCmdOsgb(cmd, entity.getFileName());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation("移动切片数据到服务器")
|
|
|
+ @GetMapping("command/move/{fileId}/")
|
|
|
+ private R cmdMove(@PathVariable("fileId") Long fileId) {
|
|
|
+ log.info("run cmdMove: {}", fileId);
|
|
|
+ FileEntity entity = fileServer.findById(fileId);
|
|
|
+
|
|
|
+ String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
|
|
|
+ String path = StringUtils.substringBeforeLast(entity.getFileUrl(),"/");
|
|
|
+
|
|
|
+ String cmd = Command.CMD_MV;
|
|
|
+ cmd = cmd.replace("@fileName",fileName);
|
|
|
+ cmd = cmd.replace("@path", path);
|
|
|
+ log.info("cmd: {}", cmd);
|
|
|
+
|
|
|
+ return cmdServer.exeCmd(cmd);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|