first commit
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using F9WebAiTest.Domain.Enums.SYS.Departments;
|
||||
using F9WebAiTest.Domain.Events.SYS.Departments;
|
||||
|
||||
namespace F9WebAiTest.Domain.Entities.SYS.Departments;
|
||||
|
||||
/// <summary>
|
||||
/// 部门:用户与部门是独立聚合,仅保存 DepartmentId 关联(避免双向强耦合)。
|
||||
/// 部门用户列表仅用于查询展示,通过读模型实现。
|
||||
/// </summary>
|
||||
[Table(Name = "sys_departments")]
|
||||
public class Department : AggregateRoot
|
||||
{
|
||||
[Column(Name = "code")]
|
||||
public string Code { get; private set; }
|
||||
|
||||
[Column(Name = "name")]
|
||||
public string Name { get; private set; }
|
||||
|
||||
[Column(Name = "parent_id")]
|
||||
public long ParentId { get; private set; }
|
||||
|
||||
[Column(Name = "manage_type")]
|
||||
public Department_ManageType_Enum ManageType { get; private set; }
|
||||
|
||||
[Column(Name = "duty_type")]
|
||||
public Department_DutyType_Enum DutyType { get; private set; }
|
||||
|
||||
[Column(Name = "description")]
|
||||
public string? Description { get; private set; }
|
||||
|
||||
[Column(Name = "is_active")]
|
||||
public bool IsActive { get; private set; }
|
||||
|
||||
[Column(Name = "sort_order")]
|
||||
public int SortOrder { get; private set; }
|
||||
|
||||
private readonly List<long> _userIds = [];
|
||||
public IReadOnlyCollection<long> UserIds => _userIds.AsReadOnly();
|
||||
|
||||
public Department() { }
|
||||
|
||||
public Department(long id, string code, string name, long parentId,
|
||||
Department_ManageType_Enum manageType, Department_DutyType_Enum dutyType, int sortOrder, string? description = null)
|
||||
{
|
||||
Id = id;
|
||||
Code = code;
|
||||
Name = name;
|
||||
ParentId = parentId;
|
||||
ManageType = manageType;
|
||||
DutyType = dutyType;
|
||||
SortOrder = sortOrder;
|
||||
Description = description;
|
||||
IsActive = true;
|
||||
AddDomainEvent(new Department_ChangedDomainEvent(Id));
|
||||
}
|
||||
|
||||
public void AddUser(long userId)
|
||||
{
|
||||
if (!_userIds.Contains(userId))
|
||||
_userIds.Add(userId);
|
||||
}
|
||||
|
||||
public void RemoveUser(long userId) => _userIds.Remove(userId);
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
IsActive = true;
|
||||
AddDomainEvent(new Department_ChangedDomainEvent(Id));
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
IsActive = false;
|
||||
AddDomainEvent(new Department_ChangedDomainEvent(Id));
|
||||
}
|
||||
|
||||
public void Deleted() => AddDomainEvent(new Department_ChangedDomainEvent(Id));
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
|
||||
namespace F9WebAiTest.Domain.Entities.SYS.Departments;
|
||||
|
||||
/// <summary>部门用户关联:部门与用户的关联记录。</summary>
|
||||
[Table(Name = "sys_department_users")]
|
||||
public class DepartmentUser : BusinessEntity
|
||||
{
|
||||
[Column(Name = "department_id")]
|
||||
public long DepartmentId { get; private set; }
|
||||
|
||||
[Column(Name = "user_id")]
|
||||
public long UserId { get; private set; }
|
||||
|
||||
[Column(Name = "assigned_at")]
|
||||
public DateTime AssignedAt { get; private set; }
|
||||
|
||||
public DepartmentUser() { }
|
||||
|
||||
public DepartmentUser(long id, long departmentId, long userId)
|
||||
{
|
||||
Id = id;
|
||||
DepartmentId = departmentId;
|
||||
UserId = userId;
|
||||
AssignedAt = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user