From 44eb64bef08ce231ac95d5ee482b046014dc8afa Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期一, 08 九月 2025 11:29:26 +0800
Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV

---
 pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigatePlan/IrrigatePlanSv.java |  103 ++++++++++++++++++++-------------------------------
 1 files changed, 41 insertions(+), 62 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigatePlan/IrrigatePlanSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigatePlan/IrrigatePlanSv.java
index 5db3988..614ff75 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigatePlan/IrrigatePlanSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigatePlan/IrrigatePlanSv.java
@@ -16,7 +16,6 @@
 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;
@@ -80,24 +79,12 @@
     @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();
@@ -143,12 +130,6 @@
         }
     }
 
-    /**
-     * 鍙戝竷鐏屾簤璁″垝
-     *
-     * @param planSimple
-     * @return
-     */
     public Map publishPlan(PlanSimple planSimple) {
         Long planId = planSimple.getPlanId();
         Long operatorId = planSimple.getOperatorId();
@@ -185,10 +166,6 @@
             }
         }
 
-        /**
-         * 鑾峰彇鐏屾簤璁″垝淇℃伅
-         * 鏇存柊鐏屾簤璁″垝璧锋鏃堕棿鍙婅鍒掔姸鎬�
-         */
         VoPlanSimple plan = irrigatePlanMapper.getPlanSimple(planId);
         if (plan == null) {
             Map map = new HashMap<>();
@@ -217,10 +194,41 @@
             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);
@@ -229,29 +237,6 @@
             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);
@@ -269,6 +254,13 @@
         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鐨�
@@ -518,12 +510,6 @@
         return irIrrigateUnitMapper.getIntakeIdByUnitId(unitId);
     }
 
-    /**
-     * 鏍规嵁璁″垝ID鑾峰彇璁″垝鍙戝竷缁撴灉
-     *
-     * @param planId
-     * @return
-     */
     public VoPlanDetails getPublishResults(Long planId) {
         VoPlanDetails planDetails = irrigatePlanMapper.getPlanDetails(planId);
         if (planDetails == null) {
@@ -548,15 +534,8 @@
 
         planDetails.setGroups(groupResults);
         return planDetails;
-
     }
 
-    /**
-     * 鏍规嵁璁″垝ID鑾峰彇璁″垝缁堟鎿嶄綔缁撴灉
-     *
-     * @param planId
-     * @return
-     */
     public VoPlanDetails getTerminateResults(Long planId) {
         // 鑾峰彇璁″垝缁堟鏃堕棿
         Date terminateTime = Optional.ofNullable(irPlanOperateMapper.getTerminateTime(planId)).orElse(null);

--
Gitblit v1.8.0