Files
Docker/CloudBuilder/CloudBuilder.Security/Entity/SysTablePkeyViewEntity.auto.cs
T
2026-08-26 10:15:02 +08:00

169 lines
5.9 KiB
C#

using CloudBuilder.Core.Authorization;
using CloudBuilder.Core.DatabaseAccessor.Entity;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace CloudBuilder.Security.Entity
{
[TypeScript]
[Table("sys_table_pkey_view")]
public class SysTablePkeyViewEntity : ViewEntityBase
{
public SysTablePkeyViewEntity()
{
}
[Column("table_qualifier")]
public string? TableQualifier { get; set; }
[Column("table_owner")]
public string TableOwner { get; set; }
[Column("table_name")]
public string TableName { get; set; }
[Column("column_name")]
public string? ColumnName { get; set; }
[Column("pk_name")]
public string? PkName { get; set; }
[Column("pk")]
public int Pk { get; set; }
public const string TABLE_QUALIFIER = "TableQualifier";
public const string TABLE_OWNER = "TableOwner";
public const string TABLE_NAME = "TableName";
public const string COLUMN_NAME = "ColumnName";
public const string PK_NAME = "PkName";
public const string PK = "Pk";
public const string DB_NAME_SYS_TABLE_PKEY_VIEW = "sys_table_pkey_view";
public const string DB_NAME_FIELDS="table_qualifier,table_owner,table_name,column_name,pk_name,pk";
public const string DB_TABLE_QUALIFIER = "table_qualifier";
public const string DB_TABLE_OWNER = "table_owner";
public const string DB_TABLE_NAME = "table_name";
public const string DB_COLUMN_NAME = "column_name";
public const string DB_PK_NAME = "pk_name";
public const string DB_PK = "pk";
public string ProviderName { get; set; }
public static SysTablePkeyViewEntity GetInstance(string providerName)
{
return new SysTablePkeyViewEntity() { ProviderName = providerName };
}
public virtual void CopyFrom(SysTablePkeyViewEntity source)
{
CopyFrom(source, true);
}
public virtual void CopyFrom(SysTablePkeyViewEntity source, bool includeSystemFields)
{
if (source == null)
{
throw new NullReferenceException("Source entity is null.");
}
this.TableQualifier = source.TableQualifier;
this.TableOwner = source.TableOwner;
this.TableName = source.TableName;
this.ColumnName = source.ColumnName;
this.PkName = source.PkName;
this.Pk = source.Pk;
if (includeSystemFields)
{
}
}
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_SYS_TABLE_PKEY_VIEW} with(nolock) ";
}
public string GetSelectFromByBySqlServer()
{
return $" select {DB_NAME_FIELDS} from { DB_NAME_SYS_TABLE_PKEY_VIEW} ";
}
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_SYS_TABLE_PKEY_VIEW} where 1=1 {sqlWhere}";
}
public string GetSelectCountFromBySqlServer(string sqlWhere)
{
return $" select count(*) from { DB_NAME_SYS_TABLE_PKEY_VIEW} 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_TABLE_QUALIFIER ; 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_SYS_TABLE_PKEY_VIEW} 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_TABLE_QUALIFIER ; 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_SYS_TABLE_PKEY_VIEW} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}";
}
public SysTablePkeyViewEntity Clone()
{
SysTablePkeyViewEntity result = new SysTablePkeyViewEntity();
result.CopyFrom(this);
return result;
}
}
}