Browse Source

增加base_value,里面增加几个日期定时刷新

menglu 3 years ago
parent
commit
29b7c98a35

+ 1 - 1
ibms-data-sdk/pom.xml

@@ -220,7 +220,7 @@
 		<dependency>
 			<groupId>com.persagy</groupId>
 			<artifactId>sailfish</artifactId>
-			<version>0.0.46</version>
+			<version>0.0.47</version>
 		</dependency>
 	</dependencies>
 

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

@@ -4,12 +4,14 @@ import java.io.File;
 import java.net.URI;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import javax.annotation.PostConstruct;
 
 import org.springframework.stereotype.Component;
 
+import com.persagy.ibms.core.data.SceneDataValue;
 import com.persagy.ibms.core.util.KeywordUtil;
 import com.persagy.ibms.core.util.LogOfDownload;
 import com.persagy.ibms.core.util.LogOfRun;
@@ -261,6 +263,18 @@ public class DaemonThread extends Thread {
 			}
 
 			RepositoryImpl Repository = RepositoryContainer.instance;
+
+			// base_value
+			Map<String, SceneDataValue> base_value_new = RepositoryImpl.generate_base_value();
+			for (String key : Repository.base_value.keySet()) {
+				SceneDataValue sdv = Repository.base_value.get(key);
+				SceneDataValue sdv_new = base_value_new.get(key);
+				if (!sdv_new.value_prim.value.equals(sdv.value_prim.value)) {
+					sdv.value_prim.value = sdv_new.value_prim.value;
+					Repository.addWaitCompute(sdv);
+				}
+			}
+
 			log.warn("********************************" + "\t" + "refresh calendar start");
 			try {
 				RWDLoadUtil.Read_calendar(Repository);

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

@@ -1,6 +1,8 @@
 package com.persagy.ibms.data.sdk.util;
 
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -83,6 +85,92 @@ public class RepositoryImpl extends RepositoryBase {
 			long interval_between_compute) {
 		super(use_thread, enable_factor, thread_count, interval_between_compute);
 		this.RepositoryProject = RepositoryProject;
+		this.base_value = generate_base_value();
+	}
+
+	public static boolean accelerate_enable = false;
+	public static long accelerate_ratio = 60 * 60 * 24;
+	public static String init_timeString = "2021-01-01 00:00:00";
+	public static Date init_time;
+	public static Date start_time;
+
+	public static Map<String, SceneDataValue> generate_base_value() {
+		Map<String, SceneDataValue> base_value = new ConcurrentHashMap<String, SceneDataValue>();
+		Calendar calendar = Calendar.getInstance();
+		Map<String, Date> timeMap = new ConcurrentHashMap<String, Date>();
+		Map<String, SimpleDateFormat> sdfMap = new ConcurrentHashMap<String, SimpleDateFormat>();
+		sdfMap.put("simple", new SimpleDateFormat("yyyyMMddHHmmss"));
+		sdfMap.put("normal", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
+		sdfMap.put("T", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
+
+		Date currTime = new Date();
+		if (accelerate_enable) {
+			if (init_time == null) {
+				try {
+					init_time = sdfMap.get("normal").parse(init_timeString);
+				} catch (ParseException e) {
+				}
+			}
+
+			if (start_time == null) {
+				start_time = currTime;
+			}
+
+			currTime = new Date(init_time.getTime() + (currTime.getTime() - start_time.getTime()) * accelerate_ratio);
+		}
+		Date today = new Date((currTime.getTime() + (1000L * 60 * 60 * 8)) / (1000L * 60 * 60 * 24) * (1000L * 60 * 60 * 24) - (1000L * 60 * 60 * 8));
+		{
+			calendar.setTime(today);
+			timeMap.put("curr_day", calendar.getTime());
+			calendar.add(Calendar.DAY_OF_MONTH, -1);
+			timeMap.put("last_day", calendar.getTime());
+			calendar.add(Calendar.DAY_OF_MONTH, +1);
+			calendar.add(Calendar.DAY_OF_MONTH, +1);
+			timeMap.put("next_day", calendar.getTime());
+		}
+		{
+			calendar.setTime(today);
+			calendar.set(Calendar.DAY_OF_WEEK, 1);
+			timeMap.put("curr_week", calendar.getTime());
+			calendar.add(Calendar.WEEK_OF_MONTH, -1);
+			timeMap.put("last_week", calendar.getTime());
+			calendar.add(Calendar.WEEK_OF_MONTH, +1);
+			calendar.add(Calendar.WEEK_OF_MONTH, +1);
+			timeMap.put("next_week", calendar.getTime());
+		}
+		{
+			calendar.setTime(today);
+			calendar.set(Calendar.DAY_OF_MONTH, 1);
+			timeMap.put("curr_month", calendar.getTime());
+			calendar.add(Calendar.MONTH, -1);
+			timeMap.put("last_month", calendar.getTime());
+			calendar.add(Calendar.MONTH, +1);
+			calendar.add(Calendar.MONTH, +1);
+			timeMap.put("next_month", calendar.getTime());
+		}
+		{
+			calendar.setTime(today);
+			calendar.set(Calendar.DAY_OF_MONTH, 1);
+			calendar.set(Calendar.MONTH, 0);
+			timeMap.put("curr_year", calendar.getTime());
+			calendar.add(Calendar.YEAR, -1);
+			timeMap.put("last_year", calendar.getTime());
+			calendar.add(Calendar.YEAR, +1);
+			calendar.add(Calendar.YEAR, +1);
+			timeMap.put("next_year", calendar.getTime());
+		}
+
+		for (String key : timeMap.keySet()) {
+			for (String sdfKey : sdfMap.keySet()) {
+				SimpleDateFormat sdf = sdfMap.get(sdfKey);
+				SceneDataValue SceneDataValue = new SceneDataValue(null, null, null, null);
+				SceneDataValue.value_prim = new SceneDataPrimitive();
+				SceneDataValue.value_prim.change = true;
+				SceneDataValue.value_prim.value = sdf.format(timeMap.get(key));
+				base_value.put(key + "_" + sdfKey, SceneDataValue);
+			}
+		}
+		return base_value;
 	}
 
 	public void copyFromRepositoryContainer() {