| | |
| | | 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; |
| | |
| | | @Value("${wechat.irr.plan.planTerminateLimitMinutes:5}") |
| | | private Integer planTerminateLimitMinutes; // 计划终止后限制发布新计划的时间间隔(分钟) |
| | | |
| | | /** |
| | | * 添加灌溉计划 |
| | | * |
| | | * @param po |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long addIrrigatePlan(IrIrrigatePlan po) { |
| | | irrigatePlanMapper.insert(po); |
| | | return po.getId(); |
| | | } |
| | | |
| | | /** |
| | | * 删除灌溉计划 |
| | | * |
| | | * @param planSimple |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Map deletePlan(PlanSimple planSimple) { |
| | | Long planId = planSimple.getPlanId(); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 发布灌溉计划 |
| | | * |
| | | * @param planSimple |
| | | * @return |
| | | */ |
| | | public Map publishPlan(PlanSimple planSimple) { |
| | | Long planId = planSimple.getPlanId(); |
| | | Long operatorId = planSimple.getOperatorId(); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取灌溉计划信息 |
| | | * 更新灌溉计划起止时间及计划状态 |
| | | */ |
| | | VoPlanSimple plan = irrigatePlanMapper.getPlanSimple(planId); |
| | | if (plan == null) { |
| | | Map map = new HashMap<>(); |
| | |
| | | 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()); |
| | | |
| | | 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()); |
| | | LocalscheduleStartTime = LocalscheduleStartTime.minusMinutes(preOpeningTime); |
| | | scheduleStartTime = Date.from(LocalscheduleStartTime.atZone(ZoneId.systemDefault()).toInstant()); |
| | | |
| | | // 根据计划ID更新计划信息(起止时间、计划状态) |
| | | if (scheduleStartTime.before(planStartTime)) { |
| | | 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()); |
| | | } |
| | | |
| | | if (this.updatePlanTimes(planStartTime, planStopTime, planId) == 0) { |
| | | Map map = new HashMap<>(); |
| | | map.put("success", false); |
| | |
| | | return map; |
| | | } |
| | | |
| | | // 更新每个灌溉次序的开始时间 |
| | | List<VoIrrigateSchedule> schedules = getSchedulesByPlanId(planId); |
| | | Date scheduleStartTime = null; |
| | | Integer sort = 0; |
| | | for (VoIrrigateSchedule schedule : schedules) { |
| | | if (scheduleStartTime == null) { |
| | | scheduleStartTime = planStartTime; |
| | | } |
| | | this.updateScheduleStartTime(schedule.getScheduleId(), scheduleStartTime); |
| | | |
| | | // 计算下一组的开始时间 |
| | | LocalDateTime LocalscheduleStartTime = scheduleStartTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); |
| | | LocalscheduleStartTime = LocalscheduleStartTime.plusMinutes(schedule.getDuration()); |
| | | LocalscheduleStartTime = LocalscheduleStartTime.minusMinutes(preOpeningTime); |
| | | scheduleStartTime = Date.from(LocalscheduleStartTime.atZone(ZoneId.systemDefault()).toInstant()); |
| | | |
| | | // 确保下一组的开始时间不早于计划开始时间 |
| | | if (scheduleStartTime.before(planStartTime)) { |
| | | scheduleStartTime = planStartTime; |
| | | } |
| | | } |
| | | |
| | | // 添加灌溉计划操作记录 |
| | | IrPlanOperate planOperate = new IrPlanOperate(); |
| | | planOperate.setPlanId(planId); |
| | | planOperate.setOperator(operatorId); |
| | |
| | | for (VoIrrigateSchedule schedule : schedules) { |
| | | Long groupId = schedule.getGroupId(); |
| | | List<Long> intakeIds = getIntakeIdsByGroupId(groupId); |
| | | if(intakeIds == null || intakeIds.size() <= 0) { |
| | | Map map = new HashMap<>(); |
| | | map.put("success", false); |
| | | map.put("msg", "当前轮灌组内没有有效的取水口"); |
| | | map.put("content", null); |
| | | return map; |
| | | } |
| | | for (Long intakeId : intakeIds) { |
| | | if (schedule.getDuration() > 0) { |
| | | // 今发布灌溉时长大于0的 |
| | |
| | | return irIrrigateUnitMapper.getIntakeIdByUnitId(unitId); |
| | | } |
| | | |
| | | /** |
| | | * 根据计划ID获取计划发布结果 |
| | | * |
| | | * @param planId |
| | | * @return |
| | | */ |
| | | public VoPlanDetails getPublishResults(Long planId) { |
| | | VoPlanDetails planDetails = irrigatePlanMapper.getPlanDetails(planId); |
| | | if (planDetails == null) { |
| | |
| | | |
| | | planDetails.setGroups(groupResults); |
| | | return planDetails; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 根据计划ID获取计划终止操作结果 |
| | | * |
| | | * @param planId |
| | | * @return |
| | | */ |
| | | public VoPlanDetails getTerminateResults(Long planId) { |
| | | // 获取计划终止时间 |
| | | Date terminateTime = Optional.ofNullable(irPlanOperateMapper.getTerminateTime(planId)).orElse(null); |