|
@@ -0,0 +1,77 @@
|
|
|
|
+package com.fdkankan.scene.controller;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.io.FileTypeUtil;
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
|
+import cn.hutool.core.io.IoUtil;
|
|
|
|
+import cn.hutool.core.lang.UUID;
|
|
|
|
+import com.fdkankan.common.constant.ConstantFilePath;
|
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
|
+import com.fdkankan.common.controller.BaseController;
|
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
|
+import com.fdkankan.common.util.CreateObjUtil;
|
|
|
|
+import java.io.BufferedInputStream;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.PrintWriter;
|
|
|
|
+import java.nio.file.Paths;
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * TODO
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author dengsixing
|
|
|
|
+ * @since 2022/5/17
|
|
|
|
+ **/
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/service/file/convert")
|
|
|
|
+public class FileConvertController extends BaseController {
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "/getModeldata", method = RequestMethod.POST)
|
|
|
|
+ public void convertTxtToModeldata(@RequestParam("file") MultipartFile file) throws Exception{
|
|
|
|
+
|
|
|
|
+ //生成uuid
|
|
|
|
+ String uuid = UUID.randomUUID().toString();
|
|
|
|
+
|
|
|
|
+ String path = ConstantFilePath.FILE_CONVERT_PATH + uuid;
|
|
|
|
+ String srcPath = path + "/" + file.getOriginalFilename();
|
|
|
|
+ String targetPath = path + "vision.modeldata";
|
|
|
|
+ File srcFile = new File(srcPath);
|
|
|
|
+// if(!srcFile.getParentFile().exists()){
|
|
|
|
+// srcFile.getParentFile().mkdir();
|
|
|
|
+// }
|
|
|
|
+ file.transferTo(new File(srcPath));
|
|
|
|
+ String type = FileTypeUtil.getType(srcFile);
|
|
|
|
+ if("txt".equals(type)){
|
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_7007, "txt");
|
|
|
|
+ }
|
|
|
|
+ CreateObjUtil.convertTxtToVisionmodeldata(srcPath, targetPath);
|
|
|
|
+ if(!FileUtil.exist(targetPath)){
|
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_8005);
|
|
|
|
+ }
|
|
|
|
+ BufferedInputStream inputStream = FileUtil.getInputStream(targetPath);
|
|
|
|
+ ServletOutputStream outputStream = response.getOutputStream();
|
|
|
|
+ IoUtil.copy(inputStream, outputStream);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// IoUtil.
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|