Browse Source

增加下载日志和操作入口

menglu 3 years ago
parent
commit
3bd6aa32aa

+ 11 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/DaemonThread.java

@@ -16,6 +16,7 @@ import com.persagy.ibms.core.util.RepositoryComputeThread;
 import com.persagy.ibms.data.sdk.test.CheckTest;
 import com.persagy.ibms.data.sdk.util.Constant;
 import com.persagy.ibms.data.sdk.util.DeamonUtil;
+import com.persagy.ibms.data.sdk.util.LogOfDownload;
 import com.persagy.ibms.data.sdk.util.LogOfRun;
 import com.persagy.ibms.data.sdk.util.RWDLoadUtil;
 import com.persagy.ibms.data.sdk.util.RWDRepositoryUtil;
@@ -65,24 +66,34 @@ public class DaemonThread extends Thread {
 				if (!root.exists()) {
 					root.mkdir();
 				}
+				RepositoryContainer.RepositoryProject.LogOfDownloadListMap.put("config", new CopyOnWriteArrayList<LogOfDownload>());
+				RepositoryContainer.RepositoryProject.SuccessLogOfDownloadListMap.put("config", new CopyOnWriteArrayList<LogOfDownload>());
 			}
 			{
 				File root = new File(Constant.physical_world);
 				if (!root.exists()) {
 					root.mkdir();
 				}
+				RepositoryContainer.RepositoryProject.LogOfDownloadListMap.put("physical_world", new CopyOnWriteArrayList<LogOfDownload>());
+				RepositoryContainer.RepositoryProject.SuccessLogOfDownloadListMap.put("physical_world", new CopyOnWriteArrayList<LogOfDownload>());
 			}
 			if (Constant.zkt_physical_world_enable) {
 				File root = new File(Constant.zkt_physical_world);
 				if (!root.exists()) {
 					root.mkdir();
 				}
+				RepositoryContainer.RepositoryProject.LogOfDownloadListMap.put("zkt_physical_world", new CopyOnWriteArrayList<LogOfDownload>());
+				RepositoryContainer.RepositoryProject.SuccessLogOfDownloadListMap.put("zkt_physical_world",
+						new CopyOnWriteArrayList<LogOfDownload>());
 			}
 			if (Constant.ibms_physical_world_enable) {
 				File root = new File(Constant.ibms_physical_world);
 				if (!root.exists()) {
 					root.mkdir();
 				}
+				RepositoryContainer.RepositoryProject.LogOfDownloadListMap.put("ibms_physical_world", new CopyOnWriteArrayList<LogOfDownload>());
+				RepositoryContainer.RepositoryProject.SuccessLogOfDownloadListMap.put("ibms_physical_world",
+						new CopyOnWriteArrayList<LogOfDownload>());
 			}
 			dir_already = true;
 		}

+ 34 - 18
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/DownloadThread_config.java

@@ -8,9 +8,13 @@ import javax.annotation.PostConstruct;
 
 import org.springframework.stereotype.Component;
 
+import com.persagy.ibms.core.util.LogUtil;
+import com.persagy.ibms.data.sdk.util.ConfigRefresh;
 import com.persagy.ibms.data.sdk.util.Constant;
 import com.persagy.ibms.data.sdk.util.FileUtil;
+import com.persagy.ibms.data.sdk.util.LogOfDownload;
 import com.persagy.ibms.data.sdk.util.RWDDownloadUtil;
+import com.persagy.ibms.data.sdk.util.RepositoryContainer;
 
 import lombok.extern.slf4j.Slf4j;
 
@@ -46,7 +50,8 @@ public class DownloadThread_config extends Thread {
 			}
 		}
 
-		Date last_refresh_config = null;
+		String name = "config";
+		ConfigRefresh ConfigRefresh = Constant.ConfigRefreshMap.get(name);
 		while (!stop) {
 			try {
 				Thread.sleep(1000L);
@@ -55,46 +60,57 @@ public class DownloadThread_config extends Thread {
 			}
 
 			Date currTime = new Date();
-			try {
-				boolean changed_config = false;
-				if (last_refresh_config == null
-						|| currTime.getTime() - last_refresh_config.getTime() > 1000L * Constant.config_refresh_interval_second) {
-					if (Constant.config_refresh_enable) {
-						log.warn("config check begin");
-						changed_config = Process_config();
-						if (changed_config) {
+			boolean changed = false;
+			if (ConfigRefresh.last_refresh == null
+					|| currTime.getTime() - ConfigRefresh.last_refresh.getTime() > 1000L * ConfigRefresh.interval_second) {
+				if (ConfigRefresh.enable) {
+					LogOfDownload LogOfDownload = new LogOfDownload();
+					RepositoryContainer.RepositoryProject.AddLogOfDownload(name, LogOfDownload);
+					try {
+						log.warn(name + " check begin");
+						changed = Process_config(LogOfDownload);
+						if (changed) {
 							String validPath = Constant.getLatestPath(Constant.config, false, false);
-							log.warn("config check end " + validPath);
+							log.warn(name + " check end " + validPath);
 						} else {
-							log.warn("config check end");
+							log.warn(name + " check end");
 						}
+						LogOfDownload.status = "success";
+						RepositoryContainer.RepositoryProject.AddSuccessLogOfDownload(name, LogOfDownload);
+					} catch (Exception e) {
+						String message = LogUtil.GetExceptionStackTrace(e);
+						log.error(e.getMessage(), e);
+						LogOfDownload.error(null, message);
+						LogOfDownload.status = "failure";
 					}
-					last_refresh_config = currTime;
+					LogOfDownload.endTime = new Date();
 				}
-			} catch (Exception e) {
-				log.error(e.getMessage(), e);
+				ConfigRefresh.last_refresh = currTime;
 			}
 		}
 	}
 
-	private boolean Process_config() throws Exception {
+	private boolean Process_config(LogOfDownload LogOfDownload) throws Exception {
 		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
 		String validPath = Constant.getLatestPath(Constant.config, false);
 
 		String tmpPath = Constant.config + Constant.getSeperator() + "tmp" + ".json";
-		RWDDownloadUtil.LoadConfig(tmpPath);
+		RWDDownloadUtil.LoadConfig(tmpPath, LogOfDownload);
 		File tmp = new File(tmpPath);
 
 		boolean compare_valid = false;
 		if (validPath != null) {
 			File valid = new File(validPath);
-			compare_valid = FileUtil.compareRecursive(valid, tmp);
+			compare_valid = FileUtil.compareRecursive(valid, tmp, LogOfDownload);
+			LogOfDownload.pathOld = validPath;
 		}
 		boolean result;
 		if (!compare_valid) {
 			Date currTime = new Date();
-			tmp.renameTo(new File(Constant.config + Constant.getSeperator() + sdf.format(currTime) + ".json"));
+			String pathNew = Constant.config + Constant.getSeperator() + sdf.format(currTime) + ".json";
+			tmp.renameTo(new File(pathNew));
 			result = true;
+			LogOfDownload.pathNew = pathNew;
 		} else {
 			result = false;
 		}

+ 27 - 14
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/DownloadThread_ibms.java

@@ -6,8 +6,12 @@ import javax.annotation.PostConstruct;
 
 import org.springframework.stereotype.Component;
 
+import com.persagy.ibms.core.util.LogUtil;
+import com.persagy.ibms.data.sdk.util.ConfigRefresh;
 import com.persagy.ibms.data.sdk.util.Constant;
+import com.persagy.ibms.data.sdk.util.LogOfDownload;
 import com.persagy.ibms.data.sdk.util.RWDDownloadUtil;
+import com.persagy.ibms.data.sdk.util.RepositoryContainer;
 
 import lombok.extern.slf4j.Slf4j;
 
@@ -43,7 +47,8 @@ public class DownloadThread_ibms extends Thread {
 			}
 		}
 
-		Date last_refresh_ibms_physical_world = null;
+		String name = "ibms_physical_world";
+		ConfigRefresh ConfigRefresh = Constant.ConfigRefreshMap.get(name);
 		while (!stop) {
 			try {
 				Thread.sleep(1000L);
@@ -52,24 +57,32 @@ public class DownloadThread_ibms extends Thread {
 			}
 
 			Date currTime = new Date();
-			try {
-				boolean changed_ibms_physical_world = false;
-				if (last_refresh_ibms_physical_world == null || currTime.getTime() - last_refresh_ibms_physical_world.getTime() > 1000L
-						* Constant.ibms_physical_world_refresh_interval_second) {
-					if (Constant.ibms_physical_world_enable && Constant.ibms_physical_world_refresh_enable) {
-						log.warn("ibms_physical_world check begin");
-						changed_ibms_physical_world = RWDDownloadUtil.Process_ibms_physical_world();
-						if (changed_ibms_physical_world) {
+			boolean changed = false;
+			if (ConfigRefresh.last_refresh == null
+					|| currTime.getTime() - ConfigRefresh.last_refresh.getTime() > 1000L * ConfigRefresh.interval_second) {
+				if (Constant.ibms_physical_world_enable && ConfigRefresh.enable) {
+					LogOfDownload LogOfDownload = new LogOfDownload();
+					RepositoryContainer.RepositoryProject.AddLogOfDownload(name, LogOfDownload);
+					try {
+						log.warn(name + " check begin");
+						changed = RWDDownloadUtil.Process_ibms_physical_world(LogOfDownload);
+						if (changed) {
 							String validPath = Constant.getLatestPath(Constant.ibms_physical_world, true, false);
-							log.warn("ibms_physical_world check end " + validPath);
+							log.warn(name + " check end " + validPath);
 						} else {
-							log.warn("ibms_physical_world check end");
+							log.warn(name + " check end");
 						}
+						LogOfDownload.status = "success";
+						RepositoryContainer.RepositoryProject.AddSuccessLogOfDownload(name, LogOfDownload);
+					} catch (Exception e) {
+						String message = LogUtil.GetExceptionStackTrace(e);
+						log.error(e.getMessage(), e);
+						LogOfDownload.error(null, message);
+						LogOfDownload.status = "failure";
 					}
-					last_refresh_ibms_physical_world = currTime;
+					LogOfDownload.endTime = new Date();
 				}
-			} catch (Exception e) {
-				log.error(e.getMessage(), e);
+				ConfigRefresh.last_refresh = currTime;
 			}
 		}
 	}

+ 27 - 14
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/DownloadThread_rwd.java

@@ -6,8 +6,12 @@ import javax.annotation.PostConstruct;
 
 import org.springframework.stereotype.Component;
 
+import com.persagy.ibms.core.util.LogUtil;
+import com.persagy.ibms.data.sdk.util.ConfigRefresh;
 import com.persagy.ibms.data.sdk.util.Constant;
+import com.persagy.ibms.data.sdk.util.LogOfDownload;
 import com.persagy.ibms.data.sdk.util.RWDDownloadUtil;
+import com.persagy.ibms.data.sdk.util.RepositoryContainer;
 
 import lombok.extern.slf4j.Slf4j;
 
@@ -43,7 +47,8 @@ public class DownloadThread_rwd extends Thread {
 			}
 		}
 
-		Date last_refresh_physical_world = null;
+		String name = "physical_world";
+		ConfigRefresh ConfigRefresh = Constant.ConfigRefreshMap.get(name);
 		while (!stop) {
 			try {
 				Thread.sleep(1000L);
@@ -52,24 +57,32 @@ public class DownloadThread_rwd extends Thread {
 			}
 
 			Date currTime = new Date();
-			try {
-				boolean changed_physical_world = false;
-				if (last_refresh_physical_world == null
-						|| currTime.getTime() - last_refresh_physical_world.getTime() > 1000L * Constant.physical_world_refresh_interval_second) {
-					if (Constant.physical_world_refresh_enable) {
-						log.warn("physical_world check begin");
-						changed_physical_world = RWDDownloadUtil.Process_physical_world();
-						if (changed_physical_world) {
+			boolean changed = false;
+			if (ConfigRefresh.last_refresh == null
+					|| currTime.getTime() - ConfigRefresh.last_refresh.getTime() > 1000L * ConfigRefresh.interval_second) {
+				if (ConfigRefresh.enable) {
+					LogOfDownload LogOfDownload = new LogOfDownload();
+					RepositoryContainer.RepositoryProject.AddLogOfDownload(name, LogOfDownload);
+					try {
+						log.warn(name + " check begin");
+						changed = RWDDownloadUtil.Process_physical_world(LogOfDownload);
+						if (changed) {
 							String validPath = Constant.getLatestPath(Constant.physical_world, true, false);
-							log.warn("physical_world check end " + validPath);
+							log.warn(name + " check end " + validPath);
 						} else {
-							log.warn("physical_world check end");
+							log.warn(name + " check end");
 						}
+						LogOfDownload.status = "success";
+						RepositoryContainer.RepositoryProject.AddSuccessLogOfDownload(name, LogOfDownload);
+					} catch (Exception e) {
+						String message = LogUtil.GetExceptionStackTrace(e);
+						log.error(e.getMessage(), e);
+						LogOfDownload.error(null, message);
+						LogOfDownload.status = "failure";
 					}
-					last_refresh_physical_world = currTime;
+					LogOfDownload.endTime = new Date();
 				}
-			} catch (Exception e) {
-				log.error(e.getMessage(), e);
+				ConfigRefresh.last_refresh = currTime;
 			}
 		}
 	}

+ 27 - 13
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/DownloadThread_zkt.java

@@ -6,8 +6,12 @@ import javax.annotation.PostConstruct;
 
 import org.springframework.stereotype.Component;
 
+import com.persagy.ibms.core.util.LogUtil;
+import com.persagy.ibms.data.sdk.util.ConfigRefresh;
 import com.persagy.ibms.data.sdk.util.Constant;
+import com.persagy.ibms.data.sdk.util.LogOfDownload;
 import com.persagy.ibms.data.sdk.util.RWDDownloadUtil;
+import com.persagy.ibms.data.sdk.util.RepositoryContainer;
 
 import lombok.extern.slf4j.Slf4j;
 
@@ -43,7 +47,8 @@ public class DownloadThread_zkt extends Thread {
 			}
 		}
 
-		Date last_refresh_zkt_physical_world = null;
+		String name = "zkt_physical_world";
+		ConfigRefresh ConfigRefresh = Constant.ConfigRefreshMap.get(name);
 		while (!stop) {
 			try {
 				Thread.sleep(1000L);
@@ -52,23 +57,32 @@ public class DownloadThread_zkt extends Thread {
 			}
 
 			Date currTime = new Date();
-			try {
-				boolean changed_zkt_physical_world = false;
-				if (last_refresh_zkt_physical_world == null || currTime.getTime() - last_refresh_zkt_physical_world.getTime() > 1000L
-						* Constant.zkt_physical_world_refresh_interval_second) {
-					if (Constant.zkt_physical_world_enable && Constant.zkt_physical_world_refresh_enable) {
-						changed_zkt_physical_world = RWDDownloadUtil.Process_zkt_physical_world();
-						if (changed_zkt_physical_world) {
+			boolean changed = false;
+			if (ConfigRefresh.last_refresh == null
+					|| currTime.getTime() - ConfigRefresh.last_refresh.getTime() > 1000L * ConfigRefresh.interval_second) {
+				if (Constant.zkt_physical_world_enable && ConfigRefresh.enable) {
+					LogOfDownload LogOfDownload = new LogOfDownload();
+					RepositoryContainer.RepositoryProject.AddLogOfDownload(name, LogOfDownload);
+					try {
+						log.warn(name + " check begin");
+						changed = RWDDownloadUtil.Process_zkt_physical_world(LogOfDownload);
+						if (changed) {
 							String validPath = Constant.getLatestPath(Constant.zkt_physical_world, true, false);
-							log.warn("zkt_physical_world check end " + validPath);
+							log.warn(name + " check end " + validPath);
 						} else {
-							log.warn("zkt_physical_world check end");
+							log.warn(name + " check end");
 						}
+						LogOfDownload.status = "success";
+						RepositoryContainer.RepositoryProject.AddSuccessLogOfDownload(name, LogOfDownload);
+					} catch (Exception e) {
+						String message = LogUtil.GetExceptionStackTrace(e);
+						log.error(e.getMessage(), e);
+						LogOfDownload.error(null, message);
+						LogOfDownload.status = "failure";
 					}
-					last_refresh_zkt_physical_world = currTime;
+					LogOfDownload.endTime = new Date();
 				}
-			} catch (Exception e) {
-				log.error(e.getMessage(), e);
+				ConfigRefresh.last_refresh = currTime;
 			}
 		}
 	}

+ 39 - 7
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/BaseApi.java

@@ -1,6 +1,7 @@
 package com.persagy.ibms.data.sdk.service.rest;
 
 import java.text.SimpleDateFormat;
+import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
 
@@ -21,6 +22,7 @@ import com.persagy.ibms.core.util.CheckUtil;
 import com.persagy.ibms.data.sdk.service.websocket.server.WebSocketChannelInfo;
 import com.persagy.ibms.data.sdk.service.websocket.server.WebSocketChannelPool;
 import com.persagy.ibms.data.sdk.service.websocket.server.WebSocketUtil;
+import com.persagy.ibms.data.sdk.util.LogOfDownload;
 import com.persagy.ibms.data.sdk.util.LogOfRun;
 import com.persagy.ibms.data.sdk.util.RepositoryContainer;
 import com.persagy.ibms.data.sdk.util.ToolUtil;
@@ -140,11 +142,18 @@ public class BaseApi {
 		return JSONObject.toJSONString(result, SerializerFeature.WriteMapNullValue);
 	}
 
+	@PostMapping(path = { "/RefreshCommand" }, produces = "application/json;charset=UTF-8")
+	public String RefreshCommand(@RequestBody String param) {
+		JSONObject paramJSON = JSON.parseObject(param);
+		JSONObject result = BaseUtil.RefreshCommand(paramJSON);
+		return JSONObject.toJSONString(result, SerializerFeature.WriteMapNullValue);
+	}
+
 	@GetMapping(path = "/LogOfRun", produces = "application/json;charset=UTF-8")
 	public JSONObject LogOfRun() {
 		JSONObject result = null;
-		if (RepositoryContainer.RepositoryProject.logOfRun != null) {
-			result = RepositoryContainer.RepositoryProject.logOfRun.toJSON();
+		if (RepositoryContainer.RepositoryProject.LogOfRun != null) {
+			result = RepositoryContainer.RepositoryProject.LogOfRun.toJSON();
 		}
 		return result;
 	}
@@ -152,20 +161,43 @@ public class BaseApi {
 	@GetMapping(path = "/LogOfRunList", produces = "application/json;charset=UTF-8")
 	public JSONArray LogOfRunList() {
 		JSONArray result = new JSONArray();
-		for (LogOfRun LogOfRun : RepositoryContainer.RepositoryProject.logOfRunList) {
+		for (LogOfRun LogOfRun : RepositoryContainer.RepositoryProject.LogOfRunList) {
 			result.add(LogOfRun.toJSON());
 		}
 		return result;
 	}
 
-	@GetMapping(path = "/LogOfAlarmList/{param}", produces = "application/json;charset=UTF-8")
-	public JSONArray LogOfAlarmList(@PathVariable("param") int count) {
+	@GetMapping(path = "/LogOfAlarmList/{count}", produces = "application/json;charset=UTF-8")
+	public JSONArray LogOfAlarmList(@PathVariable("count") int count) {
+		JSONArray result = new JSONArray();
+		if (count == 0) {
+			count = Integer.MAX_VALUE;
+		}
+		for (int i = 0; i < count && i < RepositoryContainer.RepositoryProject.LogOfAlarmList.size() - 1; i++) {
+			JSONObject LogOfRun = RepositoryContainer.RepositoryProject.LogOfAlarmList.get(i);
+			result.add(LogOfRun);
+		}
+		return result;
+	}
+
+	@GetMapping(path = "/LogOfDownload/{name}", produces = "application/json;charset=UTF-8")
+	public JSONObject LogOfDownload(@PathVariable("name") String name) {
+		JSONObject result = null;
+		List<LogOfDownload> list = RepositoryContainer.RepositoryProject.LogOfDownloadListMap.get(name);
+		LogOfDownload LogOfDownload = list.get(0);
+		result = LogOfDownload.toJSON();
+		return result;
+	}
+
+	@GetMapping(path = "/LogOfDownloadList/{name}/{count}", produces = "application/json;charset=UTF-8")
+	public JSONArray LogOfDownloadList(@PathVariable("name") String name, @PathVariable("count") int count) {
 		JSONArray result = new JSONArray();
 		if (count == 0) {
 			count = Integer.MAX_VALUE;
 		}
-		for (int i = 0; i < count && i < RepositoryContainer.RepositoryProject.logOfAlarmList.size() - 1; i++) {
-			JSONObject LogOfRun = RepositoryContainer.RepositoryProject.logOfAlarmList.get(i);
+		List<LogOfDownload> list = RepositoryContainer.RepositoryProject.LogOfDownloadListMap.get(name);
+		for (int i = 0; i < count && i < list.size() - 1; i++) {
+			JSONObject LogOfRun = list.get(i).toJSON();
 			result.add(LogOfRun);
 		}
 		return result;

+ 37 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/BaseUtil.java

@@ -1,5 +1,8 @@
 package com.persagy.ibms.data.sdk.service.rest;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -9,6 +12,8 @@ import com.persagy.ibms.core.data.SceneDataValue;
 import com.persagy.ibms.core.util.ComputeUtil;
 import com.persagy.ibms.core.util.LogUtil;
 import com.persagy.ibms.core.util.RecursiveUtil;
+import com.persagy.ibms.data.sdk.util.ConfigRefresh;
+import com.persagy.ibms.data.sdk.util.Constant;
 import com.persagy.ibms.data.sdk.util.RepositoryContainer;
 import com.persagy.ibms.data.sdk.util.RepositoryImpl;
 
@@ -16,6 +21,38 @@ import lombok.extern.slf4j.Slf4j;
 
 @Slf4j
 public class BaseUtil {
+	public static JSONObject RefreshCommand(JSONObject paramJSON) {
+		JSONObject result = new JSONObject();
+		String command = paramJSON.getString("command");
+		if (command.equals("get")) {
+			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+			JSONArray Content = new JSONArray();
+			for (String name : Constant.ConfigRefreshMap.keySet()) {
+				ConfigRefresh ConfigRefresh = Constant.ConfigRefreshMap.get(name);
+				JSONObject ContentItem = new JSONObject();
+				ContentItem.put("enable", ConfigRefresh.enable);
+				ContentItem.put("interval_second", ConfigRefresh.interval_second);
+				ContentItem.put("last_refresh", ConfigRefresh.last_refresh == null ? null : sdf.format(ConfigRefresh.last_refresh));
+				Content.add(ContentItem);
+			}
+			result.put("Content", Content);
+		} else {
+			String name = paramJSON.getString("name");
+			ConfigRefresh ConfigRefresh = Constant.ConfigRefreshMap.get(name);
+			if (command.equals("start")) {
+				ConfigRefresh.enable = true;
+			} else if (command.equals("stop")) {
+				ConfigRefresh.enable = false;
+			} else if (command.equals("reset_time")) {
+				ConfigRefresh.last_refresh = new Date((new Date()).getTime() - ConfigRefresh.interval_second);
+			} else if (command.equals("interval_second")) {
+				long interval_second = paramJSON.getLong("interval_second");
+				interval_second = interval_second < 0L ? 0L : interval_second;
+				ConfigRefresh.interval_second = interval_second;
+			}
+		}
+		return result;
+	}
 
 	public static String showTree() {
 		RepositoryImpl Repository = RepositoryContainer.instance;

+ 14 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/ConfigRefresh.java

@@ -0,0 +1,14 @@
+package com.persagy.ibms.data.sdk.util;
+
+import java.util.Date;
+
+public class ConfigRefresh {
+	public boolean enable;
+	public long interval_second;
+	public Date last_refresh;
+
+	public ConfigRefresh(boolean enable, long interval_second) {
+		this.enable = enable;
+		this.interval_second = interval_second;
+	}
+}

+ 23 - 17
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/Constant.java

@@ -37,20 +37,12 @@ public class Constant {
 	public static boolean rwd_compress = false;
 	public static String zkt_monitor_url;
 	public static String zkt_control_url;
-	public static String physical_world;
 	public static String config;
-	public static boolean config_refresh_enable;
-	public static long config_refresh_interval_second;
-	public static boolean physical_world_refresh_enable;
-	public static long physical_world_refresh_interval_second;
+	public static String physical_world;
 	public static String zkt_physical_world;
 	public static boolean zkt_physical_world_enable;
-	public static boolean zkt_physical_world_refresh_enable;
-	public static long zkt_physical_world_refresh_interval_second;
 	public static String ibms_physical_world;
 	public static boolean ibms_physical_world_enable;
-	public static boolean ibms_physical_world_refresh_enable;
-	public static long ibms_physical_world_refresh_interval_second;
 	public static String info_point;
 	public static boolean info_point_enable;
 	public static String iot_websocket_url;
@@ -61,6 +53,8 @@ public class Constant {
 	public static String alarm_url;
 	public static String alarm_service_name;
 
+	public static Map<String, ConfigRefresh> ConfigRefreshMap = new ConcurrentHashMap<String, ConfigRefresh>();
+
 	public static String adm_project_url;
 
 	public static Map<String, String> SceneCode2TabName = new ConcurrentHashMap<String, String>();
@@ -137,31 +131,43 @@ public class Constant {
 				if (iter.hasNext()) {
 					element = (Element) iter.next();
 					config = element.attribute("path").getValue();
-					config_refresh_enable = Boolean.parseBoolean(element.attribute("refresh_enable").getValue());
-					config_refresh_interval_second = Long.parseLong(element.attribute("refresh_interval_second").getValue());
+					{
+						boolean enable = Boolean.parseBoolean(element.attribute("refresh_enable").getValue());
+						long interval_second = Long.parseLong(element.attribute("refresh_interval_second").getValue());
+						ConfigRefreshMap.put("config", new ConfigRefresh(enable, interval_second));
+					}
 				}
 				iter = document.selectNodes("/root/physical_world").iterator();
 				if (iter.hasNext()) {
 					element = (Element) iter.next();
 					physical_world = element.attribute("path").getValue();
-					physical_world_refresh_enable = Boolean.parseBoolean(element.attribute("refresh_enable").getValue());
-					physical_world_refresh_interval_second = Long.parseLong(element.attribute("refresh_interval_second").getValue());
+					{
+						boolean enable = Boolean.parseBoolean(element.attribute("refresh_enable").getValue());
+						long interval_second = Long.parseLong(element.attribute("refresh_interval_second").getValue());
+						ConfigRefreshMap.put("physical_world", new ConfigRefresh(enable, interval_second));
+					}
 				}
 				iter = document.selectNodes("/root/zkt_physical_world").iterator();
 				if (iter.hasNext()) {
 					element = (Element) iter.next();
 					zkt_physical_world = element.attribute("path").getValue();
 					zkt_physical_world_enable = Boolean.parseBoolean(element.attribute("enable").getValue());
-					zkt_physical_world_refresh_enable = Boolean.parseBoolean(element.attribute("refresh_enable").getValue());
-					zkt_physical_world_refresh_interval_second = Long.parseLong(element.attribute("refresh_interval_second").getValue());
+					if (zkt_physical_world_enable) {
+						boolean enable = Boolean.parseBoolean(element.attribute("refresh_enable").getValue());
+						long interval_second = Long.parseLong(element.attribute("refresh_interval_second").getValue());
+						ConfigRefreshMap.put("zkt_physical_world", new ConfigRefresh(enable, interval_second));
+					}
 				}
 				iter = document.selectNodes("/root/ibms_physical_world").iterator();
 				if (iter.hasNext()) {
 					element = (Element) iter.next();
 					ibms_physical_world = element.attribute("path").getValue();
 					ibms_physical_world_enable = Boolean.parseBoolean(element.attribute("enable").getValue());
-					ibms_physical_world_refresh_enable = Boolean.parseBoolean(element.attribute("refresh_enable").getValue());
-					ibms_physical_world_refresh_interval_second = Long.parseLong(element.attribute("refresh_interval_second").getValue());
+					if (ibms_physical_world_enable) {
+						boolean enable = Boolean.parseBoolean(element.attribute("refresh_enable").getValue());
+						long interval_second = Long.parseLong(element.attribute("refresh_interval_second").getValue());
+						ConfigRefreshMap.put("ibms_physical_world", new ConfigRefresh(enable, interval_second));
+					}
 				}
 				iter = document.selectNodes("/root/info_point").iterator();
 				if (iter.hasNext()) {

+ 82 - 16
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/FileUtil.java

@@ -4,9 +4,14 @@ import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.OutputStreamWriter;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.persagy.ibms.core.util.FastJsonCompareUtil;
 import com.persagy.ibms.core.util.FastJsonReaderUtil;
 
@@ -16,9 +21,21 @@ import lombok.extern.slf4j.Slf4j;
 @Slf4j
 public class FileUtil {
 	public static void Save(String filename, String content) throws Exception {
+		Save(filename, content, null);
+	}
+
+	public static void Save(String filename, String content, List<JSONObject> downloadList) throws Exception {
 		BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "UTF-8"));
 		writer.write(content);
 		writer.close();
+		if (downloadList != null) {
+			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+			JSONObject json = new JSONObject();
+			json.put("time", sdf.format(new Date()));
+			json.put("filename", filename);
+			json.put("filesize", content.length());
+			downloadList.add(json);
+		}
 	}
 
 	public static void deleteRecursive(File file) {
@@ -41,8 +58,9 @@ public class FileUtil {
 		file.delete();
 	}
 
-	public static boolean compareRecursive(File file1, File file2) throws Exception {
+	public static boolean compareRecursive(File file1, File file2, LogOfDownload LogOfDownload) throws Exception {
 		if (file1.isDirectory() && file2.isDirectory()) {
+			boolean result = true;
 			Map<String, File> fileMap1 = new ConcurrentHashMap<String, File>();
 			Map<String, File> dirMap1 = new ConcurrentHashMap<String, File>();
 			draw(file1, fileMap1, dirMap1);
@@ -50,35 +68,83 @@ public class FileUtil {
 			Map<String, File> dirMap2 = new ConcurrentHashMap<String, File>();
 			draw(file2, fileMap2, dirMap2);
 
-			if (!compareKey(fileMap1, fileMap2)) {
-				return false;
-			}
-			for (String key : fileMap1.keySet()) {
-				File tmp1 = fileMap1.get(key);
-				File tmp2 = fileMap2.get(key);
-				if (!compareRecursive(tmp1, tmp2)) {
-					return false;
+			if (!compareKey(fileMap1, fileMap2) || !compareKey(dirMap1, dirMap2)) {
+				result = false;
+
+				if (LogOfDownload != null) {
+					JSONArray file_old = new JSONArray();
+					JSONArray file_new = new JSONArray();
+					JSONArray dir_old = new JSONArray();
+					JSONArray dir_new = new JSONArray();
+					if (!compareKey(fileMap1, fileMap2)) {
+						for (String key : fileMap1.keySet()) {
+							if (!fileMap2.containsKey(key)) {
+								file_old.add(fileMap1.get(key).getAbsolutePath());
+							}
+						}
+						for (String key : fileMap2.keySet()) {
+							if (!fileMap1.containsKey(key)) {
+								file_new.add(fileMap2.get(key).getAbsolutePath());
+							}
+						}
+					}
+					if (!compareKey(dirMap1, dirMap2)) {
+						for (String key : dirMap1.keySet()) {
+							if (!dirMap2.containsKey(key)) {
+								dir_old.add(dirMap1.get(key).getAbsolutePath());
+							}
+						}
+						for (String key : dirMap2.keySet()) {
+							if (!dirMap1.containsKey(key)) {
+								dir_new.add(dirMap2.get(key).getAbsolutePath());
+							}
+						}
+					}
+					JSONObject file_change = new JSONObject();
+					file_change.put("dir_name", file1.getAbsolutePath());
+					file_change.put("file_old", file_old);
+					file_change.put("file_new", file_new);
+					file_change.put("dir_old", dir_old);
+					file_change.put("dir_new", dir_new);
+					LogOfDownload.changeList.add(file_change);
 				}
 			}
 
-			if (!compareKey(dirMap1, dirMap2)) {
-				return false;
+			for (String key : fileMap1.keySet()) {
+				if (fileMap2.containsKey(key)) {
+					File tmp1 = fileMap1.get(key);
+					File tmp2 = fileMap2.get(key);
+					if (!compareRecursive(tmp1, tmp2, LogOfDownload)) {
+						result = false;
+					}
+				}
 			}
 			for (String key : dirMap1.keySet()) {
-				File tmp1 = dirMap1.get(key);
-				File tmp2 = dirMap2.get(key);
-				if (!compareRecursive(tmp1, tmp2)) {
-					return false;
+				if (dirMap2.containsKey(key)) {
+					File tmp1 = dirMap1.get(key);
+					File tmp2 = dirMap2.get(key);
+					if (!compareRecursive(tmp1, tmp2, LogOfDownload)) {
+						result = false;
+					}
 				}
 			}
 
-			return true;
+			return result;
 		} else if (file1.isFile() && file2.isFile()) {
 			Object json1 = FastJsonReaderUtil.Instance().Read(file1);
 			Object json2 = FastJsonReaderUtil.Instance().Read(file2);
 			boolean file_compare = FastJsonCompareUtil.Instance().CompareObject(json1, json2, true);
 			// boolean file_compare = file1.length() == file2.length();
 			log.debug("Compare " + file1.getPath() + " " + file2.getPath() + "\t" + file_compare);
+			if (!file_compare) {
+				if (LogOfDownload != null) {
+					JSONObject file_change = new JSONObject();
+					file_change.put("file_name", file1.getAbsolutePath());
+					file_change.put("length_old", file1.length());
+					file_change.put("length_new", file2.length());
+					LogOfDownload.changeList.add(file_change);
+				}
+			}
 			return file_compare;
 		} else {
 			return false;

+ 24 - 4
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/LogOfDownload.java

@@ -15,8 +15,10 @@ public class LogOfDownload {
 	public Date endTime;
 	public List<JSONObject> downloadList = new CopyOnWriteArrayList<JSONObject>();
 	public String pathOld;
-	public long fileSizeOld;
 	public String pathNew;
+	public long fileCountOld;
+	public long fileSizeOld;
+	public long fileCountNew;
 	public long fileSizeNew;
 	public List<JSONObject> changeList = new CopyOnWriteArrayList<JSONObject>();
 	public List<JSONObject> errorList = new CopyOnWriteArrayList<JSONObject>();
@@ -26,18 +28,36 @@ public class LogOfDownload {
 		this.startTime = new Date();
 	}
 
+	public synchronized void error(String path, String message) {
+		JSONObject item = new JSONObject();
+		item.put("path", path);
+		item.put("message", message);
+		if (this.errorList.size() <= 1024) {
+			this.errorList.add(item);
+		}
+	}
+
 	public synchronized JSONObject toJSON() {
 		JSONObject result = new JSONObject();
 		if (startTime != null) {
 			result.put("startTime", sdf.format(startTime));
 		}
 		{
+			JSONArray downloadArray = new JSONArray();
+			downloadArray.addAll(downloadList);
+			result.put("downloadArray", downloadArray);
+		}
+		{
 			JSONArray errorArray = new JSONArray();
-			for (JSONObject error : errorList) {
-				errorArray.add(error);
-			}
+			errorArray.addAll(errorList);
 			result.put("errorArray", errorArray);
 		}
+		if (pathOld != null) {
+			result.put("pathOld", pathOld);
+		}
+		if (pathNew != null) {
+			result.put("pathNew", pathNew);
+		}
 		if (endTime != null) {
 			result.put("endTime", sdf.format(endTime));
 		}

+ 61 - 73
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RWDDownloadUtil.java

@@ -20,7 +20,7 @@ import lombok.extern.slf4j.Slf4j;
 @Slf4j
 public class RWDDownloadUtil {
 
-	public static void LoadConfig(String path) throws Exception {
+	public static void LoadConfig(String path, LogOfDownload LogOfDownload) throws Exception {
 		FileUtil.deleteRecursive(new File(path));
 		JSONArray classArray = null;
 		List<String> groupCodeList = new CopyOnWriteArrayList<String>();
@@ -51,11 +51,11 @@ public class RWDDownloadUtil {
 		}
 		if (classArray != null && classArray.size() == 1) {
 			JSONObject item = (JSONObject) classArray.get(0);
-			FileUtil.Save(path, FastJsonUtil.toFormatString(item.get("itemData")));
+			FileUtil.Save(path, FastJsonUtil.toFormatString(item.get("itemData")), LogOfDownload.downloadList);
 		}
 	}
 
-	public static boolean Process_physical_world() throws Exception {
+	public static boolean Process_physical_world(LogOfDownload LogOfDownload) throws Exception {
 		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
 		String validPath = Constant.getLatestPath(Constant.physical_world, true);
 		// 存储临时文件
@@ -63,39 +63,34 @@ public class RWDDownloadUtil {
 		{
 			String tmpPath = Constant.physical_world + Constant.getSeperator() + "tmp1";
 			dir1 = new File(tmpPath);
-			RWDDownloadUtil.LoadPhysicalWorld(tmpPath);
+			RWDDownloadUtil.LoadPhysicalWorld(tmpPath, LogOfDownload);
 		}
 		File dir2;
 		{
 			String tmpPath = Constant.physical_world + Constant.getSeperator() + "tmp2";
 			dir2 = new File(tmpPath);
-			RWDDownloadUtil.LoadPhysicalWorld(tmpPath);
+			RWDDownloadUtil.LoadPhysicalWorld(tmpPath, LogOfDownload);
 		}
 		// 检查一致性
-		boolean compare = FileUtil.compareRecursive(dir1, dir2);
+		boolean compare = FileUtil.compareRecursive(dir1, dir2, null);
 		log.debug("Compare tmp1" + (compare ? "==" : "!=") + "tmp2");
 		boolean result;
 		if (compare) {
-			File valid = null;
+			boolean compare_valid = false;
 			if (validPath != null) {
-				valid = new File(validPath);
+				File valid = new File(validPath);
+				compare_valid = FileUtil.compareRecursive(valid, dir2, LogOfDownload);
+				LogOfDownload.pathOld = validPath;
 			}
-			if (valid != null && valid.exists()) {
-				boolean compare_valid = FileUtil.compareRecursive(valid, dir2);
-				log.debug("Compare valid" + (compare_valid ? "==" : "!=") + "tmp2");
-				if (compare_valid) {
-					result = false;
-				} else {
-					// 移动tmp2
-					Date currTime = new Date();
-					dir2.renameTo(new File(Constant.physical_world + Constant.getSeperator() + sdf.format(currTime)));
-					result = true;
-				}
-			} else {
+			if (!compare_valid) {
 				// 移动tmp2
 				Date currTime = new Date();
-				dir2.renameTo(new File(Constant.physical_world + Constant.getSeperator() + sdf.format(currTime)));
+				String pathNew = Constant.physical_world + Constant.getSeperator() + sdf.format(currTime);
+				dir2.renameTo(new File(pathNew));
+				LogOfDownload.pathNew = pathNew;
 				result = true;
+			} else {
+				result = false;
 			}
 		} else {
 			result = false;
@@ -106,7 +101,7 @@ public class RWDDownloadUtil {
 		return result;
 	}
 
-	public static void LoadPhysicalWorld(String path) throws Exception {
+	public static void LoadPhysicalWorld(String path, LogOfDownload LogOfDownload) throws Exception {
 		log.debug("Download physical world refresh dir");
 		FileUtil.deleteRecursive(new File(path));
 		{
@@ -140,7 +135,7 @@ public class RWDDownloadUtil {
 			JSONObject resultJSON = JSON.parseObject(post_result);
 			classArray = resultJSON.getJSONArray("data");
 			classArray = classArray == null ? new JSONArray() : classArray;
-			FileUtil.Save(path + Constant.getSeperator() + "classArray.json", FastJsonUtil.toFormatString(classArray));
+			FileUtil.Save(path + Constant.getSeperator() + "classArray.json", FastJsonUtil.toFormatString(classArray), LogOfDownload.downloadList);
 		}
 		for (int i = 0; i < classArray.size(); i++) {
 			JSONObject item = (JSONObject) classArray.get(i);
@@ -159,7 +154,8 @@ public class RWDDownloadUtil {
 				infoArray = resultJSON.getJSONArray("data");
 			}
 			infoArray = infoArray == null ? new JSONArray() : infoArray;
-			FileUtil.Save(path + Constant.getSeperator() + "info" + Constant.getSeperator() + code + ".json", FastJsonUtil.toFormatString(infoArray));
+			FileUtil.Save(path + Constant.getSeperator() + "info" + Constant.getSeperator() + code + ".json", FastJsonUtil.toFormatString(infoArray),
+					LogOfDownload.downloadList);
 		}
 		Map<String, Boolean> objTypeMap = new ConcurrentHashMap<String, Boolean>();
 		for (int i = 0; i < classArray.size(); i++) {
@@ -196,7 +192,7 @@ public class RWDDownloadUtil {
 			}
 			infoArray = infoArray == null ? new JSONArray() : infoArray;
 			FileUtil.Save(path + Constant.getSeperator() + "object" + Constant.getSeperator() + code + ".json",
-					FastJsonUtil.toFormatString(infoArray));
+					FastJsonUtil.toFormatString(infoArray), LogOfDownload.downloadList);
 		}
 		Map<String, Map<String, Integer>> relDic = new ConcurrentHashMap<String, Map<String, Integer>>();
 		try (InputStream stream = Constant.getStream("relation.xlsx")) {
@@ -228,13 +224,13 @@ public class RWDDownloadUtil {
 				}
 				infoArray = infoArray == null ? new JSONArray() : infoArray;
 				FileUtil.Save(path + Constant.getSeperator() + "relation" + Constant.getSeperator() + graphCode + Constant.getSeperator() + relCode
-						+ ".json", FastJsonUtil.toFormatString(infoArray));
+						+ ".json", FastJsonUtil.toFormatString(infoArray), LogOfDownload.downloadList);
 			}
 		}
 		log.debug("Download physical world finish " + path);
 	}
 
-	public static boolean Process_zkt_physical_world() throws Exception {
+	public static boolean Process_zkt_physical_world(LogOfDownload LogOfDownload) throws Exception {
 		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
 		String validPath = Constant.getLatestPath(Constant.zkt_physical_world, true);
 		// 存储临时文件
@@ -242,39 +238,34 @@ public class RWDDownloadUtil {
 		{
 			String tmpPath = Constant.zkt_physical_world + Constant.getSeperator() + "tmp1";
 			dir1 = new File(tmpPath);
-			RWDDownloadUtil.LoadZKTPhysicalWorld(tmpPath);
+			RWDDownloadUtil.LoadZKTPhysicalWorld(tmpPath, LogOfDownload);
 		}
 		File dir2;
 		{
 			String tmpPath = Constant.zkt_physical_world + Constant.getSeperator() + "tmp2";
 			dir2 = new File(tmpPath);
-			RWDDownloadUtil.LoadZKTPhysicalWorld(tmpPath);
+			RWDDownloadUtil.LoadZKTPhysicalWorld(tmpPath, LogOfDownload);
 		}
 		// 检查一致性
-		boolean compare = FileUtil.compareRecursive(dir1, dir2);
+		boolean compare = FileUtil.compareRecursive(dir1, dir2, null);
 		log.debug("Compare tmp1" + (compare ? "==" : "!=") + "tmp2");
 		boolean result;
 		if (compare) {
-			File valid = null;
+			boolean compare_valid = false;
 			if (validPath != null) {
-				valid = new File(validPath);
+				File valid = new File(validPath);
+				compare_valid = FileUtil.compareRecursive(valid, dir2, LogOfDownload);
+				LogOfDownload.pathOld = validPath;
 			}
-			if (valid != null && valid.exists()) {
-				boolean compare_valid = FileUtil.compareRecursive(valid, dir2);
-				log.debug("Compare valid" + (compare_valid ? "==" : "!=") + "tmp2");
-				if (compare_valid) {
-					result = false;
-				} else {
-					// 移动tmp2
-					Date currTime = new Date();
-					dir2.renameTo(new File(Constant.zkt_physical_world + Constant.getSeperator() + sdf.format(currTime)));
-					result = true;
-				}
-			} else {
+			if (!compare_valid) {
 				// 移动tmp2
 				Date currTime = new Date();
-				dir2.renameTo(new File(Constant.zkt_physical_world + Constant.getSeperator() + sdf.format(currTime)));
+				String pathNew = Constant.zkt_physical_world + Constant.getSeperator() + sdf.format(currTime);
+				dir2.renameTo(new File(pathNew));
+				LogOfDownload.pathNew = pathNew;
 				result = true;
+			} else {
+				result = false;
 			}
 		} else {
 			result = false;
@@ -285,7 +276,7 @@ public class RWDDownloadUtil {
 		return result;
 	}
 
-	public static void LoadZKTPhysicalWorld(String path) throws Exception {
+	public static void LoadZKTPhysicalWorld(String path, LogOfDownload LogOfDownload) throws Exception {
 		log.debug("Download zkt physical world refresh dir");
 		FileUtil.deleteRecursive(new File(path));
 		{
@@ -312,7 +303,7 @@ public class RWDDownloadUtil {
 					param.toJSONString());
 			sceneArray = JSON.parseArray(post_result);
 			sceneArray = sceneArray == null ? new JSONArray() : sceneArray;
-			FileUtil.Save(path + Constant.getSeperator() + "sceneArray.json", FastJsonUtil.toFormatString(sceneArray));
+			FileUtil.Save(path + Constant.getSeperator() + "sceneArray.json", FastJsonUtil.toFormatString(sceneArray), LogOfDownload.downloadList);
 		}
 		JSONArray classArray;
 		{
@@ -326,7 +317,7 @@ public class RWDDownloadUtil {
 			JSONObject resultJSON = JSON.parseObject(post_result);
 			classArray = resultJSON.getJSONArray("data");
 			classArray = classArray == null ? new JSONArray() : classArray;
-			FileUtil.Save(path + Constant.getSeperator() + "classArray.json", FastJsonUtil.toFormatString(classArray));
+			FileUtil.Save(path + Constant.getSeperator() + "classArray.json", FastJsonUtil.toFormatString(classArray), LogOfDownload.downloadList);
 		}
 		for (int i = 0; i < classArray.size(); i++) {
 			JSONObject item = (JSONObject) classArray.get(i);
@@ -352,7 +343,7 @@ public class RWDDownloadUtil {
 				sceneDir.mkdir();
 			}
 			FileUtil.Save(path + Constant.getSeperator() + "object" + Constant.getSeperator() + ibmsSceneCode + Constant.getSeperator()
-					+ ibmsClassCode + ".json", FastJsonUtil.toFormatString(infoArray));
+					+ ibmsClassCode + ".json", FastJsonUtil.toFormatString(infoArray), LogOfDownload.downloadList);
 		}
 		log.debug("Download zkt physical world finish " + path);
 
@@ -417,7 +408,8 @@ public class RWDDownloadUtil {
 				item.put("name", alarmTypeMap.get(key));
 				alarmTypeArray.add(item);
 			}
-			FileUtil.Save(path + Constant.getSeperator() + "alarmTypeArray.json", FastJsonUtil.toFormatString(alarmTypeArray));
+			FileUtil.Save(path + Constant.getSeperator() + "alarmTypeArray.json", FastJsonUtil.toFormatString(alarmTypeArray),
+					LogOfDownload.downloadList);
 		}
 
 		{
@@ -466,11 +458,12 @@ public class RWDDownloadUtil {
 				JSONObject resultJSON = JSON.parseObject(post_result);
 				alarmConfigArray = resultJSON.getJSONArray("Content");
 			}
-			FileUtil.Save(path + Constant.getSeperator() + "zkt_alarm_config.json", FastJsonUtil.toFormatString(alarmConfigArray));
+			FileUtil.Save(path + Constant.getSeperator() + "zkt_alarm_config.json", FastJsonUtil.toFormatString(alarmConfigArray),
+					LogOfDownload.downloadList);
 		}
 	}
 
-	public static boolean Process_ibms_physical_world() throws Exception {
+	public static boolean Process_ibms_physical_world(LogOfDownload LogOfDownload) throws Exception {
 		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
 		String validPath = Constant.getLatestPath(Constant.ibms_physical_world, true);
 		// 存储临时文件
@@ -478,39 +471,34 @@ public class RWDDownloadUtil {
 		{
 			String tmpPath = Constant.ibms_physical_world + Constant.getSeperator() + "tmp1";
 			dir1 = new File(tmpPath);
-			RWDDownloadUtil.LoadIBMSPhysicalWorld(tmpPath);
+			RWDDownloadUtil.LoadIBMSPhysicalWorld(tmpPath, LogOfDownload);
 		}
 		File dir2;
 		{
 			String tmpPath = Constant.ibms_physical_world + Constant.getSeperator() + "tmp2";
 			dir2 = new File(tmpPath);
-			RWDDownloadUtil.LoadIBMSPhysicalWorld(tmpPath);
+			RWDDownloadUtil.LoadIBMSPhysicalWorld(tmpPath, LogOfDownload);
 		}
 		// 检查一致性
-		boolean compare = FileUtil.compareRecursive(dir1, dir2);
+		boolean compare = FileUtil.compareRecursive(dir1, dir2, null);
 		log.debug("Compare tmp1" + (compare ? "==" : "!=") + "tmp2");
 		boolean result;
 		if (compare) {
-			File valid = null;
+			boolean compare_valid = false;
 			if (validPath != null) {
-				valid = new File(validPath);
+				File valid = new File(validPath);
+				compare_valid = FileUtil.compareRecursive(valid, dir2, LogOfDownload);
+				LogOfDownload.pathOld = validPath;
 			}
-			if (valid != null && valid.exists()) {
-				boolean compare_valid = FileUtil.compareRecursive(valid, dir2);
-				log.debug("Compare valid" + (compare_valid ? "==" : "!=") + "tmp2");
-				if (compare_valid) {
-					result = false;
-				} else {
-					// 移动tmp2
-					Date currTime = new Date();
-					dir2.renameTo(new File(Constant.ibms_physical_world + Constant.getSeperator() + sdf.format(currTime)));
-					result = true;
-				}
-			} else {
+			if (!compare_valid) {
 				// 移动tmp2
 				Date currTime = new Date();
-				dir2.renameTo(new File(Constant.ibms_physical_world + Constant.getSeperator() + sdf.format(currTime)));
+				String pathNew = Constant.ibms_physical_world + Constant.getSeperator() + sdf.format(currTime);
+				dir2.renameTo(new File(pathNew));
+				LogOfDownload.pathNew = pathNew;
 				result = true;
+			} else {
+				result = false;
 			}
 		} else {
 			result = false;
@@ -566,7 +554,7 @@ public class RWDDownloadUtil {
 		return result;
 	}
 
-	public static void LoadIBMSPhysicalWorld(String path) throws Exception {
+	public static void LoadIBMSPhysicalWorld(String path, LogOfDownload LogOfDownload) throws Exception {
 		log.debug("Download ibms physical world refresh dir");
 		FileUtil.deleteRecursive(new File(path));
 		{
@@ -585,7 +573,7 @@ public class RWDDownloadUtil {
 			criteria.put("projectId", RepositoryContainer.RepositoryProject.projectId);
 			criteria.put("groupCode", RepositoryContainer.RepositoryProject.groupCode);
 			classArray = post_by_page("zkt_monitor", Constant.zkt_monitor_url + "/logicalGrouping/list", criteria, page_size);
-			FileUtil.Save(path + Constant.getSeperator() + "groupArray.json", FastJsonUtil.toFormatString(classArray));
+			FileUtil.Save(path + Constant.getSeperator() + "groupArray.json", FastJsonUtil.toFormatString(classArray), LogOfDownload.downloadList);
 		}
 		Map<String, Map<String, List<String>>> idListMapMap = new ConcurrentHashMap<String, Map<String, List<String>>>();
 		for (int i = 0; i < classArray.size(); i++) {
@@ -627,7 +615,7 @@ public class RWDDownloadUtil {
 				}
 				infoArray = infoArray == null ? new JSONArray() : infoArray;
 				FileUtil.Save(path + Constant.getSeperator() + ibmsSceneCode + Constant.getSeperator() + ibmsClassCode + ".json",
-						FastJsonUtil.toFormatString(infoArray));
+						FastJsonUtil.toFormatString(infoArray), LogOfDownload.downloadList);
 			}
 		}
 		log.debug("Download ibms physical world finish " + path);

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

@@ -354,7 +354,7 @@ public class RepositoryImpl extends RepositoryBase {
 
 	@Override
 	public void log_step_count(int step_count) {
-		this.RepositoryProject.logOfRun.step_count = step_count;
+		this.RepositoryProject.LogOfRun.step_count = step_count;
 	}
 
 	@Override
@@ -364,19 +364,19 @@ public class RepositoryImpl extends RepositoryBase {
 		stepJSON.put("property_count", property_count);
 		stepJSON.put("value_count", value_count);
 		stepJSON.put("beginTime", sdf.format(new Date()));
-		this.RepositoryProject.logOfRun.stepList.add(stepJSON);
+		this.RepositoryProject.LogOfRun.stepList.add(stepJSON);
 	}
 
 	@Override
 	public void log_step_end(int step, int finish_count) {
 		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
-		JSONObject stepJSON = this.RepositoryProject.logOfRun.stepList.get(this.RepositoryProject.logOfRun.stepList.size() - 1);
+		JSONObject stepJSON = this.RepositoryProject.LogOfRun.stepList.get(this.RepositoryProject.LogOfRun.stepList.size() - 1);
 		stepJSON.put("finish_count", finish_count);
 		stepJSON.put("endTime", sdf.format(new Date()));
 	}
 
 	@Override
 	public void log_error(String path, String message) {
-		this.RepositoryProject.logOfRun.error(path, message);
+		this.RepositoryProject.LogOfRun.error(path, message);
 	}
 }

+ 34 - 14
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RepositoryProject.java

@@ -2,6 +2,7 @@ package com.persagy.ibms.data.sdk.util;
 
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 
@@ -33,31 +34,50 @@ public class RepositoryProject {
 	// 限流用
 	public ConcurrentHashMap<String, ConcurrentHashMap<String, Date>> ip2param2time = new ConcurrentHashMap<String, ConcurrentHashMap<String, Date>>();
 
-	public LogOfRun logOfRun;
-	public List<LogOfRun> logOfRunList = new CopyOnWriteArrayList<LogOfRun>();
-	public List<LogOfRun> successLogOfRunList = new CopyOnWriteArrayList<LogOfRun>();
+	public LogOfRun LogOfRun;
+	public List<LogOfRun> LogOfRunList = new CopyOnWriteArrayList<LogOfRun>();
+	public List<LogOfRun> SuccessLogOfRunList = new CopyOnWriteArrayList<LogOfRun>();
 
-	public List<JSONObject> logOfAlarmList = new CopyOnWriteArrayList<JSONObject>();
+	public List<JSONObject> LogOfAlarmList = new CopyOnWriteArrayList<JSONObject>();
+
+	public Map<String, List<LogOfDownload>> LogOfDownloadListMap = new ConcurrentHashMap<String, List<LogOfDownload>>();
+	public Map<String, List<LogOfDownload>> SuccessLogOfDownloadListMap = new ConcurrentHashMap<String, List<LogOfDownload>>();
 
 	public void AddLogOfRun(LogOfRun LogOfRun) {
-		this.logOfRun = LogOfRun;
-		this.logOfRunList.add(0, LogOfRun);
-		for (int i = this.logOfRunList.size() - 1; i > 32; i--) {
-			this.logOfRunList.remove(i);
+		this.LogOfRun = LogOfRun;
+		this.LogOfRunList.add(0, LogOfRun);
+		for (int i = this.LogOfRunList.size() - 1; i > 32; i--) {
+			this.LogOfRunList.remove(i);
 		}
 	}
 
 	public void AddSuccessLogOfRun(LogOfRun LogOfRun) {
-		this.successLogOfRunList.add(0, LogOfRun);
-		for (int i = this.successLogOfRunList.size() - 1; i > 4; i--) {
-			this.successLogOfRunList.remove(i);
+		this.SuccessLogOfRunList.add(0, LogOfRun);
+		for (int i = this.SuccessLogOfRunList.size() - 1; i > 4; i--) {
+			this.SuccessLogOfRunList.remove(i);
 		}
 	}
 
 	public void AddLogOfAlarm(JSONObject LogOfRun) {
-		this.logOfAlarmList.add(0, LogOfRun);
-		for (int i = this.logOfAlarmList.size() - 1; i > 1024; i--) {
-			this.logOfAlarmList.remove(i);
+		this.LogOfAlarmList.add(0, LogOfRun);
+		for (int i = this.LogOfAlarmList.size() - 1; i > 1024; i--) {
+			this.LogOfAlarmList.remove(i);
+		}
+	}
+
+	public void AddLogOfDownload(String name, LogOfDownload LogOfDownload) {
+		List<LogOfDownload> list = this.LogOfDownloadListMap.get(name);
+		list.add(0, LogOfDownload);
+		for (int i = list.size() - 1; i > 32; i--) {
+			list.remove(i);
+		}
+	}
+
+	public void AddSuccessLogOfDownload(String name, LogOfDownload LogOfDownload) {
+		List<LogOfDownload> list = this.SuccessLogOfDownloadListMap.get(name);
+		list.add(0, LogOfDownload);
+		for (int i = list.size() - 1; i > 4; i--) {
+			list.remove(i);
 		}
 	}
 }