|
@@ -1,118 +1,119 @@
|
|
-package com.fdkankan.fusion.common.ai;
|
|
|
|
-
|
|
|
|
-import cn.hutool.core.io.FileUtil;
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
-import com.alibaba.fastjson.TypeReference;
|
|
|
|
-
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.FileReader;
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.io.Reader;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * @author Xiewj
|
|
|
|
- * @date 2025/4/15
|
|
|
|
- */
|
|
|
|
-public class test {
|
|
|
|
- public static void main(String[] args) throws IOException {
|
|
|
|
- // 假设从某个地方获取 FloorUser 对象
|
|
|
|
- FloorUser cad = getFloorUserFromJson("C:\\Users\\Admin\\Downloads\\floorplan1.json");
|
|
|
|
-
|
|
|
|
- // 处理 cad.floors 数组,生成新的数组 res
|
|
|
|
- List<Result> res = cad.getFloors().stream().map(floor -> {
|
|
|
|
- // 初始化 childrens 数组,用于存储楼层中的子元素
|
|
|
|
- List<Child> childrens = new ArrayList<>();
|
|
|
|
-
|
|
|
|
- // 获取楼层的标签对象,如果不存在则使用空对象
|
|
|
|
- Map<String, Tag> tag = floor.getTags() != null ? floor.getTags() : new HashMap<>();
|
|
|
|
-
|
|
|
|
- // 获取楼层的家具对象,如果不存在则使用空对象
|
|
|
|
- Map<String, Furniture> fur = floor.getFurnitures() != null ? floor.getFurnitures() : new HashMap<>();
|
|
|
|
-
|
|
|
|
- // 遍历标签对象,将每个标签转换为 childrens 数组中的对象
|
|
|
|
- for (Map.Entry<String, Tag> entry : tag.entrySet()) {
|
|
|
|
- Tag item = entry.getValue();
|
|
|
|
- childrens.add(new Child(item.getBbox(), item.getTitle(),item.getGeoType()));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 遍历家具对象,将每个家具转换为 childrens 数组中的对象
|
|
|
|
- for (Map.Entry<String, Furniture> entry : fur.entrySet()) {
|
|
|
|
- Furniture item = entry.getValue();
|
|
|
|
- childrens.add(new Child(item.getBbox(), item.getTitle(), item.getGeoType()));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 返回处理后的楼层对象,包含 childrens 数组、指南针信息和楼层名称
|
|
|
|
- Result result = new Result();
|
|
|
|
- result.setChildrens(childrens);
|
|
|
|
- result.setCompass(cad.getCompass());
|
|
|
|
- result.setFloorname(floor.getName());
|
|
|
|
- return result;
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- // 打印结果
|
|
|
|
- System.out.println(JSONObject.toJSONString(res));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 从 JSON 文件中读取 FloorUser 对象
|
|
|
|
- private static FloorUser getFloorUserFromJson(String filePath) throws IOException {
|
|
|
|
- String s = FileUtil.readUtf8String(filePath);
|
|
|
|
- JSONObject jsonObject = JSON.parseObject(s);
|
|
|
|
- FloorUser floorUser = new FloorUser();
|
|
|
|
- if (jsonObject.containsKey("floors")) {
|
|
|
|
- JSONArray array = jsonObject.getJSONArray("floors");
|
|
|
|
- List<Floor> floors=new ArrayList<>();
|
|
|
|
- for (Object o : array) {
|
|
|
|
- JSONObject a = JSON.parseObject(JSONObject.toJSON(o).toString());
|
|
|
|
- Floor floor = JSONObject.toJavaObject(a, Floor.class);
|
|
|
|
- System.out.println(floor);
|
|
|
|
- floors.add(floor);
|
|
|
|
- }
|
|
|
|
- floorUser.setFloors(floors);
|
|
|
|
- }
|
|
|
|
- if (jsonObject.containsKey("compass")) {
|
|
|
|
- System.out.println(jsonObject.getString("compass"));
|
|
|
|
- floorUser.setCompass(jsonObject.getInteger("compass"));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return floorUser;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 模拟从 SDK 获取 FloorUser 对象,
|
|
|
|
- //
|
|
|
|
-// private static FloorUser getFloorUserFromSdk() {
|
|
|
|
-// FloorUser cad = new FloorUser();
|
|
|
|
-// cad.setCompass(new Compass());
|
|
|
|
|
|
+//package com.fdkankan.fusion.common.ai;
|
|
//
|
|
//
|
|
-// List<Floor> floors = new ArrayList<>();
|
|
|
|
-// Floor floor = new Floor();
|
|
|
|
-// floor.setName("Floor 1");
|
|
|
|
|
|
+//import cn.hutool.core.io.FileUtil;
|
|
|
|
+//import com.alibaba.fastjson.JSON;
|
|
|
|
+//import com.alibaba.fastjson.JSONArray;
|
|
|
|
+//import com.alibaba.fastjson.JSONObject;
|
|
//
|
|
//
|
|
-// Map<String, Tag> tags = new HashMap<>();
|
|
|
|
-// Tag tag = new Tag();
|
|
|
|
-// tag.setBbox("bbox1");
|
|
|
|
-// tag.setTitle("Title1");
|
|
|
|
-// tag.setGeoType("GeoType1");
|
|
|
|
-// tags.put("tag1", tag);
|
|
|
|
|
|
+//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;
|
|
//
|
|
//
|
|
-// Map<String, Furniture> furnitures = new HashMap<>();
|
|
|
|
-// Furniture fur = new Furniture();
|
|
|
|
-// fur.setBbox("bbox2");
|
|
|
|
-// fur.setTitle("Title2");
|
|
|
|
-// fur.setGeoType("GeoType2");
|
|
|
|
-// furnitures.put("fur1", fur);
|
|
|
|
|
|
+///**
|
|
|
|
+// * @author Xiewj
|
|
|
|
+// * @date 2025/4/15
|
|
|
|
+// */
|
|
|
|
+//public class test {
|
|
|
|
+// public static void main(String[] args) throws IOException {
|
|
|
|
+// List<Result> res = coverFloorplanJson();
|
|
//
|
|
//
|
|
-// floor.setTags(tags);
|
|
|
|
-// floor.setFurnitures(furnitures);
|
|
|
|
-// floors.add(floor);
|
|
|
|
|
|
+// // 打印结果
|
|
|
|
+// System.out.println(JSONObject.toJSONString(res));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// private static List<Result> coverFloorplanJson() throws IOException {
|
|
|
|
+// // 假设从某个地方获取 FloorUser 对象
|
|
|
|
+// FloorUser cad = getFloorUserFromJson("C:\\Users\\Admin\\Downloads\\floorplan1.json");
|
|
|
|
+//
|
|
|
|
+// // 处理 cad.floors 数组,生成新的数组 res
|
|
|
|
+// List<Result> res = cad.getFloors().stream().map(floor -> {
|
|
|
|
+// // 初始化 children 数组,用于存储楼层中的子元素
|
|
|
|
+// List<FloorPlanChild> children = new ArrayList<>();
|
|
|
|
+//
|
|
|
|
+// // 获取楼层的标签对象,如果不存在则使用空对象
|
|
|
|
+// Map<String, Tag> tag = floor.getTags() != null ? floor.getTags() : new HashMap<>();
|
|
|
|
+//
|
|
|
|
+// // 获取楼层的家具对象,如果不存在则使用空对象
|
|
|
|
+// Map<String, Furniture> fur = floor.getFurnitures() != null ? floor.getFurnitures() : new HashMap<>();
|
|
|
|
+//
|
|
|
|
+// // 遍历标签对象,将每个标签转换为 children 数组中的对象
|
|
|
|
+// for (Map.Entry<String, Tag> entry : tag.entrySet()) {
|
|
|
|
+// Tag item = entry.getValue();
|
|
|
|
+// children.add(new FloorPlanChild(item.getBbox(), item.getTitle(),item.getGeoType()));
|
|
|
|
+// }
|
|
//
|
|
//
|
|
-// cad.setFloors(floors);
|
|
|
|
-// return cad;
|
|
|
|
|
|
+// // 遍历家具对象,将每个家具转换为 children 数组中的对象
|
|
|
|
+// for (Map.Entry<String, Furniture> entry : fur.entrySet()) {
|
|
|
|
+// Furniture item = entry.getValue();
|
|
|
|
+// children.add(new FloorPlanChild(item.getBbox(), item.getTitle(), item.getGeoType()));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 返回处理后的楼层对象,包含 children 数组、指南针信息和楼层名称
|
|
|
|
+// Result result = new Result();
|
|
|
|
+// result.setChildrens(children);
|
|
|
|
+// result.setCompass(cad.getCompass());
|
|
|
|
+// result.setFloorname(floor.getName());
|
|
|
|
+// return result;
|
|
|
|
+// }).collect(Collectors.toList());
|
|
|
|
+// return res;
|
|
// }
|
|
// }
|
|
-}
|
|
|
|
|
|
+//
|
|
|
|
+// // 从 JSON 文件中读取 FloorUser 对象
|
|
|
|
+// private static FloorUser getFloorUserFromJson(String filePath) throws IOException {
|
|
|
|
+// String s = FileUtil.readUtf8String(filePath);
|
|
|
|
+// JSONObject jsonObject = JSON.parseObject(s);
|
|
|
|
+// FloorUser floorUser = new FloorUser();
|
|
|
|
+// if (jsonObject.containsKey("floors")) {
|
|
|
|
+// JSONArray array = jsonObject.getJSONArray("floors");
|
|
|
|
+// List<Floors> floors=new ArrayList<>();
|
|
|
|
+// for (Object o : array) {
|
|
|
|
+// JSONObject a = JSON.parseObject(JSONObject.toJSON(o).toString());
|
|
|
|
+// Floors floor = JSONObject.toJavaObject(a, Floors.class);
|
|
|
|
+// System.out.println(floor);
|
|
|
|
+// floors.add(floor);
|
|
|
|
+// }
|
|
|
|
+// floorUser.setFloors(floors);
|
|
|
|
+// }
|
|
|
|
+// if (jsonObject.containsKey("compass")) {
|
|
|
|
+// System.out.println(jsonObject.getString("compass"));
|
|
|
|
+// floorUser.setCompass(jsonObject.getInteger("compass"));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// return floorUser;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 模拟从 SDK 获取 FloorUser 对象,
|
|
|
|
+// //
|
|
|
|
+//// private static FloorUser getFloorUserFromSdk() {
|
|
|
|
+//// FloorUser cad = new FloorUser();
|
|
|
|
+//// cad.setCompass(new Compass());
|
|
|
|
+////
|
|
|
|
+//// List<Floors> floors = new ArrayList<>();
|
|
|
|
+//// Floors floor = new Floors();
|
|
|
|
+//// floor.setName("Floors 1");
|
|
|
|
+////
|
|
|
|
+//// Map<String, Tag> tags = new HashMap<>();
|
|
|
|
+//// Tag tag = new Tag();
|
|
|
|
+//// tag.setBbox("bbox1");
|
|
|
|
+//// tag.setTitle("Title1");
|
|
|
|
+//// tag.setGeoType("GeoType1");
|
|
|
|
+//// tags.put("tag1", tag);
|
|
|
|
+////
|
|
|
|
+//// Map<String, Furniture> furnitures = new HashMap<>();
|
|
|
|
+//// Furniture fur = new Furniture();
|
|
|
|
+//// fur.setBbox("bbox2");
|
|
|
|
+//// fur.setTitle("Title2");
|
|
|
|
+//// fur.setGeoType("GeoType2");
|
|
|
|
+//// furnitures.put("fur1", fur);
|
|
|
|
+////
|
|
|
|
+//// floor.setTags(tags);
|
|
|
|
+//// floor.setFurnitures(furnitures);
|
|
|
|
+//// floors.add(floor);
|
|
|
|
+////
|
|
|
|
+//// cad.setFloors(floors);
|
|
|
|
+//// return cad;
|
|
|
|
+//// }
|
|
|
|
+//}
|