package com.zy.acs.conveyor.core.operation; import com.zy.acs.common.utils.News; import com.zy.acs.conveyor.core.enums.ConveyorStateType; import com.zy.acs.conveyor.core.properties.CtuOperationConfig; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @Slf4j @Component public class ConveyorOperationExecutor { private final Map handlerMap = new ConcurrentHashMap<>(); @Autowired public ConveyorOperationExecutor(List handlers) { // 自动注册所有操作处理器 for (OperationHandler handler : handlers) { handlerMap.put(handler.getType(), handler); News.info("注册输送线操作处理器: {}", handler.getType()); } } public void execute(CtuOperationConfig config) { OperationHandler handler = handlerMap.get(config.getType()); if (handler == null) { News.warn("未找到操作处理器: {}", config.getType()); return; } try { handler.execute(config); } catch (Exception e) { News.error("操作执行失败,等待下一周期重试: {}", config.getType(), e); } } }