添加项目文件。

This commit is contained in:
2026-05-09 17:06:30 +08:00
parent c60f5fe117
commit 720ef957d4
378 changed files with 14843 additions and 0 deletions
@@ -0,0 +1,24 @@
using GroupService.Domain.Events;
using IM.Commons.IntegrationEvents;
using MassTransit;
using MediatR;
namespace GroupService.WebApi.Application.EventHandler
{
public class GroupBlockHandler : INotificationHandler<GroupBlockedDomainEvent>
{
private readonly IPublishEndpoint endpoint;
public GroupBlockHandler(IPublishEndpoint endpoint)
{
this.endpoint = endpoint;
}
public async Task Handle(GroupBlockedDomainEvent notification, CancellationToken cancellationToken)
{
var groupInfo = notification.Group;
await endpoint.Publish(new GroupBlockEvent(groupInfo.Id, groupInfo.Name,
groupInfo.GroupMaster, groupInfo.Status.ToString(), groupInfo.Avatar));
}
}
}
@@ -0,0 +1,42 @@
using GroupService.Domain.Events;
using GroupService.Domain.IReposities;
using GroupService.Infrastructure;
using GroupService.WebApi.Application.GroupMember;
using GroupService.WebApi.Application.IntegrationServices;
using IM.Commons.IntegrationEvents;
using MassTransit;
using MediatR;
namespace GroupService.WebApi.Application.EventHandler
{
public class GroupCreateHandler : INotificationHandler<GroupCreateDomainEvent>
{
private readonly IPublishEndpoint endpoint;
private readonly IGroupMemberReposity reposity;
private readonly IIdentityIntegrationService service;
private readonly GroupDbContext groupDb;
public GroupCreateHandler(IPublishEndpoint endpoint, IGroupMemberReposity reposity, IIdentityIntegrationService service, GroupDbContext groupDb)
{
this.endpoint = endpoint;
this.reposity = reposity;
this.service = service;
this.groupDb = groupDb;
}
public async Task Handle(GroupCreateDomainEvent notification, CancellationToken cancellationToken)
{
var group = notification.Group;
var userInfo = await service.FindUserByIdAsync(group.GroupMaster);
string nickName = "未知昵称";
if (userInfo.Succeeded)
{
nickName = userInfo.Data.NickName;
}
reposity.Create(new Domain.Entities.GroupMember(group.GroupMaster, group.Id, userInfo.Data.NickName, userInfo.Data.Avatar, Domain.Enums.GroupMemberRole.Master));
await groupDb.SaveChangesAsync();
await endpoint.Publish(new GroupCreateEvent(group.Id, group.Name, group.GroupMaster, group.Avatar));
}
}
}
@@ -0,0 +1,50 @@
using GroupService.Domain.Events;
using GroupService.WebApi.Application.GroupRequest;
using IM.Commons;
using IM.Commons.IntegrationEvents;
using MassTransit;
using MediatR;
namespace GroupService.WebApi.Application.EventHandler
{
public class GroupInvitationEventHandler :
INotificationHandler<GroupInvitationAcceptDomainEvent>
, INotificationHandler<GroupInvitationCreateDomainEvent>
{
private readonly IPublishEndpoint endpoint;
private readonly GroupRequestService requestService;
public GroupInvitationEventHandler(IPublishEndpoint endpoint, GroupRequestService requestService)
{
this.endpoint = endpoint;
this.requestService = requestService;
}
public async Task Handle(GroupInvitationAcceptDomainEvent notification, CancellationToken cancellationToken)
{
var invitation = notification.Invitation;
var res = await requestService.CreateAsync(invitation.GroupId, invitation.UserId,
$"邀请入群"
);
await endpoint.Publish(new GroupInvitationAcceptEvent(invitation.Id, invitation.UserId, invitation.UserProfile.NickName, invitation.UserProfile.Avatar
, invitation.GroupId, invitation.GroupProfile.GroupName, invitation.GroupProfile.Avatar, invitation.OperatorId
, invitation.OperatorProfile.NickName, invitation.OperatorProfile.Avatar
), cancellationToken);
if (!res.Succeeded)
{
throw new EventHandlerException(res.Message);
}
}
public async Task Handle(GroupInvitationCreateDomainEvent notification, CancellationToken cancellationToken)
{
var invitation = notification.Invitation;
await endpoint.Publish(new GroupInvitationCreateEvent(invitation.Id, invitation.UserId, invitation.UserProfile.NickName, invitation.UserProfile.Avatar
, invitation.GroupId, invitation.GroupProfile.GroupName, invitation.GroupProfile.Avatar, invitation.OperatorId
, invitation.OperatorProfile.NickName, invitation.OperatorProfile.Avatar), cancellationToken);
}
}
}
@@ -0,0 +1,25 @@
using GroupService.Domain.Events;
using IM.Commons.IntegrationEvents;
using MassTransit;
using MediatR;
namespace GroupService.WebApi.Application.EventHandler
{
public class GroupMemberJoinedHandler : INotificationHandler<GroupMemberJoinedDomainEvent>
{
private readonly IPublishEndpoint endpoint;
public GroupMemberJoinedHandler(IPublishEndpoint endpoint)
{
this.endpoint = endpoint;
}
public async Task Handle(GroupMemberJoinedDomainEvent notification, CancellationToken cancellationToken)
{
var member = notification.Member;
await endpoint.Publish(new GroupMemberJoinedEvent(member.Id,
member.UserId, member.GroupId, member.GroupNickName, member.Avatar,
member.Role.ToString()), cancellationToken);
}
}
}
@@ -0,0 +1,29 @@
using GroupService.Domain.Events;
using IM.Commons.IntegrationEvents;
using MassTransit;
using MediatR;
namespace GroupService.WebApi.Application.EventHandler
{
public class GroupRequestDeclinedHandler : INotificationHandler<GroupJoinRequestDeclinedDomainEvent>
{
private readonly IPublishEndpoint endpoint;
public GroupRequestDeclinedHandler(IPublishEndpoint endpoint)
{
this.endpoint = endpoint;
}
public async Task Handle(GroupJoinRequestDeclinedDomainEvent notification, CancellationToken cancellationToken)
{
var request = notification.Request;
await endpoint.Publish(new GroupRequestDeclinedEvent(
request.Id, request.GroupId, request.GroupProfile.GroupName,
request.GroupProfile.Avatar, request.UserId,
request.UserProfile.NickName, request.UserProfile.Avatar,
request.OperatorId.Value,request.OperatorName,
request.OperatorAvatar, request.Description,
request.CreationTime, request.ModificationTime.Value));
}
}
}
@@ -0,0 +1,46 @@
using GroupService.Domain.Events;
using GroupService.WebApi.Application.GroupMember;
using IM.Commons;
using IM.Commons.IntegrationEvents;
using MassTransit;
using MediatR;
namespace GroupService.WebApi.Application.EventHandler
{
public class GroupRequestPassedHandler : INotificationHandler<GroupJoinRequestPassedDomainEvent>
{
private readonly IPublishEndpoint endpoint;
private readonly Application.GroupMember.GroupMemberService memberService;
private readonly ILogger<GroupRequestPassedHandler> logger;
public GroupRequestPassedHandler(IPublishEndpoint endpoint,
GroupMemberService memberService, ILogger<GroupRequestPassedHandler> logger)
{
this.endpoint = endpoint;
this.memberService = memberService;
this.logger = logger;
}
public async Task Handle(GroupJoinRequestPassedDomainEvent notification, CancellationToken cancellationToken)
{
var request = notification.Request;
var memberCreateRes = await memberService.CreateAsync(request.GroupId, request.UserId);
await endpoint.Publish(new GroupRequestPassedEvent(request.Id, request.GroupId, request.GroupProfile.GroupName,
request.GroupProfile.Avatar, request.UserId,
request.UserProfile.NickName, request.UserProfile.Avatar,
request.OperatorId.Value, request.OperatorName,
request.OperatorAvatar, request.Description,
request.CreationTime, request.ModificationTime.Value));
if (!memberCreateRes.Succeeded)
{
logger.LogError(memberCreateRes.Message);
throw new EventHandlerException(memberCreateRes.Message);
}
}
}
}
@@ -0,0 +1,32 @@
using GroupService.Domain.IReposities;
using GroupService.Infrastructure;
using IM.Commons.IntegrationEvents;
using MassTransit;
namespace GroupService.WebApi.Application.EventHandler
{
public class MessageCreatedHandler : IConsumer<MsgCreatedEvent>
{
private readonly IGroupReposity reposity;
private readonly GroupDbContext groupDb;
public MessageCreatedHandler(IGroupReposity reposity, GroupDbContext groupDb)
{
this.reposity = reposity;
this.groupDb = groupDb;
}
public async Task Consume(ConsumeContext<MsgCreatedEvent> context)
{
var @event = context.Message;
if(@event.MsgType == "GROUP")
{
var group = await reposity.FindByIdAsync(@event.TargetId);
if (group is null) return;
group.UpdateLastMsg(@event.SequenceId, @event.Content.Fallback, "未知用户");
groupDb.Groups.Update(group);
await groupDb.SaveChangesAsync();
}
}
}
}
@@ -0,0 +1,31 @@
using GroupService.Domain.IReposities;
using GroupService.Infrastructure;
using IM.Commons.IntegrationEvents;
using MassTransit;
namespace GroupService.WebApi.Application.EventHandler
{
public class UserProfileUpdateHandler : IConsumer<UserProfileUpdateEvent>
{
private readonly GroupDbContext db;
private readonly IGroupMemberReposity memberReposity;
public UserProfileUpdateHandler(GroupDbContext db, IGroupMemberReposity memberReposity)
{
this.db = db;
this.memberReposity = memberReposity;
}
public async Task Consume(ConsumeContext<UserProfileUpdateEvent> context)
{
var @event = context.Message;
var members = await memberReposity.FindByUserIdAsync(@event.UserId);
foreach (var member in members)
{
member.UpdateAvatar(@event.Avatar);
}
await db.SaveChangesAsync();
}
}
}