wuweihao 5 anni fa
parent
commit
19c8d094cb

+ 3 - 2
src/main/java/com/fd/constant/Command.java

@@ -115,8 +115,9 @@ public class Command {
 //    public static String RASTER_TRANSFORM_GDALWARP  = "docker run --rm -v /root/gis/cesium/input:/root/gis/cesium/input " +
 //            "osgeo/gdal  gdalwarp -t_srs EPSG:4326  /root/gis/cesium/input/@fileName.tif  /root/gis/cesium/input/transform/@fileName.tif";
 
-    public static String RASTER_TRANSFORM_GDALWARP  = "docker run --rm -v /root/gis/cesium:/root/gis/cesium " +
-            "osgeo/gdal  gdalwarp -t_srs EPSG:4326  /root/gis/cesium/input/@fileName.tif  /root/gis/cesium/output/transform/@fileName.tif";
+            // 好像没有使用
+//    public static String RASTER_TRANSFORM_GDALWARP  = "docker run --rm -v /root/gis/cesium:/root/gis/cesium " +
+//            "osgeo/gdal  gdalwarp -t_srs EPSG:4326  /root/gis/cesium/input/@fileName.tif  /root/gis/cesium/output/transform/@fileName.tif";
 
 
     // 严格坐标转换,step:1

+ 2 - 0
src/main/java/com/fd/constant/MsgCode.java

@@ -28,6 +28,8 @@ public class MsgCode {
 
     public static final String E51006 = "文件名重复";
 
+    public static final String E51007 = "目录重复";
+
     public static final String E50007 = "只支持.zip 文件";
 
     public static final String E50008 = "只支持.tip 文件";

+ 21 - 14
src/main/java/com/fd/controller/FdModelController.java

@@ -6,10 +6,9 @@ import com.fd.constant.TypeCode;
 import com.fd.dto.PageDto;
 import com.fd.dto.MyQueue;
 import com.fd.entity.FileEntity;
-import com.fd.entity.FileSchedule;
 import com.fd.entity.OutputFileEntity;
 import com.fd.server.CmdServer;
-import com.fd.server.FileServer;
+//import com.fd.server.FileServer;
 import com.fd.server.ModelServer;
 import com.fd.util.FileUtils;
 import com.fd.util.R;
@@ -40,14 +39,14 @@ import java.util.concurrent.atomic.AtomicInteger;
 @RestController
 public class FdModelController {
 
-    @Value("${input.file.path}")
+    @Value("${input.file.path.model}")
     private String INPUT_FILE_PATH;
 
-    @Value("${output.file.path}")
+    @Value("${output.file.path.model}")
     private String OUTPUT_FILE_PATH;
 
-    @Autowired
-    private FileServer fileServer;
+//    @Autowired
+//    private FileServer fileServer;
 
     @Autowired
     private CmdServer cmdServer;
@@ -56,11 +55,8 @@ public class FdModelController {
     private ModelServer modelServer;
 
     // 队列
-    BlockingQueue<String> queue = new LinkedBlockingQueue<String>(5);
-
     BlockingQueue<MyQueue> modelQueue = new LinkedBlockingQueue<MyQueue>(5);
 
-    private static AtomicInteger count = new AtomicInteger();
 
 
     /**
@@ -92,13 +88,14 @@ public class FdModelController {
         public void run() {
             log.warn("run modelSliceConsumerThread");
             while (true) {
+                OutputFileEntity obj = null;
                 try {
                     MyQueue data = queue.poll(2, TimeUnit.SECONDS);
                     if (data != null) {
                         log.info("消费者,拿到队列中的数据data:" + data.toString());
 
                         Integer integer = cmdServer.exeCmdModelSlice(data.getStr());
-                        OutputFileEntity obj = data.getOutputFile();
+                        obj = data.getOutputFile();
 
                         if (integer != 0) {
                             log.info("error command exeCmdModelSlice");
@@ -111,7 +108,14 @@ public class FdModelController {
                     }
 //                    Thread.sleep(4000);
                 } catch (InterruptedException e) {
+
+                    // o:代表切片失败
+                    obj.setStatus(0);
+                    modelServer.save(obj);
+
 //                    isRun = false;
+                    log.error("error  consume queue modelSliceConsumerThread: {}", e);
+
                     e.printStackTrace();
                 }
             }
@@ -157,13 +161,14 @@ public class FdModelController {
 //        FileEntity entity = fileServer.findById(fileId);
         OutputFileEntity entity = modelServer.findById(fileId);
 
-        FileEntity uploadFiel = fileServer.findById(entity.getUploadId());
+//        FileEntity uploadFiel = fileServer.findById(entity.getUploadId());
 
 
         String outputPath = OUTPUT_FILE_PATH + "unzip";
         FileUtils.createDir(outputPath);
 
-        boolean unzip = FileUtils.unzip(uploadFiel.getFileUrl(), outputPath);
+//        boolean unzip = FileUtils.unzip(uploadFiel.getFileUrl(), outputPath);
+        boolean unzip = FileUtils.unzip(entity.getUploadPath(), outputPath);
 
         if (!unzip) {
             log.info("zip error: {}", MsgCode.E51001);
@@ -209,7 +214,7 @@ public class FdModelController {
 
 
         String fileName = StringUtils.substringBeforeLast(entity.getFileName(), ".");
-        String outputPath = OUTPUT_FILE_PATH + "model";
+        String outputPath = OUTPUT_FILE_PATH + "slice";
         FileUtils.createDir(outputPath);
 
         outputPath = outputPath + File.separator + fileName;
@@ -234,7 +239,9 @@ public class FdModelController {
         try {
             modelQueue.offer(data, 1, TimeUnit.SECONDS);
             log.info("入队成功");
-        } catch (InterruptedException e) {
+        } catch (Exception e) {
+
+            log.error("error  producer queue model cmdModelSlice: {}", e);
             e.printStackTrace();
         }
 

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

@@ -1,39 +1,39 @@
-package com.fd.controller;
-
-import com.fd.server.FileServer;
-import com.fd.util.R;
-import io.swagger.annotations.ApiOperation;
-import lombok.extern.log4j.Log4j2;
-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;
-
-import javax.servlet.http.HttpServletResponse;
-import java.io.File;
-
-/**
- * Created by Owen on 2019/11/13 0013 10:59
- */
-@Log4j2
-@RequestMapping("api/geo")
-@RestController
-public class GeoController {
-
-    @Autowired
-    private FileServer fileServer;
-
-
-    @ApiOperation("layer:图层名称, zxy:坐标")
-    @GetMapping("/{layer}/{z}/{x}/{y}/")
-    private Integer getGeoData(HttpServletResponse response,
-                         @PathVariable("layer") String layer,
-                         @PathVariable("z") String z,
-                         @PathVariable("x") String x,
-                         @PathVariable("y") String y) {
-        String filePath = layer + File.separator + z + File.separator + x + File.separator + y + ".pbf";
-        return fileServer.getGeoData(response, filePath);
-
-    }
-}
+//package com.fd.controller;
+//
+//import com.fd.server.FileServer;
+//import com.fd.util.R;
+//import io.swagger.annotations.ApiOperation;
+//import lombok.extern.log4j.Log4j2;
+//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;
+//
+//import javax.servlet.http.HttpServletResponse;
+//import java.io.File;
+//
+///**
+// * Created by Owen on 2019/11/13 0013 10:59
+// */
+//@Log4j2
+//@RequestMapping("api/geo")
+//@RestController
+//public class GeoController {
+//
+//    @Autowired
+//    private FileServer fileServer;
+//
+//
+//    @ApiOperation("layer:图层名称, zxy:坐标")
+//    @GetMapping("/{layer}/{z}/{x}/{y}/")
+//    private Integer getGeoData(HttpServletResponse response,
+//                         @PathVariable("layer") String layer,
+//                         @PathVariable("z") String z,
+//                         @PathVariable("x") String x,
+//                         @PathVariable("y") String y) {
+//        String filePath = layer + File.separator + z + File.separator + x + File.separator + y + ".pbf";
+//        return fileServer.getGeoData(response, filePath);
+//
+//    }
+//}

+ 31 - 19
src/main/java/com/fd/controller/RasterController.java

@@ -9,7 +9,7 @@ import com.fd.dto.PageDto;
 import com.fd.entity.FileEntity;
 import com.fd.entity.OutputFileEntity;
 import com.fd.server.CmdServer;
-import com.fd.server.FileServer;
+//import com.fd.server.FileServer;
 import com.fd.server.RasterServer;
 import com.fd.util.FileUtils;
 import com.fd.util.R;
@@ -40,14 +40,14 @@ import java.util.concurrent.TimeUnit;
 @RestController
 public class RasterController {
 
-    @Value("${input.file.path}")
+    @Value("${input.file.path.raster}")
     private String INPUT_FILE_PATH;
 
-    @Value("${output.file.path}")
+    @Value("${output.file.path.raster}")
     private String OUTPUT_FILE_PATH;
 
-    @Autowired
-    private FileServer fileServer;
+//    @Autowired
+//    private FileServer fileServer;
 
     @Autowired
     private CmdServer cmdServer;
@@ -144,7 +144,10 @@ public class RasterController {
         try {
             coordQueue.offer(data, 1, TimeUnit.SECONDS);
             log.info("入队成功");
-        } catch (InterruptedException e) {
+        } catch (Exception e) {
+
+            log.error("error  producer queue raster cmdJudgeCoord: {}", e);
+
             e.printStackTrace();
         }
 
@@ -168,13 +171,14 @@ public class RasterController {
         public void run() {
             log.warn("run JudgeCoordConsumerThread");
             while (true) {
+                OutputFileEntity  entity = null;
                 try {
                     MyQueue data = queue.poll(2, TimeUnit.SECONDS);
                     if (data != null) {
                         log.info("消费者,拿到队列中的数据data:" + data.toString());
 
                         Integer isJudge = cmdServer.exeCmdRasterJudgeCoord(data.getStr());
-                        OutputFileEntity  entity = data.getOutputFile();
+                        entity = data.getOutputFile();
 
                         if (1000 == isJudge){
                             log.info("need to transform");
@@ -194,11 +198,14 @@ public class RasterController {
                             entity.setUpdateTime(new Date());
                             rasterServer.save(entity);
                         }
-//                        OutputFileEntity obj = data.getOutputFile();
 
                     }
-                } catch (InterruptedException e) {
-//                    isRun = false;
+                } catch (Exception e) {
+                    entity.setStatus(0);
+                    entity.setUpdateTime(new Date());
+                    rasterServer.save(entity);
+
+                    log.error("error  consume queue raster JudgeCoordConsumerThread: {}", e);
                     e.printStackTrace();
                 }
             }
@@ -207,13 +214,13 @@ public class RasterController {
 
     @ApiOperation("栅格数据切片命令")
     @GetMapping("command/osgeo/{fileId}/")
-    private R cmdOsgeo(@PathVariable("fileId") Long fileId) {
-        log.info("run cmdOsgeo: {}", fileId);
+    private R cmdSlice(@PathVariable("fileId") Long fileId) {
+        log.info("run cmdSlice: {}", fileId);
         OutputFileEntity entity = rasterServer.findById(fileId);
 
         String fileName = StringUtils.substringBeforeLast(entity.getFileName(), ".");
 
-        String outFilePath = OUTPUT_FILE_PATH + "tiles" + File.separator + fileName;
+        String outFilePath = OUTPUT_FILE_PATH + "slice" + File.separator + fileName;
         FileUtils.createDir(outFilePath);
 
 
@@ -231,8 +238,6 @@ public class RasterController {
 
         entity = rasterServer.save(entity);
 
-        // 多线程运行切片
-//        new Thread(new RasterSliceThread(cmd, entity)).start();
 
         // 把数据放入队列中
         MyQueue data = new MyQueue();
@@ -241,7 +246,8 @@ public class RasterController {
         try {
             sliceQueue.offer(data, 1, TimeUnit.SECONDS);
             log.info("入队成功");
-        } catch (InterruptedException e) {
+        } catch (Exception e) {
+            log.error("error  producer queue raster cmdSlice: {}", e);
             e.printStackTrace();
         }
 
@@ -264,12 +270,13 @@ public class RasterController {
         public void run() {
             log.warn("run SliceConsumerThread");
             while (isRun) {
+                OutputFileEntity  entity = null;
                 try {
                     MyQueue data = queue.poll(2, TimeUnit.SECONDS);
                     if (data != null) {
                         log.info("消费者,拿到队列中的数据data:" + data.toString());
 
-                        OutputFileEntity  entity = data.getOutputFile();
+                        entity = data.getOutputFile();
 
                         Integer integer = cmdServer.exeCmdRasterSlice(data.getStr(), entity);
                         if (integer != 0) {
@@ -287,8 +294,13 @@ public class RasterController {
                         log.info("entity: {}", entity.toString());
                     }
 
-                } catch (InterruptedException e) {
-//                    isRun = false;
+                } catch (Exception e) {
+
+                    entity.setStatus(0);
+                    entity.setUpdateTime(new Date());
+                    rasterServer.save(entity);
+
+                    log.error("error  consume queue raster SliceConsumerThread: {}", e);
                     e.printStackTrace();
                 }
             }

+ 71 - 146
src/main/java/com/fd/controller/VectorController.java

@@ -9,11 +9,9 @@ import com.fd.dto.PageDto;
 import com.fd.entity.FileEntity;
 import com.fd.entity.OutputFileEntity;
 import com.fd.server.CmdServer;
-import com.fd.server.FileServer;
 import com.fd.server.VectorServer;
 import com.fd.util.FileUtils;
 import com.fd.util.R;
-import com.fd.util.RegexUtils;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.StringUtils;
@@ -21,12 +19,9 @@ 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 org.springframework.web.multipart.commons.CommonsMultipartFile;
 
 import javax.annotation.PostConstruct;
-import javax.servlet.http.HttpServletRequest;
 import java.io.File;
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
@@ -42,16 +37,13 @@ import java.util.concurrent.TimeUnit;
 @RestController
 public class VectorController {
 
-    @Value("${input.file.path}")
+    @Value("${input.file.path.vector}")
     private String INPUT_FILE_PATH;
 
-    @Value("${output.file.path}")
+    @Value("${output.file.path.vector}")
     private String OUTPUT_FILE_PATH;
 
     @Autowired
-    private FileServer fileServer;
-
-    @Autowired
     private VectorServer vectorServer;
 
     @Autowired
@@ -77,129 +69,45 @@ public class VectorController {
 
 
 
-//    @ApiOperation("上传矢量数据,coord:坐标, directoryName:目录名称")
+//    @ApiOperation("上传矢量数据, coord:坐标(可以为空), 坐标格式:0,0,0,0,0,0,0")
 //    @PostMapping(value = "upload/{directoryName}/", consumes = { "multipart/form-data" })
-//    private R upload(@RequestParam("file") MultipartFile file, @PathVariable("directoryName") String directoryName,
-//                     @RequestParam(value = "coord",required = false) String coord){
-//        log.info("run upload");
-//        return fileServer.uploadFile(file, directoryName, TypeCode.FILE_TYPE_VECTOR);
-//    }
-
-//    @ApiOperation("上传矢量数据,只能上传zip文件,里面的文件名必须跟压缩包一致, coord:坐标(可以为空), 坐标格式:0,0,0,0,0,0,0")
-//    @PostMapping(value = "upload", consumes = { "multipart/form-data" })
 //    private R upload(@RequestParam("file") MultipartFile file,
-//                     @RequestParam(value = "coord",required = false) String coord){
-//        log.info("run upload");
-//
-//        // 文件名全名
-//        String fileName = file.getOriginalFilename();
-//        String s = StringUtils.substringAfterLast(fileName, ".");
+//                           @PathVariable("directoryName") String directoryName,
+//                           @RequestParam(value = "coord",required = false) String coord){
+//        log.info("run uploadVector");
+//        log.info("coord: {}", coord);
 //
-//        if (!"zip".equals(s)) {
-//            return new R(50007,MsgCode.E50007);
+//        // 文件是否包含中文字符
+//        if (RegexUtils.regexChinese(file.getOriginalFilename())) {
+//            return new R(51005, MsgCode.E51005);
 //        }
 //
-//        return vectorServer.uploadFile(file, coord);
+////        FileEntity en = vectorServer.findByDirectory(directoryName);
+////        if (en != null){
+////            return new R(51006, MsgCode.E51006);
+////        }
+//
+//        return vectorServer.uploadDirectoryFile(file, directoryName, coord);
 //    }
 
-
+    /**
+     * 因为他是要目录上传,所以一目录名为唯一标识符。
+     * 这个模块的所有生成的文件都需要加个目录,以防重名覆盖
+     */
     @ApiOperation("上传矢量数据, coord:坐标(可以为空), 坐标格式:0,0,0,0,0,0,0")
-    @PostMapping(value = "upload/{directoryName}/", consumes = { "multipart/form-data" })
-    private R upload(@RequestParam("file") MultipartFile file,
-                           @PathVariable("directoryName") String directoryName,
-                           @RequestParam(value = "coord",required = false) String coord){
-        log.info("run uploadVector");
+    @PostMapping(value = "uploadMult/{directoryName}", consumes = { "multipart/form-data" })
+    private R uploadMult(@RequestParam("file") MultipartFile[] file,
+                     @PathVariable("directoryName") String directoryName,
+                     @RequestParam(value = "coord",required = false) String coord){
+        log.info("run uploadMult");
         log.info("coord: {}", coord);
 
-        // 文件是否包含中文字符
-        if (RegexUtils.regexChinese(file.getOriginalFilename())) {
-            return new R(51005, MsgCode.E51005);
-        }
 
-//        FileEntity en = vectorServer.findByDirectory(directoryName);
-//        if (en != null){
-//            return new R(51006, MsgCode.E51006);
-//        }
 
-        return vectorServer.uploadDirectoryFile(file, directoryName, coord);
+        return vectorServer.uploadDirectoryFileMul(file, directoryName, coord);
     }
 
 
-//    @ApiOperation("上传矢量数据, coord:坐标(可以为空), 坐标格式:0,0,0,0,0,0,0")
-//    @PostMapping(value = "upload/{directoryName}", consumes = { "multipart/form-data" })
-//    private R upload(@RequestParam("file") MultipartFile[] file,
-//                     @PathVariable("directoryName") String directoryName,
-//                     @RequestParam(value = "coord",required = false) String coord){
-//        log.info("run uploadVector");
-//        log.info("coord: {}", coord);
-//
-//
-//
-//        return vectorServer.uploadDirectoryFileMul(file, directoryName, coord);
-//    }
-
-
-
-//    @ApiOperation("解压zip文件")
-//    @GetMapping("unzip/{fileId}/")
-//    private R fileUnzip(@PathVariable("fileId") Long fileId) {
-//        log.info("run fileUnzip: {}", fileId);
-//        FileEntity entity = fileServer.findById(fileId);
-//
-//        boolean unzip = FileUtils.unzip(entity.getFileUrl(), INPUT_FILE_PATH);
-//
-//        if (!unzip) {
-//            log.info("zip error: {}", MsgCode.E51001);
-//            return new R(51001, MsgCode.E51001);
-//        }
-//
-//
-//
-//        String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
-//
-//        // 判断文件内容是否跟目录名称一样
-//        String shpPath = INPUT_FILE_PATH + fileName + File.separator + fileName + ".shp";
-//        File file = new File(shpPath);
-//        if (!file.exists()) {
-//            log.info("zip error: {}", MsgCode.E51002);
-//            return new R(51002, MsgCode.E51002);
-//        }
-//
-//        FileEntity fileEntity = new FileEntity();
-//
-//        // 添加文件夹到数据库
-//        fileEntity.setFileName(fileName);
-//        fileEntity.setFileUrl(INPUT_FILE_PATH + fileName);
-//        fileEntity.setCreateTime(new Date());
-//        fileEntity.setUpdateTime(new Date());
-//        fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
-//        fileEntity.setCoord(entity.getCoord());
-//        fileEntity.setStatus(2);
-//
-//        fileEntity = fileServer.save(fileEntity);
-//
-//        // xxx.shp到数据库
-////        String sName = StringUtils.substringAfter(fileName, "_");
-////        sName = sName + ".shp";
-//        fileEntity = new FileEntity();
-////        fileEntity.setFileName(sName);
-////        fileEntity.setFileUrl(INPUT_FILE_PATH + fileName + File.separator + sName);
-//
-//        fileEntity.setFileName(fileName + ".shp");
-//        fileEntity.setFileUrl(shpPath);
-//
-//        fileEntity.setCreateTime(new Date());
-//        fileEntity.setUpdateTime(new Date());
-//        fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
-//        fileEntity.setCoord(entity.getCoord());
-//        fileEntity = fileServer.save(fileEntity);
-//
-//        return new R(200, fileEntity);
-//    }
-
-
-
-
     @ApiOperation("获取矢量数据列表")
     @PostMapping(value = "list")
     private R list(@RequestBody PageDto param){
@@ -247,7 +155,8 @@ public class VectorController {
         try {
             vectorCoordQueue.offer(data, 1, TimeUnit.SECONDS);
             log.info("入队成功");
-        } catch (InterruptedException e) {
+        } catch (Exception e) {
+            log.error("error vector producer queue cmdJudgeCoord: {}", e);
             e.printStackTrace();
         }
 
@@ -256,6 +165,11 @@ public class VectorController {
 
     /**
      * 坐标判断消费队列
+     *
+     * 矢量数据转坐标只转一次就成功了。
+     * 所以转换的成功的路径都放到strictCoordTransform 路径
+     * 文件都放transform 目录
+     *
      */
     public class VectorJudgeCoordConsumerThread implements Runnable{
 
@@ -270,13 +184,14 @@ public class VectorController {
         public void run() {
             log.info("run VectorJudgeCoordConsumerThread 出队");
             while (true) {
+                OutputFileEntity entity = null;
                 try {
                     MyQueue data = queue.poll(2, TimeUnit.SECONDS);
                     if (data != null) {
                         log.info("消费者,拿到队列中的数据data: " + data.toString());
 
                         Integer isJudge = cmdServer.exeCmdJudgeCoord(data.getStr());
-                        OutputFileEntity entity = data.getOutputFile();
+                        entity = data.getOutputFile();
 
                         // 转换坐标 普通坐标转换
                         if (isJudge == 1000){
@@ -307,8 +222,26 @@ public class VectorController {
                                 entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS84);
                             }
 
-                        } else if (0 == isJudge){ // 不转换坐标
+                        } else if (0 == isJudge){
+                            // 不转换坐标 把文件信息移动到CoordStrictPath 这路径下
                             log.info("not to transform");
+
+                            // 若果改成用一张表,这里需要修改
+//                            FileEntity fileEntity = vectorServer.findByFileName(entity.getFileName());
+//
+//                            String shpPath = OUTPUT_FILE_PATH + "transform" + File.separator + fileEntity.getDirectory();
+//                            FileUtils.createDir(shpPath);
+//                            shpPath = shpPath + "transform" + File.separator + entity.getFileName();
+//                            entity.setCoordStrictPath(shpPath);
+//
+//                            try {
+//                                String uploadPath = entity.getUploadPath();
+//                                uploadPath= StringUtils.substringBeforeLast(uploadPath, "/");
+//                                org.apache.commons.io.FileUtils.copyDirectoryToDirectory(new File(uploadPath), new File(OUTPUT_FILE_PATH + "transform"));
+//                            } catch (IOException e) {
+//                                e.printStackTrace();
+//                            }
+                            entity.setCoordStrictPath(entity.getUploadPath());
                             entity.setUpdateTime(new Date());
                             entity.setStatus(3);
                             vectorServer.save(entity);
@@ -320,9 +253,16 @@ public class VectorController {
                         }
                     }
 //                    Thread.sleep(4000);
-                } catch (InterruptedException e) {
-//                    isRun = false;
-                    e.printStackTrace();
+                } catch (Exception e) {
+                    //出现异常了,修改修改状态
+                    entity.setStatus(7);
+                    entity.setUpdateTime(new Date());
+                    vectorServer.save(entity);
+
+                    log.error("error vector consume queue VectorJudgeCoordConsumerThread: {}", e);
+                    throw new RuntimeException(e);
+
+
                 }
             }
         }
@@ -337,21 +277,14 @@ public class VectorController {
         String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
 //        // 截取目录名称
 
-        String outPath = OUTPUT_FILE_PATH + "geojson";
+        String outPath = OUTPUT_FILE_PATH + "geojson" + File.separator + entity.getDirectory();
         FileUtils.createDir(outPath);
         outPath = outPath +File.separator + fileName + ".json";
 
         String cmd = Command.VECTOR_TO_GEOJSON;
         if (entity.getCoordStrictPath() != null) {
-            // 严格坐标转换
-            cmd = cmd.replace("@inputFile", entity.getCoordStrictPath());
-        } else if (entity.getCoordStrictPath() == null && entity.getCoordGeneralPath() == null ) {
-            // 不需要坐标转换
-            cmd = cmd.replace("@inputFile", entity.getUploadPath());
 
-        } else {
-            // 普通坐标转换
-            cmd = cmd.replace("@inputFile", entity.getCoordGeneralPath());
+            cmd = cmd.replace("@inputFile", entity.getCoordStrictPath());
         }
 
         cmd = cmd.replace("@outputFile", outPath);
@@ -376,18 +309,11 @@ public class VectorController {
     @GetMapping("command/slice/{fileId}/")
     private R cmdSlice (@PathVariable("fileId") Long fileId) {
         log.info("run cmdSlice: {}", fileId);
-//        FileEntity entity = fileServer.findById(fileId);
-        OutputFileEntity entity = vectorServer.findById(fileId);
 
-        String fileName = StringUtils.substringBeforeLast(entity.getFileName(), ".");
+        OutputFileEntity entity = vectorServer.findById(fileId);
 
-        // 如果是全局修改输出目录,这里要注意修改
-        String outPath = OUTPUT_FILE_PATH + "vector/slice";
-//        String outPath = OUTPUT_FILE_PATH + "mbtiles";
+        String outPath = OUTPUT_FILE_PATH + "slice" + File.separator + entity.getDirectory();
         FileUtils.createDir(outPath);
-//        outPath = outPath +File.separator + fileName + ".mbtiles";
-        outPath = outPath +File.separator + fileName;
-
 
         String cmd = Command.VECTOR_SLICE_TIPPECANOE;
         cmd = cmd.replace("@inputFile", entity.getGeojsonPath());
@@ -425,7 +351,8 @@ public class VectorController {
         cmd = cmd.replace("@inputFile", entity.getUploadPath());
         cmd = cmd.replace("@outputFile", directory);
         log.info("cmd: {}", cmd);
-        return  runCmd(cmd, entity, directory, null);
+//        return  runCmd(cmd, entity, directory, null);
+        return  runCmd(cmd, entity, null, directory);
     }
 
 
@@ -446,9 +373,7 @@ public class VectorController {
 
     // 创建目录
     private String createDirectory(OutputFileEntity entity){
-        String fileName = StringUtils.substringBeforeLast(entity.getFileName(), ".");
-//        String directory = INPUT_FILE_PATH + "transform" + File.separator + fileName;
-        String directory = OUTPUT_FILE_PATH + "transform" + File.separator + fileName;
+        String directory = OUTPUT_FILE_PATH + "transform" + File.separator + entity.getDirectory();
         FileUtils.createDir(directory);
         return directory;
     }

+ 0 - 2
src/main/java/com/fd/dto/MyQueue.java

@@ -1,7 +1,5 @@
 package com.fd.dto;
 
-import com.fd.entity.FileEntity;
-import com.fd.entity.FileSchedule;
 import com.fd.entity.OutputFileEntity;
 import lombok.Data;
 

+ 0 - 69
src/main/java/com/fd/entity/FileSchedule.java

@@ -1,69 +0,0 @@
-package com.fd.entity;
-
-import lombok.Data;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Table;
-import java.io.Serializable;
-
-/**
- * Created by Owen on 2019/11/22 0022 18:39
- *
- * 文件进度控制表
- *
- *
- */
-
-@Data
-@Entity
-@Table(name = "t_file_schedule")
-public class FileSchedule extends BaseEntity implements Serializable {
-
-
-    @Column
-    private Long uploadId; // 上传文件ID
-
-    @Column
-    private String fileName; // 文件名称
-
-    @Column
-    private String zipPath; // 压缩文件路径
-
-    @Column
-    private String coordGeneralPath; // 简单坐标文件路径
-
-    @Column
-    private String coordStrictPath; // 严格坐标文件路径
-
-    @Column
-    private String geojsonPath; // geoJson文件路径
-
-    @Column
-    private String slicePath; // 切片文件路径
-
-    @Column
-    private Integer progress; // 进度
-
-    @Column
-    private String type; // 文件类型
-
-    @Column
-    private String coord; // 坐标
-
-
-    /**
-     * 状态
-     * 0:切片失败
-     * 1:未解压
-     * 2:未判断坐标
-     * 3:未转geojson
-     * 4:未切片
-     * 5:切片完成
-     * 6:切片中
-     */
-    @Column
-    private Integer status;
-
-
-}

+ 4 - 0
src/main/java/com/fd/entity/OutputFileEntity.java

@@ -51,6 +51,9 @@ public class OutputFileEntity extends BaseEntity implements Serializable {
     @Column
     private String coord; // 坐标
 
+    @Column
+    private String directory; // 目录名称
+
 
     /**
      * 状态
@@ -64,6 +67,7 @@ public class OutputFileEntity extends BaseEntity implements Serializable {
      * 7: 坐标转换失败
      * 8: 服务已发布
      * 9:判断中
+     * 10:发布失败
      */
     @Column
     private Integer status;

+ 0 - 21
src/main/java/com/fd/repository/FileScheduleRepository.java

@@ -1,21 +0,0 @@
-package com.fd.repository;
-
-import com.fd.entity.FileEntity;
-import com.fd.entity.FileSchedule;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
-import org.springframework.data.jpa.repository.Query;
-
-/**
- * Created by Owen on 2019/10/28 0028 11:36
- *
- * JpaSpecificationExecutor 条件分页查询
- */
-public interface FileScheduleRepository extends JpaRepository<FileSchedule, Long> {
-
-    FileSchedule findByAndAndUploadId(Long uploadId);
-
-
-}

+ 0 - 1
src/main/java/com/fd/repository/OutputFileRepository.java

@@ -1,7 +1,6 @@
 package com.fd.repository;
 
 import com.fd.entity.FileEntity;
-import com.fd.entity.FileSchedule;
 import com.fd.entity.OutputFileEntity;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;

+ 34 - 34
src/main/java/com/fd/server/FileServer.java

@@ -1,34 +1,34 @@
-package com.fd.server;
-
-import com.fd.dto.PageDto;
-import com.fd.entity.FileEntity;
-import com.fd.util.R;
-import org.springframework.web.multipart.MultipartFile;
-
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * Created by Owen on 2019/11/12 0012 10:04
- */
-public interface FileServer {
-
-    // 大文件上传
-    R uploadBigFile(MultipartFile file, String type);
-
-    // 小文件上传
-    R uploadFile(MultipartFile file, String directoryName, String type);
-
-    R findByType(String param, PageDto pageDto);
-
-    R findByType(String type1, String type2, PageDto pageDto);
-
-    R deleteById(Long fileId);
-
-    Integer getGeoData(HttpServletResponse response, String filePath);
-
-    FileEntity findById(Long fileId);
-
-    FileEntity save(FileEntity entity);
-
-    R uploadRasterBigFile(MultipartFile file, String type);
-}
+//package com.fd.server;
+//
+//import com.fd.dto.PageDto;
+//import com.fd.entity.FileEntity;
+//import com.fd.util.R;
+//import org.springframework.web.multipart.MultipartFile;
+//
+//import javax.servlet.http.HttpServletResponse;
+//
+///**
+// * Created by Owen on 2019/11/12 0012 10:04
+// */
+//public interface FileServer {
+//
+//    // 大文件上传
+//    R uploadBigFile(MultipartFile file, String type);
+//
+//    // 小文件上传
+//    R uploadFile(MultipartFile file, String directoryName, String type);
+//
+//    R findByType(String param, PageDto pageDto);
+//
+//    R findByType(String type1, String type2, PageDto pageDto);
+//
+//    R deleteById(Long fileId);
+//
+//    Integer getGeoData(HttpServletResponse response, String filePath);
+//
+//    FileEntity findById(Long fileId);
+//
+//    FileEntity save(FileEntity entity);
+//
+//    R uploadRasterBigFile(MultipartFile file, String type);
+//}

+ 4 - 2
src/main/java/com/fd/server/VectorServer.java

@@ -14,7 +14,7 @@ import java.util.List;
  */
 public interface VectorServer {
 
-    R uploadFile(MultipartFile file, String coord);
+//    R uploadFile(MultipartFile file, String coord);
 
     R uploadDirectoryFile(MultipartFile file, String directoryName, String coord);
 
@@ -30,7 +30,9 @@ public interface VectorServer {
 
     R deleteById(Long fileId);
 
-    FileEntity findByFileName(String fileName);
+//    FileEntity findByFileName(String fileName);
 
     List<FileEntity> findByDirectory(String directory);
+
+    FileEntity findByUploadId(Long uploadId);
 }

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

@@ -25,8 +25,8 @@ import java.util.Date;
 public class CmdServerImpl implements CmdServer {
 
 
-    @Value("${output.file.path}")
-    private String OUTPUT_FILE_PATH;
+//    @Value("${output.file.path}")
+//    private String OUTPUT_FILE_PATH;
 
     @Autowired
     private FileRepository fileRepository;

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

@@ -1,252 +1,252 @@
-package com.fd.server.impl;
-
-import com.fd.constant.MsgCode;
-import com.fd.dto.PageDto;
-import com.fd.entity.FileEntity;
-import com.fd.repository.FileRepository;
-import com.fd.server.FileServer;
-import com.fd.util.FileUtils;
-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.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Sort;
-import org.springframework.stereotype.Service;
-import org.springframework.web.multipart.MultipartFile;
-
-import javax.servlet.http.HttpServletResponse;
-import javax.transaction.Transactional;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Base64;
-import java.util.Date;
-import java.util.Optional;
-
-/**
- * Created by Owen on 2019/11/12 0012 10:05
- */
-@Log4j2
-@Service
-@Transactional
-public class FileServerImpl implements FileServer {
-
-    @Value("${input.file.path}")
-    private String INPUT_FILE_PATH;
-
-    @Value("${output.file.path}")
-    private String OUTPUT_FILE_PATH;
-
-    @Autowired
-    private FileRepository fileRepository;
-
-    @Override
-    public R uploadBigFile(MultipartFile file, String type) {
-        log.warn("run uploadBigFile");
-        long start = System.currentTimeMillis();
-        if (file.isEmpty() || file.getSize() <= 0) {
-            log.info("文件为空");
-            return new R(50001, MsgCode.E50001);
-        }
-
-        // 文件名全名
-        String fullFileName = file.getOriginalFilename();
-
-        // 创建目录路径
-        FileUtils.createDir(INPUT_FILE_PATH);
-
-        // 拼接唯一文件名
-        long timeMillis = System.currentTimeMillis();
-//        String fileName = timeMillis + "_" + fullFileName;
-        String fileName = fullFileName;
-
-        // 文件保存路径
-        String filePath = INPUT_FILE_PATH + fileName;
-
-        // 写文件到本地
-        try {
-            FileUtils.bigFileWrite(file.getInputStream(), filePath);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        log.info("filePath: {}", filePath);
-
-        // 保存信息到db
-        FileEntity entity = new FileEntity();
-        entity.setFileName(fileName);
-        entity.setFileUrl(filePath);
-        entity.setCreateTime(new Date());
-        entity.setUpdateTime(new Date());
-        entity.setType(type);
-        entity.setStatus(1);
-        fileRepository.save(entity);
-        long end = System.currentTimeMillis();
-        log.info("end uploadBigFile, total time: {} s", (end - start)/1000);
-        return new R(200, entity);
-    }
-
-
-    @Override
-    public R uploadRasterBigFile(MultipartFile file, String type) {
-        log.warn("run uploadBigFile");
-        long start = System.currentTimeMillis();
-        if (file.isEmpty() || file.getSize() <= 0) {
-            log.info("文件为空");
-            return new R(50001, MsgCode.E50001);
-        }
-
-        // 文件名全名
-        String fullFileName = file.getOriginalFilename();
-
-        // 创建目录路径
-        FileUtils.createDir(INPUT_FILE_PATH);
-
-        // 拼接唯一文件名
-        long timeMillis = System.currentTimeMillis();
-//        String fileName = timeMillis + "_" + fullFileName;
-        String fileName = fullFileName;
-
-        // 文件保存路径
-        String filePath = INPUT_FILE_PATH + fileName;
-
-        // 写文件到本地
-
-        try {
-            FileUtils.bigFileWrite(file.getInputStream(), filePath);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        log.info("filePath: {}", filePath);
-
-        // 保存信息到db
-        FileEntity entity = new FileEntity();
-        entity.setFileName(fileName);
-        entity.setFileUrl(filePath);
-        entity.setCreateTime(new Date());
-        entity.setUpdateTime(new Date());
-        entity.setType(type);
-        entity.setStatus(2);
-        fileRepository.save(entity);
-        long end = System.currentTimeMillis();
-        log.info("end uploadBigFile, total time: {} s", (end - start)/1000);
-        return new R(200, entity);
-    }
-
-    @Override
-    public R uploadFile(MultipartFile file, String directoryName, String type) {
-        if (file.isEmpty() || file.getSize() <= 0) {
-            log.info("文件为空");
-            return new R(50001, MsgCode.E50001);
-        }
-
-        // 文件名全名
-        String fullFileName = file.getOriginalFilename();
-
-        // 创建目录路径
-        FileUtils.createDir(INPUT_FILE_PATH + directoryName);
-
-        // 拼接唯一文件名
-//        String fileName = FileUtils.dateStr() + fullFileName;
-
-        // 文件保存路径
-        String filePath = INPUT_FILE_PATH + directoryName + File.separator + fullFileName;
-        log.info("filePath: {}", filePath);
-
-        // 写文件到本地
-        try {
-            byte[] bytes = file.getBytes();
-            String content = Base64.getEncoder().encodeToString(bytes);
-            FileUtils.base64ToFileWriter(content, filePath);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-
-        // 保存信息到db
-        FileEntity entity = new FileEntity();
-        entity.setFileName(fullFileName);
-        entity.setFileUrl(filePath);
-        entity.setCreateTime(new Date());
-        entity.setUpdateTime(new Date());
-        entity.setType(type);
-        fileRepository.save(entity);
-
-        log.info("end uploadBigFile");
-        return new R(200, entity);
-    }
-
-
-    @Override
-    public R findByType(String type, PageDto pageDto) {
-        Page<FileEntity> page = fileRepository.findByType(type, PageRequest.of(pageDto.getPageNum(), pageDto.getPageSize(), Sort.by("createTime").descending()));
-        return new R(200, page);
-    }
-
-    @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);
-        if (!e.isPresent()) {
-            return new R(50002, MsgCode.E50002);
-        }
-        FileEntity fileEntity = e.get();
-        String fileName = fileEntity.getFileName();
-        // 文件
-        if (fileName.contains(".")) {
-            File file = new File(fileEntity.getFileUrl());
-            file.delete();
-        } else { // 目录
-            FileUtils.delAllFile(fileEntity.getFileUrl());
-        }
-
-        // 删除数据库记录
-        fileRepository.deleteById(fileId);
-
-        return new R(200, MsgCode.SUCCESS);
-    }
-
-    @Override
-    public Integer getGeoData(HttpServletResponse response, String filePath) {
-        // 判断文件是否存在
-        filePath = OUTPUT_FILE_PATH + filePath;
+//package com.fd.server.impl;
+//
+//import com.fd.constant.MsgCode;
+//import com.fd.dto.PageDto;
+//import com.fd.entity.FileEntity;
+//import com.fd.repository.FileRepository;
+//import com.fd.server.FileServer;
+//import com.fd.util.FileUtils;
+//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.data.domain.Page;
+//import org.springframework.data.domain.PageRequest;
+//import org.springframework.data.domain.Sort;
+//import org.springframework.stereotype.Service;
+//import org.springframework.web.multipart.MultipartFile;
+//
+//import javax.servlet.http.HttpServletResponse;
+//import javax.transaction.Transactional;
+//import java.io.File;
+//import java.io.IOException;
+//import java.io.InputStream;
+//import java.util.Base64;
+//import java.util.Date;
+//import java.util.Optional;
+//
+///**
+// * Created by Owen on 2019/11/12 0012 10:05
+// */
+//@Log4j2
+//@Service
+//@Transactional
+//public class FileServerImpl implements FileServer {
+//
+//    @Value("${input.file.path}")
+//    private String INPUT_FILE_PATH;
+//
+//    @Value("${output.file.path}")
+//    private String OUTPUT_FILE_PATH;
+//
+//    @Autowired
+//    private FileRepository fileRepository;
+//
+//    @Override
+//    public R uploadBigFile(MultipartFile file, String type) {
+//        log.warn("run uploadBigFile");
+//        long start = System.currentTimeMillis();
+//        if (file.isEmpty() || file.getSize() <= 0) {
+//            log.info("文件为空");
+//            return new R(50001, MsgCode.E50001);
+//        }
+//
+//        // 文件名全名
+//        String fullFileName = file.getOriginalFilename();
+//
+//        // 创建目录路径
+//        FileUtils.createDir(INPUT_FILE_PATH);
+//
+//        // 拼接唯一文件名
+//        long timeMillis = System.currentTimeMillis();
+////        String fileName = timeMillis + "_" + fullFileName;
+//        String fileName = fullFileName;
+//
+//        // 文件保存路径
+//        String filePath = INPUT_FILE_PATH + fileName;
+//
+//        // 写文件到本地
+//        try {
+//            FileUtils.bigFileWrite(file.getInputStream(), filePath);
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
 //        log.info("filePath: {}", filePath);
-        File file = new File(filePath);
-        if (!file.exists()) {
-//            log.info("文件不存在: {}", filePath);
-            return null;
-
-        }
-
-        try {
-            FileUtils.fileDownload(response, filePath);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        // 文件下载,不能有返回值
-        return null;
-    }
-
-    @Override
-    public FileEntity findById(Long fileId) {
-        Optional<FileEntity> o = fileRepository.findById(fileId);
-        if (!o.isPresent()) {
-            log.info("id:{} 不存在");
-            return null;
-        }
-
-        FileEntity entity = o.get();
-        return entity;
-    }
-
-    @Override
-    public FileEntity save(FileEntity entity) {
-        return fileRepository.save(entity);
-    }
-}
+//
+//        // 保存信息到db
+//        FileEntity entity = new FileEntity();
+//        entity.setFileName(fileName);
+//        entity.setFileUrl(filePath);
+//        entity.setCreateTime(new Date());
+//        entity.setUpdateTime(new Date());
+//        entity.setType(type);
+//        entity.setStatus(1);
+//        fileRepository.save(entity);
+//        long end = System.currentTimeMillis();
+//        log.info("end uploadBigFile, total time: {} s", (end - start)/1000);
+//        return new R(200, entity);
+//    }
+//
+//
+//    @Override
+//    public R uploadRasterBigFile(MultipartFile file, String type) {
+//        log.warn("run uploadBigFile");
+//        long start = System.currentTimeMillis();
+//        if (file.isEmpty() || file.getSize() <= 0) {
+//            log.info("文件为空");
+//            return new R(50001, MsgCode.E50001);
+//        }
+//
+//        // 文件名全名
+//        String fullFileName = file.getOriginalFilename();
+//
+//        // 创建目录路径
+//        FileUtils.createDir(INPUT_FILE_PATH);
+//
+//        // 拼接唯一文件名
+//        long timeMillis = System.currentTimeMillis();
+////        String fileName = timeMillis + "_" + fullFileName;
+//        String fileName = fullFileName;
+//
+//        // 文件保存路径
+//        String filePath = INPUT_FILE_PATH + fileName;
+//
+//        // 写文件到本地
+//
+//        try {
+//            FileUtils.bigFileWrite(file.getInputStream(), filePath);
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+//        log.info("filePath: {}", filePath);
+//
+//        // 保存信息到db
+//        FileEntity entity = new FileEntity();
+//        entity.setFileName(fileName);
+//        entity.setFileUrl(filePath);
+//        entity.setCreateTime(new Date());
+//        entity.setUpdateTime(new Date());
+//        entity.setType(type);
+//        entity.setStatus(2);
+//        fileRepository.save(entity);
+//        long end = System.currentTimeMillis();
+//        log.info("end uploadBigFile, total time: {} s", (end - start)/1000);
+//        return new R(200, entity);
+//    }
+//
+//    @Override
+//    public R uploadFile(MultipartFile file, String directoryName, String type) {
+//        if (file.isEmpty() || file.getSize() <= 0) {
+//            log.info("文件为空");
+//            return new R(50001, MsgCode.E50001);
+//        }
+//
+//        // 文件名全名
+//        String fullFileName = file.getOriginalFilename();
+//
+//        // 创建目录路径
+//        FileUtils.createDir(INPUT_FILE_PATH + directoryName);
+//
+//        // 拼接唯一文件名
+////        String fileName = FileUtils.dateStr() + fullFileName;
+//
+//        // 文件保存路径
+//        String filePath = INPUT_FILE_PATH + directoryName + File.separator + fullFileName;
+//        log.info("filePath: {}", filePath);
+//
+//        // 写文件到本地
+//        try {
+//            byte[] bytes = file.getBytes();
+//            String content = Base64.getEncoder().encodeToString(bytes);
+//            FileUtils.base64ToFileWriter(content, filePath);
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+//
+//        // 保存信息到db
+//        FileEntity entity = new FileEntity();
+//        entity.setFileName(fullFileName);
+//        entity.setFileUrl(filePath);
+//        entity.setCreateTime(new Date());
+//        entity.setUpdateTime(new Date());
+//        entity.setType(type);
+//        fileRepository.save(entity);
+//
+//        log.info("end uploadBigFile");
+//        return new R(200, entity);
+//    }
+//
+//
+//    @Override
+//    public R findByType(String type, PageDto pageDto) {
+//        Page<FileEntity> page = fileRepository.findByType(type, PageRequest.of(pageDto.getPageNum(), pageDto.getPageSize(), Sort.by("createTime").descending()));
+//        return new R(200, page);
+//    }
+//
+//    @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);
+//        if (!e.isPresent()) {
+//            return new R(50002, MsgCode.E50002);
+//        }
+//        FileEntity fileEntity = e.get();
+//        String fileName = fileEntity.getFileName();
+//        // 文件
+//        if (fileName.contains(".")) {
+//            File file = new File(fileEntity.getFileUrl());
+//            file.delete();
+//        } else { // 目录
+//            FileUtils.delAllFile(fileEntity.getFileUrl());
+//        }
+//
+//        // 删除数据库记录
+//        fileRepository.deleteById(fileId);
+//
+//        return new R(200, MsgCode.SUCCESS);
+//    }
+//
+//    @Override
+//    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 null;
+//
+//        }
+//
+//        try {
+//            FileUtils.fileDownload(response, filePath);
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+//        // 文件下载,不能有返回值
+//        return null;
+//    }
+//
+//    @Override
+//    public FileEntity findById(Long fileId) {
+//        Optional<FileEntity> o = fileRepository.findById(fileId);
+//        if (!o.isPresent()) {
+//            log.info("id:{} 不存在");
+//            return null;
+//        }
+//
+//        FileEntity entity = o.get();
+//        return entity;
+//    }
+//
+//    @Override
+//    public FileEntity save(FileEntity entity) {
+//        return fileRepository.save(entity);
+//    }
+//}

+ 2 - 2
src/main/java/com/fd/server/impl/ModelServerImpl.java

@@ -35,10 +35,10 @@ import java.util.Optional;
 @Service
 public class ModelServerImpl implements ModelServer {
 
-    @Value("${input.file.path}")
+    @Value("${input.file.path.model}")
     private String INPUT_FILE_PATH;
 
-    @Value("${output.file.path}")
+    @Value("${output.file.path.model}")
     private String OUTPUT_FILE_PATH;
 
     @Value("${copy.file.path.model}")

+ 3 - 2
src/main/java/com/fd/server/impl/RasterServerImpl.java

@@ -37,10 +37,10 @@ import java.util.Optional;
 @Service
 public class RasterServerImpl implements RasterServer {
 
-    @Value("${input.file.path}")
+    @Value("${input.file.path.raster}")
     private String INPUT_FILE_PATH;
 
-    @Value("${output.file.path}")
+    @Value("${output.file.path.raster}")
     private String OUTPUT_FILE_PATH;
 
     @Value("${copy.file.path.raster}")
@@ -74,6 +74,7 @@ public class RasterServerImpl implements RasterServer {
 
         // 删除数据库记录
         outputFileRepository.deleteById(fileId);
+        fileRepository.deleteById(fileEntity.getUploadId());
 
         return new R(200, MsgCode.SUCCESS);
     }

+ 92 - 70
src/main/java/com/fd/server/impl/VectorServerImpl.java

@@ -37,10 +37,10 @@ import java.util.*;
 @Service
 public class VectorServerImpl implements VectorServer {
 
-    @Value("${input.file.path}")
+    @Value("${input.file.path.vector}")
     private String INPUT_FILE_PATH;
 
-    @Value("${output.file.path}")
+    @Value("${output.file.path.vector}")
     private String OUTPUT_FILE_PATH;
 
     @Value("${copy.file.path.vector}")
@@ -70,24 +70,26 @@ public class VectorServerImpl implements VectorServer {
         }
         OutputFileEntity entity = o.get();
         FileUtils.createDir(MOVE_FILE_TO_SERVER);
-//        FileUtils.base64ToFileWriter(entity.getSlicePath(), MOVE_FILE_TO_SERVER);
 
         try {
-            org.apache.commons.io.FileUtils.copyFileToDirectory(new File(entity.getSlicePath()), new File(MOVE_FILE_TO_SERVER));
+            org.apache.commons.io.FileUtils.copyDirectoryToDirectory(new File(entity.getSlicePath()), new File(MOVE_FILE_TO_SERVER));
+            // 修改前端的config.json 文件
+            writeJsonFile(param, entity.getDirectory());
+
+            entity.setStatus(8);
+            entity.setUpdateTime(new Date());
+            outputFileRepository.save(entity);
+            return new R(200, MsgCode.SUCCESS);
         } catch (IOException e) {
             e.printStackTrace();
-            return new R(200, MsgCode.E51004, e);
+            // 服务发布失败
+            entity.setStatus(10);
+            entity.setUpdateTime(new Date());
+            outputFileRepository.save(entity);
+            return new R(51004, MsgCode.E51004, e);
         }
 
-        // 修改前端的config.json 文件
-        String lastName = StringUtils.substringAfterLast(entity.getSlicePath(), "/");
-        log.info("lastName: {}", lastName);
-        writeJsonFile(param, lastName);
 
-
-        entity.setStatus(8);
-        outputFileRepository.save(entity);
-        return new R(200, MsgCode.SUCCESS);
     }
 
     @Override
@@ -97,59 +99,84 @@ public class VectorServerImpl implements VectorServer {
         if (!e.isPresent()) {
             return new R(50002, MsgCode.E50002);
         }
-        OutputFileEntity fileEntity = e.get();
-        // 文件
-
-
-        // 删除数据库记录
-        outputFileRepository.deleteById(fileId);
+        OutputFileEntity entity = e.get();
 
-        return new R(200, MsgCode.SUCCESS);
-    }
+        // 删除文件
+        if (entity.getUploadPath() != null) {
+            FileUtils.delFolder(entity.getUploadPath());
+        }
 
-    @Override
-    public R uploadFile(MultipartFile file, String coord) {
-        log.warn("run uploadFile");
-        if (file.isEmpty() || file.getSize() <= 0) {
-            log.info("文件为空");
-            return new R(50001, MsgCode.E50001);
+        if (entity.getUnZipPath() != null) {
+            FileUtils.delFolder(entity.getUnZipPath());
         }
 
-        // 文件名全名
-        String fullFileName = file.getOriginalFilename();
+        if (entity.getCoordGeneralPath() != null) {
+            FileUtils.delFolder(entity.getCoordGeneralPath());
+        }
 
-//        // 拼接唯一文件名
-//        String fileName = FileUtils.dateStr() + fullFileName;
-//        String filePath = INPUT_FILE_PATH + fileName;
+        if (entity.getCoordStrictPath() != null) {
+            FileUtils.delFolder(entity.getCoordStrictPath());
+        }
 
-        // 文件保存路径
-        String filePath = INPUT_FILE_PATH + fullFileName;
-        log.info("filePath: {}", filePath);
+        if (entity.getGeojsonPath() != null) {
+            FileUtils.delFolder(entity.getGeojsonPath());
+        }
 
-        // 写文件到本地
-        try {
-            byte[] bytes = file.getBytes();
-            String content = Base64.getEncoder().encodeToString(bytes);
-            FileUtils.base64ToFileWriter(content, filePath);
-        } catch (IOException e) {
-            e.printStackTrace();
+        if (entity.getSlicePath() != null) {
+            FileUtils.delFolder(entity.getSlicePath());
         }
 
-        // 保存信息到db
-        FileEntity entity = new FileEntity();
-        entity.setFileName(fullFileName);
-        entity.setFileUrl(filePath);
-        entity.setCreateTime(new Date());
-        entity.setUpdateTime(new Date());
-        entity.setType(TypeCode.FILE_TYPE_VECTOR);
-        entity.setCoord(coord);
-        entity.setStatus(1);
-        fileRepository.save(entity);
 
-        log.info("end uploadFile");
-        return new R(200, entity);
+        // 删除数据库记录
+        outputFileRepository.deleteById(fileId);
+        fileRepository.deleteById(entity.getUploadId());
+
+        return new R(200, MsgCode.SUCCESS);
     }
 
+//    @Override
+//    public R uploadFile(MultipartFile file, String coord) {
+//        log.warn("run uploadFile");
+//        if (file.isEmpty() || file.getSize() <= 0) {
+//            log.info("文件为空");
+//            return new R(50001, MsgCode.E50001);
+//        }
+//
+//        // 文件名全名
+//        String fullFileName = file.getOriginalFilename();
+//
+////        // 拼接唯一文件名
+////        String fileName = FileUtils.dateStr() + fullFileName;
+////        String filePath = INPUT_FILE_PATH + fileName;
+//
+//        // 文件保存路径
+//        String filePath = INPUT_FILE_PATH + fullFileName;
+//        log.info("filePath: {}", filePath);
+//
+//        // 写文件到本地
+//        try {
+//            byte[] bytes = file.getBytes();
+//            String content = Base64.getEncoder().encodeToString(bytes);
+//            FileUtils.base64ToFileWriter(content, filePath);
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+//
+//        // 保存信息到db
+//        FileEntity entity = new FileEntity();
+//        entity.setFileName(fullFileName);
+//        entity.setFileUrl(filePath);
+//        entity.setCreateTime(new Date());
+//        entity.setUpdateTime(new Date());
+//        entity.setType(TypeCode.FILE_TYPE_VECTOR);
+//        entity.setCoord(coord);
+//        entity.setStatus(1);
+//        fileRepository.save(entity);
+//
+//        log.info("end uploadFile");
+//        return new R(200, entity);
+//    }
+
     @Override
     public R uploadDirectoryFile(MultipartFile file, String directoryName, String coord) {
 
@@ -219,15 +246,12 @@ public class VectorServerImpl implements VectorServer {
     public R uploadDirectoryFileMul(MultipartFile[] files, String directoryName, String coord) {
 
         log.warn("run uploadDirectoryFileMul");
-//        if (file.isEmpty() || file.getSize() <= 0) {
-//            log.info("文件为空");
-//            return new R(50001, MsgCode.E50001);
-//        }
+
 
         // 判断目录重名
         List<FileEntity> en = fileRepository.findByDirectory(directoryName);
         if (en.size() > 0){
-            return new R(51006, MsgCode.E51006);
+            return new R(51007, MsgCode.E51007);
         }
 
         // 创建目录路径
@@ -249,24 +273,18 @@ public class VectorServerImpl implements VectorServer {
             return new R(51005, MsgCode.E51005);
         }
 
-
-
-
                 log.info("fileName : {}", filename);
                 String s = StringUtils.substringAfterLast(filename, ".");
                 if ("shp".equals(s)){
                     shpName = filename;
-//                    entity.setFileName(filename);
                     entity.setDirectory(directoryName);
                     entity.setFileUrl(filePath + filename);
                     entity.setCreateTime(new Date());
                     entity.setUpdateTime(new Date());
                     entity.setType(TypeCode.FILE_TYPE_VECTOR);
                     entity.setCoord(coord);
-//                    entity.setStatus(2);
                     entity = fileRepository.save(entity);
 
-
                 }
                 try {
             FileUtils.bigFileWrite(f.getInputStream(), filePath + filename);
@@ -286,6 +304,7 @@ public class VectorServerImpl implements VectorServer {
         outputFile = new OutputFileEntity();
         outputFile.setUploadId(entity.getId());
         outputFile.setUploadPath(entity.getFileUrl());
+        outputFile.setDirectory(entity.getDirectory());
         outputFile.setFileName(shpName);
         outputFile.setStatus(2);
         outputFile.setType(TypeCode.FILE_TYPE_VECTOR);
@@ -306,15 +325,18 @@ public class VectorServerImpl implements VectorServer {
 
 
     @Override
-    public FileEntity findByFileName(String fileName) {
+    public List<FileEntity> findByDirectory(String directory) {
 
-        return fileRepository.findByFileName(fileName);
+        return fileRepository.findByDirectory(directory);
     }
 
     @Override
-    public List<FileEntity> findByDirectory(String directory) {
-
-        return fileRepository.findByDirectory(directory);
+    public FileEntity findByUploadId(Long uploadId) {
+        Optional<FileEntity> o = fileRepository.findById(uploadId);
+        if (o.isPresent()) {
+            return o.get();
+        }
+        return null;
     }
 
     @Override

+ 8 - 2
src/main/resources/application-dev.properties

@@ -6,8 +6,14 @@ spring.datasource.password=123456
 
 logging.file=log/cesium.log
 
-input.file.path=F:\\test\\cesium\\input\\
-output.file.path=F:\\test\\cesium\\output\\
+input.file.path.model=/root/gis/cesium/input/model/
+output.file.path.model=/root/gis/cesium/output/model/
+
+input.file.path.vector=/root/gis/cesium/input/vector/
+output.file.path.vector=/root/gis/cesium/output/vector/
+
+input.file.path.raster=/root/gis/cesium/input/raster/
+output.file.path.raster=/root/gis/cesium/output/raster/
 
 
 #·¢²¼·þÎñµØÖ·

+ 9 - 2
src/main/resources/application-pro.properties

@@ -6,8 +6,15 @@ spring.datasource.password=4dage
 
 logging.file=/root/java/apache-tomcat-8.5.47_8082_cesium/log/cesium.log
 
-input.file.path=/root/gis/cesium/input/
-output.file.path=/root/gis/cesium/output/
+# 文件存放路径
+input.file.path.model=/root/gis/cesium/input/model/
+output.file.path.model=/root/gis/cesium/output/model/
+
+input.file.path.vector=/root/gis/cesium/input/vector/
+output.file.path.vector=/root/gis/cesium/output/vector/
+
+input.file.path.raster=/root/gis/cesium/input/raster/
+output.file.path.raster=/root/gis/cesium/output/raster/
 
 
 #发布服务地址

+ 8 - 2
src/main/resources/application-uat.properties

@@ -6,8 +6,14 @@ spring.datasource.password=123456
 
 logging.file=/root/java/apache-tomcat_8082_cesium/log/cesium.log
 
-input.file.path=/root/gis/cesium/input/
-output.file.path=/root/gis/cesium/output/
+input.file.path.model=/root/gis/cesium/input/model/
+output.file.path.model=/root/gis/cesium/output/model/
+
+input.file.path.vector=/root/gis/cesium/input/vector/
+output.file.path.vector=/root/gis/cesium/output/vector/
+
+input.file.path.raster=/root/gis/cesium/input/raster/
+output.file.path.raster=/root/gis/cesium/output/raster/
 
 
 #·¢²¼·þÎñµØÖ·

+ 1 - 1
src/main/resources/application.properties

@@ -1,7 +1,7 @@
 server.port=8082
 
 # file multipart
-spring.profiles.active=uat
+spring.profiles.active=pro
 spring.servlet.multipart.enabled=true
 spring.servlet.multipart.max-file-size=51200MB
 spring.servlet.multipart.max-request-size=51200MB