309 lines
12 KiB
C#
309 lines
12 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")]
|
|
public class FamilyPersonEntity : ViewEntityBase
|
|
{
|
|
|
|
public FamilyPersonEntity()
|
|
{
|
|
}
|
|
|
|
[Column("alias")]
|
|
public string? Alias { get; set; }
|
|
[Column("avatar_filename")]
|
|
public string? AvatarFilename { get; set; }
|
|
[Column("bind_user_id")]
|
|
public string? BindUserId { get; set; }
|
|
[Column("birth_date")]
|
|
public Nullable<DateTime> BirthDate { get; set; }
|
|
[Column("birth_order")]
|
|
public string? BirthOrder { get; set; }
|
|
[Column("birth_text")]
|
|
public string? BirthText { get; set; }
|
|
[Column("common_name")]
|
|
public string? CommonName { get; set; }
|
|
[Column("created_by")]
|
|
public string CreatedBy { get; set; }
|
|
[Column("created_datetime")]
|
|
public DateTime CreatedDatetime { get; set; }
|
|
[Column("death_date")]
|
|
public Nullable<DateTime> DeathDate { get; set; }
|
|
[Column("death_text")]
|
|
public string? DeathText { get; set; }
|
|
[Column("duty")]
|
|
public string? Duty { get; set; }
|
|
[Column("education")]
|
|
public string? Education { get; set; }
|
|
[Column("father_id")]
|
|
public string? FatherId { get; set; }
|
|
[Column("gender")]
|
|
public string? Gender { get; set; }
|
|
[Column("genealogy_name")]
|
|
public string? GenealogyName { get; set; }
|
|
[Column("graduation_status")]
|
|
public string? GraduationStatus { get; set; }
|
|
[Column("hao")]
|
|
public string? Hao { get; set; }
|
|
[Column("introduction")]
|
|
public string? Introduction { get; set; }
|
|
[Column("is_bind_user")]
|
|
public string? IsBindUser { get; set; }
|
|
[Column("live_status")]
|
|
public string LiveStatus { get; set; }
|
|
[Column("major")]
|
|
public string? Major { get; set; }
|
|
[Column("marital_status")]
|
|
public string? MaritalStatus { get; set; }
|
|
[Column("mother_name")]
|
|
public string? MotherName { get; set; }
|
|
[Key]
|
|
[Column("person_id")]
|
|
public string PersonId { get; set; }
|
|
[Column("privacy")]
|
|
public string? Privacy { get; set; }
|
|
[Column("school")]
|
|
public string? School { get; set; }
|
|
[Column("surname")]
|
|
public string Surname { get; set; }
|
|
[Column("title")]
|
|
public string? Title { get; set; }
|
|
[Column("tree_id")]
|
|
public string? TreeId { get; set; }
|
|
[Column("updated_by")]
|
|
public string UpdatedBy { get; set; }
|
|
[Column("updated_datetime")]
|
|
public DateTime UpdatedDatetime { get; set; }
|
|
[Column("zi")]
|
|
public string? Zi { get; set; }
|
|
|
|
public const string ALIAS = "Alias";
|
|
public const string AVATAR_FILENAME = "AvatarFilename";
|
|
public const string BIND_USER_ID = "BindUserId";
|
|
public const string BIRTH_DATE = "BirthDate";
|
|
public const string BIRTH_ORDER = "BirthOrder";
|
|
public const string BIRTH_TEXT = "BirthText";
|
|
public const string COMMON_NAME = "CommonName";
|
|
public const string CREATED_BY = "CreatedBy";
|
|
public const string CREATED_DATETIME = "CreatedDatetime";
|
|
public const string DEATH_DATE = "DeathDate";
|
|
public const string DEATH_TEXT = "DeathText";
|
|
public const string DUTY = "Duty";
|
|
public const string EDUCATION = "Education";
|
|
public const string FATHER_ID = "FatherId";
|
|
public const string GENDER = "Gender";
|
|
public const string GENEALOGY_NAME = "GenealogyName";
|
|
public const string GRADUATION_STATUS = "GraduationStatus";
|
|
public const string HAO = "Hao";
|
|
public const string INTRODUCTION = "Introduction";
|
|
public const string IS_BIND_USER = "IsBindUser";
|
|
public const string LIVE_STATUS = "LiveStatus";
|
|
public const string MAJOR = "Major";
|
|
public const string MARITAL_STATUS = "MaritalStatus";
|
|
public const string MOTHER_NAME = "MotherName";
|
|
public const string PERSON_ID = "PersonId";
|
|
public const string PRIVACY = "Privacy";
|
|
public const string SCHOOL = "School";
|
|
public const string SURNAME = "Surname";
|
|
public const string TITLE = "Title";
|
|
public const string TREE_ID = "TreeId";
|
|
public const string UPDATED_BY = "UpdatedBy";
|
|
public const string UPDATED_DATETIME = "UpdatedDatetime";
|
|
public const string ZI = "Zi";
|
|
|
|
public const string DB_NAME_FAMILY_PERSON = "family_person";
|
|
public const string DB_NAME_FIELDS="alias,avatar_filename,bind_user_id,birth_date,birth_order,birth_text,common_name,created_by,created_datetime,death_date,death_text,duty,education,father_id,gender,genealogy_name,graduation_status,hao,introduction,is_bind_user,live_status,major,marital_status,mother_name,person_id,privacy,school,surname,title,tree_id,updated_by,updated_datetime,zi";
|
|
|
|
public const string DB_ALIAS = "alias";
|
|
public const string DB_AVATAR_FILENAME = "avatar_filename";
|
|
public const string DB_BIND_USER_ID = "bind_user_id";
|
|
public const string DB_BIRTH_DATE = "birth_date";
|
|
public const string DB_BIRTH_ORDER = "birth_order";
|
|
public const string DB_BIRTH_TEXT = "birth_text";
|
|
public const string DB_COMMON_NAME = "common_name";
|
|
public const string DB_CREATED_BY = "created_by";
|
|
public const string DB_CREATED_DATETIME = "created_datetime";
|
|
public const string DB_DEATH_DATE = "death_date";
|
|
public const string DB_DEATH_TEXT = "death_text";
|
|
public const string DB_DUTY = "duty";
|
|
public const string DB_EDUCATION = "education";
|
|
public const string DB_FATHER_ID = "father_id";
|
|
public const string DB_GENDER = "gender";
|
|
public const string DB_GENEALOGY_NAME = "genealogy_name";
|
|
public const string DB_GRADUATION_STATUS = "graduation_status";
|
|
public const string DB_HAO = "hao";
|
|
public const string DB_INTRODUCTION = "introduction";
|
|
public const string DB_IS_BIND_USER = "is_bind_user";
|
|
public const string DB_LIVE_STATUS = "live_status";
|
|
public const string DB_MAJOR = "major";
|
|
public const string DB_MARITAL_STATUS = "marital_status";
|
|
public const string DB_MOTHER_NAME = "mother_name";
|
|
public const string DB_PERSON_ID = "person_id";
|
|
public const string DB_PRIVACY = "privacy";
|
|
public const string DB_SCHOOL = "school";
|
|
public const string DB_SURNAME = "surname";
|
|
public const string DB_TITLE = "title";
|
|
public const string DB_TREE_ID = "tree_id";
|
|
public const string DB_UPDATED_BY = "updated_by";
|
|
public const string DB_UPDATED_DATETIME = "updated_datetime";
|
|
public const string DB_ZI = "zi";
|
|
|
|
private string ProviderName { get; set; }
|
|
|
|
public static FamilyPersonEntity GetInstance(string providerName)
|
|
{
|
|
return new FamilyPersonEntity() { ProviderName = providerName };
|
|
}
|
|
|
|
public virtual void CopyFrom(FamilyPersonEntity source)
|
|
{
|
|
CopyFrom(source, true);
|
|
}
|
|
|
|
public virtual void CopyFrom(FamilyPersonEntity source, bool includeSystemFields)
|
|
{
|
|
if (source == null)
|
|
{
|
|
throw new NullReferenceException("Source entity is null.");
|
|
}
|
|
|
|
this.Alias = source.Alias;
|
|
this.AvatarFilename = source.AvatarFilename;
|
|
this.BindUserId = source.BindUserId;
|
|
this.BirthDate = source.BirthDate;
|
|
this.BirthOrder = source.BirthOrder;
|
|
this.BirthText = source.BirthText;
|
|
this.CommonName = source.CommonName;
|
|
this.CreatedBy = source.CreatedBy;
|
|
this.CreatedDatetime = source.CreatedDatetime;
|
|
this.DeathDate = source.DeathDate;
|
|
this.DeathText = source.DeathText;
|
|
this.Duty = source.Duty;
|
|
this.Education = source.Education;
|
|
this.FatherId = source.FatherId;
|
|
this.Gender = source.Gender;
|
|
this.GenealogyName = source.GenealogyName;
|
|
this.GraduationStatus = source.GraduationStatus;
|
|
this.Hao = source.Hao;
|
|
this.Introduction = source.Introduction;
|
|
this.IsBindUser = source.IsBindUser;
|
|
this.LiveStatus = source.LiveStatus;
|
|
this.Major = source.Major;
|
|
this.MaritalStatus = source.MaritalStatus;
|
|
this.MotherName = source.MotherName;
|
|
this.PersonId = source.PersonId;
|
|
this.Privacy = source.Privacy;
|
|
this.School = source.School;
|
|
this.Surname = source.Surname;
|
|
this.Title = source.Title;
|
|
this.TreeId = source.TreeId;
|
|
this.UpdatedBy = source.UpdatedBy;
|
|
this.UpdatedDatetime = source.UpdatedDatetime;
|
|
this.Zi = source.Zi;
|
|
|
|
if (includeSystemFields)
|
|
{
|
|
this.CreatedBy = source.CreatedBy;
|
|
this.CreatedDatetime = source.CreatedDatetime;
|
|
this.UpdatedBy = source.UpdatedBy;
|
|
this.UpdatedDatetime = source.UpdatedDatetime;
|
|
}
|
|
}
|
|
|
|
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} with(nolock) ";
|
|
}
|
|
public string GetSelectFromByBySqlServer()
|
|
{
|
|
return $" select {DB_NAME_FIELDS} from { DB_NAME_FAMILY_PERSON} ";
|
|
}
|
|
|
|
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} where 1=1 {sqlWhere}";
|
|
}
|
|
public string GetSelectCountFromBySqlServer(string sqlWhere)
|
|
{
|
|
return $" select count(*) from { DB_NAME_FAMILY_PERSON} 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_PERSON_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} 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_PERSON_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} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}";
|
|
}
|
|
|
|
public FamilyPersonEntity Clone()
|
|
{
|
|
FamilyPersonEntity result = new FamilyPersonEntity();
|
|
result.CopyFrom(this);
|
|
|
|
return result;
|
|
}
|
|
|
|
}
|
|
}
|