Browse Source

dev
vector 模块修改好

wuweihao 5 years ago
parent
commit
e78d869f0c

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

@@ -1,39 +0,0 @@
-//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);
-//
-//    }
-//}

+ 13 - 5
src/main/java/com/fd/controller/ModelController.java

@@ -39,11 +39,15 @@ import java.util.concurrent.TimeUnit;
 @RestController
 public class ModelController {
 
-    @Value("${input.file.path.model}")
-    private String INPUT_FILE_PATH;
+//    @Value("${input.file.path.model}")
+//    private String INPUT_FILE_PATH;
+//
+//    @Value("${output.file.path.model}")
+//    private String OUTPUT_FILE_PATH;
 
-    @Value("${output.file.path.model}")
-    private String OUTPUT_FILE_PATH;
+    private static String INPUT_FILE_PATH = "/root/gis/cesium/input/model/";
+
+    private static String OUTPUT_FILE_PATH = "/root/gis/cesium/output/model/";
 
 
     /**
@@ -54,7 +58,11 @@ public class ModelController {
 
 
 
-
+    @GetMapping("test")
+    private void test(){
+        log.info("path: {}", OUTPUT_FILE_PATH);
+        log.info("path input: {}", INPUT_FILE_PATH);
+    }
 
 
     @ApiOperation("上传数据,校验文件名")

+ 8 - 4
src/main/java/com/fd/controller/RasterController.java

@@ -44,11 +44,15 @@ import java.util.concurrent.TimeUnit;
 @RestController
 public class RasterController {
 
-    @Value("${input.file.path.raster}")
-    private String INPUT_FILE_PATH;
+//    @Value("${input.file.path.raster}")
+//    private String INPUT_FILE_PATH;
+//
+//    @Value("${output.file.path.raster}")
+//    private String OUTPUT_FILE_PATH;
 
-    @Value("${output.file.path.raster}")
-    private String OUTPUT_FILE_PATH;
+    private static String INPUT_FILE_PATH = "/root/gis/cesium/input/raster/";
+
+    private static String OUTPUT_FILE_PATH = "/root/gis/cesium/output/raster/";
 
 
     private static BlockingQueue<MyQueue> sliceQueue = new LinkedBlockingQueue<MyQueue>(2);

+ 346 - 215
src/main/java/com/fd/controller/VectorController.java

@@ -14,9 +14,11 @@ import com.fd.entity.OutputFileEntity;
 import com.fd.entity.StyleEntity;
 import com.fd.server.CmdServer;
 import com.fd.server.VectorServer;
+import com.fd.server.impl.VectorServerImpl;
 import com.fd.util.FileUtils;
 import com.fd.util.R;
 import com.fd.util.RegexUtils;
+import com.fd.util.SpringContext;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.StringUtils;
@@ -46,17 +48,20 @@ import java.util.concurrent.TimeUnit;
 @RestController
 public class VectorController {
 
-    @Value("${input.file.path.vector}")
-    private String INPUT_FILE_PATH;
+//    @Value("${input.file.path.vector}")
+    private static String INPUT_FILE_PATH = "/root/gis/cesium/input/vector/";
 
-    @Value("${output.file.path.vector}")
-    private String OUTPUT_FILE_PATH;
+//    @Value("${output.file.path.vector}")
+    private static String OUTPUT_FILE_PATH = "/root/gis/cesium/output/vector/";
 
-    @Autowired
-    private VectorServer vectorServer;
 
-    @Autowired
-    private CmdServer cmdServer;
+
+
+//    @Autowired
+//    private VectorServer vectorServer;
+//
+//    @Autowired
+//    private CmdServer cmdServer;
 
     /**
      * 需要坐标转换
@@ -76,9 +81,15 @@ public class VectorController {
      */
     private static int COORD_NOT_WGS84 = 0;
 
-    BlockingQueue<MyQueue> vectorCoordQueue = new LinkedBlockingQueue<MyQueue>(2);
+    private static BlockingQueue<MyQueue> vectorCoordQueue = new LinkedBlockingQueue<MyQueue>(2);
+
+    private static BlockingQueue<MyQueue> vectorSliceQueue = new LinkedBlockingQueue<MyQueue>(2);
 
-    BlockingQueue<MyQueue> vectorSliceQueue = new LinkedBlockingQueue<MyQueue>(2);
+    @GetMapping("test")
+    private void test(){
+        log.info("path: {}", OUTPUT_FILE_PATH);
+        log.info("path input: {}", INPUT_FILE_PATH);
+    }
 
 
     /**
@@ -86,16 +97,16 @@ public class VectorController {
      *
      * @return
      */
-    @PostConstruct
-    private void init() {
-
-        // 判断坐标消费队列
-        new Thread(new VectorJudgeCoordConsumerThread(vectorCoordQueue)).start();
-
-
-        new Thread(new VectorSliceThread(vectorSliceQueue)).start();
-
-    }
+//    @PostConstruct
+//    private void init() {
+//
+//        // 判断坐标消费队列
+//        new Thread(new VectorJudgeCoordConsumerThread(vectorCoordQueue)).start();
+//
+//
+//        new Thread(new VectorSliceThread(vectorSliceQueue)).start();
+//
+//    }
 
 
     @ApiOperation("上传矢量数据, coord:坐标(可以为空), 坐标格式:0,0,0,0,0,0,0")
@@ -110,7 +121,7 @@ public class VectorController {
         if (RegexUtils.regexChinese(directoryName)) {
             return new R(51005, MsgCode.E51005);
         }
-
+        VectorServer vectorServer = SpringContext.getBean(VectorServerImpl.class);
         List<FileEntity> directory = vectorServer.findByDirectory(directoryName);
         if (directory.size() > 0) {
             return new R(51006, MsgCode.E51006);
@@ -128,7 +139,7 @@ public class VectorController {
         OutputFileEntity entity = (OutputFileEntity) r.getData();
 
         // 判断坐标
-        entity = JudgeCoord(entity);
+        entity = JudgeCoord(entity, vectorServer);
 
         return new R(200, entity);
 
@@ -140,7 +151,7 @@ public class VectorController {
      *
      * @return
      */
-    private OutputFileEntity JudgeCoord(OutputFileEntity entity) {
+    private OutputFileEntity JudgeCoord(OutputFileEntity entity, VectorServer vectorServer) {
 
         // 判断是否需要坐标转换
         String cmd = Command.VECTOR_JUDGE_COORD;
@@ -193,19 +204,11 @@ public class VectorController {
     @ApiOperation("获取矢量数据列表")
     @PostMapping(value = "list")
     private R list(@RequestBody PageDto param) {
+        VectorServer vectorServer = SpringContext.getBean(VectorServerImpl.class);
         return vectorServer.findByType(TypeCode.FILE_TYPE_VECTOR, param);
     }
 
-//    /**
-//     * 删除文件
-//     */
-//    @ApiOperation("删除文件")
-//    @GetMapping("delete/{fileId}/")
-//    private R deleteFile(@PathVariable("fileId") Long fileId) {
-//        log.info("run deleteFile: {}", fileId);
-//
-//        return vectorServer.deleteById(fileId);
-//    }
+
 
 
     /**
@@ -215,7 +218,7 @@ public class VectorController {
     @GetMapping("delete/{fileId}/")
     private R deleteFile(@PathVariable("fileId") Long fileId) {
         log.info("run deleteFile: {}", fileId);
-
+        VectorServer vectorServer = SpringContext.getBean(VectorServerImpl.class);
         OutputFileEntity entity = vectorServer.findById(fileId);
         entity.setResStatus(1);
         vectorServer.save(entity);
@@ -224,31 +227,40 @@ public class VectorController {
         fileEntity.setResStatus(1);
         fileEntity = vectorServer.saveInputFile(fileEntity);
 
-        new Thread(new DeleteThread(fileId)).start();
+//        new Thread(new DeleteThread(fileId)).start();
+        deleteThread(fileId, vectorServer);
         log.info("delete vector id");
         return new R(200, MsgCode.SUCCESS);
     }
 
-    public class DeleteThread implements Runnable{
-
-        private Long fileId;
-
-        public DeleteThread(Long fileId){
-            this.fileId = fileId;
-        }
-
-        @Override
-        public void run() {
-            log.info("run DeleteThread");
-            vectorServer.deleteById(fileId);
-            log.info("end DeleteThread: {}", fileId);
-        }
+    @Async("taskExecutor")
+    public void deleteThread(Long fileId, VectorServer vectorServer){
+        log.info("run deleteThread");
+        vectorServer.deleteById(fileId);
+        log.info("end deleteThread id : {}", fileId);
     }
 
+//    public class DeleteThread implements Runnable{
+//
+//        private Long fileId;
+//
+//        public DeleteThread(Long fileId){
+//            this.fileId = fileId;
+//        }
+//
+//        @Override
+//        public void run() {
+//            log.info("run DeleteThread");
+//            vectorServer.deleteById(fileId);
+//            log.info("end DeleteThread: {}", fileId);
+//        }
+//    }
+
     @ApiOperation("矢量数据判断坐标")
     @GetMapping("command/judge/coord/{fileId}/")
     private R cmdJudgeCoord(@PathVariable("fileId") Long fileId) {
         log.info("run cmdJudgeCoord: {}", fileId);
+        VectorServer vectorServer = SpringContext.getBean(VectorServerImpl.class);
 
         OutputFileEntity entity = vectorServer.findById(fileId);
 
@@ -277,160 +289,239 @@ public class VectorController {
             e.printStackTrace();
         }
 
-//        if (offer){
-//            entity.setUpdateTime(new Date());
-//            entity.setStatus(9);
-//            entity = vectorServer.save(entity);
-//            return new R(200, entity);
-//        }
-//
-//        return new R(52000, MsgCode.E52000);
+        if (offer){
+            entity.setUpdateTime(new Date());
+            entity.setStatus(9);
+            entity = vectorServer.save(entity);
+
+            convertCoordThread(vectorCoordQueue, vectorServer);
+
+            return new R(200, entity);
+        }
+
+        return new R(52000, MsgCode.E52000);
 
-        return new R(200, entity);
     }
 
+
     /**
      * 坐标判断消费队列
-     * <p>
      * 矢量数据转坐标只转一次就成功了。
      * 所以转换的成功的路径都放到strictCoordTransform 路径
      * 文件都放transform 目录
      */
-    public class VectorJudgeCoordConsumerThread implements Runnable {
-
-        private BlockingQueue<MyQueue> queue;
-
-        private boolean isRun = true;
+    @Async("taskExecutor")
+    public void convertCoordThread (BlockingQueue<MyQueue> queue, VectorServer vectorServer){
+        try {
+            MyQueue data = queue.poll(2, TimeUnit.SECONDS);
+            if (data != null) {
+                log.info("run convertCoordThread 出队");
+                Thread.sleep(2000);
+                OutputFileEntity entity = data.getOutputFile();
+                // 坐标处理
+                String coord = entity.getCoord();
+                log.info("convert coord: {}", coord);
+                JSONArray arrayCoord = JSON.parseArray(coord);
+
+
+                // 转换坐标 普通坐标转换
+                if (TypeCode.COORD_SYSTEM_2000.equals(entity.getCoordType())) {
+                    // 普通坐标转换
+                    log.info("need to general transform");
+                    if (arrayCoord.size() == 0) {
+                        // 没有坐标参数,执行普通坐标转换(ogrinfo)
+                        log.info("run generalCoordTransform");
+                        entity = generalCoordTransform(entity, Command.VECTOR_TRANSFORM_GENERAL, vectorServer);
+
+                    } else {
+                        // 有坐标参数,执行严格坐标转换(CGCS2000转wgs80)
+                        log.info("run strictCoordTransform");
+                        entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS80, vectorServer);
+                    }
 
-        public VectorJudgeCoordConsumerThread(BlockingQueue<MyQueue> queue) {
-            this.queue = queue;
-        }
+                } else if (TypeCode.COORD_XIAN_1980.equals(entity.getCoordType())) {
 
-        @Override
-        public void run() {
-            while (true) {
-                try {
-                    MyQueue data = queue.poll(2, TimeUnit.SECONDS);
-                    if (data != null) {
-                        log.info("run VectorJudgeCoordConsumerThread 出队");
-                        Thread.sleep(2000);
-                        OutputFileEntity entity = data.getOutputFile();
-                        // 坐标处理
-                        String coord = entity.getCoord();
-                        log.info("convert coord: {}", coord);
-                        JSONArray arrayCoord = JSON.parseArray(coord);
-
-
-                        // 转换坐标 普通坐标转换
-                        if (TypeCode.COORD_SYSTEM_2000.equals(entity.getCoordType())) {
-                            // 普通坐标转换
-                            log.info("need to general transform");
-                            if (arrayCoord.size() == 0) {
-                                // 没有坐标参数,执行普通坐标转换(ogrinfo)
-                                log.info("run generalCoordTransform");
-                                entity = generalCoordTransform(entity, Command.VECTOR_TRANSFORM_GENERAL);
-
-                            } else {
-                                // 有坐标参数,执行严格坐标转换(CGCS2000转wgs80)
-                                log.info("run strictCoordTransform");
-                                entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS80);
-                            }
-
-                        } else if (TypeCode.COORD_XIAN_1980.equals(entity.getCoordType())) {
-
-                            // 严格坐标转换 (西安80转wgs84),需要参数
-                            log.info("need to strict transform, CoordType: {}", entity.getCoordType());
-                            if (arrayCoord.size() == 0) {
-                                log.info("error: {}", MsgCode.E50009);
-                                entity.setStatus(7);
-                                entity.setUpdateTime(new Date());
-                                vectorServer.save(entity);
-                            } else {
-                                log.info("run strictCoordTransform");
-                                entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS84);
-                            }
-
-                        } else if (TypeCode.COORD_WGS84.equals(entity.getCoordType())) {
-                            // 不转换坐标 把文件信息移动到CoordStrictPath 这路径下
-                            log.info("not to transform");
-
-                            entity.setCoordStrictPath(entity.getUploadPath());
-                            entity.setUpdateTime(new Date());
-                            entity.setStatus(3);
-                            entity.setCoordType(TypeCode.COORD_WGS84);
-                            vectorServer.save(entity);
-                        } else {
-                            log.info("error exeCmd");
-                            entity.setStatus(7);
-                            entity.setUpdateTime(new Date());
-                            vectorServer.save(entity);
-                        }
-                        log.info("end VectorJudgeCoordConsumerThread ");
+                    // 严格坐标转换 (西安80转wgs84),需要参数
+                    log.info("need to strict transform, CoordType: {}", entity.getCoordType());
+                    if (arrayCoord.size() == 0) {
+                        log.info("error: {}", MsgCode.E50009);
+                        entity.setStatus(7);
+                        entity.setUpdateTime(new Date());
+                        vectorServer.save(entity);
+                    } else {
+                        log.info("run strictCoordTransform");
+                        entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS84, vectorServer);
                     }
-                } catch (Exception e) {
-                    Thread.currentThread().interrupt();
-                    log.error("error vector consume queue VectorJudgeCoordConsumerThread: {}", e);
-                    throw new RuntimeException(e);
-
 
+                } else if (TypeCode.COORD_WGS84.equals(entity.getCoordType())) {
+                    // 不转换坐标 把文件信息移动到CoordStrictPath 这路径下
+                    log.info("not to transform");
+
+                    entity.setCoordStrictPath(entity.getUploadPath());
+                    entity.setUpdateTime(new Date());
+                    entity.setStatus(3);
+                    entity.setCoordType(TypeCode.COORD_WGS84);
+                    vectorServer.save(entity);
+                } else {
+                    log.info("error exeCmd");
+                    entity.setStatus(7);
+                    entity.setUpdateTime(new Date());
+                    vectorServer.save(entity);
                 }
+                log.info("end convertCoordThread id: {}", entity.getId());
             }
-        }
-    }
+        } catch (Exception e) {
+            Thread.currentThread().interrupt();
+            log.error("error vector consume queue VectorJudgeCoordConsumerThread: {}", e);
+            throw new RuntimeException(e);
 
 
-    public class VectorSliceThread implements Runnable {
+        }
+    }
 
-        private BlockingQueue<MyQueue> queue;
+    /**
+     * 坐标判断消费队列
+     * <p>
+     * 矢量数据转坐标只转一次就成功了。
+     * 所以转换的成功的路径都放到strictCoordTransform 路径
+     * 文件都放transform 目录
+     */
+//    public class VectorJudgeCoordConsumerThread implements Runnable {
+//
+//        private BlockingQueue<MyQueue> queue;
+//
+//        private boolean isRun = true;
+//
+//        public VectorJudgeCoordConsumerThread(BlockingQueue<MyQueue> queue) {
+//            this.queue = queue;
+//        }
+//
+//        @Override
+//        public void run() {
+//            while (true) {
+//                try {
+//                    MyQueue data = queue.poll(2, TimeUnit.SECONDS);
+//                    if (data != null) {
+//                        log.info("run VectorJudgeCoordConsumerThread 出队");
+//                        Thread.sleep(2000);
+//                        OutputFileEntity entity = data.getOutputFile();
+//                        // 坐标处理
+//                        String coord = entity.getCoord();
+//                        log.info("convert coord: {}", coord);
+//                        JSONArray arrayCoord = JSON.parseArray(coord);
+//
+//
+//                        // 转换坐标 普通坐标转换
+//                        if (TypeCode.COORD_SYSTEM_2000.equals(entity.getCoordType())) {
+//                            // 普通坐标转换
+//                            log.info("need to general transform");
+//                            if (arrayCoord.size() == 0) {
+//                                // 没有坐标参数,执行普通坐标转换(ogrinfo)
+//                                log.info("run generalCoordTransform");
+//                                entity = generalCoordTransform(entity, Command.VECTOR_TRANSFORM_GENERAL);
+//
+//                            } else {
+//                                // 有坐标参数,执行严格坐标转换(CGCS2000转wgs80)
+//                                log.info("run strictCoordTransform");
+//                                entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS80);
+//                            }
+//
+//                        } else if (TypeCode.COORD_XIAN_1980.equals(entity.getCoordType())) {
+//
+//                            // 严格坐标转换 (西安80转wgs84),需要参数
+//                            log.info("need to strict transform, CoordType: {}", entity.getCoordType());
+//                            if (arrayCoord.size() == 0) {
+//                                log.info("error: {}", MsgCode.E50009);
+//                                entity.setStatus(7);
+//                                entity.setUpdateTime(new Date());
+//                                vectorServer.save(entity);
+//                            } else {
+//                                log.info("run strictCoordTransform");
+//                                entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS84);
+//                            }
+//
+//                        } else if (TypeCode.COORD_WGS84.equals(entity.getCoordType())) {
+//                            // 不转换坐标 把文件信息移动到CoordStrictPath 这路径下
+//                            log.info("not to transform");
+//
+//                            entity.setCoordStrictPath(entity.getUploadPath());
+//                            entity.setUpdateTime(new Date());
+//                            entity.setStatus(3);
+//                            entity.setCoordType(TypeCode.COORD_WGS84);
+//                            vectorServer.save(entity);
+//                        } else {
+//                            log.info("error exeCmd");
+//                            entity.setStatus(7);
+//                            entity.setUpdateTime(new Date());
+//                            vectorServer.save(entity);
+//                        }
+//                        log.info("end VectorJudgeCoordConsumerThread ");
+//                    }
+//                } catch (Exception e) {
+//                    Thread.currentThread().interrupt();
+//                    log.error("error vector consume queue VectorJudgeCoordConsumerThread: {}", e);
+//                    throw new RuntimeException(e);
+//
+//
+//                }
+//            }
+//        }
+//    }
 
-        public VectorSliceThread(BlockingQueue<MyQueue> queue) {
-            this.queue = queue;
-        }
 
-        @Override
-        public void run() {
-
-            while (true) {
-                try {
-                    MyQueue data = queue.poll(4, TimeUnit.SECONDS);
-                    if (data != null) {
-                        log.warn("run SliceVectorThread");
-
-                        OutputFileEntity entity = data.getOutputFile();
-                        log.info("slice cmd: {}", data.getStr());
-                        Integer integer =  vectorServer.cmdSlice(data.getStr(), entity);
-                        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());
-                        vectorServer.save(entity);
-                        log.warn("end SliceVectorThread");
-                    }
-                } catch (Exception e) {
-                    Thread.currentThread().interrupt();
-                    log.error("error  consume queue vector SliceConsumerThread: {}", e);
-                    e.printStackTrace();
-                }
-            }
-        }
-    }
+//    public class VectorSliceThread implements Runnable {
+//
+//        private BlockingQueue<MyQueue> queue;
+//
+//        public VectorSliceThread(BlockingQueue<MyQueue> queue) {
+//            this.queue = queue;
+//        }
+//
+//        @Override
+//        public void run() {
+//
+//            while (true) {
+//                try {
+//                    MyQueue data = queue.poll(4, TimeUnit.SECONDS);
+//                    if (data != null) {
+//                        log.warn("run SliceVectorThread");
+//
+//                        OutputFileEntity entity = data.getOutputFile();
+//                        log.info("slice cmd: {}", data.getStr());
+//                        Integer integer =  vectorServer.cmdSlice(data.getStr(), entity);
+//                        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());
+//                        vectorServer.save(entity);
+//                        log.warn("end SliceVectorThread");
+//                    }
+//                } catch (Exception e) {
+//                    Thread.currentThread().interrupt();
+//                    log.error("error  consume queue vector SliceConsumerThread: {}", e);
+//                    e.printStackTrace();
+//                }
+//            }
+//        }
+//    }
 
     @ApiOperation("矢量数据转geojson")
     @GetMapping("command/geojson/{fileId}/")
     private R cmdGeojson(@PathVariable("fileId") Long fileId) {
         log.info("run cmdGeojson: {}", fileId);
+        VectorServer vectorServer = SpringContext.getBean(VectorServerImpl.class);
         OutputFileEntity entity = vectorServer.findById(fileId);
 
         String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
 //        // 截取目录名称
-
+        log.info("json path: {}", OUTPUT_FILE_PATH);
         String outPath = OUTPUT_FILE_PATH + "geojson" + File.separator + entity.getDirectory();
         FileUtils.createDir(outPath);
         outPath = outPath + File.separator + fileName + ".json";
@@ -445,7 +536,8 @@ public class VectorController {
         log.info("cmd: {}", cmd);
 
 
-        Integer integer = cmdServer.exeCmdInt(cmd);
+//        Integer integer = cmdServer.exeCmdInt(cmd);
+        Integer integer = vectorServer.exeCmd(cmd);
         if (integer != 0) {
             return new R(50005, MsgCode.E50005);
         }
@@ -464,6 +556,8 @@ public class VectorController {
     private R cmdSlice(@PathVariable("fileId") Long fileId, @PathVariable("layerMin") String layerMin, @PathVariable("layerMax") String layerMax) {
         log.info("run cmdSlice: {}", fileId);
 
+        VectorServer vectorServer = SpringContext.getBean(VectorServerImpl.class);
+
         if (!RegexUtils.regexInt(layerMin)) {
             return new R(50010, MsgCode.E50010);
         }
@@ -484,13 +578,13 @@ public class VectorController {
         log.info("cmd: {}", cmd);
 
 
-        entity.setSlicePath(outPath);
-        entity.setUpdateTime(new Date());
-        // 6:切片中
-        entity.setStatus(6);
-        entity.setLayerMin(Integer.valueOf(layerMin));
-        entity.setLayerMax(Integer.valueOf(layerMax));
-        entity = vectorServer.save(entity);
+//        entity.setSlicePath(outPath);
+//        entity.setUpdateTime(new Date());
+//        // 6:切片中
+//        entity.setStatus(6);
+//        entity.setLayerMin(Integer.valueOf(layerMin));
+//        entity.setLayerMax(Integer.valueOf(layerMax));
+//        entity = vectorServer.save(entity);
 
 
         // 把数据放入队列中
@@ -506,24 +600,58 @@ public class VectorController {
             e.printStackTrace();
         }
 
-//        if (offer) {
-//            entity.setSlicePath(outPath);
-//            entity.setUpdateTime(new Date());
-//            // 6:切片中
-//            entity.setStatus(6);
-//            entity.setLayerMin(Integer.valueOf(layerMin));
-//            entity.setLayerMax(Integer.valueOf(layerMax));
-//            entity = vectorServer.save(entity);
-//            return new R(200, entity);
-//        }
-//        return new R(52000, MsgCode.E52000);
-        return new R(200, entity);
+        if (offer) {
+            entity.setSlicePath(outPath);
+            entity.setUpdateTime(new Date());
+            // 6:切片中
+            entity.setStatus(6);
+            entity.setLayerMin(Integer.valueOf(layerMin));
+            entity.setLayerMax(Integer.valueOf(layerMax));
+            entity = vectorServer.save(entity);
+
+            sliceThread(vectorSliceQueue, vectorServer);
+
+            return new R(200, entity);
+        }
+        return new R(52000, MsgCode.E52000);
+    }
+
+
+    private void sliceThread(BlockingQueue<MyQueue> queue, VectorServer vectorServer){
+        try {
+            MyQueue data = queue.poll(4, TimeUnit.SECONDS);
+            if (data != null) {
+                log.warn("run SliceVectorThread");
+
+                OutputFileEntity entity = data.getOutputFile();
+                log.info("slice cmd: {}", data.getStr());
+                Integer integer =  vectorServer.cmdSlice(data.getStr(), entity);
+                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());
+                vectorServer.save(entity);
+                log.warn("end SliceVectorThread");
+            }
+        } catch (Exception e) {
+            Thread.currentThread().interrupt();
+            log.error("error  consume queue vector SliceConsumerThread: {}", e);
+            e.printStackTrace();
+        }
     }
 
 
     @ApiOperation("矢量数据进度查询")
     @GetMapping("progress/{fileId}/")
     private R getProgress(@PathVariable("fileId") Long fileId) {
+        VectorServer vectorServer = SpringContext.getBean(VectorServerImpl.class);
         OutputFileEntity entity = vectorServer.findById(fileId);
         return new R(200, entity);
     }
@@ -532,6 +660,7 @@ public class VectorController {
     @PostMapping("move/{fileId}/")
     private R moveFile(@PathVariable("fileId") Long fileId, @RequestBody ConfigJsonDto param) {
         log.info("run moveFile: {}", fileId);
+        VectorServer vectorServer = SpringContext.getBean(VectorServerImpl.class);
         return vectorServer.moveFileToServer(fileId, param);
     }
 
@@ -551,27 +680,28 @@ public class VectorController {
 //        return new R(200, entity);
 //    }
 
-    public class MoveVectorThread implements Runnable{
-
-        private Long fileId;
-        private ConfigJsonDto param;
-        public MoveVectorThread(Long fileId, ConfigJsonDto param){
-            this.fileId = fileId;
-            this.param = param;
-        }
-
-        @Override
-        public void run() {
-            log.info("run MoveVectorThread");
-            vectorServer.moveFileToServer(fileId, param);
-        }
-    }
+//    public class MoveVectorThread implements Runnable{
+//
+//        private Long fileId;
+//        private ConfigJsonDto param;
+//        public MoveVectorThread(Long fileId, ConfigJsonDto param){
+//            this.fileId = fileId;
+//            this.param = param;
+//        }
+//
+//        @Override
+//        public void run() {
+//            log.info("run MoveVectorThread");
+//            vectorServer.moveFileToServer(fileId, param);
+//        }
+//    }
 
 
     @ApiOperation("保存样式")
     @PostMapping("style/save/")
     private R saveStyle(@RequestBody StyleDto param) {
         log.info("run saveStyle");
+        VectorServer vectorServer = SpringContext.getBean(VectorServerImpl.class);
         return vectorServer.editStyle(param);
     }
 
@@ -579,6 +709,7 @@ public class VectorController {
     @GetMapping("style/get/{fileId}/")
     private R getStyle(@PathVariable("fileId") Long fileId) {
         log.info("run getStyle: {}", fileId);
+        VectorServer vectorServer = SpringContext.getBean(VectorServerImpl.class);
         return vectorServer.getStyle(fileId);
     }
 
@@ -586,7 +717,7 @@ public class VectorController {
     /**
      * 普通坐标转换
      */
-    private OutputFileEntity generalCoordTransform(OutputFileEntity entity, String cmd) {
+    private OutputFileEntity generalCoordTransform(OutputFileEntity entity, String cmd, VectorServer vectorServer) {
 
         String directory = createDirectory(entity);
         directory = directory + File.separator + entity.getFileName();
@@ -594,12 +725,12 @@ 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, vectorServer);
     }
 
 
     // 严格坐标转换
-    private OutputFileEntity strictCoordTransform(OutputFileEntity entity, String cmd) {
+    private OutputFileEntity strictCoordTransform(OutputFileEntity entity, String cmd, VectorServer vectorServer) {
 
         String directory = createDirectory(entity);
         directory = directory + File.separator + entity.getFileName();
@@ -614,7 +745,7 @@ public class VectorController {
         cmd = cmd.replace("@outputFile", directory);
         log.info("cmd: {}", cmd);
 
-        return runCmd(cmd, entity, null, directory);
+        return runCmd(cmd, entity, null, directory, vectorServer);
     }
 
     // 创建目录
@@ -625,8 +756,8 @@ public class VectorController {
     }
 
     // 执行命令,创建对象, 坐标转换使用
-    private OutputFileEntity runCmd(String cmd, OutputFileEntity entity, String generalPath, String strictPath) {
-        Integer integer = cmdServer.exeCmdInt(cmd);
+    private OutputFileEntity runCmd(String cmd, OutputFileEntity entity, String generalPath, String strictPath, VectorServer vectorServer) {
+        Integer integer = vectorServer.exeCmd(cmd);
         // 转换坐标失败, 修改状态
         if (integer != 0) {
             entity.setUpdateTime(new Date());

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

@@ -73,4 +73,6 @@ public interface VectorServer {
     FileEntity findByInputFileId(Long fileId);
 
     FileEntity saveInputFile(FileEntity fileEntity);
+
+    Integer exeCmd(String cmd);
 }

+ 57 - 0
src/main/java/com/fd/server/impl/VectorServerImpl.java

@@ -663,6 +663,63 @@ public class VectorServerImpl implements VectorServer {
         return save;
     }
 
+    @Override
+    public Integer exeCmd(String cmd) {
+        Integer isCmd = exeCmdSingle(cmd);
+        return isCmd;
+    }
+
+    private Integer exeCmdSingle(String commandStr) {
+
+        // 命令运行结果 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");
+            }
+            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("result: {}", sb.toString());
+
+            // 结束命令行
+            isCmd = ps.waitFor();
+
+            // 关闭流
+            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;
+    }
+
+
 
     /**
      * 获取经纬度平均值