From 1a2b07f01ba4616fd9e894dddf474b56d020158c Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期一, 07 四月 2025 15:18:51 +0800
Subject: [PATCH] 整理版本

---
 pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtu/RtuLogCtrl.java |  140 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 140 insertions(+), 0 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtu/RtuLogCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtu/RtuLogCtrl.java
new file mode 100644
index 0000000..84a72ae
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtu/RtuLogCtrl.java
@@ -0,0 +1,140 @@
+package com.dy.pipIrrRemote.rtu;
+
+import com.dy.common.aop.SsoAop;
+import com.dy.common.webUtil.BaseResponse;
+import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.pipIrrGlobal.rtuMw.Web2RtuMw;
+import jakarta.servlet.ServletOutputStream;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.util.UriComponentsBuilder;
+
+import java.net.URLEncoder;
+import java.util.List;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2024/8/29 9:22
+ * @Description
+ */
+
+@Slf4j
+@RestController
+@RequestMapping(path="rtuLog")
+public class RtuLogCtrl extends Web2RtuMw {
+
+    private Environment env ;
+    private RestTemplate restTemplate;
+
+    @Autowired
+    public RtuLogCtrl(Environment env, RestTemplate restTemplate) {
+        this.env = env;
+        this.restTemplate = restTemplate;
+    }
+
+    /**
+     * 鍙戦�佸懡浠わ紝璇锋眰涓嬭浇rtu涓婁笅琛屾暟鎹棩蹇楁枃浠�
+     * @param rtuAddr rtu鍦板潃
+     * @return
+     */
+    @GetMapping(path = "file")
+    @SsoAop()
+    public BaseResponse<List<String>> rtuLogFile(String rtuAddr, HttpServletRequest req, HttpServletResponse rep){
+        String rqUrl = this.get2MwRequestUrl(this.env, ContextRtuLogFile) ;
+        ServletOutputStream out = null ;
+        try{
+            byte[] bs = this.requestMw4File(rtuAddr, rqUrl) ;
+            if(bs != null && bs.length > 0){
+                String fileReName = rtuAddr + ".log" ;
+                //URLEncoder.encode鍙互闃叉涓枃涔辩爜
+                fileReName = URLEncoder.encode(fileReName, "UTF-8").replaceAll("\\+", "%20");
+                rep.addHeader("content-type", "application/octet-stream;charset=UTF-8");
+                rep.addHeader("Content-Disposition", "attachment;fileName=" + fileReName);
+                out = rep.getOutputStream() ;
+                out.write(bs, 0, (bs==null?0:bs.length));
+                out.flush();
+            }else{
+                return BaseResponseUtils.buildError("鑾峰彇鏂囦欢澶辫触") ;
+            }
+        }catch (Exception e){
+        }finally {
+            if(out != null){
+                try{
+                    out.close();
+                }catch(Exception e){
+                }
+            }
+        }
+        return null ;
+    }
+
+    /**
+     * 鍙戦�佸懡浠わ紝璇锋眰rtu涓婁笅琛屾暟鎹棩蹇楁枃浠跺唴瀹�
+     * @param rtuAddr rtu鍦板潃
+     * @return
+     */
+    @GetMapping(path="text")
+    @SsoAop()
+    public BaseResponse<List<String>> rtuLogText(String rtuAddr){
+        String rqUrl = this.get2MwRequestUrl(this.env, ContextRtuLogText) ;
+        //String mwUrlRtuLogText = env.getProperty(pro_mw + "." + DataSourceContext.get() + "." + key_mw_text);
+        BaseResponse<List<String>> text = this.requestMw4Text(rtuAddr, rqUrl);
+        if (text != null){
+            if (text.getContent().get(0).contains("鎺у埗鍣�")){
+                return BaseResponseUtils.buildErrorMsg(""+text.getContent().get(0)+"") ;
+            }
+            return text ;
+        }else {
+            return BaseResponseUtils.buildErrorMsg("鑾峰彇鏃ュ織鏂囦欢涓簄ull") ;
+        }
+    }
+
+
+    /**
+     * 鍙戦�佸懡浠わ紝璇锋眰涓嬭浇rtu涓婁笅琛屾暟鎹棩蹇楁枃浠�
+     * @param rtuAddr rtu鍦板潃
+     * @param mwUrl mw鏈嶅姟鍣ㄥ湴鍧�
+     * @return
+     */
+    private byte[] requestMw4File(String rtuAddr, String mwUrl) throws Exception{
+        String url = UriComponentsBuilder.fromUriString(mwUrl)
+                .build()
+                .toUriString();
+        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url)
+                .queryParam("rtuAddr", rtuAddr);
+        return restTemplate.getForObject(builder.toUriString(), byte[].class);
+    }
+
+    /**
+     * 鍙戦�佸懡浠わ紝璇锋眰rtu涓婁笅琛屾暟鎹棩蹇楁枃浠跺唴瀹�
+     * @param rtuAddr rtu鍦板潃
+     * @param mwUrl mw鏈嶅姟鍣ㄥ湴鍧�
+     * @return
+     */
+    private BaseResponse<List<String>> requestMw4Text(String rtuAddr, String mwUrl){
+        String url = UriComponentsBuilder.fromUriString(mwUrl)
+                .build()
+                .toUriString();
+
+        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url)
+                .queryParam("rtuAddr", rtuAddr);
+
+        ResponseEntity<BaseResponse> response = restTemplate.exchange(builder.toUriString(),
+                HttpMethod.GET,
+                new HttpEntity<>(new HttpHeaders()),
+                BaseResponse.class);
+
+        return (response==null?null:response.getBody());
+    }
+}

--
Gitblit v1.8.0