yeg
2026-08-27 a4f06a9095a2eab0bb48b406c4609be6e70b8854
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
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.ruoyi.config;
 
import java.io.IOException;
import java.util.List;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import com.ruoyi.device.bts.BtsDeviceAdapterFactory;
import com.ruoyi.device.bts.BtsDevelopmentSimulator;
import com.ruoyi.device.registry.DeviceAdapterRegistry;
import com.ruoyi.system.domain.TDeviceAdapter;
import com.ruoyi.system.service.IDeviceAdapterService;
 
/** 装配单进程设备适配器运行时。 */
@Configuration
@EnableScheduling
public class DeviceAdapterRuntimeConfig
{
    @Bean(destroyMethod = "close")
    public DeviceAdapterRegistry deviceAdapterRegistry()
    {
        return new DeviceAdapterRegistry(List.of(new BtsDeviceAdapterFactory()));
    }
 
    @Bean(destroyMethod = "close")
    public BtsDevelopmentSimulator btsDevelopmentSimulator() throws IOException
    {
        return new BtsDevelopmentSimulator(BtsDevelopmentSimulator.DEFAULT_PORT);
    }
 
    @Bean
    public ApplicationRunner registerDevelopmentSimulatorAdapter(IDeviceAdapterService service)
    {
        // ApplicationRunner 先于 ApplicationReadyEvent,确保恢复启用适配器时 dev-sim 已存在。
        return arguments -> service.ensureManagedAdapter(developmentSimulatorAdapter());
    }
 
    private TDeviceAdapter developmentSimulatorAdapter()
    {
        TDeviceAdapter adapter = new TDeviceAdapter();
        adapter.setAdapterCode("dev-sim");
        adapter.setAdapterName("dev-sim BTS 模拟器");
        adapter.setAdapterType("BTS");
        adapter.setHost(BtsDevelopmentSimulator.HOST);
        adapter.setPort(BtsDevelopmentSimulator.DEFAULT_PORT);
        adapter.setPollIntervalMs(5000);
        adapter.setTimezoneId("Asia/Hong_Kong");
        adapter.setReadOnly(true);
        adapter.setCapabilities("{\"discovery\":true,\"realtimeObservation\":true,"
                + "\"historyDownload\":false,\"control\":false}");
        adapter.setRemark("临时人工验收设备");
        return adapter;
    }
}