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 _hubContext; private readonly ILogger _logger; public AssetSyncFrontendSubscriber(IHubContext hubContext, ILogger 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); } } } }