wuweihao 5 gadi atpakaļ
vecāks
revīzija
70e96c5caa

+ 4 - 1
src/main/java/com/fd/constant/Command.java

@@ -69,8 +69,11 @@ public class Command {
     /**
      * 栅格数据切片命令
      */
+//    public static String RASTER_SLICE_OSGEO  = "docker run --rm -v /root/gis/cesium:/root/gis/cesium " +
+//            "osgeo/gdal python3 /usr/bin/gdal2tiles.py --zoom=@layerMin-@layerMax --processes=6 @inputFile @outputFile";
+
     public static String RASTER_SLICE_OSGEO  = "docker run --rm -v /root/gis/cesium:/root/gis/cesium " +
-            "osgeo/gdal python3 /usr/bin/gdal2tiles.py --zoom=@layerMin-@layerMax --processes=6 @inputFile @outputFile";
+            "osgeo/gdal python3 /usr/bin/gdal2tiles.py -p geodetic -d --zoom=@layerMin-@layerMax --processes=6 @inputFile @outputFile";
 
     /**
      * 栅格数据判断坐标

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

@@ -30,6 +30,8 @@ public class MsgCode {
 
     public static final String E51007 = "目录重复";
 
+    public static final String E51008 = "上传文件有误";
+
     public static final String E50007 = "只支持.zip 文件";
 
     public static final String E50008 = "只支持.tip 文件";

+ 2 - 11
src/main/java/com/fd/controller/FdModelController.java

@@ -55,7 +55,7 @@ public class FdModelController {
     /**
      * 队列
      */
-    private BlockingQueue<MyQueue> modelQueue = new LinkedBlockingQueue<MyQueue>(5);
+    private BlockingQueue<MyQueue> modelQueue = new LinkedBlockingQueue<MyQueue>(1);
 
 
 
@@ -88,7 +88,7 @@ public class FdModelController {
                 try {
                     MyQueue data = queue.poll(2, TimeUnit.SECONDS);
                     if (data != null) {
-                        log.info("消费者,拿到队列中的数据data:" + data.toString());
+                        log.info("Consumer slice: {}", data.toString());
 
                         Integer integer = cmdServer.exeCmdModelSlice(data.getStr());
                         obj = data.getOutputFile();
@@ -103,15 +103,8 @@ public class FdModelController {
                             return;
                         }
                     }
-//                    Thread.sleep(4000);
                 } catch (InterruptedException e) {
 
-                    // o:代表切片失败
-//                    obj.setStatus(0);
-//                    obj.setUpdateTime(new Date());
-//                    modelServer.save(obj);
-
-//                    isRun = false;
                     log.error("error  consume queue modelSliceConsumerThread: {}", e);
 
                     e.printStackTrace();
@@ -200,7 +193,6 @@ public class FdModelController {
     @ApiOperation("获取3D模型数据列表")
     @PostMapping(value = "list")
     private R list(@RequestBody PageDto param) {
-//        log.info("run list");
         return modelServer.findByType(TypeCode.FILE_TYPE_MODEL, param);
     }
 
@@ -220,7 +212,6 @@ public class FdModelController {
     private R cmdModelSlice(@PathVariable("fileId") Long fileId) {
         log.info("run cmdModelSlice: {}", fileId);
 
-//        FileEntity entity = fileServer.findById(fileId);
         OutputFileEntity entity = modelServer.findById(fileId);
 
 

+ 5 - 5
src/main/java/com/fd/controller/RasterController.java

@@ -54,9 +54,9 @@ public class RasterController {
     @Autowired
     private RasterServer rasterServer;
 
-    BlockingQueue<MyQueue> sliceQueue = new LinkedBlockingQueue<MyQueue>(5);
+    BlockingQueue<MyQueue> sliceQueue = new LinkedBlockingQueue<MyQueue>(1);
 
-    BlockingQueue<MyQueue> coordQueue = new LinkedBlockingQueue<MyQueue>(5);
+    BlockingQueue<MyQueue> coordQueue = new LinkedBlockingQueue<MyQueue>(1);
 
 
     /**
@@ -319,7 +319,7 @@ public class RasterController {
         data.setStr(cmd);
         try {
             sliceQueue.offer(data, 1, TimeUnit.SECONDS);
-            log.info("入队成功");
+            log.info("raster slice 入队成功");
         } catch (Exception e) {
             log.error("error  producer queue raster cmdSlice: {}", e);
             e.printStackTrace();
@@ -348,10 +348,10 @@ public class RasterController {
                 try {
                     MyQueue data = queue.poll(2, TimeUnit.SECONDS);
                     if (data != null) {
-                        log.info("消费者,拿到队列中的数据data:" + data.toString());
+                        log.info("raster consume data:" + data.toString());
 
                         entity = data.getOutputFile();
-
+                        log.info("raster cmd: {}", data.getStr());
                         Integer integer = cmdServer.exeCmdRasterSlice(data.getStr(), entity);
                         if (integer != 0) {
                             log.info("error command exeCmdRasterSlice");

+ 127 - 52
src/main/java/com/fd/controller/VectorController.java

@@ -37,7 +37,7 @@ import java.util.concurrent.TimeUnit;
 
 /**
  * Created by Owen on 2019/11/12 0012 9:40
- *
+ * <p>
  * 矢量数据
  */
 @Log4j2
@@ -57,7 +57,27 @@ public class VectorController {
     @Autowired
     private CmdServer cmdServer;
 
-    BlockingQueue<MyQueue> vectorCoordQueue = new LinkedBlockingQueue<MyQueue>(5);
+    /**
+     * 需要坐标转换
+     * CGCS_2000
+     */
+    private static int COORD_CONVERT_CGCS_2000 = 1000;
+
+    /**
+     * 需要坐标转换
+     * _XIAN_1980
+     */
+    private static int COORD_CONVERT_XIAN_1980 = 1001;
+
+    /**
+     * 不需要坐标转换
+     * WGS84
+     */
+    private static int COORD_NOT_WGS84 = 0;
+
+    BlockingQueue<MyQueue> vectorCoordQueue = new LinkedBlockingQueue<MyQueue>(1);
+
+    BlockingQueue<MyQueue> vectorSliceQueue = new LinkedBlockingQueue<MyQueue>(1);
 
 
     /**
@@ -72,16 +92,16 @@ public class VectorController {
         new Thread(new VectorJudgeCoordConsumerThread(vectorCoordQueue)).start();
 
 
+        new Thread(new VectorSliceThread(vectorSliceQueue)).start();
 
     }
 
 
-
     @ApiOperation("上传矢量数据, coord:坐标(可以为空), 坐标格式:0,0,0,0,0,0,0")
-    @PostMapping(value = "uploadMult/{directoryName}", consumes = { "multipart/form-data" })
+    @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){
+                         @RequestParam(value = "coord", required = false) String[] coord) {
         log.info("run uploadMult");
         log.info("coord: {}", Arrays.toString(coord));
 
@@ -99,6 +119,11 @@ public class VectorController {
 
         R r = vectorServer.uploadDirectoryFileMul(file, directoryName, strCoord);
 
+        // 判断文件是否有错误
+        if (r.getStatus() != 200) {
+            return new R(r.getStatus(), r.getMessage());
+        }
+
         OutputFileEntity entity = (OutputFileEntity) r.getData();
 
         // 判断坐标
@@ -111,34 +136,33 @@ public class VectorController {
 
     /**
      * 上传后判断坐标,显示原始坐标
+     *
      * @return
      */
-    private OutputFileEntity JudgeCoord(OutputFileEntity entity){
+    private OutputFileEntity JudgeCoord(OutputFileEntity entity) {
 
         // 判断是否需要坐标转换
         String cmd = Command.VECTOR_JUDGE_COORD;
         cmd = cmd.replace("@inputFile", entity.getUploadPath());
         log.info("cmd: {}", cmd);
 
-//        Integer isJudge = cmdServer.exeCmdJudgeCoord(cmd);
-
         Map map = vectorServer.cmdJudgeCoord(cmd);
-        Integer code = (int)map.get("code");
+        Integer code = (int) map.get("code");
         log.info("judgeCoord code: {}", code);
 
 
         // 转换坐标 普通坐标转换
-        if (code == 1000){
+        if (code == COORD_CONVERT_CGCS_2000) {
             // 普通坐标转换
             log.info("need to general transform");
             entity.setCoordType(TypeCode.COORD_SYSTEM_2000);
-        } else if (code == 1001) {
+        } else if (code == COORD_CONVERT_XIAN_1980) {
 
             // 严格坐标转换 (西安80转wgs84),需要参数
             log.info("need to strict transform, code: {}", code);
             entity.setCoordType(TypeCode.COORD_XIAN_1980);
 
-        } else if (0 == code){
+        } else if (0 == COORD_NOT_WGS84) {
             // 不转换坐标 把文件信息移动到CoordStrictPath 这路径下
             log.info("not to transform");
             entity.setCoordType(TypeCode.COORD_WGS84);
@@ -156,8 +180,8 @@ public class VectorController {
         styleEntity.setOutputFileId(entity.getId());
         styleEntity.setCreateTime(new Date());
         styleEntity.setUpdateTime(new Date());
-        styleEntity.setLongitude(map.get("longitude")+"");
-        styleEntity.setLatitude(map.get("latitude")+"");
+        styleEntity.setLongitude(map.get("longitude") + "");
+        styleEntity.setLatitude(map.get("latitude") + "");
 
         vectorServer.saveStyle(styleEntity);
 
@@ -167,7 +191,7 @@ public class VectorController {
 
     @ApiOperation("获取矢量数据列表")
     @PostMapping(value = "list")
-    private R list(@RequestBody PageDto param){
+    private R list(@RequestBody PageDto param) {
         return vectorServer.findByType(TypeCode.FILE_TYPE_VECTOR, param);
     }
 
@@ -182,7 +206,6 @@ public class VectorController {
     }
 
 
-
     @ApiOperation("矢量数据判断坐标")
     @GetMapping("command/judge/coord/{fileId}/")
     private R cmdJudgeCoord(@PathVariable("fileId") Long fileId) {
@@ -193,9 +216,6 @@ public class VectorController {
         entity.setStatus(9);
         entity = vectorServer.save(entity);
 
-        // 坐标参数
-//        String coord = entity.getCoord();
-//        log.info("coord: {}", coord);
 
         // 判断是否需要坐标转换
         String cmd = Command.VECTOR_JUDGE_COORD;
@@ -220,18 +240,18 @@ public class VectorController {
 
     /**
      * 坐标判断消费队列
-     *
+     * <p>
      * 矢量数据转坐标只转一次就成功了。
      * 所以转换的成功的路径都放到strictCoordTransform 路径
      * 文件都放transform 目录
-     *
      */
-    public class VectorJudgeCoordConsumerThread implements Runnable{
+    public class VectorJudgeCoordConsumerThread implements Runnable {
 
         private BlockingQueue<MyQueue> queue;
 
         private boolean isRun = true;
-        public VectorJudgeCoordConsumerThread(BlockingQueue<MyQueue> queue){
+
+        public VectorJudgeCoordConsumerThread(BlockingQueue<MyQueue> queue) {
             this.queue = queue;
         }
 
@@ -245,7 +265,6 @@ public class VectorController {
                     if (data != null) {
                         log.info("消费者,拿到队列中的数据data: " + data.toString());
 
-//                        Integer isJudge = cmdServer.exeCmdJudgeCoord(data.getStr());
                         entity = data.getOutputFile();
 
                         // 坐标处理
@@ -255,8 +274,7 @@ public class VectorController {
 
 
                         // 转换坐标 普通坐标转换
-//                        if (isJudge == 1000){
-                        if (TypeCode.COORD_SYSTEM_2000.equals(entity.getCoordType())){
+                        if (TypeCode.COORD_SYSTEM_2000.equals(entity.getCoordType())) {
                             // 普通坐标转换
                             log.info("need to general transform");
                             if (arrayCoord.size() == 0) {
@@ -270,7 +288,6 @@ public class VectorController {
                                 entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS80);
                             }
 
-//                        } else if (isJudge == 1001) {
                         } else if (TypeCode.COORD_XIAN_1980.equals(entity.getCoordType())) {
 
                             // 严格坐标转换 (西安80转wgs84),需要参数
@@ -285,8 +302,7 @@ public class VectorController {
                                 entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS84);
                             }
 
-//                        } else if (0 == isJudge){
-                        } else if (TypeCode.COORD_WGS84.equals(entity.getCoordType())){
+                        } else if (TypeCode.COORD_WGS84.equals(entity.getCoordType())) {
                             // 不转换坐标 把文件信息移动到CoordStrictPath 这路径下
                             log.info("not to transform");
 
@@ -312,6 +328,52 @@ public class VectorController {
         }
     }
 
+
+    public class VectorSliceThread implements Runnable {
+
+        private BlockingQueue<MyQueue> queue;
+
+        public VectorSliceThread(BlockingQueue<MyQueue> queue) {
+            this.queue = queue;
+        }
+
+        @Override
+        public void run() {
+            log.warn("run SliceVectorThread");
+
+            while (true) {
+                try {
+                    MyQueue data = queue.poll(2, TimeUnit.SECONDS);
+                    if (data != null) {
+                        log.info("vector consume data:" + data.toString());
+
+                        OutputFileEntity entity = data.getOutputFile();
+                        log.info("slice cmd: {}", data.getStr());
+                        Integer integer =  vectorServer.cmdSlice(data.getStr(), entity);
+                        log.info("slice test 1");
+                        if (integer != 0) {
+                            log.info("error command exeCmdVectorSlice");
+                            // 如果命令运行失败,状态改为0
+                            entity.setStatus(0);
+                            entity.setUpdateTime(new Date());
+                            vectorServer.save(entity);
+                            return;
+                        }
+                        // 切片完成,修改完成状态
+                        entity.setStatus(5);
+                        entity.setUpdateTime(new Date());
+                        entity = vectorServer.save(entity);
+                        log.info("entity: {}", entity.toString());
+                    }
+
+                } catch (Exception e) {
+                    log.error("error  consume queue vector SliceConsumerThread: {}", e);
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
     @ApiOperation("矢量数据转geojson")
     @GetMapping("command/geojson/{fileId}/")
     private R cmdGeojson(@PathVariable("fileId") Long fileId) {
@@ -323,7 +385,7 @@ public class VectorController {
 
         String outPath = OUTPUT_FILE_PATH + "geojson" + File.separator + entity.getDirectory();
         FileUtils.createDir(outPath);
-        outPath = outPath +File.separator + fileName + ".json";
+        outPath = outPath + File.separator + fileName + ".json";
 
         String cmd = Command.VECTOR_TO_GEOJSON;
         if (entity.getCoordStrictPath() != null) {
@@ -351,14 +413,14 @@ public class VectorController {
 
     @ApiOperation("矢量数据切片")
     @GetMapping("command/slice/{fileId}/{layerMin}/{layerMax}/")
-    private R cmdSlice (@PathVariable("fileId") Long fileId, @PathVariable("layerMin") String layerMin, @PathVariable("layerMax") String layerMax) {
+    private R cmdSlice(@PathVariable("fileId") Long fileId, @PathVariable("layerMin") String layerMin, @PathVariable("layerMax") String layerMax) {
         log.info("run cmdSlice: {}", fileId);
 
-        if (!RegexUtils.regexInt(layerMin)){
-            return new R(50010, MsgCode.E50010) ;
+        if (!RegexUtils.regexInt(layerMin)) {
+            return new R(50010, MsgCode.E50010);
         }
-        if (!RegexUtils.regexInt(layerMax)){
-            return new R(50010, MsgCode.E50010) ;
+        if (!RegexUtils.regexInt(layerMax)) {
+            return new R(50010, MsgCode.E50010);
         }
 
         OutputFileEntity entity = vectorServer.findById(fileId);
@@ -373,19 +435,34 @@ public class VectorController {
         cmd = cmd.replace("@layerMax", layerMax);
         log.info("cmd: {}", cmd);
 
-
-        Integer integer = cmdServer.exeCmdInt(cmd);
-        if (integer != 0) {
-            return new R(50005, MsgCode.E50005);
-        }
-
         entity.setSlicePath(outPath);
         entity.setUpdateTime(new Date());
-        entity.setStatus(5);
+        // 6:切片中
+        entity.setStatus(6);
         entity.setLayerMin(Integer.valueOf(layerMin));
         entity.setLayerMax(Integer.valueOf(layerMax));
         entity = vectorServer.save(entity);
 
+        // 把数据放入队列中
+        MyQueue data = new MyQueue();
+        data.setOutputFile(entity);
+        data.setStr(cmd);
+        try {
+            vectorSliceQueue.offer(data, 1, TimeUnit.SECONDS);
+            log.info("vector slice 入队成功");
+        } catch (Exception e) {
+            log.error("error  producer queue raster cmdSlice: {}", e);
+            e.printStackTrace();
+        }
+
+        return new R(200, entity);
+    }
+
+
+    @ApiOperation("矢量数据进度查询")
+    @GetMapping("progress/{fileId}/")
+    private R getProgress(@PathVariable("fileId") Long fileId) {
+        OutputFileEntity entity = vectorServer.findById(fileId);
         return new R(200, entity);
     }
 
@@ -412,11 +489,10 @@ public class VectorController {
     }
 
 
-
     /**
      * 普通坐标转换
      */
-    private OutputFileEntity generalCoordTransform(OutputFileEntity entity, String cmd){
+    private OutputFileEntity generalCoordTransform(OutputFileEntity entity, String cmd) {
 
         String directory = createDirectory(entity);
         directory = directory + File.separator + entity.getFileName();
@@ -424,19 +500,18 @@ public class VectorController {
         cmd = cmd.replace("@inputFile", entity.getUploadPath());
         cmd = cmd.replace("@outputFile", directory);
         log.info("cmd: {}", cmd);
-        return  runCmd(cmd, entity, null, directory);
+        return runCmd(cmd, entity, null, directory);
     }
 
 
-
     // 严格坐标转换
-    private OutputFileEntity strictCoordTransform(OutputFileEntity entity, String cmd){
+    private OutputFileEntity strictCoordTransform(OutputFileEntity entity, String cmd) {
 
         String directory = createDirectory(entity);
         directory = directory + File.separator + entity.getFileName();
         String coord = entity.getCoord();
-        coord = coord.replace("[","");
-        coord = coord.replace("]","");
+        coord = coord.replace("[", "");
+        coord = coord.replace("]", "");
         // 去空格
         coord = StringUtils.deleteWhitespace(coord);
 
@@ -445,18 +520,18 @@ public class VectorController {
         cmd = cmd.replace("@outputFile", directory);
         log.info("cmd: {}", cmd);
 
-        return  runCmd(cmd, entity, null, directory);
+        return runCmd(cmd, entity, null, directory);
     }
 
     // 创建目录
-    private String createDirectory(OutputFileEntity entity){
+    private String createDirectory(OutputFileEntity entity) {
         String directory = OUTPUT_FILE_PATH + "transform" + File.separator + entity.getDirectory();
         FileUtils.createDir(directory);
         return directory;
     }
 
     // 执行命令,创建对象, 坐标转换使用
-    private OutputFileEntity runCmd(String cmd, OutputFileEntity entity, String generalPath, String strictPath){
+    private OutputFileEntity runCmd(String cmd, OutputFileEntity entity, String generalPath, String strictPath) {
         Integer integer = cmdServer.exeCmdInt(cmd);
         // 转换坐标失败, 修改状态
         if (integer != 0) {

+ 8 - 0
src/main/java/com/fd/server/VectorServer.java

@@ -61,4 +61,12 @@ public interface VectorServer {
      * @return Map
      */
     Map cmdJudgeCoord(String cmd);
+
+
+    /**
+     * 矢量切片
+     * @param cmd
+     * @param entity
+     */
+    Integer cmdSlice(String cmd, OutputFileEntity entity);
 }

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

@@ -71,7 +71,8 @@ public class CmdServerImpl implements CmdServer {
 
     private Integer exeCmdSingle(String commandStr) {
 
-        Integer isCmd = null; // 命令运行结果 1:失败, 0:成功
+        // 命令运行结果 1:失败, 0:成功
+        Integer isCmd = null;
         try {
             String[] cmd = new String[]{"/bin/sh", "-c", commandStr};
             Process ps = Runtime.getRuntime().exec(cmd);
@@ -87,7 +88,6 @@ public class CmdServerImpl implements CmdServer {
             while ((errorLine = errorBuf.readLine()) != null) {
                 errorStr.append(errorLine).append("\n");
             }
-//            log.info("error result: {}", errorStr.toString());
             if (StringUtils.isNotEmpty(errorStr)){
                 log.info("error result: {}", errorStr.toString());
             }
@@ -95,7 +95,6 @@ public class CmdServerImpl implements CmdServer {
             // success ,没有获取到信息
             String line;
             while ((line = br.readLine()) != null) {
-//                log.info("=====  br.readLine: ======== {}", br.readLine());
                 //执行结果加上回车
                 sb.append(line).append("\n");
             }

+ 234 - 108
src/main/java/com/fd/server/impl/VectorServerImpl.java

@@ -10,11 +10,9 @@ import com.fd.dto.ConfigJsonDto;
 import com.fd.dto.PageDto;
 import com.fd.dto.StyleDto;
 import com.fd.entity.FileEntity;
-//import com.fd.entity.LayerEntity;
 import com.fd.entity.OutputFileEntity;
 import com.fd.entity.StyleEntity;
 import com.fd.repository.FileRepository;
-//import com.fd.repository.LayerRepository;
 import com.fd.repository.OutputFileRepository;
 import com.fd.repository.StyleRepository;
 import com.fd.server.CmdServer;
@@ -32,7 +30,6 @@ import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
-import javax.transaction.Transactional;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
@@ -46,7 +43,7 @@ import java.util.*;
  */
 @Log4j2
 @Service
-@Transactional
+//@Transactional
 public class VectorServerImpl implements VectorServer {
 
     @Value("${input.file.path.vector}")
@@ -147,23 +144,39 @@ public class VectorServerImpl implements VectorServer {
 
         // 文件类型
         if (entity.getGeojsonPath() != null) {
+            log.info("test file geojson");
             String path = entity.getGeojsonPath();
             deleteFolder(path, entity);
         }
 
         if (entity.getSlicePath() != null) {
-            FileUtils.delFolder(entity.getSlicePath());
+            log.info("test file getSlicePath");
+            File file = new File(entity.getSlicePath());
+            if (file.exists()) {
+                log.info("test file ");
+                FileUtils.delFolder(entity.getSlicePath());
+            }
+            log.info("test file getSlicePath ok");
         }
 
         // 目录类型
         if (entity.getServicePath() != null) {
-            FileUtils.delFolder(entity.getServicePath());
+            log.info("test file getServicePath");
+
+            File file = new File(entity.getServicePath());
+            if (file.exists()) {
+                log.info("test file ");
+                FileUtils.delFolder(entity.getServicePath());
+            }
+            log.info("test file getServicePath ok");
         }
 
 
         // 删除配置文件config.json制定行
         StyleEntity styleEntity = styleRepository.findByOutputFileIdTop(fileId);
-        deleteRowConfigJson(styleEntity);
+        if (styleEntity != null) {
+            deleteRowConfigJson(styleEntity);
+        }
 
 
         // 删除数据库记录
@@ -177,11 +190,12 @@ public class VectorServerImpl implements VectorServer {
 
 
     // 以目录形式删除
-    private void deleteFolder(String path, OutputFileEntity entity){
+    private void deleteFolder(String path, OutputFileEntity entity) {
         String directory = entity.getDirectory();
         int length = directory.length();
-        path = path.substring(0, path.lastIndexOf(directory)+length);
+        path = path.substring(0, path.lastIndexOf(directory) + length);
         log.warn("delete vector file: {}", path);
+
         FileUtils.delFolder(path);
     }
 
@@ -247,7 +261,7 @@ public class VectorServerImpl implements VectorServer {
 
 
         long end = System.currentTimeMillis();
-        log.info("end uploadBigFile, total time: {} s", (end - start)/1000);
+        log.info("end uploadBigFile, total time: {} s", (end - start) / 1000);
         return new R(200, outputFile);
     }
 
@@ -259,7 +273,7 @@ public class VectorServerImpl implements VectorServer {
 
         // 判断目录重名
         List<FileEntity> en = fileRepository.findByDirectory(directoryName);
-        if (en.size() > 0){
+        if (en.size() > 0) {
             return new R(51007, MsgCode.E51007);
         }
 
@@ -271,58 +285,87 @@ public class VectorServerImpl implements VectorServer {
 
         StringBuilder sb = new StringBuilder();
 
+
+
+        // 检查文件名、格式
+        int suffixCheckInt = 0;
+        HashSet<Object> setPrefix = new HashSet<>();
+
+        // 记录shp 信息
+        boolean shpFlag = false;
         String shpName = "";
 
         if (files != null && files.length > 0) {
-            for (MultipartFile f: files) {
+            for (MultipartFile f : files) {
                 String filename = f.getOriginalFilename();
 
                 // 文件是否包含中文字符
-        if (RegexUtils.regexChinese(filename)) {
-            return new R(51005, MsgCode.E51005);
-        }
+                if (RegexUtils.regexChinese(filename)) {
+                    return new R(51005, MsgCode.E51005);
+                }
 
                 log.info("fileName : {}", filename);
                 String s = StringUtils.substringAfterLast(filename, ".");
-                if ("shp".equals(s)){
-                    shpName = 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 = fileRepository.save(entity);
 
+                // 判断后缀名,需要包含这以下四个
+                String [] suffixCheck = {"dbf","shp","shx","prj"};
+                if (Arrays.asList(suffixCheck).contains(s)) {
+                    suffixCheckInt += 1;
                 }
+
+                // 判断前缀名字是否一致
+                String prefix = StringUtils.substringBeforeLast(filename, ".");
+                setPrefix.add(prefix);
+
+                if ("shp".equals(s)) {
+                    shpFlag = true;
+                    shpName = filename;
+                }
+
                 try {
-            FileUtils.bigFileWrite(f.getInputStream(), filePath + filename);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
+                    FileUtils.bigFileWrite(f.getInputStream(), filePath + filename);
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
                 sb.append(filename).append(",");
             }
         }
 
-        entity.setFileName(sb.toString());
-        entity.setUpdateTime(new Date());
-        entity = fileRepository.save(entity);
+        // 上传文件名是否一致
+        if (setPrefix.size() > 1) {
 
-        OutputFileEntity outputFile = new OutputFileEntity();
+            log.info("文件名前缀不一致");
+            return new R(51008, MsgCode.E51008);
+        }
 
-        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);
-        outputFile.setCoord(entity.getCoord());
-        outputFile.setCreateTime(new Date());
-        outputFile.setUpdateTime(new Date());
+        // 上传文件格式有误
+        if (suffixCheckInt != 4) {
+            log.info("文件后缀名有误");
+            return new R(51008, MsgCode.E51008);
+        }
 
-        outputFile = outputFileRepository.save(outputFile);
+        OutputFileEntity outputFile = new OutputFileEntity();
+        if (shpFlag) {
+            entity.setDirectory(directoryName);
+            entity.setFileName(sb.toString());
+            entity.setFileUrl(filePath + shpName);
+            entity.setCreateTime(new Date());
+            entity.setUpdateTime(new Date());
+            entity.setType(TypeCode.FILE_TYPE_VECTOR);
+            entity.setCoord(coord);
+            entity = fileRepository.save(entity);
 
+            outputFile.setUploadId(entity.getId());
+            outputFile.setUploadPath(entity.getFileUrl());
+            outputFile.setDirectory(entity.getDirectory());
+            outputFile.setFileName(shpName);
+            outputFile.setStatus(2);
+            outputFile.setType(TypeCode.FILE_TYPE_VECTOR);
+            outputFile.setCoord(entity.getCoord());
+            outputFile.setCreateTime(new Date());
+            outputFile.setUpdateTime(new Date());
+            outputFile = outputFileRepository.save(outputFile);
+        }
         return new R(200, outputFile);
     }
 
@@ -393,98 +436,181 @@ public class VectorServerImpl implements VectorServer {
 
     @Override
     public Map cmdJudgeCoord(String commandStr) {
-            // 命令运行结果 1:失败, 0:成功
-            Integer isCmd = null;
+        // 命令运行结果 1:失败, 0:成功
+        Integer isCmd = null;
 
-            StringBuffer sb = new StringBuffer();
-            StringBuffer errorStr = new StringBuffer();
+        StringBuffer sb = new StringBuffer();
+        StringBuffer errorStr = new StringBuffer();
 
-            Map map = null;
-            try {
-                String[] cmd = new String[]{"/bin/sh", "-c", commandStr};
-                Process ps = Runtime.getRuntime().exec(cmd);
+        Map map = null;
+        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()));
+            BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
+            BufferedReader errorBuf = new BufferedReader(new InputStreamReader(ps.getErrorStream()));
 
-                // error : 坑, 控制台信息是从errorBuf这里出来的
-                String errorLine;
-                while ((errorLine = errorBuf.readLine()) != null) {
-                    errorStr.append(errorLine).append("\n");
-                }
-                if (StringUtils.isNotEmpty(errorStr)){
-                    log.info("error result: {}", errorStr.toString());
-                }
+            // error : 坑, 控制台信息是从errorBuf这里出来的
+            String errorLine;
+            while ((errorLine = errorBuf.readLine()) != null) {
+                errorStr.append(errorLine).append("\n");
+            }
+            if (StringUtils.isNotEmpty(errorStr)) {
+                log.info("error result: {}", errorStr.toString());
+            }
 
 
-                // success ,没有获取到信息
-                String line;
-                while ((line = br.readLine()) != null) {
-                    //执行结果加上回车
-                    sb.append(line).append("\n");
-                    // 获取经纬度
+            // success ,没有获取到信息
+            String line;
+            while ((line = br.readLine()) != null) {
+                //执行结果加上回车
+                sb.append(line).append("\n");
+                // 获取经纬度
 
-                    if (line.contains("Extent: (")){
-                        log.info("extent: {}", line);
-                        map = getExtent(line);
-                    }
+                if (line.contains("Extent: (")) {
+                    log.info("extent: {}", line);
+                    map = getExtent(line);
                 }
-                log.info("result: {}", sb.toString());
+            }
+            log.info("result: {}", sb.toString());
+
+            // 结束命令行
+            isCmd = ps.waitFor();
 
-                // 结束命令行
-                isCmd = ps.waitFor();
 
+            // 关闭流
+            br.close();
+            errorBuf.close();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
 
-                // 关闭流
-                br.close();
-                errorBuf.close();
 
-            } catch (Exception e) {
-                e.printStackTrace();
+        if (isCmd == 0) {
+            log.info("end exeCmd : {}", isCmd);
+            // 判断坐标
+            if (sb.toString().contains("GEOGCS[\"China Geodetic Coordinate System 2000\"")) {
+                // 需要普通坐标转换
+                isCmd = 1000;
+                map.put("code", isCmd);
+                log.info("需要坐标转换code:{}, GEOGCS[\"China Geodetic Coordinate System 2000\"", isCmd);
             }
 
+            if (sb.toString().contains("GEOGCS[\"Xian 1980\"")) {
+                // 需要严格坐标转换
+                isCmd = 1001;
+                map.put("code", isCmd);
+                log.info("需要严格坐标转换code:{}, GEOGCS[\"Xian 1980\"", isCmd);
+            }
 
-            if (isCmd == 0) {
-                log.info("end exeCmd : {}", isCmd);
-                // 判断坐标
-                if (sb.toString().contains("GEOGCS[\"China Geodetic Coordinate System 2000\"")) {
-                    // 需要普通坐标转换
-                    isCmd = 1000;
-                    map.put("code", isCmd);
-                    log.info("需要坐标转换code:{}, GEOGCS[\"China Geodetic Coordinate System 2000\"", isCmd);
-                }
+            if (sb.toString().contains("GEOGCS[\"WGS 84\"")) {
+                // 不需要坐标转换
+                isCmd = 0;
+                map.put("code", isCmd);
+                log.info("不需要坐标转换code:{}, GEOGCS[\"WGS 84\"", isCmd);
+            }
 
-                if (sb.toString().contains("GEOGCS[\"Xian 1980\"")) {
-                    // 需要严格坐标转换
-                    isCmd = 1001;
-                    map.put("code", isCmd);
-                    log.info("需要严格坐标转换code:{}, GEOGCS[\"Xian 1980\"", isCmd);
-                }
 
-                if (sb.toString().contains("GEOGCS[\"WGS 84\"")) {
-                    // 不需要坐标转换
-                    isCmd = 0;
-                    map.put("code", isCmd);
-                    log.info("不需要坐标转换code:{}, GEOGCS[\"WGS 84\"", isCmd);
-                }
+        } else {
+            map.put("code", isCmd);
+            log.info("error exeCmd wsitFore: {}", isCmd);
+        }
+
+        return map;
 
+    }
 
-            } else {
-                map.put("code", isCmd);
-                log.info("error exeCmd wsitFore: {}", isCmd);
+    /**
+     * 这个进度输出是从getErrorStream 输出
+     * @param commandStr
+     * @param entity
+     * @return
+     */
+    @Override
+    public Integer cmdSlice(String commandStr, OutputFileEntity entity) {
+        log.info("run vector cmdSlice");
+        // 命令运行结果 1:失败, 0:成功
+        Integer isCmd = null;
+        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: {}", errorLine);
+
+                // 获取进度
+                if (errorLine.contains("%")) {
+                    String s = StringUtils.substringBefore(errorLine, "%");
+                    // 去除空白字符串
+                    s = StringUtils.deleteWhitespace(s);
+
+                    // 只有是数字的
+                    if (RegexUtils.regexInt(s)) {
+
+                        Integer round = (int) Math.round(Double.valueOf(s));
+                        log.info("round: {}", round);
+                        if (round % 5 == 0 ) {
+                            log.info("round1: {}", round);
+                            entity.setUpdateTime(new Date());
+                            entity.setProgress(round - 1);
+                            if (s.equals("99.9")) {
+                                entity.setProgress(100);
+                            }
+                            outputFileRepository.save(entity);
+                        }
+                    }
+
+
+                }
+
+            }
+            if (StringUtils.isNotEmpty(errorStr)){
+                log.info("error result: {}", errorStr.toString());
+            }
+            // success ,没有获取到信息
+            String line;
+            while ((line = br.readLine()) != null) {
+                //执行结果加上回车
+                sb.append(line).append("\n");
+                log.info("data: {}", line);
             }
+            log.info("result: {}", sb.toString());
+            // 结束命令行
+            isCmd = ps.waitFor();
 
-            return map;
+            // 关闭流
+            br.close();
+            errorBuf.close();
 
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        if (isCmd == 0) {
+            log.info("end exeCmd : {}", isCmd);
+        } else {
+            log.info("wsitFore cmd run error : {}", isCmd);
+        }
+        return isCmd;
     }
 
 
     /**
      * 获取经纬度平均值
+     *
      * @param str 传入参数
      * @return map
      */
-    private Map getExtent(String str){
+    private Map getExtent(String str) {
 
         str = str.replace("Extent: (", "");
         str = str.replaceAll("\\(", "");
@@ -585,7 +711,7 @@ public class VectorServerImpl implements VectorServer {
     /**
      * 删除指定行的config.json 数据
      */
-    private void deleteRowConfigJson(StyleEntity entity){
+    private void deleteRowConfigJson(StyleEntity entity) {
         String s = FileUtils.readFile(CONFIG_JSON_PATH);
         JSONObject original = JSON.parseObject(s);
         log.info("original: {}", s);
@@ -618,7 +744,7 @@ public class VectorServerImpl implements VectorServer {
      * 编辑样式,指定行的config.json 数据
      * 添加样式
      */
-    private void editStyleConfigJson(StyleEntity entity){
+    private void editStyleConfigJson(StyleEntity entity) {
         String s = FileUtils.readFile(CONFIG_JSON_PATH);
         JSONObject original = JSON.parseObject(s);
         log.info("original: {}", s);
@@ -630,7 +756,7 @@ public class VectorServerImpl implements VectorServer {
             if (o.getString("name").equals(entity.getName())) {
                 log.warn("old sytle: {}", o.toJSONString());
                 //修改样式
-                o.put("style",JSON.parse(entity.getContent()));
+                o.put("style", JSON.parse(entity.getContent()));
             }
         }
         log.warn("update sytle: {}", layers.toJSONString());

+ 69 - 0
src/main/java/com/fd/thread/SliceVectorThread.java

@@ -0,0 +1,69 @@
+//package com.fd.thread;
+//
+//import com.fd.dto.MyQueue;
+//import com.fd.entity.OutputFileEntity;
+//import com.fd.server.CmdServer;
+//import com.fd.server.VectorServer;
+//import lombok.extern.log4j.Log4j2;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.scheduling.annotation.Async;
+//
+//import java.util.Date;
+//import java.util.concurrent.BlockingQueue;
+//import java.util.concurrent.TimeUnit;
+//
+///**
+// * Created by Owen on 2019/12/6 0006 11:27
+// *
+// * 矢量数据切片多线程处理
+// */
+//@Log4j2
+//public class SliceVectorThread {
+//
+//    @Autowired
+//    private VectorServer vectorServer;
+//
+//    @Autowired
+//    private CmdServer cmdServer;
+//
+//    private BlockingQueue<MyQueue> queue;
+//
+//    public SliceVectorThread(BlockingQueue<MyQueue> queue){
+//        this.queue = queue;
+//    }
+//
+//    @Async("taskExecutor")
+//    public void run(){
+//        log.warn("run SliceVectorThread");
+//
+//        while (true) {
+//            try {
+//                MyQueue data = queue.poll(2, TimeUnit.SECONDS);
+//                if (data != null) {
+//                    log.info("vector consume data:" + data.toString());
+//
+//                    OutputFileEntity entity = data.getOutputFile();
+//
+//                    Integer integer = cmdServer.exeCmdInt(data.getStr());
+//                    if (integer != 0) {
+//                        log.info("error command exeCmdVectorSlice");
+//                        // 如果命令运行失败,状态改为0
+//                        entity.setStatus(0);
+//                        entity.setUpdateTime(new Date());
+//                        vectorServer.save(entity);
+//                        return;
+//                    }
+//                    // 切片完成,修改完成状态
+//                    entity.setStatus(5);
+//                    entity.setUpdateTime(new Date());
+//                    entity = vectorServer.save(entity);
+//                    log.info("entity: {}", entity.toString());
+//                }
+//
+//            } catch (Exception e) {
+//                log.error("error  consume queue vector SliceConsumerThread: {}", e);
+//                e.printStackTrace();
+//            }
+//        }
+//    }
+//}

+ 42 - 0
src/main/java/com/fd/thread/TaskExecutePool.java

@@ -0,0 +1,42 @@
+//package com.fd.thread;
+//
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.scheduling.annotation.EnableAsync;
+//import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+//
+//import java.util.concurrent.Executor;
+//import java.util.concurrent.ThreadPoolExecutor;
+//
+///**
+// * Created by owen on 2017/8/29.
+// */
+//@Configuration
+//@EnableAsync
+//public class TaskExecutePool {
+//
+//    @Value("${spring.task.pool.corePoolSize}")
+//    private int corePoolSize;
+//    @Value("${spring.task.pool.corePoolSize}")
+//    private int maxPoolSize;
+//    @Value("${spring.task.pool.keepAliveSeconds}")
+//    private int keepAliveSeconds;
+//    @Value("${spring.task.pool.queueCapacity}")
+//    private int queueCapacity;
+//
+//    @Bean
+//    public Executor taskExecutor() {
+//        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+//        executor.setCorePoolSize(corePoolSize);
+//        executor.setMaxPoolSize(maxPoolSize);
+//        executor.setQueueCapacity(keepAliveSeconds);
+//        executor.setKeepAliveSeconds(queueCapacity);
+//        executor.setThreadNamePrefix("MyExecutor-");
+//        // rejection-policy:当pool已经达到max size的时候,如何处理新任务
+//        // CALLER_RUNS:不在新线程中执行任务,而是由调用者所在的线程来执行
+//        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+//        executor.initialize();
+//        return executor;
+//    }
+//}

+ 13 - 5
src/main/java/com/fd/util/FileUtils.java

@@ -253,11 +253,19 @@ public class FileUtils {
      */
     public static void delFolder(String folderPath) {
         try {
-            delAllFile(folderPath); //删除完里面所有内容
-            String filePath = folderPath;
-            filePath = filePath.toString();
-            File myFilePath = new File(filePath);
-            myFilePath.delete(); //删除空文件夹
+
+//            File file = new File(folderPath);
+//            if (file.exists()){
+                //删除完里面所有内容
+                delAllFile(folderPath);
+                String filePath = folderPath;
+                filePath = filePath.toString();
+                File myFilePath = new File(filePath);
+                //删除空文件夹
+                myFilePath.delete();
+//            }
+
+
         } catch (Exception e) {
             e.printStackTrace();
         }

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

@@ -11,4 +11,8 @@ spring.jpa.hibernate.ddl-auto=update
 spring.jpa.hibernate.naming.implicit-strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
 spring.jpa.open-in-view=false
 
-
+#Ï̳߳Ø
+spring.task.pool.corePoolSize=5
+spring.task.pool.maxPoolSize=100
+spring.task.pool.keepAliveSeconds=100
+spring.task.pool.queueCapacity=100