2025-07-18 22:21:16 +08:00
|
|
|
|
using DMS.Core.Enums;
|
2025-07-18 19:56:00 +08:00
|
|
|
|
using DMS.Models;
|
|
|
|
|
|
using DMS.ViewModels;
|
2025-07-01 21:34:20 +08:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
2025-07-18 19:56:00 +08:00
|
|
|
|
namespace DMS.Helper;
|
2025-07-01 21:34:20 +08:00
|
|
|
|
|
|
|
|
|
|
public class DataServicesHelper
|
|
|
|
|
|
{
|
2025-07-02 12:01:20 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 从设备列表中找到变量表VarTable对象
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="vtableId">VarTable的ID</param>
|
|
|
|
|
|
/// <returns>如果找到择返回对象,否则返回null</returns>
|
|
|
|
|
|
public static VariableTable FindVarTableForDevice(List<Device> devices, int vtableId)
|
|
|
|
|
|
{
|
|
|
|
|
|
VariableTable varTable = null;
|
|
|
|
|
|
foreach (var device in devices)
|
|
|
|
|
|
{
|
|
|
|
|
|
varTable = device.VariableTables.FirstOrDefault(v => v.Id == vtableId);
|
|
|
|
|
|
if (varTable != null)
|
|
|
|
|
|
return varTable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return varTable;
|
|
|
|
|
|
}
|
2025-07-04 18:33:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static MenuBean FindMenusForDevice(Device device, IEnumerable<MenuBean> menus)
|
2025-07-01 21:34:20 +08:00
|
|
|
|
{
|
2025-07-04 18:33:48 +08:00
|
|
|
|
if (menus == null)
|
2025-07-01 21:34:20 +08:00
|
|
|
|
{
|
2025-07-04 18:33:48 +08:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var menu in menus)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 检查当前菜单项是否匹配
|
|
|
|
|
|
if (menu.Type==MenuType.DeviceMenu && menu.DataId ==device.Id)
|
2025-07-01 21:34:20 +08:00
|
|
|
|
{
|
2025-07-04 18:33:48 +08:00
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 递归搜索子菜单
|
|
|
|
|
|
var foundInSubMenu = FindMenusForDevice(device, menu.Items);
|
|
|
|
|
|
if (foundInSubMenu != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return foundInSubMenu;
|
2025-07-01 21:34:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-07-04 18:33:48 +08:00
|
|
|
|
|
2025-07-01 21:34:20 +08:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-02 12:01:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 给菜单排序
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="menu"></param>
|
|
|
|
|
|
public static void SortMenus(MenuBean menu)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (menu.Items == null || menu.Items.Count() == 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
menu.Items.Sort((a, b) =>
|
|
|
|
|
|
a.Type.ToString().Length.CompareTo(b.Type.ToString().Length)
|
|
|
|
|
|
);
|
|
|
|
|
|
foreach (var menuItem in menu.Items)
|
|
|
|
|
|
{
|
|
|
|
|
|
SortMenus(menuItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-01 21:34:20 +08:00
|
|
|
|
public static ViewModelBase GetMainViewModel(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
ViewModelBase navgateVM = App.Current.Services.GetRequiredService<HomeViewModel>();
|
|
|
|
|
|
switch (name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "主页":
|
|
|
|
|
|
navgateVM = App.Current.Services.GetRequiredService<HomeViewModel>();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "设备":
|
|
|
|
|
|
navgateVM = App.Current.Services.GetRequiredService<DevicesViewModel>();
|
|
|
|
|
|
break;
|
2025-07-04 23:34:54 +08:00
|
|
|
|
case "Mqtt服务器":
|
|
|
|
|
|
navgateVM = App.Current.Services.GetRequiredService<MqttsViewModel>();
|
|
|
|
|
|
break;
|
2025-07-01 21:34:20 +08:00
|
|
|
|
case "数据转换":
|
|
|
|
|
|
navgateVM = App.Current.Services.GetRequiredService<DataTransformViewModel>();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "设置":
|
|
|
|
|
|
navgateVM = App.Current.Services.GetRequiredService<SettingViewModel>();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return navgateVM;
|
|
|
|
|
|
}
|
2025-07-16 20:15:39 +08:00
|
|
|
|
|
|
|
|
|
|
public static MenuBean FindVarTableMenu(int varTableId, List<MenuBean> menus)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (menus == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var menu in menus)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 检查当前菜单项是否匹配
|
|
|
|
|
|
if (menu.Type==MenuType.VariableTableMenu && menu.DataId ==varTableId)
|
|
|
|
|
|
{
|
|
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 递归搜索子菜单
|
|
|
|
|
|
var foundInSubMenu = FindVarTableMenu(varTableId, menu.Items);
|
|
|
|
|
|
if (foundInSubMenu != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return foundInSubMenu;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2025-07-01 21:34:20 +08:00
|
|
|
|
}
|