From 7d6921a3cd3c6bcf04bf5503fa78275d09aa26f9 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期一, 01 十二月 2025 16:25:09 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/ServerBootstrap.java | 150 ++++++++++++++++++++++++++-----------------------
1 files changed, 80 insertions(+), 70 deletions(-)
diff --git a/src/main/java/com/zy/core/ServerBootstrap.java b/src/main/java/com/zy/core/ServerBootstrap.java
index 5097e9b..9cf6d99 100644
--- a/src/main/java/com/zy/core/ServerBootstrap.java
+++ b/src/main/java/com/zy/core/ServerBootstrap.java
@@ -1,14 +1,17 @@
package com.zy.core;
+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.model.CrnSlave;
-import com.zy.core.model.DevpSlave;
-import com.zy.core.model.LedSlave;
-import com.zy.core.model.SteSlave;
-import com.zy.core.properties.SlaveProperties;
-import com.zy.core.thread.*;
+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;
@@ -16,6 +19,7 @@
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
+import java.util.List;
/**
* Created by vincent on 2020/8/4
@@ -25,15 +29,16 @@
public class ServerBootstrap {
@Autowired
- private SlaveProperties slaveProperties;
- @Autowired
private MainProcess mainProcess;
-
+ @Autowired
+ private RedisUtil redisUtil;
+ @Autowired
+ private DeviceConfigService deviceConfigService;
@PostConstruct
@Async
public void init() throws InterruptedException {
- log.info("鏍稿績鎺у埗灞傚紑濮嬪垵濮嬪寲...............................................");
+ News.info("鏍稿績鎺у埗灞傚紑濮嬪垵濮嬪寲...............................................");
Thread.sleep(2000);
// 鍒濆鍖栨秷鎭槦鍒�
initMq();
@@ -41,83 +46,88 @@
initThread();
// 寮�濮嬩富娴佺▼杩涚▼
mainProcess.start();
- log.info("鏍稿績鎺у埗灞傚凡鍚姩...............................................");
+ News.info("鏍稿績鎺у埗灞傚凡鍚姩...............................................");
}
private void initMq(){
// 鍒濆鍖栧爢鍨涙満mq
- for (Slave crn : slaveProperties.getCrn()) {
- MessageQueue.init(SlaveType.Crn, crn);
+ 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
- for (Slave devp : slaveProperties.getDevp()) {
- MessageQueue.init(SlaveType.Devp, devp);
+ 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
- for (Slave barcode : slaveProperties.getBarcode()) {
- MessageQueue.init(SlaveType.Barcode, barcode);
+ 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
- for (Slave led : slaveProperties.getLed()) {
- MessageQueue.init(SlaveType.Led, led);
- }
- // 鍒濆鍖栫绉癿q
- for (Slave scale : slaveProperties.getScale()) {
- MessageQueue.init(SlaveType.Scale, scale);
- }
- // 鍒濆鍖栧彴杞q
- for (Slave car : slaveProperties.getCar()) {
- MessageQueue.init(SlaveType.Car, car);
- }
- // 鍒濆鍖栫┛姊溅mq
- for (Slave ste : slaveProperties.getSte()) {
- MessageQueue.init(SlaveType.Ste, ste);
+ 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(){
- // 鍒濆鍖栧爢鍨涙満绾跨▼
- log.info("鍒濆鍖栧爢鍨涙満绾跨▼...................................................");
- for (CrnSlave crn : slaveProperties.getCrn()) {
- CrnThread crnThread = new SiemensCrnThread(crn);
- new Thread((Runnable) crnThread).start();
- SlaveConnection.put(SlaveType.Crn, crn.getId(), crnThread);
+ 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);
}
- // 鍒濆鍖栫┛姊溅绾跨▼
- log.info("鍒濆鍖栫┛姊溅绾跨▼...................................................");
- for (SteSlave crn : slaveProperties.getSte()) {
- SteThread steThread = new SteThread(crn);
- new Thread(steThread).start();
- SlaveConnection.put(SlaveType.Ste, crn.getId(), steThread);
+
+ 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);
}
- // 鍒濆鍖栬緭閫佺嚎绾跨▼
- log.info("鍒濆鍖栬緭閫佺嚎绾跨▼...................................................");
- for (DevpSlave devp : slaveProperties.getDevp()) {
- DevpThread devpThread = new SiemensDevpThread(devp);
- new Thread((Runnable) devpThread).start();
- SlaveConnection.put(SlaveType.Devp, devp.getId(), devpThread);
+
+ 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);
}
- // 鍒濆鍖栨潯鐮佹壂鎻忎华绾跨▼
- log.info("鍒濆鍖栨潯鐮佹壂鎻忎华绾跨▼...................................................");
- for (Slave barcode : slaveProperties.getBarcode()) {
- BarcodeThread barcodeThread = new BarcodeThread(barcode);
- new Thread(barcodeThread).start();
- SlaveConnection.put(SlaveType.Barcode, barcode.getId(), barcodeThread);
- }
- // 鍒濆鍖朙ED绾跨▼
- log.info("鍒濆鍖朙ED绾跨▼...................................................");
- for (LedSlave led : slaveProperties.getLed()) {
- LedThread ledThread = new LedThread(led);
- new Thread(ledThread).start();
- SlaveConnection.put(SlaveType.Led, led.getId(), ledThread);
- }
- // 鍒濆鍖栫绉ょ嚎绋�
-// log.info("鍒濆鍖栫绉ょ嚎绋�...................................................");
-// for (Slave scale : slaveProperties.getScale()) {
-// ScaleThread barcodeThread = new ScaleThread(scale);
-// new Thread(barcodeThread).start();
-// SlaveConnection.put(SlaveType.Scale, scale.getId(), barcodeThread);
-// }
+
}
--
Gitblit v1.9.1