From 02d965a2ff0cb5d415cedceacd2ae90c7ec1ac39 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期六, 10 五月 2025 09:03:50 +0800
Subject: [PATCH] 解决开关阀记录数据因重绑定或改RTU地址而引起的地址变更问题

---
 pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/common/ComCtrl.java |  189 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 189 insertions(+), 0 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/common/ComCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/common/ComCtrl.java
new file mode 100644
index 0000000..27657cc
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/common/ComCtrl.java
@@ -0,0 +1,189 @@
+package com.dy.pipIrrRemote.monitor.common;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.dy.common.mw.protocol.Command;
+import com.dy.common.util.IDLongGenerator;
+import com.dy.common.webUtil.BaseResponse;
+import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.pipIrrGlobal.command.ComResultWait;
+import com.dy.pipIrrGlobal.pojoPr.PrController;
+import com.dy.pipIrrGlobal.pojoRm.RmCommandHistory;
+import com.dy.pipIrrRemote.common.dto.DtoBase;
+import com.dy.pipIrrRemote.monitor.p202404V201.Cd50Param;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.env.Environment;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2025/5/9 14:53
+ * @Description
+ */
+public abstract class ComCtrl {
+
+    @Autowired
+    protected Environment env ;
+
+    @Autowired
+    protected RestTemplate restTemplate ;
+
+    @Value("${mw.waitMwRtnResultTimeout}")
+    protected int waitMwRtnResultTimeout ;
+
+    @Value("${mw.rtuCallbackUrl_rm}")
+    protected String rtuResultSendWebUrl;
+
+    //鎺у埗鍣ㄥ璞�
+    protected PrController ctrlPo ;
+    //寮傛绛夊緟鍣�
+    protected CompletableFuture<JSONObject> feature;
+    //鍛戒护鍚嶇О
+    protected String comName ;
+    //鍛戒护鏃ュ織id
+    protected Long comId ;
+
+    /**
+     * 鍙戦�佸懡浠ゅ墠-1锛氶獙璇�
+     * @param comSv
+     * @param comCode
+     * @param dto
+     * @param bindingResult
+     * @return
+     */
+    public BaseResponse<Object> pre1(ComSv comSv, String comCode, DtoBase dto, BindingResult bindingResult) {
+        if (bindingResult != null && bindingResult.hasErrors()) {
+            return BaseResponseUtils.buildError(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+        }
+        String msg = this.checkDto(dto) ;
+        if(msg != null){
+            return BaseResponseUtils.buildError("鏈嶅姟绔嚭閿欙紝" + msg) ;
+        }
+        return  null ;
+    }
+
+    /**
+     * 鍙戦�佸懡浠ゅ墠-2锛氳幏寰楁暟鎹�
+     * @param comSv
+     * @param comCode
+     * @param dto
+     * @param bindingResult
+     * @return
+     */
+    public BaseResponse<Object> pre2(ComSv comSv, String comCode, DtoBase dto, BindingResult bindingResult) {
+        //寰楀埌鎺у埗鍣ㄥ璞�
+        ctrlPo = comSv.getRtu(dto.getIntakeId());
+        if (ctrlPo == null) {
+            return BaseResponseUtils.buildError("鏈嶅姟绔嚭閿欙紝浠庢暟鎹簱涓湭寰楀埌鎺у埗鍣ㄦ暟鎹�") ;
+        }
+        //妫�鏌ュ崗璁�
+        String msg = comSv.checkProtocol(ctrlPo) ;
+        if(msg != null) {
+            return BaseResponseUtils.buildError("鏈嶅姟绔嚭閿欙紝" + msg) ;
+        }
+        //寰楀埌鍔熻兘鐮佸搴旂殑鍛戒护鍚嶇О
+        comName = comSv.getCommandName(comCode, ctrlPo) ;
+        if(comName == null) {
+            return BaseResponseUtils.buildError("鏈嶅姟绔嚭閿欙紝鏈緱鍒板姛鑳界爜瀵瑰簲鍛戒护鍚嶇О") ;
+        }
+        return  null ;
+    }
+    /**
+     * 鍙戦�佸懡浠ゅ墠-3锛氫繚瀛樺懡浠ゆ棩蹇�
+     * @param comSv sv瀵硅薄
+     * @param intakeId 鍙栨按鍙D
+     * @param operator 褰撳墠鐢ㄧ櫥褰曠敤鎴穒d(鎿嶄綔浜�)
+     * @param comCode 鍔熻兘鐮�
+     * @param param 鍛戒护鍙傛暟
+     * @return
+     */
+    public BaseResponse<Object> pre3(ComSv comSv, Long intakeId, Long operator, String comCode, CdParam param) {
+        comId = new IDLongGenerator().generate();
+        //鐢熸垚骞朵繚瀛樺懡浠ゆ棩蹇�
+        RmCommandHistory po = comSv.saveComHistoryPo(comId,
+                ctrlPo.getProtocol(),
+                comCode, comName,
+                intakeId,
+                ctrlPo.getRtuAddr(),
+                param,
+                operator);
+        if(po == null){
+            return BaseResponseUtils.buildError("鏈嶅姟绔嚭閿欙紝鏈兘鐢熸垚骞朵繚瀛樺懡浠ゆ棩蹇�") ;
+        }
+        return  null ;
+    }
+    /**
+     * 鍙戦�佸懡浠ゅ墠-4锛氬噯澶嘑eature
+     * @return
+     */
+    public void pre4() {
+        feature = new CompletableFuture<>();
+        ComResultWait.put(comId, feature);
+    }
+
+    /**
+     * 鍙戦�佸懡浠�
+     * @param comSv
+     * @param com
+     * @return
+     */
+    public BaseResponse<Object> doSend(ComSv comSv, Command com){
+        //寰楀埌閫氫俊涓棿浠跺彂閫佸懡浠ょ殑web URL
+        String rqUrl = comSv.get2MwRequestUrl(env, comSv.ContextComSend) ;
+        //鍚戦�氫俊涓棿浠跺彂閫亀eb璇锋眰
+        BaseResponse res = comSv.sendPostRequest2Mw(restTemplate, rqUrl, com) ;
+        //澶勭悊閫氫俊涓棿浠跺web璇锋眰鐨勫搷搴�
+        String msg = comSv.dealMwDealResponse(res) ;
+        if(msg != null) {
+            return BaseResponseUtils.buildError(msg) ;
+        }else{
+            return null ;
+        }
+    }
+
+    /**
+     * 鍙戦�佸懡浠ゅ悗
+     * @return
+     */
+    public BaseResponse<Object> after(String comCode) {
+        try{
+            //绛夊緟閫氫俊涓棿浠堕�氱煡鎺у埗鍣ㄦ墽琛屽懡浠や笂琛屾暟鎹紙鍛戒护缁撴灉锛�
+            JSONObject resultData = feature.get(waitMwRtnResultTimeout, TimeUnit.SECONDS);
+            return BaseResponseUtils.buildSuccess(this.createRtnMsg(comCode, resultData));
+        }catch (Exception e){
+            return BaseResponseUtils.buildFail("绛夊緟閫氫俊涓棿浠堕�氱煡鍛戒护缁撴灉瓒呮椂");
+        }
+    }
+
+    /**
+     * 鍙戦�佸懡浠ゆ渶鍚�
+     * @return
+     */
+    public void end(){
+        try {
+            //鏈�鍚庢竻闄ompletableFuture缂撳瓨
+            if(ComResultWait.contain(comId)){
+                ComResultWait.remove(comId);
+            }
+        }catch (Exception ee){}
+    }
+
+    /**
+     * 楠岃瘉
+     * @param dto
+     * @return
+     */
+    protected abstract String checkDto(DtoBase dto) ;
+
+
+    /**
+     * 鐢熸垚鍛戒护杩斿洖淇℃伅
+     */
+    protected abstract String createRtnMsg(String code, JSONObject resultData);
+}

--
Gitblit v1.8.0