From 4513ef24bf9b188c2a77d6ce94f1a6b7e9ebf0e6 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期日, 27 四月 2025 20:40:19 +0800
Subject: [PATCH] fix(irrigatePlan): 修正灌溉计划开始时间逻辑

---
 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/Config.java |  125 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 125 insertions(+), 0 deletions(-)

diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/Config.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/Config.java
new file mode 100644
index 0000000..a1ba3a0
--- /dev/null
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/Config.java
@@ -0,0 +1,125 @@
+package com.dy.common.util;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import org.jdom2.Document;
+import org.jdom2.Element;
+import org.jdom2.input.SAXBuilder;
+
+@SuppressWarnings("unused")
+public class Config {
+
+	private static HashMap<String, String> configs;
+	private static Config config;
+	
+	/**
+	 * 寰楀埌鍞竴瀹炰緥
+	 * @return 杩斿洖瀹炰緥
+	 */
+	public static Config getInstance() {
+		if (config == null) {
+			config = new Config();
+			configs = new HashMap<>();
+		}
+		return config;
+	}
+	    
+	private Config() {
+	}
+	/**
+	 * 鏍规嵁閰嶇疆鍚嶇О寰楀埌閰嶇疆鍊�
+	 * @param name 閰嶇疆鍚嶇О
+	 * @return 閰嶇疆鍊�
+	 */
+	public static String getConfig(String name) {
+		if (configs == null) {
+			return null;
+		}
+		if(name.trim().equals("")){
+			return "" ;
+		}
+		return configs.get(name);
+	}
+
+	/**
+	 * 鍒濆鍖栭厤缃�
+	 * @param fileUrl 閰嶇疆鏂囦欢璺緞
+	 * @throws Exception 鎶涘嚭寮傚父
+	 */
+	public void init(URL fileUrl) throws Exception {
+		parseConfig(createDom(fileUrl));		
+	}
+	/**
+	 * 閲嶆柊鍒濆鍖�
+	 * @param fileUrl 閰嶇疆鏂囦欢璺緞
+	 * @param propertiesInput 灞炴�ф枃浠惰緭鍏ユ祦
+	 * @throws Exception 鎶涘嚭寮傚父
+	 */
+	public void reInit(URL fileUrl, InputStream propertiesInput) throws Exception {
+		configs = new HashMap<>();
+		parseConfig(createDom(fileUrl));
+	}
+
+	/**
+	 * 鍒涘缓dom瀵硅薄
+	 * @param configFileURL 閰嶇疆鏂囦欢璺緞
+	 * @return dom瀵硅薄
+	 */
+	private Document createDom(URL configFileURL) throws Exception {
+		if (configFileURL == null) {
+			throw new Exception("娌℃湁寰楀埌閰嶇疆鏂囦欢!", null);
+		}
+		Document doc = null;
+		try {
+			SAXBuilder sb = new SAXBuilder();
+			doc = sb.build(configFileURL);
+			if (doc == null) {
+				throw new Exception("娌℃湁鐢熸垚閰嶇疆鏂囦欢鐨凞OM瀵硅薄!", null);
+			}
+		} catch (Exception e) {
+			throw new Exception("鐢熸垚閰嶇疆鏂囦欢鐨凞OM瀵硅薄澶辫触!", e);
+		}
+		return doc;
+	}
+
+	/**
+	 * 鍒嗘瀽鏈嶅姟鍣ㄨ繍琛屽弬鏁�
+	 * @param doc dom瀵硅薄
+	 * @throws Exception 鎶涘嚭寮傚父
+	 */
+	private void parseConfig(Document doc) throws Exception {
+		Element root = doc.getRootElement();
+		if (root == null) {
+			throw new Exception("娌℃湁寰楀埌閰嶇疆鏂囦欢鏍瑰厓绱燾onfig!");
+		}
+		List<Element> list = root.getChildren();
+		if (list == null) {
+			throw new Exception("閰嶇疆鏂囦欢娌℃湁閰嶇疆鍏冪礌!");
+		}
+		Iterator<Element> it = list.iterator();
+		Element e ;
+		String name ;
+		String tx ;
+		while (it.hasNext()) {
+			e = it.next();
+			if (e == null) {
+				throw new Exception("寰楀埌閰嶇疆鏂囦欢涓厓绱犻厤缃嚭閿�!");
+			}
+			name = e.getName();
+			if (configs.get(name) != null) {
+				throw new Exception("閰嶇疆鏂囦欢涓厓绱�" + name + "閲嶅悕锛�");
+			}
+			tx = e.getText();
+
+			if(tx != null && tx.startsWith("${") && tx.endsWith("}")){
+				tx = tx.substring(2, tx.length() - 1) ;
+				tx = ConfigProperties.getConfig(tx) ;
+			}
+			configs.put(name, tx);	
+		}
+	}
+}

--
Gitblit v1.8.0