From c03f536ed22584a4899f48061a8eca8b5a5b7f59 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期四, 03 四月 2025 15:44:44 +0800
Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV

---
 pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIntakeOperateMapper.java                  |    9 ++
 pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIrrigatePlanMapper.java                   |    7 +
 pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIrrigatePlanMapper.xml                                  |   17 ++++
 pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/CommandSv.java             |    5 
 pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/resources/application-self.yml                              |    7 +
 pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/ValveCtrl.java             |    2 
 pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigatePlan/IrrigatePlanCtrl.java |  111 ++++++++++++++++++++-------
 pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIntakeOperateMapper.xml                                 |    8 ++
 pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigatePlan/IrrigatePlanSv.java   |   30 +++++++
 9 files changed, 164 insertions(+), 32 deletions(-)

diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIntakeOperateMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIntakeOperateMapper.java
index f0b4201..734c09c 100644
--- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIntakeOperateMapper.java
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIntakeOperateMapper.java
@@ -5,6 +5,8 @@
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 /**
  * @author ZhuBaoMin
  * @date 2025-04-02 10:54
@@ -33,4 +35,11 @@
      * @return
      */
     int updateByCommandId(@Param("commandId") Long commandId, @Param("commandResult") Byte commandResult, @Param("failureFactors") String failureFactors);
+
+    /**
+     * 鏍规嵁璁″垝ID鑾峰彇寰呯粓姝㈢殑鍙栨按鍙D锛堝凡鍙戝竷寮�鍙戝懡浠わ紝鏃犺鏄惁鎴愬姛锛�
+     * @param planId
+     * @return
+     */
+    List<Long> getToTerminateIntakeIds(Long planId);
 }
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIrrigatePlanMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIrrigatePlanMapper.java
index 44d7b26..b9afdc0 100644
--- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIrrigatePlanMapper.java
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrIrrigatePlanMapper.java
@@ -78,4 +78,11 @@
      * @return
      */
     List<VoPlans> getCompletedPlans();
+
+    /**
+     * 鏍规嵁璁″垝ID鑾峰彇寰呯粓姝㈣鍒掔殑缁撴潫鏃堕棿锛氭湭鍒犻櫎銆佹湭缁堟銆佸凡鍙戝竷銆佸綋鍓嶆椂闂村皬浜庤鍒掔粨鏉熸椂闂�
+     * @param planId
+     * @return
+     */
+    Date getToTerminatePlan(@Param("planId") Long planId);
 }
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIntakeOperateMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIntakeOperateMapper.xml
index ab8bc1a..4790842 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIntakeOperateMapper.xml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIntakeOperateMapper.xml
@@ -155,4 +155,12 @@
     set command_result = #{commandResult}, failure_factors = #{failureFactors}
     where command_id = #{commandId}
   </update>
+
+  <!--鏍规嵁璁″垝ID鑾峰彇寰呯粓姝㈢殑鍙栨按鍙D锛堝凡鍙戝竷寮�鍙戝懡浠わ紝鏃犺鏄惁鎴愬姛锛�-->
+  <select id="getToTerminateIntakeIds" resultType="java.lang.Long">
+    SELECT
+      intake_id AS intakeId
+    FROM ir_intake_operate
+    WHERE operate_type = 1 AND plan_id = #{planId}
+  </select>
 </mapper>
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIrrigatePlanMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIrrigatePlanMapper.xml
index 08b7a87..50a525a 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIrrigatePlanMapper.xml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrIrrigatePlanMapper.xml
@@ -320,4 +320,21 @@
     ORDER BY plan.plan_state DESC
   </select>
 
+  <!--鏍规嵁璁″垝ID鑾峰彇寰呯粓姝㈣鍒掔殑缁撴潫鏃堕棿锛氭湭鍒犻櫎銆佹湭缁堟銆佸凡鍙戝竷銆佸綋鍓嶆椂闂村皬浜庤鍒掔粨鏉熸椂闂�-->
+  <select id="getToTerminatePlan" resultType="java.util.Date">
+    SELECT
+      plan_start_time AS planStartTime
+    FROM ir_irrigate_plan
+    <where>
+      AND deleted = 0
+      AND executing_state != 3
+      AND plan_state = 2
+      AND NOW() &lt; plan_stop_time
+      <if test = "planId != null">
+        AND id = #{planId}
+      </if>
+    </where>
+
+  </select>
+
 </mapper>
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/CommandSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/CommandSv.java
index 714a413..2cd24f0 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/CommandSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/CommandSv.java
@@ -250,7 +250,7 @@
      * @param automaticClose
      * @return
      */
-    public Map planedOpenTimedClose(AutomaticClose automaticClose, Long planId, Date startTime, Integer duration) {
+    public Map planedOpenTimedClose(AutomaticClose automaticClose, Long planId, Byte operatetype, Date startTime, Integer duration) {
         Long intakeId = automaticClose.getIntakeId();
         Long vcId = automaticClose.getVcId();
         Date plannedOpenTime = automaticClose.getPlannedOpenTime();
@@ -259,10 +259,11 @@
         Byte openType = automaticClose.getOpenType();
         Long comId = new IDLongGenerator().generate();
 
+        // 濡傛灉鏄疆鐏�
         if(openType != null && openType == 1) {
             IrIntakeOperate irIntakeOperate = new IrIntakeOperate();
             irIntakeOperate.setPlanId(planId);
-            irIntakeOperate.setOperateType((byte)1);
+            irIntakeOperate.setOperateType(operatetype);
             irIntakeOperate.setCommandId(comId);
             irIntakeOperate.setIntakeId(intakeId);
             irIntakeOperate.setStartTime(startTime);
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/ValveCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/ValveCtrl.java
index 74f1502..bfe5672 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/ValveCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/ValveCtrl.java
@@ -538,7 +538,7 @@
             return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
         }
 
-        Map map_result = commandSv.planedOpenTimedClose(automaticClose, null, null,null);
+        Map map_result = commandSv.planedOpenTimedClose(automaticClose, null, null, null,null);
         if(map_result.get("success").equals(false)) {
             return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
         }
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigatePlan/IrrigatePlanCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigatePlan/IrrigatePlanCtrl.java
index 59708ae..8114e04 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigatePlan/IrrigatePlanCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/irrigatePlan/IrrigatePlanCtrl.java
@@ -25,6 +25,7 @@
 
 import java.time.LocalDateTime;
 import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.Date;
 import java.util.List;
 import java.util.Objects;
@@ -112,7 +113,7 @@
 
         // 娣诲姞鐏屾簤娆″簭鍙婅鍒掓搴忓叧鑱旇〃
         //Date scheduleStartTime = null;
-        Integer sort = 0;
+        Integer sort = 1;
         for(IrrigateSchedule schedule : planAndSchedule.getSchedules()){
             IrIrrigateSchedule po = new IrIrrigateSchedule();
             po.setGroupId(schedule.getGroupId());
@@ -205,6 +206,7 @@
 
         Long planId = planSimple.getPlanId();
         Long operatorId = planSimple.getOperatorId();
+        Byte operateType = 1;
 
         /**
          * 鑾峰彇鐏屾簤璁″垝淇℃伅
@@ -225,7 +227,8 @@
         }
         LocalDateTime startTime = planStartTime.toInstant().atZone(ZoneId.systemDefault()) .toLocalDateTime();
         if(startupMode == 1){
-            startTime = startTime.plusMinutes(5);
+            startTime = startTime.plusMinutes(1);
+            //startTime = startTime.plusMinutes(5);
         }
         planStartTime = Date.from(startTime.atZone(ZoneId.systemDefault()).toInstant());
         LocalDateTime stopTime = startTime.plusMinutes(duration);
@@ -266,14 +269,17 @@
             Long groupId = schedule.getGroupId();
             List<Long> intakeIds = irrigatePlanSv.getIntakeIdsByGroupId(groupId);
             for(Long intakeId : intakeIds) {
-                AutomaticClose automaticClose = new AutomaticClose();
-                automaticClose.setIntakeId(intakeId);
-                automaticClose.setPlannedOpenTime(schedule.getStartTime());
-                automaticClose.setMinutes(schedule.getDuration());
-                automaticClose.setOperator(operatorId);
-                automaticClose.setOpenType(Byte.valueOf("1"));
+                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, schedule.getStartTime(), schedule.getDuration());
+                    commandSv.planedOpenTimedClose(automaticClose, planId, operateType, schedule.getStartTime(), schedule.getDuration());
+                }
             }
         }
 
@@ -286,24 +292,71 @@
      * @param bindingResult
      * @return
      */
-    //@PostMapping(path = "terminatePlan", consumes = MediaType.APPLICATION_JSON_VALUE)
-    //@Transactional(rollbackFor = Exception.class)
-    //public BaseResponse<Boolean> terminatePlan(@RequestBody @Valid PlanSimple planSimple, BindingResult bindingResult){
-    //    if(bindingResult != null && bindingResult.hasErrors()){
-    //        return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
-    //    }
-    //
-    //    Long planId = planSimple.getPlanId();
-    //    Long operatorId = planSimple.getOperatorId();
-    //
-    //    IrIrrigatePlan iIrrigatePlan = new IrIrrigatePlan();
-    //    iIrrigatePlan.setId(planId);
-    //    iIrrigatePlan.setExecutingState((byte)3);
-    //    if(irrigatePlanSv.updatePlan(iIrrigatePlan) == 0){
-    //        return BaseResponseUtils.buildErrorMsg("缁堟璁″垝鐘舵�佸け璐�");
-    //    }
-    //
-    //
-    //
-    //}
+    @PostMapping(path = "terminatePlan", consumes = MediaType.APPLICATION_JSON_VALUE)
+    @Transactional(rollbackFor = Exception.class)
+    public BaseResponse<Boolean> terminatePlan(@RequestBody @Valid PlanSimple planSimple, BindingResult bindingResult){
+        if(bindingResult != null && bindingResult.hasErrors()){
+            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+        }
+
+        Long planId = planSimple.getPlanId();
+        Long operatorId = planSimple.getOperatorId();
+        Byte operateType = 2;
+
+        // 鐢熸垚缁堟寮�濮嬫椂闂淬�佺粓姝㈢亴婧夋椂闀�
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        String terminateStartTimeStr = "2000-01-01 00:00:00";
+        Date terminateStartTime = Date.from(LocalDateTime.parse(terminateStartTimeStr, formatter).atZone(ZoneId.systemDefault()).toInstant());
+        Integer terminateDuration = 100000;
+
+        // 鑾峰彇鍙粓姝㈡搷浣滆鍒掔殑鐏屾簤寮�濮嬫椂闂�
+        Date planStartTime = irrigatePlanSv.getToTerminatePlan(planId);
+        if(planStartTime == null){
+            return BaseResponseUtils.buildErrorMsg("璇ヨ鍒掍笉瀛樺湪鎴栦笉鏀寔缁堟鎿嶄綔");
+        }
+
+        // 缁堟璁″垝
+        IrIrrigatePlan iIrrigatePlan = new IrIrrigatePlan();
+        iIrrigatePlan.setId(planId);
+        iIrrigatePlan.setExecutingState((byte)3);
+        if(irrigatePlanSv.updatePlan(iIrrigatePlan) == 0){
+            return BaseResponseUtils.buildErrorMsg("缁堟璁″垝澶辫触");
+        }
+
+        // 缁堟鐏屾簤娆″簭
+        if(irrigatePlanSv.terminateSchedule(planId) == 0){
+            return BaseResponseUtils.buildErrorMsg("缁堟鐏屾簤娆″簭澶辫触");
+        }
+
+        // 娣诲姞缁堟鎿嶄綔璁板綍
+        IrPlanOperate planOperate  = new IrPlanOperate();
+        planOperate.setPlanId(planId);
+        planOperate.setOperator(operatorId);
+        planOperate.setOperateType(OperateTypeENUM.TERMINATE.getCode());
+        planOperate.setOperateTime(new Date());
+        if(irrigatePlanSv.addPlanOperate(planOperate) == 0){
+            return BaseResponseUtils.buildErrorMsg("娣诲姞缁堟鎿嶄綔璁板綍澶辫触");
+        }
+
+        Date currentTime = new Date();
+        if(currentTime.before(planStartTime)){
+            // 鍙栨秷寮�闃�璁″垝
+            List<Long> intakeIds = irrigatePlanSv.getToTerminateIntakeIds(planId);
+            for(Long intakeId : intakeIds) {
+                AutomaticClose automaticClose = new AutomaticClose();
+                automaticClose.setIntakeId(intakeId);
+                automaticClose.setPlannedOpenTime(terminateStartTime);
+                automaticClose.setMinutes(terminateDuration);
+                automaticClose.setOperator(operatorId);
+                automaticClose.setOpenType(Byte.valueOf("1"));
+
+                commandSv.planedOpenTimedClose(automaticClose, planId, operateType, terminateStartTime, terminateDuration);
+            }
+        } else {
+            // 鎵ц杩滅▼鍏抽榾
+        }
+
+        return BaseResponseUtils.buildSuccess();
+
+    }
 }
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 0bb1ba1..11e295a 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
@@ -49,6 +49,9 @@
     @Autowired
     private IrGroupIntakeMapper irGroupIntakeMapper;
 
+    @Autowired
+    private IrIntakeOperateMapper irIntakeOperateMapper;
+
     /**
      * 娣诲姞鐏屾簤璁″垝
      * @param po
@@ -57,6 +60,24 @@
     public Long addIrrigatePlan(IrIrrigatePlan po) {
         irrigatePlanMapper.insert(po);
         return po.getId();
+    }
+
+    /**
+     * 鏍规嵁璁″垝ID鑾峰彇寰呯粓姝㈣鍒掔殑缁撴潫鏃堕棿锛氭湭鍒犻櫎銆佹湭缁堟銆佸凡鍙戝竷銆佸綋鍓嶆椂闂村皬浜庤鍒掔粨鏉熸椂闂�
+     * @param planId
+     * @return
+     */
+    public Date getToTerminatePlan(Long planId) {
+        return irrigatePlanMapper.getToTerminatePlan(planId);
+    }
+
+    /**
+     * 鏍规嵁璁″垝ID鑾峰彇寰呯粓姝㈢殑鍙栨按鍙D锛堝凡鍙戝竷寮�鍙戝懡浠わ紝鏃犺鏄惁鎴愬姛锛�
+     * @param planId
+     * @return
+     */
+    public List<Long> getToTerminateIntakeIds(Long planId) {
+        return irIntakeOperateMapper.getToTerminateIntakeIds(planId);
     }
 
     /**
@@ -133,6 +154,15 @@
     }
 
     /**
+     * 鏍规嵁璁″垝ID缁堟鐏屾簤娆″簭锛屽皢鐏屾簤娆″簭鐨勫綋鍓嶇姸鎬佹敼涓哄凡缁堟
+     * @param planId
+     * @return
+     */
+    public Integer terminateSchedule(Long planId) {
+        return irIrrigateScheduleMapper.terminateSchedule(planId);
+    }
+
+    /**
      * 鏍规嵁璁″垝ID鑾峰彇鐏屾簤娆″簭璁板綍
      * @param planId
      * @return
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/resources/application-self.yml b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/resources/application-self.yml
index 188b296..1a7ca23 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/resources/application-self.yml
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/resources/application-self.yml
@@ -20,3 +20,10 @@
         sms-access-key-secret: sU2CoLdNgcjnf5uPPU2dY7NNGNvOIX
         sms-template-code: SMS_460776024
         sms-sign-name: 澶х鑺傛按
+
+logging:
+    level:
+        com:
+            dy:
+                pipIrrGlobal:
+                    daoIr: trace
\ No newline at end of file

--
Gitblit v1.8.0