#
Junjie
2026-01-15 6200ba627af8af4045155c1bd7e65220ce59d6ba
src/main/java/com/zy/core/MainProcess.java
@@ -1,90 +1,75 @@
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 int i = 0;
    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 {
                    // 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);
                        }
                    }
                    // 间隔
                    Thread.sleep(300);
                    // 系统运行状态判断
                    if (!SystemProperties.WCS_RUNNING_STATUS.get()) {
                    // 如果加载失败,等待后重试,防止空指针
                    if (mainProcessPluginApi == null) {
                        Thread.sleep(3000);
                        continue;
                    }
                    // 入库  ===>> 入库站到堆垛机站,根据条码扫描生成入库工作档
                    mainService.generateStoreWrkFile(); // 组托
//                    mainService.generateStoreWrkFile0(); // WMS入库
                    // 2. 系统运行状态判断
                    if (!SystemProperties.WCS_RUNNING_STATUS.get()) {
                        // 防止忙等 (Busy-wait optimization)
                        Thread.sleep(1000);
                        continue;
                    }
                    // 间隔
                    Thread.sleep(500);
                    // 3. 执行主流程
                    mainProcessPluginApi.run();
                    //初始化实时地图
                    mainService.initRealtimeBasMap();
                    // 拣料、并板、盘点再入库
                    mainService.stnToCrnStnPick();
                    // 入库  ===>>  四向穿梭车入库作业下发
                    mainService.shuttleInExecute();
                    // 出库  ===>>  四向穿梭车出库作业下发
                    mainService.shuttleOutExecute();
                    //四向穿梭车任务完成
                    mainService.shuttleFinished();
                    //提升机任务
                    mainService.liftIoExecute();
                    //提升机任务完成
                    mainService.liftFinished();
                    //库位移转
                    mainService.locToLocExecute();
                    //执行小车移库任务
                    mainService.shuttleMoveExecute();
                    // 异常信息记录
                    mainService.recErr();
                    // 入库  ===>> 空栈板初始化入库,叉车入库站放货
                    mainService.storeEmptyPlt();
                    // 出库  ===>> 工作档信息写入led显示器
                    mainService.ledExecute();
                    // 其他  ===>> LED显示器复位,显示默认信息
                    mainService.ledReset();
                    // 穿梭车 ===>> 小车电量检测充电
                    mainService.loopShuttleCharge();
                    mainService.executeShuttleCharge();
                    // 间隔
                    // 4. 间隔
                    Thread.sleep(200);
                } catch (Exception e) {
                    e.printStackTrace();
                    log.error("Error in MainProcess execution loop", e);
                }
            }
        });
        thread.setName("MainProcess");
        thread.setDaemon(true);
        thread.start();
    }