From cf330c6a6c2ae7ec86d20de465d5af27a4684cf6 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期二, 03 十一月 2026 19:16:58 +0800
Subject: [PATCH] 巡检任务频次增加“每年”支持
---
src/main/java/com/ruoyi/inspectiontask/service/impl/TimingTaskServiceImpl.java | 43 +++++++++++++++++++++++++++++++++++++++----
1 files changed, 39 insertions(+), 4 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 02a444b..032ef14 100644
--- a/src/main/java/com/ruoyi/inspectiontask/service/impl/TimingTaskServiceImpl.java
+++ b/src/main/java/com/ruoyi/inspectiontask/service/impl/TimingTaskServiceImpl.java
@@ -6,6 +6,7 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
+import com.ruoyi.device.pojo.DeviceLedger;
import com.ruoyi.inspectiontask.dto.TimingTaskDto;
import com.ruoyi.inspectiontask.mapper.TimingTaskMapper;
import com.ruoyi.inspectiontask.pojo.TimingTask;
@@ -191,8 +192,13 @@
if (taskId == null || taskId <= 0) {
return;
}
- if (deviceLedgerMapper.selectById(taskId.longValue()) == null) {
+ DeviceLedger deviceLedger = deviceLedgerMapper.selectById(taskId.longValue());
+ if (deviceLedger == null) {
throw new IllegalArgumentException("鎵�閫夎澶囦笉瀛樺湪锛岃閲嶆柊閫夋嫨");
+ }
+ boolean deviceChanged = oldTimingTask == null || !Objects.equals(oldTimingTask.getTaskId(), taskId);
+ if (deviceChanged && Integer.valueOf(0).equals(deviceLedger.getIsEnabled())) {
+ throw new IllegalArgumentException("鎵�閫夎澶囧凡鍋滅敤锛屼笉鑳藉畨鎺掑贰妫�");
}
}
@@ -216,6 +222,9 @@
throw new IllegalArgumentException("涓嶆敮鎸佺殑棰戠巼绫诲瀷: " + task.getFrequencyType());
}
}
+
+ /** 姣忓勾宸℃榛樿鎵ц鏃堕棿锛�07:00锛堥〉闈笂涓嶇簿纭埌鏃跺垎锛� */
+ private static final LocalTime DEFAULT_EXECUTION_TIME = LocalTime.of(7, 0);
private LocalDateTime calculateDailyFirstExecution(String frequencyDetail) {
// frequencyDetail鍙兘鏄叿浣撴椂闂达紝濡� "14:30"
@@ -332,8 +341,9 @@
private LocalDateTime calculateAnnualFirstExecution(String frequencyDetail) {
String[] parts = frequencyDetail.split(",");
- if (parts.length != 3) {
- throw new IllegalArgumentException("鍙傛暟鏍煎紡閿欒锛屽簲涓�'12,31,09:00'鏍煎紡");
+ // 姣忓勾棰戠巼涓嶉渶瑕佺簿纭埌鏃跺垎锛氶粯璁ゆ牸寮忎负 "鏈�,鏃�"锛屽吋瀹规棫鐨� "鏈�,鏃�,HH:mm"
+ if (parts.length != 2 && parts.length != 3) {
+ throw new IllegalArgumentException("鍙傛暟鏍煎紡閿欒锛屽簲涓�'12,31'鏍煎紡");
}
int month;
@@ -348,7 +358,9 @@
throw new IllegalArgumentException("鏈堜唤蹇呴』鍦�1-12涔嬮棿锛屾棩鏈熷繀椤诲湪1-31涔嬮棿");
}
- LocalTime time = LocalTime.parse(parts[2].trim(), DateTimeFormatter.ofPattern("HH:mm"));
+ LocalTime time = parts.length == 3
+ ? LocalTime.parse(parts[2].trim(), DateTimeFormatter.ofPattern("HH:mm"))
+ : DEFAULT_EXECUTION_TIME;
LocalDateTime now = LocalDateTime.now();
int year = now.getYear();
LocalDateTime target = LocalDateTime.of(LocalDate.of(year, month, Math.min(day, YearMonth.of(year, month).lengthOfMonth())), time);
@@ -391,6 +403,8 @@
LocalDateTime currentTime) {
try {
switch (frequencyType) {
+ case "YEARLY":
+ return calculateYearlyNextTime(frequencyDetail, currentTime);
case "DAILY":
return calculateDailyNextTime(frequencyDetail, currentTime);
case "WEEKLY":
@@ -408,6 +422,27 @@
}
/**
+ * 璁$畻姣忓勾浠诲姟鐨勪笅娆℃墽琛屾椂闂�
+ * frequencyDetail 鏍煎紡涓� "鏈�,鏃�"锛屽吋瀹� "鏈�,鏃�,HH:mm"锛堥粯璁� 07:00锛�
+ */
+ private LocalDateTime calculateYearlyNextTime(String detail, LocalDateTime current) {
+ String[] parts = detail.split(",");
+ int month = Integer.parseInt(parts[0].trim());
+ int day = Integer.parseInt(parts[1].trim());
+ LocalTime time = parts.length >= 3 ? LocalTime.parse(parts[2].trim()) : DEFAULT_EXECUTION_TIME;
+
+ int year = current.getYear();
+ LocalDateTime target = LocalDateTime.of(
+ year, month, Math.min(day, YearMonth.of(year, month).lengthOfMonth()), time.getHour(), time.getMinute());
+ if (!current.isBefore(target)) {
+ year++;
+ target = LocalDateTime.of(
+ year, month, Math.min(day, YearMonth.of(year, month).lengthOfMonth()), time.getHour(), time.getMinute());
+ }
+ return target;
+ }
+
+ /**
* 璁$畻姣忔棩浠诲姟鐨勪笅娆℃墽琛屾椂闂�
*/
private LocalDateTime calculateDailyNextTime(String timeStr, LocalDateTime current) {
--
Gitblit v1.9.3