新增预警页面

This commit is contained in:
2025-12-10 00:08:30 +08:00
parent ec2622743a
commit 2de5b51e07
11 changed files with 638 additions and 116 deletions

View File

@@ -7,60 +7,5 @@ import java.util.Date;
public class DateUtils {
// 日期格式化器(线程安全,复用提升性能)
private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE; // yyyy-MM-dd
private static final DateTimeFormatter MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM"); // yyyy-MM
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
public static String calculateStartCycleCode(String cycleType) {
// 默认使用当前日期计算,留参便于测试时指定日期
return calculateStartCycleCode(cycleType, LocalDate.now());
}
/**
* 重载方法支持指定基准日期计算起始cycleCode便于测试
*
* @param cycleType 周期类型D:日, M:月, Q:季度, Y:年)
* @param baseDate 基准日期(以此日期为起点计算时间范围)
* @return 起始cycleCode符合对应格式未识别类型返回null
*/
public static String calculateStartCycleCode(String cycleType, LocalDate baseDate) {
if (baseDate == null) {
throw new IllegalArgumentException("基准日期不能为null");
}
if (cycleType == null) {
return null;
}
return switch (cycleType) {
case "D" ->
// 日最近30天格式 yyyy-MM-dd
baseDate.minusDays(30).format(DAY_FORMATTER);
case "M" ->
// 月最近1年格式 yyyy-MM
baseDate.minusYears(1).format(MONTH_FORMATTER);
case "Q" ->
// 季度最近3年格式 yyyy-Qx
getQuarterCycleCode(baseDate.minusYears(3));
case "Y" ->
// 年最近6年格式 yyyy
String.valueOf(baseDate.minusYears(6).getYear());
default ->
// 未识别的周期类型返回null
null;
};
}
/**
* 计算指定日期对应的季度cycleCode格式yyyy-Qx
*
* @param date 日期
* @return 季度cycleCode如2023-Q3
*/
private static String getQuarterCycleCode(LocalDate date) {
int month = date.getMonthValue(); // 1-12月
int quarter = (month - 1) / 3 + 1;
return String.format("%d-Q%d", date.getYear(), quarter);
}
}

View File

@@ -111,4 +111,56 @@ public class vDate {
result.append(seconds).append("");
return result.toString();
}
public static String calculateStartCycleCode(String cycleType) {
// 默认使用当前日期计算,留参便于测试时指定日期
return calculateStartCycleCode(cycleType, LocalDate.now());
}
/**
* 重载方法支持指定基准日期计算起始cycleCode便于测试
*
* @param cycleType 周期类型D:日, M:月, Q:季度, Y:年)
* @param baseDate 基准日期(以此日期为起点计算时间范围)
* @return 起始cycleCode符合对应格式未识别类型返回null
*/
public static String calculateStartCycleCode(String cycleType, LocalDate baseDate) {
if (baseDate == null) {
throw new IllegalArgumentException("基准日期不能为null");
}
if (cycleType == null) {
return null;
}
return switch (cycleType) {
case "D" ->
// 日最近30天格式 yyyy-MM-dd
baseDate.minusDays(30).format(DAY_FORMATTER);
case "M" ->
// 月最近1年格式 yyyy-MM
baseDate.minusYears(1).format(MONTH_FORMATTER);
case "Q" ->
// 季度最近3年格式 yyyy-Qx
getQuarterCycleCode(baseDate.minusYears(3));
case "Y" ->
// 年最近6年格式 yyyy
String.valueOf(baseDate.minusYears(6).getYear());
default ->
// 未识别的周期类型返回null
null;
};
}
/**
* 计算指定日期对应的季度cycleCode格式yyyy-Qx
*
* @param date 日期
* @return 季度cycleCode如2023-Q3
*/
private static String getQuarterCycleCode(LocalDate date) {
int month = date.getMonthValue(); // 1-12月
int quarter = (month - 1) / 3 + 1;
return String.format("%d-Q%d", date.getYear(), quarter);
}
}