diff --git a/Falcon.SugarApi/DatabaseDefinitions/SugarBasicTable.cs b/Falcon.SugarApi/DatabaseDefinitions/SugarBasicTable.cs new file mode 100644 index 0000000..a089d67 --- /dev/null +++ b/Falcon.SugarApi/DatabaseDefinitions/SugarBasicTable.cs @@ -0,0 +1,49 @@ +using SqlSugar; +using System; + +namespace Falcon.SugarApi.DatabaseDefinitions +{ + /// + /// 基础表,定义表基础数据结构和构造方法 + /// + public abstract class SugarBasicTable + { + /// + /// 主键 + /// + [SugarColumn(IsPrimaryKey = true, ColumnDescription = "主键")] + public Guid Id { get; set; } = Guid.NewGuid(); + /// + /// 创建时间 + /// + [SugarColumn(IsOnlyIgnoreUpdate = true, IsNullable = true, ColumnDescription = "创建时间")] + public DateTime? CreateTime { get; set; } = DateTime.Now; + + /// + /// 记录状态 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "记录状态。有效 无效")] + public string Status { get; set; } = "有效"; + + /// + /// 将数据设置为新数据。 + /// 主要更新Id、创建时间和记录状态 + /// + /// 本条数据 + public virtual SugarBasicTable SetNew() { + this.Id = Guid.NewGuid(); + this.CreateTime = DateTime.Now; + this.Status = "有效"; + return this; + } + /// + /// 设置本条记录有效状态 + /// + /// 有效还是无效,默认有效 + /// 本条数据 + public virtual SugarBasicTable SetEnable(bool enable = true) { + this.Status = enable ? "有效" : "无效"; + return this; + } + } +}