huang
2025-11-26 792236ef78c2cdd3a989fb40a7f2e2487c4e17b6
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
42
package com.mes.interaction;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
 
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 交互注册中心
 * @author huang
 */
@Slf4j
@Component
public class DeviceInteractionRegistry {
 
    private final Map<String, DeviceInteraction> interactionMap = new HashMap<>();
 
    public DeviceInteractionRegistry(List<DeviceInteraction> interactions) {
        if (interactions != null) {
            for (DeviceInteraction interaction : interactions) {
                if (interaction.getDeviceType() != null) {
                    interactionMap.put(interaction.getDeviceType(), interaction);
                    log.info("注册设备交互: {}", interaction.getDeviceType());
                }
            }
        }
    }
 
    public DeviceInteraction getInteraction(String deviceType) {
        if (deviceType == null) {
            return null;
        }
        return interactionMap.get(deviceType);
    }
 
    public Map<String, DeviceInteraction> getInteractions() {
        return Collections.unmodifiableMap(interactionMap);
    }
}