From bf580699fbe3fe2996712d90f09325e870991435 Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期三, 04 六月 2025 09:33:45 +0800
Subject: [PATCH] 两次请求命令时保存第二次的ID,开阀时判断阀门开闭状态

---
 pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigatePlan/IrrigatePlanSv.java |   53 ++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 38 insertions(+), 15 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..86c013c 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;
@@ -217,28 +216,27 @@
             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());
@@ -249,6 +247,24 @@
             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());
+        }
+
+        // 鏍规嵁璁″垝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;
         }
 
         // 娣诲姞鐏屾簤璁″垝鎿嶄綔璁板綍
@@ -269,6 +285,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鐨�

--
Gitblit v1.8.0