diff --git a/IoTGateway.ViewModel/BasicData/ImportExcelVM.cs b/IoTGateway.ViewModel/BasicData/ImportExcelVM.cs index e61a872..2ebaf98 100644 --- a/IoTGateway.ViewModel/BasicData/ImportExcelVM.cs +++ b/IoTGateway.ViewModel/BasicData/ImportExcelVM.cs @@ -101,11 +101,8 @@ namespace IoTGateway.ViewModel.BasicData myMqttClient.StartClientAsync().Wait(); //重新启动采集 - foreach (var device in devices.Where(x => x.DeviceTypeEnum == DeviceTypeEnum.Device && x.DriverId != null)) - { - device.Driver = _drivers.FirstOrDefault(x => x.ID == device.DriverId); - deviceService.CreateDeviceThread(device); - } + deviceService.CreateDeviceThreads(); + 导入结果 = $"成功导入{devices.Count(x => x.DeviceTypeEnum == DeviceTypeEnum.Device)}个设备,{devices.Count(x => x.DeviceTypeEnum == DeviceTypeEnum.Group)}个组"; } diff --git a/Plugins/Plugin/DeviceService.cs b/Plugins/Plugin/DeviceService.cs index 7441380..b38a376 100644 --- a/Plugins/Plugin/DeviceService.cs +++ b/Plugins/Plugin/DeviceService.cs @@ -32,6 +32,12 @@ namespace Plugin _myMqttClient = myMqttClient; //_uAService = uAService; _mqttServer = mqttServer ?? throw new ArgumentNullException(nameof(mqttServer)); + + CreateDeviceThreads(); + } + + public void CreateDeviceThreads() + { try { using (var dc = new DataContext(_connnectSetting, _dbType))