Files
ThingsGateway/src/Admin/ThingsGateway.Admin.Application/Util/VerificatInfoUtil.cs
2025-06-11 10:26:48 +08:00

64 lines
2.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//------------------------------------------------------------------------------
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
// 此代码版权除特别声明外的代码归作者本人Diego所有
// 源代码使用协议遵循本仓库的开源协议及附加协议
// Gitee源代码仓库https://gitee.com/diego2098/ThingsGateway
// Github源代码仓库https://github.com/kimdiego2098/ThingsGateway
// 使用文档https://thingsgateway.cn/
// QQ群605534569
//------------------------------------------------------------------------------
using ThingsGateway.Extension.Generic;
using ThingsGateway.SqlSugar;
namespace ThingsGateway.Admin.Application;
public static class VerificatInfoUtil
{
private static IVerificatInfoService VerificatInfoService { get; set; }
static VerificatInfoUtil()
{
VerificatInfoService = App.GetService<IVerificatInfoService>();
}
#region
/// <summary>
/// 更新cache
/// </summary>
/// <param name="clientId">事件用户id</param>
/// <param name="verificatId">上线时的验证id</param>
/// <param name="isConnect">上线</param>
public static void UpdateVerificat(string clientId, long verificatId = 0, bool isConnect = true)
{
if (!clientId.IsNullOrEmpty())
{
//获取cache当前用户的verificat信息列表
if (isConnect)
{
//获取cache中当前verificat
var verificatInfo = VerificatInfoService.GetOne(verificatId);
if (verificatInfo != null)
{
verificatInfo.ClientIds.Add(clientId);//添加到客户端列表
VerificatInfoService.Update(verificatInfo);//更新Cache
}
}
else
{
//获取当前客户端ID所在的verificat信息
var verificatInfo = VerificatInfoService.GetOne(verificatId);
if (verificatInfo != null)
{
verificatInfo.ClientIds.RemoveWhere(it => it == clientId);//从客户端列表删除
VerificatInfoService.Update(verificatInfo);//更新Cache
}
}
}
}
#endregion
}