195 lines
7.1 KiB
C#
195 lines
7.1 KiB
C#
|
|
using CloudBuilder.Core.Authorization;
|
|
using CloudBuilder.Core.DatabaseAccessor.Entity;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
namespace CloudBuilder.Master.Entity
|
|
{
|
|
[TypeScript]
|
|
[Table("family_person_log")]
|
|
public class FamilyPersonLogEntity : ViewEntityBase
|
|
{
|
|
|
|
public FamilyPersonLogEntity()
|
|
{
|
|
}
|
|
|
|
[Column("created_datetime")]
|
|
public DateTime CreatedDatetime { get; set; }
|
|
[Column("created_by")]
|
|
public string CreatedBy { get; set; }
|
|
[Column("updated_datetime")]
|
|
public DateTime UpdatedDatetime { get; set; }
|
|
[Column("updated_by")]
|
|
public string UpdatedBy { get; set; }
|
|
[Key]
|
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
[Column("log_id")]
|
|
public long LogId { get; set; }
|
|
[Column("person_id")]
|
|
public string PersonId { get; set; }
|
|
[Column("audit_code")]
|
|
public string AuditCode { get; set; }
|
|
[Column("event_actor")]
|
|
public string EventActor { get; set; }
|
|
[Column("old_value")]
|
|
public string? OldValue { get; set; }
|
|
[Column("new_value")]
|
|
public string? NewValue { get; set; }
|
|
|
|
public const string CREATED_DATETIME = "CreatedDatetime";
|
|
public const string CREATED_BY = "CreatedBy";
|
|
public const string UPDATED_DATETIME = "UpdatedDatetime";
|
|
public const string UPDATED_BY = "UpdatedBy";
|
|
public const string LOG_ID = "LogId";
|
|
public const string PERSON_ID = "PersonId";
|
|
public const string AUDIT_CODE = "AuditCode";
|
|
public const string EVENT_ACTOR = "EventActor";
|
|
public const string OLD_VALUE = "OldValue";
|
|
public const string NEW_VALUE = "NewValue";
|
|
|
|
public const string DB_NAME_FAMILY_PERSON_LOG = "family_person_log";
|
|
public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,log_id,person_id,audit_code,event_actor,old_value,new_value";
|
|
|
|
public const string DB_CREATED_DATETIME = "created_datetime";
|
|
public const string DB_CREATED_BY = "created_by";
|
|
public const string DB_UPDATED_DATETIME = "updated_datetime";
|
|
public const string DB_UPDATED_BY = "updated_by";
|
|
public const string DB_LOG_ID = "log_id";
|
|
public const string DB_PERSON_ID = "person_id";
|
|
public const string DB_AUDIT_CODE = "audit_code";
|
|
public const string DB_EVENT_ACTOR = "event_actor";
|
|
public const string DB_OLD_VALUE = "old_value";
|
|
public const string DB_NEW_VALUE = "new_value";
|
|
|
|
private string ProviderName { get; set; }
|
|
|
|
public static FamilyPersonLogEntity GetInstance(string providerName)
|
|
{
|
|
return new FamilyPersonLogEntity() { ProviderName = providerName };
|
|
}
|
|
|
|
public virtual void CopyFrom(FamilyPersonLogEntity source)
|
|
{
|
|
CopyFrom(source, true);
|
|
}
|
|
|
|
public virtual void CopyFrom(FamilyPersonLogEntity source, bool includeSystemFields)
|
|
{
|
|
if (source == null)
|
|
{
|
|
throw new NullReferenceException("Source entity is null.");
|
|
}
|
|
|
|
this.CreatedDatetime = source.CreatedDatetime;
|
|
this.CreatedBy = source.CreatedBy;
|
|
this.UpdatedDatetime = source.UpdatedDatetime;
|
|
this.UpdatedBy = source.UpdatedBy;
|
|
this.LogId = source.LogId;
|
|
this.PersonId = source.PersonId;
|
|
this.AuditCode = source.AuditCode;
|
|
this.EventActor = source.EventActor;
|
|
this.OldValue = source.OldValue;
|
|
this.NewValue = source.NewValue;
|
|
|
|
if (includeSystemFields)
|
|
{
|
|
this.CreatedDatetime = source.CreatedDatetime;
|
|
this.CreatedBy = source.CreatedBy;
|
|
this.UpdatedDatetime = source.UpdatedDatetime;
|
|
this.UpdatedBy = source.UpdatedBy;
|
|
}
|
|
}
|
|
|
|
public override string GetSelectFrom()
|
|
{
|
|
if (ProviderName.Contains("MySql"))
|
|
{
|
|
return GetSelectFromByMySql();
|
|
}
|
|
else if (ProviderName.Contains("SqlServer"))
|
|
{
|
|
return GetSelectFromByBySqlServer();
|
|
}
|
|
else
|
|
{
|
|
throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}");
|
|
}
|
|
}
|
|
public string GetSelectFromByMySql()
|
|
{
|
|
return $" select {DB_NAME_FIELDS} from { DB_NAME_FAMILY_PERSON_LOG} with(nolock) ";
|
|
}
|
|
public string GetSelectFromByBySqlServer()
|
|
{
|
|
return $" select {DB_NAME_FIELDS} from { DB_NAME_FAMILY_PERSON_LOG} ";
|
|
}
|
|
|
|
public override string GetSelectCountFrom(string sqlWhere)
|
|
{
|
|
if (ProviderName.Contains("MySql"))
|
|
{
|
|
return GetSelectCountFromByMySql(sqlWhere);
|
|
}
|
|
else if (ProviderName.Contains("SqlServer"))
|
|
{
|
|
return GetSelectCountFromBySqlServer(sqlWhere);
|
|
}
|
|
else
|
|
{
|
|
throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}");
|
|
}
|
|
}
|
|
|
|
public string GetSelectCountFromByMySql(string sqlWhere)
|
|
{
|
|
return $" select count(*) from { DB_NAME_FAMILY_PERSON_LOG} where 1=1 {sqlWhere}";
|
|
}
|
|
public string GetSelectCountFromBySqlServer(string sqlWhere)
|
|
{
|
|
return $" select count(*) from { DB_NAME_FAMILY_PERSON_LOG} with(nolock) where 1=1 {sqlWhere}";
|
|
}
|
|
|
|
public override string GetSelectTopFrom(int limit, int start, string orderby, string orderbytag, string sqlWhere)
|
|
{
|
|
if (ProviderName.Contains("MySql"))
|
|
{
|
|
return GetSelectTopFromByMySql(limit, start, orderby, orderbytag, sqlWhere);
|
|
}
|
|
else if (ProviderName.Contains("SqlServer"))
|
|
{
|
|
return GetSelectTopFromBySqlServer(limit, start, orderby, orderbytag, sqlWhere);
|
|
}
|
|
else
|
|
{
|
|
throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}");
|
|
}
|
|
}
|
|
|
|
public string GetSelectTopFromByMySql(int limit, int start,string orderby,string orderbytag, string sqlWhere)
|
|
{
|
|
if (string.IsNullOrEmpty(orderbytag) || orderbytag.Trim() != "desc") orderbytag = "asc";
|
|
if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_LOG_ID ;
|
|
int offset = limit * (start - 1);
|
|
return $" select {DB_NAME_FIELDS} from (select {DB_NAME_FIELDS} ,row_number() over(order by {orderby} {orderbytag}) as num from { DB_NAME_FAMILY_PERSON_LOG} where 1=1 {sqlWhere} ) a where num> {offset} LIMIT {limit} ";
|
|
}
|
|
|
|
public string GetSelectTopFromBySqlServer(int limit, int start,string orderby,string orderbytag, string sqlWhere)
|
|
{
|
|
if (string.IsNullOrEmpty(orderbytag) || orderbytag.Trim() != "desc") orderbytag = "asc";
|
|
if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_LOG_ID ;
|
|
string top = limit > 0 ? $"top {limit}" : "";
|
|
return $" select {top} {DB_NAME_FIELDS} from (select {DB_NAME_FIELDS} ,row_number() over(order by {orderby} {orderbytag}) as num from { DB_NAME_FAMILY_PERSON_LOG} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}";
|
|
}
|
|
|
|
public FamilyPersonLogEntity Clone()
|
|
{
|
|
FamilyPersonLogEntity result = new FamilyPersonLogEntity();
|
|
result.CopyFrom(this);
|
|
|
|
return result;
|
|
}
|
|
|
|
}
|
|
}
|