From f16e0460ed079626e7a9a936f91714001e02f130 Mon Sep 17 00:00:00 2001
From: wuyouming666 <2265557248@qq.com>
Date: 星期三, 08 五月 2024 08:27:42 +0800
Subject: [PATCH] 测试代码

---
 hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/common/Plcdownglass.java |   94 +++++++++++++++++++++--------------------------
 1 files changed, 42 insertions(+), 52 deletions(-)

diff --git a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/common/Plcdownglass.java b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/common/Plcdownglass.java
index 56b0c56..9b1b935 100644
--- a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/common/Plcdownglass.java
+++ b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/common/Plcdownglass.java
@@ -2,24 +2,21 @@
 
 import cn.hutool.json.JSONObject;
 
-import com.mes.device.PlcParameterObject;
-import com.mes.downglassinfo.entity.DownGlassTask;
-import com.mes.downglassinfo.service.DownGlassTaskService;
-import com.mes.downstorage.entity.DownStorageCageDetails;
-import com.mes.downstorage.mapper.DownStorageCageDetailsMapper;
 import com.mes.downstorage.service.DownStorageCageService;
 import com.mes.downworkstation.service.DownWorkstationService;
-import com.mes.glassinfo.entity.GlassInfo;
-import com.mes.glassinfo.service.GlassInfoService;
+
+
 import com.mes.tools.WebSocketServer;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
 
 import java.util.List;
-import java.util.function.Supplier;
 
+@Component
 @Slf4j
-public class Plcdownglass extends Thread {
+public class Plcdownglass {
 
     public static final String RESULT_IN = "1";
     public static final String RESULT_OUT = "2";
@@ -28,54 +25,47 @@
     @Autowired
     private DownStorageCageService downStorageCageService;
     @Autowired
-  private DownWorkstationService downWorkstationService;
-
-//     private final Supplier<DownWorkstationService> plcServiceSupplier;
-//
-//    public Plcdownglass() {
-//        this.plcServiceSupplier = () -> WebSocketServer.applicationContext.getBean(DownWorkstationService.class);
-//    }
+    private DownWorkstationService downWorkstationService;
 
 
+   @Scheduled(fixedDelay = 300)
+    public void PlcdownglassTask() throws InterruptedException {
+        JSONObject jsonObject = new JSONObject();
+        try {
+            Thread.sleep(300);
 
-    @Override
-    public void run() {
-        while (this != null) {
-            JSONObject jsonObject = new JSONObject();
-            try {
-                Thread.sleep(100);
-                downWorkstationService = WebSocketServer.applicationContext.getBean(DownWorkstationService.class);
-                downStorageCageService = WebSocketServer.applicationContext.getBean(DownStorageCageService.class);
-                //                String result = S7control.getinstance().ReadWord("DB14.0", 1).get(0) + "";
+
+            //                String result = S7control.getinstance().ReadWord("DB14.0", 1).get(0) + "";
 //                String number = S7control.getinstance().ReadWord("DB14.2", 1).get(0) + "";
-                String result ="1";
-                String number ="1";
-                // 杩涚墖璇锋眰
-                if (RESULT_IN.equals(result)) {
-                    downStorageCageService.processInto(number);
-                }
-                // 鍑虹墖璇锋眰
-                else if (RESULT_OUT.equals(result)) {
-                    downStorageCageService.processOut();
-                }
-                // 杩涘嚭鐗囪姹�
-                else if (RESULT_IN_OUT.equals(result)) {
-                    // 鍏堝嚭鍚庤繘
-                    if (!downStorageCageService.processOut()) {
-                        downStorageCageService.processInto(number);
-                    }
-                }
-
-
-                downWorkstationService.insertdownglassinfo();
-
-
-
-
-            } catch (Exception e) {
-                e.printStackTrace();
+            String result = "3";
+            String number = "4";
+            // 杩涚墖璇锋眰
+            if (RESULT_IN.equals(result)) {
+                downStorageCageService.processInto(number);
             }
-        }
+            // 鍑虹墖璇锋眰
+            else if (RESULT_OUT.equals(result)) {
+                downStorageCageService.processOut();
+            }
+            // 杩涘嚭鐗囪姹�
+            else if (RESULT_IN_OUT.equals(result)) {
+                // 鍏堝嚭鍚庤繘
+                if (downStorageCageService.processOut()) {
+                    //涓嬬墖鏇存柊
+                    downWorkstationService.insertdownglassinfo();
+                    // 鎵ц杩涚墖鎿嶄綔
+                    downStorageCageService.processInto(number);
+                } else {
+                    // 濡傛灉 processOut() 杩斿洖 false锛屽彲浠ュ湪杩欓噷澶勭悊鍏朵粬閫昏緫
+                    log.info("鍑虹墖璇锋眰澶辫触锛屾棤娉曟墽琛岃繘鐗囨搷浣�");
+                }
 
+            }
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
+
 }
\ No newline at end of file

--
Gitblit v1.8.0