Browse Source

生成houseType.json工具

dengsixing 3 years ago
parent
commit
919742374c

+ 195 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/util/CreateHouseJsonUtil.java

@@ -0,0 +1,195 @@
+package com.fdkankan.common.util;
+
+import java.io.IOException;
+import java.util.Map;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
+public class CreateHouseJsonUtil {
+
+	/**
+	 * 根据用户上传的户型图json文件生成houseType.json
+	 * @param filePath
+	 * @return
+	 */
+	public static JSONObject createHouseTypeJsonByUser(String filePath) {
+		JSONObject house = init();
+		JSONArray floors = house.getJSONArray("floors");
+		
+		JSONArray floorJson = readFloorJson(filePath);
+		for(int i=0;i<floorJson.size();++i) {
+			JSONObject floor = floorJson.getJSONObject(i);
+			JSONObject floorData = convert(floor,i);
+			floors.add(floorData);
+		}
+		return house;
+	}
+	
+	private static JSONObject init() {
+		JSONObject outContent = new JSONObject();
+		outContent.put("name", "houseType.json");
+		outContent.put("version", "2.1");
+		
+		outContent.put("floors", new JSONArray());
+		outContent.put("newVectorId", null);
+		outContent.put("setting", null);
+		outContent.put("boundingBox", null);
+		return outContent;
+	}
+	
+	private static JSONArray readFloorJson(String filePath) {
+		try {
+			JSONObject floorplan = FileUtil.readJson(filePath);
+			JSONArray floors = floorplan.getJSONArray("floors");
+			return floors;
+		} catch (IOException e) {
+
+			return null;
+		}
+	}
+	
+	private static JSONObject convert(JSONObject floorJson,int floor) {
+		JSONArray rooms = floorJson.getJSONArray("rooms");
+		JSONObject walls = floorJson.getJSONObject("walls");
+		JSONObject points = floorJson.getJSONObject("points");
+		JSONObject symbols = floorJson.getJSONObject("symbols");
+		
+		JSONArray _points = convertPoints(points);
+		JSONArray _walls = convertPoints(walls);
+		JSONArray _symbols = convertSymbols(symbols,floor);
+		JSONArray _rooms = convertRooms(rooms,floor);
+
+
+		JSONObject floorData = new JSONObject();
+		floorData.put("points", points);
+		floorData.put("walls", walls);
+		floorData.put("symbols", symbols);
+		floorData.put("rooms", rooms);
+		return floorData;
+	}
+	
+	private static JSONArray convertPoints(JSONObject points) {
+		
+	   JSONArray _points = new JSONArray();
+       for (Map.Entry<String, Object> entry: points.entrySet()) {
+    	   JSONObject pointValue = (JSONObject)entry.getValue();
+    	   JSONObject _pointValue = new JSONObject();
+    	   _pointValue.put("x", pointValue.getFloat("x"));
+    	   _pointValue.put("y", pointValue.getFloat("y"));
+    	   _pointValue.put("parent", pointValue.getJSONObject("parent"));
+    	   _pointValue.put("vectorId", pointValue.getString("vectorId"));
+    	   
+    	   _points.add(_pointValue);
+       }
+		
+       return _points;
+	}
+	
+	private static JSONArray convertWalls(JSONObject walls) {
+		
+	   JSONArray _walls = new JSONArray();
+       for (Map.Entry<String, Object> entry: walls.entrySet()) {
+    	   JSONObject wallValue = (JSONObject)entry.getValue();
+    	   JSONObject _wallValue = new JSONObject();
+    	   _wallValue.put("start", wallValue.getString("start"));
+    	   _wallValue.put("end", wallValue.getString("end"));
+    	   _wallValue.put("children", wallValue.getJSONArray("children"));
+    	   _wallValue.put("vectorId", wallValue.getString("vectorId"));
+    	   _wallValue.put("width", 0.2);
+    	   //leftEdgeId
+    	   //rightEdgeId
+    	   _walls.add(_wallValue);
+       }
+		
+       return _walls;
+	}
+	
+	//门/窗
+	private static JSONArray convertSymbols(JSONObject symbols,int floor) {
+	   JSONArray _symbols = new JSONArray();
+       for (Map.Entry<String, Object> entry: symbols.entrySet()) {
+    	   JSONObject symbolValue = (JSONObject)entry.getValue();
+    	   JSONObject _symbolValue = new JSONObject();
+    	   _symbolValue.put("start", symbolValue.getJSONObject("startPoint"));
+    	   _symbolValue.put("end", symbolValue.getJSONObject("endPoint"));
+    	   _symbolValue.put("parent", symbolValue.getString("parent"));
+    	   _symbolValue.put("openSide", symbolValue.getString("openSide"));
+    	   _symbolValue.put("vectorId", symbolValue.getString("vectorId"));
+    	   											_symbolValue.put("points2d", symbolValue.getJSONArray("points2d"));
+    	   _symbolValue.put("geoType", symbolValue.getString("geoType"));
+    	   _symbolValue.put("floor", floor);
+    	   
+    	   //"groundClearance": -0.7,
+		   //"height": 1.3,
+    	   
+    	   _symbols.add(_symbolValue);
+       }
+		
+       return _symbols;
+	}
+	
+	private static JSONArray convertRooms(JSONArray rooms,int floor) {
+		JSONArray _rooms = new JSONArray();
+		
+		for(int i=0;i<rooms.size();++i) {
+			JSONObject room = rooms.getJSONObject(i);
+			String name = room.getString("name");
+			JSONObject center = room.getJSONObject("center");
+			String roomId = room.getString("roomId");
+			JSONArray wallIds = room.getJSONArray("wallIds");
+			JSONArray wallPointIDs = room.getJSONArray("wallPointIDs");
+			String parent = room.getString("parent");
+			
+			JSONObject _room = new JSONObject();
+			_room.put("name", name);
+			_room.put("roomId", roomId);
+			_room.put("center", center);
+			_room.put("wallIds", wallIds);
+			_room.put("wallPointIDs", wallPointIDs);
+			_room.put("parent", parent);
+			
+			_rooms.add(_room);
+		}
+		return _rooms;
+	}
+
+	/*
+	//构件,包括:柱子,烟囱等
+	private JSONObject convertComponents(JSONObject components) {
+	   JSONArray beams = new JSONArray();
+	   JSONArray flues = new JSONArray();
+	   
+	   JSONObject result = new JSONObject();
+	   
+       for (Map.Entry<String, Object> entry: components.entrySet()) {
+    	   JSONObject componentValue = (JSONObject)entry.getValue();
+    	   JSONObject _componentValue = new JSONObject();
+    	   String geoType = componentValue.getString("geoType");
+    	   
+    		   
+    	   											_componentValue.put("center", componentValue.getJSONObject("center"));
+    	   _componentValue.put("angle", componentValue.getIntValue("angle"));  	   
+    	   _componentValue.put("vectorId", componentValue.getString("vectorId"));
+    	   _componentValue.put("points2d", componentValue.getJSONArray("points2d"));
+    	   _componentValue.put("geoType", componentValue.getString("geoType"));
+    	   _componentValue.put("sideWidth", componentValue.getFloatValue("sideWidth"));  	   
+    	   _componentValue.put("sideThickness", componentValue.getFloatValue("sideThickness"));  	   
+    	   if(geoType.endsWith("Beam")) {
+    		   beams.add(_componentValue);
+    	   }
+    	   else if(geoType.endsWith("Flue")) {
+    		   flues.add(_componentValue);
+    	   }
+       }
+		
+       result.put("beams", beams);
+       result.put("flues", flues);
+       return result;
+	}
+	*/
+	
+	//rooms
+	//tags
+}

+ 14 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/util/FileUtil.java

@@ -1,6 +1,8 @@
 package com.fdkankan.common.util;
 
 import cn.hutool.core.collection.CollUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.common.constant.ErrorCode;
 import com.fdkankan.common.exception.BusinessException;
 import java.io.*;
@@ -411,6 +413,18 @@ public class FileUtil {
 		}
 	}
 
+	public static JSONObject readJson(String filePath) throws IOException {
+		try {
+			String content = cn.hutool.core.io.FileUtil.readUtf8String(filePath);
+			JSONObject jsonObj = JSON.parseObject(content);
+			return jsonObj;
+
+		} catch (Exception e) {
+			log.error("读取json失败,filePath=" + filePath, e);
+			return null;
+		}
+	}
+
 	public static void main(String[] args) throws Exception {
 
 

+ 1 - 1
4dkankan-common-utils/src/main/java/com/fdkankan/common/util/JwtUtil.java

@@ -138,7 +138,7 @@ public class JwtUtil {
 
     public static void main(String[] args) {
         long start = System.currentTimeMillis();
-        System.out.println(getUsername("eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMzExMjMxMTE3OCIsInVzZXJOYW1lIjoiMTMxMTIzMTExNzgiLCJpYXQiOjE1NjQwNDY0OTgsImp0aSI6IjhhZWJlNzhlLTU2OGUtNDY2Yi1iY2E3LWQ4ZjI0MjgxYzJhZCJ9.1N3UNjkT39mXtymfkJQVQJxOlFM3gfC6bgfur5mVmEU"));
+        System.out.println(getUsername("eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMzUzNjUwMTEyOCIsImxvZ2luVHlwZSI6InVzZXIiLCJ1c2VyTmFtZSI6IjEzNTM2NTAxMTI4IiwiaWF0IjoxNjU4ODI4NjA2LCJqdGkiOiI4NjczYjFiMi0xYjc4LTRmMTEtOGQ5My05OWE0OWRlMGVhMjAifQ.0oYzEwTsV1iLn_cMeiqLc5upJfcYipRbIDSndSxeuK0"));
         System.out.println(System.currentTimeMillis() - start);
     }
 

+ 25 - 24
4dkankan-common-utils/src/main/java/com/fdkankan/common/util/TestUtil.java

@@ -1,5 +1,6 @@
 package com.fdkankan.common.util;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.ListUtil;
 import cn.hutool.core.img.ImgUtil;
 import cn.hutool.core.io.IoUtil;
@@ -22,6 +23,7 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import java.util.function.Consumer;
+import lombok.Data;
 
 /**
  * <p>
@@ -43,33 +45,32 @@ public class TestUtil {
     }
 
     public static void main(String[] args) throws Exception {
-        String s = FileUtils.readFile("F:\\test\\link-scene.json");
-        JSONObject jsonObject = JSON.parseObject(s);
-        JSONArray tags = jsonObject.getJSONArray("tags");
-        ExecutorService executorService = Executors.newFixedThreadPool(5);
-        List<Future> futureList = new ArrayList<>();
-        for (Object tag : tags) {
-            Callable<Boolean> call = new Callable() {
-                @Override
-                public Boolean call() throws Exception {
-                    JSONObject tag1 = (JSONObject) tag;
-                    String path = tag1.getString("path");
-                    if(StrUtil.isNotEmpty(path)){
-                        tag1.put("path", path.replace("4k", "123"));
-                    }
-                    return true;
-                }
-            };
-            futureList.add(executorService.submit(call));
-        }
-        //这里一定要加阻塞,不然会导致oss文件还没打包好,主程序已经结束返回了
-        for (Future future : futureList) {
-            future.get();
-        }
 
-        System.out.println(JSON.toJSONString(jsonObject));
+        test test = new test();
+        test1 test1 = new test1();
+        test1.setTest("test1");
+        test2 test2 = new test2();
+        test2.setTest("test2");
+        BeanUtil.copyProperties(test1, test);
+        BeanUtil.copyProperties(test2, test);
+        System.out.println(test.getTest());
 
 
     }
 
 }
+
+@Data
+class test{
+    private String test;
+}
+
+@Data
+class test1{
+    private String test;
+}
+
+@Data
+class test2{
+    private String test;
+}