浏览代码

更新V2floor.json文件下载处理

xiewenjie 3 年之前
父节点
当前提交
b693a0ab1f

+ 196 - 202
sxz-application/src/main/java/com.fdkk.sxz/main.java

@@ -1,211 +1,205 @@
 package com.fdkk.sxz;
 
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
 import com.fdkk.sxz.util.FileUtils;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
 public class main {
-    public static void main(String[] args) throws IOException {
-        String json = "{\n" +
-                "    \"sweepLocations\": [\n" +
-                "        {\n" +
-                "            \"subgroup\": 0,\n" +
-                "            \"pose\": {\n" +
-                "                \"rotation\": {\n" +
-                "                    \"w\": 0.95928264,\n" +
-                "                    \"x\": -0.0017092235,\n" +
-                "                    \"y\": -0.0016763769,\n" +
-                "                    \"z\": -0.28243768\n" +
-                "                },\n" +
-                "                \"translation\": {\n" +
-                "                    \"x\": 3.6112025,\n" +
-                "                    \"y\": 0.12166519,\n" +
-                "                    \"z\": 1\n" +
-                "                }\n" +
-                "            },\n" +
-                "            \"visibles3\": [\n" +
-                "                1,\n" +
-                "                2,\n" +
-                "                3\n" +
-                "            ],\n" +
-                "            \"visibles2\": [\n" +
-                "                1,\n" +
-                "                2,\n" +
-                "                3\n" +
-                "            ],\n" +
-                "            \"puck\": {\n" +
-                "                \"x\": 3.6112025,\n" +
-                "                \"y\": 0.12166519,\n" +
-                "                \"z\": -1.39718955\n" +
-                "            },\n" +
-                "            \"uuid\": \"0\",\n" +
-                "            \"visibles\": [\n" +
-                "                1,\n" +
-                "                2,\n" +
-                "                3\n" +
-                "            ],\n" +
-                "            \"group\": 1\n" +
-                "        },\n" +
-                "        {\n" +
-                "            \"subgroup\": 0,\n" +
-                "            \"pose\": {\n" +
-                "                \"rotation\": {\n" +
-                "                    \"w\": 0.97998166,\n" +
-                "                    \"x\": -0.00051350286,\n" +
-                "                    \"y\": -0.00007887775,\n" +
-                "                    \"z\": -0.19908713\n" +
-                "                },\n" +
-                "                \"translation\": {\n" +
-                "                    \"x\": 1.6813623,\n" +
-                "                    \"y\": 0.20879818,\n" +
-                "                    \"z\": 1\n" +
-                "                }\n" +
-                "            },\n" +
-                "            \"visibles3\": [\n" +
-                "                0,\n" +
-                "                2,\n" +
-                "                3\n" +
-                "            ],\n" +
-                "            \"visibles2\": [\n" +
-                "                0,\n" +
-                "                2,\n" +
-                "                3\n" +
-                "            ],\n" +
-                "            \"puck\": {\n" +
-                "                \"x\": 1.6813623,\n" +
-                "                \"y\": 0.20879818,\n" +
-                "                \"z\": -1.50\n" +
-                "            },\n" +
-                "            \"uuid\": \"2\",\n" +
-                "            \"visibles\": [\n" +
-                "                0,\n" +
-                "                2,\n" +
-                "                3\n" +
-                "            ],\n" +
-                "            \"group\": 1\n" +
-                "        },\n" +
-                "        {\n" +
-                "            \"subgroup\": 0,\n" +
-                "            \"pose\": {\n" +
-                "                \"rotation\": {\n" +
-                "                    \"w\": 0.7688388,\n" +
-                "                    \"x\": -0.0022818057,\n" +
-                "                    \"y\": 0.0016657045,\n" +
-                "                    \"z\": -0.6394364\n" +
-                "                },\n" +
-                "                \"translation\": {\n" +
-                "                    \"x\": -1.0941758,\n" +
-                "                    \"y\": -0.15828772,\n" +
-                "                    \"z\": 2\n" +
-                "                }\n" +
-                "            },\n" +
-                "            \"visibles3\": [\n" +
-                "                0,\n" +
-                "                1,\n" +
-                "                3\n" +
-                "            ],\n" +
-                "            \"visibles2\": [\n" +
-                "                0,\n" +
-                "                1,\n" +
-                "                3\n" +
-                "            ],\n" +
-                "            \"puck\": {\n" +
-                "                \"x\": -1.0941758,\n" +
-                "                \"y\": -0.15828772,\n" +
-                "                \"z\": -1.39718955\n" +
-                "            },\n" +
-                "            \"uuid\": \"4\",\n" +
-                "            \"visibles\": [\n" +
-                "                0,\n" +
-                "                1,\n" +
-                "                3\n" +
-                "            ],\n" +
-                "            \"group\": 1\n" +
-                "        },\n" +
-                "        {\n" +
-                "            \"subgroup\": 1,\n" +
-                "            \"pose\": {\n" +
-                "                \"rotation\": {\n" +
-                "                    \"w\": 0.75378096,\n" +
-                "                    \"x\": -0.00085483055,\n" +
-                "                    \"y\": 0.0011985971,\n" +
-                "                    \"z\": -0.6571241\n" +
-                "                },\n" +
-                "                \"translation\": {\n" +
-                "                    \"x\": -4.213454,\n" +
-                "                    \"y\": -0.17369196,\n" +
-                "                    \"z\": 0.07516695\n" +
-                "                }\n" +
-                "            },\n" +
-                "            \"visibles3\": [\n" +
-                "                0,\n" +
-                "                1,\n" +
-                "                2\n" +
-                "            ],\n" +
-                "            \"visibles2\": [\n" +
-                "                0,\n" +
-                "                1,\n" +
-                "                2\n" +
-                "            ],\n" +
-                "            \"puck\": {\n" +
-                "                \"x\": -4.213454,\n" +
-                "                \"y\": -0.17369196,\n" +
-                "                \"z\": -1.39718955\n" +
-                "            },\n" +
-                "            \"uuid\": \"6\",\n" +
-                "            \"visibles\": [\n" +
-                "                0,\n" +
-                "                1,\n" +
-                "                2\n" +
-                "            ],\n" +
-                "            \"group\": 1\n" +
-                "        }\n" +
-                "    ]\n" +
-                "}";
-
-        JSONObject visionJson = JSON.parseObject(json);
-        FileUtils.writeFile("D:\\test\\vision.txt", visionJson.toString());
-
+    //public static void main(String[] args) throws IOException {
+    //    String json = "{\n" +
+    //            "    \"sweepLocations\": [\n" +
+    //            "        {\n" +
+    //            "            \"subgroup\": 0,\n" +
+    //            "            \"pose\": {\n" +
+    //            "                \"rotation\": {\n" +
+    //            "                    \"w\": 0.95928264,\n" +
+    //            "                    \"x\": -0.0017092235,\n" +
+    //            "                    \"y\": -0.0016763769,\n" +
+    //            "                    \"z\": -0.28243768\n" +
+    //            "                },\n" +
+    //            "                \"translation\": {\n" +
+    //            "                    \"x\": 3.6112025,\n" +
+    //            "                    \"y\": 0.12166519,\n" +
+    //            "                    \"z\": 1\n" +
+    //            "                }\n" +
+    //            "            },\n" +
+    //            "            \"visibles3\": [\n" +
+    //            "                1,\n" +
+    //            "                2,\n" +
+    //            "                3\n" +
+    //            "            ],\n" +
+    //            "            \"visibles2\": [\n" +
+    //            "                1,\n" +
+    //            "                2,\n" +
+    //            "                3\n" +
+    //            "            ],\n" +
+    //            "            \"puck\": {\n" +
+    //            "                \"x\": 3.6112025,\n" +
+    //            "                \"y\": 0.12166519,\n" +
+    //            "                \"z\": -1.39718955\n" +
+    //            "            },\n" +
+    //            "            \"uuid\": \"0\",\n" +
+    //            "            \"visibles\": [\n" +
+    //            "                1,\n" +
+    //            "                2,\n" +
+    //            "                3\n" +
+    //            "            ],\n" +
+    //            "            \"group\": 1\n" +
+    //            "        },\n" +
+    //            "        {\n" +
+    //            "            \"subgroup\": 0,\n" +
+    //            "            \"pose\": {\n" +
+    //            "                \"rotation\": {\n" +
+    //            "                    \"w\": 0.97998166,\n" +
+    //            "                    \"x\": -0.00051350286,\n" +
+    //            "                    \"y\": -0.00007887775,\n" +
+    //            "                    \"z\": -0.19908713\n" +
+    //            "                },\n" +
+    //            "                \"translation\": {\n" +
+    //            "                    \"x\": 1.6813623,\n" +
+    //            "                    \"y\": 0.20879818,\n" +
+    //            "                    \"z\": 1\n" +
+    //            "                }\n" +
+    //            "            },\n" +
+    //            "            \"visibles3\": [\n" +
+    //            "                0,\n" +
+    //            "                2,\n" +
+    //            "                3\n" +
+    //            "            ],\n" +
+    //            "            \"visibles2\": [\n" +
+    //            "                0,\n" +
+    //            "                2,\n" +
+    //            "                3\n" +
+    //            "            ],\n" +
+    //            "            \"puck\": {\n" +
+    //            "                \"x\": 1.6813623,\n" +
+    //            "                \"y\": 0.20879818,\n" +
+    //            "                \"z\": -1.50\n" +
+    //            "            },\n" +
+    //            "            \"uuid\": \"2\",\n" +
+    //            "            \"visibles\": [\n" +
+    //            "                0,\n" +
+    //            "                2,\n" +
+    //            "                3\n" +
+    //            "            ],\n" +
+    //            "            \"group\": 1\n" +
+    //            "        },\n" +
+    //            "        {\n" +
+    //            "            \"subgroup\": 0,\n" +
+    //            "            \"pose\": {\n" +
+    //            "                \"rotation\": {\n" +
+    //            "                    \"w\": 0.7688388,\n" +
+    //            "                    \"x\": -0.0022818057,\n" +
+    //            "                    \"y\": 0.0016657045,\n" +
+    //            "                    \"z\": -0.6394364\n" +
+    //            "                },\n" +
+    //            "                \"translation\": {\n" +
+    //            "                    \"x\": -1.0941758,\n" +
+    //            "                    \"y\": -0.15828772,\n" +
+    //            "                    \"z\": 2\n" +
+    //            "                }\n" +
+    //            "            },\n" +
+    //            "            \"visibles3\": [\n" +
+    //            "                0,\n" +
+    //            "                1,\n" +
+    //            "                3\n" +
+    //            "            ],\n" +
+    //            "            \"visibles2\": [\n" +
+    //            "                0,\n" +
+    //            "                1,\n" +
+    //            "                3\n" +
+    //            "            ],\n" +
+    //            "            \"puck\": {\n" +
+    //            "                \"x\": -1.0941758,\n" +
+    //            "                \"y\": -0.15828772,\n" +
+    //            "                \"z\": -1.39718955\n" +
+    //            "            },\n" +
+    //            "            \"uuid\": \"4\",\n" +
+    //            "            \"visibles\": [\n" +
+    //            "                0,\n" +
+    //            "                1,\n" +
+    //            "                3\n" +
+    //            "            ],\n" +
+    //            "            \"group\": 1\n" +
+    //            "        },\n" +
+    //            "        {\n" +
+    //            "            \"subgroup\": 1,\n" +
+    //            "            \"pose\": {\n" +
+    //            "                \"rotation\": {\n" +
+    //            "                    \"w\": 0.75378096,\n" +
+    //            "                    \"x\": -0.00085483055,\n" +
+    //            "                    \"y\": 0.0011985971,\n" +
+    //            "                    \"z\": -0.6571241\n" +
+    //            "                },\n" +
+    //            "                \"translation\": {\n" +
+    //            "                    \"x\": -4.213454,\n" +
+    //            "                    \"y\": -0.17369196,\n" +
+    //            "                    \"z\": 0.07516695\n" +
+    //            "                }\n" +
+    //            "            },\n" +
+    //            "            \"visibles3\": [\n" +
+    //            "                0,\n" +
+    //            "                1,\n" +
+    //            "                2\n" +
+    //            "            ],\n" +
+    //            "            \"visibles2\": [\n" +
+    //            "                0,\n" +
+    //            "                1,\n" +
+    //            "                2\n" +
+    //            "            ],\n" +
+    //            "            \"puck\": {\n" +
+    //            "                \"x\": -4.213454,\n" +
+    //            "                \"y\": -0.17369196,\n" +
+    //            "                \"z\": -1.39718955\n" +
+    //            "            },\n" +
+    //            "            \"uuid\": \"6\",\n" +
+    //            "            \"visibles\": [\n" +
+    //            "                0,\n" +
+    //            "                1,\n" +
+    //            "                2\n" +
+    //            "            ],\n" +
+    //            "            \"group\": 1\n" +
+    //            "        }\n" +
+    //            "    ]\n" +
+    //            "}";
+    //
+    //    JSONObject visionJson = JSON.parseObject(json);
+    //    FileUtils.writeFile("D:\\test\\vision.txt", visionJson.toString());
+    //
+    //
+    //    JSONArray sweepArray = visionJson.getJSONArray("sweepLocations");
+    //    List<JSONObject> roamingPoint = new ArrayList();
+    //    for (int i = 0; i < sweepArray.size(); i++) {
+    //        JSONObject objectJson = sweepArray.getJSONObject(i);
+    //        JSONObject newJson = new JSONObject();
+    //        JSONObject puck = objectJson.getJSONObject("puck");
+    //        JSONObject pose = objectJson.getJSONObject("pose");
+    //        newJson.put("puck", puck);
+    //        newJson.put("pose", pose);
+    //        newJson.put("subgroup", objectJson.getInteger("subgroup"));
+    //        roamingPoint.add(newJson);
+    //    }
+    //    Map<String, List<JSONObject>> subgroup = roamingPoint.stream().collect(
+    //                    Collectors.groupingBy(x -> x.getString("subgroup"))).entrySet().stream()
+    //            .collect(Collectors.toMap(e -> "floor" + e.getKey(), Map.Entry::getValue));
+    //    Map<String, Map<String, Double>> avg = new HashMap<>();
+    //    if (subgroup.size() == 1) {
+    //        for (String s : subgroup.keySet()) {
+    //            List<JSONObject> jsonObjects = subgroup.get(s);
+    //            Map<String, Double> avgMath = new HashMap<>();
+    //            double puckTotal = jsonObjects.stream().collect(Collectors.averagingDouble(item -> item.getJSONObject("puck").getDouble("z")));
+    //            double translationTotal = jsonObjects.stream().collect(Collectors.averagingDouble(item -> item.getJSONObject("pose").getJSONObject("translation").getDouble("z")));
+    //            avgMath.put("translationTotalAvg", translationTotal);
+    //            avgMath.put("puckTotalAvg", puckTotal);
+    //            avg.put(s, avgMath);
+    //        }
+    //    }
+    //
+    //    System.out.println(JSON.toJSONString(subgroup));
+    //}
 
-        JSONArray sweepArray = visionJson.getJSONArray("sweepLocations");
-        List<JSONObject> roamingPoint = new ArrayList();
-        for (int i = 0; i < sweepArray.size(); i++) {
-            JSONObject objectJson = sweepArray.getJSONObject(i);
-            JSONObject newJson = new JSONObject();
-            JSONObject puck = objectJson.getJSONObject("puck");
-            JSONObject pose = objectJson.getJSONObject("pose");
-            newJson.put("puck", puck);
-            newJson.put("pose", pose);
-            newJson.put("subgroup", objectJson.getInteger("subgroup"));
-            roamingPoint.add(newJson);
-        }
-        Map<String, List<JSONObject>> subgroup = roamingPoint.stream().collect(
-                        Collectors.groupingBy(x -> x.getString("subgroup"))).entrySet().stream()
-                .collect(Collectors.toMap(e -> "floor" + e.getKey(), Map.Entry::getValue));
-        Map<String, Map<String, Double>> avg = new HashMap<>();
-        if (subgroup.size() == 1) {
-            for (String s : subgroup.keySet()) {
-                List<JSONObject> jsonObjects = subgroup.get(s);
-                Map<String, Double> avgMath = new HashMap<>();
-                double puckTotal = jsonObjects.stream().collect(Collectors.averagingDouble(item -> item.getJSONObject("puck").getDouble("z")));
-                double translationTotal = jsonObjects.stream().collect(Collectors.averagingDouble(item -> item.getJSONObject("pose").getJSONObject("translation").getDouble("z")));
-                avgMath.put("translationTotalAvg", translationTotal);
-                avgMath.put("puckTotalAvg", puckTotal);
-                avg.put(s, avgMath);
-            }
-        }
-
-        System.out.println(JSON.toJSONString(subgroup));
+    public static void main(String[] args) {
+        boolean b = FileUtils.downLoadFromUrl("https://4dkk.4dage.com/data/datat-sEPz6Eq/houst_f123123123loor.json?t=" + System.currentTimeMillis(),
+                "floor.json", "d://temp//");
+        System.out.println(b);
     }
-
-
 }

+ 478 - 0
sxz-base/src/main/java/com/fdkk/sxz/util/readFloorplan.java

@@ -0,0 +1,478 @@
+package com.fdkk.sxz.util;
+
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
+import java.io.*;
+import java.util.Iterator;
+import java.util.Map;
+
+
+public class readFloorplan {
+
+    private static String filePath = "F:\\2021\\����װ\\house.json";
+    private static String version = "2.0";
+    private static String outputPath = "F:\\2021\\����װ\\cad\\house2.json";
+
+    public static JSONObject inputFile() {
+        return null;
+    }
+
+    public static void main(String args[]) {
+
+        try {
+            readFloorplan m_readFloorplan = new readFloorplan();
+            JSONObject cad = m_readFloorplan.readFile(m_readFloorplan.filePath);
+            JSONArray floors = cad.getJSONArray("floors");
+            floors = m_readFloorplan.analysisCad(floors);
+            JSONObject data = new JSONObject();
+            data.put("floors", floors);
+            data.put("version", readFloorplan.version);
+            readFloorplan.writeFile(readFloorplan.outputPath, data.toString());
+            System.out.println();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public JSONObject analysisCadJsonObj(JSONArray floors) {
+
+        JSONArray jsonArray = analysisCad(floors);
+        JSONObject V2data = new JSONObject();
+        V2data.put("floors", jsonArray);
+        V2data.put("version", readFloorplan.version);
+        return V2data;
+    }
+
+    public JSONArray analysisCad(JSONArray floors) {
+
+        JSONArray floorplan = new JSONArray();
+        for (int i = 0; i < floors.size(); ++i) {
+
+            JSONObject item = new JSONObject();
+
+            JSONObject floor = floors.getJSONObject(i);
+
+            JSONArray doors = floor.getJSONArray("door");
+            JSONArray slideDoors = floor.getJSONArray("slideDoor");
+            JSONArray doubleDoors = floor.getJSONArray("doubleDoor");
+
+            JSONArray windows = floor.getJSONArray("window");
+            JSONArray bayCases = floor.getJSONArray("bayCase");
+            JSONArray frenchWindows = floor.getJSONArray("groundCase");
+
+            doors = createSymbols(doors, "door");
+            slideDoors = createSymbols(slideDoors, "slideDoor");
+            doubleDoors = createSymbols(doubleDoors, "doubleDoor");
+
+            windows = createSymbols(windows, "window");
+            bayCases = createSymbols(bayCases, "bayCase");
+            frenchWindows = createSymbols(frenchWindows, "groundCase");
+
+            JSONArray beams = floor.getJSONArray("furnColumn");
+            beams = createBeams(beams);
+
+            JSONArray flues = floor.getJSONArray("furnFlue");
+            flues = createFlues(flues);
+
+            JSONArray vertexs = floor.getJSONArray("vertex");
+            vertexs = createPoints(vertexs);
+
+            JSONArray walls = floor.getJSONArray("wall");
+            walls = createWalls(walls);
+
+            vertexs = updatePointsParent(vertexs, walls);
+
+            JSONArray symbols = new JSONArray();
+            for (int j = 0; j < doors.size(); ++j) {
+                JSONObject door = doors.getJSONObject(j);
+                symbols.add(door);
+            }
+            for (int j = 0; j < slideDoors.size(); ++j) {
+                JSONObject slideDoor = slideDoors.getJSONObject(j);
+                symbols.add(slideDoor);
+            }
+            for (int j = 0; j < doubleDoors.size(); ++j) {
+                JSONObject doubleDoor = doubleDoors.getJSONObject(j);
+                symbols.add(doubleDoor);
+            }
+            for (int j = 0; j < windows.size(); ++j) {
+                JSONObject window = windows.getJSONObject(j);
+                symbols.add(window);
+            }
+            for (int j = 0; j < bayCases.size(); ++j) {
+                JSONObject bayCase = bayCases.getJSONObject(j);
+                symbols.add(bayCase);
+            }
+            for (int j = 0; j < frenchWindows.size(); ++j) {
+                JSONObject frenchWindow = frenchWindows.getJSONObject(j);
+                symbols.add(frenchWindow);
+            }
+
+            item.put("points", vertexs);
+            item.put("walls", walls);
+            item.put("symbols", symbols);
+            item.put("flues", flues);
+            item.put("beams", beams);
+
+            floorplan.add(item);
+        }
+
+        JSONObject V2data = new JSONObject();
+        V2data.put("floors", floors);
+        V2data.put("version", readFloorplan.version);
+
+        return floorplan;
+    }
+
+    private JSONArray createPoints(JSONArray vertexs) {
+        if (vertexs == null) {
+            return null;
+        }
+
+        JSONArray result = new JSONArray();
+        for (int i = 0; i < vertexs.size(); ++i) {
+            JSONObject vertex = vertexs.getJSONObject(i);
+            JSONObject item = new JSONObject();
+            item.put("x", vertex.getDouble("x"));
+            item.put("y", vertex.getDouble("y"));
+            item.put("vectorId", "Point" + vertex.getString("id"));
+            result.add(item);
+        }
+        return result;
+    }
+
+    private JSONArray createWalls(JSONArray walls) {
+        if (walls == null) {
+            return null;
+        }
+
+        JSONArray result = new JSONArray();
+        for (int i = 0; i < walls.size(); ++i) {
+            JSONObject wall = walls.getJSONObject(i);
+
+            JSONObject item = new JSONObject();
+            item.put("start", "Point" + wall.getInteger("p1"));
+            item.put("end", "Point" + wall.getInteger("p2"));
+            item.put("vectorId", "Wall" + wall.getString("id"));
+            if (wall.getBoolean("border")) {
+                item.put("border", 1);
+            } else {
+                item.put("border", 0);
+            }
+            result.add(item);
+        }
+        return result;
+    }
+
+    private JSONArray updatePointsParent(JSONArray points, JSONArray walls) {
+        JSONObject jsonPoints = new JSONObject();
+        for (int i = 0; i < points.size(); ++i) {
+            JSONObject point = points.getJSONObject(i);
+            jsonPoints.put(point.getString("vectorId"), point);
+        }
+
+        for (int i = 0; i < walls.size(); ++i) {
+            JSONObject wall = walls.getJSONObject(i);
+
+            String startPointId = wall.getString("start");
+            String endPointId = wall.getString("end");
+            String wallId = wall.getString("vectorId");
+
+            JSONObject start = jsonPoints.getJSONObject(startPointId);
+            JSONObject end = jsonPoints.getJSONObject(endPointId);
+
+            JSONObject startParent = start.getJSONObject("parent");
+            if (!startParent.isEmpty()) {
+                startParent.put(wallId, "start");
+            } else {
+                startParent = new JSONObject();
+                startParent.put(wallId, "start");
+            }
+            start.put("parent", startParent);
+
+            JSONObject endParent = end.getJSONObject("parent");
+            if (!endParent.isEmpty()) {
+                endParent.put(wallId, "end");
+            } else {
+                endParent = new JSONObject();
+                endParent.put(wallId, "end");
+            }
+            end.put("parent", endParent);
+        }
+
+        JSONArray result = new JSONArray();
+
+        Iterator iter = jsonPoints.entrySet().iterator();
+        while (iter.hasNext()) {
+            Map.Entry entry = (Map.Entry) iter.next();
+            result.add(entry.getValue());
+        }
+        return result;
+    }
+
+    private JSONArray createSymbols(JSONArray symbols, String geoType) {
+        if (symbols == null) {
+            return null;
+        }
+
+        JSONArray result = new JSONArray();
+
+        for (int i = 0; i < symbols.size(); ++i) {
+
+            JSONObject item = new JSONObject();
+
+            JSONObject symbol = symbols.getJSONObject(i);
+
+            int parent = symbol.getInteger("line");
+
+            JSONArray pos = symbol.getJSONArray("pos");
+            JSONObject start = new JSONObject();
+            start.put("x", pos.getDouble(0));
+            start.put("y", pos.getDouble(1));
+            JSONObject end = new JSONObject();
+            end.put("x", pos.getDouble(2));
+            end.put("y", pos.getDouble(3));
+
+            JSONArray points = new JSONArray();
+
+            if (geoType.equals("door")) {
+                JSONArray ctl = symbol.getJSONArray("ctl");
+                JSONObject dirPoint = new JSONObject();
+                dirPoint.put("x", ctl.getDouble(0));
+                dirPoint.put("y", ctl.getDouble(1));
+
+                double dis1 = distance(start, dirPoint);
+                double dis2 = distance(end, dirPoint);
+                if (dis1 > dis2) {
+                    JSONObject temp = start;
+                    start = end;
+                    end = temp;
+                }
+
+                points.add(start);
+                points.add(end);
+                points.add(dirPoint);
+                boolean flag = this.isClockwise(points);
+                if (flag) {
+                    //left
+                    item.put("openSide", "LEFT");
+                } else {
+                    //right
+                    item.put("openSide", "RIGHT");
+                }
+                item.put("geoType", "SingleDoor");
+            } else if (geoType.equals("doubleDoor")) {
+                item.put("geoType", "DoubleDoor");
+            } else if (geoType.equals("slideDoor")) {
+                item.put("geoType", "SlideDoor");
+            } else if (geoType.equals("window")) {
+                item.put("geoType", "SingleWindow");
+            } else if (geoType.equals("groundCase")) {
+                item.put("geoType", "FrenchWindow");
+            } else if (geoType.equals("bayCase")) {
+                JSONArray ctl = symbol.getJSONArray("ctl");
+                points.add(start);
+                points.add(end);
+
+                JSONObject point1 = new JSONObject();
+                point1.put("x", ctl.getDouble(0));
+                point1.put("y", ctl.getDouble(1));
+
+                JSONObject point2 = new JSONObject();
+                point2.put("x", ctl.getDouble(2));
+                point2.put("y", ctl.getDouble(3));
+
+                points.add(point1);
+                points.add(point2);
+
+                boolean flag = this.isClockwise(points);
+                if (flag) {
+                    //left
+                    item.put("openSide", "LEFT");
+                } else {
+                    //right
+                    item.put("openSide", "RIGHT");
+                }
+                item.put("geoType", "BayWindow");
+            }
+
+            item.put("start", start);
+            item.put("end", end);
+            item.put("parent", parent);
+
+            result.add(item);
+        }
+
+        return result;
+    }
+
+    private JSONArray createBeams(JSONArray beams) {
+
+        if (beams == null) {
+            return null;
+        }
+
+        JSONArray result = new JSONArray();
+
+        for (int i = 0; i < beams.size(); ++i) {
+            JSONObject item = new JSONObject();
+            JSONObject beam = beams.getJSONObject(i);
+            JSONArray pos = beam.getJSONArray("pos");
+
+            JSONObject point1 = new JSONObject();
+            point1.put("x", pos.getDouble(0));
+            point1.put("y", pos.getDouble(1));
+
+            JSONObject point2 = new JSONObject();
+            point2.put("x", pos.getDouble(2));
+            point2.put("y", pos.getDouble(3));
+
+            JSONObject point3 = new JSONObject();
+            point3.put("x", pos.getDouble(4));
+            point3.put("y", pos.getDouble(5));
+
+            JSONObject point4 = new JSONObject();
+            point4.put("x", pos.getDouble(6));
+            point4.put("y", pos.getDouble(7));
+
+            JSONArray points = new JSONArray();
+            points.add(point1);
+            points.add(point2);
+            points.add(point3);
+            points.add(point4);
+            int angle = beam.getInteger("angle");
+            angle += 90;
+            if (angle > 360) {
+                angle -= 360;
+            }
+            item.put("points", points);
+            item.put("angle", angle);
+            result.add(item);
+        }
+        return result;
+    }
+
+    private JSONArray createFlues(JSONArray flues) {
+
+        if (flues == null) {
+            return null;
+        }
+
+        JSONArray result = new JSONArray();
+
+        for (int i = 0; i < flues.size(); ++i) {
+            JSONObject item = new JSONObject();
+            JSONObject flue = flues.getJSONObject(i);
+            JSONArray pos = flue.getJSONArray("pos");
+
+            JSONObject point1 = new JSONObject();
+            point1.put("x", pos.getDouble(0));
+            point1.put("y", pos.getDouble(1));
+
+            JSONObject point2 = new JSONObject();
+            point2.put("x", pos.getDouble(2));
+            point2.put("y", pos.getDouble(3));
+
+            JSONObject point3 = new JSONObject();
+            point3.put("x", pos.getDouble(4));
+            point3.put("y", pos.getDouble(5));
+
+            JSONObject point4 = new JSONObject();
+            point4.put("x", pos.getDouble(6));
+            point4.put("y", pos.getDouble(7));
+
+            JSONArray points = new JSONArray();
+            points.add(point1);
+            points.add(point2);
+            points.add(point3);
+            points.add(point4);
+            int angle = flue.getInteger("angle");
+            angle += 90;
+            if (angle > 360) {
+                angle -= 360;
+            }
+            item.put("points", points);
+            item.put("angle", angle);
+            result.add(item);
+        }
+        return result;
+    }
+
+    public JSONObject readFile(String floorPath) {
+
+        String floorplan = readFileByLines(floorPath);
+        if (floorplan == null) {
+            return null;
+        } else {
+            JSONObject input = JSONObject.parseObject(floorplan);
+            return input;
+        }
+    }
+
+    public String readFileByLines(String fileName) {
+        FileInputStream file = null;
+        BufferedReader reader = null;
+        InputStreamReader inputFileReader = null;
+        String content = "";
+        String tempString = null;
+
+        File f = new File(fileName);
+        if (!f.exists()) {
+            return null;
+        }
+
+        try {
+            file = new FileInputStream(fileName);
+            inputFileReader = new InputStreamReader(file, "utf-8");
+            reader = new BufferedReader(inputFileReader);
+            // һ�ζ���һ�У�ֱ������nullΪ�ļ�����
+            while ((tempString = reader.readLine()) != null) {
+                content += tempString;
+            }
+            reader.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+            return null;
+        } finally {
+            if (reader != null) {
+                try {
+                    reader.close();
+                } catch (IOException e1) {
+                }
+            }
+        }
+        return content;
+    }
+
+    public static void writeFile(String filePath, String str) throws IOException {
+        File fout = new File(filePath);
+        FileOutputStream fos = new FileOutputStream(fout);
+        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
+        bw.write(str);
+        bw.close();
+    }
+
+    private boolean isClockwise(JSONArray vertices) {
+        double area = 0;
+        for (int i = 0; i < vertices.size(); i++) {
+            int j = (i + 1) % vertices.size();
+            area += vertices.getJSONObject(i).getDouble("x") * vertices.getJSONObject(j).getDouble("y");
+            area -= vertices.getJSONObject(j).getDouble("x") * vertices.getJSONObject(i).getDouble("y");
+        }
+        double sub = area / 2;
+        if (sub > 0) {
+            //��ʱ��
+            return true;
+        } else {
+            //˳ʱ��
+            return false;
+        }
+    }
+
+    private double distance(JSONObject point1, JSONObject point2) {
+        double dis = Math.pow(point1.getDouble("x") - point2.getDouble("x"), 2) + Math.pow(point1.getDouble("y") - point2.getDouble("y"), 2);
+        return Math.sqrt(dis);
+    }
+}

+ 60 - 45
sxz-core/src/main/java/com/fdkk/sxz/webApi/controller/ImportDataController.java

@@ -631,26 +631,72 @@ public class ImportDataController extends BaseController {
             }
 
             Map<String, Double> map = null;
-            FileUtils.downLoadFromUrl("https://4dkk.4dage.com/data/data" + num + "/floor.json?t=" + System.currentTimeMillis(),
+            Boolean isV2 = FileUtils.downLoadFromUrl("https://4dkk.4dage.com/data/data" + num + "/houst_floor.json?t=" + System.currentTimeMillis(),
                     "floor.json", basePath);
-
+            ImportDataController.log.info("下载V2版本houst_floor,状态={}", isV2);
+            if (!isV2) {
+                boolean isV1 = FileUtils.downLoadFromUrl("https://4dkk.4dage.com/data/data" + num + "/floor.json?t=" + System.currentTimeMillis(),
+                        "floor.json", basePath);
+                ImportDataController.log.info("下载V1版本floor,状态={}", isV1);
+            }
             ConvertCadKjl cad = new ConvertCadKjl();
             String data = FileUtils.readFile(basePath + File.separator + "floor.json");
             JSONObject inputJson = null;
             JSONArray inputArray = null;
             JSONArray resultArray = new JSONArray();
-            if (StrUtil.isNotEmpty(data)) {
-                inputJson = JSON.parseObject(data);
-                if (inputJson.containsKey("floors")) {
-                    inputArray = inputJson.getJSONArray("floors");
-                    for (int i = 0, len = inputArray.size(); i < len; i++) {
-                        cad = new ConvertCadKjl();
-                        cad.init(inputArray.getJSONObject(i));
+            if (isV2) {
+                readFloorplan m_readFloorplan = new readFloorplan();
+                JSONObject V2cad = m_readFloorplan.readFile(basePath + File.separator + "floor.json");
+                JSONArray floors = V2cad.getJSONArray("floors");
+                JSONObject V2data = m_readFloorplan.analysisCadJsonObj(floors);
+                resultJson.put("floors", V2data);
+            } else {
+                if (StrUtil.isNotEmpty(data)) {
+                    inputJson = JSON.parseObject(data);
+                    if (inputJson.containsKey("floors")) {
+                        inputArray = inputJson.getJSONArray("floors");
+                        for (int i = 0, len = inputArray.size(); i < len; i++) {
+                            cad = new ConvertCadKjl();
+                            cad.init(inputArray.getJSONObject(i));
+                            cad.input = cad.preHandle(cad.input);
+                            JSONArray beams = cad.getBeams();
+                            JSONArray walls = ObjectUtil.isNotNull(cad.getWalls()) ? cad.getWalls() : new JSONArray();
+                            //判断是否需要重复出去墙
+                            AtomicBoolean removeAgain = new AtomicBoolean(false);
+                            walls = cad.removeRepeat(walls);
+
+                            JSONArray rooms = cad.getRooms();
+                            JSONArray flues = cad.getFlues();
+                            JSONArray holes = cad.getHoles();
+
+                            cad.output.put("holes", holes);
+                            cad.output.put("flues", flues);
+                            cad.output.put("beams", beams);
+                            cad.output.put("rooms", rooms);
+                            cad.output.put("walls", walls);
+
+                            map = ConvertCadKjl.getMaxOrMinValue(inputArray.getJSONObject(i));
+
+                            if (map != null) {
+                                JSONObject scene = new JSONObject();
+                                scene.put("bottom", map.get("translationAverage"));
+                                scene.put("top", map.get("puckAverage") == null ? null : map.get("puckAverage"));
+                                cad.output.put("scene", scene);
+                            }
+
+                            cad.output.put("version", floorPublishVer);
+                            resultArray.add(cad.output);
+                        }
+                        resultJson.put("floors", resultArray);
+
+                    } else {
+                        cad.init(inputJson);
                         cad.input = cad.preHandle(cad.input);
                         JSONArray beams = cad.getBeams();
-                        JSONArray walls = ObjectUtil.isNotNull(cad.getWalls()) ? cad.getWalls() : new JSONArray();
+                        JSONArray walls = cad.getWalls();
                         //判断是否需要重复出去墙
                         AtomicBoolean removeAgain = new AtomicBoolean(false);
+                        //去除重复的墙
                         walls = cad.removeRepeat(walls);
 
                         JSONArray rooms = cad.getRooms();
@@ -663,7 +709,7 @@ public class ImportDataController extends BaseController {
                         cad.output.put("rooms", rooms);
                         cad.output.put("walls", walls);
 
-                        map = ConvertCadKjl.getMaxOrMinValue(inputArray.getJSONObject(i));
+                        map = ConvertCadKjl.getMaxOrMinValue(inputJson);
 
                         if (map != null) {
                             JSONObject scene = new JSONObject();
@@ -673,44 +719,13 @@ public class ImportDataController extends BaseController {
                         }
 
                         cad.output.put("version", floorPublishVer);
-                        resultArray.add(cad.output);
+                        resultJson = cad.output;
                     }
-                    resultJson.put("floors", resultArray);
-
-                } else {
                     cad.init(inputJson);
-                    cad.input = cad.preHandle(cad.input);
-                    JSONArray beams = cad.getBeams();
-                    JSONArray walls = cad.getWalls();
-                    //判断是否需要重复出去墙
-                    AtomicBoolean removeAgain = new AtomicBoolean(false);
-                    //去除重复的墙
-                    walls = cad.removeRepeat(walls);
-
-                    JSONArray rooms = cad.getRooms();
-                    JSONArray flues = cad.getFlues();
-                    JSONArray holes = cad.getHoles();
-
-                    cad.output.put("holes", holes);
-                    cad.output.put("flues", flues);
-                    cad.output.put("beams", beams);
-                    cad.output.put("rooms", rooms);
-                    cad.output.put("walls", walls);
-
-                    map = ConvertCadKjl.getMaxOrMinValue(inputJson);
-
-                    if (map != null) {
-                        JSONObject scene = new JSONObject();
-                        scene.put("bottom", map.get("translationAverage"));
-                        scene.put("top", map.get("puckAverage") == null ? null : map.get("puckAverage"));
-                        cad.output.put("scene", scene);
-                    }
-
-                    cad.output.put("version", floorPublishVer);
-                    resultJson = cad.output;
                 }
-                cad.init(inputJson);
             }
+
+
             resultJson.put("entry", entryJson);
             cad.writeBinary(resultJson.toString().getBytes(), basePath + File.separator + "kjl.json");