From 9fa73c998ffe1ba6d0d79d3c1dbd5a911403c2cc Mon Sep 17 00:00:00 2001
From: zhangc <zc@123>
Date: 星期四, 10 四月 2025 22:43:28 +0800
Subject: [PATCH] 1

---
 src/main/java/com/zy/core/properties/SlaveProperties.java   |    5 
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |   90 +++++++++++++----
 src/main/java/com/zy/core/thread/impl/NormalLedThread.java  |   65 ++++++++++--
 src/main/java/com/zy/core/model/LedSlave.java               |   24 ++++
 src/main/java/com/zy/core/MainProcess.java                  |   12 +-
 src/main/resources/application.yml                          |   65 +++++++++++-
 src/main/java/com/zy/core/ServerBootstrap.java              |   15 +-
 7 files changed, 219 insertions(+), 57 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
index 162bc07..efe8350 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -91,24 +91,6 @@
     @Autowired
     private LiftAction liftAction;
 
-    //鍏ュ簱绔欑偣
-    public static final ArrayList<Integer> inSta = new ArrayList<Integer>() {{
-        add(1012);
-        add(1014);
-        add(1022);
-        add(1025);
-        add(1032);
-    }};
-
-    //鍑哄簱绔欑偣
-    public static final ArrayList<Integer> outSta = new ArrayList<Integer>() {{
-        add(1012);
-        add(1014);
-        add(1022);
-        add(1025);
-        add(1032);
-    }};
-
 
     private boolean isInEnable(DevpThread devpThread, Integer staNo) {
         if (staNo == null) {
@@ -180,7 +162,7 @@
      */
     public synchronized void generateInboundWrk() {
         try {
-            DevpSlave devpSlave = slaveProperties.getDevpSlave().get(0);
+            DevpSlave devpSlave = slaveProperties.getDevp().get(0);
             // 閬嶅巻鍏ュ簱鍙�
             for (DevpSlave.Sta inSta : devpSlave.getInSta()) {
                 // 鑾峰彇鍏ュ簱绔欎俊鎭�
@@ -232,7 +214,6 @@
                     }
                     continue;
                 }
-
                 // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢
                 if (staProtocol.isAutoing() && staProtocol.isLoading()
                         && isInEnable(devpThread, inSta.getStaNo())
@@ -243,7 +224,6 @@
                     if (!Cools.isEmpty(barcode)) {
                         News.info("鏉$爜鎵弿鍣ㄦ娴嬫潯鐮佷俊鎭細{}", barcode);
                     }
-
                     // 鍒ゆ柇閲嶅宸ヤ綔妗�
                     WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>()
                             .eq("source_sta_no", inSta.getStaNo())
@@ -336,6 +316,74 @@
 
 
     /**
+     * 鍑哄簱鍒板嚭搴撳彛
+     */
+    public synchronized void stnToOutStn() {
+        DevpSlave devpSlave = slaveProperties.getDevp().get(0);
+        // 閬嶅巻鍫嗗灈鏈哄嚭搴撶珯
+        for (DevpSlave.Sta outSta : devpSlave.getOutSta()) {
+            // 鑾峰彇鍫嗗灈鏈哄嚭搴撶珯淇℃伅
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devpSlave.getId());
+            StaProtocol staProtocol = devpThread.getStation().get(outSta.getStaNo());
+            if (staProtocol == null) {
+                continue;
+            } else {
+                staProtocol = staProtocol.clone();
+            }
+            if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
+                // 鏌ヨ宸ヤ綔妗�
+//                WrkMast wrkMast = wrkMastMapper.selectPakOutStep2(staProtocol.getSiteId());
+//                if (wrkMast == null) {
+//                    continue;
+//                }
+//                // 鍒ゆ柇宸ヤ綔妗f潯浠�
+//                if (wrkMast.getIoType() < 100 || wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null) {
+//
+//                }
+
+                //  鍒ゆ柇杈撻�佺嚎鍜屽皬杞︾姸鎬佺姸鎬佺瓑寰呯‘璁�
+//                if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(wrkMast.getWrkNo().shortValue())
+//                        && crnProtocol.statusType == CrnStatusType.WAITING
+//                        && crnProtocol.forkPosType == CrnForkPosType.HOME) {
+//                    log.info("鍫嗗灈鏈哄嚭搴撳畬鎴� - 寮�濮嬫墽琛�");
+//
+//                    // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
+//
+//                    // 涓嬪彂绔欑偣淇℃伅
+//                    staProtocol.setWorkNo(wrkMast.getWrkNo());
+//                    staProtocol.setStaNo(RouteUtils.CrnStaEnd(wrkMast.getStaNo(), wrkMast.getSourceStaNo()));
+//                    if (!MessageQueue.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol))) {
+//                        log.info(staProtocol.getWorkNo() + "," + staProtocol.getStaNo() + "杈撻�佺嚎鍑哄簱鍛戒护涓嬪彂澶辫触");
+//                        continue;
+//                    } else {
+//                        log.info(staProtocol.getWorkNo() + "," + staProtocol.getStaNo() + "杈撻�佺嚎鍑哄簱鍛戒护涓嬪彂鎴愬姛");
+//                    }
+//
+//                    // 鏇存柊宸ヤ綔妗g姸鎬佷负14澶辫触
+//                    wrkMast.setWrkSts(14L);
+//                    wrkMast.setCrnEndTime(new Date());
+//                    if (wrkMastMapper.updateById(wrkMast) != 0) {
+//                        // 澶嶄綅鍫嗗灈鏈�
+//                        log.error("鍑哄簱浠诲姟瀹屾垚涓嬪彂鍫嗗灈鏈哄浣�,{}", wrkMast.getWrkNo());
+//                        crnThread.setResetFlag(true);
+//                    } else {
+//                        News.error("" + mark + " - 1" + " - 鏇存柊宸ヤ綔妗g殑宸ヤ綔鐘舵�佷负14澶辫触锛侊紒锛� [宸ヤ綔鍙�:{}]", wrkMast.getWrkNo());
+//                    }
+//
+//                } else {
+//                    News.errorNoLog("" + mark + " - 6" + " - 鍫嗗灈鏈轰俊鎭笉绗﹀悎鍏ュ簱鏉′欢锛侊紒锛�"
+//                            + " 鍫嗗灈鏈虹姸鎬侊細" + crnProtocol.modeType + "==鑷姩AUTO锛�" + CrnModeType.AUTO
+//                            + "銆佸爢鍨涙満浠诲姟鍙凤細" + crnProtocol.getTaskNo() + "==宸ヤ綔妗d换鍔″彿锛�" + wrkMast.getWrkNo().shortValue()
+//                            + "銆佺姸鎬佹灇涓撅細" + crnProtocol.statusType + "==WAITING锛�90 //浠诲姟瀹屾垚绛夊緟WCS纭)锛�" + CrnStatusType.WAITING
+//                            + "銆佽揣鍙変綅缃細" + crnProtocol.forkPosType + "==HOME锛�0  // 璐у弶鍘熶綅锛�" + CrnForkPosType.HOME);
+//                }
+
+            }
+        }
+    }
+
+
+    /**
      * 鍒濆鍖栧疄鏃跺湴鍥�
      */
     public synchronized void initRealtimeBasMap() {
diff --git a/src/main/java/com/zy/core/MainProcess.java b/src/main/java/com/zy/core/MainProcess.java
index 2fb54ae..76f7997 100644
--- a/src/main/java/com/zy/core/MainProcess.java
+++ b/src/main/java/com/zy/core/MainProcess.java
@@ -28,7 +28,7 @@
     /**
      * =====>>  寮�濮嬪伐浣�
      */
-    public void start(){
+    public void start() {
         thread = new Thread(() -> {
             while (!Thread.currentThread().isInterrupted()) {
                 try {
@@ -42,10 +42,10 @@
                     }
                     //zhangc
                     //杈撻�佺嚎
-                    // 鍏ュ簱  ===>> 鍏ュ簱绔欏埌鍫嗗灈鏈虹珯锛屾牴鎹潯鐮佹壂鎻忕敓鎴愬叆搴撳伐浣滄。
-                    mainService.generateInboundWrk(); // 缁勬墭
-
-
+                    // 鍏ュ簱
+                    //mainService.generateInboundWrk();
+                    // 鍑哄簱
+                    //mainService.stnToOutStn();
 
                     //鍒濆鍖栧疄鏃跺湴鍥�
                     mainService.initRealtimeBasMap();
@@ -84,7 +84,7 @@
     }
 
     @PreDestroy
-    public void shutDown(){
+    public void shutDown() {
         if (thread != null) thread.interrupt();
     }
 
diff --git a/src/main/java/com/zy/core/ServerBootstrap.java b/src/main/java/com/zy/core/ServerBootstrap.java
index e93b49b..dcdccd7 100644
--- a/src/main/java/com/zy/core/ServerBootstrap.java
+++ b/src/main/java/com/zy/core/ServerBootstrap.java
@@ -5,10 +5,7 @@
 import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.SlaveConnection;
 import com.zy.core.enums.SlaveType;
-import com.zy.core.model.DevpSlave;
-import com.zy.core.model.ForkLiftSlave;
-import com.zy.core.model.LiftSlave;
-import com.zy.core.model.ShuttleSlave;
+import com.zy.core.model.*;
 import com.zy.core.properties.SlaveProperties;
 import com.zy.core.thread.impl.*;
 import lombok.extern.slf4j.Slf4j;
@@ -122,7 +119,7 @@
             SlaveConnection.put(SlaveType.Shuttle, shuttleSlave.getId(), thread);
         }
         // 鍒濆鍖栬緭閫佺嚎
-        for (DevpSlave devpSlave : slaveProperties.getDevpSlave()) {
+        for (DevpSlave devpSlave : slaveProperties.getDevp()) {
             News.info("鍒濆鍖栬緭閫佺嚎......................................................");
             ThreadHandler thread = null;
             if (devpSlave.getThreadImpl().equals("FyDevpThread")) {
@@ -136,17 +133,17 @@
         }
 
         // 鍒濆鍖栫數瑙嗘満
-        for (DevpSlave devpSlave : slaveProperties.getL()) {
+        for (LedSlave ledSlave : slaveProperties.getLed()) {
             News.info("鍒濆鍖栫數瑙嗘満......................................................");
             ThreadHandler thread = null;
-            if (devpSlave.getThreadImpl().equals("FyDevpThread")) {
-                thread = new FyDevpThread(devpSlave);
+            if (ledSlave.getThreadImpl().equals("NormalLedThread")) {
+                thread = new NormalLedThread(ledSlave);
             } else {
                 throw new CoolException("鏈煡鐨勭嚎绋嬪疄鐜�");
             }
 
             new Thread(thread).start();
-            SlaveConnection.put(SlaveType.Shuttle, devpSlave.getId(), thread);
+            SlaveConnection.put(SlaveType.Shuttle, ledSlave.getId(), thread);
         }
     }
 
diff --git a/src/main/java/com/zy/core/model/LedSlave.java b/src/main/java/com/zy/core/model/LedSlave.java
new file mode 100644
index 0000000..af02dfc
--- /dev/null
+++ b/src/main/java/com/zy/core/model/LedSlave.java
@@ -0,0 +1,24 @@
+package com.zy.core.model;
+
+import com.zy.core.Slave;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * LED閰嶇疆
+ * Created by vincent on 2020/8/6
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class LedSlave extends Slave {
+
+    // 杈撻�佺嚎plc缂栧彿
+    private Integer devpPlcId;
+
+    // 鍙夎溅绔欑偣鏁扮粍
+    private List<Integer> staArr = new ArrayList<>();
+
+}
diff --git a/src/main/java/com/zy/core/properties/SlaveProperties.java b/src/main/java/com/zy/core/properties/SlaveProperties.java
index ff4f254..1e295f1 100644
--- a/src/main/java/com/zy/core/properties/SlaveProperties.java
+++ b/src/main/java/com/zy/core/properties/SlaveProperties.java
@@ -1,6 +1,5 @@
 package com.zy.core.properties;
 
-import com.zy.core.Slave;
 import com.zy.core.model.*;
 import lombok.Data;
 import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -23,9 +22,9 @@
 
     private int groupCount;
 
-    private List<LedS> Led = new ArrayList<>();
+    private List<LedSlave> Led = new ArrayList<>();
 
-    private List<DevpSlave> devpSlave = new ArrayList<>();
+    private List<DevpSlave> devp = new ArrayList<>();
 
     private List<ShuttleSlave> shuttle = new ArrayList<>();
 
diff --git a/src/main/java/com/zy/core/thread/impl/NormalLedThread.java b/src/main/java/com/zy/core/thread/impl/NormalLedThread.java
index 50c4cd6..5a8635c 100644
--- a/src/main/java/com/zy/core/thread/impl/NormalLedThread.java
+++ b/src/main/java/com/zy/core/thread/impl/NormalLedThread.java
@@ -1,6 +1,11 @@
 package com.zy.core.thread.impl;
 
 import com.zy.common.model.MatDto;
+import com.zy.core.Slave;
+import com.zy.core.cache.MessageQueue;
+import com.zy.core.enums.SlaveType;
+import com.zy.core.model.LedSlave;
+import com.zy.core.model.Task;
 import com.zy.core.model.command.LedCommand;
 import com.zy.core.thread.LedThread;
 import lombok.extern.slf4j.Slf4j;
@@ -13,7 +18,9 @@
 @SuppressWarnings("all")
 public class NormalLedThread implements LedThread, Runnable {
 
+    private Slave slave;
     private Set<Integer> workNos = new HashSet<>();
+
     private boolean ledMk = false;
     private boolean resetStatus = false;    // 澶嶄綅鐘舵��
 
@@ -23,9 +30,43 @@
 
     private StringBuffer errorMsg = new StringBuffer();
 
+    public NormalLedThread(LedSlave ledSlave) {
+        this.slave = ledSlave;
+    }
+
 
     @Override
+    @SuppressWarnings({"InfiniteLoopStatement", "unchecked"})
     public void run() {
+//        connect();
+        while (true) {
+            try {
+                Task task = MessageQueue.poll(SlaveType.Led, slave.getId());
+                if (task != null) {
+                    switch (task.getStep()) {
+                        // 鍐欐暟鎹�
+                        case 1:
+                            write((List<LedCommand>) task.getData());
+                            break;
+                        // 澶嶄綅
+                        case 2:
+                            reset();
+                            break;
+                        case 3:
+                            error((String) task.getData());
+                            break;
+                        case 4:
+                            errorReset();
+                            break;
+                        default:
+                            break;
+                    }
+                }
+                Thread.sleep(1000);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
     }
 
     public void write(List<LedCommand> list) {
@@ -52,11 +93,13 @@
         errorReset();
     }
 
+
     public void reset() {
         commandList = null;
+
         stringBuffer.delete(0, stringBuffer.length());
-        errorMsg.delete(0, errorMsg.length());
     }
+
 
     public void error(String msg) {
         errorMsg.delete(0, errorMsg.length());
@@ -68,21 +111,21 @@
     }
 
     @Override
-    public boolean connect() {
-        return true;
-    }
-
-    @Override
-    public void close() {
-    }
-
-    @Override
     public void setLedMk(boolean mk) {
         this.ledMk = mk;
     }
 
     @Override
     public boolean isLedMk() {
-        return this.ledMk;
+        return false;
+    }
+
+    @Override
+    public boolean connect() {
+        return true;
+    }
+
+    @Override
+    public void close() {
     }
 }
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 3130db1..7014689 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -13,7 +13,7 @@
     driver-class-name: com.mysql.jdbc.Driver
     url: jdbc:mysql://127.0.0.1:3306/fyxc_shuttle?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
     username: root
-    password: zhangchao
+    password: root
   mvc:
     static-path-pattern: /**
   redis:
@@ -72,14 +72,65 @@
     standByBay: 1
     staRow: 2
     staBay: 1
-  devpSlave[0]:
-    id:
+  devp[0]:
+    id: 1
+    ip: 192.168.10.51
+    port: 102
+    rack: 0
+    slot: 0
+    # 鍏ュ簱鍙�1
     inSta[0]:
-      staNo:
-      backSta:
+      staNo: 1012
+      backSta: 1011
+      led: ${wcs-slave.led[0].id}
+    # 鍏ュ簱鍙�2
     inSta[1]:
-      staNo:
-      backSta:
+      staNo: 1014
+      backSta: 1013
+      led: ${wcs-slave.led[1].id}
+    # 鍏ュ簱鍙�3
+    inSta[2]:
+      staNo: 1022
+      backSta: 1021
+      led: ${wcs-slave.led[2].id}
+    # 鍏ュ簱鍙�4
+    inSta[3]:
+      staNo: 1025
+      backSta: 1024
+      led: ${wcs-slave.led[3].id}
+    # 鍑哄簱鍙�1
+    outSta[0]:
+      staNo: 1012
+    outSta[1]:
+      staNo: 1014
+    outSta[2]:
+      staNo: 1022
+    outSta[3]:
+      staNo: 1025
+  # LED1
+  led[0]:
+    id: 1
+    ip: 192.168.10.62
+    port: 5005
+    devpPlcId: ${wcs-slave.devp[0].id}
+  # LED2
+  led[1]:
+    id: 2
+    ip: 192.168.10.63
+    port: 5005
+    devpPlcId: ${wcs-slave.devp[0].id}
+  # LED3
+  led[2]:
+    id: 3
+    ip: 192.168.10.64
+    port: 5005
+    devpPlcId: ${wcs-slave.devp[0].id}
+  # LED4
+  led[3]:
+    id: 4
+    ip: 192.168.10.65
+    port: 5005
+    devpPlcId: ${wcs-slave.devp[0].id}
 
 
 

--
Gitblit v1.9.1