Explorar o código

完成vector 模块 队列

wuweihao %!s(int64=5) %!d(string=hai) anos
pai
achega
b47fd9f9de

+ 3 - 1
src/main/java/com/fd/controller/FdModelController.java

@@ -118,6 +118,7 @@ public class FdModelController {
     public class modelSliceConsumerThread implements Runnable{
 
         private BlockingQueue<MyQueue> queue;
+        private boolean isRun = true;
         public modelSliceConsumerThread(BlockingQueue<MyQueue> queue){
             this.queue = queue;
         }
@@ -125,7 +126,7 @@ public class FdModelController {
         @Override
         public void run() {
             log.warn("run modelSliceConsumerThread");
-            while (true) {
+            while (isRun) {
                 try {
                     MyQueue data = queue.poll(2, TimeUnit.SECONDS);
                     if (data != null) {
@@ -145,6 +146,7 @@ public class FdModelController {
                     }
 //                    Thread.sleep(4000);
                 } catch (InterruptedException e) {
+                    isRun = false;
                     e.printStackTrace();
                 }
             }

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

@@ -156,6 +156,8 @@ public class RasterController {
     public class JudgeCoordConsumerThread implements Runnable{
 
         private BlockingQueue<MyQueue> queue;
+
+        private boolean isRun = true;
         public JudgeCoordConsumerThread(BlockingQueue<MyQueue> queue){
             this.queue = queue;
         }
@@ -163,7 +165,7 @@ public class RasterController {
         @Override
         public void run() {
             log.warn("run JudgeCoordConsumerThread");
-            while (true) {
+            while (isRun) {
                 try {
                     MyQueue data = queue.poll(2, TimeUnit.SECONDS);
                     if (data != null) {
@@ -187,6 +189,7 @@ public class RasterController {
 
                     }
                 } catch (InterruptedException e) {
+                    isRun = false;
                     e.printStackTrace();
                 }
             }
@@ -243,6 +246,7 @@ public class RasterController {
     public class SliceConsumerThread implements Runnable{
 
         private BlockingQueue<MyQueue> queue;
+        private boolean isRun = true;
         public SliceConsumerThread(BlockingQueue<MyQueue> queue){
             this.queue = queue;
         }
@@ -250,7 +254,7 @@ public class RasterController {
         @Override
         public void run() {
             log.warn("run SliceConsumerThread");
-            while (true) {
+            while (isRun) {
                 try {
                     MyQueue data = queue.poll(2, TimeUnit.SECONDS);
                     if (data != null) {
@@ -268,6 +272,7 @@ public class RasterController {
                         }
                     }
                 } catch (InterruptedException e) {
+                    isRun = false;
                     e.printStackTrace();
                 }
             }

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

@@ -3,6 +3,7 @@ package com.fd.controller;
 import com.fd.constant.Command;
 import com.fd.constant.MsgCode;
 import com.fd.constant.TypeCode;
+import com.fd.dto.MyQueue;
 import com.fd.dto.PageDto;
 import com.fd.entity.FileEntity;
 import com.fd.entity.OutputFileEntity;
@@ -19,8 +20,12 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.PostConstruct;
 import java.io.File;
 import java.util.Date;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
 
 /**
  * Created by Owen on 2019/11/12 0012 9:40
@@ -47,6 +52,24 @@ public class VectorController {
     @Autowired
     private CmdServer cmdServer;
 
+    BlockingQueue<MyQueue> coordQueue = new LinkedBlockingQueue<MyQueue>(5);
+
+
+    /**
+     * 初始化队列
+     *
+     * @return
+     */
+    @PostConstruct
+    private void init() {
+
+        // 判断坐标消费队列
+        new Thread(new JudgeCoordConsumerThread(coordQueue)).start();
+
+
+
+    }
+
 
 
 //    @ApiOperation("上传矢量数据,coord:坐标, directoryName:目录名称")
@@ -183,43 +206,117 @@ public class VectorController {
         cmd = cmd.replace("@inputFile", entity.getUploadPath());
         log.info("cmd: {}", cmd);
 
-        Integer isJudge = cmdServer.exeCmdJudgeCoord(cmd);
-
-//        FileEntity fileEntity = null;
-        // 转换坐标 普通坐标转换
-        if (isJudge == 1000){
-            // 普通坐标转换
-            log.info("need to general transform");
-            if (coord == null) {
-                // 没有坐标参数,执行普通坐标转换(ogrinfo)
-                entity = generalCoordTransform(entity, Command.VECTOR_TRANSFORM_GENERAL);
-
-            } else {
-                // 有坐标参数,执行严格坐标转换(CGCS2000转wgs80)
-                entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS80);
-            }
-
-        } else if (isJudge == 1001) {
-            // 严格坐标转换 (西安80转wgs84),需要参数
-            log.info("need to strict transform");
-            if (coord == null) {
-                log.info("error: {}", MsgCode.E50009);
-                return new R(50009, MsgCode.E50009);
-            }
-            entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS84);
 
-        } else if (0 == isJudge){ // 不转换坐标
-            log.info("not to transform");
-            entity = entity;
-        } else {
-            log.info("error exeCmd");
-            return new R(50005, MsgCode.E50005);
+        // 把数据放入队列中
+        MyQueue data = new MyQueue();
+        data.setOutputFile(entity);
+        data.setStr(cmd);
+        try {
+            coordQueue.offer(data, 1, TimeUnit.SECONDS);
+            log.info("入队成功");
+        } catch (InterruptedException e) {
+            e.printStackTrace();
         }
 
+//        Integer isJudge = cmdServer.exeCmdJudgeCoord(cmd);
+//
+////        FileEntity fileEntity = null;
+//        // 转换坐标 普通坐标转换
+//        if (isJudge == 1000){
+//            // 普通坐标转换
+//            log.info("need to general transform");
+//            if (coord == null) {
+//                // 没有坐标参数,执行普通坐标转换(ogrinfo)
+//                entity = generalCoordTransform(entity, Command.VECTOR_TRANSFORM_GENERAL);
+//
+//            } else {
+//                // 有坐标参数,执行严格坐标转换(CGCS2000转wgs80)
+//                entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS80);
+//            }
+//
+//        } else if (isJudge == 1001) {
+//            // 严格坐标转换 (西安80转wgs84),需要参数
+//            log.info("need to strict transform");
+//            if (coord == null) {
+//                log.info("error: {}", MsgCode.E50009);
+//                return new R(50009, MsgCode.E50009);
+//            }
+//            entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS84);
+//
+//        } else if (0 == isJudge){ // 不转换坐标
+//            log.info("not to transform");
+//            entity = entity;
+//        } else {
+//            log.info("error exeCmd");
+//            return new R(50005, MsgCode.E50005);
+//        }
+
 
         return new R(200, entity);
     }
 
+    public class JudgeCoordConsumerThread implements Runnable{
+
+        private BlockingQueue<MyQueue> queue;
+
+        private boolean isRun = true;
+        public JudgeCoordConsumerThread(BlockingQueue<MyQueue> queue){
+            this.queue = queue;
+        }
+
+        @Override
+        public void run() {
+            while (isRun) {
+                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();
+
+                        // 转换坐标 普通坐标转换
+                        if (isJudge == 1000){
+                            // 普通坐标转换
+                            log.info("need to general transform");
+                            if (entity.getCoord() == null) {
+                                // 没有坐标参数,执行普通坐标转换(ogrinfo)
+                                entity = generalCoordTransform(entity, Command.VECTOR_TRANSFORM_GENERAL);
+
+                            } else {
+                                // 有坐标参数,执行严格坐标转换(CGCS2000转wgs80)
+                                entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS80);
+                            }
+
+                        } else if (isJudge == 1001) {
+                            // 严格坐标转换 (西安80转wgs84),需要参数
+                            log.info("need to strict transform");
+                            if (entity.getCoord() == null) {
+                                log.info("error: {}", MsgCode.E50009);
+
+                                entity.setStatus(7);
+                                vectorServer.save(entity);
+                            }
+                            entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS84);
+
+                        } else if (0 == isJudge){ // 不转换坐标
+                            log.info("not to transform");
+                            entity = entity;
+                        } else {
+                            log.info("error exeCmd");
+                            entity.setStatus(7);
+                            vectorServer.save(entity);
+                        }
+                    }
+//                    Thread.sleep(4000);
+                } catch (InterruptedException e) {
+                    isRun = false;
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
     @ApiOperation("矢量数据转geojson")
     @GetMapping("command/geojson/{fileId}/")
     private R cmdGeojson(@PathVariable("fileId") Long fileId) {

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

@@ -61,6 +61,7 @@ public class OutputFileEntity extends BaseEntity implements Serializable {
      * 4:未切片
      * 5:切片完成
      * 6:切片中
+     * 7: 坐标转换失败
      */
     @Column
     private Integer status;