From 400af57e240a4c0d74c81ffc8b3417226b51345a Mon Sep 17 00:00:00 2001
From: Administrator <zhubaomin>
Date: 星期四, 06 六月 2024 08:19:13 +0800
Subject: [PATCH] 2024-06-06 朱宝民 生产环境版本

---
 pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/valve/ValveCtrl.java |  440 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 303 insertions(+), 137 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/valve/ValveCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/valve/ValveCtrl.java
index aa2d7c7..f79bf18 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/valve/ValveCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/valve/ValveCtrl.java
@@ -1,27 +1,28 @@
 package com.dy.pipIrrRemote.valve;
 
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
 import com.dy.common.aop.SsoAop;
 import com.dy.common.mw.protocol.Command;
 import com.dy.common.mw.protocol.Data;
+import com.dy.common.mw.protocol.p206V1_0_0.CodeV1_0_1;
+import com.dy.common.mw.protocol.p206V1_0_0.downVos.Com97Vo;
+import com.dy.common.mw.protocol.p206V1_0_0.downVos.Com98Vo;
 import com.dy.common.mw.protocol.p206V202404.CodeV202404;
 import com.dy.common.mw.protocol.p206V202404.downVos.ComCd92_A2Vo;
 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.pipIrrGlobal.daoPr.PrWaterPriceMapper;
-import com.dy.pipIrrGlobal.daoRm.RmCommandHistoryMapper;
+import com.dy.pipIrrGlobal.command.ComSupport;
 import com.dy.pipIrrGlobal.daoSe.SeVirtualCardMapper;
 import com.dy.pipIrrGlobal.pojoRm.RmCommandHistory;
-import com.dy.pipIrrGlobal.pojoSe.SeVirtualCard;
 import com.dy.pipIrrGlobal.voRm.VoUnclosedValve;
 import com.dy.pipIrrGlobal.voSe.VoVirtualCard;
-import com.dy.pipIrrRemote.common.ComSupport;
 import com.dy.pipIrrRemote.common.CommandSv;
 import com.dy.pipIrrRemote.common.dto.ValveClose;
 import com.dy.pipIrrRemote.common.dto.ValveOpen;
 import com.dy.pipIrrRemote.result.RemoteResultCode;
-import com.dy.pipIrrRemote.utils.RestTemplateUtils;
-import com.dy.pipIrrSell.virtualCard.enums.LastOperateENUM;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import jakarta.validation.Valid;
 import lombok.RequiredArgsConstructor;
@@ -31,12 +32,9 @@
 import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.*;
 
-import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
-import java.util.Date;
 import java.util.List;
 import java.util.Objects;
-import java.util.Random;
 
 /**
  * @author ZhuBaoMin
@@ -46,19 +44,18 @@
  */
 
 @Slf4j
-@Tag(name = "鍒嗘按鎴跨鐞�", description = "鍒嗘按鎴挎搷浣�")
+@Tag(name = "骞冲彴闃�鎺у櫒鎺у埗", description = "骞冲彴闃�鎺у櫒鎺у埗")
 @RestController
 @RequestMapping(path="valve")
 @RequiredArgsConstructor
 public class ValveCtrl extends ComSupport {
-    private final RestTemplateUtils restTemplateUtils;
     private final CommandSv commandSv;
     private final SeVirtualCardMapper seVirtualCardMapper;
-    private final PrWaterPriceMapper prWaterPriceMapper;
-    private final RmCommandHistoryMapper rmCommandHistoryMapper;
+    private final IDLongGenerator idLongGenerator;
+    private String rtuResultSendWebUrl = "http://127.0.0.1:8081/remote/comRes/receive" ;
 
     /**
-     * 杩滅▼寮�闃�锛堝钩鍙般�丄PP锛�
+     * 骞冲彴杩滅▼寮�闃�
      * @param valve
      * @param bindingResult
      * @return
@@ -74,47 +71,55 @@
 
         Long intakeId = valve.getIntakeId();
         Long vcId = valve.getVcId();
-        Integer userType = valve.getUserType();
         Long operator = valve.getOperator();
-        String comId = null;
+        Long comId = idLongGenerator.generate();
+
+        /**
+         * 濡傛灉鍐滄埛閫夋嫨浜嗚櫄鎷熷崱锛屽垯浣跨敤璇ヨ櫄鎷熷崱
+         * 濡傛灉鍐滄埛鏈�夋嫨铏氭嫙鍗★紝鍒欐牴鎹彇姘村彛ID鑾峰彇涓庝箣缁戝畾鐨勮櫄鎷熷崱
+         * 濡傛灉鍙栨按鍙f病鏈変笌涔嬬粦瀹氱殑铏氭嫙鍗★紝鍒欐彁绀哄啘鎴烽�夋嫨涓�寮犺櫄鎷熷崱
+         */
+        if(vcId == null) {
+            vcId = commandSv.getVcIdByIntakeId(intakeId);
+            if(vcId == null) {
+                return BaseResponseUtils.buildFail(RemoteResultCode.PLEASE_SELECT_A_VC.getMessage());
+            }
+        }
 
         // 鑾峰彇绯荤粺鍙傛暟
         if(!setuped) {
             setUp();
         }
+// 鍙栨按鍙D鎹㈠彇姘村彛瀵硅薄
+// 濡傛灉鍙栨按鍙d负鎵撳紑鐘舵�侊紝鍒欎笉鍏佽琚紑闃�
 
         // 铏氭嫙鍗D鎹㈣櫄鎷熷崱瀵硅薄
-        VoVirtualCard vc = seVirtualCardMapper.getVcById(vcId);
-        // 鑾峰彇姘翠环
-        Double waterPrice = prWaterPriceMapper.getPrice();
-
-        // 鍙栨按鍙D鎹㈤榾鎺у櫒鍦板潃
-        String rtuAddr = commandSv.getRtuAddrByIntakeId(intakeId);
-        if(rtuAddr == null || rtuAddr.length() == 0) {
-            return BaseResponseUtils.buildError(RemoteResultCode.RTU_ADDR_CANNOT_BE_NULL.getMessage());
+        VoVirtualCard vc = commandSv.getVcById(vcId);
+        if(vc == null) {
+            return BaseResponseUtils.buildFail(RemoteResultCode.PLEASE_SELECT_A_VC.getMessage());
         }
+        if(vc.getInUse() == 1) {
+            return BaseResponseUtils.buildFail(RemoteResultCode.IN_USE_VC_CANNOT_OPEN_VALVE.getMessage());
+        }
+
+        // 鑾峰彇姘翠环
+        Double waterPrice = commandSv.getPrice();
+
+        // 鍙栨按鍙D鎹㈤榾鎺у櫒鍦板潃鍙婇�氳鍗忚
+        JSONObject job_rtu = getRtu(intakeId, null);
+        if(job_rtu == null) {
+            return BaseResponseUtils.buildError(RemoteResultCode.RTU_NOT_EXIST.getMessage());
+        }
+        String rtuAddr = job_rtu.getString("rtuAddr");
+        String protocol = job_rtu.getString("protocol");
 
         // 鐢熸垚璁㈠崟鍙�
-        LocalDateTime dateTime = LocalDateTime.now();
-        Random random = new Random();
-        String CHARACTERS = "0123456789";
-        StringBuilder sb = new StringBuilder(4);
-        for (int i = 0; i < 4; i++) {
-            int index = random.nextInt(CHARACTERS.length());
-            sb.append(CHARACTERS.charAt(index));
-        }
-        String orderNo = dtf.format(dateTime) + sb.toString();
+        String orderNo = generateOrderNo();
 
         String commandCode = null;
-        if(protocolName.equals("p206V202404")) {
+        if(protocol.equals("p206V202404")) {
             // 鑾峰彇鍔熻兘鐮�
-            if(userType == 1) {
-                // 骞冲彴寮�闃�
-                commandCode = CodeV202404.cd_92;
-            }else {
-                // APP寮�闃�
-                commandCode = CodeV202404.cd_A2;
-            }
+            commandCode = CodeV202404.cd_92;
 
             // 鍒涘缓瑙嗗浘
             ComCd92_A2Vo param = new ComCd92_A2Vo();
@@ -127,55 +132,138 @@
             param.elePrice = 0.0;
             param.orderNo = orderNo;
 
-            // 鍒涘缓鍛戒护鏃ュ織瀵硅薄骞舵坊鍔犲埌鏁版嵁搴撲腑
-            RmCommandHistory rmCommandHistory = getComHistory(commandCode, rtuAddr, param, operator);
-            comId = commandSv.insert(rmCommandHistory);
+            // 鏋勯�犲懡浠�
+            Command com = command(comId, commandCode, rtuAddr, protocol, rtuResultSendWebUrl, param);
 
-            // 鏋勯�犲苟鍙戦�佸懡浠�
-            Command com = command(comId, commandCode, rtuAddr, param);
-            sendCom2Mw(com);
-        } else {
-            // 鑾峰彇鍔熻兘鐮�
-            if(userType == 1) {
-                // 骞冲彴寮�闃�
-                commandCode = "92";
-            }else {
-                // APP寮�闃�
-                commandCode = "97";
+            // 鍙戦�佸懡浠�
+            JSONObject response_SendCom= (JSONObject) JSON.toJSON(sendCom2Mw(com));
+            if(response_SendCom != null && response_SendCom.getString("code").equals("0001")) {
+                //if(1 > 0) {
+                // 璇锋眰鎴愬姛
+
+                // 鍒涘缓鍛戒护鏃ュ織瀵硅薄骞舵坊鍔犲埌鏁版嵁搴撲腑
+                String commandName = CodeV202404.getCodeName(commandCode);
+                RmCommandHistory rmCommandHistory = getComHistory(comId, commandCode, commandName, intakeId, rtuAddr, protocol, param, operator);
+                commandSv.insert(rmCommandHistory);
+
+                // 澶勭悊鍥炶皟
+                BaseResponse response_CallBack = dealWithCallBack(comId);
+
+                // 鍥炶皟澶辫触
+                if(!response_CallBack.getCode().equals("0001")) {
+                    // 鍛戒护鏃ュ織鎵ц缁撴灉鏀逛负澶辫触
+                    //rmCommandHistory = new RmCommandHistory();
+                    //rmCommandHistory.setId(comId);
+                    //rmCommandHistory.setResult((byte)0);
+                    //commandSv.updateCommandResult(rmCommandHistory);
+                    return BaseResponseUtils.buildFail(response_CallBack.getMsg());
+                    //return BaseResponseUtils.buildFail(response_CallBack.getContent().toString());
+                }
+
+                // 鍥炶皟鎴愬姛锛屽啀鍒ゆ柇鎵ц鏄惁鎴愬姛
+                JSONObject job_content = (JSONObject)JSON.toJSON(response_CallBack.getContent());
+                System.out.println(job_content);
+                JSONObject job_subData = (JSONObject) job_content.getJSONObject("subData").getJSONObject("subData");
+                System.out.println(job_subData);
+                Boolean dealResult = job_subData.getBoolean("success");
+                if(!dealResult) {
+                    return BaseResponseUtils.buildFail(response_CallBack.getContent().toString());
+                }
+
+                /**
+                 * 鎵ц鎴愬姛
+                 * 鏇存敼铏氭嫙鍗$姸鎬侊細鏄惁浣跨敤涓�佹渶鍚庢搷浣溿�佹渶鍚庢搷浣滄椂闂�
+                 */
+                //SeVirtualCard virtualCard = new SeVirtualCard();
+                //virtualCard.setId(vcId);
+                //virtualCard.setInUse((byte) 1);
+                //virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
+                //virtualCard.setLastOperateTime(new Date());
+                //seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
+
+                // 鍥炶皟杩斿洖鐨勫唴瀹�
+                Data myData = (Data)response_CallBack.getContent();
+                return BaseResponseUtils.buildSuccess(myData) ;
+            } else {
+                // 璇锋眰澶辫触
+                JSONObject job_param = response_SendCom.getJSONObject("content").getJSONObject("param");
+                return BaseResponseUtils.buildFail(job_param.getString("message"));
             }
+        } else if(protocol.equals("p206V1_0_1")) {
+            // 鑾峰彇鍔熻兘鐮�
+            commandCode = CodeV1_0_1.cd_92;
 
             // 鍒涘缓瑙嗗浘
-            ComCd92_A2Vo param = new ComCd92_A2Vo();
+            Com97Vo param = new Com97Vo() ;
+            param.icCardNo = vc.getVcNum();
+            param.moneyRemain = vc.getMoney();
+            param.waterPrice = waterPrice;
+            param.orderNo = orderNo;
 
-            // 鍒涘缓鍛戒护鏃ュ織瀵硅薄骞舵坊鍔犲埌鏁版嵁搴撲腑
-            RmCommandHistory rmCommandHistory = getComHistory(commandCode, rtuAddr, param, operator);
-            comId = commandSv.insert(rmCommandHistory);
+            // 鏋勯�犲懡浠�
+            Command com = command(comId, commandCode, rtuAddr, protocol, rtuResultSendWebUrl, param);
 
-            // 鏋勯�犲苟鍙戦�佸懡浠�
-            Command com = command(comId, commandCode, rtuAddr, param);
-            sendCom2Mw(com);
+            // 鍙戦�佸懡浠�
+            JSONObject response_SendCom= (JSONObject) JSON.toJSON(sendCom2Mw(com));
+            if(response_SendCom != null && response_SendCom.getString("code").equals("0001")) {
+                //if(1 > 0) {
+                // 璇锋眰鎴愬姛
+
+                // 鍒涘缓鍛戒护鏃ュ織瀵硅薄骞舵坊鍔犲埌鏁版嵁搴撲腑
+                String commandName = CodeV1_0_1.getCodeName(commandCode);
+                RmCommandHistory rmCommandHistory = getComHistory(comId, commandCode, commandName, intakeId, rtuAddr, protocol, param, operator);
+                commandSv.insert(rmCommandHistory);
+
+                // 澶勭悊鍥炶皟
+                BaseResponse response_CallBack = dealWithCallBack(comId);
+
+                //鍥炶皟澶辫触
+                if(!response_CallBack.getCode().equals("0001")) {
+                    // 鍛戒护鏃ュ織鎵ц缁撴灉鏀逛负澶辫触
+                    //rmCommandHistory = new RmCommandHistory();
+                    //rmCommandHistory.setId(comId);
+                    //rmCommandHistory.setResult((byte)0);
+                    //commandSv.updateCommandResult(rmCommandHistory);
+                    return BaseResponseUtils.buildFail(response_CallBack.getMsg());
+                    //return BaseResponseUtils.buildFail(response_CallBack.getContent().toString());
+                }
+
+                // 鍥炶皟鎴愬姛锛屽啀鍒ゆ柇鎵ц鏄惁鎴愬姛
+                JSONObject job_content = (JSONObject)JSON.toJSON(response_CallBack.getContent());
+                System.out.println(job_content);
+                JSONObject job_subData = (JSONObject) job_content.getJSONObject("subData").getJSONObject("subData");
+                System.out.println(job_subData);
+                Boolean dealResult = job_subData.getBoolean("success");
+                if(!dealResult) {
+                    return BaseResponseUtils.buildFail(response_CallBack.getContent().toString());
+                }
+
+                /**
+                 * 鎵ц鎴愬姛
+                 * 鏇存敼铏氭嫙鍗$姸鎬侊細鏄惁浣跨敤涓�佹渶鍚庢搷浣溿�佹渶鍚庢搷浣滄椂闂�
+                 */
+                //SeVirtualCard virtualCard = new SeVirtualCard();
+                //virtualCard.setId(vcId);
+                //virtualCard.setInUse((byte) 1);
+                //virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
+                //virtualCard.setLastOperateTime(new Date());
+                //seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
+
+                // 鍥炶皟杩斿洖鐨勫唴瀹�
+                Data myData = (Data)response_CallBack.getContent();
+                return BaseResponseUtils.buildSuccess(myData) ;
+            } else {
+                // 璇锋眰澶辫触
+                JSONObject job_param = response_SendCom.getJSONObject("content").getJSONObject("param");
+                return BaseResponseUtils.buildFail(job_param.getString("message"));
+            }
+        } else {
+            return BaseResponseUtils.buildFail("绯荤粺鏆備笉鏀寔璇ュ崗璁�");
         }
-
-        // 澶勭悊鍥炶皟
-        BaseResponse response = dealWithCallBack(comId);
-        if(!response.getCode().equals("0001")) {
-            return BaseResponseUtils.buildError(RemoteResultCode.GET_RESULT_ERROR.getMessage());
-        }
-
-        // 鏇存敼铏氭嫙鍗$姸鎬侊細鏄惁浣跨敤涓�佹渶鍚庢搷浣溿�佹渶鍚庢搷浣滄椂闂�
-        SeVirtualCard virtualCard = new SeVirtualCard();
-        virtualCard.setId(vcId);
-        virtualCard.setInUse((byte) 1);
-        virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
-        virtualCard.setLastOperateTime(new Date());
-        seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
-
-        Data myData = (Data)response.getContent();
-        return BaseResponseUtils.buildSuccess(myData) ;
     }
 
     /**
-     * 杩滅▼鍏抽榾锛堝钩鍙般�丄PP锛�
+     * 骞冲彴杩滅▼鍏抽榾
      * @param valve
      * @param bindingResult
      * @return
@@ -192,25 +280,26 @@
         String rtuAddr = valve.getRtuAddr();
         String vcNum = valve.getVcNum();
         String orderNo = valve.getOrderNo();
-        Integer userType = valve.getUserType();
         Long operator = valve.getOperator();
-        String comId = null;
+        Long comId = idLongGenerator.generate();
 
         // 鑾峰彇绯荤粺鍙傛暟
         if(!setuped) {
             setUp();
         }
 
+        // 闃�鎺у櫒鍦板潃鎹㈠彇姘村彛ID鍜岄�氳鍗忚
+        JSONObject job_rtu = getRtu(null, rtuAddr);
+        if(job_rtu == null) {
+            return BaseResponseUtils.buildError(RemoteResultCode.RTU_NOT_EXIST.getMessage());
+        }
+        Long intakeId = job_rtu.getLong("intakeId");
+        String protocol = job_rtu.getString("protocol");
+
         String commandCode = null;
-        if(protocolName.equals("p206V202404")) {
+        if(protocol.equals("p206V202404")) {
             // 鑾峰彇鍔熻兘鐮�
-            if (userType == 1) {
-                // 骞冲彴鍏抽榾
-                commandCode = CodeV202404.cd_93;
-            } else {
-                // APP鍏抽榾
-                commandCode = CodeV202404.cd_A3;
-            }
+            commandCode = CodeV202404.cd_93;
 
             // 鍒涘缓瑙嗗浘
             ComCd93_A3Vo param = new ComCd93_A3Vo();
@@ -219,56 +308,133 @@
             param.icCardNo = vcNum;
             param.orderNo = orderNo;
 
-            // 鍒涘缓鍛戒护鏃ュ織瀵硅薄骞舵坊鍔犲埌鏁版嵁搴撲腑
-            RmCommandHistory rmCommandHistory = getComHistory(commandCode, rtuAddr, param, operator);
-            comId = commandSv.insert(rmCommandHistory);
+            // 鏋勯�犲懡浠�
+            Command com = command(comId, commandCode, rtuAddr, protocol, rtuResultSendWebUrl, param);
 
-            // 鏋勯�犲苟鍙戦�佸懡浠�
-            Command com = command(comId, commandCode, rtuAddr, param);
-            sendCom2Mw(com);
+            // 鍙戦�佸懡浠�
+            JSONObject response_SendCom= (JSONObject) JSON.toJSON(sendCom2Mw(com));
+            if(response_SendCom != null && response_SendCom.getString("code").equals("0001")) {
+                // 璇锋眰鎴愬姛
+
+                // 鍒涘缓鍛戒护鏃ュ織瀵硅薄骞舵坊鍔犲埌鏁版嵁搴撲腑
+                String commandName = CodeV202404.getCodeName(commandCode);
+                RmCommandHistory rmCommandHistory = getComHistory(comId, commandCode, commandName, intakeId, rtuAddr, protocol, param, operator);
+                commandSv.insert(rmCommandHistory);
+
+                // 澶勭悊鍥炶皟
+                BaseResponse response_CallBack = dealWithCallBack(comId);
+
+                // 鍥炶皟澶辫触
+                if(!response_CallBack.getCode().equals("0001")) {
+                    // 鍛戒护鏃ュ織鎵ц缁撴灉鏀逛负澶辫触
+                    //rmCommandHistory = new RmCommandHistory();
+                    //rmCommandHistory.setId(comId);
+                    //rmCommandHistory.setResult((byte)0);
+                    //commandSv.updateCommandResult(rmCommandHistory);
+                    return BaseResponseUtils.buildFail(response_CallBack.getMsg());
+                    //return BaseResponseUtils.buildError(WechatResultCode.GET_RESULT_ERROR.getMessage());
+                }
+
+                // 鍥炶皟鎴愬姛锛屽啀鍒ゆ柇鎵ц鏄惁鎴愬姛
+                JSONObject job_content = (JSONObject)JSON.toJSON(response_CallBack.getContent());
+                System.out.println(job_content);
+                JSONObject job_subData = (JSONObject) job_content.getJSONObject("subData").getJSONObject("subData");
+                System.out.println(job_subData);
+                Boolean dealResult = job_subData.getBoolean("success");
+                if(!dealResult) {
+                    return BaseResponseUtils.buildFail(response_CallBack.getContent().toString());
+                }
+
+                /**
+                 * 鎵ц鎴愬姛
+                 * 鏇存敼铏氭嫙鍗$姸鎬侊細鏄惁浣跨敤涓�佹渶鍚庢搷浣溿�佹渶鍚庢搷浣滄椂闂�
+                 */
+                //Long vcId = seVirtualCardMapper.getVcIdByNum(vcNum);
+                //SeVirtualCard virtualCard = new SeVirtualCard();
+                //virtualCard.setId(vcId);
+                //virtualCard.setInUse((byte) 0);
+                //virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
+                //virtualCard.setLastOperateTime(new Date());
+                //seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
+
+                // 鍥炶皟杩斿洖鐨勫唴瀹�
+                Data myData = (Data)response_CallBack.getContent();
+                return BaseResponseUtils.buildSuccess(myData) ;
+            } else {
+                // 璇锋眰澶辫触
+                JSONObject job_param = response_SendCom.getJSONObject("content").getJSONObject("param");
+                return BaseResponseUtils.buildFail(job_param.getString("message"));
+            }
+        } else if(protocol.equals("p206V1_0_1")) {
+            // 鑾峰彇鍔熻兘鐮�
+            commandCode = CodeV1_0_1.cd_93;
+
+            // 鍒涘缓瑙嗗浘
+            Com98Vo param = new Com98Vo() ;
+            param.icCardNo = vcNum;
+            param.orderNo = orderNo;
+
+            // 鏋勯�犲懡浠�
+            Command com = command(comId, commandCode, rtuAddr, protocol, rtuResultSendWebUrl, param);
+
+            // 鍙戦�佸懡浠�
+            JSONObject response_SendCom= (JSONObject) JSON.toJSON(sendCom2Mw(com));
+            if(response_SendCom != null && response_SendCom.getString("code").equals("0001")) {
+                //if(1 > 0) {
+                // 璇锋眰鎴愬姛
+
+                // 鍒涘缓鍛戒护鏃ュ織瀵硅薄骞舵坊鍔犲埌鏁版嵁搴撲腑
+                String commandName = CodeV1_0_1.getCodeName(commandCode);
+                RmCommandHistory rmCommandHistory = getComHistory(comId, commandCode, commandName, intakeId, rtuAddr, protocol, param, operator);
+                commandSv.insert(rmCommandHistory);
+
+                // 澶勭悊鍥炶皟
+                BaseResponse response_CallBack = dealWithCallBack(comId);
+
+                // 鍥炶皟澶辫触
+                if(!response_CallBack.getCode().equals("0001")) {
+                    // 鍛戒护鏃ュ織鎵ц缁撴灉鏀逛负澶辫触
+                    //rmCommandHistory = new RmCommandHistory();
+                    //rmCommandHistory.setId(comId);
+                    //rmCommandHistory.setResult((byte)0);
+                    //commandSv.updateCommandResult(rmCommandHistory);
+                    return BaseResponseUtils.buildFail(response_CallBack.getMsg());
+                    //return BaseResponseUtils.buildError(WechatResultCode.GET_RESULT_ERROR.getMessage());
+                }
+
+                // 鍥炶皟鎴愬姛锛屽啀鍒ゆ柇鎵ц鏄惁鎴愬姛
+                JSONObject job_content = (JSONObject)JSON.toJSON(response_CallBack.getContent());
+                System.out.println(job_content);
+                JSONObject job_subData = (JSONObject) job_content.getJSONObject("subData").getJSONObject("subData");
+                System.out.println(job_subData);
+                Boolean dealResult = job_subData.getBoolean("success");
+                if(!dealResult) {
+                    return BaseResponseUtils.buildFail(response_CallBack.getContent().toString());
+                }
+
+                /**
+                 * 鎵ц鎴愬姛
+                 * 鏇存敼铏氭嫙鍗$姸鎬侊細鏄惁浣跨敤涓�佹渶鍚庢搷浣溿�佹渶鍚庢搷浣滄椂闂�
+                 */
+                //Long vcId = seVirtualCardMapper.getVcIdByNum(vcNum);
+                //SeVirtualCard virtualCard = new SeVirtualCard();
+                //virtualCard.setId(vcId);
+                //virtualCard.setInUse((byte) 0);
+                //virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
+                //virtualCard.setLastOperateTime(new Date());
+                //seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
+
+                // 鍥炶皟杩斿洖鐨勫唴瀹�
+                Data myData = (Data)response_CallBack.getContent();
+                return BaseResponseUtils.buildSuccess(myData) ;
+            } else {
+                // 璇锋眰澶辫触
+                JSONObject job_param = response_SendCom.getJSONObject("content").getJSONObject("param");
+                return BaseResponseUtils.buildFail(job_param.getString("message"));
+            }
         } else {
-            // 鑾峰彇鍔熻兘鐮�
-            if (userType == 1) {
-                // 骞冲彴鍏抽榾
-                commandCode = "93";
-            } else {
-                // APP鍏抽榾
-                commandCode = "98";
-            }
-
-            // 鍒涘缓瑙嗗浘
-            ComCd93_A3Vo param = new ComCd93_A3Vo();
-            param.controllerType = controllerType;
-            param.projectNo = projectNo;
-            param.icCardNo = vcNum;
-            param.orderNo = orderNo;
-
-            // 鍒涘缓鍛戒护鏃ュ織瀵硅薄骞舵坊鍔犲埌鏁版嵁搴撲腑
-            RmCommandHistory rmCommandHistory = getComHistory(commandCode, rtuAddr, param, operator);
-            comId = commandSv.insert(rmCommandHistory);
-
-            // 鏋勯�犲苟鍙戦�佸懡浠�
-            Command com = command(comId, commandCode, rtuAddr, param);
-            sendCom2Mw(com);
+            return BaseResponseUtils.buildFail("绯荤粺鏆備笉鏀寔璇ュ崗璁�");
         }
-
-        // 澶勭悊鍥炶皟
-        BaseResponse response = dealWithCallBack(comId);
-        if(!response.getCode().equals("0001")) {
-            return BaseResponseUtils.buildError(RemoteResultCode.GET_RESULT_ERROR.getMessage());
-        }
-
-        // 鏇存敼铏氭嫙鍗$姸鎬侊細鏄惁浣跨敤涓�佹渶鍚庢搷浣溿�佹渶鍚庢搷浣滄椂闂�
-        Long vcId = seVirtualCardMapper.getVcIdByNum(vcNum);
-        SeVirtualCard virtualCard = new SeVirtualCard();
-        virtualCard.setId(vcId);
-        virtualCard.setInUse((byte) 0);
-        virtualCard.setLastOperate(LastOperateENUM.CLOSE_VALVE.getCode());
-        virtualCard.setLastOperateTime(new Date());
-        seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
-
-        Data myData = (Data)response.getContent();
-        return BaseResponseUtils.buildSuccess(myData) ;
     }
 
     /**

--
Gitblit v1.8.0