SugarBasicTable 基础表增加时间,和实现ICreateNew
This commit is contained in:
		
							parent
							
								
									82745b15fc
								
							
						
					
					
						commit
						9a200420a9
					
				@ -6,7 +6,7 @@ namespace Falcon.SugarApi.DatabaseDefinitions
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 基础表,定义表基础数据结构和构造方法
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public abstract class SugarBasicTable
 | 
			
		||||
    public abstract class SugarBasicTable : ICreateNew
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 主键
 | 
			
		||||
@ -19,14 +19,20 @@ namespace Falcon.SugarApi.DatabaseDefinitions
 | 
			
		||||
        [SugarColumn(IsOnlyIgnoreUpdate = true, IsNullable = false, ColumnDescription = "创建时间")]
 | 
			
		||||
        public DateTime CreateTime { get; set; } = DateTime.Now;
 | 
			
		||||
 | 
			
		||||
        /// <inheritdoc/>
 | 
			
		||||
        public void CreateNew(string createBy) {
 | 
			
		||||
            this.SetNew();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 将数据设置为新数据。
 | 
			
		||||
        /// <para>主要更新Id、创建时间和记录状态</para>
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="now">当前时间,如果采用非本机时间可以提供</param>
 | 
			
		||||
        /// <returns>本条数据</returns>
 | 
			
		||||
        public virtual SugarBasicTable SetNew() {
 | 
			
		||||
        public virtual SugarBasicTable SetNew(DateTime? now = null) {
 | 
			
		||||
            this.Id = Guid.NewGuid();
 | 
			
		||||
            this.CreateTime = DateTime.Now;
 | 
			
		||||
            this.CreateTime = now ?? DateTime.Now;
 | 
			
		||||
            return this;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user