2021-12-12 06:55:48 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using WalkingTec.Mvvm.Core;
|
|
|
|
|
using WalkingTec.Mvvm.Core.Extensions;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using IoTGateway.Model;
|
2022-04-18 08:35:33 +00:00
|
|
|
|
using Plugin;
|
2021-12-12 06:55:48 +00:00
|
|
|
|
|
|
|
|
|
namespace IoTGateway.ViewModel.BasicData.DeviceConfigVMs
|
|
|
|
|
{
|
|
|
|
|
public partial class DeviceConfigListVM : BasePagedListVM<DeviceConfig_View, DeviceConfigSearcher>
|
|
|
|
|
{
|
|
|
|
|
public List<TreeSelectListItem> AllDevices { get; set; }
|
|
|
|
|
protected override List<GridAction> InitGridAction()
|
|
|
|
|
{
|
|
|
|
|
return new List<GridAction>
|
|
|
|
|
{
|
|
|
|
|
this.MakeStandardAction("DeviceConfig", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"BasicData", dialogWidth: 800),
|
|
|
|
|
this.MakeStandardAction("DeviceConfig", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "BasicData", dialogWidth: 800),
|
|
|
|
|
//this.MakeStandardAction("DeviceConfig", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "BasicData", dialogWidth: 800),
|
|
|
|
|
this.MakeStandardAction("DeviceConfig", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "BasicData", dialogWidth: 800),
|
|
|
|
|
this.MakeStandardAction("DeviceConfig", GridActionStandardTypesEnum.BatchEdit, Localizer["Sys.BatchEdit"], "BasicData", dialogWidth: 800),
|
|
|
|
|
//this.MakeStandardAction("DeviceConfig", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "BasicData", dialogWidth: 800),
|
|
|
|
|
//this.MakeStandardAction("DeviceConfig", GridActionStandardTypesEnum.Import, Localizer["Sys.Import"], "BasicData", dialogWidth: 800),
|
|
|
|
|
this.MakeStandardAction("DeviceConfig", GridActionStandardTypesEnum.ExportExcel, Localizer["Sys.Export"], "BasicData"),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
protected override void InitListVM()
|
|
|
|
|
{
|
|
|
|
|
AllDevices = DC.Set<Device>().AsNoTracking()
|
|
|
|
|
.OrderBy(x => x.Parent.Index).ThenBy(x => x.Parent.DeviceName)
|
|
|
|
|
.OrderBy(x => x.Index).ThenBy(x => x.DeviceName)
|
|
|
|
|
.GetTreeSelectListItems(Wtm, x => x.DeviceName);
|
2022-08-08 07:16:42 +00:00
|
|
|
|
|
|
|
|
|
var deviceService = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
|
2021-12-12 06:55:48 +00:00
|
|
|
|
foreach (var device in AllDevices)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in device.Children)
|
|
|
|
|
{
|
2022-08-10 08:55:44 +00:00
|
|
|
|
var deviceThread = deviceService.DeviceThreads.Where(x => x.Device.ID.ToString() == (string)item.Value).FirstOrDefault();
|
2022-08-08 07:16:42 +00:00
|
|
|
|
if (deviceThread != null)
|
2022-08-10 08:55:44 +00:00
|
|
|
|
item.Icon = deviceThread.Device.AutoStart ? (deviceThread.Driver.IsConnected ? "layui-icon layui-icon-link" : "layui-icon layui-icon-unlink") : "layui-icon layui-icon-pause";
|
2022-08-08 07:16:42 +00:00
|
|
|
|
|
|
|
|
|
item.Text = " "+item.Text;
|
2021-12-12 06:55:48 +00:00
|
|
|
|
item.Expended = true;
|
2022-08-08 07:16:42 +00:00
|
|
|
|
item.Selected =item.Value.ToString() == IoTBackgroundService.ConfigSelectDeviceId.ToString();
|
2021-12-12 06:55:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
base.InitListVM();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override IEnumerable<IGridColumn<DeviceConfig_View>> InitGridHeader()
|
|
|
|
|
{
|
|
|
|
|
return new List<GridColumn<DeviceConfig_View>>{
|
2021-12-17 14:39:18 +00:00
|
|
|
|
this.MakeGridHeader(x => x.DeviceConfigName).SetWidth(100),
|
2022-03-24 13:38:11 +00:00
|
|
|
|
this.MakeGridHeader(x => x.DataSide).SetWidth(100),
|
2021-12-17 14:39:18 +00:00
|
|
|
|
this.MakeGridHeader(x => x.Description).SetWidth(100),
|
|
|
|
|
this.MakeGridHeader(x => x.Value).SetWidth(100),
|
|
|
|
|
this.MakeGridHeader(x => x.DeviceName_view).SetWidth(100),
|
2021-12-12 06:55:48 +00:00
|
|
|
|
this.MakeGridHeader(x => x.EnumInfo),
|
|
|
|
|
this.MakeGridHeaderAction(width: 200)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IOrderedQueryable<DeviceConfig_View> GetSearchQuery()
|
|
|
|
|
{
|
2022-04-18 08:35:33 +00:00
|
|
|
|
if (Searcher.DeviceId != null)
|
|
|
|
|
IoTBackgroundService.ConfigSelectDeviceId = Searcher.DeviceId;
|
2021-12-12 06:55:48 +00:00
|
|
|
|
var query = DC.Set<DeviceConfig>()
|
2022-03-24 13:38:11 +00:00
|
|
|
|
.CheckContain(Searcher.DeviceConfigName, x => x.DeviceConfigName)
|
|
|
|
|
.CheckContain(Searcher.Value, x => x.Value)
|
|
|
|
|
.CheckEqual(Searcher.DeviceId, x => x.DeviceId)
|
|
|
|
|
.CheckEqual(Searcher.DataSide, x => x.DataSide)
|
2021-12-12 06:55:48 +00:00
|
|
|
|
.Select(x => new DeviceConfig_View
|
|
|
|
|
{
|
2022-03-24 13:38:11 +00:00
|
|
|
|
ID = x.ID,
|
2021-12-12 06:55:48 +00:00
|
|
|
|
DeviceConfigName = x.DeviceConfigName,
|
2022-03-24 13:38:11 +00:00
|
|
|
|
DataSide = x.DataSide,
|
2021-12-12 06:55:48 +00:00
|
|
|
|
Description = x.Description,
|
|
|
|
|
Value = x.Value,
|
|
|
|
|
EnumInfo = x.EnumInfo,
|
|
|
|
|
DeviceName_view = x.Device.DeviceName,
|
|
|
|
|
})
|
2022-03-24 13:38:11 +00:00
|
|
|
|
.OrderBy(x => x.DeviceName_view).ThenBy(x => x.DeviceConfigName);
|
2021-12-12 06:55:48 +00:00
|
|
|
|
return query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-24 13:38:11 +00:00
|
|
|
|
public class DeviceConfig_View : DeviceConfig
|
|
|
|
|
{
|
2021-12-12 06:55:48 +00:00
|
|
|
|
[Display(Name = "设备名")]
|
|
|
|
|
public String DeviceName_view { get; set; }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|