From b2abd25927c39e849e592f1abdc08879d8d35245 Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期三, 07 五月 2025 09:48:39 +0800
Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV

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

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/msCenter/Register2MwMsCenterListener.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/msCenter/Register2MwMsCenterListener.java
new file mode 100644
index 0000000..c7fcc00
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/msCenter/Register2MwMsCenterListener.java
@@ -0,0 +1,97 @@
+package com.dy.pipIrrRemote.msCenter;
+
+import com.dy.pipIrrGlobal.rtuMw.Web2RtuMw;
+import com.dy.pipIrrGlobal.util.Org;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.event.ApplicationReadyEvent;
+import org.springframework.context.ApplicationListener;
+import org.springframework.core.env.Environment;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.lang.NonNull;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2025/2/13 9:47
+ * @Description
+ */
+@Slf4j
+@Component
+public class Register2MwMsCenterListener extends Web2RtuMw implements ApplicationListener<ApplicationReadyEvent> {
+    @Autowired
+    private Environment env;
+
+    @Autowired
+    private RestTemplate restTemplate;
+
+    @Autowired
+    protected ResourceLoader resourceLoader;
+
+    @Value("${mw.mwMsCenterReceiveUrl_rm}")
+    protected String mwMsCenterReceiveUrl;//娑堟伅鎺ユ敹缃戝潃
+
+    private static final String mwParamName = "msReceiverWebUrl" ;
+
+    private List<Org.OrgVo> orgs;
+
+    private Timer timer;
+
+    /**
+     * SpringBoot瀹瑰櫒宸茬粡鍑嗗濂戒簡锛屾墽琛屼笅闈㈡柟娉�
+     *
+     * @param event 浜嬩欢
+     */
+    @Override
+    public void onApplicationEvent(@NonNull ApplicationReadyEvent event) {
+        try {
+            //绛�1绉掞紝绛夊緟com.alibaba.druid.pool.DruidDataSource瀹炲鍖栧畬鎴�
+            Thread.sleep(1000L);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                this.start(event);
+            } catch (Exception e) {
+                log.error("鍚戦�氫俊涓棿浠舵敞鍐屾秷鎭帴鏀惰�呭嚭閿�", e);
+            }
+        }
+    }
+
+    /**
+     * 鎵ц涓氬姟閫昏緫
+     * @param event
+     * @throws Exception
+     */
+    private void start(ApplicationReadyEvent event) throws Exception {
+        if(mwMsCenterReceiveUrl == null || mwMsCenterReceiveUrl.trim().equals("")){
+            throw new Exception("閫氫俊涓棿浠舵秷鎭帴鏀剁綉鍧�鏈厤缃�");
+        }
+        orgs = super.get(resourceLoader);
+        if(orgs != null && orgs.size() > 0) {
+            this.timer = new Timer();
+            this.timer.schedule(new TimerTask() {
+                public void run() {
+                    register(event) ;
+                }
+            }, 100 , 5 * 60 * 1000);
+        }
+    }
+
+    /**
+     * 鍚戦�氫俊涓棿浠舵敞鍐屾秷鎭帴鏀惰��
+     * @param event
+     */
+    private void register(ApplicationReadyEvent event){
+        for (Org.OrgVo vo : this.orgs){
+            String rqUrl = this.get2MwRequestUrl(this.env, vo.tag, ContextRegisterMsReceiverWebUrl) ;
+            sendGetRequest2Mw(restTemplate, rqUrl, mwParamName, mwMsCenterReceiveUrl) ;
+        }
+    }
+}

--
Gitblit v1.8.0