From aa151079c2d02047f6cb5f8ad56ff92b98544e99 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期三, 14 一月 2026 08:30:49 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/MainProcess.java | 75 +++++++++++++++++++++++++------------
1 files changed, 50 insertions(+), 25 deletions(-)
diff --git a/src/main/java/com/zy/core/MainProcess.java b/src/main/java/com/zy/core/MainProcess.java
index 680ac07..70f7954 100644
--- a/src/main/java/com/zy/core/MainProcess.java
+++ b/src/main/java/com/zy/core/MainProcess.java
@@ -1,60 +1,85 @@
package com.zy.core;
-import com.zy.asrs.service.impl.MainServiceImpl;
+import com.core.common.SpringUtils;
+import com.zy.core.plugin.api.MainProcessPluginApi;
import com.zy.core.properties.SystemProperties;
-import lombok.Data;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
-
import javax.annotation.PreDestroy;
/**
* WCS涓绘祦绋�
- * Created by vincent on 2020/8/6
*/
-@Data
@Slf4j
@Component
public class MainProcess {
- @Autowired
- private MainServiceImpl mainService;
+ @Value("${mainProcessPlugin}")
+ private String mainProcessPlugin;
+ private MainProcessPluginApi mainProcessPluginApi;
// 鎵�灞炵嚎绋�
- private Thread thread;
+ private volatile Thread thread;
/**
* =====>> 寮�濮嬪伐浣�
*/
- public void start(){
+ public void start() {
+ if (thread != null && thread.isAlive()) {
+ log.warn("MainProcess is already running.");
+ return;
+ }
+
thread = new Thread(() -> {
while (!Thread.currentThread().isInterrupted()) {
try {
- // 绯荤粺杩愯鐘舵�佸垽鏂�
- if (SystemProperties.WCS_RUNNING_STATUS.get()) {
+ // 1. 鍔犺浇鎻掍欢
+ if (mainProcessPluginApi == null) {
+ try {
+ String className = mainProcessPlugin.contains(".") ? mainProcessPlugin : "com.zy.core.plugin." + mainProcessPlugin;
+ Class<? extends MainProcessPluginApi> clazz = Class.forName(className).asSubclass(MainProcessPluginApi.class);
+ mainProcessPluginApi = SpringUtils.getBean(clazz);
+ } catch (Exception e) {
+ log.error("Failed to load mainProcessPlugin: {}", mainProcessPlugin, e);
+ }
+ }
+
+ // 濡傛灉鍔犺浇澶辫触锛岀瓑寰呭悗閲嶈瘯锛岄槻姝㈢┖鎸囬拡
+ if (mainProcessPluginApi == null) {
+ Thread.sleep(3000);
continue;
}
- // 鍏ュ簱绔欙紝鏍规嵁鏉$爜鎵弿鐢熸垚鍏ュ簱宸ヤ綔妗o紝宸ヤ綔鐘舵��2锛屾棤璁惧鍛戒护涓嬪彂
- mainService.generateStoreWrkFile();
- // 鎷f枡銆佸苟鏉裤�佺洏鐐瑰啀鍏ュ簱
- mainService.stnToCrnStnPick();
+ // 2. 绯荤粺杩愯鐘舵�佸垽鏂�
+ if (!SystemProperties.WCS_RUNNING_STATUS.get()) {
+ // 闃叉蹇欑瓑 (Busy-wait optimization)
+ Thread.sleep(1000);
+ continue;
+ }
+ // 3. 鎵ц涓绘祦绋�
+ mainProcessPluginApi.run();
+ // 4. 闂撮殧
+ Thread.sleep(200);
-
-
-
-
-
- // 闂撮殧
- Thread.sleep(1500);
- log.info("WCS 宸ヤ綔涓� .....................");
+ } catch (InterruptedException ie) {
+ log.info("MainProcess thread interrupted, stopping...");
+ Thread.currentThread().interrupt();
+ break;
} catch (Exception e) {
- e.printStackTrace();
+ log.error("Error in MainProcess execution loop", e);
+ try {
+ // 閬垮厤寮傚父瀵艰嚧鐨勭媯鍒锋棩蹇�
+ Thread.sleep(1000);
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ }
}
}
});
+ thread.setName("MainProcess");
+ thread.setDaemon(true);
thread.start();
}
--
Gitblit v1.9.1