This commit is contained in:
owenchen committed 2026-08-28 17:02:34 +08:00
1 parent c253805122
commit 7df55a11bf
46 files changed
+3689 -27

No files matched your search

@@ -0,0 +1,48 @@
using CloudBuilder.Core.DependencyInjection.EFCore;
using Microsoft.EntityFrameworkCore;
using System.Reflection;
namespace CloudBuilder.Master.Entity
{
public class CloudBuilderMasterRegistEntity : IMasterRegistEntityType<ModelBuilder>
{
///<summary>
///注入模块内的所有实体类
///</summary>
///<param name="builder"></param>
public void RegistEntity(ModelBuilder builder)
{
string _assemblyName = Assembly.GetExecutingAssembly().GetName().Name;
//注入所有Entity实体类
AddEntityType(builder, _assemblyName);
//如果Entity实体类不是单一主键,要单独重写注入
RegistKeys(builder);
}
public void AddEntityType(ModelBuilder builder, string _assemblyName)
{
RegistEntityHelper.AddMasterEntityType(builder, _assemblyName);
}
///<summary>
///如果存在多个主键的,要在RegistKeys方法注入
///builder.Entity<xxxxxxEntity>().HasKey(c => new { c.TableName, c.FieldName });
///builder.Entity<xxxxxxEntity>(eb => { eb.HasNoKey(); });
///</summary>
///<param name="builder"></param>
public void RegistKeys(ModelBuilder builder)
{
//***BEGIN***
builder.Entity<FamilyTreeChildrenMapEntity>().HasKey(c => new {c.TreeId,c.PersonId,c.ChildrenId});
builder.Entity<FamilyTreeSpouseMapEntity>().HasKey(c => new {c.TreeId,c.PersonId,c.SpouseId});
//***END***
}
}
}
@@ -0,0 +1,303 @@
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("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]
[Column("person_id")]
public string PersonId { get; set; }
[Column("avatar_filename")]
public string? AvatarFilename { get; set; }
[Column("surname")]
public string Surname { get; set; }
[Column("genealogy_name")]
public string? GenealogyName { get; set; }
[Column("common_name")]
public string? CommonName { get; set; }
[Column("alias")]
public string? Alias { get; set; }
[Column("zi")]
public string? Zi { get; set; }
[Column("hao")]
public string? Hao { get; set; }
[Column("father_id")]
public string? FatherId { get; set; }
[Column("mother_name")]
public string? MotherName { get; set; }
[Column("birth_order")]
public string? BirthOrder { get; set; }
[Column("gender")]
public string? Gender { get; set; }
[Column("marital_status")]
public string? MaritalStatus { get; set; }
[Column("school")]
public string? School { get; set; }
[Column("major")]
public string? Major { get; set; }
[Column("education")]
public string? Education { get; set; }
[Column("graduation_status")]
public string? GraduationStatus { get; set; }
[Column("duty")]
public string? Duty { get; set; }
[Column("title")]
public string? Title { get; set; }
[Column("birth_text")]
public string? BirthText { get; set; }
[Column("birth_date")]
public Nullable<DateTime> BirthDate { get; set; }
[Column("death_text")]
public string? DeathText { get; set; }
[Column("death_date")]
public Nullable<DateTime> DeathDate { get; set; }
[Column("privacy")]
public string? Privacy { get; set; }
[Column("live_status")]
public string LiveStatus { get; set; }
[Column("introduction")]
public string? Introduction { get; set; }
[Column("is_bind_user")]
public string? IsBindUser { get; set; }
[Column("bind_user_id")]
public string? BindUserId { 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 PERSON_ID = "PersonId";
public const string AVATAR_FILENAME = "AvatarFilename";
public const string SURNAME = "Surname";
public const string GENEALOGY_NAME = "GenealogyName";
public const string COMMON_NAME = "CommonName";
public const string ALIAS = "Alias";
public const string ZI = "Zi";
public const string HAO = "Hao";
public const string FATHER_ID = "FatherId";
public const string MOTHER_NAME = "MotherName";
public const string BIRTH_ORDER = "BirthOrder";
public const string GENDER = "Gender";
public const string MARITAL_STATUS = "MaritalStatus";
public const string SCHOOL = "School";
public const string MAJOR = "Major";
public const string EDUCATION = "Education";
public const string GRADUATION_STATUS = "GraduationStatus";
public const string DUTY = "Duty";
public const string TITLE = "Title";
public const string BIRTH_TEXT = "BirthText";
public const string BIRTH_DATE = "BirthDate";
public const string DEATH_TEXT = "DeathText";
public const string DEATH_DATE = "DeathDate";
public const string PRIVACY = "Privacy";
public const string LIVE_STATUS = "LiveStatus";
public const string INTRODUCTION = "Introduction";
public const string IS_BIND_USER = "IsBindUser";
public const string BIND_USER_ID = "BindUserId";
public const string DB_NAME_FAMILY_PERSON = "family_person";
public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,person_id,avatar_filename,surname,genealogy_name,common_name,alias,zi,hao,father_id,mother_name,birth_order,gender,marital_status,school,major,education,graduation_status,duty,title,birth_text,birth_date,death_text,death_date,privacy,live_status,introduction,is_bind_user,bind_user_id";
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_PERSON_ID = "person_id";
public const string DB_AVATAR_FILENAME = "avatar_filename";
public const string DB_SURNAME = "surname";
public const string DB_GENEALOGY_NAME = "genealogy_name";
public const string DB_COMMON_NAME = "common_name";
public const string DB_ALIAS = "alias";
public const string DB_ZI = "zi";
public const string DB_HAO = "hao";
public const string DB_FATHER_ID = "father_id";
public const string DB_MOTHER_NAME = "mother_name";
public const string DB_BIRTH_ORDER = "birth_order";
public const string DB_GENDER = "gender";
public const string DB_MARITAL_STATUS = "marital_status";
public const string DB_SCHOOL = "school";
public const string DB_MAJOR = "major";
public const string DB_EDUCATION = "education";
public const string DB_GRADUATION_STATUS = "graduation_status";
public const string DB_DUTY = "duty";
public const string DB_TITLE = "title";
public const string DB_BIRTH_TEXT = "birth_text";
public const string DB_BIRTH_DATE = "birth_date";
public const string DB_DEATH_TEXT = "death_text";
public const string DB_DEATH_DATE = "death_date";
public const string DB_PRIVACY = "privacy";
public const string DB_LIVE_STATUS = "live_status";
public const string DB_INTRODUCTION = "introduction";
public const string DB_IS_BIND_USER = "is_bind_user";
public const string DB_BIND_USER_ID = "bind_user_id";
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.CreatedDatetime = source.CreatedDatetime;
this.CreatedBy = source.CreatedBy;
this.UpdatedDatetime = source.UpdatedDatetime;
this.UpdatedBy = source.UpdatedBy;
this.PersonId = source.PersonId;
this.AvatarFilename = source.AvatarFilename;
this.Surname = source.Surname;
this.GenealogyName = source.GenealogyName;
this.CommonName = source.CommonName;
this.Alias = source.Alias;
this.Zi = source.Zi;
this.Hao = source.Hao;
this.FatherId = source.FatherId;
this.MotherName = source.MotherName;
this.BirthOrder = source.BirthOrder;
this.Gender = source.Gender;
this.MaritalStatus = source.MaritalStatus;
this.School = source.School;
this.Major = source.Major;
this.Education = source.Education;
this.GraduationStatus = source.GraduationStatus;
this.Duty = source.Duty;
this.Title = source.Title;
this.BirthText = source.BirthText;
this.BirthDate = source.BirthDate;
this.DeathText = source.DeathText;
this.DeathDate = source.DeathDate;
this.Privacy = source.Privacy;
this.LiveStatus = source.LiveStatus;
this.Introduction = source.Introduction;
this.IsBindUser = source.IsBindUser;
this.BindUserId = source.BindUserId;
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} 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;
}
}
}
@@ -0,0 +1,194 @@
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;
}
}
}
@@ -0,0 +1,192 @@
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_tree_children_map")]
public class FamilyTreeChildrenMapEntity : EntityBase<FamilyTreeChildrenMapEntityKey>
{
public FamilyTreeChildrenMapEntity()
{
}
[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; }
[Column("tree_id")]
public string TreeId { get; set; }
[Column("person_id")]
public string PersonId { get; set; }
[Column("spouse_id")]
public string SpouseId { get; set; }
[Column("children_id")]
public string ChildrenId { get; set; }
[Column("relation_type")]
public string? RelationType { get; set; }
[Column("remark")]
public string? Remark { 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 TREE_ID = "TreeId";
public const string PERSON_ID = "PersonId";
public const string SPOUSE_ID = "SpouseId";
public const string CHILDREN_ID = "ChildrenId";
public const string RELATION_TYPE = "RelationType";
public const string REMARK = "Remark";
public const string DB_NAME_FAMILY_TREE_CHILDREN_MAP = "family_tree_children_map";
public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,tree_id,person_id,spouse_id,children_id,relation_type,remark";
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_TREE_ID = "tree_id";
public const string DB_PERSON_ID = "person_id";
public const string DB_SPOUSE_ID = "spouse_id";
public const string DB_CHILDREN_ID = "children_id";
public const string DB_RELATION_TYPE = "relation_type";
public const string DB_REMARK = "remark";
private string ProviderName { get; set; }
public static FamilyTreeChildrenMapEntity GetInstance(string providerName)
{
return new FamilyTreeChildrenMapEntity() { ProviderName = providerName };
}
public virtual void CopyFrom(FamilyTreeChildrenMapEntity source)
{
CopyFrom(source, true);
}
public virtual void CopyFrom(FamilyTreeChildrenMapEntity 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.TreeId = source.TreeId;
this.PersonId = source.PersonId;
this.SpouseId = source.SpouseId;
this.ChildrenId = source.ChildrenId;
this.RelationType = source.RelationType;
this.Remark = source.Remark;
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_TREE_CHILDREN_MAP} with(nolock) ";
}
public string GetSelectFromByBySqlServer()
{
return $" select {DB_NAME_FIELDS} from { DB_NAME_FAMILY_TREE_CHILDREN_MAP} ";
}
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_TREE_CHILDREN_MAP} where 1=1 {sqlWhere}";
}
public string GetSelectCountFromBySqlServer(string sqlWhere)
{
return $" select count(*) from { DB_NAME_FAMILY_TREE_CHILDREN_MAP} 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_TREE_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_TREE_CHILDREN_MAP} 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_TREE_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_TREE_CHILDREN_MAP} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}";
}
public FamilyTreeChildrenMapEntity Clone()
{
FamilyTreeChildrenMapEntity result = new FamilyTreeChildrenMapEntity();
result.CopyFrom(this);
return result;
}
}
}
@@ -0,0 +1,35 @@
using CloudBuilder.Core.Authorization;
namespace CloudBuilder.Master
{
[TypeScript]
public class FamilyTreeChildrenMapEntityKey
{
public string TreeId { get; set; }
public string PersonId { get; set; }
public string ChildrenId { get; set; }
public override bool Equals(object obj)
{
if (this == obj) return true;
FamilyTreeChildrenMapEntityKey pkey = obj as FamilyTreeChildrenMapEntityKey;
if (pkey == null) return false;
if (TreeId != pkey.TreeId) return false;
if (PersonId != pkey.PersonId) return false;
if (ChildrenId != pkey.ChildrenId) return false;
return true;
}
public override string ToString()
{
string declareSql="";
declareSql=declareSql+$"declare @__tkey_TreeId_0 varchar(50) select @__tkey_TreeId_0 ='{TreeId}'; " ; declareSql=declareSql+$"declare @__tkey_PersonId_1 varchar(50) select @__tkey_PersonId_1 ='{PersonId}'; " ; declareSql=declareSql+$"declare @__tkey_ChildrenId_2 varchar(50) select @__tkey_ChildrenId_2 ='{ChildrenId}'; " ;
return declareSql;
}
}
}
/* builder.Entity<FamilyTreeChildrenMapEntity>().HasKey(c => new { c.TreeId, c.PersonId, c.ChildrenId}); */
@@ -0,0 +1,193 @@
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_tree")]
public class FamilyTreeEntity : ViewEntityBase
{
public FamilyTreeEntity()
{
}
[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]
[Column("tree_id")]
public string TreeId { get; set; }
[Column("tree_name")]
public string TreeName { get; set; }
[Column("brief")]
public string? Brief { get; set; }
[Column("ancestor_person_id")]
public string AncestorPersonId { get; set; }
[Column("tree_cover_filename")]
public string TreeCoverFilename { get; set; }
[Column("public_indc")]
public string PublicIndc { 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 TREE_ID = "TreeId";
public const string TREE_NAME = "TreeName";
public const string BRIEF = "Brief";
public const string ANCESTOR_PERSON_ID = "AncestorPersonId";
public const string TREE_COVER_FILENAME = "TreeCoverFilename";
public const string PUBLIC_INDC = "PublicIndc";
public const string DB_NAME_FAMILY_TREE = "family_tree";
public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,tree_id,tree_name,brief,ancestor_person_id,tree_cover_filename,public_indc";
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_TREE_ID = "tree_id";
public const string DB_TREE_NAME = "tree_name";
public const string DB_BRIEF = "brief";
public const string DB_ANCESTOR_PERSON_ID = "ancestor_person_id";
public const string DB_TREE_COVER_FILENAME = "tree_cover_filename";
public const string DB_PUBLIC_INDC = "public_indc";
private string ProviderName { get; set; }
public static FamilyTreeEntity GetInstance(string providerName)
{
return new FamilyTreeEntity() { ProviderName = providerName };
}
public virtual void CopyFrom(FamilyTreeEntity source)
{
CopyFrom(source, true);
}
public virtual void CopyFrom(FamilyTreeEntity 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.TreeId = source.TreeId;
this.TreeName = source.TreeName;
this.Brief = source.Brief;
this.AncestorPersonId = source.AncestorPersonId;
this.TreeCoverFilename = source.TreeCoverFilename;
this.PublicIndc = source.PublicIndc;
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_TREE} with(nolock) ";
}
public string GetSelectFromByBySqlServer()
{
return $" select {DB_NAME_FIELDS} from { DB_NAME_FAMILY_TREE} ";
}
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_TREE} where 1=1 {sqlWhere}";
}
public string GetSelectCountFromBySqlServer(string sqlWhere)
{
return $" select count(*) from { DB_NAME_FAMILY_TREE} 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_TREE_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_TREE} 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_TREE_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_TREE} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}";
}
public FamilyTreeEntity Clone()
{
FamilyTreeEntity result = new FamilyTreeEntity();
result.CopyFrom(this);
return result;
}
}
}
@@ -0,0 +1,212 @@
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_tree_spouse_map")]
public class FamilyTreeSpouseMapEntity : EntityBase<FamilyTreeSpouseMapEntityKey>
{
public FamilyTreeSpouseMapEntity()
{
}
[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; }
[Column("tree_id")]
public string TreeId { get; set; }
[Column("person_id")]
public string PersonId { get; set; }
[Column("spouse_id")]
public string SpouseId { get; set; }
[Column("marry_date_text")]
public string? MarryDateText { get; set; }
[Column("marry_date")]
public Nullable<DateTime> MarryDate { get; set; }
[Column("divorce_date_text")]
public string? DivorceDateText { get; set; }
[Column("divorce_date")]
public Nullable<DateTime> DivorceDate { get; set; }
[Column("marry_type")]
public string? MarryType { get; set; }
[Column("is_current")]
public string? IsCurrent { get; set; }
[Column("remark")]
public string? Remark { 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 TREE_ID = "TreeId";
public const string PERSON_ID = "PersonId";
public const string SPOUSE_ID = "SpouseId";
public const string MARRY_DATE_TEXT = "MarryDateText";
public const string MARRY_DATE = "MarryDate";
public const string DIVORCE_DATE_TEXT = "DivorceDateText";
public const string DIVORCE_DATE = "DivorceDate";
public const string MARRY_TYPE = "MarryType";
public const string IS_CURRENT = "IsCurrent";
public const string REMARK = "Remark";
public const string DB_NAME_FAMILY_TREE_SPOUSE_MAP = "family_tree_spouse_map";
public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,tree_id,person_id,spouse_id,marry_date_text,marry_date,divorce_date_text,divorce_date,marry_type,is_current,remark";
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_TREE_ID = "tree_id";
public const string DB_PERSON_ID = "person_id";
public const string DB_SPOUSE_ID = "spouse_id";
public const string DB_MARRY_DATE_TEXT = "marry_date_text";
public const string DB_MARRY_DATE = "marry_date";
public const string DB_DIVORCE_DATE_TEXT = "divorce_date_text";
public const string DB_DIVORCE_DATE = "divorce_date";
public const string DB_MARRY_TYPE = "marry_type";
public const string DB_IS_CURRENT = "is_current";
public const string DB_REMARK = "remark";
private string ProviderName { get; set; }
public static FamilyTreeSpouseMapEntity GetInstance(string providerName)
{
return new FamilyTreeSpouseMapEntity() { ProviderName = providerName };
}
public virtual void CopyFrom(FamilyTreeSpouseMapEntity source)
{
CopyFrom(source, true);
}
public virtual void CopyFrom(FamilyTreeSpouseMapEntity 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.TreeId = source.TreeId;
this.PersonId = source.PersonId;
this.SpouseId = source.SpouseId;
this.MarryDateText = source.MarryDateText;
this.MarryDate = source.MarryDate;
this.DivorceDateText = source.DivorceDateText;
this.DivorceDate = source.DivorceDate;
this.MarryType = source.MarryType;
this.IsCurrent = source.IsCurrent;
this.Remark = source.Remark;
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_TREE_SPOUSE_MAP} with(nolock) ";
}
public string GetSelectFromByBySqlServer()
{
return $" select {DB_NAME_FIELDS} from { DB_NAME_FAMILY_TREE_SPOUSE_MAP} ";
}
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_TREE_SPOUSE_MAP} where 1=1 {sqlWhere}";
}
public string GetSelectCountFromBySqlServer(string sqlWhere)
{
return $" select count(*) from { DB_NAME_FAMILY_TREE_SPOUSE_MAP} 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_TREE_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_TREE_SPOUSE_MAP} 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_TREE_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_TREE_SPOUSE_MAP} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}";
}
public FamilyTreeSpouseMapEntity Clone()
{
FamilyTreeSpouseMapEntity result = new FamilyTreeSpouseMapEntity();
result.CopyFrom(this);
return result;
}
}
}
@@ -0,0 +1,35 @@
using CloudBuilder.Core.Authorization;
namespace CloudBuilder.Master
{
[TypeScript]
public class FamilyTreeSpouseMapEntityKey
{
public string TreeId { get; set; }
public string PersonId { get; set; }
public string SpouseId { get; set; }
public override bool Equals(object obj)
{
if (this == obj) return true;
FamilyTreeSpouseMapEntityKey pkey = obj as FamilyTreeSpouseMapEntityKey;
if (pkey == null) return false;
if (TreeId != pkey.TreeId) return false;
if (PersonId != pkey.PersonId) return false;
if (SpouseId != pkey.SpouseId) return false;
return true;
}
public override string ToString()
{
string declareSql="";
declareSql=declareSql+$"declare @__tkey_TreeId_0 varchar(50) select @__tkey_TreeId_0 ='{TreeId}'; " ; declareSql=declareSql+$"declare @__tkey_PersonId_1 varchar(50) select @__tkey_PersonId_1 ='{PersonId}'; " ; declareSql=declareSql+$"declare @__tkey_SpouseId_2 varchar(50) select @__tkey_SpouseId_2 ='{SpouseId}'; " ;
return declareSql;
}
}
}
/* builder.Entity<FamilyTreeSpouseMapEntity>().HasKey(c => new { c.TreeId, c.PersonId, c.SpouseId}); */