package com.ruoyi.system.core.scnner;

import com.ruoyi.system.core.ClientExecute;
import com.ruoyi.system.core.ClientExecuteFactory;
import com.ruoyi.system.domain.SysDevice;
import com.ruoyi.system.mapper.SysDeviceMapper;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class DeviceStart implements ApplicationRunner {
    @Resource
    private SysDeviceMapper deviceMapper;
    @Resource
    private ClientExecuteFactory factory;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        SysDevice query = new SysDevice();
        query.setEnable(true);
        deviceMapper.selectList(query).collectList().subscribe(devices -> {
            for (SysDevice device : devices) {
                ClientExecute clientExecute = factory.getClientExecute(device.getConnectionType());
                clientExecute.connection(device);
            }
        });
    }
}
