3 天以前 c477506a6d672f71c6353608f3cf3424d8026790
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("自动生成自定时任务ID: " + 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);
            }
        }