| | |
| | | import org.jeecg.modules.eam.request.EamEquipmentQuery; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentExtendService; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentService; |
| | | import org.jeecg.modules.eam.service.IEamThirdMaintenanceWorkPlanSheetService; |
| | | import org.jeecg.modules.eam.vo.EamEquipmentTree; |
| | | import org.jeecg.modules.eam.vo.EquipmentSearchResult; |
| | | import org.jeecg.modules.system.entity.BaseFactory; |
| | |
| | | if (eamEquipment.getNextThirdMaintenance() != null && |
| | | eamEquipment.getThirdMaintenancePeriod() != null) { |
| | | |
| | | calculateMaintenanceDates( |
| | | org.jeecg.common.util.DateUtils.calculateMaintenanceDates( |
| | | eamEquipment.getNextThirdMaintenance(), |
| | | eamEquipment.getThirdMaintenancePeriod(), |
| | | newDate -> eamEquipment.setNextThirdMaintenance(newDate), |
| | |
| | | if (eamEquipment.getNextTechnologyCheck() != null && |
| | | eamEquipment.getTechnologyCheckPeriod() != null) { |
| | | |
| | | calculateMaintenanceDates( |
| | | org.jeecg.common.util.DateUtils.calculateMaintenanceDates( |
| | | eamEquipment.getNextTechnologyCheck(), |
| | | eamEquipment.getTechnologyCheckPeriod(), |
| | | newDate -> eamEquipment.setNextTechnologyCheck(newDate), |
| | |
| | | return Result.OK(items); |
| | | }catch (Exception e) { |
| | | return Result.error("数据转译失败!"); |
| | | } |
| | | } |
| | | |
| | | // 日期计算工具方法 |
| | | private void calculateMaintenanceDates(Date nextDate, Integer periodYears, |
| | | Consumer<Date> setNextMaintenance, |
| | | Consumer<Date> setLatestMaintenance) { |
| | | if (nextDate == null || periodYears == null || periodYears <= 0) { |
| | | return; |
| | | } |
| | | |
| | | // 转换为Java 8日期类型 |
| | | LocalDate nextLocal = nextDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); |
| | | LocalDate today = LocalDate.now(); |
| | | |
| | | // 确保有效的计算周期 |
| | | int period = Math.max(1, periodYears); // 防止传入0或负值 |
| | | |
| | | if (nextLocal.isAfter(today)) { |
| | | // 未过期:计算最近维护日期 |
| | | setLatestMaintenance.accept( |
| | | Date.from(nextLocal.minusYears(period).atStartOfDay() |
| | | .atZone(ZoneId.systemDefault()).toInstant()) |
| | | ); |
| | | } else { |
| | | // 已过期:计算新的下次维护日期 |
| | | while (!nextLocal.isAfter(today)) { |
| | | nextLocal = nextLocal.plusYears(period); |
| | | } |
| | | |
| | | // 设置新日期 |
| | | setNextMaintenance.accept( |
| | | Date.from(nextLocal.atStartOfDay() |
| | | .atZone(ZoneId.systemDefault()).toInstant()) |
| | | ); |
| | | |
| | | // 计算最近维护日期 |
| | | setLatestMaintenance.accept( |
| | | Date.from(nextLocal.minusYears(period).atStartOfDay() |
| | | .atZone(ZoneId.systemDefault()).toInstant()) |
| | | ); |
| | | } |
| | | } |
| | | |