Files
Yi.Admin/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Forum/ArticleAggregateRoot.cs

75 lines
2.3 KiB
C#
Raw Normal View History

2023-12-11 09:55:12 +08:00
using SqlSugar;
using Volo.Abp;
2023-12-11 22:14:13 +08:00
using Volo.Abp.Auditing;
2023-12-11 09:55:12 +08:00
using Volo.Abp.Domain.Entities;
2023-04-15 22:44:33 +08:00
2024-01-11 18:51:53 +08:00
namespace Yi.Framework.Bbs.Domain.Entities.Forum
2023-04-15 22:44:33 +08:00
{
[SugarTable("Article")]
2024-01-11 22:06:15 +08:00
[SugarIndex($"index_{nameof(Name)}", nameof(Name), OrderByType.Asc)]
[SugarIndex($"index_{nameof(ParentId)}", nameof(ParentId), OrderByType.Asc)]
[SugarIndex($"index_{nameof(DiscussId)}", nameof(DiscussId), OrderByType.Asc)]
2024-05-22 14:35:08 +08:00
public class ArticleAggregateRoot : AggregateRoot<Guid>, ISoftDelete, IAuditedObject
2023-04-15 22:44:33 +08:00
{
2023-12-11 09:55:12 +08:00
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
public override Guid Id { get; protected set; }
2023-04-15 22:44:33 +08:00
public bool IsDeleted { get; set; }
2023-12-11 09:55:12 +08:00
[SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString)]
2023-04-15 22:44:33 +08:00
public string Content { get; set; }
public string Name { get; set; }
2023-12-11 09:55:12 +08:00
public Guid DiscussId { get; set; }
2023-04-15 22:44:33 +08:00
2023-12-11 09:55:12 +08:00
public Guid ParentId { get; set; }
2023-04-15 22:44:33 +08:00
[SugarColumn(IsIgnore = true)]
2024-05-22 14:35:08 +08:00
public List<ArticleAggregateRoot>? Children { get; set; }
2023-12-11 22:14:13 +08:00
public DateTime CreationTime { get; set; }
public Guid? CreatorId { get; set; }
public Guid? LastModifierId { get; set; }
public DateTime? LastModificationTime { get; set; }
2024-01-05 10:47:36 +08:00
/// <summary>
/// 排序
/// </summary>
public int OrderNum { get; set; } = 0;
2023-04-15 22:44:33 +08:00
}
public static class ArticleEntityExtensions
{
/// <summary>
/// 平铺自己
/// </summary>
/// <param name="entities"></param>
/// <returns></returns>
2024-05-22 14:35:08 +08:00
public static List<ArticleAggregateRoot> Tile(this List<ArticleAggregateRoot> entities)
2023-04-15 22:44:33 +08:00
{
2024-05-22 14:35:08 +08:00
if (entities is null) return new List<ArticleAggregateRoot>();
var result = new List<ArticleAggregateRoot>();
2023-04-15 22:44:33 +08:00
return StartRecursion(entities, result);
}
2024-05-22 14:35:08 +08:00
private static List<ArticleAggregateRoot> StartRecursion(List<ArticleAggregateRoot> entities, List<ArticleAggregateRoot> result)
2023-04-15 22:44:33 +08:00
{
foreach (var entity in entities)
{
result.Add(entity);
if (entity.Children is not null && entity.Children.Where(x => x.IsDeleted == false).Count() > 0)
{
StartRecursion(entity.Children, result);
}
}
return result;
}
}
}