|
@@ -2,12 +2,14 @@ package com.fdkankan.scene.common.house;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
public class JsonToHouseUtil {
|
|
@@ -159,6 +161,37 @@ public class JsonToHouseUtil {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+ public static Integer floorPlanToHouseJson(String srcPath){
|
|
|
+ HouseJson houseJson = new HouseJson();
|
|
|
+ List<Floor> floorList = new ArrayList<>();
|
|
|
+ houseJson.setFloors(floorList);
|
|
|
+ try {
|
|
|
+ String msg = FileWriterUtil.readFile(srcPath);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(msg);
|
|
|
+ JSONArray floors = jsonObject.getJSONArray("floors");
|
|
|
+ for (Object o : floors) {
|
|
|
+ JSONObject floor = (JSONObject) o;
|
|
|
+ JSONObject wallObject = floor.getJSONObject("walls");
|
|
|
+ List<Object> walls = wallObject.values().stream().collect(Collectors.toList());
|
|
|
+ floor.put("walls",walls);
|
|
|
+
|
|
|
+ JSONObject pointsObject = floor.getJSONObject("points");
|
|
|
+ List<Object> points = pointsObject.values().stream().collect(Collectors.toList());
|
|
|
+ floor.put("points",points);
|
|
|
+ }
|
|
|
+
|
|
|
+ int i = checkPointAndWall(floorList);
|
|
|
+ if(i !=0){
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+ String tag = srcPath.replace("houst_floor.json","");
|
|
|
+ FileWriterUtil.writerJson(tag,"house.json",JSONObject.toJSONString(houseJson));
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return -3;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
private static void setComponents(JSONObject floor, List<Component> componentList,String key, String geoType) {
|
|
@@ -325,6 +358,23 @@ public class JsonToHouseUtil {
|
|
|
return bo;
|
|
|
}
|
|
|
|
|
|
+ public static Integer ToHouseJsonV4(String src) {
|
|
|
+ File file = new File(src);
|
|
|
+ Integer bo = -4;
|
|
|
+ if(file.exists() && file.isDirectory()){
|
|
|
+ File[] files = file.listFiles();
|
|
|
+ List<String> fileNameList = new ArrayList<>();
|
|
|
+ for (File file1 : files) {
|
|
|
+ fileNameList.add(file1.getName());
|
|
|
+ }
|
|
|
+ if(fileNameList.contains("houst_floor.json")){
|
|
|
+ log.info("JsonToHouseUtil:houstFloorToHouseJson--->{}",src +File.separator + "floorplan.json");
|
|
|
+ bo = JsonToHouseUtil.floorPlanToHouseJson(src +File.separator + "floorplan.json");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return bo;
|
|
|
+ }
|
|
|
+
|
|
|
public static int checkPointAndWall(List<Floor> floors){
|
|
|
if(floors.size() <=0){
|
|
|
return -1;
|