using GroupService.Domain.Enums; using GroupService.Domain.Events; using GroupService.Domain.ValueObjects; using IM.DomainCommons; namespace GroupService.Domain.Entities { public class GroupJoinRequest : AggregateRootEntity { /// /// 群聊编号 /// /// public Guid GroupId { get; private set; } public GroupProfile GroupProfile { get; private set; } /// /// 申请人 /// public Guid UserId { get; private set; } public UserProfile UserProfile { get; private set; } public Guid? OperatorId { get; private set; } public string? OperatorName { get; private set; } public string? OperatorAvatar { get; private set; } /// /// 申请状态(0:待管理员同意,1:已拒绝,2:已同意) /// public GroupJoinRequestState State { get; private set; } = GroupJoinRequestState.Pending; /// /// 入群附言 /// public string Description { get; private set; } = "申请入群"; private GroupJoinRequest() { } public GroupJoinRequest(Guid userId, UserProfile user, Guid groupId, GroupProfile group, string? desc) { UserId = userId; GroupId = groupId; GroupProfile = group; UserProfile = user; if (desc is not null && desc.Length > 20) { throw new DomainException("入群描述不可超过20字符"); } Description = desc ?? Description; } public void Approve(Guid id, string nickName, string avatar) { if (State != GroupJoinRequestState.Pending) return; State = GroupJoinRequestState.Passed; OperatorAvatar = avatar; OperatorId = id; OperatorName = nickName; ModificationTime = DateTime.Now; AddDomainEvent(new GroupJoinRequestPassedDomainEvent(this)); } public void Decline(Guid id, string nickName, string avatar) { if (State != GroupJoinRequestState.Pending) return; State = GroupJoinRequestState.Declined; OperatorAvatar = avatar; OperatorId = id; OperatorName = nickName; ModificationTime = DateTime.Now; AddDomainEvent(new GroupJoinRequestDeclinedDomainEvent(this)); } } }