169 lines
6.4 KiB
C#
169 lines
6.4 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("security_function_map_view")]
|
|
public class SecurityFunctionMapViewEntity : ViewEntityBase
|
|
{
|
|
|
|
public SecurityFunctionMapViewEntity()
|
|
{
|
|
}
|
|
|
|
[Column("orderby")]
|
|
public int Orderby { get; set; }
|
|
[Column("parent_function_name")]
|
|
public string ParentFunctionName { get; set; }
|
|
[Column("parent_function_local_name")]
|
|
public string? ParentFunctionLocalName { get; set; }
|
|
[Column("son_function_name")]
|
|
public string SonFunctionName { get; set; }
|
|
[Column("son_function_local_name")]
|
|
public string? SonFunctionLocalName { get; set; }
|
|
[Column("son_page_name")]
|
|
public string? SonPageName { get; set; }
|
|
|
|
public const string ORDERBY = "Orderby";
|
|
public const string PARENT_FUNCTION_NAME = "ParentFunctionName";
|
|
public const string PARENT_FUNCTION_LOCAL_NAME = "ParentFunctionLocalName";
|
|
public const string SON_FUNCTION_NAME = "SonFunctionName";
|
|
public const string SON_FUNCTION_LOCAL_NAME = "SonFunctionLocalName";
|
|
public const string SON_PAGE_NAME = "SonPageName";
|
|
|
|
public const string DB_NAME_SECURITY_FUNCTION_MAP_VIEW = "security_function_map_view";
|
|
public const string DB_NAME_FIELDS="orderby,parent_function_name,parent_function_local_name,son_function_name,son_function_local_name,son_page_name";
|
|
|
|
public const string DB_ORDERBY = "orderby";
|
|
public const string DB_PARENT_FUNCTION_NAME = "parent_function_name";
|
|
public const string DB_PARENT_FUNCTION_LOCAL_NAME = "parent_function_local_name";
|
|
public const string DB_SON_FUNCTION_NAME = "son_function_name";
|
|
public const string DB_SON_FUNCTION_LOCAL_NAME = "son_function_local_name";
|
|
public const string DB_SON_PAGE_NAME = "son_page_name";
|
|
|
|
private string ProviderName { get; set; }
|
|
|
|
public static SecurityFunctionMapViewEntity GetInstance(string providerName)
|
|
{
|
|
return new SecurityFunctionMapViewEntity() { ProviderName = providerName };
|
|
}
|
|
|
|
public virtual void CopyFrom(SecurityFunctionMapViewEntity source)
|
|
{
|
|
CopyFrom(source, true);
|
|
}
|
|
|
|
public virtual void CopyFrom(SecurityFunctionMapViewEntity source, bool includeSystemFields)
|
|
{
|
|
if (source == null)
|
|
{
|
|
throw new NullReferenceException("Source entity is null.");
|
|
}
|
|
|
|
this.Orderby = source.Orderby;
|
|
this.ParentFunctionName = source.ParentFunctionName;
|
|
this.ParentFunctionLocalName = source.ParentFunctionLocalName;
|
|
this.SonFunctionName = source.SonFunctionName;
|
|
this.SonFunctionLocalName = source.SonFunctionLocalName;
|
|
this.SonPageName = source.SonPageName;
|
|
|
|
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_SECURITY_FUNCTION_MAP_VIEW} with(nolock) ";
|
|
}
|
|
public string GetSelectFromByBySqlServer()
|
|
{
|
|
return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_FUNCTION_MAP_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_SECURITY_FUNCTION_MAP_VIEW} where 1=1 {sqlWhere}";
|
|
}
|
|
public string GetSelectCountFromBySqlServer(string sqlWhere)
|
|
{
|
|
return $" select count(*) from { DB_NAME_SECURITY_FUNCTION_MAP_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_ORDERBY ; 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_SECURITY_FUNCTION_MAP_VIEW} 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_ORDERBY ; 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_FUNCTION_MAP_VIEW} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}";
|
|
}
|
|
|
|
public SecurityFunctionMapViewEntity Clone()
|
|
{
|
|
SecurityFunctionMapViewEntity result = new SecurityFunctionMapViewEntity();
|
|
result.CopyFrom(this);
|
|
|
|
return result;
|
|
}
|
|
|
|
}
|
|
}
|