添加项目文件。
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using CommonDomain;
|
||||
using DotNetCore.CAP;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace UserService.Hubs
|
||||
{
|
||||
public class AdminNotifySubscriber : ICapSubscribe
|
||||
{
|
||||
private readonly IHubContext<LoginHub> _hubContext;
|
||||
private readonly ILogger<AdminNotifySubscriber> _logger;
|
||||
|
||||
public AdminNotifySubscriber(IHubContext<LoginHub> hubContext, ILogger<AdminNotifySubscriber> logger)
|
||||
{
|
||||
_hubContext = hubContext;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[CapSubscribe("BackgroundOperation.NotifyUser")]
|
||||
public async Task HandleNotify(BackgroundOperationNotifyMessage message)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(message.UserId))
|
||||
throw new InvalidOperationException("CAP消息缺少UserId");
|
||||
|
||||
|
||||
|
||||
switch (message.Action)
|
||||
{
|
||||
case "new_email":
|
||||
await _hubContext.Clients.Group(message.UserId).SendAsync("NewEmail", new { message.Title, message.EmailId });
|
||||
return;
|
||||
case "backpack_add":
|
||||
case "backpack_update":
|
||||
case "backpack_delete":
|
||||
await _hubContext.Clients.Group(message.UserId).SendAsync("BackpackUpdated", new
|
||||
{
|
||||
message.Action,
|
||||
message.PropNumber,
|
||||
message.Count
|
||||
});
|
||||
return;
|
||||
case "level_change":
|
||||
await _hubContext.Clients.Group(message.UserId).SendAsync("LevelChanged", new
|
||||
{
|
||||
NewLevel = message.NewLevel,
|
||||
NewExp = message.NewExp,
|
||||
NewGold = message.NewGold,
|
||||
NewDiamond = message.NewDiamond,
|
||||
Source = message.Source,
|
||||
Remark = message.Remark
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await _hubContext.Clients.Group(message.UserId).SendAsync("AssetUpdated", new
|
||||
{
|
||||
message.CurrencyType,
|
||||
message.ChangeType,
|
||||
message.Amount,
|
||||
message.NewGold,
|
||||
message.NewDiamond,
|
||||
message.NewLevel,
|
||||
message.NewExp,
|
||||
message.Source,
|
||||
message.Remark
|
||||
});
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "处理后台通知CAP消息失败 userId={UserId} action={Action}", message?.UserId, message?.Action);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user