wuweihao 5 éve
szülő
commit
581df7f3d0

+ 13 - 1
src/main/java/com/fd/controller/VectorController.java

@@ -29,6 +29,7 @@ import javax.annotation.PostConstruct;
 import java.io.File;
 import java.util.Arrays;
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
@@ -83,6 +84,17 @@ public class VectorController {
                          @RequestParam(value = "coord",required = false) String[] coord){
         log.info("run uploadMult");
         log.info("coord: {}", Arrays.toString(coord));
+
+        // 文件是否包含中文字符
+        if (RegexUtils.regexChinese(directoryName)) {
+            return new R(51005, MsgCode.E51005);
+        }
+
+        List<FileEntity> directory = vectorServer.findByDirectory(directoryName);
+        if (directory.size() > 0) {
+            return new R(51006, MsgCode.E51006);
+        }
+
         String strCoord = Arrays.toString(coord);
 
         R r = vectorServer.uploadDirectoryFileMul(file, directoryName, strCoord);
@@ -389,7 +401,7 @@ public class VectorController {
     @PostMapping("style/save/")
     private R saveStyle(@RequestBody StyleDto param) {
         log.info("run saveStyle");
-        return vectorServer.saveStyle(param);
+        return vectorServer.editStyle(param);
     }
 
     @ApiOperation("获取样式")

+ 1 - 1
src/main/java/com/fd/server/VectorServer.java

@@ -41,7 +41,7 @@ public interface VectorServer {
      * @param entity 样式对象
      * @return R
      */
-    R saveStyle(StyleDto entity);
+    R editStyle(StyleDto entity);
 
 
     StyleEntity saveStyle(StyleEntity entity);

+ 60 - 8
src/main/java/com/fd/server/impl/VectorServerImpl.java

@@ -348,12 +348,20 @@ public class VectorServerImpl implements VectorServer {
         return null;
     }
 
+    /**
+     * 修改样式
+     *
+     * @param entity
+     * @return
+     */
     @Override
-    public R saveStyle(StyleDto entity) {
+    public R editStyle(StyleDto entity) {
         StyleEntity styleEntity = styleRepository.findByOutputFileIdTop(entity.getOutputFileId());
         Optional<OutputFileEntity> o = outputFileRepository.findById(entity.getOutputFileId());
+
+        OutputFileEntity outputFileEntity = null;
         if (o.isPresent()) {
-            OutputFileEntity outputFileEntity = o.get();
+            outputFileEntity = o.get();
             outputFileEntity.setStatus(11);
             outputFileEntity.setUpdateTime(new Date());
             outputFileRepository.save(outputFileEntity);
@@ -361,6 +369,15 @@ public class VectorServerImpl implements VectorServer {
         styleEntity.setUpdateTime(new Date());
         styleEntity.setContent(entity.getContent());
         StyleEntity save = styleRepository.save(styleEntity);
+
+        /**
+         * 发布完成才允许这一步操作,因为第一次发布时,还没有样式在config里面
+         *
+         * 发布时数据,已经把样式提交过去config了
+         */
+
+        editStyleConfigJson(save);
+
         return new R(200, save.getOutputFileId());
     }
 
@@ -514,6 +531,7 @@ public class VectorServerImpl implements VectorServer {
 
 
     /**
+     * 发布服务
      * 修改config.json
      */
     private void writeJsonFile(ConfigJsonDto param, String lastName, OutputFileEntity entity) {
@@ -540,7 +558,7 @@ public class VectorServerImpl implements VectorServer {
         subJson.put("checked", false);
         subJson.put("show", true);
         subJson.put("url", "../data/" + lastName);
-        subJson.put("style", JSON.parse(styleEntity.getContent()));
+//        subJson.put("style", JSON.parse(styleEntity.getContent()));
         layers.add(subJson);
 
         original.put("layers", layers);
@@ -550,14 +568,13 @@ public class VectorServerImpl implements VectorServer {
             FileUtils.fileWriter(JSON.toJSONString(original), CONFIG_JSON_PATH);
 
             // 将图层信息保存到db
-
-            log.info("check test 1");
+            // 前端需要layer信息
             styleEntity.setLayer(subJson.toJSONString());
             styleEntity.setUpdateTime(new Date());
             styleEntity.setName(name);
-            log.info("check test 2");
+//            log.info("check test 2");
             styleRepository.save(styleEntity);
-            log.info("check test 3");
+//            log.info("check test 3");
 
         } catch (IOException e) {
             e.printStackTrace();
@@ -566,7 +583,7 @@ public class VectorServerImpl implements VectorServer {
 
 
     /**
-     * 删除定行的config.json 数据
+     * 删除定行的config.json 数据
      */
     private void deleteRowConfigJson(StyleEntity entity){
         String s = FileUtils.readFile(CONFIG_JSON_PATH);
@@ -597,6 +614,41 @@ public class VectorServerImpl implements VectorServer {
     }
 
 
+    /**
+     * 编辑样式,指定行的config.json 数据
+     * 添加样式
+     */
+    private void editStyleConfigJson(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())) {
+                log.warn("old sytle: {}", o.toJSONString());
+                //修改样式
+                o.put("style",JSON.parse(entity.getContent()));
+            }
+        }
+        log.warn("update sytle: {}", layers.toJSONString());
+
+        // 更新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();
+        }
+
+    }
+
+
     public static void main(String[] args) throws IOException {
 
         String inPath = "F:\\test\\clip\\aaa\\wwww";

+ 66 - 1
src/main/java/com/fd/util/JsonUtils.java

@@ -16,10 +16,72 @@ public class JsonUtils {
 
     public static void main(String[] args) {
         String path = "static/config.json";
-        deleteContent(path);
+        addJson(path);
 
     }
 
+
+    /**
+     * 修改json
+     * @param path
+     * @return
+     */
+    private static String editJson(String path){
+        String s = readFile(path);
+        JSONObject original = JSON.parseObject(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("road")) {
+                System.out.println("old sytle:" + o.toJSONString());
+                //修改样式
+                o.put("url",JSON.parse("11111"));
+
+            }
+        }
+
+        // 更新
+        original.put("layers", layers);
+        System.out.println();
+        System.out.println("update:" + layers);
+        System.out.println();
+        System.out.println("update original: " + original);
+
+        return null;
+    }
+
+
+    /**
+     * 在指定对象里,加一条记录
+     */
+    private static String addJson(String path){
+        String s = readFile(path);
+        JSONObject original = JSON.parseObject(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("road")) {
+                System.out.println("old sytle:" + o.toJSONString());
+                //加样式
+                o.put("style",JSON.parse("11111"));
+
+            }
+        }
+
+        // 更新
+        original.put("layers", layers);
+        System.out.println();
+        System.out.println("update:" + layers);
+        System.out.println();
+        System.out.println("update original: " + original);
+
+        return null;
+    }
+
     /**
      * 删除一行json内容
      * @param path
@@ -53,6 +115,9 @@ public class JsonUtils {
 
     }
 
+
+
+
     /**
      * 写json
      * @param str