From 64f046ed41c2ae607dc065c82b6d454f64e90584 Mon Sep 17 00:00:00 2001
From: whyclxw <810412026@qq.com>
Date: 星期四, 19 六月 2025 21:52:33 +0800
Subject: [PATCH] 预警分析管理-电源告警

---
 src/main/java/com/whyc/util/ActionUtil.java |   78 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 73 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/whyc/util/ActionUtil.java b/src/main/java/com/whyc/util/ActionUtil.java
index 2d8a998..13cab65 100644
--- a/src/main/java/com/whyc/util/ActionUtil.java
+++ b/src/main/java/com/whyc/util/ActionUtil.java
@@ -17,9 +17,9 @@
 import java.lang.reflect.Type;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Locale;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import com.whyc.pojo.db_user.User;
@@ -28,6 +28,8 @@
 
 	public static String time_yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss";
 	public static String time_yyyyMMdd = "yyyy-MM-dd";
+	public static String time_yyyyMM = "yyyy-MM";
+	public static String time_yyyy_MM = "yyyy_MM";
 	public static String time_yyyyMMdd_HH_mm_ss = "yyyy-MM-dd_HH_mm_ss";
 	public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 	public static SimpleDateFormat sdfwithOutday = new SimpleDateFormat("yyyy_MM");
@@ -417,8 +419,34 @@
         } else {//鐩哥瓑
             return 0;
         }
-        }
-    /**
+	}
+	//璁$畻褰撳墠鏈堢殑涓婁竴涓搴﹀勾_鏈堜唤闆嗗悎
+	public static List<String> getLastQuarterYearMonths() {
+		LocalDate currentDate = LocalDate.now();
+		int currentYear = currentDate.getYear();
+		int currentMonth = currentDate.getMonthValue();
+
+		int quarter = (currentMonth - 1) / 3 + 1; // 璁$畻褰撳墠瀛e害
+		int lastQuarter = quarter - 1; // 涓婁竴瀛e害
+
+		if (lastQuarter == 0) {
+			lastQuarter = 4; // 濡傛灉褰撳墠鏄涓�瀛e害锛屽垯涓婁竴瀛e害涓虹鍥涘搴�
+		}
+
+		List<String> yearMonths = new ArrayList<>();
+		for (int i = 1; i <= 3; i++) {
+			int month = (lastQuarter - 1) * 3 + i;
+			int year = currentYear;
+			// 濡傛灉涓婁竴瀛e害鏄鍥涘搴︼紝鍒欏勾浠介渶瑕佸噺涓�骞�
+			if (lastQuarter == 4) {
+				year = currentYear - 1;
+			}
+			yearMonths.add(year + "_" + (month < 10 ? "0" + month : month)); // 淇濊瘉鏈堜唤涓轰袱浣嶆牸寮�
+		}
+
+		return yearMonths;
+	}
+	/**
      * @Description: 鏍规嵁鍥剧墖鍦板潃杞崲涓篵ase64缂栫爜瀛楃涓�
      * @Author: 
      * @CreateTime: 
@@ -612,5 +640,45 @@
 		}
 		return lang;
 	}
+     //涓ゆ椂闂翠箣闂寸殑骞存湀闆嗗悎
+	public static List<String> getDateListBetweenDates(Date startTime, Date endTime) {
+		// 鎸囧畾寮�濮嬫棩鏈熷拰缁撴潫鏃ユ湡
+		LocalDate startDate = LocalDate.of(startTime.getYear() + 1900, startTime.getMonth() + 1, startTime.getDay()); // 绀轰緥璧峰鏃ユ湡
+		LocalDate endDate = LocalDate.of(endTime.getYear() + 1900, endTime.getMonth() + 1, endTime.getDay());  // 绀轰緥缁撴潫鏃ユ湡
 
+		List<String> dateList = new ArrayList<>();
+		LocalDate currentDate = startDate;
+		DateTimeFormatter formatter = DateTimeFormatter.ofPattern(ActionUtil.time_yyyy_MM);
+		while (!currentDate.isAfter(endDate)) {
+			String formattedDate = currentDate.format(formatter);
+			dateList.add(formattedDate);
+			currentDate = currentDate.plusMonths(1);
+		}
+		return dateList;
+	}
+	// 鍖归厤 "_" 鍚庤窡涓�涓瓧姣嶏紙灏忓啓鎴栧ぇ鍐欙級
+	public static String toCamelCase(String input) {
+		// 鍖归厤 "_" 鍚庤窡涓�涓瓧姣嶏紙灏忓啓鎴栧ぇ鍐欙級
+		Pattern pattern = Pattern.compile("_(\\w)");
+		Matcher matcher = pattern.matcher(input);
+		StringBuffer result = new StringBuffer();
+
+		while (matcher.find()) {
+			// 灏嗗尮閰嶅埌鐨勫瓧姣嶈浆涓哄ぇ鍐欙紝骞舵浛鎹㈡帀鍓嶉潰鐨勪笅鍒掔嚎
+			matcher.appendReplacement(result, matcher.group(1).toUpperCase());
+		}
+		matcher.appendTail(result);
+
+		return result.toString();
+	}
+
+	public static void main(String[] args) throws ParseException {
+		/*List<String> dateList =getDateListBetweenDates(ActionUtil.sdf.parse("2025-01-01 00:00:00"),new Date());
+		for (String date : dateList) {
+			System.out.println(date);
+		}*/
+		//System.out.println(toCamelCase("user_name_and_age"));
+		Date time1=getDateAdd(new Date(),-10);
+		System.out.println(ActionUtil.sdf.format(time1));
+	}
 }	

--
Gitblit v1.9.1