From 4bd0c2c252df008b98d3e9c7dac708ff642c90d1 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期三, 17 七月 2024 16:21:47 +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/ValveCtrl.java |   54 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 46 insertions(+), 8 deletions(-)

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 59f32ed..b3058bf 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
@@ -23,10 +23,11 @@
 import com.dy.pipIrrWechat.result.WechatResultCode;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import jakarta.validation.Valid;
-import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.RandomStringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.env.Environment;
 import org.springframework.http.MediaType;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.BindingResult;
@@ -47,7 +48,7 @@
 @Tag(name = "灏忕▼搴忛榾鎺у櫒鎺у埗", description = "灏忕▼搴忛榾鎺у櫒鎺у埗")
 @RestController
 @RequestMapping(path = "valve")
-@RequiredArgsConstructor
+//@RequiredArgsConstructor
 public class ValveCtrl extends ComSupport {
     private final CommandSv commandSv;
     private final SeVirtualCardMapper seVirtualCardMapper;
@@ -57,22 +58,53 @@
     private String rtuCallbackUrl_wx;
 
     /**
+     * pro_mw锛氬睘鎬�
+     * tag浠庢帶鍒跺櫒涓幏鍙�
+     * key_mw锛歶rl鐨刱ey
+     */
+    private Environment env = null;
+    private String pro_mw = "mw";
+    private String key_mw = "comSendUrl";
+
+    @Autowired
+    public ValveCtrl(CommandSv commandSv, SeVirtualCardMapper seVirtualCardMapper, IDLongGenerator idLongGenerator, Environment env) {
+        this.commandSv = commandSv;
+        this.seVirtualCardMapper = seVirtualCardMapper;
+        this.idLongGenerator = idLongGenerator;
+        this.env = env;
+    }
+
+    /**
      * 灏忕▼搴忚繙绋嬪紑闃�
      * @param valve
      * @param bindingResult
      * @return
      */
     @PostMapping(path = "open_wx", consumes = MediaType.APPLICATION_JSON_VALUE)
-    @Transactional(rollbackFor = Exception.class)
+    //@Transactional(rollbackFor = Exception.class)
     public BaseResponse<Boolean> open(@RequestBody @Valid ValveOpen valve, BindingResult bindingResult) {
         if (bindingResult != null && bindingResult.hasErrors()) {
             return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
         }
 
         Long intakeId = valve.getIntakeId();
+        String intakeName = valve.getIntakeName();
         Long vcId = valve.getVcId();
+        Boolean forceOpen = valve.getForceOpen();
         Long operator = valve.getOperator();
         Long comId = idLongGenerator.generate();
+
+        if(intakeId == null && intakeName == null) {
+            return BaseResponseUtils.buildErrorMsg(WechatResultCode.PLEASE_SELECT_A_INTAKE.getMessage());
+        }
+
+        // intakeName鎹ntakeId
+        if(intakeId == null) {
+            intakeId = commandSv.getIntakeIdByName(intakeName);
+            if(intakeId == null) {
+                return BaseResponseUtils.buildErrorMsg(WechatResultCode.PLEASE_SELECT_A_INTAKE.getMessage());
+            }
+        }
 
         /**
          * 濡傛灉鍐滄埛閫夋嫨浜嗚櫄鎷熷崱锛屽垯浣跨敤璇ヨ櫄鎷熷崱
@@ -96,8 +128,10 @@
         if (vc == null) {
             return BaseResponseUtils.buildErrorMsg(WechatResultCode.PLEASE_SELECT_A_VC.getMessage());
         }
-        if (vc.getInUse() == 1) {
-            return BaseResponseUtils.buildErrorMsg(WechatResultCode.IN_USE_VC_CANNOT_OPEN_VALVE.getMessage());
+
+        // 铏氭嫙鍗$姸鎬佷负浣跨敤涓紝涓斾笉鏄己鍒跺紑闃�鏃舵彁绀�
+        if (vc.getInUse() == 1 && !forceOpen) {
+            return BaseResponseUtils.buildCodeMsg(WechatResultCode.IN_USE_VC_CANNOT_OPEN_VALVE.getCode(), WechatResultCode.IN_USE_VC_CANNOT_OPEN_VALVE.getMessage());
         }
 
         // 鑾峰彇姘翠环
@@ -110,6 +144,8 @@
         }
         String rtuAddr = job_rtu.getString("rtuAddr");
         String protocol = job_rtu.getString("protocol");
+        String orgTag = job_rtu.getString("orgTag");
+        comSendUrl = env.getProperty(pro_mw + "." + orgTag + "." + key_mw);
 
         // 鐢熸垚璁㈠崟鍙�
         String orderNo = generateOrderNo();
@@ -123,7 +159,7 @@
             ComCd92_A2Vo param = new ComCd92_A2Vo();
             param.controllerType = controllerType;
             param.projectNo = projectNo;
-            param.icCardNo = vc.getVcNum();
+            param.icCardNo = vc.getVcNum().toString();
             param.waterRemain = 0.0;
             param.moneyRemain = vc.getMoney();
             param.waterPrice = waterPrice;
@@ -155,7 +191,7 @@
 
             // 鍒涘缓瑙嗗浘
             Com97Vo param = new Com97Vo();
-            param.icCardNo = vc.getVcNum();
+            param.icCardNo = vc.getVcNum().toString();
             param.moneyRemain = vc.getMoney();
             param.waterPrice = waterPrice;
             param.orderNo = orderNo;
@@ -191,7 +227,7 @@
      * @return
      */
     @PostMapping(path = "close_wx", consumes = MediaType.APPLICATION_JSON_VALUE)
-    @Transactional(rollbackFor = Exception.class)
+    //@Transactional(rollbackFor = Exception.class)
     public BaseResponse<Boolean> close(@RequestBody @Valid ValveClose valve, BindingResult bindingResult) {
         if (bindingResult != null && bindingResult.hasErrors()) {
             return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
@@ -216,6 +252,8 @@
         }
         Long intakeId = job_rtu.getLong("intakeId");
         String protocol = job_rtu.getString("protocol");
+        String orgTag = job_rtu.getString("orgTag");
+        comSendUrl = env.getProperty(pro_mw + "." + orgTag + "." + key_mw);
 
         String commandCode = null;
         if (protocol.equals("p206V202404")) {

--
Gitblit v1.8.0