添加设备复制功能
This commit is contained in:
@@ -46,6 +46,63 @@ namespace ThingsGateway.Web.Foundation
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
[OperDesc("复制采集设备")]
|
||||
public async Task CopyDev(IEnumerable<CollectDevice> input)
|
||||
{
|
||||
var newId = Yitter.IdGenerator.YitIdHelper.NextId();
|
||||
var newDevs = input.Adapt<List<CollectDevice>>();
|
||||
newDevs.ForEach(a =>
|
||||
{
|
||||
a.Id = newId;
|
||||
a.Name = "Copy-" + a.Name + "-" + newId.ToString();
|
||||
});
|
||||
|
||||
var result = await InsertRangeAsync(newDevs);//添加数据
|
||||
_sysCacheService.Remove(ThingsGatewayCacheConst.Cache_CollectDevice, "");//cache删除
|
||||
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
[OperDesc("复制采集设备与变量")]
|
||||
public async Task CopyDevAndVar(IEnumerable<CollectDevice> input)
|
||||
{
|
||||
|
||||
using var serviceScope = _scopeFactory.CreateScope();
|
||||
var variableService = serviceScope.ServiceProvider.GetService<IVariableService>();
|
||||
List<CollectDeviceVariable> collectDeviceVariables = new();
|
||||
var newDevs = input.Adapt<List<CollectDevice>>();
|
||||
foreach (var item in newDevs)
|
||||
{
|
||||
var newId = YitIdHelper.NextId();
|
||||
var deviceVariables = await Context.Queryable<CollectDeviceVariable>().Where(a => a.DeviceId == item.Id).ToListAsync();
|
||||
deviceVariables.ForEach(b =>
|
||||
{
|
||||
b.Id = 0;
|
||||
b.DeviceId = newId;
|
||||
});
|
||||
collectDeviceVariables.AddRange(deviceVariables);
|
||||
item.Id = newId;
|
||||
item.Name = "Copy-" + item.Name + "-" + Yitter.IdGenerator.YitIdHelper.NextId().ToString();
|
||||
}
|
||||
|
||||
var result = await itenant.UseTranAsync(async () =>
|
||||
{
|
||||
await InsertRangeAsync(newDevs);//添加数据
|
||||
await Context.Insertable(collectDeviceVariables).ExecuteCommandAsync();//添加数据
|
||||
});
|
||||
|
||||
if(result.IsSuccess)
|
||||
{
|
||||
_sysCacheService.Remove(ThingsGatewayCacheConst.Cache_CollectDevice, "");//cache删除
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Oops.Oh(ErrorCodeEnum.A0003+ result.ErrorMessage);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public long? GetIdByName(string name)
|
||||
{
|
||||
|
@@ -9,6 +9,8 @@ namespace ThingsGateway.Web.Foundation
|
||||
public interface ICollectDeviceService : ITransient
|
||||
{
|
||||
Task Add(CollectDevice input);
|
||||
Task CopyDev(IEnumerable<CollectDevice> input);
|
||||
Task CopyDevAndVar(IEnumerable<CollectDevice> input);
|
||||
Task Delete(List<BaseIdInput> input);
|
||||
Task Edit(CollectDeviceEditInput input);
|
||||
Task<MemoryStream> ExportFile();
|
||||
|
@@ -9,6 +9,7 @@ namespace ThingsGateway.Web.Foundation
|
||||
public interface IUploadDeviceService : ITransient
|
||||
{
|
||||
Task Add(UploadDevice input);
|
||||
Task CopyDev(IEnumerable<UploadDevice> input);
|
||||
Task Delete(List<BaseIdInput> input);
|
||||
Task Edit(UploadDeviceEditInput input);
|
||||
Task<MemoryStream> ExportFile();
|
||||
|
@@ -44,6 +44,24 @@ namespace ThingsGateway.Web.Foundation
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
[OperDesc("复制上传设备")]
|
||||
public async Task CopyDev(IEnumerable<UploadDevice> input)
|
||||
{
|
||||
var newId = Yitter.IdGenerator.YitIdHelper.NextId();
|
||||
var newDevs = input.Adapt<List<UploadDevice>>();
|
||||
newDevs.ForEach(a =>
|
||||
{
|
||||
a.Id = newId;
|
||||
a.Name = "Copy-" + a.Name + "-" + newId.ToString();
|
||||
});
|
||||
|
||||
var result = await InsertRangeAsync(newDevs);//添加数据
|
||||
_sysCacheService.Remove(ThingsGatewayCacheConst.Cache_UploadDevice, "");//cache删除
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public long? GetIdByName(string name)
|
||||
{
|
||||
|
@@ -17,12 +17,12 @@
|
||||
|
||||
<MRow>
|
||||
<MCol Md=2 Cols="12">
|
||||
<MCard Class="ma-2" Style="height:100%">
|
||||
<MCard Class="ma-2" Style="height: calc(100vh - 200px)">
|
||||
<MCardTitle>
|
||||
<MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="mx-2 my-1" @bind-Value="_searchName"
|
||||
Outlined Label=@typeof(CollectDevice).GetDescription(nameof(CollectDevice.DeviceGroup)) />
|
||||
</MCardTitle>
|
||||
<MTreeview Dense TItem="string" TKey="string" ActiveChanged=@(async a=>
|
||||
<MTreeview Style="height: calc(100vh - 320px);overflow-y:auto" Dense TItem="string" TKey="string" ActiveChanged=@(async a=>
|
||||
{
|
||||
if(search.DeviceGroup!=a.FirstOrDefault())
|
||||
{
|
||||
@@ -56,7 +56,24 @@
|
||||
Outlined Label=@context.Description(x => x.PluginName) />
|
||||
</SearchTemplate>
|
||||
<OtherToolbarTemplate>
|
||||
|
||||
<MMenu OffsetY Context="menu" >
|
||||
<ActivatorContent>
|
||||
<MButton @attributes="@menu.Attrs" Color="primary"
|
||||
Icon="@MasaBlazor.Breakpoint.SmAndDown"
|
||||
Class="my-1 mx-2 "
|
||||
>
|
||||
@T("复制")
|
||||
<AppChevronDown></AppChevronDown>
|
||||
</MButton>
|
||||
</ActivatorContent>
|
||||
<ChildContent>
|
||||
<MList>
|
||||
<MListItem OnClick="()=>CopyDevice(context)"> @T("复制设备") </MListItem>
|
||||
<MListItem OnClick="()=>CopyDevAndVar(context)"> @T("复制设备及设备下变量") </MListItem>
|
||||
</MList>
|
||||
|
||||
</ChildContent>
|
||||
</MMenu>
|
||||
<MButton Class="my-1 mx-2" Loading=@isDownExport OnClick=DownDeviceExport Color="primary">
|
||||
@T("导出")
|
||||
</MButton>
|
||||
@@ -104,7 +121,33 @@
|
||||
|
||||
<ImportExcel @ref=ImportExcel Import="SaveDeviceImport" Preview="DeviceImport" Template="DownTemplate" />
|
||||
|
||||
@code{
|
||||
async Task CopyDevice(IEnumerable<CollectDevice> data)
|
||||
{
|
||||
if(data.Count()==0)
|
||||
{
|
||||
await PopupService.EnqueueSnackbarAsync(@T("需选择一项或多项"), AlertTypes.Warning);
|
||||
return;
|
||||
}
|
||||
await CollectDeviceService.CopyDev(data);
|
||||
await datatableQuery();
|
||||
await PopupService.EnqueueSnackbarAsync("复制成功", AlertTypes.Success);
|
||||
|
||||
}
|
||||
async Task CopyDevAndVar(IEnumerable<CollectDevice> data)
|
||||
{
|
||||
|
||||
if (data.Count() == 0)
|
||||
{
|
||||
await PopupService.EnqueueSnackbarAsync(@T("需选择一项或多项"), AlertTypes.Warning);
|
||||
return;
|
||||
}
|
||||
await CollectDeviceService.CopyDevAndVar(data);
|
||||
await datatableQuery();
|
||||
await PopupService.EnqueueSnackbarAsync("复制成功", AlertTypes.Success);
|
||||
|
||||
}
|
||||
}
|
||||
@code {
|
||||
string _searchName;
|
||||
List<string> _deviceGroups = new();
|
||||
|
@@ -18,12 +18,12 @@
|
||||
|
||||
<MRow>
|
||||
<MCol Md=2 Cols="12">
|
||||
<MCard Class="ma-2" Style="height:100%">
|
||||
<MCard Class="ma-2" Style="height: calc(100vh - 200px)">
|
||||
<MCardTitle>
|
||||
<MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="mx-2 my-1" @bind-Value="_searchName"
|
||||
Outlined Label=@typeof(CollectDevice).GetDescription(nameof(CollectDevice.DeviceGroup)) />
|
||||
</MCardTitle>
|
||||
<MTreeview Dense TItem="DeviceTree" TKey="string" OpenOnClick ActiveChanged=@(async a=>
|
||||
<MTreeview Style="height: calc(100vh - 320px);overflow-y:auto" Dense TItem="DeviceTree" TKey="string" OpenOnClick ActiveChanged=@(async a=>
|
||||
{
|
||||
if(search.DeviceName!=a.FirstOrDefault())
|
||||
{
|
||||
|
@@ -17,12 +17,12 @@
|
||||
|
||||
<MRow>
|
||||
<MCol Md=2 Cols="12">
|
||||
<MCard Class="ma-2" Style="height:100%">
|
||||
<MCard Class="ma-2" Style="height: calc(100vh - 200px)">
|
||||
<MCardTitle>
|
||||
<MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="mx-2 my-1" @bind-Value="_searchName"
|
||||
Outlined Label=@typeof(CollectDevice).GetDescription(nameof(CollectDevice.DeviceGroup)) />
|
||||
</MCardTitle>
|
||||
<MTreeview Dense TItem="string" TKey="string" ActiveChanged=@(async a=>
|
||||
<MTreeview Style="height: calc(100vh - 320px);overflow-y:auto" Dense TItem="string" TKey="string" ActiveChanged=@(async a=>
|
||||
{
|
||||
if(search.DeviceGroup!=a.FirstOrDefault())
|
||||
{
|
||||
@@ -56,7 +56,22 @@
|
||||
Outlined Label=@context.Description(x => x.PluginName) />
|
||||
</SearchTemplate>
|
||||
<OtherToolbarTemplate>
|
||||
<MMenu OffsetY Context="menu">
|
||||
<ActivatorContent>
|
||||
<MButton @attributes="@menu.Attrs" Color="primary"
|
||||
Icon="@MasaBlazor.Breakpoint.SmAndDown"
|
||||
Class="my-1 mx-2 ">
|
||||
@T("复制")
|
||||
<AppChevronDown></AppChevronDown>
|
||||
</MButton>
|
||||
</ActivatorContent>
|
||||
<ChildContent>
|
||||
<MList>
|
||||
<MListItem OnClick="()=>CopyDevice(context)"> @T("复制设备") </MListItem>
|
||||
</MList>
|
||||
|
||||
</ChildContent>
|
||||
</MMenu>
|
||||
<MButton Class="my-1 mx-2" Loading=@isDownExport OnClick=DownDeviceExport Color="primary">
|
||||
@T("导出")
|
||||
</MButton>
|
||||
@@ -104,7 +119,20 @@
|
||||
|
||||
<ImportExcel @ref=ImportExcel Import="SaveDeviceImport" Preview="DeviceImport" Template="DownTemplate" />
|
||||
|
||||
@code {
|
||||
async Task CopyDevice(IEnumerable<UploadDevice> data)
|
||||
{
|
||||
if (data.Count() == 0)
|
||||
{
|
||||
await PopupService.EnqueueSnackbarAsync(@T("需选择一项或多项"), AlertTypes.Warning);
|
||||
return;
|
||||
}
|
||||
await UploadDeviceService.CopyDev(data);
|
||||
await datatableQuery();
|
||||
await PopupService.EnqueueSnackbarAsync("复制成功", AlertTypes.Success);
|
||||
|
||||
}
|
||||
}
|
||||
@code {
|
||||
string _searchName;
|
||||
List<string> _deviceGroups = new();
|
||||
|
Reference in New Issue
Block a user