SqlServer and MySql
This commit is contained in:
1 parent
42405492b6
commit
011e60afa9
53 files changed
+3419
-1238
No files matched your search
@@ -14,68 +14,69 @@ namespace CloudBuilder.Security.Entity
|
||||
{
|
||||
}
|
||||
|
||||
[Column("created_by")]
|
||||
public string CreatedBy { get; set; }
|
||||
[Column("created_datetime")]
|
||||
public DateTime CreatedDatetime { get; set; }
|
||||
[Column("eng_description")]
|
||||
public string? EngDescription { get; set; }
|
||||
[Column("local_description")]
|
||||
public string? LocalDescription { get; set; }
|
||||
[Column("master_category")]
|
||||
public string MasterCategory { get; set; }
|
||||
[Column("master_code_item")]
|
||||
public string MasterCodeItem { get; set; }
|
||||
[Column("master_subcategory")]
|
||||
public string MasterSubcategory { get; set; }
|
||||
[Column("order_by")]
|
||||
public int OrderBy { get; set; }
|
||||
[Column("remark")]
|
||||
public string? Remark { get; set; }
|
||||
[Column("updated_by")]
|
||||
public string UpdatedBy { get; set; }
|
||||
[Column("created_by")]
|
||||
public string CreatedBy { get; set; }
|
||||
[Column("updated_datetime")]
|
||||
public DateTime UpdatedDatetime { get; set; }
|
||||
[Column("valid_indc")]
|
||||
public string ValidIndc { get; set; }
|
||||
[Column("updated_by")]
|
||||
public string UpdatedBy { get; set; }
|
||||
[Column("master_category")]
|
||||
public string MasterCategory { get; set; }
|
||||
[Column("master_subcategory")]
|
||||
public string MasterSubcategory { get; set; }
|
||||
[Column("master_code_item")]
|
||||
public string MasterCodeItem { get; set; }
|
||||
[Column("local_description")]
|
||||
public string? LocalDescription { get; set; }
|
||||
[Column("eng_description")]
|
||||
public string? EngDescription { get; set; }
|
||||
[Column("value")]
|
||||
public string Value { get; set; }
|
||||
[Column("order_by")]
|
||||
public int OrderBy { get; set; }
|
||||
[Column("valid_indc")]
|
||||
public string ValidIndc { get; set; }
|
||||
[Column("remark")]
|
||||
public string? Remark { get; set; }
|
||||
|
||||
public const string CREATED_BY = "CreatedBy";
|
||||
public const string CREATED_DATETIME = "CreatedDatetime";
|
||||
public const string ENG_DESCRIPTION = "EngDescription";
|
||||
public const string LOCAL_DESCRIPTION = "LocalDescription";
|
||||
public const string MASTER_CATEGORY = "MasterCategory";
|
||||
public const string MASTER_CODE_ITEM = "MasterCodeItem";
|
||||
public const string MASTER_SUBCATEGORY = "MasterSubcategory";
|
||||
public const string ORDER_BY = "OrderBy";
|
||||
public const string REMARK = "Remark";
|
||||
public const string UPDATED_BY = "UpdatedBy";
|
||||
public const string CREATED_BY = "CreatedBy";
|
||||
public const string UPDATED_DATETIME = "UpdatedDatetime";
|
||||
public const string VALID_INDC = "ValidIndc";
|
||||
public const string UPDATED_BY = "UpdatedBy";
|
||||
public const string MASTER_CATEGORY = "MasterCategory";
|
||||
public const string MASTER_SUBCATEGORY = "MasterSubcategory";
|
||||
public const string MASTER_CODE_ITEM = "MasterCodeItem";
|
||||
public const string LOCAL_DESCRIPTION = "LocalDescription";
|
||||
public const string ENG_DESCRIPTION = "EngDescription";
|
||||
public const string VALUE = "Value";
|
||||
public const string ORDER_BY = "OrderBy";
|
||||
public const string VALID_INDC = "ValidIndc";
|
||||
public const string REMARK = "Remark";
|
||||
|
||||
public const string DB_NAME_SECURITY_MASTER = "security_master";
|
||||
public const string DB_NAME_FIELDS="created_by,created_datetime,eng_description,local_description,master_category,master_code_item,master_subcategory,order_by,remark,updated_by,updated_datetime,valid_indc,value";
|
||||
public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,master_category,master_subcategory,master_code_item,local_description,eng_description,value,order_by,valid_indc,remark";
|
||||
|
||||
public const string DB_CREATED_BY = "created_by";
|
||||
public const string DB_CREATED_DATETIME = "created_datetime";
|
||||
public const string DB_ENG_DESCRIPTION = "eng_description";
|
||||
public const string DB_LOCAL_DESCRIPTION = "local_description";
|
||||
public const string DB_MASTER_CATEGORY = "master_category";
|
||||
public const string DB_MASTER_CODE_ITEM = "master_code_item";
|
||||
public const string DB_MASTER_SUBCATEGORY = "master_subcategory";
|
||||
public const string DB_ORDER_BY = "order_by";
|
||||
public const string DB_REMARK = "remark";
|
||||
public const string DB_UPDATED_BY = "updated_by";
|
||||
public const string DB_CREATED_BY = "created_by";
|
||||
public const string DB_UPDATED_DATETIME = "updated_datetime";
|
||||
public const string DB_VALID_INDC = "valid_indc";
|
||||
public const string DB_UPDATED_BY = "updated_by";
|
||||
public const string DB_MASTER_CATEGORY = "master_category";
|
||||
public const string DB_MASTER_SUBCATEGORY = "master_subcategory";
|
||||
public const string DB_MASTER_CODE_ITEM = "master_code_item";
|
||||
public const string DB_LOCAL_DESCRIPTION = "local_description";
|
||||
public const string DB_ENG_DESCRIPTION = "eng_description";
|
||||
public const string DB_VALUE = "value";
|
||||
public const string DB_ORDER_BY = "order_by";
|
||||
public const string DB_VALID_INDC = "valid_indc";
|
||||
public const string DB_REMARK = "remark";
|
||||
|
||||
public string ProviderName { get; set; }
|
||||
|
||||
public static SecurityMasterEntity GetInstance()
|
||||
public static SecurityMasterEntity GetInstance(string providerName)
|
||||
{
|
||||
return new SecurityMasterEntity();
|
||||
return new SecurityMasterEntity() { ProviderName = providerName };
|
||||
}
|
||||
|
||||
public virtual void CopyFrom(SecurityMasterEntity source)
|
||||
@@ -90,40 +91,95 @@ namespace CloudBuilder.Security.Entity
|
||||
throw new NullReferenceException("Source entity is null.");
|
||||
}
|
||||
|
||||
this.CreatedBy = source.CreatedBy;
|
||||
this.CreatedDatetime = source.CreatedDatetime;
|
||||
this.EngDescription = source.EngDescription;
|
||||
this.LocalDescription = source.LocalDescription;
|
||||
this.MasterCategory = source.MasterCategory;
|
||||
this.MasterCodeItem = source.MasterCodeItem;
|
||||
this.MasterSubcategory = source.MasterSubcategory;
|
||||
this.OrderBy = source.OrderBy;
|
||||
this.Remark = source.Remark;
|
||||
this.UpdatedBy = source.UpdatedBy;
|
||||
this.CreatedBy = source.CreatedBy;
|
||||
this.UpdatedDatetime = source.UpdatedDatetime;
|
||||
this.ValidIndc = source.ValidIndc;
|
||||
this.UpdatedBy = source.UpdatedBy;
|
||||
this.MasterCategory = source.MasterCategory;
|
||||
this.MasterSubcategory = source.MasterSubcategory;
|
||||
this.MasterCodeItem = source.MasterCodeItem;
|
||||
this.LocalDescription = source.LocalDescription;
|
||||
this.EngDescription = source.EngDescription;
|
||||
this.Value = source.Value;
|
||||
this.OrderBy = source.OrderBy;
|
||||
this.ValidIndc = source.ValidIndc;
|
||||
this.Remark = source.Remark;
|
||||
|
||||
if (includeSystemFields)
|
||||
{
|
||||
this.CreatedBy = source.CreatedBy;
|
||||
this.CreatedDatetime = source.CreatedDatetime;
|
||||
this.UpdatedBy = source.UpdatedBy;
|
||||
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_SECURITY_MASTER} with(nolock) ";
|
||||
}
|
||||
public string GetSelectFromByBySqlServer()
|
||||
{
|
||||
return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_MASTER} ";
|
||||
}
|
||||
|
||||
|
||||
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_SECURITY_MASTER} where 1=1 {sqlWhere}";
|
||||
}
|
||||
|
||||
public override string GetSelectTopFrom(int limit, int start,string orderby,string orderbytag, string sqlWhere)
|
||||
public string GetSelectCountFromBySqlServer(string sqlWhere)
|
||||
{
|
||||
return $" select count(*) from { DB_NAME_SECURITY_MASTER} 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_MASTER_CATEGORY ;
|
||||
@@ -131,6 +187,14 @@ namespace CloudBuilder.Security.Entity
|
||||
return $" select {DB_NAME_FIELDS} from (select {DB_NAME_FIELDS} ,row_number() over(order by {orderby} {orderbytag}) as num from { DB_NAME_SECURITY_MASTER} where 1=1 {sqlWhere} ) a where num> {offset} LIMIT {offset},{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_MASTER_CATEGORY ;
|
||||
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_SECURITY_MASTER} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}";
|
||||
}
|
||||
|
||||
public SecurityMasterEntity Clone()
|
||||
{
|
||||
SecurityMasterEntity result = new SecurityMasterEntity();
|
||||
|
||||
Reference in new issue
Block a user