完成添加设备
This commit is contained in:
@@ -45,6 +45,7 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
|||||||
// 菜单树列表。
|
// 菜单树列表。
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private ObservableCollection<MenuBeanItemViewModel> _menus;
|
private ObservableCollection<MenuBeanItemViewModel> _menus;
|
||||||
|
|
||||||
// 菜单树列表。
|
// 菜单树列表。
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private ObservableCollection<MenuBeanItemViewModel> _menuTrees;
|
private ObservableCollection<MenuBeanItemViewModel> _menuTrees;
|
||||||
@@ -72,7 +73,6 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
|||||||
public event Action<Device, bool> OnDeviceIsActiveChanged;
|
public event Action<Device, bool> OnDeviceIsActiveChanged;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DataServices类的构造函数。
|
/// DataServices类的构造函数。
|
||||||
/// 注入ILogger<DataServices>,并初始化各个数据仓库。
|
/// 注入ILogger<DataServices>,并初始化各个数据仓库。
|
||||||
@@ -80,7 +80,8 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
|||||||
/// <param name="mapper">AutoMapper 实例。</param>
|
/// <param name="mapper">AutoMapper 实例。</param>
|
||||||
/// <param name="varDataRepository"></param>
|
/// <param name="varDataRepository"></param>
|
||||||
public DataServices(IMapper mapper, IDeviceAppService deviceAppService,
|
public DataServices(IMapper mapper, IDeviceAppService deviceAppService,
|
||||||
IVariableTableAppService variableTableAppService, IVariableAppService variableAppService,IMenuService menuService,INavigationService navigationService)
|
IVariableTableAppService variableTableAppService, IVariableAppService variableAppService,
|
||||||
|
IMenuService menuService, INavigationService navigationService)
|
||||||
{
|
{
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
_deviceAppService = deviceAppService;
|
_deviceAppService = deviceAppService;
|
||||||
@@ -115,7 +116,7 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
|||||||
{
|
{
|
||||||
// 设备仍然存在,检查是否有更新
|
// 设备仍然存在,检查是否有更新
|
||||||
var dto = deviceDtos.First(d => d.Id == existingItem.Id);
|
var dto = deviceDtos.First(d => d.Id == existingItem.Id);
|
||||||
|
|
||||||
// 逐一比较属性,只有在发生变化时才更新
|
// 逐一比较属性,只有在发生变化时才更新
|
||||||
if (existingItem.Name != dto.Name) existingItem.Name = dto.Name;
|
if (existingItem.Name != dto.Name) existingItem.Name = dto.Name;
|
||||||
if (existingItem.Protocol != dto.Protocol) existingItem.Protocol = dto.Protocol;
|
if (existingItem.Protocol != dto.Protocol) existingItem.Protocol = dto.Protocol;
|
||||||
@@ -204,13 +205,13 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
|||||||
{
|
{
|
||||||
// 这是一个新菜单项,添加到集合中
|
// 这是一个新菜单项,添加到集合中
|
||||||
// 注意:这里直接添加 IMenuService 返回的 MenuItemViewModel 实例
|
// 注意:这里直接添加 IMenuService 返回的 MenuItemViewModel 实例
|
||||||
Menus.Add(new MenuBeanItemViewModel(newDto,_navigationService));
|
Menus.Add(new MenuBeanItemViewModel(newDto, _navigationService));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildMenuTree();
|
BuildMenuTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据扁平菜单列表构建树形结构。
|
/// 根据扁平菜单列表构建树形结构。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -244,7 +245,6 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
|||||||
MenuTrees.Add(menu);
|
MenuTrees.Add(menu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -280,17 +280,21 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
|||||||
if (existingItem.SignalType != dto.SignalType) existingItem.SignalType = dto.SignalType;
|
if (existingItem.SignalType != dto.SignalType) existingItem.SignalType = dto.SignalType;
|
||||||
if (existingItem.PollLevel != dto.PollLevel) existingItem.PollLevel = dto.PollLevel;
|
if (existingItem.PollLevel != dto.PollLevel) existingItem.PollLevel = dto.PollLevel;
|
||||||
if (existingItem.IsActive != dto.IsActive) existingItem.IsActive = dto.IsActive;
|
if (existingItem.IsActive != dto.IsActive) existingItem.IsActive = dto.IsActive;
|
||||||
if (existingItem.VariableTableId != dto.VariableTableId) existingItem.VariableTableId = dto.VariableTableId;
|
if (existingItem.VariableTableId != dto.VariableTableId)
|
||||||
|
existingItem.VariableTableId = dto.VariableTableId;
|
||||||
if (existingItem.OpcUaNodeId != dto.OpcUaNodeId) existingItem.OpcUaNodeId = dto.OpcUaNodeId;
|
if (existingItem.OpcUaNodeId != dto.OpcUaNodeId) existingItem.OpcUaNodeId = dto.OpcUaNodeId;
|
||||||
if (existingItem.IsHistoryEnabled != dto.IsHistoryEnabled) existingItem.IsHistoryEnabled = dto.IsHistoryEnabled;
|
if (existingItem.IsHistoryEnabled != dto.IsHistoryEnabled)
|
||||||
if (existingItem.HistoryDeadband != dto.HistoryDeadband) existingItem.HistoryDeadband = dto.HistoryDeadband;
|
existingItem.IsHistoryEnabled = dto.IsHistoryEnabled;
|
||||||
|
if (existingItem.HistoryDeadband != dto.HistoryDeadband)
|
||||||
|
existingItem.HistoryDeadband = dto.HistoryDeadband;
|
||||||
if (existingItem.IsAlarmEnabled != dto.IsAlarmEnabled) existingItem.IsAlarmEnabled = dto.IsAlarmEnabled;
|
if (existingItem.IsAlarmEnabled != dto.IsAlarmEnabled) existingItem.IsAlarmEnabled = dto.IsAlarmEnabled;
|
||||||
if (existingItem.AlarmMinValue != dto.AlarmMinValue) existingItem.AlarmMinValue = dto.AlarmMinValue;
|
if (existingItem.AlarmMinValue != dto.AlarmMinValue) existingItem.AlarmMinValue = dto.AlarmMinValue;
|
||||||
if (existingItem.AlarmMaxValue != dto.AlarmMaxValue) existingItem.AlarmMaxValue = dto.AlarmMaxValue;
|
if (existingItem.AlarmMaxValue != dto.AlarmMaxValue) existingItem.AlarmMaxValue = dto.AlarmMaxValue;
|
||||||
if (existingItem.AlarmDeadband != dto.AlarmDeadband) existingItem.AlarmDeadband = dto.AlarmDeadband;
|
if (existingItem.AlarmDeadband != dto.AlarmDeadband) existingItem.AlarmDeadband = dto.AlarmDeadband;
|
||||||
if (existingItem.Protocol != dto.Protocol) existingItem.Protocol = dto.Protocol;
|
if (existingItem.Protocol != dto.Protocol) existingItem.Protocol = dto.Protocol;
|
||||||
if (existingItem.CSharpDataType != dto.CSharpDataType) existingItem.CSharpDataType = dto.CSharpDataType;
|
if (existingItem.CSharpDataType != dto.CSharpDataType) existingItem.CSharpDataType = dto.CSharpDataType;
|
||||||
if (existingItem.ConversionFormula != dto.ConversionFormula) existingItem.ConversionFormula = dto.ConversionFormula;
|
if (existingItem.ConversionFormula != dto.ConversionFormula)
|
||||||
|
existingItem.ConversionFormula = dto.ConversionFormula;
|
||||||
if (existingItem.CreatedAt != dto.CreatedAt) existingItem.CreatedAt = dto.CreatedAt;
|
if (existingItem.CreatedAt != dto.CreatedAt) existingItem.CreatedAt = dto.CreatedAt;
|
||||||
if (existingItem.UpdatedAt != dto.UpdatedAt) existingItem.UpdatedAt = dto.UpdatedAt;
|
if (existingItem.UpdatedAt != dto.UpdatedAt) existingItem.UpdatedAt = dto.UpdatedAt;
|
||||||
if (existingItem.UpdatedBy != dto.UpdatedBy) existingItem.UpdatedBy = dto.UpdatedBy;
|
if (existingItem.UpdatedBy != dto.UpdatedBy) existingItem.UpdatedBy = dto.UpdatedBy;
|
||||||
@@ -381,8 +385,8 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
|||||||
{
|
{
|
||||||
// 1. 创建一个字典,按 DeviceId 分组所有变量表,以便高效查找
|
// 1. 创建一个字典,按 DeviceId 分组所有变量表,以便高效查找
|
||||||
var variableTablesGroupedByDevice = _variableTables
|
var variableTablesGroupedByDevice = _variableTables
|
||||||
.GroupBy(vt => vt.DeviceId)
|
.GroupBy(vt => vt.DeviceId)
|
||||||
.ToDictionary(g => g.Key, g => g.ToList());
|
.ToDictionary(g => g.Key, g => g.ToList());
|
||||||
|
|
||||||
foreach (var device in _devices)
|
foreach (var device in _devices)
|
||||||
{
|
{
|
||||||
@@ -427,8 +431,8 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
|||||||
{
|
{
|
||||||
// 1. 创建一个字典,按 VariableTableId 分组所有变量,以便高效查找
|
// 1. 创建一个字典,按 VariableTableId 分组所有变量,以便高效查找
|
||||||
var variablesGroupedByVariableTable = _variables
|
var variablesGroupedByVariableTable = _variables
|
||||||
.GroupBy(v => v.VariableTableId)
|
.GroupBy(v => v.VariableTableId)
|
||||||
.ToDictionary(g => g.Key, g => g.ToList());
|
.ToDictionary(g => g.Key, g => g.ToList());
|
||||||
|
|
||||||
foreach (var variableTable in _variableTables)
|
foreach (var variableTable in _variableTables)
|
||||||
{
|
{
|
||||||
@@ -465,4 +469,32 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddMenuItem(MenuBeanItemViewModel menuBeanItemViewModel)
|
||||||
|
{
|
||||||
|
if (menuBeanItemViewModel == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var deviceMenu = Menus.FirstOrDefault(m => m.Id == menuBeanItemViewModel.ParentId);
|
||||||
|
if (deviceMenu != null)
|
||||||
|
{
|
||||||
|
deviceMenu.Children.Add(menuBeanItemViewModel);
|
||||||
|
Menus.Add(menuBeanItemViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddVariableTable(VariableTableItemViewModel variableTableItemViewModel)
|
||||||
|
{
|
||||||
|
if (variableTableItemViewModel == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
VariableTables.Add(variableTableItemViewModel);
|
||||||
|
var device = Devices.FirstOrDefault(d => d.Id == variableTableItemViewModel.DeviceId);
|
||||||
|
if (device != null)
|
||||||
|
{
|
||||||
|
device.VariableTables.Add(variableTableItemViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -147,18 +147,15 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var addDto = await _deviceAppService.CreateDeviceWithDetailsAsync(dto);
|
var addDto = await _deviceAppService.CreateDeviceWithDetailsAsync(dto);
|
||||||
|
|
||||||
|
// 更新界面
|
||||||
DataServices.Devices.Add(_mapper.Map<DeviceItemViewModel>(addDto.Device));
|
DataServices.Devices.Add(_mapper.Map<DeviceItemViewModel>(addDto.Device));
|
||||||
if (addDto.DeviceMenu != null)
|
DataServices.AddMenuItem(_mapper.Map<MenuBeanItemViewModel>(addDto.DeviceMenu));
|
||||||
{
|
DataServices.AddVariableTable(_mapper.Map<VariableTableItemViewModel>(addDto.VariableTable));
|
||||||
var deviceMenu = DataServices.Menus.FirstOrDefault(m => m.Id == addDto.DeviceMenu.ParentId);
|
DataServices.AddMenuItem(_mapper.Map<MenuBeanItemViewModel>(addDto.VariableTableMenu));
|
||||||
if (deviceMenu!=null)
|
|
||||||
{
|
NotificationHelper.ShowSuccess($"设备添加成功:{addDto.Device.Name}");
|
||||||
deviceMenu.Children.Add(_mapper.Map<MenuBeanItemViewModel>(addDto.DeviceMenu));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user