通过前端批量写入
This commit is contained in:
parent
149c621351
commit
bf5864cdd5
@ -28,6 +28,7 @@ namespace IoTGateway.Model
|
|||||||
[Display(Name = "权限")]
|
[Display(Name = "权限")]
|
||||||
public ProtectTypeEnum ProtectType { get; set; }
|
public ProtectTypeEnum ProtectType { get; set; }
|
||||||
|
|
||||||
|
[Newtonsoft.Json.JsonIgnore]
|
||||||
public Device Device { get; set; }
|
public Device Device { get; set; }
|
||||||
[Display(Name = "设备")]
|
[Display(Name = "设备")]
|
||||||
public Guid? DeviceId { get; set; }
|
public Guid? DeviceId { get; set; }
|
||||||
|
@ -21,7 +21,7 @@ namespace IoTGateway.ViewModel.BasicData.DeviceVariableVMs
|
|||||||
{
|
{
|
||||||
return new List<GridAction>
|
return new List<GridAction>
|
||||||
{
|
{
|
||||||
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.Create, Localizer["Sys.Create"],"BasicData", dialogWidth: 800),
|
||||||
this.MakeStandardAction("DeviceVariable", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "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),
|
this.MakeStandardAction("DeviceVariable", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "BasicData", dialogWidth: 800),
|
||||||
|
@ -7,80 +7,139 @@ using WalkingTec.Mvvm.Core;
|
|||||||
using WalkingTec.Mvvm.Core.Extensions;
|
using WalkingTec.Mvvm.Core.Extensions;
|
||||||
using IoTGateway.Model;
|
using IoTGateway.Model;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Microsoft.Extensions.Primitives;
|
||||||
|
using System.Runtime.Intrinsics.Arm;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace IoTGateway.ViewModel.BasicData.DeviceVariableVMs
|
namespace IoTGateway.ViewModel.BasicData.DeviceVariableVMs
|
||||||
{
|
{
|
||||||
public class SetValueVM : BaseVM
|
public class SetValueVM : BaseVM
|
||||||
{
|
{
|
||||||
public string 设备名 { get; set; }
|
public List<SetValue> SetValues { get; set; } = new();
|
||||||
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 string 设置结果 { get; set; }
|
||||||
|
|
||||||
public void Set()
|
public void Set()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var variable = DC.Set<DeviceVariable>().Where(x => x.ID == Guid.Parse(FC["id"].ToString())).AsNoTracking().Include(x => x.Device).FirstOrDefault();
|
var ids = (StringValues)FC["setValue.ID[]"];
|
||||||
设备名 = variable.Device.DeviceName;
|
var values= (StringValues)FC["setValue.SetRawValue[]"];
|
||||||
变量名 = variable.Name;
|
Dictionary<string, string> kv = new(0);
|
||||||
类型 = variable.DataType.GetEnumDisplayName();
|
for (int i = 0; i < ids.Count; i++)
|
||||||
|
|
||||||
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();
|
kv[ids[i]]=values[i];
|
||||||
当前计算值 = dapThread.DeviceValues[variable.ID].CookedValue?.ToString();
|
|
||||||
状态 = dapThread.DeviceValues[variable.ID].StatusType.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (variable == null || variable.Device == null || dapThread == null)
|
|
||||||
设置结果 = "设置失败,找不到设备(变量)";
|
|
||||||
|
|
||||||
else
|
var setValues = JsonConvert.DeserializeObject<List<SetValue>>(
|
||||||
|
JsonConvert.SerializeObject(DC.Set<DeviceVariable>()
|
||||||
|
.Where(x => ids.Contains(x.ID.ToString().ToLower())).AsNoTracking()
|
||||||
|
.OrderBy(x => x.DeviceId).ToList()));
|
||||||
|
|
||||||
|
var deviceService = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
|
||||||
|
|
||||||
|
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();
|
||||||
|
variable.SetRawValue = kv[variable.ID.ToString()];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PluginInterface.RpcRequest request = new PluginInterface.RpcRequest()
|
PluginInterface.RpcRequest request = new PluginInterface.RpcRequest()
|
||||||
{
|
{
|
||||||
RequestId = Guid.NewGuid().ToString(),
|
RequestId = Guid.NewGuid().ToString(),
|
||||||
DeviceName = variable.Device.DeviceName,
|
DeviceName = deviceName,
|
||||||
Method = "write",
|
Method = "write",
|
||||||
Params = new Dictionary<string, object>() { { variable.Name, 设定原始值 } }
|
Params = deviceVariables.ToDictionary(x => x.Name, x => x.SetRawValue)
|
||||||
};
|
};
|
||||||
dapThread.MyMqttClient_OnExcRpc(this, request);
|
dapThread.MyMqttClient_OnExcRpc(this, request);
|
||||||
设置结果 = "设置成功";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
设置结果 = "设置成功";
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
||||||
设置结果 = $"设置失败,{ex}";
|
设置结果 = $"设置失败,{ex}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void InitVM()
|
protected override void InitVM()
|
||||||
{
|
{
|
||||||
var variable = DC.Set<DeviceVariable>().Where(x => x.ID == Guid.Parse(FC["id"].ToString())).AsNoTracking().Include(x => x.Device).FirstOrDefault();
|
StringValues ids;
|
||||||
设备名 = variable.Device.DeviceName;
|
if (FC.ContainsKey("setValue.ID[]"))
|
||||||
变量名 = variable.Name;
|
ids = (StringValues)FC["setValue.ID[]"];
|
||||||
类型 = variable.DataType.GetEnumDisplayName();
|
else
|
||||||
|
ids = (StringValues)FC["Ids[]"];
|
||||||
|
|
||||||
|
var setValues = JsonConvert.DeserializeObject<List<SetValue>>(
|
||||||
|
JsonConvert.SerializeObject(DC.Set<DeviceVariable>()
|
||||||
|
.Where(x => ids.Contains(x.ID.ToString().ToLower())).AsNoTracking()
|
||||||
|
.OrderBy(x => x.DeviceId).ToList()));
|
||||||
|
|
||||||
var deviceService = Wtm.ServiceProvider.GetService(typeof(DeviceService)) as DeviceService;
|
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))
|
if (setValues != null)
|
||||||
|
foreach (var deviceVariables in setValues.GroupBy(x => x.DeviceId))
|
||||||
{
|
{
|
||||||
当前原始值 = dapThread.DeviceValues[variable.ID].Value?.ToString();
|
if (deviceService != null)
|
||||||
当前计算值 = dapThread.DeviceValues[variable.ID].CookedValue?.ToString();
|
{
|
||||||
状态 = dapThread.DeviceValues[variable.ID].StatusType.ToString();
|
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();
|
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; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ using WalkingTec.Mvvm.Core;
|
|||||||
using WalkingTec.Mvvm.Mvc;
|
using WalkingTec.Mvvm.Mvc;
|
||||||
using WalkingTec.Mvvm.Core.Extensions;
|
using WalkingTec.Mvvm.Core.Extensions;
|
||||||
using IoTGateway.ViewModel.BasicData.DeviceVariableVMs;
|
using IoTGateway.ViewModel.BasicData.DeviceVariableVMs;
|
||||||
|
using Opc.Ua.Security.Certificates;
|
||||||
|
|
||||||
namespace IoTGateway.Controllers
|
namespace IoTGateway.Controllers
|
||||||
{
|
{
|
||||||
@ -216,16 +217,21 @@ namespace IoTGateway.Controllers
|
|||||||
}
|
}
|
||||||
#region 下发写入
|
#region 下发写入
|
||||||
[ActionDescription("下发写入")]
|
[ActionDescription("下发写入")]
|
||||||
public ActionResult SetValue()
|
[HttpPost]
|
||||||
|
public ActionResult SetValue(string[] IDs)
|
||||||
{
|
{
|
||||||
var vm = Wtm.CreateVM<SetValueVM>();
|
var vm = Wtm.CreateVM<SetValueVM>(Ids: IDs);
|
||||||
return PartialView(vm);
|
return PartialView(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ActionDescription("下发写入")]
|
[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<SetValueVM>(Ids: ids);
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
{
|
{
|
||||||
return PartialView(vm);
|
return PartialView(vm);
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,13 +1,22 @@
|
|||||||
@model IoTGateway.ViewModel.BasicData.DeviceVariableVMs.SetValueVM
|
@using IoTGateway.ViewModel.BasicData.DeviceVariableVMs
|
||||||
|
@model IoTGateway.ViewModel.BasicData.DeviceVariableVMs.SetValueVM
|
||||||
@inject IStringLocalizer<Program> Localizer;
|
@inject IStringLocalizer<Program> Localizer;
|
||||||
|
|
||||||
|
|
||||||
<wt:form vm="@Model">
|
<wt:form vm="@Model" Url="/BasicData/DeviceVariable/DoSetValue">
|
||||||
<wt:row items-per-row="ItemsPerRowEnum.One">
|
<wt:row items-per-row="ItemsPerRowEnum.One">
|
||||||
<wt:quote>@Model.设备名/@Model.变量名</wt:quote>
|
@if (@Model.SetValues.Any())
|
||||||
<wt:quote>当前原始值:@Model.当前原始值======>当前计算值:@Model.当前计算值</wt:quote>
|
{
|
||||||
<wt:quote>类型:@Model.类型======状态:@Model.状态</wt:quote>
|
foreach (var setValue in @Model.SetValues)
|
||||||
<wt:textbox field=设定原始值 />
|
{
|
||||||
|
<hr class="layui-border-blue">
|
||||||
|
<wt:quote>@setValue.DeviceName/@setValue.Name:【原值:@setValue.RawValue】=>【计算值:@setValue.Value】</wt:quote>
|
||||||
|
<div style="display: none">
|
||||||
|
<wt:textbox field=@setValue.ID />
|
||||||
|
</div>
|
||||||
|
<wt:textbox field=@setValue.SetRawValue/>
|
||||||
|
}
|
||||||
|
}
|
||||||
</wt:row>
|
</wt:row>
|
||||||
|
|
||||||
<wt:row align="AlignEnum.Right">
|
<wt:row align="AlignEnum.Right">
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user