| | |
| | | inspectionTask.setMaintenanceTaskId(timingTask.getId()); |
| | | inspectionTask.setDeviceLedgerId(timingTask.getTaskId()); |
| | | inspectionTask.setMaintenancePlanTime(LocalDateTime.now()); |
| | | inspectionTask.setMaintenanceActuallyName(timingTask.getMaintenancePerson()); |
| | | inspectionTask.setFrequencyType(timingTask.getFrequencyType()); |
| | | inspectionTask.setFrequencyDetail(timingTask.getFrequencyDetail()); |
| | | inspectionTask.setTenantId(timingTask.getTenantId()); |
| | |
| | | return calculateMonthlyNextTime(frequencyDetail, currentTime); |
| | | case "QUARTERLY": |
| | | return calculateQuarterlyNextTime(frequencyDetail, currentTime); |
| | | case "YEARLY": |
| | | return calculateYearlyNextTime(frequencyDetail, currentTime); |
| | | default: |
| | | throw new IllegalArgumentException("不支持的频率类型: " + frequencyType); |
| | | } |
| | |
| | | ); |
| | | } |
| | | |
| | | private LocalDateTime calculateYearlyNextTime(String detail, LocalDateTime current) { |
| | | String[] parts = detail.split(","); |
| | | int month = Integer.parseInt(parts[0]); |
| | | int day = Integer.parseInt(parts[1]); |
| | | LocalTime time = LocalTime.parse(parts[2]); |
| | | |
| | | int year = current.getYear(); |
| | | LocalDateTime nextTime = LocalDateTime.of(java.time.LocalDate.of(year, month, |
| | | Math.min(day, YearMonth.of(year, month).lengthOfMonth())), time); |
| | | if (!nextTime.isAfter(current)) { |
| | | year++; |
| | | nextTime = LocalDateTime.of(java.time.LocalDate.of(year, month, |
| | | Math.min(day, YearMonth.of(year, month).lengthOfMonth())), time); |
| | | } |
| | | return nextTime; |
| | | } |
| | | |
| | | /** |
| | | * 解析星期几字符串 |
| | | */ |