From a017829dfbcd09d395256d9714a34c3317c1b12d Mon Sep 17 00:00:00 2001
From: ZY <zc>
Date: 星期四, 25 七月 2024 13:43:27 +0800
Subject: [PATCH] 本地代码提交

---
 src/main/java/com/zy/common/model/LocTypeDto.java       |   15 +++++--
 src/main/java/com/zy/core/thread/SpringContextUtil.java |   41 ++++++++++++++++++++
 src/main/java/com/zy/core/thread/SiemensDevpThread.java |    4 +-
 src/main/java/com/zy/core/ServerBootstrap.java          |    3 +
 4 files changed, 56 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/zy/common/model/LocTypeDto.java b/src/main/java/com/zy/common/model/LocTypeDto.java
index 38fb7d2..4ca1df1 100644
--- a/src/main/java/com/zy/common/model/LocTypeDto.java
+++ b/src/main/java/com/zy/common/model/LocTypeDto.java
@@ -31,14 +31,19 @@
     }
 
     public LocTypeDto(StaProtocol staProtocol) {
+        if (staProtocol.isLow()) {
+            this.locType1 = 1; // 浣庡簱浣�
+        }else {
+            this.locType1 = 2; // 楂樺簱浣�
+        }
 //        if (staProtocol.isHigh() == staProtocol.isLow()) {
 //            throw new CoolException("plc楂樹綆妫�娴嬪紓甯�");
 //        }
-        if (staProtocol.getSiteId() == 106 || staProtocol.getSiteId() == 159){
-            this.locType1 = 2; // 楂樺簱浣�
-        }else {
-            this.locType1 = 1; // 浣庡簱浣�
-        }
+//        if (staProtocol.getSiteId() == 106 || staProtocol.getSiteId() == 159){
+//            this.locType1 = 2; // 楂樺簱浣�
+//        }else {
+//            this.locType1 = 1; // 浣庡簱浣�
+//        }
     }
 
     /**
diff --git a/src/main/java/com/zy/core/ServerBootstrap.java b/src/main/java/com/zy/core/ServerBootstrap.java
index c7c8a21..d9f526d 100644
--- a/src/main/java/com/zy/core/ServerBootstrap.java
+++ b/src/main/java/com/zy/core/ServerBootstrap.java
@@ -12,6 +12,7 @@
 import com.zy.core.thread.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.DependsOn;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
@@ -26,6 +27,7 @@
  */
 @Slf4j
 @Component
+@DependsOn("springContextUtil")
 public class ServerBootstrap {
 
     @Autowired
@@ -41,6 +43,7 @@
      */
     @PostConstruct
     @Async
+    @DependsOn("basDevpService")
     public void init() throws InterruptedException {
         News.info("鏍稿績鎺у埗灞傚紑濮嬪垵濮嬪寲...............................................");
         Thread.sleep(2000);
diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index 288fb99..c06e37d 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -329,8 +329,8 @@
                     StaProtocol staProtocol = station.get(siteId);
                     basDevps.add(staProtocol.toSqlModel());
                 }
-
-                BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
+                BasDevpService basDevpService = SpringContextUtil.getBean(BasDevpService.class);
+                //BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
                 if (null != basDevpService && !basDevpService.updateBatchById(basDevps)) {
                     throw new Exception("鏇存柊鏁版嵁搴撴暟鎹け璐�");
                 }
diff --git a/src/main/java/com/zy/core/thread/SpringContextUtil.java b/src/main/java/com/zy/core/thread/SpringContextUtil.java
new file mode 100644
index 0000000..45974ee
--- /dev/null
+++ b/src/main/java/com/zy/core/thread/SpringContextUtil.java
@@ -0,0 +1,41 @@
+package com.zy.core.thread;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SpringContextUtil implements ApplicationContextAware {
+    private static final Logger logger = LoggerFactory.getLogger(SpringContextUtil.class);
+    private static ApplicationContext applicationContext;
+
+    public SpringContextUtil() {
+    }
+
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        if (SpringContextUtil.applicationContext == null) {
+            SpringContextUtil.applicationContext = applicationContext;
+        }
+
+        System.out.println("========ApplicationContext閰嶇疆鎴愬姛,鍦ㄦ櫘閫氱被鍙互閫氳繃璋冪敤SpringUtils.getAppContext()鑾峰彇applicationContext瀵硅薄,applicationContext=" + SpringContextUtil.applicationContext + "========");
+    }
+
+    public static ApplicationContext getApplicationContext() {
+        return applicationContext;
+    }
+
+    public static Object getBean(String name) {
+        return getApplicationContext().getBean(name);
+    }
+
+    public static <T> T getBean(Class<T> clazz) {
+        return getApplicationContext().getBean(clazz);
+    }
+
+    public static <T> T getBean(String name, Class<T> clazz) {
+        return getApplicationContext().getBean(name, clazz);
+    }
+}

--
Gitblit v1.9.1