|
@@ -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) {
|