This commit is contained in:
2026-08-31 14:42:22 +08:00
72 changed files with 2479 additions and 168 deletions
@@ -39,6 +39,13 @@ namespace GroupService.WebApi.Application.GroupInvitation
return Result.Fail<GroupInvitationResponse>(ResultCode.PERMISSION_DENIED);
}
// 检查是否已存在对该用户的未处理邀请,避免 Duplicate entry 报错
var existing = await reposity.FindByGroupIdAndUserIdAsync(groupId, userId);
if (existing != null)
{
return Result.Success(mapper.Map<GroupInvitationResponse>(existing));
}
var group = await groupReposity.FindByIdAsync(groupId);
var userProfile = new UserProfile()
@@ -66,6 +73,54 @@ namespace GroupService.WebApi.Application.GroupInvitation
return Result.Success(mapper.Map<GroupInvitationResponse>(invitation));
}
public async Task<Result<object>> CreateBatchAsync(Guid operatorId, List<Guid> userIds, Guid groupId)
{
var group = await groupReposity.FindByIdAsync(groupId);
if (group is null)
return Result.Fail(ResultCode.GROUP_NOT_FOUND);
// 校验操作者是否有权限(群成员/管理员/群主)
var operatorMember = await memberReposity.FindOneByGroupIdAndUserIdAsync(groupId, operatorId);
if (operatorMember == null)
return Result.Fail(ResultCode.PERMISSION_DENIED);
var operatorInfo = await idService.FindUserByIdAsync(operatorId);
var operatorProfile = new UserProfile()
{
Avatar = operatorInfo.Data?.Avatar,
NickName = operatorInfo.Data?.NickName ?? string.Empty
};
var groupProfile = new GroupProfile()
{
Avatar = group.Avatar,
GroupName = group.Name
};
// 批量创建邀请,跳过已存在未处理邀请的用户
foreach (var userId in userIds)
{
var existing = await reposity.FindByGroupIdAndUserIdAsync(groupId, userId);
if (existing != null)
continue;
var userRes = await idService.FindUserByIdAsync(userId);
if (!userRes.Succeeded)
continue;
var userProfile = new UserProfile()
{
Avatar = userRes.Data?.Avatar,
NickName = userRes.Data?.NickName ?? string.Empty
};
var invitation = new Domain.Entities.GroupInvitation(
groupId, groupProfile, userId, userProfile, operatorId, operatorProfile);
reposity.Create(invitation);
}
return Result.Success();
}
public async Task<Result<object>> HandleAsync(GroupInvitationHandleCommand command)
{
var invitation = await reposity.FindByIdAsync(command.InvitationId);