wuweihao 5 år sedan
förälder
incheckning
f2c4d331c3

+ 22 - 22
src/main/java/com/fd/controller/FdModelController.java

@@ -126,7 +126,7 @@ public class FdModelController {
         @Override
         public void run() {
             log.warn("run modelSliceConsumerThread");
-            while (isRun) {
+            while (true) {
                 try {
                     MyQueue data = queue.poll(2, TimeUnit.SECONDS);
                     if (data != null) {
@@ -146,7 +146,7 @@ public class FdModelController {
                     }
 //                    Thread.sleep(4000);
                 } catch (InterruptedException e) {
-                    isRun = false;
+//                    isRun = false;
                     e.printStackTrace();
                 }
             }
@@ -195,24 +195,24 @@ public class FdModelController {
 //        return new R(200, data);
 //    }
 
-    public class ConsumerThread implements Runnable{
-
-        @Override
-        public void run() {
-            log.warn("run ConsumerThread");
-            while (true) {
-                try {
-                    String data = queue.poll(2, TimeUnit.SECONDS);
-                    if (data != null) {
-                        log.info("消费者,拿到队列中的数据data:" + data);
-                    }
-                    Thread.sleep(2000);
-                } catch (InterruptedException e) {
-                    e.printStackTrace();
-                }
-            }
-        }
-    }
+//    public class ConsumerThread implements Runnable{
+//
+//        @Override
+//        public void run() {
+//            log.warn("run ConsumerThread");
+//            while (true) {
+//                try {
+//                    String data = queue.poll(2, TimeUnit.SECONDS);
+//                    if (data != null) {
+//                        log.info("消费者,拿到队列中的数据data:" + data);
+//                    }
+//                    Thread.sleep(2000);
+//                } catch (InterruptedException e) {
+//                    e.printStackTrace();
+//                }
+//            }
+//        }
+//    }
 
 
     @ApiOperation("上传3D模型数据,只能上传zip文件")
@@ -265,7 +265,7 @@ public class FdModelController {
     @ApiOperation("获取3D模型数据列表")
     @PostMapping(value = "list")
     private R list(@RequestBody PageDto param) {
-        log.info("run list");
+//        log.info("run list");
         return modelServer.findByType(TypeCode.FILE_TYPE_MODEL, param);
     }
 
@@ -276,7 +276,7 @@ public class FdModelController {
     @GetMapping("delete/{fileId}/")
     private R deleteFile(@PathVariable("fileId") Long fileId) {
         log.info("run deleteFile: {}", fileId);
-        return fileServer.deleteById(fileId);
+        return modelServer.deleteById(fileId);
     }
 
 

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

@@ -96,7 +96,7 @@ public class RasterController {
     @ApiOperation("获取栅格数据列表")
     @PostMapping(value = "list")
     private R list(@RequestBody PageDto param){
-        log.info("run list");
+//        log.info("run list");
         return rasterServer.findByType(TypeCode.FILE_TYPE_RASTER, param);
     }
 
@@ -108,7 +108,7 @@ public class RasterController {
     @GetMapping("delete/{fileId}/")
     private R deleteFile(@PathVariable("fileId") Long fileId) {
         log.info("run deleteFile: {}", fileId);
-        return fileServer.deleteById(fileId);
+        return rasterServer.deleteById(fileId);
     }
 
     @ApiOperation("栅格数据判断坐标")
@@ -117,6 +117,9 @@ public class RasterController {
         log.info("run cmdJudgeCoord: {}", fileId);
 
         OutputFileEntity entity = rasterServer.findById(fileId);
+        entity.setStatus(9);
+        entity.setUpdateTime(new Date());
+        entity = rasterServer.save(entity);
 
         String cmd = Command.RASTER_JUDGE_COORD;
         cmd = cmd.replace("@inputFile", entity.getUploadPath());
@@ -133,20 +136,6 @@ public class RasterController {
             e.printStackTrace();
         }
 
-
-//        Integer isJudge = cmdServer.exeCmdRasterJudgeCoord(cmd);
-//
-//        if (1000 == isJudge){
-//            log.info("need to transform");
-//            // 严格坐标转换
-//            entity = cmdTansformGdalwarpStrict(entity);
-//        } else if (0 == isJudge){
-//            log.info("not to transform");
-//        } else {
-//            log.info("error exeCmd");
-//            return new R(50005, MsgCode.E50005);
-//        }
-
         return new R(200, entity);
     }
 
@@ -166,7 +155,7 @@ public class RasterController {
         @Override
         public void run() {
             log.warn("run JudgeCoordConsumerThread");
-            while (isRun) {
+            while (true) {
                 try {
                     MyQueue data = queue.poll(2, TimeUnit.SECONDS);
                     if (data != null) {
@@ -181,16 +170,23 @@ public class RasterController {
                             entity = cmdTansformGdalwarpStrict(entity);
                         } else if (0 == isJudge){
                             log.info("not to transform");
+                            // 4:未切片
+                            entity.setStatus(4);
+                            // 不需要转,就把上传文件路径复制到严格坐标路径上
+                            entity.setCoordStrictPath(entity.getUploadPath());
+                            entity.setUpdateTime(new Date());
+                            rasterServer.save(entity);
                         } else {
                             log.info("error exeCmd");
                             entity.setStatus(0);
+                            entity.setUpdateTime(new Date());
                             rasterServer.save(entity);
                         }
-                        OutputFileEntity obj = data.getOutputFile();
+//                        OutputFileEntity obj = data.getOutputFile();
 
                     }
                 } catch (InterruptedException e) {
-                    isRun = false;
+//                    isRun = false;
                     e.printStackTrace();
                 }
             }
@@ -268,12 +264,19 @@ public class RasterController {
                             log.info("error command exeCmdRasterSlice");
                             // 如果命令运行失败,状态改为0
                             entity.setStatus(0);
+                            entity.setUpdateTime(new Date());
                             rasterServer.save(entity);
                             return;
                         }
+                        // 切片完成,修改完成状态
+                        entity.setStatus(5);
+                        entity.setUpdateTime(new Date());
+                        entity = rasterServer.save(entity);
+                        log.info("entity: {}", entity.toString());
                     }
+
                 } catch (InterruptedException e) {
-                    isRun = false;
+//                    isRun = false;
                     e.printStackTrace();
                 }
             }
@@ -314,7 +317,7 @@ public class RasterController {
     @ApiOperation("栅格数据进度查询")
     @GetMapping("progress/{fileId}/")
     private R getProgress(@PathVariable("fileId") Long fileId) {
-        log.info("run getProgress: {}", fileId);
+//        log.info("run getProgress: {}", fileId);
         OutputFileEntity entity = rasterServer.findById(fileId);
         return new R(200, entity);
     }
@@ -366,16 +369,6 @@ public class RasterController {
 
         entity = rasterServer.save(entity);
 
-//        FileEntity fileEntity = new FileEntity();
-//        fileEntity.setFileName(entity.getFileName());
-//        fileEntity.setFileUrl(INPUT_FILE_PATH + "transform_strict" + File.separator + entity.getFileName());
-//        fileEntity.setCreateTime(new Date());
-//        fileEntity.setUpdateTime(new Date());
-//        fileEntity.setType(TypeCode.FILE_TYPE_RASTER);
-//        fileEntity.setStatus(4);
-//
-//        fileEntity = fileServer.save(fileEntity);
-
         return entity;
     }
 

+ 27 - 36
src/main/java/com/fd/controller/VectorController.java

@@ -52,7 +52,7 @@ public class VectorController {
     @Autowired
     private CmdServer cmdServer;
 
-    BlockingQueue<MyQueue> coordQueue = new LinkedBlockingQueue<MyQueue>(5);
+    BlockingQueue<MyQueue> vectorCoordQueue = new LinkedBlockingQueue<MyQueue>(5);
 
 
     /**
@@ -64,7 +64,7 @@ public class VectorController {
     private void init() {
 
         // 判断坐标消费队列
-        new Thread(new JudgeCoordConsumerThread(coordQueue)).start();
+        new Thread(new VectorJudgeCoordConsumerThread(vectorCoordQueue)).start();
 
 
 
@@ -104,6 +104,7 @@ public class VectorController {
                            @PathVariable("directoryName") String directoryName,
                            @RequestParam(value = "coord",required = false) String coord){
         log.info("run uploadVector");
+        log.info("coord: {}", coord);
         return vectorServer.uploadDirectoryFile(file, directoryName, coord);
     }
 
@@ -172,8 +173,7 @@ public class VectorController {
     @ApiOperation("获取矢量数据列表")
     @PostMapping(value = "list")
     private R list(@RequestBody PageDto param){
-        log.info("run list");
-//        return fileServer.findByType(TypeCode.FILE_TYPE_VECTOR, TypeCode.FILE_TYPE_VECTOR_SHP, param);
+//        log.info("run list");
         return vectorServer.findByType(TypeCode.FILE_TYPE_VECTOR, param);
     }
 
@@ -184,7 +184,7 @@ public class VectorController {
     @GetMapping("delete/{fileId}/")
     private R deleteFile(@PathVariable("fileId") Long fileId) {
         log.info("run deleteFile: {}", fileId);
-        return fileServer.deleteById(fileId);
+        return vectorServer.deleteById(fileId);
     }
 
 
@@ -196,7 +196,9 @@ public class VectorController {
 //        FileEntity entity = fileServer.findById(fileId);
 
         OutputFileEntity entity = vectorServer.findById(fileId);
-
+        entity.setUpdateTime(new Date());
+        entity.setStatus(9);
+        entity = vectorServer.save(entity);
 
         String coord = entity.getCoord();
         log.info("coord: {}", coord);
@@ -212,7 +214,7 @@ public class VectorController {
         data.setOutputFile(entity);
         data.setStr(cmd);
         try {
-            coordQueue.offer(data, 1, TimeUnit.SECONDS);
+            vectorCoordQueue.offer(data, 1, TimeUnit.SECONDS);
             log.info("入队成功");
         } catch (InterruptedException e) {
             e.printStackTrace();
@@ -255,22 +257,26 @@ public class VectorController {
         return new R(200, entity);
     }
 
-    public class JudgeCoordConsumerThread implements Runnable{
+    /**
+     * 坐标判断消费队列
+     */
+    public class VectorJudgeCoordConsumerThread implements Runnable{
 
         private BlockingQueue<MyQueue> queue;
 
         private boolean isRun = true;
-        public JudgeCoordConsumerThread(BlockingQueue<MyQueue> queue){
+        public VectorJudgeCoordConsumerThread(BlockingQueue<MyQueue> queue){
             this.queue = queue;
         }
 
         @Override
         public void run() {
-            while (isRun) {
+            log.info("run VectorJudgeCoordConsumerThread 出队");
+            while (true) {
                 try {
                     MyQueue data = queue.poll(2, TimeUnit.SECONDS);
                     if (data != null) {
-                        log.info("消费者,拿到队列中的数据data:" + data.toString());
+                        log.info("消费者,拿到队列中的数据data: " + data.toString());
 
                         Integer isJudge = cmdServer.exeCmdJudgeCoord(data.getStr());
                         OutputFileEntity entity = data.getOutputFile();
@@ -295,22 +301,28 @@ public class VectorController {
                                 log.info("error: {}", MsgCode.E50009);
 
                                 entity.setStatus(7);
+                                entity.setUpdateTime(new Date());
                                 vectorServer.save(entity);
+                            } else {
+
+                                entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS84);
                             }
-                            entity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS84);
 
                         } else if (0 == isJudge){ // 不转换坐标
                             log.info("not to transform");
-                            entity = entity;
+                            entity.setUpdateTime(new Date());
+                            entity.setStatus(3);
+                            vectorServer.save(entity);
                         } else {
                             log.info("error exeCmd");
                             entity.setStatus(7);
+                            entity.setUpdateTime(new Date());
                             vectorServer.save(entity);
                         }
                     }
 //                    Thread.sleep(4000);
                 } catch (InterruptedException e) {
-                    isRun = false;
+//                    isRun = false;
                     e.printStackTrace();
                 }
             }
@@ -325,9 +337,7 @@ public class VectorController {
 
         String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
 //        // 截取目录名称
-//        String fileUrl = entity.getUploadPath();
-//        String outputFile = StringUtils.substringBefore(fileUrl, ".");
-//        outputFile = outputFile + ".json";
+
         String outPath = OUTPUT_FILE_PATH + "geojson";
         FileUtils.createDir(outPath);
         outPath = outPath +File.separator + fileName + ".json";
@@ -354,15 +364,6 @@ public class VectorController {
             return new R(50005, MsgCode.E50005);
         }
 
-//        FileEntity fileEntity = new FileEntity();
-//        fileEntity.setFileName(fileName + ".json");
-//        fileEntity.setFileUrl(outputFile);
-//        fileEntity.setCreateTime(new Date());
-//        fileEntity.setUpdateTime(new Date());
-//        fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
-//        fileEntity.setStatus(4);
-
-
         entity.setGeojsonPath(outPath);
         entity.setUpdateTime(new Date());
         entity.setStatus(4);
@@ -397,16 +398,6 @@ public class VectorController {
             return new R(50005, MsgCode.E50005);
         }
 
-//        FileEntity fileEntity = new FileEntity();
-//        fileEntity.setFileName(fileName + ".mbtiles");
-//        fileEntity.setFileUrl(outputFile);
-//        fileEntity.setCreateTime(new Date());
-//        fileEntity.setUpdateTime(new Date());
-//        fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
-//        fileEntity.setStatus(5);
-//
-//        fileEntity = fileServer.save(fileEntity);
-
         entity.setSlicePath(outPath);
         entity.setUpdateTime(new Date());
         entity.setStatus(5);

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

@@ -63,6 +63,7 @@ public class OutputFileEntity extends BaseEntity implements Serializable {
      * 6:切片中
      * 7: 坐标转换失败
      * 8: 服务已发布
+     * 9:判断中
      */
     @Column
     private Integer status;

+ 2 - 2
src/main/java/com/fd/server/ModelServer.java

@@ -1,8 +1,6 @@
 package com.fd.server;
 
 import com.fd.dto.PageDto;
-import com.fd.entity.FileEntity;
-import com.fd.entity.FileSchedule;
 import com.fd.entity.OutputFileEntity;
 import com.fd.util.R;
 import org.springframework.web.multipart.MultipartFile;
@@ -24,4 +22,6 @@ public interface ModelServer {
     R findByType(String fileTypeModel, PageDto param);
 
     R moveFileToServer(Long fileId);
+
+    R deleteById(Long fileId);
 }

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

@@ -22,4 +22,6 @@ public interface RasterServer {
     OutputFileEntity findById(Long fileId);
 
     OutputFileEntity save(OutputFileEntity fileSchedule);
+
+    R deleteById(Long fileId);
 }

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

@@ -21,4 +21,6 @@ public interface VectorServer {
     OutputFileEntity save(OutputFileEntity entity);
 
     R moveFileToServer(Long fileId);
+
+    R deleteById(Long fileId);
 }

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

@@ -1,16 +1,16 @@
 package com.fd.server.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.fd.constant.MsgCode;
 import com.fd.constant.TypeCode;
 import com.fd.dto.PageDto;
 import com.fd.entity.FileEntity;
-import com.fd.entity.FileSchedule;
 import com.fd.entity.OutputFileEntity;
 import com.fd.repository.FileRepository;
-import com.fd.repository.FileScheduleRepository;
 import com.fd.repository.OutputFileRepository;
 import com.fd.server.ModelServer;
-import com.fd.server.VectorServer;
 import com.fd.util.FileUtils;
 import com.fd.util.R;
 import lombok.extern.log4j.Log4j2;
@@ -22,9 +22,7 @@ import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.io.File;
 import java.io.IOException;
-import java.util.Base64;
 import java.util.Date;
 import java.util.Optional;
 
@@ -51,6 +49,32 @@ public class ModelServerImpl implements ModelServer {
     @Autowired
     private OutputFileRepository outputFileRepository;
 
+    @Override
+    public R deleteById(Long fileId) {
+        // 删除服务器文件
+        Optional<OutputFileEntity> e = outputFileRepository.findById(fileId);
+        if (!e.isPresent()) {
+            return new R(50002, MsgCode.E50002);
+        }
+        OutputFileEntity fileEntity = e.get();
+        String fileName = fileEntity.getFileName();
+        // 文件
+        if (fileName.contains(".")) {
+//            File file = new File(fileEntity.getGeojsonPath());
+//            file.delete();
+        } else { // 目录
+//            FileUtils.delAllFile(fileEntity.getSlicePath());
+        }
+
+        // 删除数据库记录
+        outputFileRepository.deleteById(fileId);
+
+        return new R(200, MsgCode.SUCCESS);
+    }
+
+
+
+
 
     @Override
     public R moveFileToServer(Long fileId) {
@@ -60,10 +84,14 @@ public class ModelServerImpl implements ModelServer {
             return new R(50002, MsgCode.E50002);
         }
         OutputFileEntity entity = o.get();
+        // 移动文件
         FileUtils.createDir(MOVE_FILE_TO_SERVER);
         FileUtils.base64ToFileWriter(entity.getSlicePath(), MOVE_FILE_TO_SERVER);
         entity.setStatus(8);
         outputFileRepository.save(entity);
+
+        // 修改前端的config.json 文件
+
         return new R(200, MsgCode.SUCCESS);
     }
 
@@ -113,6 +141,7 @@ public class ModelServerImpl implements ModelServer {
 
         OutputFileEntity outputFile = new OutputFileEntity();
         outputFile.setUploadId(entity.getId());
+        outputFile.setUploadPath(entity.getFileUrl());
         outputFile.setFileName(entity.getFileName());
         outputFile.setStatus(1);
         outputFile.setType(TypeCode.FILE_TYPE_MODEL);
@@ -153,4 +182,37 @@ public class ModelServerImpl implements ModelServer {
     }
 
 
+    /**
+     * 修改config.json 文件
+     * @param str
+     */
+    public static void writeJsonFile(String str){
+        JSONObject original = JSON.parseObject(str);
+
+        JSONArray layers = JSON.parseArray(original.getString("layers"));
+
+        JSONObject subJson = new JSONObject();
+        subJson.put("name", "111");
+        subJson.put("text", "222");
+        subJson.put("type", "3333");
+        subJson.put("checked", "444");
+        subJson.put("show", "555");
+        subJson.put("url", "6666");
+
+        layers.add(subJson);
+
+        original.put("layers", layers);
+
+        System.out.println();
+        System.out.println(original.toString());
+
+        try {
+            FileUtils.fileWriter(JSON.toJSONString(original), "F:\\test\\123.json");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+    }
+
+
 }

+ 24 - 0
src/main/java/com/fd/server/impl/RasterServerImpl.java

@@ -55,6 +55,30 @@ public class RasterServerImpl implements RasterServer {
 
 
     @Override
+    public R deleteById(Long fileId) {
+        // 删除服务器文件
+        Optional<OutputFileEntity> e = outputFileRepository.findById(fileId);
+        if (!e.isPresent()) {
+            return new R(50002, MsgCode.E50002);
+        }
+        OutputFileEntity fileEntity = e.get();
+        String fileName = fileEntity.getFileName();
+        // 文件
+        if (fileName.contains(".")) {
+//            File file = new File(fileEntity.getGeojsonPath());
+//            file.delete();
+        } else { // 目录
+//            FileUtils.delAllFile(fileEntity.getSlicePath());
+        }
+
+        // 删除数据库记录
+        outputFileRepository.deleteById(fileId);
+
+        return new R(200, MsgCode.SUCCESS);
+    }
+
+
+    @Override
     public R moveFileToServer(Long fileId, ConfigJsonDto param) {
         Optional<OutputFileEntity> o = outputFileRepository.findById(fileId);
         if (!o.isPresent()) {

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

@@ -66,6 +66,29 @@ public class VectorServerImpl implements VectorServer {
     }
 
     @Override
+    public R deleteById(Long fileId) {
+        // 删除服务器文件
+        Optional<OutputFileEntity> e = outputFileRepository.findById(fileId);
+        if (!e.isPresent()) {
+            return new R(50002, MsgCode.E50002);
+        }
+        OutputFileEntity fileEntity = e.get();
+        String fileName = fileEntity.getFileName();
+        // 文件
+        if (fileName.contains(".")) {
+//            File file = new File(fileEntity.getGeojsonPath());
+//            file.delete();
+        } else { // 目录
+//            FileUtils.delAllFile(fileEntity.getSlicePath());
+        }
+
+        // 删除数据库记录
+        outputFileRepository.deleteById(fileId);
+
+        return new R(200, MsgCode.SUCCESS);
+    }
+
+    @Override
     public R uploadFile(MultipartFile file, String coord) {
         log.warn("run uploadFile");
         if (file.isEmpty() || file.getSize() <= 0) {

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

@@ -4,7 +4,7 @@ spring.datasource.url=jdbc:mysql://39.108.123.31:3306/gis_cesium?serverTimezone=
 spring.datasource.username=root
 spring.datasource.password=123456
 
-logging.file=/root/java/apache-tomcat-8.5.47_8082_cesium/log/cesium.log
+logging.file=/root/java/apache-tomcat_8082_cesium/log/cesium.log
 
 input.file.path=/root/gis/cesium/input/
 output.file.path=/root/gis/cesium/output/