Browse Source

配置文件使用压缩,信息点识别更新

menglu 3 năm trước cách đây
mục cha
commit
8dd0be4a8c

+ 4 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/Constant.java

@@ -38,6 +38,7 @@ public class Constant {
 	public static String rwd_url;
 	public static boolean rwd_compress = false;
 	public static String zkt_monitor_url;
+	public static boolean zkt_monitor_compress;
 	public static String zkt_control_url;
 	public static String config;
 	public static String physical_world;
@@ -123,6 +124,9 @@ public class Constant {
 					element = (Element) iter.next();
 					zkt_monitor_url = element.attribute("url").getValue();
 					zkt_monitor_url = StrUtil.removeSuffix(zkt_monitor_url, "/");
+					if (element.attribute("compress") != null) {
+						zkt_monitor_compress = element.attribute("compress").getValue().equalsIgnoreCase("true");
+					}
 				}
 				iter = document.selectNodes("/root/zkt_control").iterator();
 				if (iter.hasNext()) {

+ 53 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/GZIPCompressUtil.java

@@ -15,6 +15,52 @@ import cn.hutool.core.codec.Base64;
 
 @Slf4j
 public class GZIPCompressUtil {
+	public static String gzipBase64(String str) throws Exception {
+		if (str == null || str.length() == 0) {
+			return "";
+		}
+
+		byte[] tArray;
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		GZIPOutputStream gzip = new GZIPOutputStream(out);
+		try {
+			gzip.write(str.getBytes("UTF-8"));
+			gzip.flush();
+		} finally {
+			gzip.close();
+		}
+
+		tArray = out.toByteArray();
+		out.close();
+
+		return Base64.encode(tArray);
+	}
+
+	public static String ungzipBase64(String str) throws Exception {
+		if (str == null || str.length() == 0) {
+			return "";
+		}
+
+		byte[] t = Base64.decode(str);
+
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		ByteArrayInputStream in = new ByteArrayInputStream(t);
+		GZIPInputStream gunzip = new GZIPInputStream(in);
+		try {
+			byte[] buffer = new byte[256];
+			int n;
+			while ((n = gunzip.read(buffer)) >= 0) {
+				out.write(buffer, 0, n);
+			}
+		} finally {
+			gunzip.close();
+		}
+		in.close();
+		out.close();
+
+		return out.toString("UTF-8");
+	}
+
 	public static String zipBase64(String text) {
 		try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
 			try (DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(out)) {
@@ -83,4 +129,11 @@ public class GZIPCompressUtil {
 		}
 		return out.toByteArray();
 	}
+
+	public static void main(String[] args) throws Exception {
+		String abc = "abc";
+		System.out.println(gzipBase64(abc));
+		String compressString = "H4sIAAAAAAAEAEtMSgYAwkEkNQMAAAA=";
+		System.out.println(unzipBase64(compressString));
+	}
 }

+ 24 - 2
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RWDDownloadUtil.java

@@ -41,7 +41,11 @@ public class RWDDownloadUtil {
 			param.put("appId", "0");
 			param.put("groupCode", groupCode);
 			param.put("projectId", projectId);
-			param.put("dictType", Constant.sdk_version);
+			if (Constant.zkt_monitor_compress) {
+				param.put("dictType", Constant.sdk_version + "-compress");
+			} else {
+				param.put("dictType", Constant.sdk_version);
+			}
 			param.put("code", "1");
 			String post_result = HttpClientUtil.instance("zkt_monitor").post(Constant.zkt_monitor_url + "/generalDictionary/list",
 					param.toJSONString());
@@ -53,7 +57,16 @@ public class RWDDownloadUtil {
 		}
 		if (classArray != null && classArray.size() == 1) {
 			JSONObject item = (JSONObject) classArray.get(0);
-			FileUtil.Save(path, FastJsonUtil.toFormatString(item.get("itemData")), LogOfDownload.downloadList);
+			JSONObject itemData = item.getJSONObject("itemData");
+			JSONObject configJSON;
+			if (Constant.zkt_monitor_compress) {
+				String compressString = itemData.getString("compressString");
+				String text = GZIPCompressUtil.ungzipBase64(compressString);
+				configJSON = JSON.parseObject(text);
+			} else {
+				configJSON = itemData;
+			}
+			FileUtil.Save(path, FastJsonUtil.toFormatString(configJSON), LogOfDownload.downloadList);
 		}
 	}
 
@@ -99,6 +112,15 @@ public class RWDDownloadUtil {
 				{
 					infoCode = infoCode.substring(0, 1).toLowerCase() + infoCode.substring(1);
 				}
+				if (feedback != null && feedback.length() > 0) {
+					feedback = feedback.substring(0, 1).toLowerCase() + feedback.substring(1);
+				}
+				if (force != null && force.length() > 0) {
+					force = force.substring(0, 1).toLowerCase() + force.substring(1);
+				}
+				if (force_feedback != null && force_feedback.length() > 0) {
+					force_feedback = force_feedback.substring(0, 1).toLowerCase() + force_feedback.substring(1);
+				}
 				{
 					JSONObject pointListItem = new JSONObject();
 					pointListItem.put("ibmsSceneCode", ibmsSceneCode);

+ 2 - 2
ibms-data-sdk/src/main/resources/config.xml

@@ -12,9 +12,9 @@
 	<physical_world path="D-physical_world" refresh_enable="true" refresh_interval_second="3600" />
 	<zkt_physical_world path="D-zkt_physical_world" enable="true" refresh_enable="true" refresh_interval_second="3600" />
 	<ibms_physical_world path="D-ibms_physical_world" enable="true" refresh_enable="true" refresh_interval_second="60" />
-	<info_point path="D-info-point" enable="true" version="new" refresh_enable="true" refresh_interval_second="60"/>
+	<info_point path="D-info-point" enable="true" version="new" refresh_enable="true" refresh_interval_second="60" />
 	<!-- zkt-monitor的服务地址 -->
-	<zkt_monitor url="http://192.168.100.33:9909/zkt-monitor/" />
+	<zkt_monitor url="http://192.168.100.33:9909/zkt-monitor/" compress="false" />
 	<!-- zkt-control的服务地址 -->
 	<zkt_control url="http://192.168.100.33:9909/zkt-control/" />
 	<!-- iot-collect的服务地址 -->

BIN
ibms-data-sdk/src/main/resources/new-info-point.xlsx