Browse Source

houseType工具判断,非cad类型不需要转换

dengsixing 2 năm trước cách đây
mục cha
commit
3478460a60

+ 25 - 7
4dkankan-utils-model/src/main/java/com/fdkankan/model/utils/CreateHouseJsonUtil.java

@@ -1,6 +1,8 @@
 package com.fdkankan.model.utils;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -25,14 +27,20 @@ public class CreateHouseJsonUtil {
 	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);
+		String type = readType(filePath);
+		if (!StrUtil.isEmpty(type) && "cad".equals(type)) {
+			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;
+		} else {
+			return null;
 		}
-		return house;
 	}
 
 	/**
@@ -68,6 +76,16 @@ public class CreateHouseJsonUtil {
 		return house;
 	}
 
+	private static String readType(String filePath) {
+		try {
+			JSONObject floorplanUser = FileUtils.readJson(filePath);
+			String type = floorplanUser.getString("type");
+			return type;
+		} catch (IOException var3) {
+			return null;
+		}
+	}
+
 	private static JSONArray[] createHouseTypeJsonHandler(JSONObject floor){
 
 		JSONArray[] result = new JSONArray[2];