Browse Source

修改了队列为2

wuweihao 5 năm trước cách đây
mục cha
commit
2d07cb5874

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

@@ -42,6 +42,8 @@ public class MsgCode {
 
     public static final String E50010 = "参数只接受数字";
 
+    public static final String E52000 = "入队操作失败,请稍后再试";
+
 
 
 

+ 29 - 11
src/main/java/com/fd/controller/FdModelController.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.ConfigJsonDto;
 import com.fd.dto.PageDto;
 import com.fd.dto.MyQueue;
 import com.fd.entity.FileEntity;
@@ -38,7 +39,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 @Log4j2
 @RequestMapping("api/fdModel")
 @RestController
-public class FdModelController {
+public class ModelController {
 
     @Value("${input.file.path.model}")
     private String INPUT_FILE_PATH;
@@ -55,7 +56,7 @@ public class FdModelController {
     /**
      * 队列
      */
-    private BlockingQueue<MyQueue> modelQueue = new LinkedBlockingQueue<MyQueue>(5);
+    private BlockingQueue<MyQueue> modelQueue = new LinkedBlockingQueue<MyQueue>(2);
 
 
 
@@ -84,7 +85,7 @@ public class FdModelController {
         public void run() {
             while (true) {
                 try {
-                    MyQueue data = queue.poll(4, TimeUnit.SECONDS);
+                    MyQueue data = queue.poll(2, TimeUnit.SECONDS);
                     if (data != null) {
                         log.warn("run ModelSliceConsumerThread");
                         log.info("cmd: {}", data.getStr());
@@ -107,7 +108,8 @@ public class FdModelController {
                         modelServer.save(entity);
                         log.warn("end ModelSliceConsumerThread");
                     }
-                } catch (InterruptedException e) {
+                } catch (Exception e) {
+                    Thread.currentThread().interrupt();
 
                     log.error("error  consume queue modelSliceConsumerThread: {}", e);
 
@@ -224,7 +226,6 @@ public class FdModelController {
         fileEntity = modelServer.saveInputFile(fileEntity);
 
         new Thread(new DeleteThread(fileId)).start();
-        log.info("delete vector id");
         return new R(200, MsgCode.SUCCESS);
     }
 
@@ -238,9 +239,9 @@ public class FdModelController {
 
         @Override
         public void run() {
-            log.info("run RasterDeleteThread");
+            log.info("run ModelDeleteThread");
             modelServer.deleteById(fileId);
-            log.info("end RasterDeleteThread");
+            log.info("end ModelDeleteThread: {}", fileId);
         }
     }
 
@@ -272,12 +273,14 @@ public class FdModelController {
         entity = modelServer.save(entity);
 
 
+
         // 把数据放入队列中
+        boolean offer = false;
         MyQueue data = new MyQueue();
         data.setOutputFile(entity);
         data.setStr(cmd);
         try {
-            modelQueue.offer(data, 1, TimeUnit.SECONDS);
+            offer = modelQueue.offer(data, 1, TimeUnit.SECONDS);
             log.info("model slice 入队成功");
         } catch (Exception e) {
 
@@ -285,16 +288,31 @@ public class FdModelController {
             e.printStackTrace();
         }
         log.info("end cmdModelSlice");
-        return new R(200, entity);
+
+        if (offer) {
+        // 命令产生的是文件夹
+        entity.setStatus(6);
+        entity.setUpdateTime(new Date());
+        entity.setSlicePath(outputPath);
+
+        entity = modelServer.save(entity);
+
+            return new R(200, entity);
+        }
+//
+        // 入队失败
+        return new R(52000 ,MsgCode.E52000);
+
+
 
     }
 
 
     @ApiOperation("移动数据到服务器上")
     @PostMapping("move/{fileId}/")
-    private R moveFile(@PathVariable("fileId") Long fileId) {
+    private R moveFile(@PathVariable("fileId") Long fileId, @RequestBody ConfigJsonDto param) {
         log.info("run moveFile: {}", fileId);
-        return modelServer.moveFileToServer(fileId);
+        return modelServer.moveFileToServer(fileId, param);
     }
 
 

+ 64 - 24
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>(2);
 
-    BlockingQueue<MyQueue> coordQueue = new LinkedBlockingQueue<MyQueue>(5);
+    BlockingQueue<MyQueue> coordQueue = new LinkedBlockingQueue<MyQueue>(2);
 
 
     /**
@@ -222,7 +222,7 @@ public class RasterController {
         public void run() {
             log.info("run RasterDeleteThread");
             rasterServer.deleteById(fileId);
-            log.info("end RasterDeleteThread");
+            log.info("end RasterDeleteThread: {}", fileId);
         }
     }
 
@@ -232,29 +232,43 @@ 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());
         log.info("cmd: {}", cmd);
 
+
+//        entity.setStatus(9);
+//        entity.setUpdateTime(new Date());
+//        entity = rasterServer.save(entity);
+//        log.info("coord entity: {}",entity);
+//            log.info("coord producer update time: {}", entity.getUpdateTime());
+
         // 把数据放入队列中
         MyQueue data = new MyQueue();
         data.setOutputFile(entity);
         data.setStr(cmd);
+        boolean offer = false;
         try {
-            coordQueue.offer(data, 1, TimeUnit.SECONDS);
+            offer = coordQueue.offer(data, 1, TimeUnit.SECONDS);
             log.info("入队成功");
         } catch (Exception e) {
-
             log.error("error  producer queue raster cmdJudgeCoord: {}", e);
-
             e.printStackTrace();
         }
 
-        return new R(200, entity);
+
+        if (offer) {
+            entity.setStatus(9);
+            entity.setUpdateTime(new Date());
+            entity = rasterServer.save(entity);
+            log.info("coord entity: {}",entity);
+            log.info("coord producer update time: {}", entity.getUpdateTime());
+            return new R(200, entity);
+        }
+        return new R(52000, MsgCode.E52000);
+//        return new R(200, entity);
     }
 
 
@@ -274,12 +288,20 @@ public class RasterController {
         public void run() {
             while (true) {
                 try {
-                    MyQueue data = queue.poll(2, TimeUnit.SECONDS);
+
+                    MyQueue data = queue.poll(3, TimeUnit.SECONDS);
                     if (data != null) {
                         log.warn("run JudgeCoordConsumerThread");
 
+                        // 先让它等一秒
+                        log.info("start time: {}", new Date());
+                        Thread.sleep(2000);
+                        log.info("end time: {}", new Date());
+
                         OutputFileEntity  entity = data.getOutputFile();
 
+                        log.info("CoordType: {}", entity.getCoordType());
+
                         if (TypeCode.COORD_XIAN_1980.equals(entity.getCoordType())){
                             log.info("need to transform");
                             // 严格坐标转换
@@ -291,17 +313,20 @@ public class RasterController {
                             // 不需要转,就把上传文件路径复制到严格坐标路径上
                             entity.setCoordStrictPath(entity.getUploadPath());
                             entity.setUpdateTime(new Date());
-                            rasterServer.save(entity);
+                            entity = rasterServer.save(entity);
+                            log.info("coord Consumer update time: {}", entity.getUpdateTime());
+                            log.info("JudgeCoordConsumerThread update entity: {}", entity);
                         } else {
                             log.info("error exeCmd");
                             entity.setStatus(0);
                             entity.setUpdateTime(new Date());
                             rasterServer.save(entity);
                         }
-                        log.warn("end JudgeCoordConsumerThread");
+                        log.warn("end JudgeCoordConsumerThread id: {}", entity.getId());
 
                     }
                 } catch (Exception e) {
+                    Thread.currentThread().interrupt();
 
 
                     log.error("error  consume queue raster JudgeCoordConsumerThread: {}", e);
@@ -340,30 +365,44 @@ public class RasterController {
         log.info("cmd: {}", cmd);
 
 
-        // 设个默认进度给前端显示
-        entity.setProgress(1);
-        entity.setStatus(6);
-        entity.setLayerMin(Integer.valueOf(layerMin));
-        entity.setLayerMax(Integer.valueOf(layerMax));
-        entity.setUpdateTime(new Date());
-        entity.setSlicePath(outFilePath);
-
-        entity = rasterServer.save(entity);
+//        // 设个默认进度给前端显示
+//        entity.setProgress(1);
+//        entity.setStatus(6);
+//        entity.setLayerMin(Integer.valueOf(layerMin));
+//        entity.setLayerMax(Integer.valueOf(layerMax));
+//        entity.setUpdateTime(new Date());
+//        entity.setSlicePath(outFilePath);
+//
+//        entity = rasterServer.save(entity);
 
 
         // 把数据放入队列中
         MyQueue data = new MyQueue();
         data.setOutputFile(entity);
         data.setStr(cmd);
+        boolean offer = false;
         try {
-            sliceQueue.offer(data, 1, TimeUnit.SECONDS);
+            offer = sliceQueue.offer(data, 1, TimeUnit.SECONDS);
             log.info("raster slice 入队成功");
         } catch (Exception e) {
             log.error("error  producer queue raster cmdSlice: {}", e);
             e.printStackTrace();
         }
 
-        return new R(200, entity) ;
+        if (offer) {
+        // 设个默认进度给前端显示
+        entity.setProgress(1);
+        entity.setStatus(6);
+        entity.setLayerMin(Integer.valueOf(layerMin));
+        entity.setLayerMax(Integer.valueOf(layerMax));
+        entity.setUpdateTime(new Date());
+        entity.setSlicePath(outFilePath);
+
+        entity = rasterServer.save(entity);
+
+            return new R(200, entity) ;
+        }
+        return new R(52000, MsgCode.E52000);
     }
 
 
@@ -404,6 +443,7 @@ public class RasterController {
                     }
 
                 } catch (Exception e) {
+                    Thread.currentThread().interrupt();
 
                     log.error("error  consume queue raster SliceConsumerThread: {}", e);
                     e.printStackTrace();

+ 37 - 8
src/main/java/com/fd/controller/VectorController.java

@@ -76,9 +76,9 @@ public class VectorController {
      */
     private static int COORD_NOT_WGS84 = 0;
 
-    BlockingQueue<MyQueue> vectorCoordQueue = new LinkedBlockingQueue<MyQueue>(5);
+    BlockingQueue<MyQueue> vectorCoordQueue = new LinkedBlockingQueue<MyQueue>(2);
 
-    BlockingQueue<MyQueue> vectorSliceQueue = new LinkedBlockingQueue<MyQueue>(5);
+    BlockingQueue<MyQueue> vectorSliceQueue = new LinkedBlockingQueue<MyQueue>(2);
 
 
     /**
@@ -241,7 +241,7 @@ public class VectorController {
         public void run() {
             log.info("run DeleteThread");
             vectorServer.deleteById(fileId);
-            log.info("end DeleteThread");
+            log.info("end DeleteThread: {}", fileId);
         }
     }
 
@@ -251,9 +251,7 @@ public class VectorController {
         log.info("run cmdJudgeCoord: {}", fileId);
 
         OutputFileEntity entity = vectorServer.findById(fileId);
-        entity.setUpdateTime(new Date());
-        entity.setStatus(9);
-        entity = vectorServer.save(entity);
+
 
 
         // 判断是否需要坐标转换
@@ -261,19 +259,33 @@ public class VectorController {
         cmd = cmd.replace("@inputFile", entity.getUploadPath());
         log.info("cmd: {}", cmd);
 
+        entity.setUpdateTime(new Date());
+        entity.setStatus(9);
+        entity = vectorServer.save(entity);
+
 
         // 把数据放入队列中
         MyQueue data = new MyQueue();
         data.setOutputFile(entity);
         data.setStr(cmd);
+        boolean offer = false;
         try {
-            vectorCoordQueue.offer(data, 1, TimeUnit.SECONDS);
+            offer = vectorCoordQueue.offer(data, 1, TimeUnit.SECONDS);
             log.info("入队成功");
         } catch (Exception e) {
             log.error("error vector producer queue cmdJudgeCoord: {}", e);
             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);
+
         return new R(200, entity);
     }
 
@@ -301,6 +313,7 @@ public class VectorController {
                     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();
@@ -355,6 +368,7 @@ public class VectorController {
                         log.info("end VectorJudgeCoordConsumerThread ");
                     }
                 } catch (Exception e) {
+                    Thread.currentThread().interrupt();
                     log.error("error vector consume queue VectorJudgeCoordConsumerThread: {}", e);
                     throw new RuntimeException(e);
 
@@ -400,6 +414,7 @@ public class VectorController {
                         log.warn("end SliceVectorThread");
                     }
                 } catch (Exception e) {
+                    Thread.currentThread().interrupt();
                     log.error("error  consume queue vector SliceConsumerThread: {}", e);
                     e.printStackTrace();
                 }
@@ -468,6 +483,7 @@ public class VectorController {
         cmd = cmd.replace("@layerMax", layerMax);
         log.info("cmd: {}", cmd);
 
+
         entity.setSlicePath(outPath);
         entity.setUpdateTime(new Date());
         // 6:切片中
@@ -476,18 +492,31 @@ public class VectorController {
         entity.setLayerMax(Integer.valueOf(layerMax));
         entity = vectorServer.save(entity);
 
+
         // 把数据放入队列中
         MyQueue data = new MyQueue();
         data.setOutputFile(entity);
         data.setStr(cmd);
+        boolean offer = false;
         try {
-            vectorSliceQueue.offer(data, 1, TimeUnit.SECONDS);
+            offer = vectorSliceQueue.offer(data, 1, TimeUnit.SECONDS);
             log.info("vector slice 入队成功");
         } catch (Exception e) {
             log.error("error  producer queue raster cmdSlice: {}", e);
             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);
     }
 

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

@@ -1,5 +1,6 @@
 package com.fd.server;
 
+import com.fd.dto.ConfigJsonDto;
 import com.fd.dto.PageDto;
 import com.fd.entity.FileEntity;
 import com.fd.entity.OutputFileEntity;
@@ -24,7 +25,7 @@ public interface ModelServer {
 
     R findByType(String fileTypeModel, PageDto param);
 
-    R moveFileToServer(Long fileId);
+    R moveFileToServer(Long fileId, ConfigJsonDto param);
 
     R deleteById(Long fileId);
 

+ 111 - 12
src/main/java/com/fd/server/impl/ModelServerImpl.java

@@ -5,12 +5,14 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.fd.constant.MsgCode;
 import com.fd.constant.TypeCode;
+import com.fd.dto.ConfigJsonDto;
 import com.fd.dto.PageDto;
 import com.fd.entity.FileEntity;
 import com.fd.entity.OutputFileEntity;
+import com.fd.entity.StyleEntity;
 import com.fd.repository.FileRepository;
-import com.fd.repository.IBaseRepository;
 import com.fd.repository.OutputFileRepository;
+import com.fd.repository.StyleRepository;
 import com.fd.server.ModelServer;
 import com.fd.util.FileUtils;
 import com.fd.util.R;
@@ -25,7 +27,6 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.BufferedReader;
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.Date;
@@ -63,6 +64,9 @@ public class ModelServerImpl implements ModelServer  {
     @Autowired
     private OutputFileRepository outputFileRepository;
 
+    @Autowired
+    private StyleRepository styleRepository;
+
     @Override
     public R deleteById(Long fileId) {
         // 删除服务器文件
@@ -71,6 +75,18 @@ public class ModelServerImpl implements ModelServer  {
             return new R(50002, MsgCode.E50002);
         }
         OutputFileEntity fileEntity = e.get();
+
+        // 删除配置文件config.json制定行
+        StyleEntity styleEntity = styleRepository.findByOutputFileIdTop(fileId);
+        if (styleEntity != null) {
+            deleteRowConfigJson(styleEntity);
+        }
+
+        // 删除数据库记录
+        outputFileRepository.deleteById(fileId);
+        fileRepository.deleteById(fileEntity.getUploadId());
+        styleRepository.deleteByOutputFileId(fileId);
+
         // 文件
         if (fileEntity.getUploadPath() != null) {
             FileUtils.delFolder(fileEntity.getUploadPath());
@@ -97,13 +113,43 @@ public class ModelServerImpl implements ModelServer  {
         }
 
 
-        // 删除数据库记录
-        outputFileRepository.deleteById(fileId);
-        fileRepository.deleteById(fileEntity.getUploadId());
+
 
         return new R(200, MsgCode.SUCCESS);
     }
 
+
+    /**
+     * 删除指定行的config.json 数据
+     */
+    private void deleteRowConfigJson(StyleEntity entity) {
+        String s = FileUtils.readFile(CONFIG_JSON_PATH);
+        JSONObject original = JSON.parseObject(s);
+        log.info("original: {}", s);
+
+        JSONArray layers = JSON.parseArray(original.getString("layers"));
+
+        for (int i = 0; i < layers.size(); i++) {
+            JSONObject o = (JSONObject) layers.get(i);
+            if (o.getString("name").equals(entity.getName())) {
+                // 删除对象
+                layers.remove(i);
+            }
+        }
+
+        // 更新json
+        original.put("layers", layers);
+        log.info("original update: {}", original.toJSONString());
+
+        // 更新config.json
+        try {
+            FileUtils.fileWriter(JSON.toJSONString(original), CONFIG_JSON_PATH);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+    }
+
     @Override
     public List<FileEntity> findByFileName(String fileName) {
 
@@ -185,7 +231,7 @@ public class ModelServerImpl implements ModelServer  {
 
 
     @Override
-    public R moveFileToServer(Long fileId) {
+    public R moveFileToServer(Long fileId, ConfigJsonDto param) {
         Optional<OutputFileEntity> o = outputFileRepository.findById(fileId);
         if (!o.isPresent()) {
             log.info("id:{} 不存在", fileId);
@@ -198,7 +244,7 @@ public class ModelServerImpl implements ModelServer  {
         try {
 //            org.apache.commons.io.FileUtils.copyDirectoryToDirectory(new File(entity.getSlicePath()), new File(MOVE_FILE_TO_SERVER));
             // 修改前端的config.json 文件
-            writeJsonFile();
+            writeJsonFile(param, entity);
 
             // 成功,状态
             entity.setStatus(8);
@@ -318,21 +364,74 @@ public class ModelServerImpl implements ModelServer  {
     /**
      * 修改config.json 文件
      */
-    public void writeJsonFile(){
+//    public void writeJsonFile(){
+//
+//        String s = FileUtils.readFile(CONFIG_JSON_PATH);
+//
+//        JSONObject original = JSON.parseObject(s);
+//        // 修改tileset value
+//        original.put("tileset", CONFIG_TILESET);
+//        log.info(original.toJSONString());
+//
+//        try {
+//            FileUtils.fileWriter(JSON.toJSONString(original), CONFIG_JSON_PATH);
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+//
+//    }
 
+
+    private void writeJsonFile(ConfigJsonDto param,  OutputFileEntity entity) {
         String s = FileUtils.readFile(CONFIG_JSON_PATH);
 
+        StyleEntity styleEntity = styleRepository.findByOutputFileIdTop(entity.getId());
+        if (styleEntity == null) {
+            styleEntity = new StyleEntity();
+            styleEntity.setOutputFileId(entity.getId());
+            styleEntity.setCreateTime(new Date());
+            styleEntity.setResStatus(0);
+        }
+
+
         JSONObject original = JSON.parseObject(s);
-        // 修改tileset value
-        original.put("tileset", CONFIG_TILESET);
-        log.info(original.toJSONString());
 
+        log.info("original: {}", s);
+
+        JSONArray layers = JSON.parseArray(original.getString("layers"));
+
+        JSONObject subJson = new JSONObject();
+        long cu = System.currentTimeMillis();
+        // 需要唯一
+        String name = "model_" + cu;
+        subJson.put("name", name);
+        subJson.put("text", param.getText());
+        // raster 就用这个类型
+        subJson.put("type", "tileset");
+        subJson.put("checked", false);
+        subJson.put("show", true);
+
+        String slicePath = entity.getSlicePath();
+        slicePath = slicePath.replace("/root/gis/cesium", "");
+        subJson.put("url", slicePath);
+
+        layers.add(subJson);
+
+        original.put("layers", layers);
+
+        log.info("original update: {}", original.toJSONString());
         try {
             FileUtils.fileWriter(JSON.toJSONString(original), CONFIG_JSON_PATH);
+
+            // 将图层信息保存到db
+            // 前端需要layer信息
+            styleEntity.setLayer(subJson.toJSONString());
+            styleEntity.setUpdateTime(new Date());
+            styleEntity.setName(name);
+            styleRepository.save(styleEntity);
         } catch (IOException e) {
             e.printStackTrace();
         }
-
     }
 
     public static void main(String[] args) throws IOException {

+ 66 - 6
src/main/java/com/fd/server/impl/RasterServerImpl.java

@@ -15,6 +15,7 @@ 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;
 import com.fd.server.RasterServer;
 import com.fd.util.FileUtils;
@@ -70,6 +71,9 @@ public class RasterServerImpl implements RasterServer {
     private CmdServer cmdServer;
 
 
+    @Autowired
+    private StyleRepository styleRepository;
+
     @Override
     public R deleteById(Long fileId) {
         // 删除服务器文件
@@ -79,6 +83,19 @@ public class RasterServerImpl implements RasterServer {
             return new R(50002, MsgCode.E50002);
         }
         OutputFileEntity fileEntity = e.get();
+
+        // 删除配置文件config.json制定行
+        StyleEntity styleEntity = styleRepository.findByOutputFileIdTop(fileId);
+        if (styleEntity != null) {
+            deleteRowConfigJson(styleEntity);
+        }
+
+        // 删除数据库记录
+        outputFileRepository.deleteById(fileId);
+        fileRepository.deleteById(fileEntity.getUploadId());
+        styleRepository.deleteByOutputFileId(fileId);
+
+
         // 文件
         if (fileEntity.getUploadPath() != null) {
             FileUtils.delFolder(fileEntity.getUploadPath());
@@ -105,14 +122,42 @@ public class RasterServerImpl implements RasterServer {
         }
 
 
-        // 删除数据库记录
-        outputFileRepository.deleteById(fileId);
-        fileRepository.deleteById(fileEntity.getUploadId());
 
         return new R(200, MsgCode.SUCCESS);
 
     }
 
+    /**
+     * 删除指定行的config.json 数据
+     */
+    private void deleteRowConfigJson(StyleEntity entity) {
+        String s = FileUtils.readFile(CONFIG_JSON_PATH);
+        JSONObject original = JSON.parseObject(s);
+        log.info("original: {}", s);
+
+        JSONArray layers = JSON.parseArray(original.getString("layers"));
+
+        for (int i = 0; i < layers.size(); i++) {
+            JSONObject o = (JSONObject) layers.get(i);
+            if (o.getString("name").equals(entity.getName())) {
+                // 删除对象
+                layers.remove(i);
+            }
+        }
+
+        // 更新json
+        original.put("layers", layers);
+        log.info("original update: {}", original.toJSONString());
+
+        // 更新config.json
+        try {
+            FileUtils.fileWriter(JSON.toJSONString(original), CONFIG_JSON_PATH);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+    }
+
 
 //    @Override
 //    public R moveFileToServer(Long fileId, ConfigJsonDto param) {
@@ -311,6 +356,14 @@ public class RasterServerImpl implements RasterServer {
     private void writeJsonFile(ConfigJsonDto param, String lastName, OutputFileEntity entity) {
         String s = FileUtils.readFile(CONFIG_JSON_PATH);
 
+        StyleEntity styleEntity = styleRepository.findByOutputFileIdTop(entity.getId());
+        if (styleEntity == null) {
+            styleEntity = new StyleEntity();
+            styleEntity.setOutputFileId(entity.getId());
+            styleEntity.setCreateTime(new Date());
+            styleEntity.setResStatus(0);
+        }
+
         JSONObject original = JSON.parseObject(s);
 
         log.info("original: {}", s);
@@ -320,14 +373,14 @@ public class RasterServerImpl implements RasterServer {
         JSONObject subJson = new JSONObject();
         long cu = System.currentTimeMillis();
         // 需要唯一
-        subJson.put("name", "raster_" + cu);
+        String name = "raster_" + cu;
+        subJson.put("name", name);
         subJson.put("text", param.getText());
         // raster 就用这个类型
         subJson.put("type", "imagery");
         subJson.put("checked", false);
         subJson.put("show", true);
-//        subJson.put("url", "../data/" + lastName);
-//        subJson.put("url", entity.getSlicePath());
+
         String slicePath = entity.getSlicePath();
         slicePath = slicePath.replace("/root/gis/cesium", "");
         subJson.put("url", slicePath);
@@ -341,6 +394,13 @@ public class RasterServerImpl implements RasterServer {
             FileUtils.fileWriter(JSON.toJSONString(original), CONFIG_JSON_PATH);
 
 
+            // 将图层信息保存到db
+            // 前端需要layer信息
+            styleEntity.setLayer(subJson.toJSONString());
+            styleEntity.setUpdateTime(new Date());
+            styleEntity.setName(name);
+            styleRepository.save(styleEntity);
+
         } catch (IOException e) {
             e.printStackTrace();
         }

+ 13 - 10
src/main/java/com/fd/server/impl/VectorServerImpl.java

@@ -162,6 +162,19 @@ public class VectorServerImpl implements VectorServer {
         }
         OutputFileEntity entity = e.get();
 
+
+        // 删除配置文件config.json制定行
+        StyleEntity styleEntity = styleRepository.findByOutputFileIdTop(fileId);
+        if (styleEntity != null) {
+            deleteRowConfigJson(styleEntity);
+        }
+
+
+        // 删除数据库记录
+        outputFileRepository.deleteById(fileId);
+        fileRepository.deleteById(entity.getUploadId());
+        styleRepository.deleteByOutputFileId(fileId);
+
         // 删除文件
         if (entity.getUploadPath() != null) {
             String path = entity.getUploadPath();
@@ -199,18 +212,8 @@ public class VectorServerImpl implements VectorServer {
 //        }
 
 
-        // 删除配置文件config.json制定行
-        StyleEntity styleEntity = styleRepository.findByOutputFileIdTop(fileId);
-        if (styleEntity != null) {
-            deleteRowConfigJson(styleEntity);
-        }
 
 
-        // 删除数据库记录
-        outputFileRepository.deleteById(fileId);
-        fileRepository.deleteById(entity.getUploadId());
-        styleRepository.deleteByOutputFileId(fileId);
-
 
         return new R(200, MsgCode.SUCCESS);
     }