瀏覽代碼

基础版本

wuweihao 5 年之前
父節點
當前提交
15476efdde

File diff suppressed because it is too large
+ 43 - 9
src/main/java/com/fd/constant/Command.java


+ 3 - 1
src/main/java/com/fd/constant/TypeCode.java

@@ -9,7 +9,9 @@ public class TypeCode {
 
     public static final String FILE_TYPE_RASTER_TIF = "tif"; // 栅格数据
 
-    public static final String FILE_TYPE_VECTOR_SHP = "shp"; // 矢量数据
+    public static final String FILE_TYPE_VECTOR_SHP = "shp"; // 转换后的矢量数据
+
+    public static final String FILE_TYPE_VECTOR = "vector"; // 矢量数据
 
     public static final String FILE_TYPE_MODEL_OSGB = "osgb"; // 模型数据
 

+ 61 - 0
src/main/java/com/fd/controller/FdModelController.java

@@ -1,11 +1,15 @@
 package com.fd.controller;
 
+import com.fd.constant.Command;
 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.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.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -23,6 +27,60 @@ public class FdModelController {
     @Autowired
     private FileServer fileServer;
 
+    @Autowired
+    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);
+
+        return cmdServer.exeCmdOsgb(cmd, fileName);
+    }
+
+    @ApiOperation("解压zip文件")
+    @GetMapping("command/unzip/{fileId}/")
+    private R cmdUnzip(@PathVariable("fileId") Long fileId) {
+        log.info("run cmdUnzip: {}", fileId);
+        FileEntity entity = fileServer.findById(fileId);
+
+        String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
+        String path = StringUtils.substringBeforeLast(entity.getFileUrl(),"/");
+
+        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);
+
+        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);
+    }
+
 
     @ApiOperation("上传3D模型数据")
     @PostMapping(value = "upload", consumes = { "multipart/form-data" })
@@ -47,4 +105,7 @@ public class FdModelController {
         log.info("run deleteFile: {}", fileId);
         return fileServer.deleteById(fileId);
     }
+
+
+
 }

+ 1 - 1
src/main/java/com/fd/controller/GeoController.java

@@ -27,7 +27,7 @@ public class GeoController {
 
     @ApiOperation("layer:图层名称, zxy:坐标")
     @GetMapping("/{layer}/{z}/{x}/{y}/")
-    private R getGeoData(HttpServletResponse response,
+    private Integer getGeoData(HttpServletResponse response,
                          @PathVariable("layer") String layer,
                          @PathVariable("z") String z,
                          @PathVariable("x") String x,

+ 85 - 2
src/main/java/com/fd/controller/RasterController.java

@@ -1,6 +1,7 @@
 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;
@@ -11,9 +12,13 @@ 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 +29,9 @@ import org.springframework.web.multipart.MultipartFile;
 @RestController
 public class RasterController {
 
+    @Value("${input.file.path}")
+    private String INPUT_FILE_PATH;
+
     @Autowired
     private FileServer fileServer;
 
@@ -65,6 +73,7 @@ public class RasterController {
         String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
 
         String cmd = Command.RASTER_OSGEO;
+        cmd = cmd.replace("@filePath", entity.getFileUrl());
         cmd = cmd.replace("@fileName",fileName);
         log.info("cmd: {}", cmd);
 
@@ -72,14 +81,88 @@ public class RasterController {
     }
 
 
-    private String getPrefix() {
-        return null;
+    @ApiOperation("栅格数据普通坐标转换")
+    @GetMapping("command/transform/gdalwarp/{fileId}/")
+    private R cmdTansformGdalwarp(@PathVariable("fileId") Long fileId) {
+        log.info("run cmdTansformGdalwarp: {}", fileId);
+        FileEntity entity = fileServer.findById(fileId);
+
+        String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
+
+        String cmd = Command.RASTER_TRANSFORM_GDALWARP;
+        cmd = cmd.replace("@fileName",fileName);
+        log.info("cmd: {}", cmd);
+
+        Integer integer = cmdServer.exeCmdInt(cmd);
+        if (integer != 0) {
+            log.info("error command transform");
+            return new R(50005, MsgCode.E50005);
+        }
+
+        FileEntity fileEntity = new FileEntity();
+        fileEntity.setFileName(entity.getFileName());
+        // /root/gis/cesium/input/transform/@fileName.tif
+        fileEntity.setFileUrl(INPUT_FILE_PATH + "transform" + File.separator + entity.getFileName());
+        fileEntity.setCreateTime(new Date());
+        fileEntity.setUpdateTime(new Date());
+        fileEntity.setType(TypeCode.FILE_TYPE_RASTER_TIF);
+        fileEntity = fileServer.save(fileEntity);
+
+        return new R(200, fileEntity) ;
+    }
+
+
+    @ApiOperation("栅格数据严格坐标转换")
+    @GetMapping("command/transform/strict/gdalwarp/{fileId}/")
+    private R cmdTansformGdalwarpStrict(@PathVariable("fileId") Long fileId) {
+        log.info("run cmdTansformGdalwarpStrict: {}", fileId);
+        FileEntity entity = fileServer.findById(fileId);
+
+        String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
+
+        String step_1 = Command.RASTER_TRANSFORM_GDALWARP_STRICT_1;
+        String step_2 = Command.RASTER_TRANSFORM_GDALWARP_STRICT_2;
+        step_1 = step_1.replace("@fileName",fileName);
+        step_2 = step_2.replace("@fileName",fileName);
+        log.info("cmd1: {}", step_1);
+        log.info("cmd2: {}", step_2);
+
+        Integer integer = cmdServer.exeCmd(step_1, step_2);
+
+        if (integer != 0) {
+            log.info("error command transform");
+            return new R(50005, MsgCode.E50005);
+        }
+
+        FileEntity fileEntity = new FileEntity();
+        fileEntity.setFileName(entity.getFileName());
+        // /root/gis/cesium/input/transform_strict/@fileName.tif
+        fileEntity.setFileUrl(INPUT_FILE_PATH + "transform_strict" + File.separator + entity.getFileName());
+        fileEntity.setCreateTime(new Date());
+        fileEntity.setUpdateTime(new Date());
+        fileEntity.setType(TypeCode.FILE_TYPE_RASTER_TIF);
+        fileEntity = fileServer.save(fileEntity);
+
+        return new R(200, fileEntity) ;
     }
 
+
+
     public static void main(String[] args) {
         String a = "112222.aa";
+        String b = "11/2222/aa";
+        String c = "11/2222/aa.zip";
+        String e = "/root/gis/cesium/input/test/clip.shp";
         System.out.println(StringUtils.stripStart(a,"."));
         System.out.println(StringUtils.substringAfter(a,"."));
         System.out.println(StringUtils.substringBefore(a,"."));
+        System.out.println("c: "+ StringUtils.substringBefore(c,"/"));
+        System.out.println("c: "+ StringUtils.substringBeforeLast(c,"/"));
+        System.out.println(StringUtils.substringBefore(b,"/"));
+        System.out.println(StringUtils.substringBeforeLast(b,"/"));
+        System.out.println(StringUtils.substring(b, b.lastIndexOf("/")+1, b.length()));
+        System.out.println("e: " + StringUtils.substringBeforeLast(e,"/"));
+        System.out.println("e1: " + StringUtils.substring(e,e.indexOf("input/") +6,e.lastIndexOf("/")));
+//        String path = StringUtils.substringBefore(e,"/");
     }
 }

+ 0 - 20
src/main/java/com/fd/controller/TestController.java

@@ -1,20 +0,0 @@
-package com.fd.controller;
-
-import com.fd.util.R;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * Created by Owen on 2019/11/11 0011 15:03
- */
-@RequestMapping("api")
-@RestController
-public class TestController {
-
-    @GetMapping("test")
-    private R test() {
-
-        return new R(200, "hahhahaah");
-    }
-}

+ 0 - 70
src/main/java/com/fd/controller/TranslationController.java

@@ -1,70 +0,0 @@
-package com.fd.controller;
-
-import com.fd.constant.Command;
-import com.fd.entity.FileEntity;
-import com.fd.server.CmdServer;
-import com.fd.server.FileServer;
-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.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * Created by Owen on 2019/11/12 0012 9:40
- *
- * 坐标转换
- */
-@Log4j2
-@RequestMapping("api/transform")
-@RestController
-public class TranslationController {
-
-
-    @Autowired
-    private FileServer fileServer;
-
-    @Autowired
-    private CmdServer cmdServer;
-
-
-    @ApiOperation("栅格数据普通坐标转换")
-    @GetMapping("command/raster/gdalwarp/{fileId}/")
-    private R cmdRasterGdalwarp(@PathVariable("fileId") Long fileId) {
-        log.info("run cmdRasterGdalwarp: {}", fileId);
-        FileEntity entity = fileServer.findById(fileId);
-
-        String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
-
-        String cmd = Command.RASTER_GDALWARP;
-        cmd = cmd.replace("@fileName",fileName);
-        log.info("cmd: {}", cmd);
-
-        return cmdServer.exeCmd(cmd);
-    }
-
-
-    @ApiOperation("栅格数据严格坐标转换")
-    @GetMapping("command/raster/gdalwarp/strict/{fileId}/")
-    private R cmdRasterGdalwarpStrict(@PathVariable("fileId") Long fileId) {
-        log.info("run cmdRasterGdalwarpStrict: {}", fileId);
-        FileEntity entity = fileServer.findById(fileId);
-
-        String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
-
-        String step_1 = Command.RASTER_GDALWARP_STRICT_1;
-        String step_2 = Command.RASTER_GDALWARP_STRICT_2;
-        step_1 = step_1.replace("@fileName",fileName);
-        step_2 = step_2.replace("@fileName",fileName);
-        log.info("cmd1: {}", step_1);
-        log.info("cmd2: {}", step_2);
-
-        return cmdServer.exeCmd(step_1, step_2);
-    }
-
-
-}

+ 56 - 2
src/main/java/com/fd/controller/VectorController.java

@@ -1,15 +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
  *
@@ -20,22 +30,29 @@ import org.springframework.web.multipart.MultipartFile;
 @RestController
 public class VectorController {
 
+    @Value("${input.file.path}")
+    private String INPUT_FILE_PATH;
+
     @Autowired
     private FileServer fileServer;
 
+    @Autowired
+    private CmdServer cmdServer;
+
+
 
     @ApiOperation("上传矢量数据")
     @PostMapping(value = "upload/{directoryName}/", consumes = { "multipart/form-data" })
     private R upload(@RequestParam("file") MultipartFile file, @PathVariable("directoryName") String directoryName){
         log.info("run upload");
-        return fileServer.uploadFile(file, directoryName, TypeCode.FILE_TYPE_VECTOR_SHP);
+        return fileServer.uploadFile(file, directoryName, TypeCode.FILE_TYPE_VECTOR);
     }
 
     @ApiOperation("获取矢量数据列表")
     @PostMapping(value = "list")
     private R list(@RequestBody PageDto param){
         log.info("run list");
-        return fileServer.findByType(TypeCode.FILE_TYPE_VECTOR_SHP, param);
+        return fileServer.findByType(TypeCode.FILE_TYPE_VECTOR, TypeCode.FILE_TYPE_VECTOR_SHP, param);
     }
 
     /**
@@ -47,4 +64,41 @@ public class VectorController {
         log.info("run deleteFile: {}", fileId);
         return fileServer.deleteById(fileId);
     }
+
+
+    @ApiOperation("矢量数据普通坐标转换")
+    @GetMapping("command/transform/{fileId}/")
+    private R cmdTransform(@PathVariable("fileId") Long fileId) {
+        log.info("run cmdTransform: {}", fileId);
+        FileEntity entity = fileServer.findById(fileId);
+
+        String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
+        // 截取目录名称
+        String fileUrl = entity.getFileUrl();
+        String directoryName = StringUtils.substring(fileUrl, fileUrl.indexOf("input/") + 6, fileUrl.lastIndexOf("/"));
+
+        String cmd = Command.VECTOR_TRANSFORM_OGR2OGR;
+        cmd = cmd.replace("@fileName", fileName);
+        cmd = cmd.replace("@directory", directoryName);
+        log.info("cmd: {}", cmd);
+
+        // 创建个目录,用来存转换后的文件,目录以文件名命名
+        String directoryPath = INPUT_FILE_PATH + "transform" + File.separator + directoryName;
+        FileUtils.createDir(directoryPath);
+
+        Integer integer = cmdServer.exeCmdInt(cmd);
+        if (integer != 0) {
+            return new R(50005, MsgCode.E50005);
+        }
+
+        FileEntity shpFile = new FileEntity();
+        shpFile.setFileName(entity.getFileName());
+        shpFile.setFileUrl(directoryPath + File.separator + entity.getFileName());
+        shpFile.setCreateTime(new Date());
+        shpFile.setUpdateTime(new Date());
+        shpFile.setType(TypeCode.FILE_TYPE_VECTOR_SHP);
+        shpFile = fileServer.save(shpFile);
+
+        return new R(200, shpFile);
+    }
 }

+ 6 - 1
src/main/java/com/fd/server/CmdServer.java

@@ -10,8 +10,13 @@ public interface CmdServer {
 
     R exeCmd(String commandStr);
 
-    R exeCmd(String cmd1, String cmd2);
+    Integer exeCmd(String cmd1, String cmd2);
 
     R exeCmd(String commandStr, Long id);
 
+    R exeCmdOsgb(String cmd, String fileName);
+
+    R exeCmdUnzip(String cmd);
+
+    Integer exeCmdInt(String cmd);
 }

+ 5 - 1
src/main/java/com/fd/server/FileServer.java

@@ -20,9 +20,13 @@ public interface FileServer {
 
     R findByType(String param, PageDto pageDto);
 
+    R findByType(String type1, String type2, PageDto pageDto);
+
     R deleteById(Long fileId);
 
-    R getGeoData(HttpServletResponse response, String filePath);
+    Integer getGeoData(HttpServletResponse response, String filePath);
 
     FileEntity findById(Long fileId);
+
+    FileEntity save(FileEntity entity);
 }

+ 103 - 44
src/main/java/com/fd/server/impl/CmdServerImpl.java

@@ -1,13 +1,18 @@
 package com.fd.server.impl;
 
 import com.fd.constant.MsgCode;
+import com.fd.entity.FileEntity;
+import com.fd.repository.FileRepository;
 import com.fd.server.CmdServer;
 import com.fd.util.R;
 import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
+import java.util.Date;
 
 /**
  * Created by Owen on 2019/11/14 0014 15:33
@@ -17,48 +22,15 @@ import java.io.InputStreamReader;
 public class CmdServerImpl implements CmdServer {
 
 
+    @Value("${output.file.path}")
+    private String OUTPUT_FILE_PATH;
+
+    @Autowired
+    private FileRepository fileRepository;
 
     @Override
     public R exeCmd(String commandStr) {
         Integer isCmd = exeCmdSingle(commandStr);
-//        Integer isCmd = null; // 命令运行结果 1:失败, 0:成功
-//        try {
-//            String[] cmd = new String[]{"/bin/sh", "-c", commandStr};
-//            Process ps = Runtime.getRuntime().exec(cmd);
-//
-//            BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
-//            BufferedReader errorBuf = new BufferedReader(new InputStreamReader(ps.getErrorStream()));
-//
-//            StringBuffer sb = new StringBuffer();
-//            StringBuffer errorStr = new StringBuffer();
-//
-//            // error : 坑, 控制台信息是从errorBuf这里出来的
-//            String errorLine;
-//            while ((errorLine = errorBuf.readLine()) != null) {
-//                errorStr.append(errorLine).append("\n");
-//            }
-//            log.info("error result: {}", errorStr.toString());
-//
-//            // success ,没有获取到信息
-//            String line;
-//            while ((line = br.readLine()) != null) {
-////                log.info("=====  br.readLine: ======== {}", br.readLine());
-//                //执行结果加上回车
-//                sb.append(line).append("\n");
-//            }
-//            log.info("result: {}", sb.toString());
-//
-//            // 结束命令行
-//            isCmd = ps.waitFor();
-//
-//            // 关闭流
-//            br.close();
-//            errorBuf.close();
-//
-//        } catch (Exception e) {
-//            e.printStackTrace();
-//        }
-
         if (isCmd == 0) {
             return new R(200, MsgCode.SUCCESS);
         } else {
@@ -68,15 +40,16 @@ public class CmdServerImpl implements CmdServer {
 
     // 复杂坐标转换
     @Override
-    public R exeCmd(String cmd1, String cmd2) {
+    public Integer exeCmd(String cmd1, String cmd2) {
 
         exeCmdSingle(cmd1);
         Integer isCmd = exeCmdSingle(cmd2);
-        if (isCmd == 0) {
-            return new R(200, MsgCode.SUCCESS);
-        } else {
-            return new R(200, MsgCode.E50005);
-        }
+//        if (isCmd == 0) {
+//            return new R(200, MsgCode.SUCCESS);
+//        } else {
+//            return new R(200, MsgCode.E50005);
+//        }
+        return isCmd;
     }
 
     @Override
@@ -133,4 +106,90 @@ public class CmdServerImpl implements CmdServer {
         }
         return isCmd;
     }
+
+
+    @Override
+    public R exeCmdOsgb(String cmd, String fileName) {
+        Integer isCmd = exeCmdSingle(cmd);
+
+
+        if (isCmd == 0) {
+
+            // 命令产生的是文件夹
+            FileEntity entity = new FileEntity();
+            entity.setFileName(fileName);
+            entity.setFileUrl(OUTPUT_FILE_PATH + fileName);
+            entity.setCreateTime(new Date());
+            entity.setUpdateTime(new Date());
+
+            entity = fileRepository.save(entity);
+
+            return new R(200, entity);
+        } else {
+            return new R(200, MsgCode.E50005);
+        }
+
+
+    }
+
+    @Override
+    public R exeCmdUnzip(String commandStr) {
+        log.info("run exeCmdUnzip");
+        Integer isCmd = null; // 命令运行结果 1:失败, 0:成功
+        try {
+            String[] cmd = new String[]{"/bin/sh", "-c", commandStr};
+            Process ps = Runtime.getRuntime().exec(cmd);
+
+            BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
+            BufferedReader errorBuf = new BufferedReader(new InputStreamReader(ps.getErrorStream()));
+
+            StringBuffer sb = new StringBuffer();
+            StringBuffer errorStr = new StringBuffer();
+
+            // error : 坑, 控制台信息是从errorBuf这里出来的
+            String errorLine;
+            log.info("run 111111");
+//            while ((errorLine = errorBuf.readLine()) != null) {
+//                log.info("run 2222222");
+//                errorStr.append(errorLine).append("\n");
+//            }
+//            log.info("run 33333333");
+//            log.info("error result: {}", errorStr.toString());
+//
+//            // success ,没有获取到信息
+//            String line;
+//            while ((line = br.readLine()) != null) {
+//                log.info("run 44444444");
+////                log.info("=====  br.readLine: ======== {}", br.readLine());
+//                //执行结果加上回车
+//                sb.append(line).append("\n");
+//            }
+
+            log.info("result: {}", sb.toString());
+
+            // 结束命令行
+            isCmd = ps.waitFor();
+            log.info("run 5555555");
+            // 关闭流
+            br.close();
+            errorBuf.close();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        if (isCmd == 0) {
+            return new R(200, MsgCode.SUCCESS);
+        } else {
+            return new R(200, MsgCode.E50005);
+        }
+    }
+
+    @Override
+    public Integer exeCmdInt(String cmd) {
+        Integer isCmd = exeCmdSingle(cmd);
+        return isCmd;
+    }
+
+
 }

+ 15 - 3
src/main/java/com/fd/server/impl/FileServerImpl.java

@@ -56,7 +56,8 @@ public class FileServerImpl implements FileServer {
 
         // 拼接唯一文件名
         long timeMillis = System.currentTimeMillis();
-        String fileName = timeMillis + "_" + fullFileName;
+//        String fileName = timeMillis + "_" + fullFileName;
+        String fileName = fullFileName;
 
         // 文件保存路径
         String filePath = INPUT_FILE_PATH + fileName;
@@ -132,6 +133,12 @@ public class FileServerImpl implements FileServer {
     }
 
     @Override
+    public R findByType(String type1, String type2, PageDto pageDto) {
+        Page<FileEntity> page = fileRepository.findByType(type1, type2, PageRequest.of(pageDto.getPageNum(), pageDto.getPageSize(), Sort.by("createTime").descending()));
+        return new R(200, page);
+    }
+
+    @Override
     public R deleteById(Long fileId) {
         // 删除服务器文件
         Optional<FileEntity> e = fileRepository.findById(fileId);
@@ -155,14 +162,14 @@ public class FileServerImpl implements FileServer {
     }
 
     @Override
-    public R getGeoData(HttpServletResponse response, String filePath) {
+    public Integer getGeoData(HttpServletResponse response, String filePath) {
         // 判断文件是否存在
         filePath = OUTPUT_FILE_PATH + filePath;
         log.info("filePath: {}", filePath);
         File file = new File(filePath);
         if (!file.exists()) {
             log.info("文件不存在: {}", filePath);
-            return new R(50004, MsgCode.E50004);
+            return null;
 
         }
 
@@ -186,4 +193,9 @@ public class FileServerImpl implements FileServer {
         FileEntity entity = o.get();
         return entity;
     }
+
+    @Override
+    public FileEntity save(FileEntity entity) {
+        return fileRepository.save(entity);
+    }
 }