47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using CommonDomain;
|
|
using CommonDomain.BaseModel;
|
|
using DotNetCore.CAP;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace UserService.Hubs
|
|
{
|
|
public class AssetSyncFrontendSubscriber : ICapSubscribe
|
|
{
|
|
private readonly IHubContext<LoginHub> _hubContext;
|
|
private readonly ILogger<AssetSyncFrontendSubscriber> _logger;
|
|
|
|
public AssetSyncFrontendSubscriber(IHubContext<LoginHub> hubContext, ILogger<AssetSyncFrontendSubscriber> logger)
|
|
{
|
|
_hubContext = hubContext;
|
|
_logger = logger;
|
|
}
|
|
|
|
[CapSubscribe(TopicKeys.用户资产同步前端)]
|
|
public async Task HandleUserAssetSync(UserAssetSyncParam param)
|
|
{
|
|
if (param == null || string.IsNullOrWhiteSpace(param.UserId))
|
|
return;
|
|
|
|
try
|
|
{
|
|
await _hubContext.Clients.Group(param.UserId).SendAsync("AssetUpdated", new
|
|
{
|
|
param.CurrencyType,
|
|
param.ChangeType,
|
|
param.Amount,
|
|
param.NewGold,
|
|
param.NewDiamond,
|
|
param.Source,
|
|
param.Remark
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "AssetUpdated推送失败 userId={UserId} currencyType={CurrencyType}",
|
|
param.UserId, param.CurrencyType);
|
|
}
|
|
}
|
|
}
|
|
}
|