From ea58523b67ad59002a1191c3c564258c5b81f6f2 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期二, 06 五月 2025 17:35:16 +0800
Subject: [PATCH] Revert "1、实现万用token(0000-0000-1234-9876-5); 2、web端单独实现命令结果等待器,并修改相关部分; 3、web端实现透传命令; 4、修改一些不当注释; 5、优化一些代码。"

---
 pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/ComTransCtrl.java |  135 --------------------------------------------
 1 files changed, 2 insertions(+), 133 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/ComTransCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/ComTransCtrl.java
index 2c87d06..a1e4b11 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/ComTransCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/ComTransCtrl.java
@@ -1,32 +1,10 @@
 package com.dy.pipIrrRemote.monitor;
 
-import com.alibaba.fastjson2.JSONObject;
-import com.dy.common.aop.SsoAop;
-import com.dy.common.mw.protocol.Command;
-import com.dy.common.util.IDLongGenerator;
-import com.dy.common.util.NumUtil;
-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 io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.validation.Valid;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-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.validation.BindingResult;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.client.RestTemplate;
-
-import java.util.Objects;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.TimeUnit;
 
 /**
  * @Author: liurunyu
@@ -37,120 +15,11 @@
 @Slf4j
 @Tag(name = "杩滅▼閫忎紶鍛戒护", description = "杩滅▼閫忎紶鍛戒护")
 @RestController
-@RequestMapping(path = "comTrans")
+@RequestMapping(path = "command")
 @RequiredArgsConstructor
 public class ComTransCtrl {
 
-    @Autowired
-    private Environment env ;
+    private final ComTransSv comSv;
 
-    @Autowired
-    private RestTemplate restTemplate ;
-
-    @Value("${mw.waitMwRtnResultTimeout}")
-    private int waitMwRtnResultTimeout ;
-
-    @Value("${mw.rtuCallbackUrl_rm}")
-    private String rtuResultSendWebUrl;
-
-    @Autowired
-    private ComTransSv comSv;
-
-    /**
-     * 鍚戣澶囷紙鎺у埗鍣級鍙戦�侀�忎紶鍛戒护
-     * @param dto 鍓嶇鍙戞潵鐨勫�煎璞�
-     * @param bindingResult 瀵筪to楠岃瘉鐨勭粨鏋�
-     * @return 杩斿洖鍓嶇
-     */
-    @PostMapping(path = "send", consumes = MediaType.APPLICATION_JSON_VALUE)
-    @SsoAop()
-    public BaseResponse<Object> send(@RequestBody @Valid ComTransDto 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) ;
-        }
-        //寰楀埌鎺у埗鍣ㄥ璞�
-        PrController ctrlPo = comSv.getRtu(dto.getIntakeId());
-        if (ctrlPo == null) {
-            return BaseResponseUtils.buildError("浠庢暟鎹簱涓湭寰楀埌鎺у埗鍣ㄦ暟鎹�") ;
-        }
-        //妫�鏌ュ崗璁�
-        msg = comSv.checkProtocol(ctrlPo) ;
-        if(msg != null) {
-            return BaseResponseUtils.buildError(msg) ;
-        }
-        //寰楀埌鍔熻兘鐮佸搴旂殑鍛戒护鍚嶇О
-        String comName = comSv.getCommandName(dto.comCode, ctrlPo) ;
-        if(comName == null) {
-            return BaseResponseUtils.buildError("鏈緱鍒板姛鑳界爜瀵瑰簲鍛戒护鍚嶇О") ;
-        }
-        Long comId = new IDLongGenerator().generate();
-        String comData = dto.comData.toUpperCase() ;
-        //鐢熸垚骞朵繚瀛樺懡浠ゆ棩蹇�
-        comSv.saveComHistoryPo(comId, ctrlPo.getProtocol(), dto.comCode, "閫忎紶锛�" + comName + "锛�",
-                dto.getIntakeId(), ctrlPo.getRtuAddr(), new ComTransParam(dto.comCode, comData), dto.getOperator());
-        try{
-            CompletableFuture<JSONObject> feature = new CompletableFuture<>();
-            ComResultWait.put(comId, feature);
-            //鍒涘缓澶栭儴閫忎紶鍛戒护锛堝彂缁欐帶鍒跺櫒锛�
-            Command com = comSv.createOuterTransparentCommand("" + comId, dto.comCode);
-            com.rtuAddr = ctrlPo.getRtuAddr() ;
-            com.attachment = comData ;
-            com.rtuResultSendWebUrl = rtuResultSendWebUrl;
-            //寰楀埌閫氫俊涓棿浠跺彂閫佸懡浠ょ殑web URL
-            String rqUrl = comSv.get2MwRequestUrl(this.env, comSv.ContextComSend) ;
-            //鍚戦�氫俊涓棿浠跺彂閫亀eb璇锋眰
-            BaseResponse res = comSv.sendPostRequest2Mw(restTemplate, rqUrl, com) ;
-            //澶勭悊閫氫俊涓棿浠跺web璇锋眰鐨勫搷搴�
-            msg = comSv.dealMwDealResponse(res) ;
-            if(msg != null) {
-                return BaseResponseUtils.buildError(msg) ;
-            }else{
-                try{
-                    //绛夊緟閫氫俊涓棿浠堕�氱煡鎺у埗鍣ㄦ墽琛屽懡浠や笂琛屾暟鎹紙鍛戒护缁撴灉锛�
-                    JSONObject resultData = feature.get(waitMwRtnResultTimeout, TimeUnit.SECONDS);
-                    Long commandId = resultData.getLong("commandId");
-                    if (commandId.equals(comId)) {
-                        return BaseResponseUtils.buildSuccess(resultData);
-                    } else {
-                        return BaseResponseUtils.buildSuccess("鎺у埗鍣ㄦ墽琛屽懡浠ゆ垚鍔�");
-                    }
-                }catch (Exception e){
-                    return BaseResponseUtils.buildFail("绛夊緟閫氫俊涓棿浠堕�氱煡鍛戒护缁撴灉瓒呮椂鎴栧紓甯�");
-                }
-            }
-        }catch (Exception e){
-            return BaseResponseUtils.buildFail("鏈嶅姟绔瀯閫犲苟鍚戦�氫俊涓棿浠跺彂閫佽姹傛椂寮傚父" + (e.getMessage() == null?"":e.getMessage())) ;
-        }finally {
-            try {
-                //鏈�鍚庢竻闄ompletableFuture缂撳瓨
-                ComResultWait.remove(comId);
-            }catch (Exception ee){}
-        }
-    }
-
-    /**
-     * 楠岃瘉
-     * @param dto
-     * @return
-     */
-    private String checkDto(ComTransDto dto){
-        if(!NumUtil.isHex(dto.comCode)){
-            return "鍛戒护鍔熻兘鐮佷笉鏄崄鍏繘鍒舵暟";
-        }
-        if(!NumUtil.isHex(dto.comData)){
-            return "鍛戒护鏁版嵁涓嶆槸鍗佸叚杩涘埗鏁�";
-        }
-        if(dto.comData.length() % 2 != 0){
-            return "鍛戒护鏁版嵁涓嶅畬澶囷紙闀垮害涓嶆槸鍋舵暟锛�";
-        }
-        if(!dto.comData.contains(dto.comCode)){
-            return "鍛戒护鏁版嵁涓笉鍖呭惈鍔熻兘鐮�";
-        }
-        return null ;
-    }
 
 }

--
Gitblit v1.8.0