From 1a89a2eca92540f2a6e9ed5c140b00610f2f4bfc Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 13 四月 2026 14:11:50 +0800
Subject: [PATCH] yys 1.设备巡检,保养加入年维度

---
 src/main/java/com/ruoyi/inspectiontask/service/impl/TimingTaskJob.java |   33 ++++++++++++++++++++++++++-------
 1 files changed, 26 insertions(+), 7 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 b32f82b..5d13ffa 100644
--- a/src/main/java/com/ruoyi/inspectiontask/service/impl/TimingTaskJob.java
+++ b/src/main/java/com/ruoyi/inspectiontask/service/impl/TimingTaskJob.java
@@ -66,12 +66,12 @@
             );
             TimingTask timingTask = tasks.isEmpty() ? null : tasks.get(0);
             if (timingTask == null) {
-                throw new JobExecutionException("鎵句笉鍒板畾鏃朵换鍔�: " + taskId);
+                throw new JobExecutionException("閹靛彞绗夐崚鏉跨暰閺冩湹鎹㈤崝? " + taskId);
             }
 
             List<Long> deviceIds = resolveTaskIds(timingTask);
             if (deviceIds.isEmpty()) {
-                throw new JobExecutionException("瀹氭椂浠诲姟鏈厤缃澶�: " + taskId);
+                throw new JobExecutionException("鐎规碍妞傛禒璇插閺堫亪鍘ょ純顔款啎婢�? " + taskId);
             }
 
             for (Long deviceId : deviceIds) {
@@ -130,7 +130,7 @@
         inspectionTask.setAreaId(deviceLedger.getAreaId());
         inspectionTask.setInspectorId(timingTask.getInspectorIds());
         inspectionTask.setInspectionLocation(timingTask.getInspectionLocation());
-        inspectionTask.setRemarks("鑷姩鐢熸垚鑷畾鏃朵换鍔D: " + timingTask.getId());
+        inspectionTask.setRemarks("閼奉亜濮╅悽鐔稿灇閼奉亜鐣鹃弮鏈垫崲閸旑搹D: " + timingTask.getId());
         inspectionTask.setRegistrantId(timingTask.getRegistrantId());
         inspectionTask.setRegistrant(timingTask.getRegistrant());
         inspectionTask.setFrequencyType(timingTask.getFrequencyType());
@@ -152,11 +152,13 @@
                     return calculateMonthlyNextTime(frequencyDetail, currentTime);
                 case "QUARTERLY":
                     return calculateQuarterlyNextTime(frequencyDetail, currentTime);
+                case "YEARLY":
+                    return calculateYearlyNextTime(frequencyDetail, currentTime);
                 default:
-                    throw new IllegalArgumentException("涓嶆敮鎸佺殑棰戠巼绫诲瀷: " + frequencyType);
+                    throw new IllegalArgumentException("娑撳秵鏁幐浣烘畱妫版垹宸肩猾璇茬��: " + frequencyType);
             }
         } catch (Exception e) {
-            throw new RuntimeException("璁$畻涓嬫鎵ц鏃堕棿澶辫触: " + e.getMessage(), e);
+            throw new RuntimeException("鐠侊紕鐣绘稉瀣偧閹笛嗩攽閺冨爼妫挎径杈Е: " + e.getMessage(), e);
         }
     }
 
@@ -179,7 +181,7 @@
                 return LocalDateTime.of(nextTime.toLocalDate(), time);
             }
             if (nextTime.isAfter(current.plusYears(1))) {
-                throw new RuntimeException("鏃犳硶鎵惧埌涓嬫鎵ц鏃堕棿");
+                throw new RuntimeException("閺冪姵纭堕幍鎯у煂娑撳顐奸幍褑顢戦弮鍫曟?");
             }
         }
     }
@@ -217,6 +219,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("\\|");
@@ -245,7 +264,7 @@
                     days.add(DayOfWeek.SUNDAY);
                     break;
                 default:
-                    throw new IllegalArgumentException("鏃犳晥鐨勬槦鏈�: " + dayStr);
+                    throw new IllegalArgumentException("閺冪姵鏅ラ惃鍕Е閺�? " + dayStr);
             }
         }
 

--
Gitblit v1.9.3