mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-21 19:14:30 +08:00
10.10.5
This commit is contained in:
@@ -213,12 +213,18 @@ public static class AppServiceCollectionExtensions
|
||||
// 缓存
|
||||
if (cacheOptions.CacheType == CacheType.Memory)
|
||||
{
|
||||
services.AddSingleton<ICache, MemoryCache>(a => new()
|
||||
services.AddSingleton<ICache>(a =>
|
||||
{
|
||||
Cache.Default = new MemoryCache()
|
||||
{
|
||||
Capacity = cacheOptions.MemoryCacheOptions.Capacity,
|
||||
Expire = cacheOptions.MemoryCacheOptions.Expire,
|
||||
Period = cacheOptions.MemoryCacheOptions.Period
|
||||
});
|
||||
};
|
||||
return Cache.Default;
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
else if (cacheOptions.CacheType == CacheType.Redis)
|
||||
{
|
||||
|
@@ -86,7 +86,7 @@ namespace ThingsGateway.SqlSugar
|
||||
|
||||
public void Add(string key, V value, int cacheDurationInSeconds)
|
||||
{
|
||||
Check.ThrowNotSupportedException("ReflectionInoCache.Add(string key, V value, int cacheDurationInSeconds)");
|
||||
this.InstanceCache.Add<V>(key, value, cacheDurationInSeconds);
|
||||
}
|
||||
|
||||
public void Remove(string key)
|
||||
@@ -109,7 +109,8 @@ namespace ThingsGateway.SqlSugar
|
||||
|
||||
public V GetOrCreate(string cacheKey, Func<V> create)
|
||||
{
|
||||
return InstanceCache.GetOrAdd<V>(cacheKey, (a) => create());
|
||||
return InstanceCache.GetOrAdd<V>(cacheKey, (a) =>
|
||||
create());
|
||||
}
|
||||
}
|
||||
public static class ReflectionInoHelper
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<PluginVersion>10.10.2</PluginVersion>
|
||||
<ProPluginVersion>10.10.2</ProPluginVersion>
|
||||
<DefaultVersion>10.10.4</DefaultVersion>
|
||||
<DefaultVersion>10.10.5</DefaultVersion>
|
||||
<AuthenticationVersion>2.9.29</AuthenticationVersion>
|
||||
<SourceGeneratorVersion>10.9.29</SourceGeneratorVersion>
|
||||
<NET8Version>8.0.18</NET8Version>
|
||||
|
@@ -27,6 +27,7 @@ public class OtherChannel : SetupConfigObject, IClientChannel
|
||||
public OtherChannel(IChannelOptions channelOptions)
|
||||
{
|
||||
ChannelOptions = channelOptions;
|
||||
ResetSign();
|
||||
}
|
||||
|
||||
public override TouchSocketConfig Config => base.Config ?? ChannelOptions.Config;
|
||||
@@ -39,7 +40,7 @@ public class OtherChannel : SetupConfigObject, IClientChannel
|
||||
pool?.SafeDispose();
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public ChannelReceivedEventHandler ChannelReceived { get; set; } = new();
|
||||
public ChannelReceivedEventHandler ChannelReceived { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IChannelOptions ChannelOptions { get; }
|
||||
@@ -51,16 +52,16 @@ public class OtherChannel : SetupConfigObject, IClientChannel
|
||||
public ConcurrentList<IDevice> Collects { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Started { get; set; } = new();
|
||||
public ChannelEventHandler Started { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Starting { get; set; } = new();
|
||||
public ChannelEventHandler Starting { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Stoped { get; set; } = new();
|
||||
public ChannelEventHandler Stoped { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Stoping { get; set; } = new();
|
||||
public ChannelEventHandler Stoping { get; } = new();
|
||||
/// <summary>
|
||||
/// 等待池
|
||||
/// </summary>
|
||||
|
@@ -24,6 +24,7 @@ public class SerialPortChannel : SerialPortClient, IClientChannel
|
||||
public SerialPortChannel(IChannelOptions channelOptions)
|
||||
{
|
||||
ChannelOptions = channelOptions;
|
||||
ResetSign();
|
||||
}
|
||||
|
||||
public override TouchSocketConfig Config => base.Config ?? ChannelOptions.Config;
|
||||
@@ -36,7 +37,7 @@ public class SerialPortChannel : SerialPortClient, IClientChannel
|
||||
pool?.SafeDispose();
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public ChannelReceivedEventHandler ChannelReceived { get; set; } = new();
|
||||
public ChannelReceivedEventHandler ChannelReceived { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IChannelOptions ChannelOptions { get; }
|
||||
@@ -51,16 +52,16 @@ public class SerialPortChannel : SerialPortClient, IClientChannel
|
||||
public DataHandlingAdapter ReadOnlyDataHandlingAdapter => ProtectedDataHandlingAdapter;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Started { get; set; } = new();
|
||||
public ChannelEventHandler Started { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Starting { get; set; } = new();
|
||||
public ChannelEventHandler Starting { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Stoped { get; set; } = new();
|
||||
public ChannelEventHandler Stoped { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Stoping { get; set; } = new();
|
||||
public ChannelEventHandler Stoping { get; } = new();
|
||||
/// <summary>
|
||||
/// 等待池
|
||||
/// </summary>
|
||||
|
@@ -23,7 +23,7 @@ public class TcpClientChannel : TcpClient, IClientChannel
|
||||
public TcpClientChannel(IChannelOptions channelOptions)
|
||||
{
|
||||
ChannelOptions = channelOptions;
|
||||
|
||||
ResetSign();
|
||||
}
|
||||
public override TouchSocketConfig Config => base.Config ?? ChannelOptions.Config;
|
||||
public void ResetSign(int minSign = 0, int maxSign = ushort.MaxValue)
|
||||
|
@@ -180,7 +180,7 @@ public class TcpServiceChannel<TClient> : TcpServiceChannelBase<TClient>, IChann
|
||||
public override TouchSocketConfig Config => base.Config ?? ChannelOptions.Config;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelReceivedEventHandler ChannelReceived { get; set; } = new();
|
||||
public ChannelReceivedEventHandler ChannelReceived { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IChannelOptions ChannelOptions { get; }
|
||||
@@ -192,15 +192,15 @@ public class TcpServiceChannel<TClient> : TcpServiceChannelBase<TClient>, IChann
|
||||
public bool Online => ServerState == ServerState.Running;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Started { get; set; } = new();
|
||||
public ChannelEventHandler Started { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Starting { get; set; } = new();
|
||||
public ChannelEventHandler Starting { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Stoped { get; set; } = new();
|
||||
public ChannelEventHandler Stoped { get; } = new();
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Stoping { get; set; } = new();
|
||||
public ChannelEventHandler Stoping { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task<Result> CloseAsync(string msg, CancellationToken token)
|
||||
@@ -228,8 +228,8 @@ public class TcpServiceChannel<TClient> : TcpServiceChannelBase<TClient>, IChann
|
||||
data.ResetSign(MinSign, MaxSign);
|
||||
return data;
|
||||
}
|
||||
public int MaxSign { get; set; }
|
||||
public int MinSign { get; set; }
|
||||
public int MaxSign { get; private set; } = 0;
|
||||
public int MinSign { get; private set; } = ushort.MaxValue;
|
||||
public void ResetSign(int minSign = 0, int maxSign = ushort.MaxValue)
|
||||
{
|
||||
MinSign = minSign;
|
||||
|
@@ -32,7 +32,7 @@ public class TcpSessionClientChannel : TcpSessionClient, IClientChannel
|
||||
pool?.SafeDispose();
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public ChannelReceivedEventHandler ChannelReceived { get; set; } = new();
|
||||
public ChannelReceivedEventHandler ChannelReceived { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IChannelOptions ChannelOptions { get; internal set; }
|
||||
@@ -47,15 +47,15 @@ public class TcpSessionClientChannel : TcpSessionClient, IClientChannel
|
||||
public DataHandlingAdapter ReadOnlyDataHandlingAdapter => DataHandlingAdapter;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Started { get; set; } = new();
|
||||
public ChannelEventHandler Started { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Starting { get; set; } = new();
|
||||
public ChannelEventHandler Starting { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Stoped { get; set; } = new();
|
||||
public ChannelEventHandler Stoped { get; } = new();
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Stoping { get; set; } = new();
|
||||
public ChannelEventHandler Stoping { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 等待池
|
||||
|
@@ -25,6 +25,7 @@ public class UdpSessionChannel : UdpSession, IClientChannel
|
||||
public UdpSessionChannel(IChannelOptions channelOptions)
|
||||
{
|
||||
ChannelOptions = channelOptions;
|
||||
ResetSign();
|
||||
}
|
||||
public override TouchSocketConfig Config => base.Config ?? ChannelOptions.Config;
|
||||
|
||||
@@ -37,7 +38,7 @@ public class UdpSessionChannel : UdpSession, IClientChannel
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelReceivedEventHandler ChannelReceived { get; set; } = new();
|
||||
public ChannelReceivedEventHandler ChannelReceived { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IChannelOptions ChannelOptions { get; }
|
||||
@@ -55,15 +56,15 @@ public class UdpSessionChannel : UdpSession, IClientChannel
|
||||
public DataHandlingAdapter ReadOnlyDataHandlingAdapter => DataHandlingAdapter;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Started { get; set; } = new();
|
||||
public ChannelEventHandler Started { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Starting { get; set; } = new();
|
||||
public ChannelEventHandler Starting { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Stoped { get; set; } = new();
|
||||
public ChannelEventHandler Stoped { get; } = new();
|
||||
/// <inheritdoc/>
|
||||
public ChannelEventHandler Stoping { get; set; } = new();
|
||||
public ChannelEventHandler Stoping { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 等待池
|
||||
|
@@ -16,20 +16,20 @@ namespace ThingsGateway.Gateway.Application;
|
||||
[ThingsGateway.DependencyInjection.SuppressSniffer]
|
||||
public static class ThingsGatewayCacheConst
|
||||
{
|
||||
/// <summary>
|
||||
/// 通道
|
||||
/// </summary>
|
||||
public const string Cache_Channel = $"{Cache_Prefix}Cache_Channel:List";
|
||||
///// <summary>
|
||||
///// 通道
|
||||
///// </summary>
|
||||
//public const string Cache_Channel = $"{Cache_Prefix}Cache_Channel:List";
|
||||
|
||||
/// <summary>
|
||||
/// device
|
||||
/// </summary>
|
||||
public const string Cache_Device = $"{Cache_Prefix}Cache_Device:List";
|
||||
///// <summary>
|
||||
///// device
|
||||
///// </summary>
|
||||
//public const string Cache_Device = $"{Cache_Prefix}Cache_Device:List";
|
||||
|
||||
/// <summary>
|
||||
/// variable
|
||||
/// </summary>
|
||||
public const string Cache_Variable = $"{Cache_Prefix}Cache_Variable:IdNameList";
|
||||
///// <summary>
|
||||
///// variable
|
||||
///// </summary>
|
||||
//public const string Cache_Variable = $"{Cache_Prefix}Cache_Variable:IdNameList";
|
||||
|
||||
/// <summary>
|
||||
/// 前缀
|
||||
|
@@ -27,7 +27,7 @@ public class LogJob : IJob
|
||||
await DeleteRpcLog(rpcLogDaysdaysAgo, stoppingToken).ConfigureAwait(false);
|
||||
await DeleteBackendLog(backendLogdaysAgo, stoppingToken).ConfigureAwait(false);
|
||||
await DeleteTextLog(stoppingToken).ConfigureAwait(false);
|
||||
await DeleteLocalDB(stoppingToken).ConfigureAwait(false);
|
||||
DeleteLocalDB(stoppingToken);
|
||||
}
|
||||
|
||||
private static async Task DeleteRpcLog(int daysAgo, CancellationToken stoppingToken)
|
||||
@@ -49,8 +49,8 @@ public class LogJob : IJob
|
||||
//网关通道日志以通道id命名
|
||||
var channelService = App.RootServices.GetService<IChannelService>();
|
||||
var deviceService = App.RootServices.GetService<IDeviceService>();
|
||||
var channelNames = (await channelService.GetAllAsync().ConfigureAwait(false)).Select(a => a.Name.ToString()).ToHashSet();
|
||||
var deviceNames = (await deviceService.GetAllAsync().ConfigureAwait(false)).Select(a => a.Name.ToString()).ToHashSet();
|
||||
var channelNames = (GlobalData.Channels.Keys).ToHashSet();
|
||||
var deviceNames = (GlobalData.Devices.Keys).ToHashSet();
|
||||
var channelBaseDir = LoggerExtensions.GetChannelLogBasePath();
|
||||
Directory.CreateDirectory(channelBaseDir);
|
||||
var deviceBaseDir = LoggerExtensions.GetDeviceLogBasePath();
|
||||
@@ -112,10 +112,9 @@ public class LogJob : IJob
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteLocalDB(CancellationToken stoppingToken)
|
||||
public void DeleteLocalDB(CancellationToken stoppingToken)
|
||||
{
|
||||
var deviceService = App.RootServices.GetService<IDeviceService>();
|
||||
var data = (await deviceService.GetAllAsync().ConfigureAwait(false)).Select(a => a.Name).ToHashSet();
|
||||
var data = (GlobalData.Devices.Keys).ToHashSet();
|
||||
var dir = CacheDBUtil.GetCacheFileBasePath();
|
||||
string[] dirs = Directory.GetDirectories(dir);
|
||||
foreach (var item in dirs)
|
||||
|
@@ -259,12 +259,12 @@ public class ChannelRuntimeService : IChannelRuntimeService
|
||||
try
|
||||
{
|
||||
await WaitLock.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
var channelIds = GlobalData.IdChannels.Keys.ToList();
|
||||
//网关启动时,获取所有通道
|
||||
var newChannelRuntimes = (await GlobalData.ChannelService.GetAllAsync().ConfigureAwait(false)).Where(a => ids.Contains(a.Id) || !GlobalData.IdChannels.ContainsKey(a.Id)).AdaptListChannelRuntime();
|
||||
var newChannelRuntimes = (await GlobalData.ChannelService.GetFromDBAsync((a => ids.Contains(a.Id) || !channelIds.Contains(a.Id))).ConfigureAwait(false)).AdaptListChannelRuntime();
|
||||
|
||||
var chanelIds = newChannelRuntimes.Select(a => a.Id).ToHashSet();
|
||||
var newDeviceRuntimes = (await GlobalData.DeviceService.GetAllAsync().ConfigureAwait(false)).Where(a => chanelIds.Contains(a.ChannelId)).AdaptListDeviceRuntime();
|
||||
var newDeviceRuntimes = (await GlobalData.DeviceService.GetFromDBAsync((a => chanelIds.Contains(a.ChannelId))).ConfigureAwait(false)).AdaptListDeviceRuntime();
|
||||
|
||||
await RuntimeServiceHelper.InitAsync(newChannelRuntimes, newDeviceRuntimes, _logger).ConfigureAwait(false);
|
||||
|
||||
|
@@ -16,6 +16,7 @@ using MiniExcelLibs;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
@@ -225,23 +226,20 @@ internal sealed class ChannelService : BaseService<Channel>, IChannelService
|
||||
/// <inheritdoc />
|
||||
public void DeleteChannelFromCache()
|
||||
{
|
||||
App.CacheService.Remove(ThingsGatewayCacheConst.Cache_Channel);//删除通道缓存
|
||||
//App.CacheService.Remove(ThingsGatewayCacheConst.Cache_Channel);//删除通道缓存
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 从缓存/数据库获取全部信息
|
||||
/// </summary>
|
||||
/// <returns>列表</returns>
|
||||
public async Task<List<Channel>> GetAllAsync(SqlSugarClient db = null)
|
||||
{
|
||||
var key = ThingsGatewayCacheConst.Cache_Channel;
|
||||
var channels = App.CacheService.Get<List<Channel>>(key);
|
||||
if (channels == null)
|
||||
public async Task<List<Channel>> GetFromDBAsync(Expression<Func<Channel, bool>> expression = null, SqlSugarClient db = null)
|
||||
{
|
||||
|
||||
db ??= GetDB();
|
||||
channels = await db.Queryable<Channel>().OrderBy(a => a.Id).ToListAsync().ConfigureAwait(false);
|
||||
App.CacheService.Set(key, channels);
|
||||
}
|
||||
var channels = await db.Queryable<Channel>().WhereIF(expression != null, expression).OrderBy(a => a.Id).ToListAsync().ConfigureAwait(false);
|
||||
return channels;
|
||||
}
|
||||
|
||||
@@ -263,7 +261,7 @@ internal sealed class ChannelService : BaseService<Channel>, IChannelService
|
||||
if (exportFilter.PluginType != null)
|
||||
{
|
||||
var pluginInfo = GlobalData.PluginService.GetList(exportFilter.PluginType).Select(a => a.FullName).ToHashSet();
|
||||
channel = (await GetAllAsync().ConfigureAwait(false)).Where(a => pluginInfo.Contains(a.PluginName)).Select(a => a.Id).ToHashSet();
|
||||
channel = GlobalData.IdChannels.Where(a => pluginInfo.Contains(a.Value.PluginName)).Select(a => a.Value.Id).ToHashSet();
|
||||
}
|
||||
var dataScope = await GlobalData.SysUserService.GetCurrentUserDataScopeAsync().ConfigureAwait(false);
|
||||
var whereQuery = (ISugarQueryable<Channel> a) => a
|
||||
@@ -285,7 +283,7 @@ internal sealed class ChannelService : BaseService<Channel>, IChannelService
|
||||
[OperDesc("SaveChannel", localizerType: typeof(Channel))]
|
||||
public async Task<bool> SaveChannelAsync(Channel input, ItemChangedType type)
|
||||
{
|
||||
if ((await GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Name).TryGetValue(input.Name, out var channel))
|
||||
if (GlobalData.Channels.TryGetValue(input.Name, out var channel))
|
||||
{
|
||||
if (channel.Id != input.Id)
|
||||
{
|
||||
@@ -409,7 +407,7 @@ internal sealed class ChannelService : BaseService<Channel>, IChannelService
|
||||
{
|
||||
var dataScope = await GlobalData.SysUserService.GetCurrentUserDataScopeAsync().ConfigureAwait(false);
|
||||
var sheetNames = MiniExcel.GetSheetNames(path);
|
||||
var channelDicts = (await GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Name);
|
||||
var channelDicts = GlobalData.Channels;
|
||||
//导入检验结果
|
||||
Dictionary<string, ImportPreviewOutputBase> ImportPreviews = new();
|
||||
//设备页
|
||||
@@ -429,7 +427,7 @@ internal sealed class ChannelService : BaseService<Channel>, IChannelService
|
||||
}
|
||||
}
|
||||
|
||||
public void SetChannelData(HashSet<long>? dataScope, Dictionary<string, Channel> channelDicts, Dictionary<string, ImportPreviewOutputBase> ImportPreviews, string sheetName, IEnumerable<IDictionary<string, object>> rows)
|
||||
public void SetChannelData(HashSet<long>? dataScope, IReadOnlyDictionary<string, ChannelRuntime> channelDicts, Dictionary<string, ImportPreviewOutputBase> ImportPreviews, string sheetName, IEnumerable<IDictionary<string, object>> rows)
|
||||
{
|
||||
#region sheet
|
||||
|
||||
|
@@ -127,7 +127,7 @@ public static class ChannelServiceHelpers
|
||||
public static async Task<Dictionary<string, ImportPreviewOutputBase>> ImportAsync(USheetDatas uSheetDatas)
|
||||
{
|
||||
var dataScope = await GlobalData.SysUserService.GetCurrentUserDataScopeAsync().ConfigureAwait(false);
|
||||
var channelDicts = (await GlobalData.ChannelService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Name);
|
||||
var channelDicts = GlobalData.Channels;
|
||||
//导入检验结果
|
||||
Dictionary<string, ImportPreviewOutputBase> ImportPreviews = new();
|
||||
//设备页
|
||||
|
@@ -12,6 +12,8 @@ using BootstrapBlazor.Components;
|
||||
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace ThingsGateway.Gateway.Application;
|
||||
|
||||
/// <summary>
|
||||
@@ -57,7 +59,7 @@ internal interface IChannelService
|
||||
/// 从缓存/数据库获取全部信息
|
||||
/// </summary>
|
||||
/// <returns>通道列表</returns>
|
||||
Task<List<Channel>> GetAllAsync(SqlSugarClient db = null);
|
||||
Task<List<Channel>> GetFromDBAsync(Expression<Func<Channel, bool>> expression = null, SqlSugarClient db = null);
|
||||
|
||||
/// <summary>
|
||||
/// 导入通道数据
|
||||
@@ -92,7 +94,7 @@ internal interface IChannelService
|
||||
/// <param name="type">保存类型</param>
|
||||
Task<bool> BatchSaveAsync(List<Channel> input, ItemChangedType type);
|
||||
|
||||
void SetChannelData(HashSet<long>? dataScope, Dictionary<string, Channel> channelDicts, Dictionary<string, ImportPreviewOutputBase> ImportPreviews, string sheetName, IEnumerable<IDictionary<string, object>> rows);
|
||||
void SetChannelData(HashSet<long>? dataScope, IReadOnlyDictionary<string, ChannelRuntime> channelDicts, Dictionary<string, ImportPreviewOutputBase> ImportPreviews, string sheetName, IEnumerable<IDictionary<string, object>> rows);
|
||||
|
||||
/// <summary>
|
||||
/// 保存是否输出日志和日志等级
|
||||
|
@@ -16,6 +16,7 @@ using MiniExcelLibs;
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
@@ -129,11 +130,11 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
|
||||
//事务
|
||||
var result = await db.UseTranAsync(async () =>
|
||||
{
|
||||
var data = (await GetAllAsync(db).ConfigureAwait(false))
|
||||
.WhereIf(dataScope != null && dataScope?.Count > 0, u => dataScope.Contains(u.CreateOrgId))//在指定机构列表查询
|
||||
.WhereIf(dataScope?.Count == 0, u => u.CreateUserId == UserManager.UserId)
|
||||
.Where(a => IdhashSet.Contains(a.ChannelId))
|
||||
.Select(a => a.Id).ToList();
|
||||
var data = GlobalData.IdDevices
|
||||
.WhereIf(dataScope != null && dataScope?.Count > 0, u => dataScope.Contains(u.Value.CreateOrgId))//在指定机构列表查询
|
||||
.WhereIf(dataScope?.Count == 0, u => u.Value.CreateUserId == UserManager.UserId)
|
||||
.Where(a => IdhashSet.Contains(a.Value.ChannelId))
|
||||
.Select(a => a.Value.Id).ToList();
|
||||
await db.Deleteable<Device>(a => data.Contains(a.Id)).ExecuteCommandAsync().ConfigureAwait(false);
|
||||
await variableService.DeleteByDeviceIdAsync(data, db).ConfigureAwait(false);
|
||||
}).ConfigureAwait(false);
|
||||
@@ -180,30 +181,19 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
|
||||
/// <inheritdoc />
|
||||
public void DeleteDeviceFromCache()
|
||||
{
|
||||
App.CacheService.Remove(ThingsGatewayCacheConst.Cache_Device);//删除设备缓存
|
||||
//App.CacheService.Remove(ThingsGatewayCacheConst.Cache_Device);//删除设备缓存
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从缓存/数据库获取全部信息
|
||||
/// </summary>
|
||||
/// <returns>列表</returns>
|
||||
public async Task<List<Device>> GetAllAsync(SqlSugarClient db = null)
|
||||
{
|
||||
var key = ThingsGatewayCacheConst.Cache_Device;
|
||||
var devices = App.CacheService.Get<List<Device>>(key);
|
||||
if (devices == null)
|
||||
public async Task<List<Device>> GetFromDBAsync(Expression<Func<Device, bool>> expression = null, SqlSugarClient db = null)
|
||||
{
|
||||
db ??= GetDB();
|
||||
devices = await db.Queryable<Device>().OrderBy(a => a.Id).ToListAsync().ConfigureAwait(false);
|
||||
App.CacheService.Set(key, devices);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
var devices = await db.Queryable<Device>().WhereIF(expression != null, expression).OrderBy(a => a.Id).ToListAsync().ConfigureAwait(false);
|
||||
|
||||
public async Task<Device?> GetDeviceByIdAsync(long id)
|
||||
{
|
||||
var data = await GetAllAsync().ConfigureAwait(false);
|
||||
return data?.FirstOrDefault(x => x.Id == id);
|
||||
return devices;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -222,12 +212,12 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
|
||||
HashSet<long>? channel = null;
|
||||
if (!exportFilter.PluginName.IsNullOrWhiteSpace())
|
||||
{
|
||||
channel = (await _channelService.GetAllAsync().ConfigureAwait(false)).Where(a => a.PluginName == exportFilter.PluginName).Select(a => a.Id).ToHashSet();
|
||||
channel = (GlobalData.IdChannels).Where(a => a.Value.PluginName == exportFilter.PluginName).Select(a => a.Value.Id).ToHashSet();
|
||||
}
|
||||
if (exportFilter.PluginType != null)
|
||||
{
|
||||
var pluginInfo = GlobalData.PluginService.GetList(exportFilter.PluginType).Select(a => a.FullName).ToHashSet();
|
||||
channel = (await _channelService.GetAllAsync().ConfigureAwait(false)).Where(a => pluginInfo.Contains(a.PluginName)).Select(a => a.Id).ToHashSet();
|
||||
channel = (GlobalData.IdChannels).Where(a => pluginInfo.Contains(a.Value.PluginName)).Select(a => a.Value.Id).ToHashSet();
|
||||
}
|
||||
var dataScope = await GlobalData.SysUserService.GetCurrentUserDataScopeAsync().ConfigureAwait(false);
|
||||
var whereQuery = (ISugarQueryable<Device> a) => a
|
||||
@@ -244,12 +234,12 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
|
||||
HashSet<long>? channel = null;
|
||||
if (!exportFilter.PluginName.IsNullOrWhiteSpace())
|
||||
{
|
||||
channel = (await _channelService.GetAllAsync().ConfigureAwait(false)).Where(a => a.PluginName == exportFilter.PluginName).Select(a => a.Id).ToHashSet();
|
||||
channel = (GlobalData.IdChannels).Where(a => a.Value.PluginName == exportFilter.PluginName).Select(a => a.Value.Id).ToHashSet();
|
||||
}
|
||||
if (exportFilter.PluginType != null)
|
||||
{
|
||||
var pluginInfo = GlobalData.PluginService.GetList(exportFilter.PluginType).Select(a => a.FullName).ToHashSet();
|
||||
channel = (await _channelService.GetAllAsync().ConfigureAwait(false)).Where(a => pluginInfo.Contains(a.PluginName)).Select(a => a.Id).ToHashSet();
|
||||
channel = (GlobalData.IdChannels).Where(a => pluginInfo.Contains(a.Value.PluginName)).Select(a => a.Value.Id).ToHashSet();
|
||||
}
|
||||
var dataScope = await GlobalData.SysUserService.GetCurrentUserDataScopeAsync().ConfigureAwait(false);
|
||||
var whereQuery = (IEnumerable<Device> a) => a
|
||||
@@ -269,7 +259,7 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
|
||||
[OperDesc("SaveDevice", localizerType: typeof(Device))]
|
||||
public async Task<bool> SaveDeviceAsync(Device input, ItemChangedType type)
|
||||
{
|
||||
if ((await GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Name).TryGetValue(input.Name, out var device))
|
||||
if (GlobalData.Devices.TryGetValue(input.Name, out var device))
|
||||
{
|
||||
if (device.Id != input.Id)
|
||||
{
|
||||
@@ -318,8 +308,8 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
|
||||
var devices = await GetAsyncEnumerableData(exportFilter).ConfigureAwait(false);
|
||||
var plugins = await GetAsyncEnumerableData(exportFilter).ConfigureAwait(false);
|
||||
var devicesSql = await GetEnumerableData(exportFilter).ConfigureAwait(false);
|
||||
var deviceDicts = (await GlobalData.DeviceService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Id);
|
||||
var channelDicts = (await GlobalData.ChannelService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Id);
|
||||
var deviceDicts = GlobalData.IdDevices;
|
||||
var channelDicts = GlobalData.IdChannels;
|
||||
var pluginSheetNames = (await devicesSql.Select(a => a.ChannelId).ToListAsync().ConfigureAwait(false)).Select(a =>
|
||||
{
|
||||
channelDicts.TryGetValue(a, out var channel);
|
||||
@@ -350,8 +340,8 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
|
||||
[OperDesc("ExportDevice", isRecordPar: false, localizerType: typeof(Device))]
|
||||
public async Task<MemoryStream> ExportMemoryStream(List<Device>? models, string channelName = null, string plugin = null)
|
||||
{
|
||||
var deviceDicts = (await GlobalData.DeviceService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Id);
|
||||
var channelDicts = (await GlobalData.ChannelService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Id);
|
||||
var deviceDicts = GlobalData.IdDevices;
|
||||
var channelDicts = GlobalData.IdChannels;
|
||||
var pluginSheetNames = models.Select(a => a.ChannelId).Select(a =>
|
||||
{
|
||||
channelDicts.TryGetValue(a, out var channel);
|
||||
@@ -415,10 +405,10 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
|
||||
var sheetNames = MiniExcel.GetSheetNames(path);
|
||||
|
||||
// 获取所有设备,并将设备名称作为键构建设备字典
|
||||
var deviceDicts = (await GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Name);
|
||||
var deviceDicts = GlobalData.Devices;
|
||||
|
||||
// 获取所有通道,并将通道名称作为键构建通道字典
|
||||
var channelDicts = (await _channelService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Name);
|
||||
var channelDicts = GlobalData.Channels;
|
||||
|
||||
// 导入检验结果的预览字典,键为名称,值为导入预览对象
|
||||
Dictionary<string, ImportPreviewOutputBase> ImportPreviews = new();
|
||||
@@ -446,7 +436,7 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDeviceData(HashSet<long>? dataScope, Dictionary<string, Device> deviceDicts, Dictionary<string, Channel> channelDicts, Dictionary<string, ImportPreviewOutputBase> ImportPreviews, ref ImportPreviewOutput<Device> deviceImportPreview, Dictionary<string, PluginInfo> driverPluginNameDict, ConcurrentDictionary<string, (Type, Dictionary<string, PropertyInfo>, Dictionary<string, PropertyInfo>)> propertysDict, string sheetName, IEnumerable<IDictionary<string, object>> rows)
|
||||
public void SetDeviceData(HashSet<long>? dataScope, IReadOnlyDictionary<string, DeviceRuntime> deviceDicts, IReadOnlyDictionary<string, ChannelRuntime> channelDicts, Dictionary<string, ImportPreviewOutputBase> ImportPreviews, ref ImportPreviewOutput<Device> deviceImportPreview, Dictionary<string, PluginInfo> driverPluginNameDict, ConcurrentDictionary<string, (Type, Dictionary<string, PropertyInfo>, Dictionary<string, PropertyInfo>)> propertysDict, string sheetName, IEnumerable<IDictionary<string, object>> rows)
|
||||
{
|
||||
#region 采集设备sheet
|
||||
|
||||
|
@@ -19,10 +19,10 @@ namespace ThingsGateway.Gateway.Application;
|
||||
|
||||
public static class DeviceServiceHelpers
|
||||
{
|
||||
public static async Task<USheetDatas> ExportDeviceAsync(IEnumerable<Device> models)
|
||||
public static USheetDatas ExportDevice(IEnumerable<Device> models)
|
||||
{
|
||||
var deviceDicts = (await GlobalData.DeviceService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Id);
|
||||
var channelDicts = (await GlobalData.ChannelService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Id);
|
||||
var deviceDicts = GlobalData.IdDevices;
|
||||
var channelDicts = GlobalData.IdChannels;
|
||||
var pluginSheetNames = models.Select(a => a.ChannelId).Select(a =>
|
||||
{
|
||||
channelDicts.TryGetValue(a, out var channel);
|
||||
@@ -35,8 +35,8 @@ public static class DeviceServiceHelpers
|
||||
|
||||
public static Dictionary<string, object> ExportSheets(
|
||||
IEnumerable<Device>? data,
|
||||
Dictionary<long, Device>? deviceDicts,
|
||||
Dictionary<long, Channel> channelDicts,
|
||||
IReadOnlyDictionary<long, DeviceRuntime>? deviceDicts,
|
||||
IReadOnlyDictionary<long, ChannelRuntime> channelDicts,
|
||||
HashSet<string> pluginSheetNames,
|
||||
string? channelName = null)
|
||||
{
|
||||
@@ -60,8 +60,8 @@ HashSet<string> pluginSheetNames,
|
||||
public static Dictionary<string, object> ExportSheets(
|
||||
IAsyncEnumerable<Device>? data1,
|
||||
IAsyncEnumerable<Device>? data2,
|
||||
Dictionary<long, Device>? deviceDicts,
|
||||
Dictionary<long, Channel> channelDicts,
|
||||
IReadOnlyDictionary<long, DeviceRuntime>? deviceDicts,
|
||||
IReadOnlyDictionary<long, ChannelRuntime> channelDicts,
|
||||
HashSet<string> pluginSheetNames,
|
||||
string? channelName = null)
|
||||
{
|
||||
@@ -82,7 +82,7 @@ string? channelName = null)
|
||||
|
||||
return result;
|
||||
}
|
||||
static IAsyncEnumerable<Device> FilterPluginDevices(IAsyncEnumerable<Device> data, string plugin, Dictionary<long, Channel> channelDicts)
|
||||
static IAsyncEnumerable<Device> FilterPluginDevices(IAsyncEnumerable<Device> data, string plugin, IReadOnlyDictionary<long, ChannelRuntime> channelDicts)
|
||||
{
|
||||
return data.Where(device =>
|
||||
{
|
||||
@@ -99,7 +99,7 @@ string? channelName = null)
|
||||
}
|
||||
});
|
||||
}
|
||||
static IEnumerable<Device> FilterPluginDevices(IEnumerable<Device> data, string plugin, Dictionary<long, Channel> channelDicts)
|
||||
static IEnumerable<Device> FilterPluginDevices(IEnumerable<Device> data, string plugin, IReadOnlyDictionary<long, ChannelRuntime> channelDicts)
|
||||
{
|
||||
return data.Where(device =>
|
||||
{
|
||||
@@ -119,8 +119,8 @@ string? channelName = null)
|
||||
|
||||
static IEnumerable<Dictionary<string, object>> GetDeviceSheets(
|
||||
IEnumerable<Device> data,
|
||||
Dictionary<long, Device>? deviceDicts,
|
||||
Dictionary<long, Channel> channelDicts,
|
||||
IReadOnlyDictionary<long, DeviceRuntime>? deviceDicts,
|
||||
IReadOnlyDictionary<long, ChannelRuntime> channelDicts,
|
||||
string? channelName)
|
||||
{
|
||||
var type = typeof(Device);
|
||||
@@ -157,8 +157,8 @@ Dictionary<long, Device>? deviceDicts,
|
||||
|
||||
static async IAsyncEnumerable<Dictionary<string, object>> GetDeviceSheets(
|
||||
IAsyncEnumerable<Device> data,
|
||||
Dictionary<long, Device>? deviceDicts,
|
||||
Dictionary<long, Channel> channelDicts,
|
||||
IReadOnlyDictionary<long, DeviceRuntime>? deviceDicts,
|
||||
IReadOnlyDictionary<long, ChannelRuntime> channelDicts,
|
||||
string? channelName)
|
||||
{
|
||||
var type = typeof(Device);
|
||||
@@ -201,8 +201,8 @@ Dictionary<long, Device>? deviceDicts,
|
||||
Device device,
|
||||
IEnumerable<PropertyInfo>? propertyInfos,
|
||||
Type type,
|
||||
Dictionary<long, Device>? deviceDicts,
|
||||
Dictionary<long, Channel>? channelDicts,
|
||||
IReadOnlyDictionary<long, DeviceRuntime>? deviceDicts,
|
||||
IReadOnlyDictionary<long, ChannelRuntime>? channelDicts,
|
||||
string? channelName)
|
||||
{
|
||||
Dictionary<string, object> devExport = new();
|
||||
@@ -276,10 +276,10 @@ string? channelName)
|
||||
{
|
||||
var dataScope = await GlobalData.SysUserService.GetCurrentUserDataScopeAsync().ConfigureAwait(false);
|
||||
// 获取所有设备,并将设备名称作为键构建设备字典
|
||||
var deviceDicts = (await GlobalData.DeviceService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Name);
|
||||
var deviceDicts = GlobalData.Devices;
|
||||
|
||||
// 获取所有通道,并将通道名称作为键构建通道字典
|
||||
var channelDicts = (await GlobalData.ChannelService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Name);
|
||||
var channelDicts = GlobalData.Channels;
|
||||
|
||||
// 导入检验结果的预览字典,键为名称,值为导入预览对象
|
||||
Dictionary<string, ImportPreviewOutputBase> ImportPreviews = new();
|
||||
|
@@ -13,6 +13,7 @@ using BootstrapBlazor.Components;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ThingsGateway.Gateway.Application;
|
||||
@@ -73,14 +74,7 @@ internal interface IDeviceService
|
||||
/// 获取所有设备信息。
|
||||
/// </summary>
|
||||
/// <returns>所有设备信息</returns>
|
||||
Task<List<Device>> GetAllAsync(SqlSugarClient db = null);
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID获取设备信息。
|
||||
/// </summary>
|
||||
/// <param name="id">设备ID</param>
|
||||
/// <returns>设备信息</returns>
|
||||
Task<Device?> GetDeviceByIdAsync(long id);
|
||||
Task<List<Device>> GetFromDBAsync(Expression<Func<Device, bool>> expression = null, SqlSugarClient db = null);
|
||||
|
||||
/// <summary>
|
||||
/// 导入设备信息。
|
||||
@@ -119,7 +113,7 @@ internal interface IDeviceService
|
||||
/// <returns>保存是否成功的异步任务</returns>
|
||||
Task<bool> BatchSaveDeviceAsync(List<Device> input, ItemChangedType type);
|
||||
|
||||
void SetDeviceData(HashSet<long>? dataScope, Dictionary<string, Device> deviceDicts, Dictionary<string, Channel> channelDicts, Dictionary<string, ImportPreviewOutputBase> ImportPreviews, ref ImportPreviewOutput<Device> deviceImportPreview, Dictionary<string, PluginInfo> driverPluginNameDict, ConcurrentDictionary<string, (Type, Dictionary<string, PropertyInfo>, Dictionary<string, PropertyInfo>)> propertysDict, string sheetName, IEnumerable<IDictionary<string, object>> rows);
|
||||
void SetDeviceData(HashSet<long>? dataScope, IReadOnlyDictionary<string, DeviceRuntime> deviceDicts, IReadOnlyDictionary<string, ChannelRuntime> channelDicts, Dictionary<string, ImportPreviewOutputBase> ImportPreviews, ref ImportPreviewOutput<Device> deviceImportPreview, Dictionary<string, PluginInfo> driverPluginNameDict, ConcurrentDictionary<string, (Type, Dictionary<string, PropertyInfo>, Dictionary<string, PropertyInfo>)> propertysDict, string sheetName, IEnumerable<IDictionary<string, object>> rows);
|
||||
|
||||
/// <summary>
|
||||
/// 保存是否输出日志和日志等级
|
||||
|
@@ -584,13 +584,13 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage
|
||||
await RemoveDeviceAsync(deviceRuntime.Id).ConfigureAwait(false);
|
||||
|
||||
//获取主设备
|
||||
var devices = await GlobalData.DeviceService.GetAllAsync().ConfigureAwait(false);//获取设备属性
|
||||
var devices = GlobalData.IdDevices;
|
||||
|
||||
if (deviceRuntime.RedundantEnable && deviceRuntime.RedundantDeviceId != null)
|
||||
{
|
||||
if (!GlobalData.ReadOnlyIdDevices.TryGetValue(deviceRuntime.RedundantDeviceId ?? 0, out newDeviceRuntime))
|
||||
{
|
||||
var newDev = await GlobalData.DeviceService.GetDeviceByIdAsync(deviceRuntime.RedundantDeviceId ?? 0).ConfigureAwait(false);
|
||||
devices.TryGetValue(deviceRuntime.RedundantDeviceId ?? 0, out var newDev);
|
||||
if (newDev == null)
|
||||
{
|
||||
LogMessage?.LogWarning($"Device with deviceId {deviceRuntime.RedundantDeviceId} not found");
|
||||
@@ -611,7 +611,7 @@ internal sealed class DeviceThreadManage : IAsyncDisposable, IDeviceThreadManage
|
||||
newDeviceRuntime = GlobalData.ReadOnlyIdDevices.FirstOrDefault(a => a.Value.RedundantDeviceId == deviceRuntime.Id).Value;
|
||||
if (newDeviceRuntime == null)
|
||||
{
|
||||
var newDev = devices.FirstOrDefault(a => a.RedundantDeviceId == deviceRuntime.Id);
|
||||
var newDev = devices.FirstOrDefault(a => a.Value.RedundantDeviceId == deviceRuntime.Id).Value;
|
||||
if (newDev == null)
|
||||
{
|
||||
LogMessage?.LogWarning($"Device with redundantDeviceId {deviceRuntime.Id} not found");
|
||||
|
@@ -39,8 +39,8 @@ internal sealed class GatewayMonitorHostedService : BackgroundService, IGatewayM
|
||||
try
|
||||
{
|
||||
//网关启动时,获取所有通道
|
||||
var channelRuntimes = (await GlobalData.ChannelService.GetAllAsync().ConfigureAwait(false)).AdaptListChannelRuntime();
|
||||
var deviceRuntimes = (await GlobalData.DeviceService.GetAllAsync().ConfigureAwait(false)).AdaptListDeviceRuntime();
|
||||
var channelRuntimes = (await GlobalData.ChannelService.GetFromDBAsync().ConfigureAwait(false)).AdaptListChannelRuntime();
|
||||
var deviceRuntimes = (await GlobalData.DeviceService.GetFromDBAsync().ConfigureAwait(false)).AdaptListDeviceRuntime();
|
||||
|
||||
var variableRuntimes = GlobalData.VariableService.GetAllVariableRuntime();
|
||||
|
||||
|
@@ -35,7 +35,7 @@ internal sealed class PluginService : IPluginService
|
||||
/// </summary>
|
||||
public const string DirName = "GatewayPlugins";
|
||||
|
||||
private const string CacheKeyGetPluginOutputs = $"{ThingsGatewayCacheConst.Cache_Prefix}{nameof(PluginService)}{nameof(GetList)}";
|
||||
private const string CacheKeyGetPluginOutputs = $"ThingsGateway.Gateway.Application.{nameof(PluginService)}{nameof(GetList)}";
|
||||
private const string SaveEx = ".save";
|
||||
private const string DelEx = ".del";
|
||||
|
||||
|
@@ -151,13 +151,13 @@ internal static class RuntimeServiceHelper
|
||||
|
||||
public static async Task<List<ChannelRuntime>> GetNewChannelRuntimesAsync(HashSet<long> ids)
|
||||
{
|
||||
var newChannelRuntimes = (await GlobalData.ChannelService.GetAllAsync().ConfigureAwait(false)).Where(a => ids.Contains(a.Id)).AdaptListChannelRuntime();
|
||||
var newChannelRuntimes = (await GlobalData.ChannelService.GetFromDBAsync((a => ids.Contains(a.Id))).ConfigureAwait(false)).AdaptListChannelRuntime();
|
||||
return newChannelRuntimes;
|
||||
}
|
||||
|
||||
public static async Task<List<DeviceRuntime>> GetNewDeviceRuntimesAsync(HashSet<long> deviceids)
|
||||
{
|
||||
var newDeviceRuntimes = (await GlobalData.DeviceService.GetAllAsync().ConfigureAwait(false)).Where(a => deviceids.Contains(a.Id)).AdaptListDeviceRuntime();
|
||||
var newDeviceRuntimes = (await GlobalData.DeviceService.GetFromDBAsync((a => deviceids.Contains(a.Id))).ConfigureAwait(false)).AdaptListDeviceRuntime();
|
||||
return newDeviceRuntimes;
|
||||
}
|
||||
|
||||
|
@@ -106,6 +106,6 @@ internal interface IVariableService
|
||||
|
||||
Task<List<Variable>> GetByDeviceIdAsync(List<long> deviceIds);
|
||||
void DeleteVariableCache();
|
||||
ImportPreviewOutput<Dictionary<string, Variable>> SetVariableData(HashSet<long>? dataScope, Dictionary<string, Device> deviceDicts, Dictionary<string, ImportPreviewOutputBase> ImportPreviews, ImportPreviewOutput<Dictionary<string, Variable>> deviceImportPreview, Dictionary<string, PluginInfo> driverPluginNameDict, ConcurrentDictionary<string, (Type, Dictionary<string, PropertyInfo>, Dictionary<string, PropertyInfo>)> propertysDict, string sheetName, IEnumerable<IDictionary<string, object>> rows);
|
||||
ImportPreviewOutput<Dictionary<string, Variable>> SetVariableData(HashSet<long>? dataScope, IReadOnlyDictionary<string, DeviceRuntime> deviceDicts, Dictionary<string, ImportPreviewOutputBase> ImportPreviews, ImportPreviewOutput<Dictionary<string, Variable>> deviceImportPreview, Dictionary<string, PluginInfo> driverPluginNameDict, ConcurrentDictionary<string, (Type, Dictionary<string, PropertyInfo>, Dictionary<string, PropertyInfo>)> propertysDict, string sheetName, IEnumerable<IDictionary<string, object>> rows);
|
||||
List<VariableRuntime> GetAllVariableRuntime();
|
||||
}
|
||||
|
@@ -375,12 +375,12 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
|
||||
HashSet<long>? deviceId = null;
|
||||
if (!exportFilter.PluginName.IsNullOrWhiteSpace())
|
||||
{
|
||||
var channel = (await _channelService.GetAllAsync().ConfigureAwait(false)).Where(a => a.PluginName == exportFilter.PluginName).Select(a => a.Id).ToHashSet();
|
||||
deviceId = (await _deviceService.GetAllAsync().ConfigureAwait(false)).Where(a => channel.Contains(a.ChannelId)).Select(a => a.Id).ToHashSet();
|
||||
var channel = (GlobalData.IdChannels).Where(a => a.Value.PluginName == exportFilter.PluginName).Select(a => a.Value.Id).ToHashSet();
|
||||
deviceId = (GlobalData.IdDevices).Where(a => channel.Contains(a.Value.ChannelId)).Select(a => a.Value.Id).ToHashSet();
|
||||
}
|
||||
else if (exportFilter.ChannelId != null)
|
||||
{
|
||||
deviceId = (await _deviceService.GetAllAsync().ConfigureAwait(false)).Where(a => a.ChannelId == exportFilter.ChannelId).Select(a => a.Id).ToHashSet();
|
||||
deviceId = (GlobalData.IdDevices).Where(a => a.Value.ChannelId == exportFilter.ChannelId).Select(a => a.Value.Id).ToHashSet();
|
||||
}
|
||||
var whereQuery = (ISugarQueryable<Variable> a) => a
|
||||
.WhereIF(!exportFilter.QueryPageOptions.SearchText.IsNullOrWhiteSpace(), a => a.Name.Contains(exportFilter.QueryPageOptions.SearchText!))
|
||||
@@ -394,18 +394,18 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
|
||||
return whereQuery;
|
||||
}
|
||||
|
||||
private async Task<Func<IEnumerable<Variable>, IEnumerable<Variable>>> GetWhereEnumerableFunc(ExportFilter exportFilter)
|
||||
private async Task<Func<IEnumerable<Variable>, IEnumerable<Variable>>> GetWhereEnumerableFunc(ExportFilter exportFilter, bool sql = false)
|
||||
{
|
||||
var dataScope = await GlobalData.SysUserService.GetCurrentUserDataScopeAsync().ConfigureAwait(false);
|
||||
HashSet<long>? deviceId = null;
|
||||
if (!exportFilter.PluginName.IsNullOrWhiteSpace())
|
||||
{
|
||||
var channel = (await _channelService.GetAllAsync().ConfigureAwait(false)).Where(a => a.PluginName == exportFilter.PluginName).Select(a => a.Id).ToHashSet();
|
||||
deviceId = (await _deviceService.GetAllAsync().ConfigureAwait(false)).Where(a => channel.Contains(a.ChannelId)).Select(a => a.Id).ToHashSet();
|
||||
var channel = (GlobalData.IdChannels).Where(a => a.Value.PluginName == exportFilter.PluginName).Select(a => a.Value.Id).ToHashSet();
|
||||
deviceId = (GlobalData.IdDevices).Where(a => channel.Contains(a.Value.ChannelId)).Select(a => a.Value.Id).ToHashSet();
|
||||
}
|
||||
else if (exportFilter.ChannelId != null)
|
||||
{
|
||||
deviceId = (await _deviceService.GetAllAsync().ConfigureAwait(false)).Where(a => a.ChannelId == exportFilter.ChannelId).Select(a => a.Id).ToHashSet();
|
||||
deviceId = (GlobalData.IdDevices).Where(a => a.Value.ChannelId == exportFilter.ChannelId).Select(a => a.Value.Id).ToHashSet();
|
||||
}
|
||||
var whereQuery = (IEnumerable<Variable> a) => a
|
||||
.WhereIF(!exportFilter.QueryPageOptions.SearchText.IsNullOrWhiteSpace(), a => a.Name.Contains(exportFilter.QueryPageOptions.SearchText!))
|
||||
@@ -415,7 +415,12 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
|
||||
.WhereIF(dataScope != null && dataScope?.Count > 0, u => dataScope.Contains(u.CreateOrgId))//在指定机构列表查询
|
||||
.WhereIF(dataScope?.Count == 0, u => u.CreateUserId == UserManager.UserId)
|
||||
|
||||
.WhereIF(exportFilter.PluginType == PluginTypeEnum.Business, u => SqlFunc.JsonLike(u.VariablePropertys, exportFilter.DeviceId.ToString()));
|
||||
.WhereIF(sql && exportFilter.PluginType == PluginTypeEnum.Business, u => SqlFunc.JsonLike(u.VariablePropertys, exportFilter.DeviceId.ToString()))
|
||||
.WhereIF(!sql && exportFilter.PluginType == PluginTypeEnum.Business && exportFilter.DeviceId > 0, u =>
|
||||
GlobalData.IdVariables.TryGetValue(u.Id, out var runtime) &&
|
||||
GlobalData.ContainsVariable(exportFilter.DeviceId.Value, runtime)
|
||||
|
||||
);
|
||||
return whereQuery;
|
||||
}
|
||||
|
||||
@@ -442,7 +447,7 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
|
||||
|
||||
public void DeleteVariableCache()
|
||||
{
|
||||
App.CacheService.Remove(ThingsGatewayCacheConst.Cache_Variable);
|
||||
//App.CacheService.Remove(ThingsGatewayCacheConst.Cache_Variable);
|
||||
}
|
||||
|
||||
public List<VariableRuntime> GetAllVariableRuntime()
|
||||
@@ -461,8 +466,8 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
|
||||
[OperDesc("ExportVariable", isRecordPar: false, localizerType: typeof(Variable))]
|
||||
public async Task<MemoryStream> ExportMemoryStream(List<Variable> variables, string deviceName = null)
|
||||
{
|
||||
var deviceDicts = (await GlobalData.DeviceService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Id);
|
||||
var channelDicts = (await GlobalData.ChannelService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Id);
|
||||
var deviceDicts = GlobalData.IdDevices;
|
||||
var channelDicts = GlobalData.IdChannels;
|
||||
var pluginSheetNames = variables.Where(a => a.VariablePropertys?.Count > 0).SelectMany(a => a.VariablePropertys).Select(a =>
|
||||
{
|
||||
if (deviceDicts.TryGetValue(a.Key, out var device) && channelDicts.TryGetValue(device.ChannelId, out var channel))
|
||||
@@ -493,8 +498,8 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
|
||||
//导出
|
||||
var variables = GlobalData.IdVariables.Select(a => a.Value).GetQuery(exportFilter.QueryPageOptions, whereQuery, exportFilter.FilterKeyValueAction);
|
||||
|
||||
var deviceDicts = (await GlobalData.DeviceService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Id);
|
||||
var channelDicts = (await GlobalData.ChannelService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Id);
|
||||
var deviceDicts = GlobalData.IdDevices;
|
||||
var channelDicts = GlobalData.IdChannels;
|
||||
var pluginSheetNames = variables.Where(a => a.VariablePropertys?.Count > 0).SelectMany(a => a.VariablePropertys).Select(a =>
|
||||
{
|
||||
if (deviceDicts.TryGetValue(a.Key, out var device) && channelDicts.TryGetValue(device.ChannelId, out var channel))
|
||||
@@ -512,8 +517,11 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
|
||||
}
|
||||
else
|
||||
{
|
||||
var data = (await PageAsync(exportFilter).ConfigureAwait(false));
|
||||
var sheets = await VariableServiceHelpers.ExportCoreAsync(data.Items, sortName: exportFilter.QueryPageOptions.SortName, sortOrder: exportFilter.QueryPageOptions.SortOrder).ConfigureAwait(false);
|
||||
var whereQuery = await GetWhereEnumerableFunc(exportFilter).ConfigureAwait(false);
|
||||
//导出
|
||||
var data = GlobalData.IdVariables.Select(a => a.Value).GetQuery(exportFilter.QueryPageOptions, whereQuery, exportFilter.FilterKeyValueAction);
|
||||
//var data = (await PageAsync(exportFilter).ConfigureAwait(false));
|
||||
var sheets = VariableServiceHelpers.ExportCore(data, sortName: exportFilter.QueryPageOptions.SortName, sortOrder: exportFilter.QueryPageOptions.SortOrder);
|
||||
return sheets;
|
||||
}
|
||||
}
|
||||
@@ -578,7 +586,7 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
|
||||
var sheetNames = MiniExcel.GetSheetNames(path);
|
||||
|
||||
// 获取所有设备的字典,以设备名称作为键
|
||||
var deviceDicts = (await _deviceService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Name);
|
||||
var deviceDicts = GlobalData.Devices;
|
||||
|
||||
// 存储导入检验结果的字典
|
||||
Dictionary<string, ImportPreviewOutputBase> ImportPreviews = new();
|
||||
@@ -609,7 +617,7 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
|
||||
}
|
||||
}
|
||||
|
||||
public ImportPreviewOutput<Dictionary<string, Variable>> SetVariableData(HashSet<long>? dataScope, Dictionary<string, Device> deviceDicts, Dictionary<string, ImportPreviewOutputBase> ImportPreviews, ImportPreviewOutput<Dictionary<string, Variable>> deviceImportPreview, Dictionary<string, PluginInfo> driverPluginNameDict, ConcurrentDictionary<string, (Type, Dictionary<string, PropertyInfo>, Dictionary<string, PropertyInfo>)> propertysDict, string sheetName, IEnumerable<IDictionary<string, object>> rows)
|
||||
public ImportPreviewOutput<Dictionary<string, Variable>> SetVariableData(HashSet<long>? dataScope, IReadOnlyDictionary<string, DeviceRuntime> deviceDicts, Dictionary<string, ImportPreviewOutputBase> ImportPreviews, ImportPreviewOutput<Dictionary<string, Variable>> deviceImportPreview, Dictionary<string, PluginInfo> driverPluginNameDict, ConcurrentDictionary<string, (Type, Dictionary<string, PropertyInfo>, Dictionary<string, PropertyInfo>)> propertysDict, string sheetName, IEnumerable<IDictionary<string, object>> rows)
|
||||
{
|
||||
// 变量页处理
|
||||
if (sheetName == ExportString.VariableName)
|
||||
|
@@ -21,10 +21,10 @@ namespace ThingsGateway.Gateway.Application;
|
||||
|
||||
public static class VariableServiceHelpers
|
||||
{
|
||||
public static async Task<USheetDatas> ExportVariableAsync(IEnumerable<Variable> variables, string sortName = nameof(Variable.Id), SortOrder sortOrder = SortOrder.Asc)
|
||||
public static USheetDatas ExportVariable(IEnumerable<Variable> variables, string sortName = nameof(Variable.Id), SortOrder sortOrder = SortOrder.Asc)
|
||||
{
|
||||
var deviceDicts = (await GlobalData.DeviceService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Id);
|
||||
var channelDicts = (await GlobalData.ChannelService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Id);
|
||||
var deviceDicts = GlobalData.IdDevices;
|
||||
var channelDicts = GlobalData.IdChannels;
|
||||
var pluginSheetNames = variables.Where(a => a.VariablePropertys?.Count > 0).SelectMany(a => a.VariablePropertys).Select(a =>
|
||||
{
|
||||
if (deviceDicts.TryGetValue(a.Key, out var device) && channelDicts.TryGetValue(device.ChannelId, out var channel))
|
||||
@@ -41,8 +41,8 @@ public static class VariableServiceHelpers
|
||||
static IAsyncEnumerable<Variable> FilterPluginDevices(
|
||||
IAsyncEnumerable<Variable> data,
|
||||
string pluginName,
|
||||
Dictionary<long, Device> deviceDicts,
|
||||
Dictionary<long, Channel> channelDicts)
|
||||
IReadOnlyDictionary<long, DeviceRuntime> deviceDicts,
|
||||
IReadOnlyDictionary<long, ChannelRuntime> channelDicts)
|
||||
{
|
||||
return data.Where(variable =>
|
||||
{
|
||||
@@ -65,8 +65,8 @@ Dictionary<long, Device> deviceDicts,
|
||||
static IEnumerable<Variable> FilterPluginDevices(
|
||||
IEnumerable<Variable> data,
|
||||
string pluginName,
|
||||
Dictionary<long, Device> deviceDicts,
|
||||
Dictionary<long, Channel> channelDicts)
|
||||
IReadOnlyDictionary<long, DeviceRuntime> deviceDicts,
|
||||
IReadOnlyDictionary<long, ChannelRuntime> channelDicts)
|
||||
{
|
||||
return data.Where(variable =>
|
||||
{
|
||||
@@ -88,8 +88,8 @@ Dictionary<long, Channel> channelDicts)
|
||||
|
||||
public static Dictionary<string, object> ExportSheets(
|
||||
IEnumerable<Variable> data,
|
||||
Dictionary<long, Device> deviceDicts,
|
||||
Dictionary<long, Channel> channelDicts,
|
||||
IReadOnlyDictionary<long, DeviceRuntime> deviceDicts,
|
||||
IReadOnlyDictionary<long, ChannelRuntime> channelDicts,
|
||||
Dictionary<string, VariablePropertyBase> pluginDrivers,
|
||||
string? deviceName = null)
|
||||
{
|
||||
@@ -112,7 +112,7 @@ Dictionary<long, Channel> channelDicts)
|
||||
|
||||
static IEnumerable<Dictionary<string, object>> GetVariableSheets(
|
||||
IEnumerable<Variable> data,
|
||||
Dictionary<long, Device> deviceDicts,
|
||||
IReadOnlyDictionary<long, DeviceRuntime> deviceDicts,
|
||||
string? deviceName)
|
||||
{
|
||||
var type = typeof(Variable);
|
||||
@@ -132,7 +132,7 @@ Dictionary<long, Channel> channelDicts)
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<string, object> GetVariable(Dictionary<long, Device> deviceDicts, string? deviceName, Type type, IOrderedEnumerable<PropertyInfo> propertyInfos, Variable variable)
|
||||
private static Dictionary<string, object> GetVariable(IReadOnlyDictionary<long, DeviceRuntime> deviceDicts, string? deviceName, Type type, IOrderedEnumerable<PropertyInfo> propertyInfos, Variable variable)
|
||||
{
|
||||
var row = new Dictionary<string, object>();
|
||||
deviceDicts.TryGetValue(variable.DeviceId, out var device);
|
||||
@@ -153,8 +153,8 @@ Dictionary<long, Channel> channelDicts)
|
||||
|
||||
static IEnumerable<Dictionary<string, object>> GetPluginSheets(
|
||||
IEnumerable<Variable> data,
|
||||
Dictionary<long, Device> deviceDicts,
|
||||
Dictionary<long, Channel> channelDicts,
|
||||
IReadOnlyDictionary<long, DeviceRuntime> deviceDicts,
|
||||
IReadOnlyDictionary<long, ChannelRuntime> channelDicts,
|
||||
string plugin,
|
||||
Dictionary<string, VariablePropertyBase> pluginDrivers,
|
||||
ConcurrentDictionary<string, (VariablePropertyBase, Dictionary<string, PropertyInfo>)> propertysDict)
|
||||
@@ -224,8 +224,8 @@ Dictionary<long, Channel> channelDicts)
|
||||
|
||||
public static Dictionary<string, object> ExportSheets(
|
||||
IAsyncEnumerable<Variable> data,
|
||||
Dictionary<long, Device> deviceDicts,
|
||||
Dictionary<long, Channel> channelDicts,
|
||||
IReadOnlyDictionary<long, DeviceRuntime> deviceDicts,
|
||||
IReadOnlyDictionary<long, ChannelRuntime> channelDicts,
|
||||
Dictionary<string, VariablePropertyBase> pluginDrivers,
|
||||
string? deviceName = null)
|
||||
{
|
||||
@@ -248,7 +248,7 @@ Dictionary<long, Channel> channelDicts)
|
||||
|
||||
static async IAsyncEnumerable<Dictionary<string, object>> GetVariableSheets(
|
||||
IAsyncEnumerable<Variable> data,
|
||||
Dictionary<long, Device> deviceDicts,
|
||||
IReadOnlyDictionary<long, DeviceRuntime> deviceDicts,
|
||||
string? deviceName)
|
||||
{
|
||||
var type = typeof(Variable);
|
||||
@@ -270,8 +270,8 @@ Dictionary<long, Channel> channelDicts)
|
||||
|
||||
static async IAsyncEnumerable<Dictionary<string, object>> GetPluginSheets(
|
||||
IAsyncEnumerable<Variable> data,
|
||||
Dictionary<long, Device> deviceDicts,
|
||||
Dictionary<long, Channel> channelDicts,
|
||||
IReadOnlyDictionary<long, DeviceRuntime> deviceDicts,
|
||||
IReadOnlyDictionary<long, ChannelRuntime> channelDicts,
|
||||
string plugin,
|
||||
Dictionary<string, VariablePropertyBase> pluginDrivers,
|
||||
ConcurrentDictionary<string, (VariablePropertyBase, Dictionary<string, PropertyInfo>)> propertysDict)
|
||||
@@ -314,14 +314,14 @@ Dictionary<long, Channel> channelDicts)
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<Dictionary<string, object>> ExportCoreAsync(IEnumerable<Variable> data, string deviceName = null, string sortName = nameof(Variable.Id), SortOrder sortOrder = SortOrder.Asc)
|
||||
public static Dictionary<string, object> ExportCore(IEnumerable<Variable> data, string deviceName = null, string sortName = nameof(Variable.Id), SortOrder sortOrder = SortOrder.Asc)
|
||||
{
|
||||
if (data?.Any() != true)
|
||||
{
|
||||
data = new List<Variable>();
|
||||
}
|
||||
var deviceDicts = (await GlobalData.DeviceService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Id);
|
||||
var channelDicts = (await GlobalData.ChannelService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Id);
|
||||
var deviceDicts = GlobalData.IdDevices;
|
||||
var channelDicts = GlobalData.IdChannels;
|
||||
var driverPluginDicts = GlobalData.PluginService.GetList(PluginTypeEnum.Business).ToDictionary(a => a.FullName);
|
||||
//总数据
|
||||
Dictionary<string, object> sheets = new();
|
||||
@@ -503,7 +503,7 @@ Dictionary<long, Channel> channelDicts)
|
||||
var dataScope = await GlobalData.SysUserService.GetCurrentUserDataScopeAsync().ConfigureAwait(false);
|
||||
|
||||
// 获取所有设备的字典,以设备名称作为键
|
||||
var deviceDicts = (await GlobalData.DeviceService.GetAllAsync().ConfigureAwait(false)).ToDictionary(a => a.Name);
|
||||
var deviceDicts = GlobalData.Devices;
|
||||
|
||||
// 存储导入检验结果的字典
|
||||
Dictionary<string, ImportPreviewOutputBase> ImportPreviews = new();
|
||||
|
@@ -752,7 +752,7 @@ EventCallback.Factory.Create<MouseEventArgs>(this, async e =>
|
||||
};
|
||||
|
||||
var models = await GlobalData.GetCurrentUserDevices().ConfigureAwait(false);
|
||||
var uSheetDatas = await DeviceServiceHelpers.ExportDeviceAsync(models);
|
||||
var uSheetDatas = DeviceServiceHelpers.ExportDevice(models);
|
||||
|
||||
op.Component = BootstrapDynamicComponent.CreateComponent<USheet>(new Dictionary<string, object?>
|
||||
{
|
||||
|
@@ -275,7 +275,7 @@ public partial class DeviceTable : IDisposable
|
||||
await ToastService.Warning("online Excel max data count 50000");
|
||||
return;
|
||||
}
|
||||
var uSheetDatas = await DeviceServiceHelpers.ExportDeviceAsync(models);
|
||||
var uSheetDatas = DeviceServiceHelpers.ExportDevice(models);
|
||||
|
||||
op.Component = BootstrapDynamicComponent.CreateComponent<USheet>(new Dictionary<string, object?>
|
||||
{
|
||||
|
@@ -331,7 +331,7 @@ public partial class VariableRuntimeInfo : IDisposable
|
||||
await ToastService.Warning("online Excel max data count 50000");
|
||||
return;
|
||||
}
|
||||
var uSheetDatas = await VariableServiceHelpers.ExportVariableAsync(models, _option.SortName, _option.SortOrder);
|
||||
var uSheetDatas = VariableServiceHelpers.ExportVariable(models, _option.SortName, _option.SortOrder);
|
||||
|
||||
op.Component = BootstrapDynamicComponent.CreateComponent<USheet>(new Dictionary<string, object?>
|
||||
{
|
||||
|
Reference in New Issue
Block a user