| | |
| | | import com.dy.pipIrrWechat.irrigatePlan.enums.OperateTypeENUM; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.dubbo.common.utils.PojoUtils; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | startTime = startTime.plusMinutes(irrPlanDelay); |
| | | } |
| | | planStartTime = Date.from(startTime.atZone(ZoneId.systemDefault()).toInstant()); |
| | | LocalDateTime stopTime = startTime.plusMinutes(duration); |
| | | planStopTime = Date.from(stopTime.atZone(ZoneId.systemDefault()).toInstant()); |
| | | |
| | | // 根据计划ID更新计划信息(起止时间、计划状态) |
| | | if (this.updatePlanTimes(planStartTime, planStopTime, planId) == 0) { |
| | | Map map = new HashMap<>(); |
| | | map.put("success", false); |
| | | map.put("msg", "计划信息更新失败"); |
| | | map.put("content", null); |
| | | return map; |
| | | } |
| | | |
| | | // 更新每个灌溉次序的开始时间 |
| | | |
| | | // 更新每个灌溉次序的开始时间并计算最后一组关阀时间 |
| | | List<VoIrrigateSchedule> schedules = getSchedulesByPlanId(planId); |
| | | Date scheduleStartTime = null; |
| | | LocalDateTime lastScheduleEndTime = null; |
| | | Integer sort = 0; |
| | | |
| | | // 第一次遍历:更新每个灌溉次序的开始时间 |
| | | for (VoIrrigateSchedule schedule : schedules) { |
| | | if (scheduleStartTime == null) { |
| | | scheduleStartTime = planStartTime; |
| | | } |
| | | this.updateScheduleStartTime(schedule.getScheduleId(), scheduleStartTime); |
| | | |
| | | |
| | | // 计算当前次序的结束时间 |
| | | LocalDateTime currentScheduleStartTime = scheduleStartTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); |
| | | LocalDateTime currentScheduleEndTime = currentScheduleStartTime.plusMinutes(schedule.getDuration()); |
| | | |
| | | // 更新最后一组的结束时间 |
| | | lastScheduleEndTime = currentScheduleEndTime; |
| | | |
| | | // 计算下一组的开始时间 |
| | | LocalDateTime LocalscheduleStartTime = scheduleStartTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); |
| | | LocalscheduleStartTime = LocalscheduleStartTime.plusMinutes(schedule.getDuration()); |
| | |
| | | scheduleStartTime = planStartTime; |
| | | } |
| | | } |
| | | |
| | | // 根据最后一组关阀时间设置计划结束时间 |
| | | if (lastScheduleEndTime != null) { |
| | | planStopTime = Date.from(lastScheduleEndTime.atZone(ZoneId.systemDefault()).toInstant()); |
| | | } else { |
| | | // 如果没有灌溉次序,则使用原来的计算方式 |
| | | LocalDateTime stopTime = startTime.plusMinutes(duration); |
| | | planStopTime = Date.from(stopTime.atZone(ZoneId.systemDefault()).toInstant()); |
| | | } |
| | | |
| | | // 根据计划ID更新计划信息(起止时间、计划状态) |
| | | if (this.updatePlanTimes(planStartTime, planStopTime, planId) == 0) { |
| | | Map map = new HashMap<>(); |
| | | map.put("success", false); |
| | | map.put("msg", "计划信息更新失败"); |
| | | map.put("content", null); |
| | | return map; |
| | | } |
| | | |
| | | // 添加灌溉计划操作记录 |
| | | IrPlanOperate planOperate = new IrPlanOperate(); |