From bf5864cdd5e6f8fb10457d02899a61fb18282168 Mon Sep 17 00:00:00 2001 From: iioter <535915157@qq.com> Date: Sun, 21 Aug 2022 22:01:32 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=BF=87=E5=89=8D=E7=AB=AF=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E5=86=99=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IoTGateway.Model/DeviceVariable.cs | 1 + .../DeviceVariableVMs/DeviceVariableListVM.cs | 2 +- .../BasicData/DeviceVariableVMs/SetValueVM.cs | 149 ++++-- .../Controllers/DeviceVariableController.cs | 12 +- .../Views/DeviceVariable/Indexbak.cshtml | 505 ------------------ .../Views/DeviceVariable/SetValue.cshtml | 23 +- IoTGateway/iotgateway.db | Bin 311296 -> 311296 bytes 7 files changed, 131 insertions(+), 561 deletions(-) delete mode 100644 IoTGateway/Areas/BasicData/Views/DeviceVariable/Indexbak.cshtml diff --git a/IoTGateway.Model/DeviceVariable.cs b/IoTGateway.Model/DeviceVariable.cs index 26b9d7d..350621c 100644 --- a/IoTGateway.Model/DeviceVariable.cs +++ b/IoTGateway.Model/DeviceVariable.cs @@ -28,6 +28,7 @@ namespace IoTGateway.Model [Display(Name = "权限")] public ProtectTypeEnum ProtectType { get; set; } + [Newtonsoft.Json.JsonIgnore] public Device Device { get; set; } [Display(Name = "设备")] public Guid? DeviceId { get; set; } diff --git a/IoTGateway.ViewModel/BasicData/DeviceVariableVMs/DeviceVariableListVM.cs b/IoTGateway.ViewModel/BasicData/DeviceVariableVMs/DeviceVariableListVM.cs index 3d655b9..d15e0d0 100644 --- a/IoTGateway.ViewModel/BasicData/DeviceVariableVMs/DeviceVariableListVM.cs +++ b/IoTGateway.ViewModel/BasicData/DeviceVariableVMs/DeviceVariableListVM.cs @@ -21,7 +21,7 @@ namespace IoTGateway.ViewModel.BasicData.DeviceVariableVMs { return new List { - this.MakeAction("DeviceVariable","SetValue","写入值","写入值", GridActionParameterTypesEnum.SingleId,"BasicData",600).SetIconCls("_wtmicon _wtmicon-xiayibu").SetHideOnToolBar(false).SetShowInRow(false).SetBindVisiableColName("setValue"), + this.MakeAction("DeviceVariable","SetValue","写入值","写入值", GridActionParameterTypesEnum.MultiIds,"BasicData",600).SetIconCls("_wtmicon _wtmicon-xiayibu").SetHideOnToolBar(false).SetShowInRow(false).SetBindVisiableColName("setValue"), this.MakeStandardAction("DeviceVariable", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"BasicData", dialogWidth: 800), this.MakeStandardAction("DeviceVariable", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "BasicData", dialogWidth: 800), this.MakeStandardAction("DeviceVariable", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "BasicData", dialogWidth: 800), diff --git a/IoTGateway.ViewModel/BasicData/DeviceVariableVMs/SetValueVM.cs b/IoTGateway.ViewModel/BasicData/DeviceVariableVMs/SetValueVM.cs index 4724a0d..05d506b 100644 --- a/IoTGateway.ViewModel/BasicData/DeviceVariableVMs/SetValueVM.cs +++ b/IoTGateway.ViewModel/BasicData/DeviceVariableVMs/SetValueVM.cs @@ -7,80 +7,139 @@ using WalkingTec.Mvvm.Core; using WalkingTec.Mvvm.Core.Extensions; using IoTGateway.Model; using System.ComponentModel.DataAnnotations; +using Microsoft.Extensions.Primitives; +using System.Runtime.Intrinsics.Arm; +using Newtonsoft.Json; namespace IoTGateway.ViewModel.BasicData.DeviceVariableVMs { public class SetValueVM : BaseVM { - public string 设备名 { get; set; } - public string 变量名 { get; set; } - public string 类型 { get; set; } - public string 当前原始值 { get; set; } - public string 当前计算值 { get; set; } - public string 状态 { get; set; } - public string 设定原始值 { get; set; } + public List SetValues { get; set; } = new(); public string 设置结果 { get; set; } public void Set() { try { - var variable = DC.Set().Where(x => x.ID == Guid.Parse(FC["id"].ToString())).AsNoTracking().Include(x => x.Device).FirstOrDefault(); - 设备名 = variable.Device.DeviceName; - 变量名 = variable.Name; - 类型 = variable.DataType.GetEnumDisplayName(); + var ids = (StringValues)FC["setValue.ID[]"]; + var values= (StringValues)FC["setValue.SetRawValue[]"]; + Dictionary kv = new(0); + for (int i = 0; i < ids.Count; i++) + { + kv[ids[i]]=values[i]; + } + + + var setValues = JsonConvert.DeserializeObject>( + JsonConvert.SerializeObject(DC.Set() + .Where(x => ids.Contains(x.ID.ToString().ToLower())).AsNoTracking() + .OrderBy(x => x.DeviceId).ToList())); var deviceService = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService; - var dapThread = deviceService.DeviceThreads.Where(x => x.Device.ID == variable.DeviceId).FirstOrDefault(); - if (dapThread?.DeviceValues != null && dapThread.DeviceValues.ContainsKey(variable.ID)) - { - 当前原始值 = dapThread.DeviceValues[variable.ID].Value?.ToString(); - 当前计算值 = dapThread.DeviceValues[variable.ID].CookedValue?.ToString(); - 状态 = dapThread.DeviceValues[variable.ID].StatusType.ToString(); - } - - if (variable == null || variable.Device == null || dapThread == null) - 设置结果 = "设置失败,找不到设备(变量)"; - - else - { - PluginInterface.RpcRequest request = new PluginInterface.RpcRequest() + if (setValues != null) + foreach (var deviceVariables in setValues.GroupBy(x => x.DeviceId)) { - RequestId = Guid.NewGuid().ToString(), - DeviceName = variable.Device.DeviceName, - Method = "write", - Params = new Dictionary() { { variable.Name, 设定原始值 } } - }; - dapThread.MyMqttClient_OnExcRpc(this, request); - 设置结果 = "设置成功"; - } + if (deviceService != null) + { + var dapThread = + deviceService.DeviceThreads.FirstOrDefault(x => + x.Device.ID == deviceVariables.Key); + + if (dapThread != null) + { + string deviceName = dapThread.Device.DeviceName; + foreach (var variable in deviceVariables) + { + if (dapThread.DeviceValues.ContainsKey(variable.ID)) + { + variable.DeviceName = deviceName; + variable.RawValue = dapThread.DeviceValues[variable.ID].Value?.ToString(); + variable.Value = dapThread.DeviceValues[variable.ID].CookedValue?.ToString(); + variable.Status = dapThread.DeviceValues[variable.ID].StatusType.ToString(); + variable.SetRawValue = kv[variable.ID.ToString()]; + } + } + + PluginInterface.RpcRequest request = new PluginInterface.RpcRequest() + { + RequestId = Guid.NewGuid().ToString(), + DeviceName = deviceName, + Method = "write", + Params = deviceVariables.ToDictionary(x => x.Name, x => x.SetRawValue) + }; + dapThread.MyMqttClient_OnExcRpc(this, request); + } + + } + } + 设置结果 = "设置成功"; } catch (Exception ex) { - 设置结果 = $"设置失败,{ex}"; } } protected override void InitVM() { - var variable = DC.Set().Where(x => x.ID == Guid.Parse(FC["id"].ToString())).AsNoTracking().Include(x => x.Device).FirstOrDefault(); - 设备名 = variable.Device.DeviceName; - 变量名 = variable.Name; - 类型 = variable.DataType.GetEnumDisplayName(); + StringValues ids; + if (FC.ContainsKey("setValue.ID[]")) + ids = (StringValues)FC["setValue.ID[]"]; + else + ids = (StringValues)FC["Ids[]"]; + + var setValues = JsonConvert.DeserializeObject>( + JsonConvert.SerializeObject(DC.Set() + .Where(x => ids.Contains(x.ID.ToString().ToLower())).AsNoTracking() + .OrderBy(x => x.DeviceId).ToList())); var deviceService = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService; - var dapThread = deviceService.DeviceThreads.Where(x => x.Device.ID == variable.DeviceId).FirstOrDefault(); - if (dapThread?.DeviceValues != null && dapThread.DeviceValues.ContainsKey(variable.ID)) - { - 当前原始值 = dapThread.DeviceValues[variable.ID].Value?.ToString(); - 当前计算值 = dapThread.DeviceValues[variable.ID].CookedValue?.ToString(); - 状态 = dapThread.DeviceValues[variable.ID].StatusType.ToString(); - } + if (setValues != null) + foreach (var deviceVariables in setValues.GroupBy(x => x.DeviceId)) + { + if (deviceService != null) + { + var dapThread = + deviceService.DeviceThreads.FirstOrDefault(x => + x.Device.ID == deviceVariables.Key); + if (dapThread != null) + { + string deviceName = dapThread.Device.DeviceName; + foreach (var variable in deviceVariables) + { + if (dapThread.DeviceValues.ContainsKey(variable.ID)) + { + variable.DeviceName = deviceName; + variable.RawValue = dapThread.DeviceValues[variable.ID].Value?.ToString(); + variable.Value = dapThread.DeviceValues[variable.ID].CookedValue?.ToString(); + variable.Status = dapThread.DeviceValues[variable.ID].StatusType.ToString(); + } + } + } + + } + } + + SetValues = setValues; base.InitVM(); } } + + public class SetValue : DeviceVariable + { + [Display(Name = "设备名")] + public string DeviceName { get; set; } + [Display(Name = "设定原值")] + public object SetRawValue { get; set; } + [Display(Name = "原值")] + public string RawValue { get; set; } + [Display(Name = "计算值")] + public string Value { get; set; } + [Display(Name = "状态")] + public string Status { get; set; } + } } diff --git a/IoTGateway/Areas/BasicData/Controllers/DeviceVariableController.cs b/IoTGateway/Areas/BasicData/Controllers/DeviceVariableController.cs index b727f98..0414edf 100644 --- a/IoTGateway/Areas/BasicData/Controllers/DeviceVariableController.cs +++ b/IoTGateway/Areas/BasicData/Controllers/DeviceVariableController.cs @@ -5,6 +5,7 @@ using WalkingTec.Mvvm.Core; using WalkingTec.Mvvm.Mvc; using WalkingTec.Mvvm.Core.Extensions; using IoTGateway.ViewModel.BasicData.DeviceVariableVMs; +using Opc.Ua.Security.Certificates; namespace IoTGateway.Controllers { @@ -216,16 +217,21 @@ namespace IoTGateway.Controllers } #region 下发写入 [ActionDescription("下发写入")] - public ActionResult SetValue() + [HttpPost] + public ActionResult SetValue(string[] IDs) { - var vm = Wtm.CreateVM(); + var vm = Wtm.CreateVM(Ids: IDs); return PartialView(vm); } [HttpPost] [ActionDescription("下发写入")] - public ActionResult SetValue(SetValueVM vm) + public ActionResult DoSetValue() { + var ids = Request.Form["setValue.ID[]"].ToArray(); + var values = Request.Form["setValue.SetRawValue[]"].ToArray(); + + var vm = Wtm.CreateVM(Ids: ids); if (!ModelState.IsValid) { return PartialView(vm); diff --git a/IoTGateway/Areas/BasicData/Views/DeviceVariable/Indexbak.cshtml b/IoTGateway/Areas/BasicData/Views/DeviceVariable/Indexbak.cshtml deleted file mode 100644 index 8edf80b..0000000 --- a/IoTGateway/Areas/BasicData/Views/DeviceVariable/Indexbak.cshtml +++ /dev/null @@ -1,505 +0,0 @@ -@model IoTGateway.ViewModel.BasicData.DeviceVariableVMs.DeviceVariableListVM -@inject IStringLocalizer Localizer; -@using Newtonsoft.Json - -
-
-
-
-
-
-
-
-
-

- 搜索条件 -
- 搜索 - -
-

-
- - -
- -
- -
- -
- -
-
- -
- - - - -
- -
- -
- -
-
- -
- - -
- -
- -
- -
-
- -
- - -
- -
- -
- -
-
- -
- - -
- -
- -
- -
-
- -
- - - -
- -
-
-
- -
- - -
- - - - - - - -
- -
- - - - - - - - - - - - - - \ No newline at end of file diff --git a/IoTGateway/Areas/BasicData/Views/DeviceVariable/SetValue.cshtml b/IoTGateway/Areas/BasicData/Views/DeviceVariable/SetValue.cshtml index 671bff7..0f38028 100644 --- a/IoTGateway/Areas/BasicData/Views/DeviceVariable/SetValue.cshtml +++ b/IoTGateway/Areas/BasicData/Views/DeviceVariable/SetValue.cshtml @@ -1,17 +1,26 @@ -@model IoTGateway.ViewModel.BasicData.DeviceVariableVMs.SetValueVM +@using IoTGateway.ViewModel.BasicData.DeviceVariableVMs +@model IoTGateway.ViewModel.BasicData.DeviceVariableVMs.SetValueVM @inject IStringLocalizer Localizer; - + - @Model.设备名/@Model.变量名 - 当前原始值:@Model.当前原始值======>当前计算值:@Model.当前计算值 - 类型:@Model.类型======状态:@Model.状态 - + @if (@Model.SetValues.Any()) + { + foreach (var setValue in @Model.SetValues) + { +
+ @setValue.DeviceName/@setValue.Name:【原值:@setValue.RawValue】=>【计算值:@setValue.Value】 +
+ +
+ + } + }
- +
diff --git a/IoTGateway/iotgateway.db b/IoTGateway/iotgateway.db index f66e24bd9345e10f51af4782a4e21bf5daace2ae..5727705d0c922262b772fbf6d0cf440055169a8f 100644 GIT binary patch delta 2553 zcma)8ZH!b`8NT87J!r#(44REz^N4-?+sOH1!tR-PyW4@cj zaYzucZH9OhJIHsaK%D#7b#2@C1g4l$ggrz_AEk>iUQE4;tBrslkv#LLC7K$M@fvh%X}oL zPmt?+c9PJLL@xX9Tuz0%j^Qyv<;&YZNv@V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