mirror of
https://gitee.com/iioter/iotgateway.git
synced 2024-12-02 03:38:01 +08:00
通过前端批量写入
This commit is contained in:
parent
149c621351
commit
bf5864cdd5
@ -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; }
|
||||
|
@ -21,7 +21,7 @@ namespace IoTGateway.ViewModel.BasicData.DeviceVariableVMs
|
||||
{
|
||||
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.Edit, Localizer["Sys.Edit"], "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 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<SetValue> SetValues { get; set; } = new();
|
||||
public string 设置结果 { get; set; }
|
||||
|
||||
public void Set()
|
||||
{
|
||||
try
|
||||
{
|
||||
var variable = DC.Set<DeviceVariable>().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<string, string> kv = new(0);
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
kv[ids[i]]=values[i];
|
||||
}
|
||||
|
||||
|
||||
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 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<string, object>() { { 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<DeviceVariable>().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<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 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; }
|
||||
}
|
||||
}
|
||||
|
@ -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<SetValueVM>();
|
||||
var vm = Wtm.CreateVM<SetValueVM>(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<SetValueVM>(Ids: ids);
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return PartialView(vm);
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,17 +1,26 @@
|
||||
@model IoTGateway.ViewModel.BasicData.DeviceVariableVMs.SetValueVM
|
||||
@using IoTGateway.ViewModel.BasicData.DeviceVariableVMs
|
||||
@model IoTGateway.ViewModel.BasicData.DeviceVariableVMs.SetValueVM
|
||||
@inject IStringLocalizer<Program> Localizer;
|
||||
|
||||
|
||||
<wt:form vm="@Model">
|
||||
<wt:form vm="@Model" Url="/BasicData/DeviceVariable/DoSetValue">
|
||||
<wt:row items-per-row="ItemsPerRowEnum.One">
|
||||
<wt:quote>@Model.设备名/@Model.变量名</wt:quote>
|
||||
<wt:quote>当前原始值:@Model.当前原始值======>当前计算值:@Model.当前计算值</wt:quote>
|
||||
<wt:quote>类型:@Model.类型======状态:@Model.状态</wt:quote>
|
||||
<wt:textbox field=设定原始值 />
|
||||
@if (@Model.SetValues.Any())
|
||||
{
|
||||
foreach (var setValue in @Model.SetValues)
|
||||
{
|
||||
<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 align="AlignEnum.Right">
|
||||
<wt:submitbutton text="下发" />
|
||||
<wt:submitbutton text="下发" />
|
||||
<wt:closebutton text="取消" />
|
||||
</wt:row>
|
||||
</wt:form>
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user