Przeglądaj źródła

加快刷新编组频率

menglu 3 lat temu
rodzic
commit
3f655a299f

+ 0 - 3
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/Application_ibms_data_sdk.java

@@ -5,12 +5,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.web.servlet.ServletComponentScan;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
-import com.github.dadiyang.autologging.aop.annotation.EnableControllerLog;
-
 @SpringBootApplication
 @EnableScheduling
 @ServletComponentScan
-@EnableControllerLog
 public class Application_ibms_data_sdk {
 
 	public static void main(String[] args) throws Exception {

+ 133 - 104
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/DaemonThread.java

@@ -2,8 +2,6 @@ package com.persagy.ibms.data.sdk.service;
 
 import java.io.File;
 import java.net.URI;
-import java.text.SimpleDateFormat;
-import java.util.Date;
 
 import javax.annotation.PostConstruct;
 
@@ -13,7 +11,6 @@ import com.persagy.ibms.core.util.KeywordUtil;
 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.RWDDownloadUtil;
 import com.persagy.ibms.data.sdk.util.RWDLoadUtil;
 import com.persagy.ibms.data.sdk.util.RWDRepositoryUtil;
 import com.persagy.ibms.data.sdk.util.RepositoryContainer;
@@ -42,73 +39,44 @@ public class DaemonThread extends Thread {
 		}
 	}
 
+	public static boolean dir_already = false;
+	public static boolean initialized = false;
+	public static String path_config;
+	public static String path_physical_world;
+	public static String path_zkt_physical_world;
+	public static String path_ibms_physical_world;
+
 	public void run() {
-		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
 		KeywordUtil.keyWordMap = Constant.keyWordMap;
 		KeywordUtil.prefixMap = Constant.prefixMap;
 		KeywordUtil.suffixMap = Constant.suffixMap;
 		// 没有就下载
 		{
-			Date currTime = new Date();
-			String[] pathArray = { Constant.physical_world, Constant.zkt_physical_world, Constant.config, Constant.ibms_physical_world };
-			for (String path : pathArray) {
-				File root = new File(path);
+			{
+				File root = new File(Constant.config);
 				if (!root.exists()) {
 					root.mkdir();
 				}
 			}
-			try {
-				String validPath = Constant.getLatestPath(Constant.physical_world, true);
-				if (validPath == null) {
-					while (true) {
-						boolean changed_physical_world = RWDDownloadUtil.Process_physical_world();
-						if (changed_physical_world) {
-							break;
-						}
-					}
+			{
+				File root = new File(Constant.physical_world);
+				if (!root.exists()) {
+					root.mkdir();
 				}
-			} catch (Exception e) {
-				log.error(e.getMessage(), e);
 			}
 			if (Constant.zkt_physical_world_enable) {
-				try {
-					String validPath = Constant.getLatestPath(Constant.zkt_physical_world, true);
-					if (validPath == null) {
-						while (true) {
-							boolean changed_physical_world = RWDDownloadUtil.Process_zkt_physical_world();
-							if (changed_physical_world) {
-								break;
-							}
-						}
-					}
-				} catch (Exception e) {
-					log.error(e.getMessage(), e);
+				File root = new File(Constant.zkt_physical_world);
+				if (!root.exists()) {
+					root.mkdir();
 				}
 			}
 			if (Constant.ibms_physical_world_enable) {
-				try {
-					String validPath = Constant.getLatestPath(Constant.ibms_physical_world, true);
-					if (validPath == null) {
-						while (true) {
-							boolean changed_physical_world = RWDDownloadUtil.Process_ibms_physical_world();
-							if (changed_physical_world) {
-								break;
-							}
-						}
-					}
-				} catch (Exception e) {
-					log.error(e.getMessage(), e);
-				}
-			}
-			try {
-				String validPath = Constant.getLatestPath(Constant.config, false);
-				if (validPath == null) {
-					String tmpPath = Constant.config + Constant.getSeperator() + sdf.format(currTime) + ".json";
-					RWDDownloadUtil.LoadConfig(tmpPath);
+				File root = new File(Constant.ibms_physical_world);
+				if (!root.exists()) {
+					root.mkdir();
 				}
-			} catch (Exception e) {
-				log.error(e.getMessage(), e);
 			}
+			dir_already = true;
 		}
 
 		// Constant.test = true;
@@ -121,66 +89,127 @@ public class DaemonThread extends Thread {
 			return;
 		}
 
-		try {
-			Constant.debug = false;// 调试模式设为true
-			RepositoryImpl Repository = RepositoryContainer.instance;
-			Repository.use_thread = !Constant.debug;
-			Repository.RepositoryBase = RepositoryContainer.RepositoryBase;
-			RWDRepositoryUtil.DoRepository(Repository, true);
-			log.warn("compute finish");
-			RepositoryContainer.RepositoryBase.compute_finish = true;
-			// 查询可变集合
-			// RecursiveUtil.print_variable_set("", Repository.objectData);
-
-			if (Constant.iot_websocket_url != null) {
-				log.warn("iot-websocket");
-				IOTWebSocketClient.client = new IOTWebSocketClient(new URI(Constant.iot_websocket_url + "?projectId="
-						+ RepositoryContainer.RepositoryBase.projectId.substring(2) + "&type=iot,text,pointset"));
-				IOTWebSocketClient.client.connect();
-				// while (!myClient.getReadyState().equals(READYSTATE.OPEN)) {
-				// Thread.sleep(1000L);
-				// log.info("连接中···请稍后");
-				// }
-				// log.info("连接成功");
-				Thread.sleep(1000L);
-			}
-			if (Constant.alarm_enable) {
-				log.warn("alarm-websocket");
-				AlarmWebSocketClient.client = new AlarmWebSocketClient(
-						new URI(Constant.alarm_websocket_url + "/" + RepositoryContainer.RepositoryBase.projectId));
-				AlarmWebSocketClient.client.connect();
-				// while (!myClient.getReadyState().equals(READYSTATE.OPEN)) {
-				// Thread.sleep(1000L);
-				// log.info("连接中···请稍后");
-				// }
-				// log.info("连接成功");
+		// 初始加载后break
+		while (!stop) {
+			try {
 				Thread.sleep(1000L);
+			} catch (InterruptedException e1) {
+				e1.printStackTrace();
 			}
 
-			while (!stop) {
-				try {
-					Thread.sleep(1000 * 60 * 5);
-				} catch (Exception e) {
-					log.error(e.getMessage(), e);
+			boolean dir_all_valid = true;
+			String tmp_config = null;
+			{
+				tmp_config = Constant.getLatestPath(Constant.config, false, false);
+				if (tmp_config == null) {
+					dir_all_valid = false;
+				}
+			}
+			String tmp_physical_world = null;
+			{
+				tmp_physical_world = Constant.getLatestPath(Constant.physical_world, true, false);
+				if (tmp_physical_world == null) {
+					dir_all_valid = false;
 				}
+			}
+			String tmp_zkt_physical_world = null;
+			if (Constant.zkt_physical_world_enable) {
+				tmp_zkt_physical_world = Constant.getLatestPath(Constant.zkt_physical_world, true, false);
+				if (tmp_zkt_physical_world == null) {
+					dir_all_valid = false;
+				}
+			}
+			String tmp_ibms_physical_world = null;
+			if (Constant.ibms_physical_world_enable) {
+				tmp_ibms_physical_world = Constant.getLatestPath(Constant.ibms_physical_world, true, false);
+				if (tmp_ibms_physical_world == null) {
+					dir_all_valid = false;
+				}
+			}
+			if (!dir_all_valid) {
+				continue;
+			}
+
+			log.warn("config: " + tmp_config);
+			log.warn("physical_world: " + tmp_physical_world);
+			if (Constant.zkt_physical_world_enable) {
+				log.warn("zkt_physical_world: " + tmp_zkt_physical_world);
+			}
+			if (Constant.ibms_physical_world_enable) {
+				log.warn("ibms_physical_world: " + tmp_ibms_physical_world);
+			}
+			try {
+				Constant.debug = false;// 调试模式设为true
+				RepositoryImpl Repository = new RepositoryImpl();
+				Repository.use_thread = !Constant.debug;
+				Repository.RepositoryBase = RepositoryContainer.RepositoryBase;
+				RWDRepositoryUtil.DoRepository(Repository, true);
+				RepositoryContainer.instance = Repository;
+				log.warn("compute finish");
+				path_config = tmp_config;
+				path_physical_world = tmp_physical_world;
+				path_zkt_physical_world = tmp_zkt_physical_world;
+				path_ibms_physical_world = tmp_ibms_physical_world;
+				DaemonThread.initialized = true;
+				// 查询可变集合
+				// RecursiveUtil.print_variable_set("", Repository.objectData);
 
-				try {
-					log.warn("refresh calendar start");
-					RWDLoadUtil.LoadCalendar(Repository);
-					log.warn("refresh calendar finish");
-				} catch (Exception e) {
-					log.error(e.getMessage(), e);
+				if (Constant.iot_websocket_url != null) {
+					log.warn("iot-websocket");
+					IOTWebSocketClient.client = new IOTWebSocketClient(new URI(Constant.iot_websocket_url + "?projectId="
+							+ RepositoryContainer.RepositoryBase.projectId.substring(2) + "&type=iot,text,pointset"));
+					IOTWebSocketClient.client.connect();
+					// while (!myClient.getReadyState().equals(READYSTATE.OPEN)) {
+					// Thread.sleep(1000L);
+					// log.info("连接中···请稍后");
+					// }
+					// log.info("连接成功");
+					Thread.sleep(1000L);
 				}
-				try {
-					log.warn("deamon start");
-					DeamonUtil.Process_deamon(Repository);
-					log.warn("deamon finish");
-				} catch (Exception e) {
-					log.error(e.getMessage(), e);
+				if (Constant.alarm_enable) {
+					log.warn("alarm-websocket");
+					AlarmWebSocketClient.client = new AlarmWebSocketClient(
+							new URI(Constant.alarm_websocket_url + "/" + RepositoryContainer.RepositoryBase.projectId));
+					AlarmWebSocketClient.client.connect();
+					// while (!myClient.getReadyState().equals(READYSTATE.OPEN)) {
+					// Thread.sleep(1000L);
+					// log.info("连接中···请稍后");
+					// }
+					// log.info("连接成功");
+					Thread.sleep(1000L);
 				}
+			} catch (Exception e) {
+				log.error(e.getMessage(), e);
+			}
+
+			if (DaemonThread.initialized) {
+				break;
+			}
+		}
+
+		// 周期性刷新
+		while (!stop) {
+			try {
+				Thread.sleep(1000 * 60 * 5);
+			} catch (Exception e) {
+				log.error(e.getMessage(), e);
+			}
+
+			RepositoryImpl Repository = RepositoryContainer.instance;
+			try {
+				log.warn("refresh calendar start");
+				RWDLoadUtil.LoadCalendar(Repository);
+				log.warn("refresh calendar finish");
+			} catch (Exception e) {
+				log.error(e.getMessage(), e);
+			}
+			try {
+				log.warn("deamon start");
+				DeamonUtil.Process_deamon(Repository);
+				log.warn("deamon finish");
+			} catch (Exception e) {
+				log.error(e.getMessage(), e);
 			}
-		} catch (Exception e) {
-			log.error(e.getMessage(), e);
 		}
 	}
 }

+ 103 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/DownloadThread_config.java

@@ -0,0 +1,103 @@
+package com.persagy.ibms.data.sdk.service;
+
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.annotation.PostConstruct;
+
+import org.springframework.stereotype.Component;
+
+import com.persagy.ibms.data.sdk.util.Constant;
+import com.persagy.ibms.data.sdk.util.FileUtil;
+import com.persagy.ibms.data.sdk.util.RWDDownloadUtil;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+@Component
+public class DownloadThread_config extends Thread {
+	@PostConstruct
+	public void init() {
+		new Thread(this).start();
+	}
+
+	private volatile boolean stop = false;
+
+	public void requestStop() {
+		stop = true;
+		try {
+			this.join();
+		} catch (InterruptedException e) {
+			log.error(e.getMessage(), e);
+		}
+	}
+
+	public void run() {
+		while (true) {
+			try {
+				Thread.sleep(1000L);
+			} catch (InterruptedException e) {
+				log.error(e.getMessage(), e);
+			}
+
+			if (DaemonThread.dir_already) {
+				break;
+			}
+		}
+
+		Date last_refresh_config = null;
+		while (!stop) {
+			try {
+				Thread.sleep(1000L);
+			} catch (InterruptedException e) {
+				log.error(e.getMessage(), e);
+			}
+
+			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) {
+							String validPath = Constant.getLatestPath(Constant.config, false, false);
+							log.warn("config check end " + validPath);
+						} else {
+							log.warn("config check end");
+						}
+					}
+					last_refresh_config = currTime;
+				}
+			} catch (Exception e) {
+				log.error(e.getMessage(), e);
+			}
+		}
+	}
+
+	private boolean Process_config() throws Exception {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+		String validPath = Constant.getLatestPath(Constant.config, false);
+		File valid = new File(validPath);
+
+		String tmpPath = Constant.config + Constant.getSeperator() + "tmp" + ".json";
+		RWDDownloadUtil.LoadConfig(tmpPath);
+		File tmp = new File(tmpPath);
+
+		boolean compare_valid = FileUtil.compareRecursive(valid, tmp);
+		boolean result;
+		if (!compare_valid) {
+			Date currTime = new Date();
+			tmp.renameTo(new File(Constant.config + Constant.getSeperator() + sdf.format(currTime) + ".json"));
+			result = true;
+		} else {
+			result = false;
+		}
+		if (Constant.clear_old_dir) {
+			RWDDownloadUtil.Clear(Constant.config, false);
+		}
+		return result;
+	}
+}

+ 76 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/DownloadThread_ibms.java

@@ -0,0 +1,76 @@
+package com.persagy.ibms.data.sdk.service;
+
+import java.util.Date;
+
+import javax.annotation.PostConstruct;
+
+import org.springframework.stereotype.Component;
+
+import com.persagy.ibms.data.sdk.util.Constant;
+import com.persagy.ibms.data.sdk.util.RWDDownloadUtil;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+@Component
+public class DownloadThread_ibms extends Thread {
+	@PostConstruct
+	public void init() {
+		new Thread(this).start();
+	}
+
+	private volatile boolean stop = false;
+
+	public void requestStop() {
+		stop = true;
+		try {
+			this.join();
+		} catch (InterruptedException e) {
+			log.error(e.getMessage(), e);
+		}
+	}
+
+	public void run() {
+		while (true) {
+			try {
+				Thread.sleep(1000L);
+			} catch (InterruptedException e) {
+				log.error(e.getMessage(), e);
+			}
+
+			if (DaemonThread.dir_already) {
+				break;
+			}
+		}
+
+		Date last_refresh_ibms_physical_world = null;
+		while (!stop) {
+			try {
+				Thread.sleep(1000L);
+			} catch (InterruptedException e) {
+				log.error(e.getMessage(), e);
+			}
+
+			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) {
+							String validPath = Constant.getLatestPath(Constant.ibms_physical_world, true, false);
+							log.warn("ibms_physical_world check end " + validPath);
+						} else {
+							log.warn("ibms_physical_world check end");
+						}
+					}
+					last_refresh_ibms_physical_world = currTime;
+				}
+			} catch (Exception e) {
+				log.error(e.getMessage(), e);
+			}
+		}
+	}
+}

+ 91 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/DownloadThread_rwd.java

@@ -0,0 +1,91 @@
+package com.persagy.ibms.data.sdk.service;
+
+import java.util.Date;
+
+import javax.annotation.PostConstruct;
+
+import org.springframework.stereotype.Component;
+
+import com.persagy.ibms.data.sdk.util.Constant;
+import com.persagy.ibms.data.sdk.util.RWDDownloadUtil;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+@Component
+public class DownloadThread_rwd extends Thread {
+	@PostConstruct
+	public void init() {
+		new Thread(this).start();
+	}
+
+	private volatile boolean stop = false;
+
+	public void requestStop() {
+		stop = true;
+		try {
+			this.join();
+		} catch (InterruptedException e) {
+			log.error(e.getMessage(), e);
+		}
+	}
+
+	public void run() {
+		while (true) {
+			try {
+				Thread.sleep(1000L);
+			} catch (InterruptedException e) {
+				log.error(e.getMessage(), e);
+			}
+
+			if (DaemonThread.dir_already) {
+				break;
+			}
+		}
+
+		Date last_refresh_physical_world = null;
+		Date last_refresh_zkt_physical_world = null;
+		while (!stop) {
+			try {
+				Thread.sleep(1000L);
+			} catch (InterruptedException e) {
+				log.error(e.getMessage(), e);
+			}
+
+			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) {
+							String validPath = Constant.getLatestPath(Constant.physical_world, true, false);
+							log.warn("physical_world check end " + validPath);
+						} else {
+							log.warn("physical_world check end");
+						}
+					}
+					last_refresh_physical_world = currTime;
+				}
+				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) {
+							String validPath = Constant.getLatestPath(Constant.zkt_physical_world, true, false);
+							log.warn("zkt_physical_world check end " + validPath);
+						} else {
+							log.warn("zkt_physical_world check end");
+						}
+					}
+					last_refresh_zkt_physical_world = currTime;
+				}
+			} catch (Exception e) {
+				log.error(e.getMessage(), e);
+			}
+		}
+	}
+}

+ 71 - 62
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/RefreshThread.java

@@ -1,16 +1,10 @@
 package com.persagy.ibms.data.sdk.service;
 
-import java.io.File;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
 import javax.annotation.PostConstruct;
 
 import org.springframework.stereotype.Component;
 
 import com.persagy.ibms.data.sdk.util.Constant;
-import com.persagy.ibms.data.sdk.util.FileUtil;
-import com.persagy.ibms.data.sdk.util.RWDDownloadUtil;
 import com.persagy.ibms.data.sdk.util.RWDRepositoryUtil;
 import com.persagy.ibms.data.sdk.util.RepositoryContainer;
 import com.persagy.ibms.data.sdk.util.RepositoryImpl;
@@ -27,6 +21,11 @@ public class RefreshThread extends Thread {
 
 	private volatile boolean stop = false;
 
+	String path_config;
+	String path_physical_world;
+	String path_zkt_physical_world;
+	String path_ibms_physical_world;
+
 	public void requestStop() {
 		stop = true;
 		try {
@@ -44,15 +43,16 @@ public class RefreshThread extends Thread {
 				log.error(e.getMessage(), e);
 			}
 
-			if (RepositoryContainer.RepositoryBase.compute_finish) {
+			if (DaemonThread.initialized) {
 				break;
 			}
 		}
 
-		Date last_refresh_config = null;
-		Date last_refresh_physical_world = null;
-		Date last_refresh_zkt_physical_world = null;
-		Date last_refresh_ibms_physical_world = null;
+		this.path_config = DaemonThread.path_config;
+		this.path_physical_world = DaemonThread.path_physical_world;
+		this.path_zkt_physical_world = DaemonThread.path_zkt_physical_world;
+		this.path_ibms_physical_world = DaemonThread.path_ibms_physical_world;
+
 		while (!stop) {
 			try {
 				Thread.sleep(1000L);
@@ -60,37 +60,64 @@ public class RefreshThread extends Thread {
 				log.error(e.getMessage(), e);
 			}
 
-			Date currTime = new Date();
-			try {
-				boolean changed_config = false;
-				if (last_refresh_config == null || currTime.getTime() - last_refresh_config.getTime() > 1000L * 15) {
-					if (Constant.config_refresh_enable) {
-						changed_config = Process_config();
-					}
-					last_refresh_config = currTime;
+			boolean changed_config = false;
+			boolean changed_physical_world = false;
+			boolean changed_zkt_physical_world = false;
+			boolean changed_ibms_physical_world = false;
+			String tmp_config = null;
+			{
+				tmp_config = Constant.getLatestPath(Constant.config, false, false);
+				if (tmp_config != null && tmp_config.compareTo(this.path_config) > 0) {
+					changed_config = true;
+				}
+			}
+			String tmp_physical_world = null;
+			{
+				tmp_physical_world = Constant.getLatestPath(Constant.physical_world, true, false);
+				if (tmp_physical_world != null && tmp_physical_world.compareTo(this.path_physical_world) > 0) {
+					changed_physical_world = true;
+				}
+			}
+			String tmp_zkt_physical_world = null;
+			if (Constant.zkt_physical_world_enable) {
+				tmp_zkt_physical_world = Constant.getLatestPath(Constant.zkt_physical_world, true, false);
+				if (tmp_zkt_physical_world != null && tmp_zkt_physical_world.compareTo(this.path_zkt_physical_world) > 0) {
+					changed_zkt_physical_world = true;
+				}
+			}
+			String tmp_ibms_physical_world = null;
+			if (Constant.ibms_physical_world_enable) {
+				tmp_ibms_physical_world = Constant.getLatestPath(Constant.ibms_physical_world, true, false);
+				if (tmp_ibms_physical_world != null && tmp_ibms_physical_world.compareTo(this.path_ibms_physical_world) > 0) {
+					changed_ibms_physical_world = true;
 				}
-				boolean changed_physical_world = false;
-				if (last_refresh_physical_world == null || currTime.getTime() - last_refresh_physical_world.getTime() > 1000L * 60 * 60) {
-					if (Constant.physical_world_refresh_enable) {
-						changed_physical_world = RWDDownloadUtil.Process_physical_world();
-					}
-					last_refresh_physical_world = currTime;
+			}
+
+			if (changed_config || changed_physical_world || changed_zkt_physical_world || changed_ibms_physical_world) {
+				if (changed_config) {
+					log.warn("config: " + this.path_config + " -> " + tmp_config);
+				}
+				if (changed_physical_world) {
+					log.warn("physical_world: " + this.path_physical_world + " -> " + tmp_physical_world);
 				}
-				boolean changed_zkt_physical_world = false;
-				if (last_refresh_zkt_physical_world == null || currTime.getTime() - last_refresh_zkt_physical_world.getTime() > 1000L * 60 * 60) {
-					if (Constant.zkt_physical_world_enable && Constant.zkt_physical_world_refresh_enable) {
-						changed_zkt_physical_world = RWDDownloadUtil.Process_zkt_physical_world();
-					}
-					last_refresh_zkt_physical_world = currTime;
+				if (changed_zkt_physical_world) {
+					log.warn("zkt_physical_world: " + this.path_zkt_physical_world + " -> " + tmp_zkt_physical_world);
 				}
-				boolean changed_ibms_physical_world = false;
-				if (last_refresh_ibms_physical_world == null || currTime.getTime() - last_refresh_ibms_physical_world.getTime() > 1000L * 60 * 60) {
-					if (Constant.ibms_physical_world_enable && Constant.ibms_physical_world_refresh_enable) {
-						changed_ibms_physical_world = RWDDownloadUtil.Process_ibms_physical_world();
-					}
-					last_refresh_ibms_physical_world = currTime;
+				if (changed_ibms_physical_world) {
+					log.warn("ibms_physical_world: " + this.path_ibms_physical_world + " -> " + tmp_ibms_physical_world);
+				}
+				this.path_config = tmp_config;
+				this.path_physical_world = tmp_physical_world;
+				this.path_zkt_physical_world = tmp_zkt_physical_world;
+				this.path_ibms_physical_world = tmp_ibms_physical_world;
+
+				try {
+					Thread.sleep(1000L);
+				} catch (InterruptedException e) {
+					log.error(e.getMessage(), e);
 				}
-				if (changed_config || changed_physical_world || changed_zkt_physical_world || changed_ibms_physical_world) {
+
+				try {
 					log.warn("recompute begin");
 					RepositoryImpl Repository = new RepositoryImpl();
 					Repository.use_thread = !Constant.debug;
@@ -98,32 +125,14 @@ public class RefreshThread extends Thread {
 					RWDRepositoryUtil.DoRepository(Repository, changed_physical_world || changed_zkt_physical_world || changed_ibms_physical_world);
 					RepositoryContainer.instance = Repository;
 					log.warn("recompute finish");
+					DaemonThread.path_config = this.path_config;
+					DaemonThread.path_physical_world = this.path_physical_world;
+					DaemonThread.path_zkt_physical_world = this.path_zkt_physical_world;
+					DaemonThread.path_ibms_physical_world = this.path_ibms_physical_world;
+				} catch (Exception e) {
+					log.error(e.getMessage(), e);
 				}
-			} catch (Exception e) {
-				log.error(e.getMessage(), e);
 			}
 		}
 	}
-
-	private boolean Process_config() throws Exception {
-		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
-		String validPath = Constant.getLatestPath(Constant.config, false);
-		File valid = new File(validPath);
-
-		String tmpPath = Constant.config + Constant.getSeperator() + "tmp" + ".json";
-		RWDDownloadUtil.LoadConfig(tmpPath);
-		File tmp = new File(tmpPath);
-
-		boolean compare_valid = FileUtil.compareRecursive(valid, tmp);
-		boolean result;
-		if (!compare_valid) {
-			Date currTime = new Date();
-			tmp.renameTo(new File(Constant.config + Constant.getSeperator() + sdf.format(currTime) + ".json"));
-			result = true;
-		} else {
-			result = false;
-		}
-		RWDDownloadUtil.Clear(Constant.config, false);
-		return result;
-	}
 }

+ 32 - 10
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/Constant.java

@@ -26,21 +26,26 @@ import lombok.extern.slf4j.Slf4j;
 public class Constant {
 	public static boolean test = false;
 	public static boolean debug = false;
+	public static boolean clear_old_dir = true;
 
 	public static String sdk_version;
 	public static String rwd_url;
 	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 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 String config;
-	public static boolean config_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;
@@ -109,11 +114,19 @@ public class Constant {
 					zkt_control_url = element.attribute("url").getValue();
 					zkt_control_url = StrUtil.removeSuffix(zkt_control_url, "/");
 				}
+				iter = document.selectNodes("/root/config").iterator();
+				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());
+				}
 				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());
 				}
 				iter = document.selectNodes("/root/zkt_physical_world").iterator();
 				if (iter.hasNext()) {
@@ -121,6 +134,7 @@ public class Constant {
 					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());
 				}
 				iter = document.selectNodes("/root/ibms_physical_world").iterator();
 				if (iter.hasNext()) {
@@ -128,12 +142,7 @@ public class Constant {
 					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());
-				}
-				iter = document.selectNodes("/root/config").iterator();
-				if (iter.hasNext()) {
-					element = (Element) iter.next();
-					config = element.attribute("path").getValue();
-					config_refresh_enable = Boolean.parseBoolean(element.attribute("refresh_enable").getValue());
+					ibms_physical_world_refresh_interval_second = Long.parseLong(element.attribute("refresh_interval_second").getValue());
 				}
 				iter = document.selectNodes("/root/info_point").iterator();
 				if (iter.hasNext()) {
@@ -240,6 +249,11 @@ public class Constant {
 	}
 
 	public static String getLatestPath(String parentPath, boolean return_dir) {
+		String result = getLatestPath(parentPath, return_dir, true);
+		return result;
+	}
+
+	public static String getLatestPath(String parentPath, boolean return_dir, boolean return_full) {
 		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
 		File file = new File(parentPath);
 		if (file.isDirectory()) {
@@ -259,7 +273,11 @@ public class Constant {
 				if (nameList.size() > 0) {
 					Collections.sort(nameList);
 					Collections.reverse(nameList);
-					return parentPath + getSeperator() + nameList.get(0);
+					if (return_full) {
+						return parentPath + getSeperator() + nameList.get(0);
+					} else {
+						return nameList.get(0);
+					}
 				}
 			} else {
 				List<String> nameList = new ArrayList<String>();
@@ -279,7 +297,11 @@ public class Constant {
 				if (nameList.size() > 0) {
 					Collections.sort(nameList);
 					Collections.reverse(nameList);
-					return parentPath + getSeperator() + nameList.get(0) + ".json";
+					if (return_full) {
+						return parentPath + getSeperator() + nameList.get(0) + ".json";
+					} else {
+						return nameList.get(0);
+					}
 				}
 			}
 		}

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

@@ -99,7 +99,9 @@ public class RWDDownloadUtil {
 		} else {
 			result = false;
 		}
-		Clear(Constant.physical_world, true);
+		if (Constant.clear_old_dir) {
+			Clear(Constant.physical_world, true);
+		}
 		return result;
 	}
 
@@ -275,7 +277,9 @@ public class RWDDownloadUtil {
 		} else {
 			result = false;
 		}
-		Clear(Constant.zkt_physical_world, true);
+		if (Constant.clear_old_dir) {
+			Clear(Constant.zkt_physical_world, true);
+		}
 		return result;
 	}
 
@@ -448,7 +452,7 @@ public class RWDDownloadUtil {
 
 	public static boolean Process_ibms_physical_world() throws Exception {
 		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
-		String validPath = Constant.getLatestPath(Constant.zkt_physical_world, true);
+		String validPath = Constant.getLatestPath(Constant.ibms_physical_world, true);
 		// 存储临时文件
 		File dir1;
 		{
@@ -491,7 +495,9 @@ public class RWDDownloadUtil {
 		} else {
 			result = false;
 		}
-		Clear(Constant.ibms_physical_world, true);
+		if (Constant.clear_old_dir) {
+			Clear(Constant.ibms_physical_world, true);
+		}
 		return result;
 	}
 

+ 5 - 8
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RWDLoadUtil.java

@@ -97,12 +97,12 @@ public class RWDLoadUtil {
 					SceneDataSet SceneDataSet = new SceneDataSet(false);
 					SceneDataSet.set = RWDUtil.array2SDOList(array);
 					infoArrayDic.put(code, SceneDataSet);
-					infoJsonArray.put(code,array);
+					infoJsonArray.put(code, array);
 				} catch (Exception e) {
 					log.warn(e.getMessage(), e);
 				}
 			}
-			Repository.infoArrayJson= infoJsonArray;
+			Repository.infoArrayJson = infoJsonArray;
 			Repository.infoArrayDic = infoArrayDic;
 		}
 
@@ -713,8 +713,7 @@ public class RWDLoadUtil {
 				SceneDataSet SceneDataSet_level1 = new SceneDataSet(false);
 				SceneDataSet_level1.set = RWDUtil.array2SDOList(level1);
 				arrayDic.put("一级编组", SceneDataSet_level1);
-				FileUtil.Save(validPath + Constant.getSeperator() + product + Constant.getSeperator() + "一级编组" + ".json",
-						FastJsonUtil.toFormatString(level1));
+				FileUtil.Save("一级编组" + ".json", FastJsonUtil.toFormatString(level1));
 				// 自动生成二级编组
 				JSONArray level2 = new JSONArray();
 				for (SceneDataObject sdo : Repository.IBMSGroupArray.set) {
@@ -747,8 +746,7 @@ public class RWDLoadUtil {
 				SceneDataSet SceneDataSet_level2 = new SceneDataSet(false);
 				SceneDataSet_level2.set = RWDUtil.array2SDOList(level2);
 				arrayDic.put("二级编组", SceneDataSet_level2);
-				FileUtil.Save(validPath + Constant.getSeperator() + product + Constant.getSeperator() + "二级编组" + ".json",
-						FastJsonUtil.toFormatString(level2));
+				FileUtil.Save("二级编组" + ".json", FastJsonUtil.toFormatString(level2));
 				// 自动生成回路
 				SceneDataSet zhaominghuilu = arrayDic.get("zhaominghuilu");
 				if (zhaominghuilu == null) {
@@ -832,8 +830,7 @@ public class RWDLoadUtil {
 				SceneDataSet huilu = new SceneDataSet(false);
 				huilu.set = RWDUtil.array2SDOList(huiluArray);
 				arrayDic.put("回路", huilu);
-				FileUtil.Save(validPath + Constant.getSeperator() + product + Constant.getSeperator() + "回路" + ".json",
-						FastJsonUtil.toFormatString(huiluArray));
+				FileUtil.Save("回路" + ".json", FastJsonUtil.toFormatString(huiluArray));
 
 				for (SceneDataObject sdo : huilu.set) {
 					String id = (String) sdo.get("回路编号").value_prim.value;

+ 1 - 1
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RepositoryContainer.java

@@ -2,5 +2,5 @@ package com.persagy.ibms.data.sdk.util;
 
 public class RepositoryContainer {
 	public static RepositoryProject RepositoryBase = new RepositoryProject();
-	public static RepositoryImpl instance = new RepositoryImpl();
+	public static RepositoryImpl instance;
 }

+ 0 - 3
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RepositoryProject.java

@@ -10,9 +10,6 @@ import com.persagy.ibms.core.data.SceneDataSet;
 import com.persagy.ibms.core.data.SceneDataValue;
 
 public class RepositoryProject {
-
-	public boolean compute_finish = false;
-
 	public String groupCode;
 	public String projectId;
 

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

@@ -5,10 +5,10 @@
 	<sdk_version>SDK-D</sdk_version>
 	<!-- zkt-dmp的服务地址 -->
 	<rwd url="http://192.168.100.33:9976/" />
-	<config path="D-config" refresh_enable="true" />
-	<physical_world path="D-physical_world" refresh_enable="true" />
-	<zkt_physical_world path="D-zkt_physical_world" enable="true" refresh_enable="true" />
-	<ibms_physical_world path="D-ibms_physical_world" enable="true" refresh_enable="true" />
+	<config path="D-config" refresh_enable="true" refresh_interval_second="60" />
+	<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" />
 	<!-- zkt-monitor的服务地址 -->
 	<zkt_monitor url="http://192.168.100.33:9909/zkt-monitor/" />
@@ -45,7 +45,7 @@
 	<ConfigRelation graphCode="ValveRelationship" relCode="Vv2Eq" objFrom="equipment" objTo="equipment" nameInFrom="限制设备" multiplicityFrom="n" nameInTo="被设备限制" multiplicityTo="n" />
 	<ConfigRelation graphCode="ArchForArch" relCode="Sp2Sp" objFrom="space" objTo="space" nameInFrom="服务于空间" multiplicityFrom="n" nameInTo="被空间服务" multiplicityTo="n" />
 
-	<!-- 中转服务的编码、请求类型、url服务地址(根据实际情况添加)-->
+	<!-- 中转服务的编码、请求类型、url服务地址(根据实际情况添加) -->
 	<Redirect code="获取报警时长" http_request_type="get" url="http://39.102.43.179:9982/alarmTime/query">
 		<!-- 中转服务的header,有几项就写几行 -->
 		<header key="Content-Type" value="application/json" />