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/command/CommandSv.java |  163 +++++++++++++-----------------------------------------
 1 files changed, 40 insertions(+), 123 deletions(-)

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 26e45fb..f4df780 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
@@ -17,11 +17,11 @@
 import com.dy.common.mw.protocol.p206V202404.downVos.ComCd93_A3Vo;
 import com.dy.common.util.IDLongGenerator;
 import com.dy.common.webUtil.BaseResponse;
-import com.dy.common.webUtil.BaseResponseUtils;
 import com.dy.common.webUtil.QueryResultVo;
 import com.dy.pipIrrGlobal.command.ComSupport;
 import com.dy.pipIrrGlobal.command.dto.Param;
 import com.dy.pipIrrGlobal.daoIr.IrIntakeOperateMapper;
+import com.dy.pipIrrGlobal.daoPr.PrIntakeControllerMapper;
 import com.dy.pipIrrGlobal.daoPr.PrIntakeMapper;
 import com.dy.pipIrrGlobal.daoPr.PrIntakeVcMapper;
 import com.dy.pipIrrGlobal.daoPr.PrWaterPriceMapper;
@@ -40,6 +40,7 @@
 import com.dy.pipIrrWechat.command.dto.AutomaticClose;
 import com.dy.pipIrrWechat.command.dto.ValveClose;
 import com.dy.pipIrrWechat.command.dto.ValveOpen;
+import com.dy.pipIrrWechat.irrigation.IrrigationSv;
 import com.dy.pipIrrWechat.result.WechatResultCode;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -47,6 +48,7 @@
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
 
@@ -71,6 +73,8 @@
     private final RmOpenCloseValveLastMapper rmOpenCloseValveLastMapper;
     //private final PrCommonIntakesMapper prCommonIntakesMapper;
     private final IrIntakeOperateMapper irIntakeOperateMapper;
+    private final IrrigationSv irrigationSv;
+    private final PrIntakeControllerMapper prIntakeControllerMapper;
 
     @Value("${mw.rtuCallbackUrl_wx}")
     private String rtuCallbackUrl_wx;
@@ -84,7 +88,7 @@
     private String pro_mw = "mw";
     private String key_mw = "comSendUrl";
     @Autowired
-    public CommandSv(RmCommandHistoryMapper rmCommandHistoryMapper,RmOpenCloseValveLastMapper rmOpenCloseValveLastMapper, SeVirtualCardMapper seVirtualCardMapper, PrIntakeMapper prIntakeMapper, PrWaterPriceMapper prWaterPriceMapper, PrIntakeVcMapper prIntakeVcMapper, SeClientCardMapper seClientCardMapper, RmIrrigateProfileMapper rmIrrigateProfileMapper, Environment env, IrIntakeOperateMapper irIntakeOperateMapper) {
+    public CommandSv(RmCommandHistoryMapper rmCommandHistoryMapper,RmOpenCloseValveLastMapper rmOpenCloseValveLastMapper, SeVirtualCardMapper seVirtualCardMapper, PrIntakeMapper prIntakeMapper, PrWaterPriceMapper prWaterPriceMapper, PrIntakeVcMapper prIntakeVcMapper, SeClientCardMapper seClientCardMapper, RmIrrigateProfileMapper rmIrrigateProfileMapper, Environment env, IrIntakeOperateMapper irIntakeOperateMapper, IrrigationSv irrigationSv, PrIntakeControllerMapper prIntakeControllerMapper) {
         this.rmCommandHistoryMapper = rmCommandHistoryMapper;
         this.rmOpenCloseValveLastMapper = rmOpenCloseValveLastMapper;
         //this.prCommonIntakesMapper = prCommonIntakesMapper;
@@ -96,29 +100,19 @@
         this.rmIrrigateProfileMapper = rmIrrigateProfileMapper;
         this.env = env;
         this.irIntakeOperateMapper = irIntakeOperateMapper;
+        this.irrigationSv = irrigationSv;
+        this.prIntakeControllerMapper = prIntakeControllerMapper;
     }
-    /**
-     * 铏氭嫙鍗D鎹㈣櫄鎷熷崱瀵硅薄
-     * @param vcId
-     * @return
-     */
+
     public VoVirtualCard getVcById(Long vcId) {
         return seVirtualCardMapper.getVcById(vcId);
     }
 
-    /**
-     * 鑾峰彇姘翠环
-     * @return
-     */
+
     public Double getPrice() {
         return prWaterPriceMapper.getPrice();
     }
 
-    /**
-     * 鏍规嵁鎿嶄綔鍛業D鑾峰彇鏈叧闃�璁板綍锛堝寘鍚湪绾挎儏鍐碉級
-     * @param operator
-     * @return
-     */
     public List<VoUnclosedValve> getUnclosedValves(Long operator) {
         Command com = new Command() ;
         com.id = Command.defaultId;
@@ -126,6 +120,7 @@
         com.type = "innerCommand";
         comSendUrl = env.getProperty(pro_mw + "." + DataSourceContext.get() + "." + key_mw);
         JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com));
+        String aa = response.toJSONString();
 
         JSONArray jsonArray = new JSONArray();
         if(response != null && response.getString("code").equals("0001")) {
@@ -141,10 +136,6 @@
             //System.out.println(jsonArray.toJSONString());
         }
 
-        /**
-         * 鑾峰彇鏈叧闃�鐨凴TU鍦板潃鍜岃櫄鎷熷崱缂栧彿瀵规暟缁�
-         * 閬嶅巻鏁扮粍鑾峰彇鏈�鍚庡懡浠ゆ棩蹇桰D闆嗗悎
-         */
         List<VoRtuAndVc> rtus = rmCommandHistoryMapper.getUnclosedRtus(operator);
         String comIds = "";
         if(rtus != null && rtus.size() > 0) {
@@ -166,78 +157,37 @@
         return new ArrayList<>();
     }
 
-    /**
-     * 涓烘寚瀹氾紙闃�鎺у櫒鍦板潃銆佹按鍗$紪鍙枫�佹棤鍏抽榾璁板綍锛夊紑鍏抽榾鏈�鏂拌褰曟坊鍔犲叧闃�鏃堕棿锛屼娇涔嬩笉鍦ㄦ湭鍏抽榾璁板綍涓樉绀�
-     * @param rtuAddr
-     * @param icCardNo
-     * @return
-     */
     public Integer addClostTime(String rtuAddr, String icCardNo) {
         return rmOpenCloseValveLastMapper.addCloseTime(rtuAddr, icCardNo);
     }
 
-    /**
-     * 鏍规嵁鍙栨按鍙D鑾峰彇涓庝箣缁戝畾铏氭嫙鍗D
-     * @param intakeId
-     * @return
-     */
     public Long getVcIdByIntakeId(Long intakeId) {
         return prIntakeVcMapper.getVcIdByIntakeId(intakeId);
     }
 
-    /**
-     * 鏍规嵁姘村崱缂栧彿鑾峰彇姘村崱瀵硅薄锛岃繙绋嬪厖鍊间娇鐢�
-     * @param cardId
-     * @return
-     */
     public SeClientCard geClientCardByCardId(Long cardId) {
         return seClientCardMapper.selectByPrimaryKey(cardId);
     }
 
-    /**
-     * 娣诲姞鍛戒护鏃ュ織
-     * @param po 鍛戒护鏃ュ織瀵硅薄
-     * @return 瀛楃涓茬被鍨嬬殑涓婚敭
-     */
     public Long insert(RmCommandHistory po) {
         rmCommandHistoryMapper.insert(po);
         return po.getComId();
     }
 
-    /**
-     * 淇敼鍛戒护鏃ュ織淇℃伅
-     * @param po 鍛戒护鏃ュ織瀵硅薄
-     * @return 褰卞搷璁板綍鏁伴噺
-     */
     public Integer update(RmCommandHistory po) {
         return rmCommandHistoryMapper.updateByPrimaryKeySelective(po);
     }
 
-    /**
-     * 鍙栨按鍙e悕绉版崲鍙栨按鍙D锛屾壂鐮佸紑闃�浣跨敤
-     * @param intakeName
-     * @return
-     */
     public Long getIntakeIdByName(String intakeName) {
         return prIntakeMapper.getIntakeIdByName(intakeName);
     }
 
-    /**
-     * 鏍规嵁閰嶇疆绫诲瀷鑾峰彇閰嶇疆鍊�
-     * @param type
-     * @return
-     */
     QueryResultVo<List<VoIrrigaterProfile>> getIrrPro(Integer type) {
         QueryResultVo<List<VoIrrigaterProfile>> rsVo = new QueryResultVo<>() ;
         rsVo.obj = rmIrrigateProfileMapper.getIrrPro(type);
         return rsVo ;
     }
 
-    /**
-     * 娣诲姞鍙栨按鍙f搷浣滆褰曪紝杞亴杩囩▼鍛戒护涓嬪彂鏃朵娇鐢�
-     * @param po
-     * @return
-     */
     public Long addIntakeOperate(IrIntakeOperate po) {
         irIntakeOperateMapper.insert(po);
         return po.getId();
@@ -253,11 +203,7 @@
     //    return irIntakeOperateMapper.updateByCommandId(commandId, commandResult);
     //}
 
-    /**
-     * 瀹氭椂鍏抽榾寮忚鍒掑紑闃�
-     * @param automaticClose
-     * @return
-     */
+    @Transactional(rollbackFor = Exception.class)
     public Map planedOpenTimedClose(AutomaticClose automaticClose, Long planId, Byte operatetype, Date startTime, Integer duration) {
         Long intakeId = automaticClose.getIntakeId();
         Long vcId = automaticClose.getVcId();
@@ -266,8 +212,10 @@
         Long operator = automaticClose.getOperator();
         Byte openType = automaticClose.getOpenType();
         Long comId = new IDLongGenerator().generate();
+        String intakeName = Optional.ofNullable(prIntakeControllerMapper.getIntakeNameById(intakeId)).orElse("");
 
         // 濡傛灉鏄疆鐏�
+        Long operateId = null;
         if(openType != null && openType == 1) {
             IrIntakeOperate irIntakeOperate = new IrIntakeOperate();
             irIntakeOperate.setPlanId(planId);
@@ -277,8 +225,8 @@
             irIntakeOperate.setStartTime(startTime);
             irIntakeOperate.setDuration(duration);
 
-            Long id = addIntakeOperate(irIntakeOperate);
-            if(id == null) {
+            operateId = addIntakeOperate(irIntakeOperate);
+            if(operateId == null) {
                 Map map = new HashMap<>();
                 map.put("success", false);
                 map.put("msg", "娣诲姞鍙栨按鍙f搷浣滆褰曞け璐�");
@@ -293,11 +241,6 @@
         Integer hour = Integer.parseInt(String.format("%tH", plannedOpenTime));
         Integer minute = Integer.parseInt(String.format("%tM", plannedOpenTime));
 
-        /**
-         * 濡傛灉鍐滄埛閫夋嫨浜嗚櫄鎷熷崱锛屽垯浣跨敤璇ヨ櫄鎷熷崱
-         * 濡傛灉鍐滄埛鏈�夋嫨铏氭嫙鍗★紝鍒欐牴鎹彇姘村彛ID鑾峰彇涓庝箣缁戝畾鐨勮櫄鎷熷崱
-         * 濡傛灉鍙栨按鍙f病鏈変笌涔嬬粦瀹氱殑铏氭嫙鍗★紝鍒欐彁绀哄啘鎴烽�夋嫨涓�寮犺櫄鎷熷崱
-         */
         if(vcId == null) {
             vcId = getVcIdByIntakeId(intakeId);
             if(vcId == null) {
@@ -305,7 +248,7 @@
 
                 Map map = new HashMap<>();
                 map.put("success", false);
-                map.put("msg", WechatResultCode.PLEASE_SELECT_A_VC.getMessage() + "(" + intakeId + ")");
+                map.put("msg", WechatResultCode.PLEASE_SELECT_A_VC.getMessage() + "(" + intakeName + ")");
                 map.put("content", null);
                 return map;
             }
@@ -318,14 +261,14 @@
 
             Map map = new HashMap<>();
             map.put("success", false);
-            map.put("msg", WechatResultCode.PLEASE_SELECT_A_VC.getMessage() + "(" + intakeId + ")");
+            map.put("msg", WechatResultCode.PLEASE_SELECT_A_VC.getMessage() + "(" + intakeName + ")");
             map.put("content", null);
             return map;
         }
         String vcNum = vc.getVcNum().toString();
         Double moneyRemain = vc.getMoney();
         if(moneyRemain < 100) {
-            irIntakeOperateMapper.updateByCommandId(comId, (byte)2, "铏氭嫙鍗′綑棰濅笉瓒筹紝璇峰厖鍊�" + "(" + intakeId + ")");
+            irIntakeOperateMapper.updateByCommandId(comId, (byte)2, "铏氭嫙鍗′綑棰濅笉瓒筹紝璇峰厖鍊�" + "(" + intakeName + ")");
             Map map = new HashMap<>();
             map.put("success", false);
             map.put("msg", "铏氭嫙鍗′綑棰濅笉瓒筹紝璇峰厖鍊�");
@@ -336,6 +279,7 @@
         // 鑾峰彇姘翠环
         Double waterPrice = getPrice();
         if(waterPrice == null) {
+            irIntakeOperateMapper.updateByCommandId(comId, (byte)2, WechatResultCode.NO_WATER_PRICE.getMessage() + "(" + intakeName + ")");
             Map map = new HashMap<>();
             map.put("success", false);
             map.put("msg", WechatResultCode.NO_WATER_PRICE.getMessage());
@@ -346,7 +290,7 @@
         // 鍙栨按鍙D鎹㈤榾鎺у櫒鍦板潃鍙婇�氳鍗忚
         JSONObject job_rtu = getRtu(intakeId, null);
         if(job_rtu == null) {
-            irIntakeOperateMapper.updateByCommandId(comId, (byte)2, WechatResultCode.RTU_NOT_EXIST.getMessage() + "(" + intakeId + ")");
+            irIntakeOperateMapper.updateByCommandId(comId, (byte)2, WechatResultCode.RTU_NOT_EXIST.getMessage() + "(" + intakeName + ")");
 
             Map map = new HashMap<>();
             map.put("success", false);
@@ -362,11 +306,22 @@
         // 鐢熸垚璁㈠崟鍙�
         String orderNo = generateOrderNo();
         if(orderNo == null) {
-            irIntakeOperateMapper.updateByCommandId(comId, (byte)2, WechatResultCode.NO_ORDER_NUMBER.getMessage() + "(" + intakeId + ")");
+            irIntakeOperateMapper.updateByCommandId(comId, (byte)2, WechatResultCode.NO_ORDER_NUMBER.getMessage() + "(" + intakeName + ")");
 
             Map map = new HashMap<>();
             map.put("success", false);
             map.put("msg", WechatResultCode.NO_ORDER_NUMBER.getMessage());
+            map.put("content", null);
+            return map;
+        }
+
+        // 鍒ゆ柇闃�鎺у櫒鏄惁宸茬粡寮�闃�
+        Boolean isOpen = irrigationSv.getOpenCloseStatus(rtuAddr);
+        if(isOpen) {
+            irIntakeOperateMapper.updateByCommandId(comId, (byte)2, intakeName + " 闃�闂ㄤ负鎵撳紑鐘舵��");
+            Map map = new HashMap<>();
+            map.put("success", false);
+            map.put("msg", intakeName + " 闃�闂ㄤ负鎵撳紑鐘舵��");
             map.put("content", null);
             return map;
         }
@@ -395,11 +350,6 @@
             param.setMinute(minute);
             param.setOrderNo(orderNo);
 
-            /**
-             * 鏋勯�犲懡浠ゃ�佸彂閫佸懡浠ゅ苟澶勭悊璇锋眰缁撴灉鍙婃墽琛岀粨鏋�
-             * 1 鍑嗗鍙傛暟
-             * 2 璋冪敤鍏叡鏂规硶
-             */
             Param myParam = new Param();
             myParam.setComId(comId);
             myParam.setComType((byte)1);
@@ -417,8 +367,12 @@
             BaseResponse<Boolean> result = dealWithCommandResult(myParam);
             // 濡傛灉鍛戒护鎵ц澶辫触锛屽垯鍐嶆鎵ц鍛戒护
             if(!result.isSuccess()) {
-                myParam.setComId(new IDLongGenerator().generate());
+                Long newComId = new IDLongGenerator().generate();
+                myParam.setComId(newComId);
                 result = dealWithCommandResult(myParam);
+
+                // 鏍规嵁operateId淇敼鍙栨按鍙f搷浣滆褰曚腑鐨刢ommandId
+                irIntakeOperateMapper.updateCommandId(newComId, operateId);
             }
 
             Map map = new HashMap<>();
@@ -437,13 +391,6 @@
         }
     }
 
-    /**
-     * 灏忕▼搴忚繙绋嬪紑闃�
-     * @param valve
-     * @param planId
-     * @param operatetype
-     * @return
-     */
     public Map openWx(ValveOpen valve, Long planId, Byte operatetype) {
         Long intakeId = valve.getIntakeId();
         String intakeName = valve.getIntakeName();
@@ -497,11 +444,6 @@
             }
         }
 
-        /**
-         * 濡傛灉鍐滄埛閫夋嫨浜嗚櫄鎷熷崱锛屽垯浣跨敤璇ヨ櫄鎷熷崱
-         * 濡傛灉鍐滄埛鏈�夋嫨铏氭嫙鍗★紝鍒欐牴鎹彇姘村彛ID鑾峰彇涓庝箣缁戝畾鐨勮櫄鎷熷崱
-         * 濡傛灉鍙栨按鍙f病鏈変笌涔嬬粦瀹氱殑铏氭嫙鍗★紝鍒欐彁绀哄啘鎴烽�夋嫨涓�寮犺櫄鎷熷崱
-         */
         if (vcId == null) {
             vcId = getVcIdByIntakeId(intakeId);
             if (vcId == null) {
@@ -600,11 +542,6 @@
             param.elePrice = 0.0;
             param.orderNo = orderNo;
 
-            /**
-             * 鏋勯�犲懡浠ゃ�佸彂閫佸懡浠ゅ苟澶勭悊璇锋眰缁撴灉鍙婃墽琛岀粨鏋�
-             * 1 鍑嗗鍙傛暟
-             * 2 璋冪敤鍏叡鏂规硶
-             */
             Param myParam = new Param();
             myParam.setComId(comId);
             myParam.setComType((byte)1);
@@ -643,11 +580,6 @@
             param.waterPrice = waterPrice;
             param.orderNo = orderNo;
 
-            /**
-             * 鏋勯�犲懡浠ゃ�佸彂閫佸懡浠ゅ苟澶勭悊璇锋眰缁撴灉鍙婃墽琛岀粨鏋�
-             * 1 鍑嗗鍙傛暟
-             * 2 璋冪敤鍏叡鏂规硶
-             */
             Param myParam = new Param();
             myParam.setComId(comId);
             myParam.setComType((byte)1);
@@ -680,13 +612,7 @@
         }
     }
 
-    /**
-     * 灏忕▼搴忚繙绋嬪叧闃�
-     * @param valve
-     * @param planId
-     * @param operatetype
-     * @return
-     */
+    @Transactional(rollbackFor = Exception.class)
     public Map closeWx(ValveClose valve, Long planId, Byte operatetype) {
         String rtuAddr = valve.getRtuAddr();
         String vcNum = valve.getVcNum();
@@ -718,6 +644,7 @@
             irIntakeOperate.setOperateType(operatetype);
             irIntakeOperate.setCommandId(comId);
             irIntakeOperate.setIntakeId(intakeId);
+            irIntakeOperate.setCommandResult((byte)1);
 
             Long id = addIntakeOperate(irIntakeOperate);
             if(id == null) {
@@ -743,11 +670,6 @@
             param.icCardNo = vcNum;
             param.orderNo = orderNo;
 
-            /**
-             * 鏋勯�犲懡浠ゃ�佸彂閫佸懡浠ゅ苟澶勭悊璇锋眰缁撴灉鍙婃墽琛岀粨鏋�
-             * 1 鍑嗗鍙傛暟
-             * 2 璋冪敤鍏叡鏂规硶
-             */
             Param myParam = new Param();
             myParam.setComId(comId);
             myParam.setComType((byte)2);
@@ -777,11 +699,6 @@
             param.icCardNo = vcNum;
             param.orderNo = orderNo;
 
-            /**
-             * 鏋勯�犲懡浠ゃ�佸彂閫佸懡浠ゅ苟澶勭悊璇锋眰缁撴灉鍙婃墽琛岀粨鏋�
-             * 1 鍑嗗鍙傛暟
-             * 2 璋冪敤鍏叡鏂规硶
-             */
             Param myParam = new Param();
             myParam.setComId(comId);
             myParam.setComType((byte)2);

--
Gitblit v1.8.0