TreeEntity.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #nullable enable
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. using Abp.Domain.Entities.Auditing;
  5. using VberZero.BaseSystem.Users;
  6. namespace VberZero.BaseSystem;
  7. public abstract class TreeEntity<TEntity> : TreeEntity<int, TEntity>
  8. where TEntity : class
  9. {
  10. }
  11. public abstract class TreeEntity<TPrimaryKey, TEntity> : TreeEntityBase<TPrimaryKey?>
  12. where TEntity : class
  13. {
  14. [ForeignKey("ParentNo")]
  15. public TEntity Parent { get; set; }
  16. }
  17. public abstract class TreeEntityBase<TPrimaryKey> : AuditedEntity<TPrimaryKey, User>
  18. {
  19. public const int MaxDepth = 20;
  20. public const int PathMaxLength = 15 * MaxDepth;
  21. /// <summary>
  22. /// 父节点
  23. /// </summary>
  24. public TPrimaryKey? ParentNo { get; set; }
  25. /// <summary>
  26. /// 路径
  27. /// </summary>
  28. [StringLength(PathMaxLength)]
  29. public string Path { get; set; }
  30. /// <summary>
  31. /// 是否是叶子节点
  32. /// </summary>
  33. public bool IsLeaf { get; set; }
  34. /// <summary>
  35. /// 节点深度
  36. /// </summary>
  37. public int Depth { get; set; }
  38. public int Sort { get; set; }
  39. }