From a7441d24458b8b6ab34928743478c831fb348c06 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期二, 02 十二月 2025 15:16:09 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/ServerBootstrap.java |  117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 111 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/zy/core/ServerBootstrap.java b/src/main/java/com/zy/core/ServerBootstrap.java
index b532458..9cf6d99 100644
--- a/src/main/java/com/zy/core/ServerBootstrap.java
+++ b/src/main/java/com/zy/core/ServerBootstrap.java
@@ -1,13 +1,25 @@
 package com.zy.core;
 
-import com.alibaba.fastjson.JSON;
-import com.zy.core.properties.SlaveProperties;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.core.exception.CoolException;
+import com.zy.asrs.entity.DeviceConfig;
+import com.zy.asrs.service.DeviceConfigService;
+import com.zy.common.utils.RedisUtil;
+import com.zy.core.cache.MessageQueue;
+import com.zy.core.cache.SlaveConnection;
+import com.zy.core.enums.SlaveType;
+import com.zy.core.thread.impl.ZySiemensCrnThread;
+import com.zy.core.thread.impl.ZyStationThread;
+import com.zy.core.thread.impl.ZyRgvThread;
+
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
+import java.util.List;
 
 /**
  * Created by vincent on 2020/8/4
@@ -17,15 +29,108 @@
 public class ServerBootstrap {
 
     @Autowired
-    private SlaveProperties slaveProperties;
-
+    private MainProcess mainProcess;
+    @Autowired
+    private RedisUtil redisUtil;
+    @Autowired
+    private DeviceConfigService deviceConfigService;
 
     @PostConstruct
-    public void init(){
-        System.out.println(JSON.toJSONString(slaveProperties));
+    @Async
+    public void init() throws InterruptedException {
+        News.info("鏍稿績鎺у埗灞傚紑濮嬪垵濮嬪寲...............................................");
+        Thread.sleep(2000);
+        // 鍒濆鍖栨秷鎭槦鍒�
+        initMq();
+        // 鍒濆鍖栦笅浣嶆満绾跨▼
+        initThread();
+        // 寮�濮嬩富娴佺▼杩涚▼
+        mainProcess.start();
+        News.info("鏍稿績鎺у埗灞傚凡鍚姩...............................................");
+    }
+
+    private void initMq(){
+        // 鍒濆鍖栧爢鍨涙満mq
+        List<DeviceConfig> crnList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Crn)));
+        for (DeviceConfig crn : crnList) {
+            MessageQueue.init(SlaveType.Crn, crn.getDeviceNo());
+        }
+        // 鍒濆鍖朢gv灏忚溅mq
+        List<DeviceConfig> rgvList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Rgv)));
+        for (DeviceConfig rgv : rgvList) {
+            MessageQueue.init(SlaveType.Rgv, rgv.getDeviceNo());
+        }
+        // 鍒濆鍖栬緭閫佺嚎mq
+        List<DeviceConfig> devpList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Devp)));
+        for (DeviceConfig devp : devpList) {
+            MessageQueue.init(SlaveType.Devp, devp.getDeviceNo());
+        }
+        // 鍒濆鍖栨潯鐮佹壂鎻忎华mq
+        List<DeviceConfig> barcodeList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Barcode)));
+        for (DeviceConfig barcode : barcodeList) {
+            MessageQueue.init(SlaveType.Barcode, barcode.getDeviceNo());
+        }
+        // 鍒濆鍖朙ed鐏痬q
+        List<DeviceConfig> ledList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Led)));
+        for (DeviceConfig led : ledList) {
+            MessageQueue.init(SlaveType.Led, led.getDeviceNo());
+        }
+    }
+
+    private void initThread(){
+        News.info("鍒濆鍖栧爢鍨涙満........................................................");
+        List<DeviceConfig> crnList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Crn)));
+        for (DeviceConfig deviceConfig : crnList) {
+            ThreadHandler thread = null;
+            if (deviceConfig.getThreadImpl().equals("ZySiemensCrnThread")) {
+                thread = new ZySiemensCrnThread(deviceConfig, redisUtil);
+            } else {
+                throw new CoolException("鏈煡鐨勭嚎绋嬪疄鐜�");
+            }
+
+            new Thread(thread).start();
+            SlaveConnection.put(SlaveType.Crn, deviceConfig.getDeviceNo(), thread);
+        }
+
+        News.info("鍒濆鍖栬緭閫佺珯........................................................");
+        List<DeviceConfig> devpList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Devp)));
+        for (DeviceConfig deviceConfig : devpList) {
+            ThreadHandler thread = null;
+            if (deviceConfig.getThreadImpl().equals("ZyStationThread")) {
+                thread = new ZyStationThread(deviceConfig, redisUtil);
+            } else {
+                throw new CoolException("鏈煡鐨勭嚎绋嬪疄鐜�");
+            }
+
+            new Thread(thread).start();
+            SlaveConnection.put(SlaveType.Devp, deviceConfig.getDeviceNo(), thread);
+        }
+
+        News.info("鍒濆鍖朢GV........................................................");
+        List<DeviceConfig> rgvList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Rgv)));
+        for (DeviceConfig deviceConfig : rgvList) {
+            ThreadHandler thread = null;
+            if (deviceConfig.getThreadImpl().equals("ZyRgvThread")) {
+                thread = new ZyRgvThread(deviceConfig, redisUtil);
+            } else {
+                throw new CoolException("鏈煡鐨勭嚎绋嬪疄鐜�");
+            }
+
+            new Thread(thread).start();
+            SlaveConnection.put(SlaveType.Rgv, deviceConfig.getDeviceNo(), thread);
+        }
 
     }
 
+
     @PreDestroy
     public void destroy() {
     }

--
Gitblit v1.9.1