From 0541c0791acea41b584f71fc59e22d4d21ba0883 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期三, 15 四月 2026 11:10:46 +0800
Subject: [PATCH] ``` refactor(energy): 优化实时能耗数据服务实现
---
src/main/java/com/ruoyi/inspectiontask/service/impl/TimingTaskServiceImpl.java | 43 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ruoyi/inspectiontask/service/impl/TimingTaskServiceImpl.java b/src/main/java/com/ruoyi/inspectiontask/service/impl/TimingTaskServiceImpl.java
index f23a6a4..d551399 100644
--- a/src/main/java/com/ruoyi/inspectiontask/service/impl/TimingTaskServiceImpl.java
+++ b/src/main/java/com/ruoyi/inspectiontask/service/impl/TimingTaskServiceImpl.java
@@ -225,6 +225,8 @@
return calculateWeeklyFirstExecution(task.getFrequencyDetail());
} else if ("MONTHLY".equals(frequencyType)) {
return calculateMonthlyFirstExecution(task.getFrequencyDetail());
+ } else if ("YEARLY".equals(frequencyType)) {
+ return calculateYearlyFirstExecution(task.getFrequencyDetail());
} else if ("QUARTERLY".equals(frequencyType)) {
return calculateCustomFirstExecution(task.getFrequencyDetail());
} else {
@@ -315,6 +317,28 @@
return targetDateTime;
}
+ private LocalDateTime calculateYearlyFirstExecution(String frequencyDetail) {
+ String[] parts = frequencyDetail.split(",");
+ if (parts.length != 3) {
+ throw new IllegalArgumentException("鍙傛暟鏍煎紡閿欒锛屽簲涓� 03,15,17:00");
+ }
+
+ int month = Integer.parseInt(parts[0].trim());
+ int dayOfMonth = Integer.parseInt(parts[1].trim());
+ LocalTime targetTime = LocalTime.parse(parts[2].trim(), DateTimeFormatter.ofPattern("HH:mm"));
+
+ LocalDateTime now = LocalDateTime.now();
+ YearMonth currentYearMonth = YearMonth.of(now.getYear(), month);
+ int adjustedDay = Math.min(dayOfMonth, currentYearMonth.lengthOfMonth());
+ LocalDateTime targetDateTime = LocalDateTime.of(now.getYear(), month, adjustedDay, targetTime.getHour(), targetTime.getMinute());
+ if (!targetDateTime.isAfter(now)) {
+ YearMonth nextYearMonth = YearMonth.of(now.getYear() + 1, month);
+ adjustedDay = Math.min(dayOfMonth, nextYearMonth.lengthOfMonth());
+ targetDateTime = LocalDateTime.of(now.getYear() + 1, month, adjustedDay, targetTime.getHour(), targetTime.getMinute());
+ }
+ return targetDateTime;
+ }
+
private LocalDateTime calculateCustomFirstExecution(String frequencyDetail) {
return null;
}
@@ -350,6 +374,8 @@
return calculateMonthlyNextTime(frequencyDetail, currentTime);
case "QUARTERLY":
return calculateQuarterlyNextTime(frequencyDetail, currentTime);
+ case "YEARLY":
+ return calculateYearlyNextTime(frequencyDetail, currentTime);
default:
throw new IllegalArgumentException("涓嶆敮鎸佺殑棰戠巼绫诲瀷: " + frequencyType);
}
@@ -415,6 +441,23 @@
);
}
+ private LocalDateTime calculateYearlyNextTime(String detail, LocalDateTime current) {
+ String[] parts = detail.split(",");
+ int month = Integer.parseInt(parts[0]);
+ int dayOfMonth = Integer.parseInt(parts[1]);
+ LocalTime time = LocalTime.parse(parts[2]);
+
+ YearMonth targetYearMonth = YearMonth.of(current.getYear(), month);
+ int adjustedDay = Math.min(dayOfMonth, targetYearMonth.lengthOfMonth());
+ LocalDateTime target = LocalDateTime.of(current.getYear(), month, adjustedDay, time.getHour(), time.getMinute());
+ if (!target.isAfter(current)) {
+ targetYearMonth = YearMonth.of(current.getYear() + 1, month);
+ adjustedDay = Math.min(dayOfMonth, targetYearMonth.lengthOfMonth());
+ target = LocalDateTime.of(current.getYear() + 1, month, adjustedDay, time.getHour(), time.getMinute());
+ }
+ return target;
+ }
+
private Set<DayOfWeek> parseDayOfWeeks(String dayOfWeekStr) {
Set<DayOfWeek> days = new HashSet<>();
String[] dayStrs = dayOfWeekStr.split("\\|");
--
Gitblit v1.9.3