pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigatePlan/IrrigatePlanCtrl.java
@@ -199,87 +199,113 @@
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        Long planId = planSimple.getPlanId();
        Long operatorId = planSimple.getOperatorId();
        Byte operateType = 1;
        Map map_result = irrigatePlanSv.publishPlan(planSimple);
        if(map_result.get("success").equals(false)) {
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
        }
        return BaseResponseUtils.buildSuccess() ;
        /**
         * 获取灌溉计划信息
         * 更新灌溉计划起止时间及计划状态
         */
        VoPlanSimple plan = irrigatePlanSv.getPlanSimple(planId);
        if(plan == null){
            return BaseResponseUtils.buildErrorMsg("您要发布的计划不存在,或该计划已发布");
        //Long planId = planSimple.getPlanId();
        //Long operatorId = planSimple.getOperatorId();
        //Byte operateType = 1;
        //
        ///**
        // * 获取灌溉计划信息
        // * 更新灌溉计划起止时间及计划状态
        // */
        //VoPlanSimple plan = irrigatePlanSv.getPlanSimple(planId);
        //if(plan == null){
        //    return BaseResponseUtils.buildErrorMsg("您要发布的计划不存在,或该计划已发布");
        //}
        //
        //Byte startupMode = plan.getStartupMode();
        //Integer duration = plan.getDuration();
        //Date planStartTime = plan.getPlanStartTime();
        //Date planStopTime = null;
        //
        //if(startupMode == 1){
        //    planStartTime = new Date();
        //}
        //LocalDateTime startTime = planStartTime.toInstant().atZone(ZoneId.systemDefault()) .toLocalDateTime();
        //if(startupMode == 1){
        //    // 测试阶段延后2分钟,正式发布为5分钟
        //    startTime = startTime.plusMinutes(2);
        //    //startTime = startTime.plusMinutes(5);
        //}
        //planStartTime = Date.from(startTime.atZone(ZoneId.systemDefault()).toInstant());
        //LocalDateTime stopTime = startTime.plusMinutes(duration);
        //planStopTime = Date.from(stopTime.atZone(ZoneId.systemDefault()).toInstant());
        //
        //
        //if(irrigatePlanSv.updatePlanTimes(planStartTime, planStopTime, planId) == 0) {
        //    return BaseResponseUtils.buildErrorMsg("计划信息更新失败");
        //}
        //
        //// 更新每个灌溉次序的开始时间
        //List<VoIrrigateSchedule> schedules = irrigatePlanSv.getSchedulesByPlanId(planId);
        //Date scheduleStartTime = null;
        //Integer sort = 0;
        //for(VoIrrigateSchedule schedule : schedules){
        //    if(scheduleStartTime == null) {
        //        scheduleStartTime = planStartTime;
        //    }
        //    irrigatePlanSv.updateScheduleStartTime(schedule.getScheduleId(), scheduleStartTime);
        //
        //    // 计算下一组的开始时间
        //    LocalDateTime LocalscheduleStartTime = scheduleStartTime.toInstant().atZone(ZoneId.systemDefault()) .toLocalDateTime();
        //    LocalscheduleStartTime = LocalscheduleStartTime.plusMinutes(schedule.getDuration());
        //    scheduleStartTime = Date.from(LocalscheduleStartTime.atZone(ZoneId.systemDefault()).toInstant());
        //}
        //
        //// 添加灌溉计划操作记录
        //IrPlanOperate planOperate  = new IrPlanOperate();
        //planOperate.setPlanId(planId);
        //planOperate.setOperator(operatorId);
        //planOperate.setOperateType(OperateTypeENUM.PUBLISH.getCode());
        //planOperate.setOperateTime(new Date());
        //if(irrigatePlanSv.addPlanOperate(planOperate) == 0){
        //    return BaseResponseUtils.buildErrorMsg("添加灌溉计划操作记录失败");
        //}
        //
        //schedules = irrigatePlanSv.getSchedulesByPlanId(planId);
        //for(VoIrrigateSchedule schedule : schedules) {
        //    Long groupId = schedule.getGroupId();
        //    List<Long> intakeIds = irrigatePlanSv.getIntakeIdsByGroupId(groupId);
        //    for(Long intakeId : intakeIds) {
        //        if(schedule.getDuration() > 0) {
        //            // 今发布灌溉时长大于0的
        //            AutomaticClose automaticClose = new AutomaticClose();
        //            automaticClose.setIntakeId(intakeId);
        //            automaticClose.setPlannedOpenTime(schedule.getStartTime());
        //            automaticClose.setMinutes(schedule.getDuration());
        //            automaticClose.setOperator(operatorId);
        //            automaticClose.setOpenType(Byte.valueOf("1"));
        //
        //            commandSv.planedOpenTimedClose(automaticClose, planId, operateType, schedule.getStartTime(), schedule.getDuration());
        //        }
        //    }
        //}
        //
        //return BaseResponseUtils.buildSuccess();
    }
    /**
     * 根据计划ID获取计划最新状态
     * @param planId
     * @return
     */
    @GetMapping(path = "/getPlanLatestState")
    public BaseResponse<Integer> getPlanLatestState(@RequestParam Long planId) {
        if(planId == null) {
            return BaseResponseUtils.buildErrorMsg("计划ID不能为空");
        }
        Byte startupMode = plan.getStartupMode();
        Integer duration = plan.getDuration();
        Date planStartTime = plan.getPlanStartTime();
        Date planStopTime = null;
        if(startupMode == 1){
            planStartTime = new Date();
        try {
            return BaseResponseUtils.buildSuccess(irrigatePlanSv.getPlanLatestState(planId));
        } catch (Exception e) {
            log.error("获取未完的计划异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        LocalDateTime startTime = planStartTime.toInstant().atZone(ZoneId.systemDefault()) .toLocalDateTime();
        if(startupMode == 1){
            // 测试阶段延后2分钟,正式发布为5分钟
            startTime = startTime.plusMinutes(2);
            //startTime = startTime.plusMinutes(5);
        }
        planStartTime = Date.from(startTime.atZone(ZoneId.systemDefault()).toInstant());
        LocalDateTime stopTime = startTime.plusMinutes(duration);
        planStopTime = Date.from(stopTime.atZone(ZoneId.systemDefault()).toInstant());
        if(irrigatePlanSv.updatePlanTimes(planStartTime, planStopTime, planId) == 0) {
            return BaseResponseUtils.buildErrorMsg("计划信息更新失败");
        }
        // 更新每个灌溉次序的开始时间
        List<VoIrrigateSchedule> schedules = irrigatePlanSv.getSchedulesByPlanId(planId);
        Date scheduleStartTime = null;
        Integer sort = 0;
        for(VoIrrigateSchedule schedule : schedules){
            if(scheduleStartTime == null) {
                scheduleStartTime = planStartTime;
            }
            irrigatePlanSv.updateScheduleStartTime(schedule.getScheduleId(), scheduleStartTime);
            // 计算下一组的开始时间
            LocalDateTime LocalscheduleStartTime = scheduleStartTime.toInstant().atZone(ZoneId.systemDefault()) .toLocalDateTime();
            LocalscheduleStartTime = LocalscheduleStartTime.plusMinutes(schedule.getDuration());
            scheduleStartTime = Date.from(LocalscheduleStartTime.atZone(ZoneId.systemDefault()).toInstant());
        }
        // 添加灌溉计划操作记录
        IrPlanOperate planOperate  = new IrPlanOperate();
        planOperate.setPlanId(planId);
        planOperate.setOperator(operatorId);
        planOperate.setOperateType(OperateTypeENUM.PUBLISH.getCode());
        planOperate.setOperateTime(new Date());
        if(irrigatePlanSv.addPlanOperate(planOperate) == 0){
            return BaseResponseUtils.buildErrorMsg("添加灌溉计划操作记录失败");
        }
        schedules = irrigatePlanSv.getSchedulesByPlanId(planId);
        for(VoIrrigateSchedule schedule : schedules) {
            Long groupId = schedule.getGroupId();
            List<Long> intakeIds = irrigatePlanSv.getIntakeIdsByGroupId(groupId);
            for(Long intakeId : intakeIds) {
                if(schedule.getDuration() > 0) {
                    // 今发布灌溉时长大于0的
                    AutomaticClose automaticClose = new AutomaticClose();
                    automaticClose.setIntakeId(intakeId);
                    automaticClose.setPlannedOpenTime(schedule.getStartTime());
                    automaticClose.setMinutes(schedule.getDuration());
                    automaticClose.setOperator(operatorId);
                    automaticClose.setOpenType(Byte.valueOf("1"));
                    commandSv.planedOpenTimedClose(automaticClose, planId, operateType, schedule.getStartTime(), schedule.getDuration());
                }
            }
        }
        return BaseResponseUtils.buildSuccess();
    }
    /**