/*
 * 文 件 名:  StepExecutorFactory
 * 版    权:  华设设计集团股份有限公司
 * 描    述:  <描述>
 * 修 改 人:  lvwenbin
 * 修改时间:  2025/11/27
 * 跟踪单号:  <跟踪单号>
 * 修改单号:  <修改单号>
 * 修改内容:  <修改内容>
 */
package com.ruoyi.ems.strategy.executor;

import com.ruoyi.ems.service.IStepExecutor;
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;

/**
 * 步骤执行器工厂
 * <功能详细描述>
 *
 * @author lvwenbin
 * @version [版本号, 2025/11/27]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Component
public class StepExecutorFactory {
    private final Map<String, IStepExecutor> executorMap = new ConcurrentHashMap<>();

    @Autowired
    public void setExecutors(List<IStepExecutor> executors) {
        executors.forEach(executor ->
            executorMap.put(executor.getSupportedType(), executor)
        );
    }

    public IStepExecutor getExecutor(String stepType) {
        IStepExecutor executor = executorMap.get(stepType);
        if (executor == null) {
            throw new IllegalArgumentException("不支持的步骤类型: " + stepType);
        }
        return executor;
    }
}