using NCC.Common.Const;
using NCC.Dependency;
using SqlSugar;
using System;
using Yitter.IdGenerator;
namespace NCC.Common.Entity
{
///
/// 创更删实体基类
///
[SuppressSniffer]
public abstract class CLDEntityBase : EntityBase, ICreatorTime, IDeleteTime
{
///
/// 获取或设置 创建时间
///
[SugarColumn(ColumnName = "F_CREATORTIME", ColumnDescription = "创建时间")]
public virtual DateTime? CreatorTime { get; set; }
///
/// 获取或设置 创建用户
///
[SugarColumn(ColumnName = "F_CREATORUSERID", ColumnDescription = "创建用户")]
public virtual string CreatorUserId { get; set; }
///
/// 获取或设置 启用标识
///
[SugarColumn(ColumnName = "F_ENABLEDMARK", ColumnDescription = "启用标识", IsNullable = true)]
public virtual int? EnabledMark { get; set; }
///
/// 获取或设置 修改时间
///
[SugarColumn(ColumnName = "F_LastModifyTime", ColumnDescription = "修改时间")]
public virtual DateTime? LastModifyTime { get; set; }
///
/// 获取或设置 修改用户
///
[SugarColumn(ColumnName = "F_LastModifyUserId", ColumnDescription = "修改用户")]
public virtual string LastModifyUserId { get; set; }
///
/// 获取或设置 删除标志
///
[SugarColumn(ColumnName = "F_DeleteMark", ColumnDescription = "删除标志")]
public virtual int? DeleteMark { get; set; }
///
/// 获取或设置 删除时间
///
[SugarColumn(ColumnName = "F_DeleteTime", ColumnDescription = "删除时间", IsNullable = true)]
public virtual DateTime? DeleteTime { get; set; }
///
/// 获取或设置 删除用户
///
[SugarColumn(ColumnName = "F_DeleteUserId", ColumnDescription = "删除用户", IsNullable = true)]
public virtual string DeleteUserId { get; set; }
///
/// 创建
///
public virtual void Creator()
{
var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
this.CreatorTime = DateTime.Now;
this.Id = YitIdHelper.NextId().ToString();
this.EnabledMark = this.EnabledMark == null ? 1 : this.EnabledMark;
if (!string.IsNullOrEmpty(userId))
{
this.CreatorUserId = userId;
}
}
///
/// 创建
///
public virtual void Create()
{
var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
this.CreatorTime = DateTime.Now;
this.Id = this.Id == null ? YitIdHelper.NextId().ToString() : this.Id;
this.EnabledMark = this.EnabledMark == null ? 1 : this.EnabledMark;
if (!string.IsNullOrEmpty(userId))
{
this.CreatorUserId = CreatorUserId == null ? userId : CreatorUserId;
}
}
///
/// 修改
///
public virtual void LastModify()
{
var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
this.LastModifyTime = DateTime.Now;
if (!string.IsNullOrEmpty(userId))
{
this.LastModifyUserId = userId;
}
}
///
/// 删除
///
public virtual void Delete()
{
var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
this.DeleteTime = DateTime.Now;
this.DeleteMark = 1;
if (!string.IsNullOrEmpty(userId))
{
this.DeleteUserId = userId;
}
}
}
}