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/TimingTaskJob.java |   49 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/ruoyi/inspectiontask/service/impl/TimingTaskJob.java b/src/main/java/com/ruoyi/inspectiontask/service/impl/TimingTaskJob.java
index adc2416..19e32f0 100644
--- a/src/main/java/com/ruoyi/inspectiontask/service/impl/TimingTaskJob.java
+++ b/src/main/java/com/ruoyi/inspectiontask/service/impl/TimingTaskJob.java
@@ -56,9 +56,11 @@
 //                throw new JobExecutionException("瀹氭椂浠诲姟宸茬鐢�: " + taskId);
 //            }
 
-            // 2. 鍒涘缓骞朵繚瀛樺贰妫�浠诲姟璁板綍 - 杩欏氨鏄偍鎻愪緵鐨勪唬鐮佸簲璇ユ斁鐨勪綅缃�
-            InspectionTask inspectionTask = createInspectionTask(timingTask);
-            inspectionTaskMapper.insert(inspectionTask);
+            // 2. 鍒涘缓骞朵繚瀛樺贰妫�浠诲姟璁板綍锛涜澶囧凡鍋滅敤鏃惰烦杩囷紝涓嶇敓鎴愬贰妫�浠诲姟
+            if (!isDeviceDisabled(timingTask.getTaskId())) {
+                InspectionTask inspectionTask = createInspectionTask(timingTask);
+                inspectionTaskMapper.insert(inspectionTask);
+            }
 
             // 3. 鏇存柊瀹氭椂浠诲姟鐨勬墽琛屾椂闂�
             if (!tasks.isEmpty()) {
@@ -97,6 +99,21 @@
         }
     }
 
+    /**
+     * 璁惧鏄惁宸插仠鐢紙鍋滅敤璁惧涓嶅弬涓庡贰妫�锛�
+     */
+    private boolean isDeviceDisabled(Integer deviceId) {
+        if (deviceId == null || deviceId <= 0) {
+            return false;
+        }
+        List<Integer> enabledList = jdbcTemplate.queryForList(
+                "SELECT is_enabled FROM device_ledger WHERE id = ?", Integer.class, deviceId);
+        if (enabledList.isEmpty() || enabledList.get(0) == null) {
+            return false;
+        }
+        return enabledList.get(0) == 0;
+    }
+
     // 杩欏氨鏄偍鎻愪緵鐨勪唬鐮佸皝瑁呮垚鐨勬柟娉�
     private InspectionTask createInspectionTask(TimingTask timingTask) {
         InspectionTask inspectionTask = new InspectionTask();
@@ -129,6 +146,8 @@
                                                      LocalDateTime currentTime) {
         try {
             switch (frequencyType) {
+                case "YEARLY":
+                    return calculateYearlyNextTime(frequencyDetail, currentTime);
                 case "DAILY":
                     return calculateDailyNextTime(frequencyDetail, currentTime);
                 case "WEEKLY":
@@ -145,6 +164,30 @@
         }
     }
 
+    /** 姣忓勾宸℃榛樿鎵ц鏃堕棿锛�07:00锛堥〉闈笂涓嶇簿纭埌鏃跺垎锛� */
+    private static final LocalTime DEFAULT_EXECUTION_TIME = LocalTime.of(7, 0);
+
+    /**
+     * 璁$畻姣忓勾浠诲姟鐨勪笅娆℃墽琛屾椂闂�
+     * 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;
+    }
+
     /**
      * 璁$畻姣忔棩浠诲姟鐨勪笅娆℃墽琛屾椂闂�
      */

--
Gitblit v1.9.3