using DS.Module.Core.Extensions;
using DS.Module.Core.Modules;
namespace DS.Module.Core.Data;
///
/// 实体类基类
///
public abstract class BaseModel
{
///
/// 主键ID
///
[SqlSugar.SugarColumn(IsPrimaryKey = true,Length = 100,ColumnDescription="主键ID")]
public TKey Id { get; set; }
///
/// 备注
///
public string Note { get; set; }
///
/// 创建时间
///
[SqlSugar.SugarColumn(ColumnDescription="创建时间")]
public DateTime AddTime { get; set; }
///
/// 创建人
///
[SqlSugar.SugarColumn(IsNullable = true,ColumnDescription="创建人")]
public string AddBy { get; set; }
///
/// 修改人
///
[SqlSugar.SugarColumn(IsNullable = true,ColumnDescription="修改人")]
public string UpdateBy { get; set; }
///
/// 更新时间
///
[SqlSugar.SugarColumn(ColumnDescription="更新时间")]
public DateTime UpdateTime { get; set; }
///
/// 删除
///
[SqlSugar.SugarColumn(ColumnDescription="是否删除")]
public bool Deleted { get; set; }
///
/// 删除时间
///
[SqlSugar.SugarColumn(ColumnDescription="删除时间")]
public DateTime DeleteTime { get; set; }
///
/// 删除人
///
[SqlSugar.SugarColumn(IsNullable = true,ColumnDescription="删除人")]
public string DeleteBy { get; set; }
///
///
///
public virtual void Create()
{
var user = DSIocManage.Instance.GetService();
if (typeof(TKey) == typeof(Guid))
{
this.Id = Guid.NewGuid().AsTo();
}
if (typeof(TKey) == typeof(string))
{
this.Id = GuidHelper.GetSnowflakeId().AsTo();
}
this.AddTime = DateTime.Now;
this.AddBy = user?.UserId;
this.UpdateTime = DateTime.Now;
this.UpdateBy = user?.UserId;
this.Deleted = false;
}
public virtual void Update()
{
var user = DSIocManage.Instance.GetService();
this.UpdateTime = DateTime.Now;
this.UpdateBy = user?.UserId;
}
public virtual void Delete()
{
var user = DSIocManage.Instance.GetService();
this.DeleteTime = DateTime.Now;
this.DeleteBy = user?.UserId;
this.Deleted = true;
}
}