| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.temporal.TemporalAdjusters; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | |
| | | private BaseFactoryMapper baseFactoryMapper; |
| | | @Autowired |
| | | private IEamSecondMaintenanceOrderDetailService eamSecondMaintenanceOrderDetailService; |
| | | @Autowired |
| | | private EamSecondMaintenanceOrderAsyncService eamSecondMaintenanceOrderAsyncService; |
| | | @Autowired |
| | | private IEamFactorySecondMaintPlanService factorySecondMaintPlanService; |
| | | |
| | |
| | | } |
| | | // 插入首页二保养计划 |
| | | // 使用 SimpleDateFormat 直接格式化为“yyyy年MM月”格式 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月"); |
| | | String formattedDate = sdf.format(order.getMaintenanceDate()); |
| | | factorySecondMaintPlanService.add(order.getEquipmentId(), formattedDate); |
| | | // SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月"); |
| | | // String formattedDate = sdf.format(order.getMaintenanceDate()); |
| | | // factorySecondMaintPlanService.add(order.getEquipmentId(), formattedDate); |
| | | return true; |
| | | } |
| | | |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.SECOND_MAINTENANCE, businessTable = "eam_second_maintenance_order") |
| | | public EamSecondMaintenanceOrder approval(EamSecondMaintenanceRequest request) { |
| | | public EamSecondMaintenanceOrder approval(EamSecondMaintenanceRequest request) throws ParseException { |
| | | EamSecondMaintenanceOrder entity = eamSecondMaintenanceOrderMapper.selectById(request.getId()); |
| | | if (entity == null) { |
| | | throw new JeecgBootException("审批的数据已删除,请刷新重试!"); |
| | |
| | | eamSecondMaintenanceOrderMapper.updateById(entity); |
| | | //异步生成下次二保工单 |
| | | if (SecondMaintenanceStatusEnum.COMPLETE.name().equals(entity.getMaintenanceStatus())) { |
| | | try { |
| | | eamSecondMaintenanceOrderAsyncService.asyncGenerateNextMaintenanceOrder(entity.getId()); |
| | | } catch (Exception e) { |
| | | log.error("触发异步生成下次工单失败,工单ID: {}", entity.getId(), e); |
| | | } |
| | | //填充计算下次二保日期 |
| | | EamEquipmentExtend eamEquipmentExtend=eamEquipmentExtendService.getById(entity.getEquipmentId()); |
| | | eamEquipmentExtend.setLatestSecondMaintenance(entity.getMaintenanceDate()); |
| | | eamEquipmentExtend.setNextSecondMaintenance(calculateNextMaintenanceDate(entity.getMaintenanceDate())); |
| | | eamEquipmentExtendService.updateById(eamEquipmentExtend); |
| | | } |
| | | |
| | | return entity; |
| | | } |
| | | |
| | | /** |
| | | * 计算六个月后的当月最后一天 |
| | | * @param currentDate 当前工单日期 |
| | | * @return 六个月后的当月最后一天 |
| | | */ |
| | | private Date calculateNextMaintenanceDate(Date currentDate) { |
| | | // 转换为LocalDate处理日期 |
| | | LocalDate localDate = DateUtils.dateToLocalDate(currentDate); |
| | | // 计算六个月后的日期 |
| | | LocalDate sixMonthsLater = localDate.plusMonths(6); |
| | | // 调整到当月的最后一天 |
| | | LocalDate lastDayOfMonth = sixMonthsLater.with(TemporalAdjusters.lastDayOfMonth()); |
| | | // 转换回Date类型 |
| | | return DateUtils.localDateToDate(lastDayOfMonth); |
| | | } |
| | | |
| | | /** |
| | | * 批量打印二保工单 |
| | | * @param ids |
| | | * @return |