123
zhang
9 天以前 0a37b816117828dfc216d00c17724900f4bb14e3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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<ConveyorStateType, OperationHandler> handlerMap = new ConcurrentHashMap<>();
 
    @Autowired
    public ConveyorOperationExecutor(List<OperationHandler> 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);
        }
    }
}