diff --git a/CloudBuilder/CloudBuilder.Core/DatabaseAccessor/Entity/IRepository.cs b/CloudBuilder/CloudBuilder.Core/DatabaseAccessor/Entity/IRepository.cs index 0fda1cc..9031cfe 100644 --- a/CloudBuilder/CloudBuilder.Core/DatabaseAccessor/Entity/IRepository.cs +++ b/CloudBuilder/CloudBuilder.Core/DatabaseAccessor/Entity/IRepository.cs @@ -64,9 +64,7 @@ namespace CloudBuilder.Core.DatabaseAccessor.Entity object ExecuteScalar(string sql, params object[] parameters); - DataTable SelectDataTableBySql(string sql, params object[] parameters); - - DataTable SelectDataTableByMySql(string sql, params object[] parameters); + DataTable SelectDataTable(string sql, params object[] parameters); #endregion diff --git a/CloudBuilder/CloudBuilder.Core/DatabaseAccessor/Repository.cs b/CloudBuilder/CloudBuilder.Core/DatabaseAccessor/Repository.cs index 4fb8c0e..ad507f9 100644 --- a/CloudBuilder/CloudBuilder.Core/DatabaseAccessor/Repository.cs +++ b/CloudBuilder/CloudBuilder.Core/DatabaseAccessor/Repository.cs @@ -1,4 +1,5 @@ using CloudBuilder.Core.Application.Builders; +using DocumentFormat.OpenXml.Math; using Microsoft.AspNetCore.Http; using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; @@ -109,6 +110,23 @@ namespace CloudBuilder.Core.DatabaseAccessor.Entity } public void PackSqlParameter(List parameters, string parameterName, object value) + { + var ProviderName = GetDbContext().Database.ProviderName; + if (ProviderName.Contains("MySql")) + { + PackMySqlParameter(parameters, parameterName, value); + } + else if (ProviderName.Contains("SqlServer")) + { + PackSqlServerParameter(parameters, parameterName, value); + } + else + { + throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}"); + } + } + + private void PackSqlServerParameter(List parameters, string parameterName, object value) { if (parameters == null) parameters = new List(); else @@ -122,11 +140,11 @@ namespace CloudBuilder.Core.DatabaseAccessor.Entity formatedValue = $"'{Convert.ToDateTime(formatedValue).ToString("yyyy-MM-dd HH:mm:ss")}'"; } - parameters.Add(new MySqlParameter(parameterName, value == null ? DBNull.Value : value)); + parameters.Add(new SqlParameter(parameterName, value == null ? DBNull.Value : value)); } } - public void PackMySqlParameter(List parameters, string parameterName, object value) + private void PackMySqlParameter(List parameters, string parameterName, object value) { if (parameters == null) parameters = new List(); else @@ -178,6 +196,22 @@ namespace CloudBuilder.Core.DatabaseAccessor.Entity return cmd.ExecuteScalar(); } + public virtual DataTable SelectDataTable(string sql, params object[] parameters) + { + var ProviderName = GetDbContext().Database.ProviderName; + if (ProviderName.Contains("MySql")) + { + return SelectDataTableByMySql(sql, parameters); + } + else if (ProviderName.Contains("SqlServer")) + { + return SelectDataTableBySqlServer(sql, parameters); + } + else + { + throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}"); + } + } public virtual DataTable SelectDataTableByMySql(string sql, params object[] parameters) { @@ -201,7 +235,7 @@ namespace CloudBuilder.Core.DatabaseAccessor.Entity } - public virtual DataTable SelectDataTableBySql(string sql, params object[] parameters) + public virtual DataTable SelectDataTableBySqlServer(string sql, params object[] parameters) { var conn = dbContext.Database.GetDbConnection(); ; diff --git a/CloudBuilder/CloudBuilder.Security.Service/LocaleService.cs b/CloudBuilder/CloudBuilder.Security.Service/LocaleService.cs index 2d4ce78..12c549e 100644 --- a/CloudBuilder/CloudBuilder.Security.Service/LocaleService.cs +++ b/CloudBuilder/CloudBuilder.Security.Service/LocaleService.cs @@ -42,7 +42,7 @@ namespace CloudBuilder.Security.Service sqlWhere = SearchFilter.ComposeWhereClause(criteria.Filter); } - LocaleEntity entity = LocaleEntity.GetInstance(); + LocaleEntity entity = LocaleEntity.GetInstance(repository.GetDbContext().Database.ProviderName); string sql = entity.GetSelectTopFrom(criteria.limit, criteria.page, criteria.orderby.StringToDbField(), criteria.orderbytag, sqlWhere); string err = null; diff --git a/CloudBuilder/CloudBuilder.Security.Service/SecurityActorService.cs b/CloudBuilder/CloudBuilder.Security.Service/SecurityActorService.cs index d804a67..8d1c772 100644 --- a/CloudBuilder/CloudBuilder.Security.Service/SecurityActorService.cs +++ b/CloudBuilder/CloudBuilder.Security.Service/SecurityActorService.cs @@ -74,7 +74,7 @@ namespace CloudBuilder.Security.Service sqlWhere = SearchFilter.ComposeWhereClause(criteria.Filter); } - SecurityActorEntity entity = SecurityActorEntity.GetInstance(); + SecurityActorEntity entity = SecurityActorEntity.GetInstance(repository.GetDbContext().Database.ProviderName); string sql = entity.GetSelectTopFrom(criteria.limit, criteria.page, criteria.orderby.StringToDbField(), criteria.orderbytag, sqlWhere); string err = null; diff --git a/CloudBuilder/CloudBuilder.Security.Service/SecurityFunctionService.cs b/CloudBuilder/CloudBuilder.Security.Service/SecurityFunctionService.cs index 416200c..6b9ee6b 100644 --- a/CloudBuilder/CloudBuilder.Security.Service/SecurityFunctionService.cs +++ b/CloudBuilder/CloudBuilder.Security.Service/SecurityFunctionService.cs @@ -64,7 +64,7 @@ namespace CloudBuilder.Security.Service sqlWhere = SearchFilter.ComposeWhereClause(criteria.Filter); } - SecurityFunctionEntity entity = SecurityFunctionEntity.GetInstance(); + SecurityFunctionEntity entity = SecurityFunctionEntity.GetInstance(repository.GetDbContext().Database.ProviderName); string sql = entity.GetSelectTopFrom(criteria.limit, criteria.page, criteria.orderby.StringToDbField(), criteria.orderbytag, sqlWhere); string err = null; diff --git a/CloudBuilder/CloudBuilder.Security.Service/SecurityGeneratorNumberService.cs b/CloudBuilder/CloudBuilder.Security.Service/SecurityGeneratorNumberService.cs index d51cc5c..22a50ff 100644 --- a/CloudBuilder/CloudBuilder.Security.Service/SecurityGeneratorNumberService.cs +++ b/CloudBuilder/CloudBuilder.Security.Service/SecurityGeneratorNumberService.cs @@ -43,7 +43,7 @@ namespace CloudBuilder.Security.Service sqlWhere = SearchFilter.ComposeWhereClause(criteria.Filter); } - SecurityGeneratorNumberEntity entity = SecurityGeneratorNumberEntity.GetInstance(); + SecurityGeneratorNumberEntity entity = SecurityGeneratorNumberEntity.GetInstance(repository.GetDbContext().Database.ProviderName); string sql = entity.GetSelectTopFrom(criteria.limit, criteria.page, criteria.orderby.StringToDbField(), criteria.orderbytag, sqlWhere); string err = null; @@ -88,7 +88,7 @@ namespace CloudBuilder.Security.Service List searCriteria = criteria.PackSearchCriteriaDisplay(ref headers, ref sqlWhere, mappings); - SecurityGeneratorNumberEntity entity = SecurityGeneratorNumberEntity.GetInstance(); + SecurityGeneratorNumberEntity entity = SecurityGeneratorNumberEntity.GetInstance(repository.GetDbContext().Database.ProviderName); string sql = entity.GetSelectFrom() + " where 1=1 " + sqlWhere; SecurityGeneratorNumberEntity[] list = repository.FromSql(sql).ToArray(); diff --git a/CloudBuilder/CloudBuilder.Security.Service/SecurityGroupService.cs b/CloudBuilder/CloudBuilder.Security.Service/SecurityGroupService.cs index a6a8542..88ce70e 100644 --- a/CloudBuilder/CloudBuilder.Security.Service/SecurityGroupService.cs +++ b/CloudBuilder/CloudBuilder.Security.Service/SecurityGroupService.cs @@ -74,7 +74,7 @@ namespace CloudBuilder.Security.Service sqlWhere = SearchFilter.ComposeWhereClause(criteria.Filter); } - SecurityGroupEntity entity = SecurityGroupEntity.GetInstance(); + SecurityGroupEntity entity = SecurityGroupEntity.GetInstance(repository.GetDbContext().Database.ProviderName); string sql = entity.GetSelectTopFrom(criteria.limit, criteria.page, criteria.orderby.StringToDbField(), criteria.orderbytag, sqlWhere); string err = null; diff --git a/CloudBuilder/CloudBuilder.Security.Service/SecurityMasterService.cs b/CloudBuilder/CloudBuilder.Security.Service/SecurityMasterService.cs index 6f05a24..ce7bb7d 100644 --- a/CloudBuilder/CloudBuilder.Security.Service/SecurityMasterService.cs +++ b/CloudBuilder/CloudBuilder.Security.Service/SecurityMasterService.cs @@ -57,7 +57,7 @@ namespace CloudBuilder.Security.Service sqlWhere = SearchFilter.ComposeWhereClause(criteria.Filter); } - SecurityMasterEntity entity = SecurityMasterEntity.GetInstance(); + SecurityMasterEntity entity = SecurityMasterEntity.GetInstance(repository.GetDbContext().Database.ProviderName); string sql = entity.GetSelectTopFrom(criteria.limit, criteria.page, criteria.orderby.StringToDbField(), criteria.orderbytag, sqlWhere); string err = null; @@ -102,7 +102,7 @@ namespace CloudBuilder.Security.Service List searCriteria = criteria.PackSearchCriteriaDisplay(ref headers, ref sqlWhere, mappings); - SecurityMasterEntity entity = SecurityMasterEntity.GetInstance(); + SecurityMasterEntity entity = SecurityMasterEntity.GetInstance(repository.GetDbContext().Database.ProviderName); string sql = entity.GetSelectFrom() + " where 1=1 " + sqlWhere; SecurityMasterEntity[] list = repository.FromSql(sql).ToArray(); diff --git a/CloudBuilder/CloudBuilder.Security.Service/SecurityPermissionService.cs b/CloudBuilder/CloudBuilder.Security.Service/SecurityPermissionService.cs index b8a389b..f842498 100644 --- a/CloudBuilder/CloudBuilder.Security.Service/SecurityPermissionService.cs +++ b/CloudBuilder/CloudBuilder.Security.Service/SecurityPermissionService.cs @@ -61,7 +61,7 @@ namespace CloudBuilder.Security.Service sqlWhere = SearchFilter.ComposeWhereClause(criteria.Filter); } - SecurityPermissionEntity entity = SecurityPermissionEntity.GetInstance(); + SecurityPermissionEntity entity = SecurityPermissionEntity.GetInstance(repository.GetDbContext().Database.ProviderName); string sql = entity.GetSelectTopFrom(criteria.limit, criteria.page, criteria.orderby.StringToDbField(), criteria.orderbytag, sqlWhere); string err = null; @@ -105,7 +105,7 @@ namespace CloudBuilder.Security.Service sqlWhere = SearchFilter.ComposeWhereClause(criteria.Filter); } - SecurityPermissionDependentEntity entity = SecurityPermissionDependentEntity.GetInstance(); + SecurityPermissionDependentEntity entity = SecurityPermissionDependentEntity.GetInstance(repository.GetDbContext().Database.ProviderName); string sql = entity.GetSelectTopFrom(criteria.limit, criteria.page, criteria.orderby.StringToDbField(), criteria.orderbytag, sqlWhere); string err = null; @@ -150,7 +150,7 @@ namespace CloudBuilder.Security.Service sqlWhere = SearchFilter.ComposeWhereClause(criteria.Filter); } - SecurityPermissionDependentEntity entity = SecurityPermissionDependentEntity.GetInstance(); + SecurityPermissionDependentEntity entity = SecurityPermissionDependentEntity.GetInstance(repository.GetDbContext().Database.ProviderName); string sql = entity.GetSelectTopFrom(criteria.limit, criteria.page, criteria.orderby.StringToDbField(), criteria.orderbytag, sqlWhere); IRepository repositoryDependent = repository.GetRepository>(); diff --git a/CloudBuilder/CloudBuilder.Security.Service/SecurityUserService.cs b/CloudBuilder/CloudBuilder.Security.Service/SecurityUserService.cs index 290304b..f5551cc 100644 --- a/CloudBuilder/CloudBuilder.Security.Service/SecurityUserService.cs +++ b/CloudBuilder/CloudBuilder.Security.Service/SecurityUserService.cs @@ -88,7 +88,7 @@ namespace CloudBuilder.Security.Service //sqlWhere = sqlWhere + string.Format(" and {0} ='{1}' ", SecurityUserEntity.DB_USER_IS_VALID_INDC, YesNoPolicy.YES); - SecurityUserEntity entity = SecurityUserEntity.GetInstance(); + SecurityUserEntity entity = SecurityUserEntity.GetInstance(repository.GetDbContext().Database.ProviderName); string sql = entity.GetSelectTopFrom(criteria.limit, criteria.page, criteria.orderby.StringToDbField(), criteria.orderbytag, sqlWhere); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/CloudBuilderSecurityRegistEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/CloudBuilderSecurityRegistEntity.auto.cs index 38cd891..6e197a5 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/CloudBuilderSecurityRegistEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/CloudBuilderSecurityRegistEntity.auto.cs @@ -121,6 +121,42 @@ builder.Entity(eb => { eb.HasNoKey(); }); builder.Entity(eb => { eb.HasNoKey(); }); builder.Entity(eb => { eb.HasNoKey(); }); + + + + + + + + +builder.Entity(eb => { eb.HasNoKey(); }); + + +builder.Entity(eb => { eb.HasNoKey(); }); + + + +builder.Entity(eb => { eb.HasNoKey(); }); + +builder.Entity(eb => { eb.HasNoKey(); }); + +builder.Entity(eb => { eb.HasNoKey(); }); + + +builder.Entity(eb => { eb.HasNoKey(); }); + +builder.Entity(eb => { eb.HasNoKey(); }); + + + +builder.Entity(eb => { eb.HasNoKey(); }); + + +builder.Entity(eb => { eb.HasNoKey(); }); + +builder.Entity(eb => { eb.HasNoKey(); }); + +builder.Entity(eb => { eb.HasNoKey(); }); //***END*** } } diff --git a/CloudBuilder/CloudBuilder.Security/Entity/LocaleEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/LocaleEntity.auto.cs index 4f8f8e9..c579caf 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/LocaleEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/LocaleEntity.auto.cs @@ -14,52 +14,53 @@ namespace CloudBuilder.Security.Entity { } - [Column("created_by")] - public string CreatedBy { get; set; } [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("group_name")] public string GroupName { get; set; } [Column("lang")] public string Lang { get; set; } [Column("name")] public string Name { get; set; } - [Column("order_by")] - public int OrderBy { get; set; } - [Column("updated_by")] - public string UpdatedBy { get; set; } - [Column("updated_datetime")] - public DateTime UpdatedDatetime { get; set; } [Column("value")] public string Value { get; set; } + [Column("order_by")] + public int OrderBy { get; set; } - public const string CREATED_BY = "CreatedBy"; 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 GROUP_NAME = "GroupName"; public const string LANG = "Lang"; public const string NAME = "Name"; - public const string ORDER_BY = "OrderBy"; - public const string UPDATED_BY = "UpdatedBy"; - public const string UPDATED_DATETIME = "UpdatedDatetime"; public const string VALUE = "Value"; + public const string ORDER_BY = "OrderBy"; public const string DB_NAME_LOCALE = "locale"; - public const string DB_NAME_FIELDS="created_by,created_datetime,group_name,lang,name,order_by,updated_by,updated_datetime,value"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,group_name,lang,name,value,order_by"; - public const string DB_CREATED_BY = "created_by"; 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_GROUP_NAME = "group_name"; public const string DB_LANG = "lang"; public const string DB_NAME = "name"; - public const string DB_ORDER_BY = "order_by"; - public const string DB_UPDATED_BY = "updated_by"; - public const string DB_UPDATED_DATETIME = "updated_datetime"; public const string DB_VALUE = "value"; + public const string DB_ORDER_BY = "order_by"; + public string ProviderName { get; set; } - public static LocaleEntity GetInstance() + public static LocaleEntity GetInstance(string providerName) { - return new LocaleEntity(); + return new LocaleEntity() { ProviderName = providerName }; } public virtual void CopyFrom(LocaleEntity source) @@ -74,36 +75,91 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; + this.CreatedBy = source.CreatedBy; + this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; this.GroupName = source.GroupName; this.Lang = source.Lang; this.Name = source.Name; - this.OrderBy = source.OrderBy; - this.UpdatedBy = source.UpdatedBy; - this.UpdatedDatetime = source.UpdatedDatetime; this.Value = source.Value; + this.OrderBy = source.OrderBy; 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_LOCALE} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_LOCALE} "; } - + 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_LOCALE} 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_LOCALE} 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_GROUP_NAME ; @@ -111,6 +167,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_LOCALE} 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_GROUP_NAME ; + 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_LOCALE} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public LocaleEntity Clone() { LocaleEntity result = new LocaleEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityActorEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityActorEntity.auto.cs index 47e5a33..2c2d8d1 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityActorEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityActorEntity.auto.cs @@ -14,45 +14,46 @@ namespace CloudBuilder.Security.Entity { } - [Column("actor_eng_name")] - public string? ActorEngName { get; set; } - [Column("actor_local_name")] - public string? ActorLocalName { get; set; } + [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("actor_name")] public string ActorName { get; set; } - [Column("created_by")] - public string CreatedBy { get; set; } - [Column("created_datetime")] - public DateTime CreatedDatetime { get; set; } - [Column("updated_by")] - public string UpdatedBy { get; set; } - [Column("updated_datetime")] - public DateTime UpdatedDatetime { get; set; } + [Column("actor_local_name")] + public string? ActorLocalName { get; set; } + [Column("actor_eng_name")] + public string? ActorEngName { get; set; } - public const string ACTOR_ENG_NAME = "ActorEngName"; - public const string ACTOR_LOCAL_NAME = "ActorLocalName"; - public const string ACTOR_NAME = "ActorName"; - public const string CREATED_BY = "CreatedBy"; public const string CREATED_DATETIME = "CreatedDatetime"; - public const string UPDATED_BY = "UpdatedBy"; + public const string CREATED_BY = "CreatedBy"; public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string UPDATED_BY = "UpdatedBy"; + public const string ACTOR_NAME = "ActorName"; + public const string ACTOR_LOCAL_NAME = "ActorLocalName"; + public const string ACTOR_ENG_NAME = "ActorEngName"; public const string DB_NAME_SECURITY_ACTOR = "security_actor"; - public const string DB_NAME_FIELDS="actor_eng_name,actor_local_name,actor_name,created_by,created_datetime,updated_by,updated_datetime"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,actor_name,actor_local_name,actor_eng_name"; - public const string DB_ACTOR_ENG_NAME = "actor_eng_name"; - public const string DB_ACTOR_LOCAL_NAME = "actor_local_name"; - public const string DB_ACTOR_NAME = "actor_name"; - public const string DB_CREATED_BY = "created_by"; public const string DB_CREATED_DATETIME = "created_datetime"; - 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_UPDATED_BY = "updated_by"; + public const string DB_ACTOR_NAME = "actor_name"; + public const string DB_ACTOR_LOCAL_NAME = "actor_local_name"; + public const string DB_ACTOR_ENG_NAME = "actor_eng_name"; + public string ProviderName { get; set; } - public static SecurityActorEntity GetInstance() + public static SecurityActorEntity GetInstance(string providerName) { - return new SecurityActorEntity(); + return new SecurityActorEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityActorEntity source) @@ -67,34 +68,89 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.ActorEngName = source.ActorEngName; - this.ActorLocalName = source.ActorLocalName; - this.ActorName = source.ActorName; - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; - this.UpdatedBy = source.UpdatedBy; + this.CreatedBy = source.CreatedBy; this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; + this.ActorName = source.ActorName; + this.ActorLocalName = source.ActorLocalName; + this.ActorEngName = source.ActorEngName; 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_ACTOR} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_ACTOR} "; } - + 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_ACTOR} 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_ACTOR} 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_ACTOR_NAME ; @@ -102,6 +158,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_ACTOR} 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_ACTOR_NAME ; + 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_ACTOR} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityActorEntity Clone() { SecurityActorEntity result = new SecurityActorEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityActorGroupEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityActorGroupEntity.auto.cs index 669bcd3..7a511eb 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityActorGroupEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityActorGroupEntity.auto.cs @@ -14,40 +14,41 @@ namespace CloudBuilder.Security.Entity { } - [Column("actor_name")] - public string ActorName { get; set; } - [Column("created_by")] - public string CreatedBy { get; set; } [Column("created_datetime")] public DateTime CreatedDatetime { get; set; } - [Column("group_name")] - public string GroupName { 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("updated_by")] + public string UpdatedBy { get; set; } + [Column("actor_name")] + public string ActorName { get; set; } + [Column("group_name")] + public string GroupName { get; set; } - public const string ACTOR_NAME = "ActorName"; - public const string CREATED_BY = "CreatedBy"; public const string CREATED_DATETIME = "CreatedDatetime"; - public const string GROUP_NAME = "GroupName"; - public const string UPDATED_BY = "UpdatedBy"; + public const string CREATED_BY = "CreatedBy"; public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string UPDATED_BY = "UpdatedBy"; + public const string ACTOR_NAME = "ActorName"; + public const string GROUP_NAME = "GroupName"; public const string DB_NAME_SECURITY_ACTOR_GROUP = "security_actor_group"; - public const string DB_NAME_FIELDS="actor_name,created_by,created_datetime,group_name,updated_by,updated_datetime"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,actor_name,group_name"; - public const string DB_ACTOR_NAME = "actor_name"; - public const string DB_CREATED_BY = "created_by"; public const string DB_CREATED_DATETIME = "created_datetime"; - public const string DB_GROUP_NAME = "group_name"; - 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_UPDATED_BY = "updated_by"; + public const string DB_ACTOR_NAME = "actor_name"; + public const string DB_GROUP_NAME = "group_name"; + public string ProviderName { get; set; } - public static SecurityActorGroupEntity GetInstance() + public static SecurityActorGroupEntity GetInstance(string providerName) { - return new SecurityActorGroupEntity(); + return new SecurityActorGroupEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityActorGroupEntity source) @@ -62,33 +63,88 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.ActorName = source.ActorName; - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; - this.GroupName = source.GroupName; - this.UpdatedBy = source.UpdatedBy; + this.CreatedBy = source.CreatedBy; this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; + this.ActorName = source.ActorName; + this.GroupName = source.GroupName; 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_ACTOR_GROUP} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_ACTOR_GROUP} "; } - + 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_ACTOR_GROUP} 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_ACTOR_GROUP} 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_ACTOR_NAME ; @@ -96,6 +152,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_ACTOR_GROUP} 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_ACTOR_NAME ; + 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_ACTOR_GROUP} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityActorGroupEntity Clone() { SecurityActorGroupEntity result = new SecurityActorGroupEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityActorGroupViewEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityActorGroupViewEntity.auto.cs index c9593cf..1f9c2aa 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityActorGroupViewEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityActorGroupViewEntity.auto.cs @@ -14,32 +14,33 @@ namespace CloudBuilder.Security.Entity { } - [Column("actor_local_name")] - public string? ActorLocalName { get; set; } [Column("actor_name")] public string ActorName { get; set; } - [Column("group_local_name")] - public string? GroupLocalName { get; set; } + [Column("actor_local_name")] + public string? ActorLocalName { get; set; } [Column("group_name")] public string GroupName { get; set; } + [Column("group_local_name")] + public string? GroupLocalName { get; set; } - public const string ACTOR_LOCAL_NAME = "ActorLocalName"; public const string ACTOR_NAME = "ActorName"; - public const string GROUP_LOCAL_NAME = "GroupLocalName"; + public const string ACTOR_LOCAL_NAME = "ActorLocalName"; public const string GROUP_NAME = "GroupName"; + public const string GROUP_LOCAL_NAME = "GroupLocalName"; public const string DB_NAME_SECURITY_ACTOR_GROUP_VIEW = "security_actor_group_view"; - public const string DB_NAME_FIELDS="actor_local_name,actor_name,group_local_name,group_name"; + public const string DB_NAME_FIELDS="actor_name,actor_local_name,group_name,group_local_name"; - public const string DB_ACTOR_LOCAL_NAME = "actor_local_name"; public const string DB_ACTOR_NAME = "actor_name"; - public const string DB_GROUP_LOCAL_NAME = "group_local_name"; + public const string DB_ACTOR_LOCAL_NAME = "actor_local_name"; public const string DB_GROUP_NAME = "group_name"; + public const string DB_GROUP_LOCAL_NAME = "group_local_name"; + public string ProviderName { get; set; } - public static SecurityActorGroupViewEntity GetInstance() + public static SecurityActorGroupViewEntity GetInstance(string providerName) { - return new SecurityActorGroupViewEntity(); + return new SecurityActorGroupViewEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityActorGroupViewEntity source) @@ -54,10 +55,10 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.ActorLocalName = source.ActorLocalName; this.ActorName = source.ActorName; - this.GroupLocalName = source.GroupLocalName; + this.ActorLocalName = source.ActorLocalName; this.GroupName = source.GroupName; + this.GroupLocalName = source.GroupLocalName; if (includeSystemFields) { @@ -65,23 +66,86 @@ namespace CloudBuilder.Security.Entity } 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_ACTOR_GROUP_VIEW} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_ACTOR_GROUP_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_ACTOR_GROUP_VIEW} 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_ACTOR_GROUP_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_ACTOR_LOCAL_NAME ; int offset = limit * (start - 1); + if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_ACTOR_NAME ; 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_ACTOR_GROUP_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_ACTOR_NAME ; 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_ACTOR_GROUP_VIEW} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityActorGroupViewEntity Clone() { SecurityActorGroupViewEntity result = new SecurityActorGroupViewEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityFunctionEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityFunctionEntity.auto.cs index 605efdf..8f72811 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityFunctionEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityFunctionEntity.auto.cs @@ -14,65 +14,66 @@ namespace CloudBuilder.Security.Entity { } - [Column("api_route")] - public string? ApiRoute { get; set; } - [Column("created_by")] - public string CreatedBy { get; set; } [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("function_name")] + public string FunctionName { get; set; } + [Column("function_local_name")] + public string? FunctionLocalName { get; set; } [Column("function_eng_name")] public string? FunctionEngName { get; set; } [Column("function_indc")] public string FunctionIndc { get; set; } - [Column("function_local_name")] - public string? FunctionLocalName { get; set; } - [Key] - [Column("function_name")] - public string FunctionName { get; set; } + [Column("page_url")] + public string? PageUrl { get; set; } + [Column("api_route")] + public string? ApiRoute { get; set; } [Column("icon")] public string? Icon { get; set; } [Column("page_name")] public string? PageName { get; set; } - [Column("page_url")] - public string? PageUrl { get; set; } - [Column("updated_by")] - public string UpdatedBy { get; set; } - [Column("updated_datetime")] - public DateTime UpdatedDatetime { get; set; } - public const string API_ROUTE = "ApiRoute"; - public const string CREATED_BY = "CreatedBy"; 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 FUNCTION_NAME = "FunctionName"; + public const string FUNCTION_LOCAL_NAME = "FunctionLocalName"; public const string FUNCTION_ENG_NAME = "FunctionEngName"; public const string FUNCTION_INDC = "FunctionIndc"; - public const string FUNCTION_LOCAL_NAME = "FunctionLocalName"; - public const string FUNCTION_NAME = "FunctionName"; + public const string PAGE_URL = "PageUrl"; + public const string API_ROUTE = "ApiRoute"; public const string ICON = "Icon"; public const string PAGE_NAME = "PageName"; - public const string PAGE_URL = "PageUrl"; - public const string UPDATED_BY = "UpdatedBy"; - public const string UPDATED_DATETIME = "UpdatedDatetime"; public const string DB_NAME_SECURITY_FUNCTION = "security_function"; - public const string DB_NAME_FIELDS="api_route,created_by,created_datetime,function_eng_name,function_indc,function_local_name,function_name,icon,page_name,page_url,updated_by,updated_datetime"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,function_name,function_local_name,function_eng_name,function_indc,page_url,api_route,icon,page_name"; - public const string DB_API_ROUTE = "api_route"; - public const string DB_CREATED_BY = "created_by"; 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_FUNCTION_NAME = "function_name"; + public const string DB_FUNCTION_LOCAL_NAME = "function_local_name"; public const string DB_FUNCTION_ENG_NAME = "function_eng_name"; public const string DB_FUNCTION_INDC = "function_indc"; - public const string DB_FUNCTION_LOCAL_NAME = "function_local_name"; - public const string DB_FUNCTION_NAME = "function_name"; + public const string DB_PAGE_URL = "page_url"; + public const string DB_API_ROUTE = "api_route"; public const string DB_ICON = "icon"; public const string DB_PAGE_NAME = "page_name"; - public const string DB_PAGE_URL = "page_url"; - public const string DB_UPDATED_BY = "updated_by"; - public const string DB_UPDATED_DATETIME = "updated_datetime"; + public string ProviderName { get; set; } - public static SecurityFunctionEntity GetInstance() + public static SecurityFunctionEntity GetInstance(string providerName) { - return new SecurityFunctionEntity(); + return new SecurityFunctionEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityFunctionEntity source) @@ -87,39 +88,94 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.ApiRoute = source.ApiRoute; - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; + this.CreatedBy = source.CreatedBy; + this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; + this.FunctionName = source.FunctionName; + this.FunctionLocalName = source.FunctionLocalName; this.FunctionEngName = source.FunctionEngName; this.FunctionIndc = source.FunctionIndc; - this.FunctionLocalName = source.FunctionLocalName; - this.FunctionName = source.FunctionName; + this.PageUrl = source.PageUrl; + this.ApiRoute = source.ApiRoute; this.Icon = source.Icon; this.PageName = source.PageName; - this.PageUrl = source.PageUrl; - this.UpdatedBy = source.UpdatedBy; - this.UpdatedDatetime = source.UpdatedDatetime; 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_FUNCTION} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_FUNCTION} "; } - + 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} 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_FUNCTION} 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_FUNCTION_NAME ; @@ -127,6 +183,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_FUNCTION} 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_FUNCTION_NAME ; + 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} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityFunctionEntity Clone() { SecurityFunctionEntity result = new SecurityFunctionEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityFunctionMapEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityFunctionMapEntity.auto.cs index 8aa32de..15771b7 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityFunctionMapEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityFunctionMapEntity.auto.cs @@ -14,44 +14,45 @@ namespace CloudBuilder.Security.Entity { } - [Column("created_by")] - public string CreatedBy { get; set; } [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("function_name_parent")] public string FunctionNameParent { get; set; } [Column("function_name_son")] public string FunctionNameSon { get; set; } [Column("orderby")] public int Orderby { get; set; } - [Column("updated_by")] - public string UpdatedBy { get; set; } - [Column("updated_datetime")] - public DateTime UpdatedDatetime { get; set; } - public const string CREATED_BY = "CreatedBy"; 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 FUNCTION_NAME_PARENT = "FunctionNameParent"; public const string FUNCTION_NAME_SON = "FunctionNameSon"; public const string ORDERBY = "Orderby"; - public const string UPDATED_BY = "UpdatedBy"; - public const string UPDATED_DATETIME = "UpdatedDatetime"; public const string DB_NAME_SECURITY_FUNCTION_MAP = "security_function_map"; - public const string DB_NAME_FIELDS="created_by,created_datetime,function_name_parent,function_name_son,orderby,updated_by,updated_datetime"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,function_name_parent,function_name_son,orderby"; - public const string DB_CREATED_BY = "created_by"; 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_FUNCTION_NAME_PARENT = "function_name_parent"; public const string DB_FUNCTION_NAME_SON = "function_name_son"; public const string DB_ORDERBY = "orderby"; - public const string DB_UPDATED_BY = "updated_by"; - public const string DB_UPDATED_DATETIME = "updated_datetime"; + public string ProviderName { get; set; } - public static SecurityFunctionMapEntity GetInstance() + public static SecurityFunctionMapEntity GetInstance(string providerName) { - return new SecurityFunctionMapEntity(); + return new SecurityFunctionMapEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityFunctionMapEntity source) @@ -66,34 +67,89 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; + this.CreatedBy = source.CreatedBy; + this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; this.FunctionNameParent = source.FunctionNameParent; this.FunctionNameSon = source.FunctionNameSon; this.Orderby = source.Orderby; - this.UpdatedBy = source.UpdatedBy; - this.UpdatedDatetime = source.UpdatedDatetime; 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_FUNCTION_MAP} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_FUNCTION_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_SECURITY_FUNCTION_MAP} 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_FUNCTION_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_FUNCTION_NAME_PARENT ; @@ -101,6 +157,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_FUNCTION_MAP} 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_FUNCTION_NAME_PARENT ; + 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} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityFunctionMapEntity Clone() { SecurityFunctionMapEntity result = new SecurityFunctionMapEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityFunctionMapViewEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityFunctionMapViewEntity.auto.cs index cfea446..b22e4ab 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityFunctionMapViewEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityFunctionMapViewEntity.auto.cs @@ -16,38 +16,39 @@ namespace CloudBuilder.Security.Entity [Column("orderby")] public int Orderby { get; set; } - [Column("parent_function_local_name")] - public string? ParentFunctionLocalName { get; set; } [Column("parent_function_name")] public string ParentFunctionName { get; set; } - [Column("son_function_local_name")] - public string? SonFunctionLocalName { 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_LOCAL_NAME = "ParentFunctionLocalName"; public const string PARENT_FUNCTION_NAME = "ParentFunctionName"; - public const string SON_FUNCTION_LOCAL_NAME = "SonFunctionLocalName"; + 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_local_name,parent_function_name,son_function_local_name,son_function_name,son_page_name"; + 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_LOCAL_NAME = "parent_function_local_name"; public const string DB_PARENT_FUNCTION_NAME = "parent_function_name"; - public const string DB_SON_FUNCTION_LOCAL_NAME = "son_function_local_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"; + public string ProviderName { get; set; } - public static SecurityFunctionMapViewEntity GetInstance() + public static SecurityFunctionMapViewEntity GetInstance(string providerName) { - return new SecurityFunctionMapViewEntity(); + return new SecurityFunctionMapViewEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityFunctionMapViewEntity source) @@ -63,10 +64,10 @@ namespace CloudBuilder.Security.Entity } this.Orderby = source.Orderby; - this.ParentFunctionLocalName = source.ParentFunctionLocalName; this.ParentFunctionName = source.ParentFunctionName; - this.SonFunctionLocalName = source.SonFunctionLocalName; + this.ParentFunctionLocalName = source.ParentFunctionLocalName; this.SonFunctionName = source.SonFunctionName; + this.SonFunctionLocalName = source.SonFunctionLocalName; this.SonPageName = source.SonPageName; if (includeSystemFields) @@ -75,16 +76,71 @@ namespace CloudBuilder.Security.Entity } 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 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_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"; @@ -92,6 +148,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_FUNCTION_MAP_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_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(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityGeneratorNumberEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityGeneratorNumberEntity.auto.cs index 7dbd182..288ff90 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityGeneratorNumberEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityGeneratorNumberEntity.auto.cs @@ -14,66 +14,67 @@ namespace CloudBuilder.Security.Entity { } - [Column("created_by")] - public string CreatedBy { get; set; } [Column("created_datetime")] public DateTime CreatedDatetime { get; set; } - [Column("format")] - public string Format { 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("generator_id")] public int GeneratorId { get; set; } - [Column("last_generator_date")] - public DateTime LastGeneratorDate { get; set; } - [Column("next_id")] - public int NextId { get; set; } + [Column("system_id")] + public string SystemId { get; set; } + [Column("subsystem_id")] + public string SubsystemId { get; set; } [Column("prefix")] public string? Prefix { get; set; } [Column("refresh_period")] public string RefreshPeriod { get; set; } - [Column("subsystem_id")] - public string SubsystemId { get; set; } - [Column("system_id")] - public string SystemId { get; set; } - [Column("updated_by")] - public string UpdatedBy { get; set; } - [Column("updated_datetime")] - public DateTime UpdatedDatetime { get; set; } + [Column("format")] + public string Format { get; set; } + [Column("last_generator_date")] + public DateTime LastGeneratorDate { get; set; } + [Column("next_id")] + public int NextId { get; set; } - public const string CREATED_BY = "CreatedBy"; public const string CREATED_DATETIME = "CreatedDatetime"; - public const string FORMAT = "Format"; + public const string CREATED_BY = "CreatedBy"; + public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string UPDATED_BY = "UpdatedBy"; public const string GENERATOR_ID = "GeneratorId"; - public const string LAST_GENERATOR_DATE = "LastGeneratorDate"; - public const string NEXT_ID = "NextId"; + public const string SYSTEM_ID = "SystemId"; + public const string SUBSYSTEM_ID = "SubsystemId"; public const string PREFIX = "Prefix"; public const string REFRESH_PERIOD = "RefreshPeriod"; - public const string SUBSYSTEM_ID = "SubsystemId"; - public const string SYSTEM_ID = "SystemId"; - public const string UPDATED_BY = "UpdatedBy"; - public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string FORMAT = "Format"; + public const string LAST_GENERATOR_DATE = "LastGeneratorDate"; + public const string NEXT_ID = "NextId"; public const string DB_NAME_SECURITY_GENERATOR_NUMBER = "security_generator_number"; - public const string DB_NAME_FIELDS="created_by,created_datetime,format,generator_id,last_generator_date,next_id,prefix,refresh_period,subsystem_id,system_id,updated_by,updated_datetime"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,generator_id,system_id,subsystem_id,prefix,refresh_period,format,last_generator_date,next_id"; - public const string DB_CREATED_BY = "created_by"; public const string DB_CREATED_DATETIME = "created_datetime"; - public const string DB_FORMAT = "format"; + 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_GENERATOR_ID = "generator_id"; - public const string DB_LAST_GENERATOR_DATE = "last_generator_date"; - public const string DB_NEXT_ID = "next_id"; + public const string DB_SYSTEM_ID = "system_id"; + public const string DB_SUBSYSTEM_ID = "subsystem_id"; public const string DB_PREFIX = "prefix"; public const string DB_REFRESH_PERIOD = "refresh_period"; - public const string DB_SUBSYSTEM_ID = "subsystem_id"; - public const string DB_SYSTEM_ID = "system_id"; - public const string DB_UPDATED_BY = "updated_by"; - public const string DB_UPDATED_DATETIME = "updated_datetime"; + public const string DB_FORMAT = "format"; + public const string DB_LAST_GENERATOR_DATE = "last_generator_date"; + public const string DB_NEXT_ID = "next_id"; + public string ProviderName { get; set; } - public static SecurityGeneratorNumberEntity GetInstance() + public static SecurityGeneratorNumberEntity GetInstance(string providerName) { - return new SecurityGeneratorNumberEntity(); + return new SecurityGeneratorNumberEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityGeneratorNumberEntity source) @@ -88,39 +89,94 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; - this.Format = source.Format; + this.CreatedBy = source.CreatedBy; + this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; this.GeneratorId = source.GeneratorId; - this.LastGeneratorDate = source.LastGeneratorDate; - this.NextId = source.NextId; + this.SystemId = source.SystemId; + this.SubsystemId = source.SubsystemId; this.Prefix = source.Prefix; this.RefreshPeriod = source.RefreshPeriod; - this.SubsystemId = source.SubsystemId; - this.SystemId = source.SystemId; - this.UpdatedBy = source.UpdatedBy; - this.UpdatedDatetime = source.UpdatedDatetime; + this.Format = source.Format; + this.LastGeneratorDate = source.LastGeneratorDate; + this.NextId = source.NextId; 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_GENERATOR_NUMBER} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_GENERATOR_NUMBER} "; } - + 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_GENERATOR_NUMBER} 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_GENERATOR_NUMBER} 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_GENERATOR_ID ; @@ -128,6 +184,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_GENERATOR_NUMBER} 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_GENERATOR_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_SECURITY_GENERATOR_NUMBER} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityGeneratorNumberEntity Clone() { SecurityGeneratorNumberEntity result = new SecurityGeneratorNumberEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupEntity.auto.cs index 5219f09..293d1f4 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupEntity.auto.cs @@ -14,45 +14,46 @@ namespace CloudBuilder.Security.Entity { } - [Column("created_by")] - public string CreatedBy { get; set; } [Column("created_datetime")] public DateTime CreatedDatetime { get; set; } - [Column("group_eng_name")] - public string? GroupEngName { get; set; } - [Column("group_local_name")] - public string? GroupLocalName { 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("group_name")] public string GroupName { get; set; } - [Column("updated_by")] - public string UpdatedBy { get; set; } - [Column("updated_datetime")] - public DateTime UpdatedDatetime { get; set; } + [Column("group_local_name")] + public string? GroupLocalName { get; set; } + [Column("group_eng_name")] + public string? GroupEngName { get; set; } - public const string CREATED_BY = "CreatedBy"; public const string CREATED_DATETIME = "CreatedDatetime"; - public const string GROUP_ENG_NAME = "GroupEngName"; - public const string GROUP_LOCAL_NAME = "GroupLocalName"; - public const string GROUP_NAME = "GroupName"; - public const string UPDATED_BY = "UpdatedBy"; + public const string CREATED_BY = "CreatedBy"; public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string UPDATED_BY = "UpdatedBy"; + public const string GROUP_NAME = "GroupName"; + public const string GROUP_LOCAL_NAME = "GroupLocalName"; + public const string GROUP_ENG_NAME = "GroupEngName"; public const string DB_NAME_SECURITY_GROUP = "security_group"; - public const string DB_NAME_FIELDS="created_by,created_datetime,group_eng_name,group_local_name,group_name,updated_by,updated_datetime"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,group_name,group_local_name,group_eng_name"; - public const string DB_CREATED_BY = "created_by"; public const string DB_CREATED_DATETIME = "created_datetime"; - public const string DB_GROUP_ENG_NAME = "group_eng_name"; - public const string DB_GROUP_LOCAL_NAME = "group_local_name"; - public const string DB_GROUP_NAME = "group_name"; - 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_UPDATED_BY = "updated_by"; + public const string DB_GROUP_NAME = "group_name"; + public const string DB_GROUP_LOCAL_NAME = "group_local_name"; + public const string DB_GROUP_ENG_NAME = "group_eng_name"; + public string ProviderName { get; set; } - public static SecurityGroupEntity GetInstance() + public static SecurityGroupEntity GetInstance(string providerName) { - return new SecurityGroupEntity(); + return new SecurityGroupEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityGroupEntity source) @@ -67,34 +68,89 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; - this.GroupEngName = source.GroupEngName; - this.GroupLocalName = source.GroupLocalName; - this.GroupName = source.GroupName; - this.UpdatedBy = source.UpdatedBy; + this.CreatedBy = source.CreatedBy; this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; + this.GroupName = source.GroupName; + this.GroupLocalName = source.GroupLocalName; + this.GroupEngName = source.GroupEngName; 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_GROUP} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_GROUP} "; } - + 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_GROUP} 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_GROUP} 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_GROUP_NAME ; @@ -102,6 +158,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_GROUP} 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_GROUP_NAME ; + 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_GROUP} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityGroupEntity Clone() { SecurityGroupEntity result = new SecurityGroupEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionDependentEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionDependentEntity.auto.cs index 847e142..8f47207 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionDependentEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionDependentEntity.auto.cs @@ -14,60 +14,61 @@ namespace CloudBuilder.Security.Entity { } - [Column("amend_indc")] - public string AmendIndc { get; set; } - [Column("create_indc")] - public string CreateIndc { get; set; } - [Column("created_by")] - public string CreatedBy { get; set; } [Column("created_datetime")] public DateTime CreatedDatetime { get; set; } - [Column("delete_indc")] - public string DeleteIndc { get; set; } - [Column("dependent_detail_name")] - public string DependentDetailName { 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("group_name")] public string GroupName { get; set; } [Column("permission_name")] public string PermissionName { get; set; } - [Column("updated_by")] - public string UpdatedBy { get; set; } - [Column("updated_datetime")] - public DateTime UpdatedDatetime { get; set; } + [Column("dependent_detail_name")] + public string DependentDetailName { get; set; } [Column("view_indc")] public string ViewIndc { get; set; } + [Column("create_indc")] + public string CreateIndc { get; set; } + [Column("amend_indc")] + public string AmendIndc { get; set; } + [Column("delete_indc")] + public string DeleteIndc { get; set; } - public const string AMEND_INDC = "AmendIndc"; - public const string CREATE_INDC = "CreateIndc"; - public const string CREATED_BY = "CreatedBy"; public const string CREATED_DATETIME = "CreatedDatetime"; - public const string DELETE_INDC = "DeleteIndc"; - public const string DEPENDENT_DETAIL_NAME = "DependentDetailName"; + public const string CREATED_BY = "CreatedBy"; + public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string UPDATED_BY = "UpdatedBy"; public const string GROUP_NAME = "GroupName"; public const string PERMISSION_NAME = "PermissionName"; - public const string UPDATED_BY = "UpdatedBy"; - public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string DEPENDENT_DETAIL_NAME = "DependentDetailName"; public const string VIEW_INDC = "ViewIndc"; + public const string CREATE_INDC = "CreateIndc"; + public const string AMEND_INDC = "AmendIndc"; + public const string DELETE_INDC = "DeleteIndc"; public const string DB_NAME_SECURITY_GROUP_PERMISSION_DEPENDENT = "security_group_permission_dependent"; - public const string DB_NAME_FIELDS="amend_indc,create_indc,created_by,created_datetime,delete_indc,dependent_detail_name,group_name,permission_name,updated_by,updated_datetime,view_indc"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,group_name,permission_name,dependent_detail_name,view_indc,create_indc,amend_indc,delete_indc"; - public const string DB_AMEND_INDC = "amend_indc"; - public const string DB_CREATE_INDC = "create_indc"; - public const string DB_CREATED_BY = "created_by"; public const string DB_CREATED_DATETIME = "created_datetime"; - public const string DB_DELETE_INDC = "delete_indc"; - public const string DB_DEPENDENT_DETAIL_NAME = "dependent_detail_name"; + 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_GROUP_NAME = "group_name"; public const string DB_PERMISSION_NAME = "permission_name"; - public const string DB_UPDATED_BY = "updated_by"; - public const string DB_UPDATED_DATETIME = "updated_datetime"; + public const string DB_DEPENDENT_DETAIL_NAME = "dependent_detail_name"; public const string DB_VIEW_INDC = "view_indc"; + public const string DB_CREATE_INDC = "create_indc"; + public const string DB_AMEND_INDC = "amend_indc"; + public const string DB_DELETE_INDC = "delete_indc"; + public string ProviderName { get; set; } - public static SecurityGroupPermissionDependentEntity GetInstance() + public static SecurityGroupPermissionDependentEntity GetInstance(string providerName) { - return new SecurityGroupPermissionDependentEntity(); + return new SecurityGroupPermissionDependentEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityGroupPermissionDependentEntity source) @@ -82,45 +83,108 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.AmendIndc = source.AmendIndc; - this.CreateIndc = source.CreateIndc; - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; - this.DeleteIndc = source.DeleteIndc; - this.DependentDetailName = source.DependentDetailName; + this.CreatedBy = source.CreatedBy; + this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; this.GroupName = source.GroupName; this.PermissionName = source.PermissionName; - this.UpdatedBy = source.UpdatedBy; - this.UpdatedDatetime = source.UpdatedDatetime; + this.DependentDetailName = source.DependentDetailName; this.ViewIndc = source.ViewIndc; + this.CreateIndc = source.CreateIndc; + this.AmendIndc = source.AmendIndc; + this.DeleteIndc = source.DeleteIndc; 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_GROUP_PERMISSION_DEPENDENT} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_GROUP_PERMISSION_DEPENDENT} "; } - + 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_GROUP_PERMISSION_DEPENDENT} 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_GROUP_PERMISSION_DEPENDENT} 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_DEPENDENT_DETAIL_NAME ; + if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_GROUP_NAME ; 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_GROUP_PERMISSION_DEPENDENT} 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_GROUP_NAME ; + 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_GROUP_PERMISSION_DEPENDENT} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityGroupPermissionDependentEntity Clone() { SecurityGroupPermissionDependentEntity result = new SecurityGroupPermissionDependentEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionDependentEntityKey.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionDependentEntityKey.auto.cs index 015546e..5208499 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionDependentEntityKey.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionDependentEntityKey.auto.cs @@ -5,9 +5,9 @@ namespace CloudBuilder.Security [TypeScript] public class SecurityGroupPermissionDependentEntityKey { - public string DependentDetailName { get; set; } public string GroupName { get; set; } public string PermissionName { get; set; } + public string DependentDetailName { get; set; } public override bool Equals(object obj) { @@ -16,9 +16,9 @@ namespace CloudBuilder.Security SecurityGroupPermissionDependentEntityKey pkey = obj as SecurityGroupPermissionDependentEntityKey; if (pkey == null) return false; - if (DependentDetailName != pkey.DependentDetailName) return false; if (GroupName != pkey.GroupName) return false; if (PermissionName != pkey.PermissionName) return false; + if (DependentDetailName != pkey.DependentDetailName) return false; return true; } @@ -27,9 +27,9 @@ namespace CloudBuilder.Security public override string ToString() { string declareSql=""; - declareSql=declareSql+$"declare @__tkey_DependentDetailName_0 varchar(50) select @__tkey_DependentDetailName_0 ='{DependentDetailName}'; " ; declareSql=declareSql+$"declare @__tkey_GroupName_1 varchar(50) select @__tkey_GroupName_1 ='{GroupName}'; " ; declareSql=declareSql+$"declare @__tkey_PermissionName_2 varchar(50) select @__tkey_PermissionName_2 ='{PermissionName}'; " ; + declareSql=declareSql+$"declare @__tkey_GroupName_0 varchar(50) select @__tkey_GroupName_0 ='{GroupName}'; " ; declareSql=declareSql+$"declare @__tkey_PermissionName_1 varchar(50) select @__tkey_PermissionName_1 ='{PermissionName}'; " ; declareSql=declareSql+$"declare @__tkey_DependentDetailName_2 varchar(50) select @__tkey_DependentDetailName_2 ='{DependentDetailName}'; " ; return declareSql; } } } - /* builder.Entity().HasKey(c => new { c.DependentDetailName, c.GroupName, c.PermissionName}); */ + /* builder.Entity().HasKey(c => new { c.GroupName, c.PermissionName, c.DependentDetailName}); */ diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionDependentViewEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionDependentViewEntity.auto.cs index 170363f..30b962f 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionDependentViewEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionDependentViewEntity.auto.cs @@ -14,56 +14,57 @@ namespace CloudBuilder.Security.Entity { } - [Column("amend_indc")] - public string AmendIndc { get; set; } - [Column("create_indc")] - public string CreateIndc { get; set; } - [Column("delete_indc")] - public string DeleteIndc { get; set; } - [Column("dependent")] - public string Dependent { get; set; } - [Column("dependent_detail_description")] - public string? DependentDetailDescription { get; set; } - [Column("dependent_detail_name")] - public string DependentDetailName { get; set; } [Column("group_name")] public string GroupName { get; set; } - [Column("permission_description")] - public string? PermissionDescription { get; set; } [Column("permission_name")] public string PermissionName { get; set; } [Column("view_indc")] public string ViewIndc { get; set; } + [Column("create_indc")] + public string CreateIndc { get; set; } + [Column("amend_indc")] + public string AmendIndc { get; set; } + [Column("delete_indc")] + public string DeleteIndc { get; set; } + [Column("dependent_detail_name")] + public string DependentDetailName { get; set; } + [Column("permission_description")] + public string? PermissionDescription { get; set; } + [Column("dependent_detail_description")] + public string? DependentDetailDescription { get; set; } + [Column("dependent")] + public string Dependent { get; set; } - public const string AMEND_INDC = "AmendIndc"; - public const string CREATE_INDC = "CreateIndc"; - public const string DELETE_INDC = "DeleteIndc"; - public const string DEPENDENT = "Dependent"; - public const string DEPENDENT_DETAIL_DESCRIPTION = "DependentDetailDescription"; - public const string DEPENDENT_DETAIL_NAME = "DependentDetailName"; public const string GROUP_NAME = "GroupName"; - public const string PERMISSION_DESCRIPTION = "PermissionDescription"; public const string PERMISSION_NAME = "PermissionName"; public const string VIEW_INDC = "ViewIndc"; + public const string CREATE_INDC = "CreateIndc"; + public const string AMEND_INDC = "AmendIndc"; + public const string DELETE_INDC = "DeleteIndc"; + public const string DEPENDENT_DETAIL_NAME = "DependentDetailName"; + public const string PERMISSION_DESCRIPTION = "PermissionDescription"; + public const string DEPENDENT_DETAIL_DESCRIPTION = "DependentDetailDescription"; + public const string DEPENDENT = "Dependent"; public const string DB_NAME_SECURITY_GROUP_PERMISSION_DEPENDENT_VIEW = "security_group_permission_dependent_view"; - public const string DB_NAME_FIELDS="amend_indc,create_indc,delete_indc,dependent,dependent_detail_description,dependent_detail_name,group_name,permission_description,permission_name,view_indc"; + public const string DB_NAME_FIELDS="group_name,permission_name,view_indc,create_indc,amend_indc,delete_indc,dependent_detail_name,permission_description,dependent_detail_description,dependent"; - public const string DB_AMEND_INDC = "amend_indc"; - public const string DB_CREATE_INDC = "create_indc"; - public const string DB_DELETE_INDC = "delete_indc"; - public const string DB_DEPENDENT = "dependent"; - public const string DB_DEPENDENT_DETAIL_DESCRIPTION = "dependent_detail_description"; - public const string DB_DEPENDENT_DETAIL_NAME = "dependent_detail_name"; public const string DB_GROUP_NAME = "group_name"; - public const string DB_PERMISSION_DESCRIPTION = "permission_description"; public const string DB_PERMISSION_NAME = "permission_name"; public const string DB_VIEW_INDC = "view_indc"; + public const string DB_CREATE_INDC = "create_indc"; + public const string DB_AMEND_INDC = "amend_indc"; + public const string DB_DELETE_INDC = "delete_indc"; + public const string DB_DEPENDENT_DETAIL_NAME = "dependent_detail_name"; + public const string DB_PERMISSION_DESCRIPTION = "permission_description"; + public const string DB_DEPENDENT_DETAIL_DESCRIPTION = "dependent_detail_description"; + public const string DB_DEPENDENT = "dependent"; + public string ProviderName { get; set; } - public static SecurityGroupPermissionDependentViewEntity GetInstance() + public static SecurityGroupPermissionDependentViewEntity GetInstance(string providerName) { - return new SecurityGroupPermissionDependentViewEntity(); + return new SecurityGroupPermissionDependentViewEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityGroupPermissionDependentViewEntity source) @@ -78,16 +79,16 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.AmendIndc = source.AmendIndc; - this.CreateIndc = source.CreateIndc; - this.DeleteIndc = source.DeleteIndc; - this.Dependent = source.Dependent; - this.DependentDetailDescription = source.DependentDetailDescription; - this.DependentDetailName = source.DependentDetailName; this.GroupName = source.GroupName; - this.PermissionDescription = source.PermissionDescription; this.PermissionName = source.PermissionName; this.ViewIndc = source.ViewIndc; + this.CreateIndc = source.CreateIndc; + this.AmendIndc = source.AmendIndc; + this.DeleteIndc = source.DeleteIndc; + this.DependentDetailName = source.DependentDetailName; + this.PermissionDescription = source.PermissionDescription; + this.DependentDetailDescription = source.DependentDetailDescription; + this.Dependent = source.Dependent; if (includeSystemFields) { @@ -95,23 +96,86 @@ namespace CloudBuilder.Security.Entity } 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_GROUP_PERMISSION_DEPENDENT_VIEW} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_GROUP_PERMISSION_DEPENDENT_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_GROUP_PERMISSION_DEPENDENT_VIEW} 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_GROUP_PERMISSION_DEPENDENT_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_AMEND_INDC ; int offset = limit * (start - 1); + if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_GROUP_NAME ; 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_GROUP_PERMISSION_DEPENDENT_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_GROUP_NAME ; 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_GROUP_PERMISSION_DEPENDENT_VIEW} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityGroupPermissionDependentViewEntity Clone() { SecurityGroupPermissionDependentViewEntity result = new SecurityGroupPermissionDependentViewEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionEntity.auto.cs index 1492a96..3327d6c 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionEntity.auto.cs @@ -14,60 +14,61 @@ namespace CloudBuilder.Security.Entity { } - [Column("amend_indc")] - public string AmendIndc { get; set; } - [Column("create_indc")] - public string CreateIndc { get; set; } - [Column("created_by")] - public string CreatedBy { get; set; } [Column("created_datetime")] public DateTime CreatedDatetime { get; set; } - [Column("delete_indc")] - public string DeleteIndc { get; set; } - [Column("dependent")] - public string? Dependent { 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("group_name")] public string GroupName { get; set; } [Column("permission_name")] public string PermissionName { get; set; } - [Column("updated_by")] - public string UpdatedBy { get; set; } - [Column("updated_datetime")] - public DateTime UpdatedDatetime { get; set; } [Column("view_indc")] public string ViewIndc { get; set; } + [Column("create_indc")] + public string CreateIndc { get; set; } + [Column("amend_indc")] + public string AmendIndc { get; set; } + [Column("delete_indc")] + public string DeleteIndc { get; set; } + [Column("dependent")] + public string? Dependent { get; set; } - public const string AMEND_INDC = "AmendIndc"; - public const string CREATE_INDC = "CreateIndc"; - public const string CREATED_BY = "CreatedBy"; public const string CREATED_DATETIME = "CreatedDatetime"; - public const string DELETE_INDC = "DeleteIndc"; - public const string DEPENDENT = "Dependent"; + public const string CREATED_BY = "CreatedBy"; + public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string UPDATED_BY = "UpdatedBy"; public const string GROUP_NAME = "GroupName"; public const string PERMISSION_NAME = "PermissionName"; - public const string UPDATED_BY = "UpdatedBy"; - public const string UPDATED_DATETIME = "UpdatedDatetime"; public const string VIEW_INDC = "ViewIndc"; + public const string CREATE_INDC = "CreateIndc"; + public const string AMEND_INDC = "AmendIndc"; + public const string DELETE_INDC = "DeleteIndc"; + public const string DEPENDENT = "Dependent"; public const string DB_NAME_SECURITY_GROUP_PERMISSION = "security_group_permission"; - public const string DB_NAME_FIELDS="amend_indc,create_indc,created_by,created_datetime,delete_indc,dependent,group_name,permission_name,updated_by,updated_datetime,view_indc"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,group_name,permission_name,view_indc,create_indc,amend_indc,delete_indc,dependent"; - public const string DB_AMEND_INDC = "amend_indc"; - public const string DB_CREATE_INDC = "create_indc"; - public const string DB_CREATED_BY = "created_by"; public const string DB_CREATED_DATETIME = "created_datetime"; - public const string DB_DELETE_INDC = "delete_indc"; - public const string DB_DEPENDENT = "dependent"; + 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_GROUP_NAME = "group_name"; public const string DB_PERMISSION_NAME = "permission_name"; - public const string DB_UPDATED_BY = "updated_by"; - public const string DB_UPDATED_DATETIME = "updated_datetime"; public const string DB_VIEW_INDC = "view_indc"; + public const string DB_CREATE_INDC = "create_indc"; + public const string DB_AMEND_INDC = "amend_indc"; + public const string DB_DELETE_INDC = "delete_indc"; + public const string DB_DEPENDENT = "dependent"; + public string ProviderName { get; set; } - public static SecurityGroupPermissionEntity GetInstance() + public static SecurityGroupPermissionEntity GetInstance(string providerName) { - return new SecurityGroupPermissionEntity(); + return new SecurityGroupPermissionEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityGroupPermissionEntity source) @@ -82,38 +83,93 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.AmendIndc = source.AmendIndc; - this.CreateIndc = source.CreateIndc; - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; - this.DeleteIndc = source.DeleteIndc; - this.Dependent = source.Dependent; + this.CreatedBy = source.CreatedBy; + this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; this.GroupName = source.GroupName; this.PermissionName = source.PermissionName; - this.UpdatedBy = source.UpdatedBy; - this.UpdatedDatetime = source.UpdatedDatetime; this.ViewIndc = source.ViewIndc; + this.CreateIndc = source.CreateIndc; + this.AmendIndc = source.AmendIndc; + this.DeleteIndc = source.DeleteIndc; + this.Dependent = source.Dependent; 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_GROUP_PERMISSION} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_GROUP_PERMISSION} "; } - + 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_GROUP_PERMISSION} 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_GROUP_PERMISSION} 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_GROUP_NAME ; @@ -121,6 +177,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_GROUP_PERMISSION} 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_GROUP_NAME ; + 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_GROUP_PERMISSION} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityGroupPermissionEntity Clone() { SecurityGroupPermissionEntity result = new SecurityGroupPermissionEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionViewEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionViewEntity.auto.cs index 23c885e..302b352 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionViewEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityGroupPermissionViewEntity.auto.cs @@ -14,48 +14,49 @@ namespace CloudBuilder.Security.Entity { } - [Column("amend_indc")] - public string AmendIndc { get; set; } - [Column("create_indc")] - public string CreateIndc { get; set; } - [Column("delete_indc")] - public string DeleteIndc { get; set; } - [Column("dependent")] - public string? Dependent { get; set; } [Column("group_name")] public string GroupName { get; set; } - [Column("permission_description")] - public string? PermissionDescription { get; set; } [Column("permission_name")] public string PermissionName { get; set; } [Column("view_indc")] public string ViewIndc { get; set; } + [Column("create_indc")] + public string CreateIndc { get; set; } + [Column("amend_indc")] + public string AmendIndc { get; set; } + [Column("delete_indc")] + public string DeleteIndc { get; set; } + [Column("dependent")] + public string? Dependent { get; set; } + [Column("permission_description")] + public string? PermissionDescription { get; set; } - public const string AMEND_INDC = "AmendIndc"; - public const string CREATE_INDC = "CreateIndc"; - public const string DELETE_INDC = "DeleteIndc"; - public const string DEPENDENT = "Dependent"; public const string GROUP_NAME = "GroupName"; - public const string PERMISSION_DESCRIPTION = "PermissionDescription"; public const string PERMISSION_NAME = "PermissionName"; public const string VIEW_INDC = "ViewIndc"; + public const string CREATE_INDC = "CreateIndc"; + public const string AMEND_INDC = "AmendIndc"; + public const string DELETE_INDC = "DeleteIndc"; + public const string DEPENDENT = "Dependent"; + public const string PERMISSION_DESCRIPTION = "PermissionDescription"; public const string DB_NAME_SECURITY_GROUP_PERMISSION_VIEW = "security_group_permission_view"; - public const string DB_NAME_FIELDS="amend_indc,create_indc,delete_indc,dependent,group_name,permission_description,permission_name,view_indc"; + public const string DB_NAME_FIELDS="group_name,permission_name,view_indc,create_indc,amend_indc,delete_indc,dependent,permission_description"; - public const string DB_AMEND_INDC = "amend_indc"; - public const string DB_CREATE_INDC = "create_indc"; - public const string DB_DELETE_INDC = "delete_indc"; - public const string DB_DEPENDENT = "dependent"; public const string DB_GROUP_NAME = "group_name"; - public const string DB_PERMISSION_DESCRIPTION = "permission_description"; public const string DB_PERMISSION_NAME = "permission_name"; public const string DB_VIEW_INDC = "view_indc"; + public const string DB_CREATE_INDC = "create_indc"; + public const string DB_AMEND_INDC = "amend_indc"; + public const string DB_DELETE_INDC = "delete_indc"; + public const string DB_DEPENDENT = "dependent"; + public const string DB_PERMISSION_DESCRIPTION = "permission_description"; + public string ProviderName { get; set; } - public static SecurityGroupPermissionViewEntity GetInstance() + public static SecurityGroupPermissionViewEntity GetInstance(string providerName) { - return new SecurityGroupPermissionViewEntity(); + return new SecurityGroupPermissionViewEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityGroupPermissionViewEntity source) @@ -70,14 +71,14 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.AmendIndc = source.AmendIndc; - this.CreateIndc = source.CreateIndc; - this.DeleteIndc = source.DeleteIndc; - this.Dependent = source.Dependent; this.GroupName = source.GroupName; - this.PermissionDescription = source.PermissionDescription; this.PermissionName = source.PermissionName; this.ViewIndc = source.ViewIndc; + this.CreateIndc = source.CreateIndc; + this.AmendIndc = source.AmendIndc; + this.DeleteIndc = source.DeleteIndc; + this.Dependent = source.Dependent; + this.PermissionDescription = source.PermissionDescription; if (includeSystemFields) { @@ -85,23 +86,86 @@ namespace CloudBuilder.Security.Entity } 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_GROUP_PERMISSION_VIEW} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_GROUP_PERMISSION_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_GROUP_PERMISSION_VIEW} 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_GROUP_PERMISSION_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_AMEND_INDC ; int offset = limit * (start - 1); + if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_GROUP_NAME ; 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_GROUP_PERMISSION_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_GROUP_NAME ; 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_GROUP_PERMISSION_VIEW} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityGroupPermissionViewEntity Clone() { SecurityGroupPermissionViewEntity result = new SecurityGroupPermissionViewEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityInitializerTickViewEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityInitializerTickViewEntity.auto.cs index 3c55e33..d19d4d6 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityInitializerTickViewEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityInitializerTickViewEntity.auto.cs @@ -1,3 +1,4 @@ + using CloudBuilder.Core.Authorization; using CloudBuilder.Core.DatabaseAccessor.Entity; using System.ComponentModel.DataAnnotations; @@ -67,10 +68,11 @@ namespace CloudBuilder.Security.Entity public const string DB_SECURITY_USER_UPD = "security_user_upd"; public const string DB_SECURITY_USER_ACTOR_UPD = "security_user_actor_upd"; + public string ProviderName { get; set; } - public static SecurityInitializerTickViewEntity GetInstance() + public static SecurityInitializerTickViewEntity GetInstance(string providerName) { - return new SecurityInitializerTickViewEntity(); + return new SecurityInitializerTickViewEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityInitializerTickViewEntity source) @@ -104,21 +106,84 @@ namespace CloudBuilder.Security.Entity } 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_INITIALIZER_TICK_VIEW} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_INITIALIZER_TICK_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_INITIALIZER_TICK_VIEW} 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_INITIALIZER_TICK_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_SECURITY_ACTOR_UPD ; 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_INITIALIZER_TICK_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_SECURITY_ACTOR_UPD ; 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_INITIALIZER_TICK_VIEW} where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + return $" select {top} {DB_NAME_FIELDS} from (select {DB_NAME_FIELDS} ,row_number() over(order by {orderby} {orderbytag}) as num from { DB_NAME_SECURITY_INITIALIZER_TICK_VIEW} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; } public SecurityInitializerTickViewEntity Clone() diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityLockEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityLockEntity.auto.cs index e0a0622..5e93d85 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityLockEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityLockEntity.auto.cs @@ -14,44 +14,45 @@ namespace CloudBuilder.Security.Entity { } - [Column("created_by")] - public string CreatedBy { get; set; } [Column("created_datetime")] public DateTime CreatedDatetime { get; set; } - [Column("entity_name")] - public string EntityName { get; set; } - [Column("locked_by_actor")] - public string LockedByActor { get; set; } - [Column("pkey_id")] - public string PkeyId { 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("updated_by")] + public string UpdatedBy { get; set; } + [Column("entity_name")] + public string EntityName { get; set; } + [Column("pkey_id")] + public string PkeyId { get; set; } + [Column("locked_by_actor")] + public string LockedByActor { get; set; } - public const string CREATED_BY = "CreatedBy"; public const string CREATED_DATETIME = "CreatedDatetime"; - public const string ENTITY_NAME = "EntityName"; - public const string LOCKED_BY_ACTOR = "LockedByActor"; - public const string PKEY_ID = "PkeyId"; - public const string UPDATED_BY = "UpdatedBy"; + public const string CREATED_BY = "CreatedBy"; public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string UPDATED_BY = "UpdatedBy"; + public const string ENTITY_NAME = "EntityName"; + public const string PKEY_ID = "PkeyId"; + public const string LOCKED_BY_ACTOR = "LockedByActor"; public const string DB_NAME_SECURITY_LOCK = "security_lock"; - public const string DB_NAME_FIELDS="created_by,created_datetime,entity_name,locked_by_actor,pkey_id,updated_by,updated_datetime"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,entity_name,pkey_id,locked_by_actor"; - public const string DB_CREATED_BY = "created_by"; public const string DB_CREATED_DATETIME = "created_datetime"; - public const string DB_ENTITY_NAME = "entity_name"; - public const string DB_LOCKED_BY_ACTOR = "locked_by_actor"; - public const string DB_PKEY_ID = "pkey_id"; - 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_UPDATED_BY = "updated_by"; + public const string DB_ENTITY_NAME = "entity_name"; + public const string DB_PKEY_ID = "pkey_id"; + public const string DB_LOCKED_BY_ACTOR = "locked_by_actor"; + public string ProviderName { get; set; } - public static SecurityLockEntity GetInstance() + public static SecurityLockEntity GetInstance(string providerName) { - return new SecurityLockEntity(); + return new SecurityLockEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityLockEntity source) @@ -66,34 +67,89 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; - this.EntityName = source.EntityName; - this.LockedByActor = source.LockedByActor; - this.PkeyId = source.PkeyId; - this.UpdatedBy = source.UpdatedBy; + this.CreatedBy = source.CreatedBy; this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; + this.EntityName = source.EntityName; + this.PkeyId = source.PkeyId; + this.LockedByActor = source.LockedByActor; 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_LOCK} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_LOCK} "; } - + 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_LOCK} 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_LOCK} 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_ENTITY_NAME ; @@ -101,6 +157,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_LOCK} 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_ENTITY_NAME ; + 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_LOCK} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityLockEntity Clone() { SecurityLockEntity result = new SecurityLockEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityLockEntityKey.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityLockEntityKey.auto.cs index 324f3dc..6f8542a 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityLockEntityKey.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityLockEntityKey.auto.cs @@ -6,8 +6,8 @@ namespace CloudBuilder.Security public class SecurityLockEntityKey { public string EntityName { get; set; } - public string LockedByActor { get; set; } public string PkeyId { get; set; } + public string LockedByActor { get; set; } public override bool Equals(object obj) { @@ -17,8 +17,8 @@ namespace CloudBuilder.Security if (pkey == null) return false; if (EntityName != pkey.EntityName) return false; - if (LockedByActor != pkey.LockedByActor) return false; if (PkeyId != pkey.PkeyId) return false; + if (LockedByActor != pkey.LockedByActor) return false; return true; } @@ -27,9 +27,9 @@ namespace CloudBuilder.Security public override string ToString() { string declareSql=""; - declareSql=declareSql+$"declare @__tkey_EntityName_0 varchar(50) select @__tkey_EntityName_0 ='{EntityName}'; " ; declareSql=declareSql+$"declare @__tkey_LockedByActor_1 varchar(50) select @__tkey_LockedByActor_1 ='{LockedByActor}'; " ; declareSql=declareSql+$"declare @__tkey_PkeyId_2 varchar(50) select @__tkey_PkeyId_2 ='{PkeyId}'; " ; + declareSql=declareSql+$"declare @__tkey_EntityName_0 varchar(50) select @__tkey_EntityName_0 ='{EntityName}'; " ; declareSql=declareSql+$"declare @__tkey_PkeyId_1 varchar(50) select @__tkey_PkeyId_1 ='{PkeyId}'; " ; declareSql=declareSql+$"declare @__tkey_LockedByActor_2 varchar(50) select @__tkey_LockedByActor_2 ='{LockedByActor}'; " ; return declareSql; } } } - /* builder.Entity().HasKey(c => new { c.EntityName, c.LockedByActor, c.PkeyId}); */ + /* builder.Entity().HasKey(c => new { c.EntityName, c.PkeyId, c.LockedByActor}); */ diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityMasterEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityMasterEntity.auto.cs index c2e5e70..1217b9b 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityMasterEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityMasterEntity.auto.cs @@ -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(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityMasterEntityKey.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityMasterEntityKey.auto.cs index 4c23beb..02b12b1 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityMasterEntityKey.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityMasterEntityKey.auto.cs @@ -6,8 +6,8 @@ namespace CloudBuilder.Security public class SecurityMasterEntityKey { public string MasterCategory { get; set; } - public string MasterCodeItem { get; set; } public string MasterSubcategory { get; set; } + public string MasterCodeItem { get; set; } public override bool Equals(object obj) { @@ -17,8 +17,8 @@ namespace CloudBuilder.Security if (pkey == null) return false; if (MasterCategory != pkey.MasterCategory) return false; - if (MasterCodeItem != pkey.MasterCodeItem) return false; if (MasterSubcategory != pkey.MasterSubcategory) return false; + if (MasterCodeItem != pkey.MasterCodeItem) return false; return true; } @@ -27,9 +27,9 @@ namespace CloudBuilder.Security public override string ToString() { string declareSql=""; - declareSql=declareSql+$"declare @__tkey_MasterCategory_0 varchar(50) select @__tkey_MasterCategory_0 ='{MasterCategory}'; " ; declareSql=declareSql+$"declare @__tkey_MasterCodeItem_1 varchar(50) select @__tkey_MasterCodeItem_1 ='{MasterCodeItem}'; " ; declareSql=declareSql+$"declare @__tkey_MasterSubcategory_2 varchar(50) select @__tkey_MasterSubcategory_2 ='{MasterSubcategory}'; " ; + declareSql=declareSql+$"declare @__tkey_MasterCategory_0 varchar(50) select @__tkey_MasterCategory_0 ='{MasterCategory}'; " ; declareSql=declareSql+$"declare @__tkey_MasterSubcategory_1 varchar(50) select @__tkey_MasterSubcategory_1 ='{MasterSubcategory}'; " ; declareSql=declareSql+$"declare @__tkey_MasterCodeItem_2 varchar(50) select @__tkey_MasterCodeItem_2 ='{MasterCodeItem}'; " ; return declareSql; } } } - /* builder.Entity().HasKey(c => new { c.MasterCategory, c.MasterCodeItem, c.MasterSubcategory}); */ + /* builder.Entity().HasKey(c => new { c.MasterCategory, c.MasterSubcategory, c.MasterCodeItem}); */ diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionDependentEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionDependentEntity.auto.cs index c39249b..d4b055f 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionDependentEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionDependentEntity.auto.cs @@ -14,48 +14,49 @@ namespace CloudBuilder.Security.Entity { } - [Column("created_by")] - public string CreatedBy { get; set; } [Column("created_datetime")] public DateTime CreatedDatetime { get; set; } - [Column("dependent")] - public string Dependent { get; set; } - [Column("dependent_detail_description")] - public string? DependentDetailDescription { get; set; } - [Column("dependent_detail_name")] - public string DependentDetailName { get; set; } - [Column("permission_name")] - public string PermissionName { 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("updated_by")] + public string UpdatedBy { get; set; } + [Column("permission_name")] + public string PermissionName { get; set; } + [Column("dependent")] + public string Dependent { get; set; } + [Column("dependent_detail_name")] + public string DependentDetailName { get; set; } + [Column("dependent_detail_description")] + public string? DependentDetailDescription { get; set; } - public const string CREATED_BY = "CreatedBy"; public const string CREATED_DATETIME = "CreatedDatetime"; - public const string DEPENDENT = "Dependent"; - public const string DEPENDENT_DETAIL_DESCRIPTION = "DependentDetailDescription"; - public const string DEPENDENT_DETAIL_NAME = "DependentDetailName"; - public const string PERMISSION_NAME = "PermissionName"; - public const string UPDATED_BY = "UpdatedBy"; + public const string CREATED_BY = "CreatedBy"; public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string UPDATED_BY = "UpdatedBy"; + public const string PERMISSION_NAME = "PermissionName"; + public const string DEPENDENT = "Dependent"; + public const string DEPENDENT_DETAIL_NAME = "DependentDetailName"; + public const string DEPENDENT_DETAIL_DESCRIPTION = "DependentDetailDescription"; public const string DB_NAME_SECURITY_PERMISSION_DEPENDENT = "security_permission_dependent"; - public const string DB_NAME_FIELDS="created_by,created_datetime,dependent,dependent_detail_description,dependent_detail_name,permission_name,updated_by,updated_datetime"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,permission_name,dependent,dependent_detail_name,dependent_detail_description"; - public const string DB_CREATED_BY = "created_by"; public const string DB_CREATED_DATETIME = "created_datetime"; - public const string DB_DEPENDENT = "dependent"; - public const string DB_DEPENDENT_DETAIL_DESCRIPTION = "dependent_detail_description"; - public const string DB_DEPENDENT_DETAIL_NAME = "dependent_detail_name"; - public const string DB_PERMISSION_NAME = "permission_name"; - 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_UPDATED_BY = "updated_by"; + public const string DB_PERMISSION_NAME = "permission_name"; + public const string DB_DEPENDENT = "dependent"; + public const string DB_DEPENDENT_DETAIL_NAME = "dependent_detail_name"; + public const string DB_DEPENDENT_DETAIL_DESCRIPTION = "dependent_detail_description"; + public string ProviderName { get; set; } - public static SecurityPermissionDependentEntity GetInstance() + public static SecurityPermissionDependentEntity GetInstance(string providerName) { - return new SecurityPermissionDependentEntity(); + return new SecurityPermissionDependentEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityPermissionDependentEntity source) @@ -70,42 +71,105 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; - this.Dependent = source.Dependent; - this.DependentDetailDescription = source.DependentDetailDescription; - this.DependentDetailName = source.DependentDetailName; - this.PermissionName = source.PermissionName; - this.UpdatedBy = source.UpdatedBy; + this.CreatedBy = source.CreatedBy; this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; + this.PermissionName = source.PermissionName; + this.Dependent = source.Dependent; + this.DependentDetailName = source.DependentDetailName; + this.DependentDetailDescription = source.DependentDetailDescription; 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_PERMISSION_DEPENDENT} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_PERMISSION_DEPENDENT} "; } - + 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_PERMISSION_DEPENDENT} 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_PERMISSION_DEPENDENT} 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_DEPENDENT_DETAIL_NAME ; + if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_PERMISSION_NAME ; 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_PERMISSION_DEPENDENT} 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_PERMISSION_NAME ; + 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_PERMISSION_DEPENDENT} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityPermissionDependentEntity Clone() { SecurityPermissionDependentEntity result = new SecurityPermissionDependentEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionDependentEntityKey.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionDependentEntityKey.auto.cs index 20260b0..e39ca79 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionDependentEntityKey.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionDependentEntityKey.auto.cs @@ -5,8 +5,8 @@ namespace CloudBuilder.Security [TypeScript] public class SecurityPermissionDependentEntityKey { - public string DependentDetailName { get; set; } public string PermissionName { get; set; } + public string DependentDetailName { get; set; } public override bool Equals(object obj) { @@ -15,8 +15,8 @@ namespace CloudBuilder.Security SecurityPermissionDependentEntityKey pkey = obj as SecurityPermissionDependentEntityKey; if (pkey == null) return false; - if (DependentDetailName != pkey.DependentDetailName) return false; if (PermissionName != pkey.PermissionName) return false; + if (DependentDetailName != pkey.DependentDetailName) return false; return true; } @@ -25,9 +25,9 @@ namespace CloudBuilder.Security public override string ToString() { string declareSql=""; - declareSql=declareSql+$"declare @__tkey_DependentDetailName_0 varchar(50) select @__tkey_DependentDetailName_0 ='{DependentDetailName}'; " ; declareSql=declareSql+$"declare @__tkey_PermissionName_1 varchar(50) select @__tkey_PermissionName_1 ='{PermissionName}'; " ; + declareSql=declareSql+$"declare @__tkey_PermissionName_0 varchar(50) select @__tkey_PermissionName_0 ='{PermissionName}'; " ; declareSql=declareSql+$"declare @__tkey_DependentDetailName_1 varchar(50) select @__tkey_DependentDetailName_1 ='{DependentDetailName}'; " ; return declareSql; } } } - /* builder.Entity().HasKey(c => new { c.DependentDetailName, c.PermissionName}); */ + /* builder.Entity().HasKey(c => new { c.PermissionName, c.DependentDetailName}); */ diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionEntity.auto.cs index 6cdb7b6..6429166 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionEntity.auto.cs @@ -14,49 +14,50 @@ namespace CloudBuilder.Security.Entity { } - [Column("created_by")] - public string CreatedBy { get; set; } [Column("created_datetime")] public DateTime CreatedDatetime { get; set; } - [Column("delegate_indc")] - public string DelegateIndc { 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("permission_name")] + public string PermissionName { get; set; } [Column("dependent")] public string? Dependent { get; set; } [Column("description")] public string? Description { get; set; } - [Key] - [Column("permission_name")] - public string PermissionName { get; set; } - [Column("updated_by")] - public string UpdatedBy { get; set; } - [Column("updated_datetime")] - public DateTime UpdatedDatetime { get; set; } + [Column("delegate_indc")] + public string DelegateIndc { get; set; } - public const string CREATED_BY = "CreatedBy"; public const string CREATED_DATETIME = "CreatedDatetime"; - public const string DELEGATE_INDC = "DelegateIndc"; + public const string CREATED_BY = "CreatedBy"; + public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string UPDATED_BY = "UpdatedBy"; + public const string PERMISSION_NAME = "PermissionName"; public const string DEPENDENT = "Dependent"; public const string DESCRIPTION = "Description"; - public const string PERMISSION_NAME = "PermissionName"; - public const string UPDATED_BY = "UpdatedBy"; - public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string DELEGATE_INDC = "DelegateIndc"; public const string DB_NAME_SECURITY_PERMISSION = "security_permission"; - public const string DB_NAME_FIELDS="created_by,created_datetime,delegate_indc,dependent,description,permission_name,updated_by,updated_datetime"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,permission_name,dependent,description,delegate_indc"; - public const string DB_CREATED_BY = "created_by"; public const string DB_CREATED_DATETIME = "created_datetime"; - public const string DB_DELEGATE_INDC = "delegate_indc"; + 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_PERMISSION_NAME = "permission_name"; public const string DB_DEPENDENT = "dependent"; public const string DB_DESCRIPTION = "description"; - public const string DB_PERMISSION_NAME = "permission_name"; - public const string DB_UPDATED_BY = "updated_by"; - public const string DB_UPDATED_DATETIME = "updated_datetime"; + public const string DB_DELEGATE_INDC = "delegate_indc"; + public string ProviderName { get; set; } - public static SecurityPermissionEntity GetInstance() + public static SecurityPermissionEntity GetInstance(string providerName) { - return new SecurityPermissionEntity(); + return new SecurityPermissionEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityPermissionEntity source) @@ -71,35 +72,90 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; - this.DelegateIndc = source.DelegateIndc; + this.CreatedBy = source.CreatedBy; + this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; + this.PermissionName = source.PermissionName; this.Dependent = source.Dependent; this.Description = source.Description; - this.PermissionName = source.PermissionName; - this.UpdatedBy = source.UpdatedBy; - this.UpdatedDatetime = source.UpdatedDatetime; + this.DelegateIndc = source.DelegateIndc; 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_PERMISSION} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_PERMISSION} "; } - + 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_PERMISSION} 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_PERMISSION} 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_PERMISSION_NAME ; @@ -107,6 +163,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_PERMISSION} 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_PERMISSION_NAME ; + 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_PERMISSION} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityPermissionEntity Clone() { SecurityPermissionEntity result = new SecurityPermissionEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionFunctionMapEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionFunctionMapEntity.auto.cs index 6e17207..101eecb 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionFunctionMapEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionFunctionMapEntity.auto.cs @@ -14,40 +14,41 @@ namespace CloudBuilder.Security.Entity { } - [Column("created_by")] - public string CreatedBy { get; set; } [Column("created_datetime")] public DateTime CreatedDatetime { get; set; } - [Column("function_name")] - public string FunctionName { get; set; } - [Column("permission_name")] - public string PermissionName { 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("updated_by")] + public string UpdatedBy { get; set; } + [Column("permission_name")] + public string PermissionName { get; set; } + [Column("function_name")] + public string FunctionName { get; set; } - public const string CREATED_BY = "CreatedBy"; public const string CREATED_DATETIME = "CreatedDatetime"; - public const string FUNCTION_NAME = "FunctionName"; - public const string PERMISSION_NAME = "PermissionName"; - public const string UPDATED_BY = "UpdatedBy"; + public const string CREATED_BY = "CreatedBy"; public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string UPDATED_BY = "UpdatedBy"; + public const string PERMISSION_NAME = "PermissionName"; + public const string FUNCTION_NAME = "FunctionName"; public const string DB_NAME_SECURITY_PERMISSION_FUNCTION_MAP = "security_permission_function_map"; - public const string DB_NAME_FIELDS="created_by,created_datetime,function_name,permission_name,updated_by,updated_datetime"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,permission_name,function_name"; - public const string DB_CREATED_BY = "created_by"; public const string DB_CREATED_DATETIME = "created_datetime"; - public const string DB_FUNCTION_NAME = "function_name"; - public const string DB_PERMISSION_NAME = "permission_name"; - 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_UPDATED_BY = "updated_by"; + public const string DB_PERMISSION_NAME = "permission_name"; + public const string DB_FUNCTION_NAME = "function_name"; + public string ProviderName { get; set; } - public static SecurityPermissionFunctionMapEntity GetInstance() + public static SecurityPermissionFunctionMapEntity GetInstance(string providerName) { - return new SecurityPermissionFunctionMapEntity(); + return new SecurityPermissionFunctionMapEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityPermissionFunctionMapEntity source) @@ -62,40 +63,103 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; - this.FunctionName = source.FunctionName; - this.PermissionName = source.PermissionName; - this.UpdatedBy = source.UpdatedBy; + this.CreatedBy = source.CreatedBy; this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; + this.PermissionName = source.PermissionName; + this.FunctionName = source.FunctionName; 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_PERMISSION_FUNCTION_MAP} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_PERMISSION_FUNCTION_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_SECURITY_PERMISSION_FUNCTION_MAP} 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_PERMISSION_FUNCTION_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_FUNCTION_NAME ; + if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_PERMISSION_NAME ; 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_PERMISSION_FUNCTION_MAP} 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_PERMISSION_NAME ; + 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_PERMISSION_FUNCTION_MAP} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityPermissionFunctionMapEntity Clone() { SecurityPermissionFunctionMapEntity result = new SecurityPermissionFunctionMapEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionFunctionMapEntityKey.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionFunctionMapEntityKey.auto.cs index 23b3e86..36d62bb 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionFunctionMapEntityKey.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionFunctionMapEntityKey.auto.cs @@ -5,8 +5,8 @@ namespace CloudBuilder.Security [TypeScript] public class SecurityPermissionFunctionMapEntityKey { - public string FunctionName { get; set; } public string PermissionName { get; set; } + public string FunctionName { get; set; } public override bool Equals(object obj) { @@ -15,8 +15,8 @@ namespace CloudBuilder.Security SecurityPermissionFunctionMapEntityKey pkey = obj as SecurityPermissionFunctionMapEntityKey; if (pkey == null) return false; - if (FunctionName != pkey.FunctionName) return false; if (PermissionName != pkey.PermissionName) return false; + if (FunctionName != pkey.FunctionName) return false; return true; } @@ -25,9 +25,9 @@ namespace CloudBuilder.Security public override string ToString() { string declareSql=""; - declareSql=declareSql+$"declare @__tkey_FunctionName_0 varchar(50) select @__tkey_FunctionName_0 ='{FunctionName}'; " ; declareSql=declareSql+$"declare @__tkey_PermissionName_1 varchar(50) select @__tkey_PermissionName_1 ='{PermissionName}'; " ; + declareSql=declareSql+$"declare @__tkey_PermissionName_0 varchar(50) select @__tkey_PermissionName_0 ='{PermissionName}'; " ; declareSql=declareSql+$"declare @__tkey_FunctionName_1 varchar(50) select @__tkey_FunctionName_1 ='{FunctionName}'; " ; return declareSql; } } } - /* builder.Entity().HasKey(c => new { c.FunctionName, c.PermissionName}); */ + /* builder.Entity().HasKey(c => new { c.PermissionName, c.FunctionName}); */ diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionFunctionMapViewEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionFunctionMapViewEntity.auto.cs index 94d6475..5c8b56c 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionFunctionMapViewEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionFunctionMapViewEntity.auto.cs @@ -14,28 +14,29 @@ namespace CloudBuilder.Security.Entity { } + [Column("permission_name")] + public string PermissionName { get; set; } [Column("function_name")] public string FunctionName { get; set; } [Column("page_name")] public string? PageName { get; set; } - [Column("permission_name")] - public string PermissionName { get; set; } + public const string PERMISSION_NAME = "PermissionName"; public const string FUNCTION_NAME = "FunctionName"; public const string PAGE_NAME = "PageName"; - public const string PERMISSION_NAME = "PermissionName"; public const string DB_NAME_SECURITY_PERMISSION_FUNCTION_MAP_VIEW = "security_permission_function_map_view"; - public const string DB_NAME_FIELDS="function_name,page_name,permission_name"; + public const string DB_NAME_FIELDS="permission_name,function_name,page_name"; + public const string DB_PERMISSION_NAME = "permission_name"; public const string DB_FUNCTION_NAME = "function_name"; public const string DB_PAGE_NAME = "page_name"; - public const string DB_PERMISSION_NAME = "permission_name"; + public string ProviderName { get; set; } - public static SecurityPermissionFunctionMapViewEntity GetInstance() + public static SecurityPermissionFunctionMapViewEntity GetInstance(string providerName) { - return new SecurityPermissionFunctionMapViewEntity(); + return new SecurityPermissionFunctionMapViewEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityPermissionFunctionMapViewEntity source) @@ -50,9 +51,9 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } + this.PermissionName = source.PermissionName; this.FunctionName = source.FunctionName; this.PageName = source.PageName; - this.PermissionName = source.PermissionName; if (includeSystemFields) { @@ -60,23 +61,86 @@ namespace CloudBuilder.Security.Entity } 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_PERMISSION_FUNCTION_MAP_VIEW} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_PERMISSION_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_PERMISSION_FUNCTION_MAP_VIEW} 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_PERMISSION_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_FUNCTION_NAME ; int offset = limit * (start - 1); + if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_PERMISSION_NAME ; 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_PERMISSION_FUNCTION_MAP_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_PERMISSION_NAME ; 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_PERMISSION_FUNCTION_MAP_VIEW} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityPermissionFunctionMapViewEntity Clone() { SecurityPermissionFunctionMapViewEntity result = new SecurityPermissionFunctionMapViewEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionViewEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionViewEntity.auto.cs index 0d5f057..75f477b 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionViewEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityPermissionViewEntity.auto.cs @@ -14,36 +14,37 @@ namespace CloudBuilder.Security.Entity { } + [Column("permission_name")] + public string PermissionName { get; set; } + [Column("function_name")] + public string? FunctionName { get; set; } + [Column("description")] + public string? Description { get; set; } [Column("created_datetime")] public DateTime CreatedDatetime { get; set; } [Column("dependent")] public string? Dependent { get; set; } - [Column("description")] - public string? Description { get; set; } - [Column("function_name")] - public string? FunctionName { get; set; } - [Column("permission_name")] - public string PermissionName { get; set; } + public const string PERMISSION_NAME = "PermissionName"; + public const string FUNCTION_NAME = "FunctionName"; + public const string DESCRIPTION = "Description"; public const string CREATED_DATETIME = "CreatedDatetime"; public const string DEPENDENT = "Dependent"; - public const string DESCRIPTION = "Description"; - public const string FUNCTION_NAME = "FunctionName"; - public const string PERMISSION_NAME = "PermissionName"; public const string DB_NAME_SECURITY_PERMISSION_VIEW = "security_permission_view"; - public const string DB_NAME_FIELDS="created_datetime,dependent,description,function_name,permission_name"; + public const string DB_NAME_FIELDS="permission_name,function_name,description,created_datetime,dependent"; + public const string DB_PERMISSION_NAME = "permission_name"; + public const string DB_FUNCTION_NAME = "function_name"; + public const string DB_DESCRIPTION = "description"; public const string DB_CREATED_DATETIME = "created_datetime"; public const string DB_DEPENDENT = "dependent"; - public const string DB_DESCRIPTION = "description"; - public const string DB_FUNCTION_NAME = "function_name"; - public const string DB_PERMISSION_NAME = "permission_name"; + public string ProviderName { get; set; } - public static SecurityPermissionViewEntity GetInstance() + public static SecurityPermissionViewEntity GetInstance(string providerName) { - return new SecurityPermissionViewEntity(); + return new SecurityPermissionViewEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityPermissionViewEntity source) @@ -58,11 +59,11 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } + this.PermissionName = source.PermissionName; + this.FunctionName = source.FunctionName; + this.Description = source.Description; this.CreatedDatetime = source.CreatedDatetime; this.Dependent = source.Dependent; - this.Description = source.Description; - this.FunctionName = source.FunctionName; - this.PermissionName = source.PermissionName; if (includeSystemFields) { @@ -71,23 +72,86 @@ namespace CloudBuilder.Security.Entity } 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_PERMISSION_VIEW} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_PERMISSION_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_PERMISSION_VIEW} 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_PERMISSION_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_CREATED_DATETIME ; int offset = limit * (start - 1); + if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_PERMISSION_NAME ; 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_PERMISSION_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_PERMISSION_NAME ; 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_PERMISSION_VIEW} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityPermissionViewEntity Clone() { SecurityPermissionViewEntity result = new SecurityPermissionViewEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityTableDescriptionEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityTableDescriptionEntity.auto.cs index e2585bd..c8db701 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityTableDescriptionEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityTableDescriptionEntity.auto.cs @@ -14,50 +14,51 @@ namespace CloudBuilder.Security.Entity { } - [Column("created_by")] - public string CreatedBy { get; set; } [Column("created_datetime")] public DateTime CreatedDatetime { get; set; } - [Column("description")] - public string? Description { 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("description_id")] public int DescriptionId { get; set; } - [Column("field_name")] - public string FieldName { get; set; } [Column("table_name")] public string TableName { get; set; } - [Column("updated_by")] - public string UpdatedBy { get; set; } - [Column("updated_datetime")] - public DateTime UpdatedDatetime { get; set; } + [Column("field_name")] + public string FieldName { get; set; } + [Column("description")] + public string? Description { get; set; } - public const string CREATED_BY = "CreatedBy"; public const string CREATED_DATETIME = "CreatedDatetime"; - public const string DESCRIPTION = "Description"; - public const string DESCRIPTION_ID = "DescriptionId"; - public const string FIELD_NAME = "FieldName"; - public const string TABLE_NAME = "TableName"; - public const string UPDATED_BY = "UpdatedBy"; + public const string CREATED_BY = "CreatedBy"; public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string UPDATED_BY = "UpdatedBy"; + public const string DESCRIPTION_ID = "DescriptionId"; + public const string TABLE_NAME = "TableName"; + public const string FIELD_NAME = "FieldName"; + public const string DESCRIPTION = "Description"; public const string DB_NAME_SECURITY_TABLE_DESCRIPTION = "security_table_description"; - public const string DB_NAME_FIELDS="created_by,created_datetime,description,description_id,field_name,table_name,updated_by,updated_datetime"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,description_id,table_name,field_name,description"; - public const string DB_CREATED_BY = "created_by"; public const string DB_CREATED_DATETIME = "created_datetime"; - public const string DB_DESCRIPTION = "description"; - public const string DB_DESCRIPTION_ID = "description_id"; - public const string DB_FIELD_NAME = "field_name"; - public const string DB_TABLE_NAME = "table_name"; - 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_UPDATED_BY = "updated_by"; + public const string DB_DESCRIPTION_ID = "description_id"; + public const string DB_TABLE_NAME = "table_name"; + public const string DB_FIELD_NAME = "field_name"; + public const string DB_DESCRIPTION = "description"; + public string ProviderName { get; set; } - public static SecurityTableDescriptionEntity GetInstance() + public static SecurityTableDescriptionEntity GetInstance(string providerName) { - return new SecurityTableDescriptionEntity(); + return new SecurityTableDescriptionEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityTableDescriptionEntity source) @@ -72,35 +73,90 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; - this.Description = source.Description; - this.DescriptionId = source.DescriptionId; - this.FieldName = source.FieldName; - this.TableName = source.TableName; - this.UpdatedBy = source.UpdatedBy; + this.CreatedBy = source.CreatedBy; this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; + this.DescriptionId = source.DescriptionId; + this.TableName = source.TableName; + this.FieldName = source.FieldName; + this.Description = source.Description; 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_TABLE_DESCRIPTION} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_TABLE_DESCRIPTION} "; } - + 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_TABLE_DESCRIPTION} 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_TABLE_DESCRIPTION} 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_DESCRIPTION_ID ; @@ -108,6 +164,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_TABLE_DESCRIPTION} 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_DESCRIPTION_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_SECURITY_TABLE_DESCRIPTION} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityTableDescriptionEntity Clone() { SecurityTableDescriptionEntity result = new SecurityTableDescriptionEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserActorEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserActorEntity.auto.cs index e30a7a6..3905afb 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserActorEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserActorEntity.auto.cs @@ -14,40 +14,41 @@ namespace CloudBuilder.Security.Entity { } - [Column("actor_name")] - public string ActorName { get; set; } - [Column("created_by")] - public string CreatedBy { get; set; } [Column("created_datetime")] public DateTime CreatedDatetime { 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("updated_by")] + public string UpdatedBy { get; set; } [Column("user_name")] public string UserName { get; set; } + [Column("actor_name")] + public string ActorName { get; set; } - public const string ACTOR_NAME = "ActorName"; - public const string CREATED_BY = "CreatedBy"; public const string CREATED_DATETIME = "CreatedDatetime"; - public const string UPDATED_BY = "UpdatedBy"; + public const string CREATED_BY = "CreatedBy"; public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string UPDATED_BY = "UpdatedBy"; public const string USER_NAME = "UserName"; + public const string ACTOR_NAME = "ActorName"; public const string DB_NAME_SECURITY_USER_ACTOR = "security_user_actor"; - public const string DB_NAME_FIELDS="actor_name,created_by,created_datetime,updated_by,updated_datetime,user_name"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,user_name,actor_name"; - public const string DB_ACTOR_NAME = "actor_name"; - public const string DB_CREATED_BY = "created_by"; public const string DB_CREATED_DATETIME = "created_datetime"; - 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_UPDATED_BY = "updated_by"; public const string DB_USER_NAME = "user_name"; + public const string DB_ACTOR_NAME = "actor_name"; + public string ProviderName { get; set; } - public static SecurityUserActorEntity GetInstance() + public static SecurityUserActorEntity GetInstance(string providerName) { - return new SecurityUserActorEntity(); + return new SecurityUserActorEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityUserActorEntity source) @@ -62,40 +63,103 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.ActorName = source.ActorName; - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; - this.UpdatedBy = source.UpdatedBy; + this.CreatedBy = source.CreatedBy; this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; this.UserName = source.UserName; + this.ActorName = source.ActorName; 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_USER_ACTOR} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_USER_ACTOR} "; } - + 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_USER_ACTOR} 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_USER_ACTOR} 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_ACTOR_NAME ; + if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_USER_NAME ; 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_USER_ACTOR} 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_USER_NAME ; + 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_USER_ACTOR} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityUserActorEntity Clone() { SecurityUserActorEntity result = new SecurityUserActorEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserActorEntityKey.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserActorEntityKey.auto.cs index d9152cc..0a0c404 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserActorEntityKey.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserActorEntityKey.auto.cs @@ -5,8 +5,8 @@ namespace CloudBuilder.Security [TypeScript] public class SecurityUserActorEntityKey { - public string ActorName { get; set; } public string UserName { get; set; } + public string ActorName { get; set; } public override bool Equals(object obj) { @@ -15,8 +15,8 @@ namespace CloudBuilder.Security SecurityUserActorEntityKey pkey = obj as SecurityUserActorEntityKey; if (pkey == null) return false; - if (ActorName != pkey.ActorName) return false; if (UserName != pkey.UserName) return false; + if (ActorName != pkey.ActorName) return false; return true; } @@ -25,9 +25,9 @@ namespace CloudBuilder.Security public override string ToString() { string declareSql=""; - declareSql=declareSql+$"declare @__tkey_ActorName_0 varchar(50) select @__tkey_ActorName_0 ='{ActorName}'; " ; declareSql=declareSql+$"declare @__tkey_UserName_1 varchar(50) select @__tkey_UserName_1 ='{UserName}'; " ; + declareSql=declareSql+$"declare @__tkey_UserName_0 varchar(50) select @__tkey_UserName_0 ='{UserName}'; " ; declareSql=declareSql+$"declare @__tkey_ActorName_1 varchar(50) select @__tkey_ActorName_1 ='{ActorName}'; " ; return declareSql; } } } - /* builder.Entity().HasKey(c => new { c.ActorName, c.UserName}); */ + /* builder.Entity().HasKey(c => new { c.UserName, c.ActorName}); */ diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserActorViewEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserActorViewEntity.auto.cs index 1d76497..704540b 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserActorViewEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserActorViewEntity.auto.cs @@ -14,36 +14,37 @@ namespace CloudBuilder.Security.Entity { } - [Column("actor_local_name")] - public string? ActorLocalName { get; set; } - [Column("actor_name")] - public string ActorName { get; set; } + [Column("user_name")] + public string UserName { get; set; } [Column("user_local_name")] public string UserLocalName { get; set; } [Column("user_mobile")] public string? UserMobile { get; set; } - [Column("user_name")] - public string UserName { get; set; } + [Column("actor_name")] + public string ActorName { get; set; } + [Column("actor_local_name")] + public string? ActorLocalName { get; set; } - public const string ACTOR_LOCAL_NAME = "ActorLocalName"; - public const string ACTOR_NAME = "ActorName"; + public const string USER_NAME = "UserName"; public const string USER_LOCAL_NAME = "UserLocalName"; public const string USER_MOBILE = "UserMobile"; - public const string USER_NAME = "UserName"; + public const string ACTOR_NAME = "ActorName"; + public const string ACTOR_LOCAL_NAME = "ActorLocalName"; public const string DB_NAME_SECURITY_USER_ACTOR_VIEW = "security_user_actor_view"; - public const string DB_NAME_FIELDS="actor_local_name,actor_name,user_local_name,user_mobile,user_name"; + public const string DB_NAME_FIELDS="user_name,user_local_name,user_mobile,actor_name,actor_local_name"; - public const string DB_ACTOR_LOCAL_NAME = "actor_local_name"; - public const string DB_ACTOR_NAME = "actor_name"; + public const string DB_USER_NAME = "user_name"; public const string DB_USER_LOCAL_NAME = "user_local_name"; public const string DB_USER_MOBILE = "user_mobile"; - public const string DB_USER_NAME = "user_name"; + public const string DB_ACTOR_NAME = "actor_name"; + public const string DB_ACTOR_LOCAL_NAME = "actor_local_name"; + public string ProviderName { get; set; } - public static SecurityUserActorViewEntity GetInstance() + public static SecurityUserActorViewEntity GetInstance(string providerName) { - return new SecurityUserActorViewEntity(); + return new SecurityUserActorViewEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityUserActorViewEntity source) @@ -58,11 +59,11 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.ActorLocalName = source.ActorLocalName; - this.ActorName = source.ActorName; + this.UserName = source.UserName; this.UserLocalName = source.UserLocalName; this.UserMobile = source.UserMobile; - this.UserName = source.UserName; + this.ActorName = source.ActorName; + this.ActorLocalName = source.ActorLocalName; if (includeSystemFields) { @@ -70,23 +71,86 @@ namespace CloudBuilder.Security.Entity } 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_USER_ACTOR_VIEW} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_USER_ACTOR_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_USER_ACTOR_VIEW} 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_USER_ACTOR_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_ACTOR_LOCAL_NAME ; int offset = limit * (start - 1); + if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_USER_NAME ; 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_USER_ACTOR_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_USER_NAME ; 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_USER_ACTOR_VIEW} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityUserActorViewEntity Clone() { SecurityUserActorViewEntity result = new SecurityUserActorViewEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserDelegatedPermissionEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserDelegatedPermissionEntity.auto.cs index ee1f0fb..d3379bf 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserDelegatedPermissionEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserDelegatedPermissionEntity.auto.cs @@ -14,52 +14,53 @@ namespace CloudBuilder.Security.Entity { } - [Column("created_by")] - public string CreatedBy { get; set; } [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("user_name")] + public string UserName { get; set; } [Column("delegated_by_user")] public string DelegatedByUser { get; set; } - [Column("end_datetime")] - public DateTime EndDatetime { get; set; } [Column("permission_name")] public string PermissionName { get; set; } [Column("start_datetime")] public DateTime StartDatetime { get; set; } - [Column("updated_by")] - public string UpdatedBy { get; set; } - [Column("updated_datetime")] - public DateTime UpdatedDatetime { get; set; } - [Column("user_name")] - public string UserName { get; set; } + [Column("end_datetime")] + public DateTime EndDatetime { get; set; } - public const string CREATED_BY = "CreatedBy"; 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 USER_NAME = "UserName"; public const string DELEGATED_BY_USER = "DelegatedByUser"; - public const string END_DATETIME = "EndDatetime"; public const string PERMISSION_NAME = "PermissionName"; public const string START_DATETIME = "StartDatetime"; - public const string UPDATED_BY = "UpdatedBy"; - public const string UPDATED_DATETIME = "UpdatedDatetime"; - public const string USER_NAME = "UserName"; + public const string END_DATETIME = "EndDatetime"; public const string DB_NAME_SECURITY_USER_DELEGATED_PERMISSION = "security_user_delegated_permission"; - public const string DB_NAME_FIELDS="created_by,created_datetime,delegated_by_user,end_datetime,permission_name,start_datetime,updated_by,updated_datetime,user_name"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,user_name,delegated_by_user,permission_name,start_datetime,end_datetime"; - public const string DB_CREATED_BY = "created_by"; 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_USER_NAME = "user_name"; public const string DB_DELEGATED_BY_USER = "delegated_by_user"; - public const string DB_END_DATETIME = "end_datetime"; public const string DB_PERMISSION_NAME = "permission_name"; public const string DB_START_DATETIME = "start_datetime"; - public const string DB_UPDATED_BY = "updated_by"; - public const string DB_UPDATED_DATETIME = "updated_datetime"; - public const string DB_USER_NAME = "user_name"; + public const string DB_END_DATETIME = "end_datetime"; + public string ProviderName { get; set; } - public static SecurityUserDelegatedPermissionEntity GetInstance() + public static SecurityUserDelegatedPermissionEntity GetInstance(string providerName) { - return new SecurityUserDelegatedPermissionEntity(); + return new SecurityUserDelegatedPermissionEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityUserDelegatedPermissionEntity source) @@ -74,43 +75,106 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; + this.CreatedBy = source.CreatedBy; + this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; + this.UserName = source.UserName; this.DelegatedByUser = source.DelegatedByUser; - this.EndDatetime = source.EndDatetime; this.PermissionName = source.PermissionName; this.StartDatetime = source.StartDatetime; - this.UpdatedBy = source.UpdatedBy; - this.UpdatedDatetime = source.UpdatedDatetime; - this.UserName = source.UserName; + this.EndDatetime = source.EndDatetime; 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_USER_DELEGATED_PERMISSION} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_USER_DELEGATED_PERMISSION} "; } - + 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_USER_DELEGATED_PERMISSION} 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_USER_DELEGATED_PERMISSION} 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_DELEGATED_BY_USER ; + if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_USER_NAME ; 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_USER_DELEGATED_PERMISSION} 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_USER_NAME ; + 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_USER_DELEGATED_PERMISSION} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityUserDelegatedPermissionEntity Clone() { SecurityUserDelegatedPermissionEntity result = new SecurityUserDelegatedPermissionEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserDelegatedPermissionEntityKey.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserDelegatedPermissionEntityKey.auto.cs index ad3d6e5..19180ff 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserDelegatedPermissionEntityKey.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserDelegatedPermissionEntityKey.auto.cs @@ -5,9 +5,9 @@ namespace CloudBuilder.Security [TypeScript] public class SecurityUserDelegatedPermissionEntityKey { + public string UserName { get; set; } public string DelegatedByUser { get; set; } public string PermissionName { get; set; } - public string UserName { get; set; } public override bool Equals(object obj) { @@ -16,9 +16,9 @@ namespace CloudBuilder.Security SecurityUserDelegatedPermissionEntityKey pkey = obj as SecurityUserDelegatedPermissionEntityKey; if (pkey == null) return false; + if (UserName != pkey.UserName) return false; if (DelegatedByUser != pkey.DelegatedByUser) return false; if (PermissionName != pkey.PermissionName) return false; - if (UserName != pkey.UserName) return false; return true; } @@ -27,9 +27,9 @@ namespace CloudBuilder.Security public override string ToString() { string declareSql=""; - declareSql=declareSql+$"declare @__tkey_DelegatedByUser_0 varchar(50) select @__tkey_DelegatedByUser_0 ='{DelegatedByUser}'; " ; declareSql=declareSql+$"declare @__tkey_PermissionName_1 varchar(50) select @__tkey_PermissionName_1 ='{PermissionName}'; " ; declareSql=declareSql+$"declare @__tkey_UserName_2 varchar(50) select @__tkey_UserName_2 ='{UserName}'; " ; + declareSql=declareSql+$"declare @__tkey_UserName_0 varchar(50) select @__tkey_UserName_0 ='{UserName}'; " ; declareSql=declareSql+$"declare @__tkey_DelegatedByUser_1 varchar(50) select @__tkey_DelegatedByUser_1 ='{DelegatedByUser}'; " ; declareSql=declareSql+$"declare @__tkey_PermissionName_2 varchar(50) select @__tkey_PermissionName_2 ='{PermissionName}'; " ; return declareSql; } } } - /* builder.Entity().HasKey(c => new { c.DelegatedByUser, c.PermissionName, c.UserName}); */ + /* builder.Entity().HasKey(c => new { c.UserName, c.DelegatedByUser, c.PermissionName}); */ diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserEntity.auto.cs index 2bcd98c..26c80b7 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserEntity.auto.cs @@ -14,169 +14,170 @@ namespace CloudBuilder.Security.Entity { } + [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("user_name")] + public string UserName { get; set; } + [Column("user_local_name")] + public string UserLocalName { get; set; } + [Column("user_eng_name")] + public string? UserEngName { get; set; } + [Column("company_name")] + public string? CompanyName { get; set; } + [Column("industry")] + public string? Industry { get; set; } + [Column("user_password")] + public string? UserPassword { get; set; } + [Column("user_mobile")] + public string? UserMobile { get; set; } + [Column("user_address")] + public string? UserAddress { get; set; } + [Column("postcode")] + public string? Postcode { get; set; } + [Column("community")] + public int Community { get; set; } + [Column("user_grade")] + public int UserGrade { get; set; } + [Column("user_type")] + public string? UserType { get; set; } + [Column("user_wechat_account")] + public string? UserWechatAccount { get; set; } + [Column("user_alipay_account")] + public string? UserAlipayAccount { get; set; } + [Column("user_alipay_account_img_path")] + public string? UserAlipayAccountImgPath { get; set; } + [Column("user_wechat_account_img_path")] + public string? UserWechatAccountImgPath { get; set; } + [Column("user_icon_img_path")] + public string? UserIconImgPath { get; set; } + [Column("user_accounts_expire_datetime")] + public Nullable UserAccountsExpireDatetime { get; set; } + [Column("user_is_valid_indc")] + public string? UserIsValidIndc { get; set; } + [Column("is_forece_change_password_indc")] + public string? IsForeceChangePasswordIndc { get; set; } + [Column("is_accounts_locked_indc")] + public string? IsAccountsLockedIndc { get; set; } [Column("accounts_locked_datetime")] public Nullable AccountsLockedDatetime { get; set; } - [Column("biometric_counter")] - public int BiometricCounter { get; set; } + [Column("user_remark")] + public string? UserRemark { get; set; } + [Column("welcome_page")] + public string? WelcomePage { get; set; } + [Column("user_type_end_datetime")] + public Nullable UserTypeEndDatetime { get; set; } + [Column("room_name")] + public string? RoomName { get; set; } + [Column("last_login_datetime")] + public Nullable LastLoginDatetime { get; set; } + [Column("error_login_count")] + public int ErrorLoginCount { get; set; } [Column("biometric_credential_id")] public string? BiometricCredentialId { get; set; } + [Column("biometric_public_key")] + public string? BiometricPublicKey { get; set; } + [Column("biometric_counter")] + public int BiometricCounter { get; set; } [Column("biometric_device_name")] public string? BiometricDeviceName { get; set; } [Column("biometric_enrolled_at")] public Nullable BiometricEnrolledAt { get; set; } [Column("biometric_last_used_at")] public Nullable BiometricLastUsedAt { get; set; } - [Column("biometric_public_key")] - public string? BiometricPublicKey { get; set; } - [Column("community")] - public int Community { get; set; } - [Column("company_name")] - public string? CompanyName { get; set; } - [Column("created_by")] - public string CreatedBy { get; set; } - [Column("created_datetime")] - public DateTime CreatedDatetime { get; set; } - [Column("error_login_count")] - public int ErrorLoginCount { get; set; } - [Column("industry")] - public string? Industry { get; set; } - [Column("is_accounts_locked_indc")] - public string? IsAccountsLockedIndc { get; set; } - [Column("is_forece_change_password_indc")] - public string? IsForeceChangePasswordIndc { get; set; } - [Column("last_login_datetime")] - public Nullable LastLoginDatetime { get; set; } - [Column("postcode")] - public string? Postcode { get; set; } - [Column("room_name")] - public string? RoomName { get; set; } - [Column("updated_by")] - public string UpdatedBy { get; set; } - [Column("updated_datetime")] - public DateTime UpdatedDatetime { get; set; } - [Column("user_accounts_expire_datetime")] - public Nullable UserAccountsExpireDatetime { get; set; } - [Column("user_address")] - public string? UserAddress { get; set; } - [Column("user_alipay_account")] - public string? UserAlipayAccount { get; set; } - [Column("user_alipay_account_img_path")] - public string? UserAlipayAccountImgPath { get; set; } - [Column("user_eng_name")] - public string? UserEngName { get; set; } - [Column("user_grade")] - public int UserGrade { get; set; } - [Column("user_icon_img_path")] - public string? UserIconImgPath { get; set; } - [Column("user_is_valid_indc")] - public string? UserIsValidIndc { get; set; } - [Column("user_local_name")] - public string UserLocalName { get; set; } - [Column("user_mobile")] - public string? UserMobile { get; set; } - [Key] - [Column("user_name")] - public string UserName { get; set; } - [Column("user_password")] - public string? UserPassword { get; set; } - [Column("user_remark")] - public string? UserRemark { get; set; } - [Column("user_type")] - public string? UserType { get; set; } - [Column("user_type_end_datetime")] - public Nullable UserTypeEndDatetime { get; set; } - [Column("user_wechat_account")] - public string? UserWechatAccount { get; set; } - [Column("user_wechat_account_img_path")] - public string? UserWechatAccountImgPath { get; set; } - [Column("welcome_page")] - public string? WelcomePage { 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 USER_NAME = "UserName"; + public const string USER_LOCAL_NAME = "UserLocalName"; + public const string USER_ENG_NAME = "UserEngName"; + public const string COMPANY_NAME = "CompanyName"; + public const string INDUSTRY = "Industry"; + public const string USER_PASSWORD = "UserPassword"; + public const string USER_MOBILE = "UserMobile"; + public const string USER_ADDRESS = "UserAddress"; + public const string POSTCODE = "Postcode"; + public const string COMMUNITY = "Community"; + public const string USER_GRADE = "UserGrade"; + public const string USER_TYPE = "UserType"; + public const string USER_WECHAT_ACCOUNT = "UserWechatAccount"; + public const string USER_ALIPAY_ACCOUNT = "UserAlipayAccount"; + public const string USER_ALIPAY_ACCOUNT_IMG_PATH = "UserAlipayAccountImgPath"; + public const string USER_WECHAT_ACCOUNT_IMG_PATH = "UserWechatAccountImgPath"; + public const string USER_ICON_IMG_PATH = "UserIconImgPath"; + public const string USER_ACCOUNTS_EXPIRE_DATETIME = "UserAccountsExpireDatetime"; + public const string USER_IS_VALID_INDC = "UserIsValidIndc"; + public const string IS_FORECE_CHANGE_PASSWORD_INDC = "IsForeceChangePasswordIndc"; + public const string IS_ACCOUNTS_LOCKED_INDC = "IsAccountsLockedIndc"; public const string ACCOUNTS_LOCKED_DATETIME = "AccountsLockedDatetime"; - public const string BIOMETRIC_COUNTER = "BiometricCounter"; + public const string USER_REMARK = "UserRemark"; + public const string WELCOME_PAGE = "WelcomePage"; + public const string USER_TYPE_END_DATETIME = "UserTypeEndDatetime"; + public const string ROOM_NAME = "RoomName"; + public const string LAST_LOGIN_DATETIME = "LastLoginDatetime"; + public const string ERROR_LOGIN_COUNT = "ErrorLoginCount"; public const string BIOMETRIC_CREDENTIAL_ID = "BiometricCredentialId"; + public const string BIOMETRIC_PUBLIC_KEY = "BiometricPublicKey"; + public const string BIOMETRIC_COUNTER = "BiometricCounter"; public const string BIOMETRIC_DEVICE_NAME = "BiometricDeviceName"; public const string BIOMETRIC_ENROLLED_AT = "BiometricEnrolledAt"; public const string BIOMETRIC_LAST_USED_AT = "BiometricLastUsedAt"; - public const string BIOMETRIC_PUBLIC_KEY = "BiometricPublicKey"; - public const string COMMUNITY = "Community"; - public const string COMPANY_NAME = "CompanyName"; - public const string CREATED_BY = "CreatedBy"; - public const string CREATED_DATETIME = "CreatedDatetime"; - public const string ERROR_LOGIN_COUNT = "ErrorLoginCount"; - public const string INDUSTRY = "Industry"; - public const string IS_ACCOUNTS_LOCKED_INDC = "IsAccountsLockedIndc"; - public const string IS_FORECE_CHANGE_PASSWORD_INDC = "IsForeceChangePasswordIndc"; - public const string LAST_LOGIN_DATETIME = "LastLoginDatetime"; - public const string POSTCODE = "Postcode"; - public const string ROOM_NAME = "RoomName"; - public const string UPDATED_BY = "UpdatedBy"; - public const string UPDATED_DATETIME = "UpdatedDatetime"; - public const string USER_ACCOUNTS_EXPIRE_DATETIME = "UserAccountsExpireDatetime"; - public const string USER_ADDRESS = "UserAddress"; - public const string USER_ALIPAY_ACCOUNT = "UserAlipayAccount"; - public const string USER_ALIPAY_ACCOUNT_IMG_PATH = "UserAlipayAccountImgPath"; - public const string USER_ENG_NAME = "UserEngName"; - public const string USER_GRADE = "UserGrade"; - public const string USER_ICON_IMG_PATH = "UserIconImgPath"; - public const string USER_IS_VALID_INDC = "UserIsValidIndc"; - public const string USER_LOCAL_NAME = "UserLocalName"; - public const string USER_MOBILE = "UserMobile"; - public const string USER_NAME = "UserName"; - public const string USER_PASSWORD = "UserPassword"; - public const string USER_REMARK = "UserRemark"; - public const string USER_TYPE = "UserType"; - public const string USER_TYPE_END_DATETIME = "UserTypeEndDatetime"; - public const string USER_WECHAT_ACCOUNT = "UserWechatAccount"; - public const string USER_WECHAT_ACCOUNT_IMG_PATH = "UserWechatAccountImgPath"; - public const string WELCOME_PAGE = "WelcomePage"; public const string DB_NAME_SECURITY_USER = "security_user"; - public const string DB_NAME_FIELDS="accounts_locked_datetime,biometric_counter,biometric_credential_id,biometric_device_name,biometric_enrolled_at,biometric_last_used_at,biometric_public_key,community,company_name,created_by,created_datetime,error_login_count,industry,is_accounts_locked_indc,is_forece_change_password_indc,last_login_datetime,postcode,room_name,updated_by,updated_datetime,user_accounts_expire_datetime,user_address,user_alipay_account,user_alipay_account_img_path,user_eng_name,user_grade,user_icon_img_path,user_is_valid_indc,user_local_name,user_mobile,user_name,user_password,user_remark,user_type,user_type_end_datetime,user_wechat_account,user_wechat_account_img_path,welcome_page"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,user_name,user_local_name,user_eng_name,company_name,industry,user_password,user_mobile,user_address,postcode,community,user_grade,user_type,user_wechat_account,user_alipay_account,user_alipay_account_img_path,user_wechat_account_img_path,user_icon_img_path,user_accounts_expire_datetime,user_is_valid_indc,is_forece_change_password_indc,is_accounts_locked_indc,accounts_locked_datetime,user_remark,welcome_page,user_type_end_datetime,room_name,last_login_datetime,error_login_count,biometric_credential_id,biometric_public_key,biometric_counter,biometric_device_name,biometric_enrolled_at,biometric_last_used_at"; + 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_USER_NAME = "user_name"; + public const string DB_USER_LOCAL_NAME = "user_local_name"; + public const string DB_USER_ENG_NAME = "user_eng_name"; + public const string DB_COMPANY_NAME = "company_name"; + public const string DB_INDUSTRY = "industry"; + public const string DB_USER_PASSWORD = "user_password"; + public const string DB_USER_MOBILE = "user_mobile"; + public const string DB_USER_ADDRESS = "user_address"; + public const string DB_POSTCODE = "postcode"; + public const string DB_COMMUNITY = "community"; + public const string DB_USER_GRADE = "user_grade"; + public const string DB_USER_TYPE = "user_type"; + public const string DB_USER_WECHAT_ACCOUNT = "user_wechat_account"; + public const string DB_USER_ALIPAY_ACCOUNT = "user_alipay_account"; + public const string DB_USER_ALIPAY_ACCOUNT_IMG_PATH = "user_alipay_account_img_path"; + public const string DB_USER_WECHAT_ACCOUNT_IMG_PATH = "user_wechat_account_img_path"; + public const string DB_USER_ICON_IMG_PATH = "user_icon_img_path"; + public const string DB_USER_ACCOUNTS_EXPIRE_DATETIME = "user_accounts_expire_datetime"; + public const string DB_USER_IS_VALID_INDC = "user_is_valid_indc"; + public const string DB_IS_FORECE_CHANGE_PASSWORD_INDC = "is_forece_change_password_indc"; + public const string DB_IS_ACCOUNTS_LOCKED_INDC = "is_accounts_locked_indc"; public const string DB_ACCOUNTS_LOCKED_DATETIME = "accounts_locked_datetime"; - public const string DB_BIOMETRIC_COUNTER = "biometric_counter"; + public const string DB_USER_REMARK = "user_remark"; + public const string DB_WELCOME_PAGE = "welcome_page"; + public const string DB_USER_TYPE_END_DATETIME = "user_type_end_datetime"; + public const string DB_ROOM_NAME = "room_name"; + public const string DB_LAST_LOGIN_DATETIME = "last_login_datetime"; + public const string DB_ERROR_LOGIN_COUNT = "error_login_count"; public const string DB_BIOMETRIC_CREDENTIAL_ID = "biometric_credential_id"; + public const string DB_BIOMETRIC_PUBLIC_KEY = "biometric_public_key"; + public const string DB_BIOMETRIC_COUNTER = "biometric_counter"; public const string DB_BIOMETRIC_DEVICE_NAME = "biometric_device_name"; public const string DB_BIOMETRIC_ENROLLED_AT = "biometric_enrolled_at"; public const string DB_BIOMETRIC_LAST_USED_AT = "biometric_last_used_at"; - public const string DB_BIOMETRIC_PUBLIC_KEY = "biometric_public_key"; - public const string DB_COMMUNITY = "community"; - public const string DB_COMPANY_NAME = "company_name"; - public const string DB_CREATED_BY = "created_by"; - public const string DB_CREATED_DATETIME = "created_datetime"; - public const string DB_ERROR_LOGIN_COUNT = "error_login_count"; - public const string DB_INDUSTRY = "industry"; - public const string DB_IS_ACCOUNTS_LOCKED_INDC = "is_accounts_locked_indc"; - public const string DB_IS_FORECE_CHANGE_PASSWORD_INDC = "is_forece_change_password_indc"; - public const string DB_LAST_LOGIN_DATETIME = "last_login_datetime"; - public const string DB_POSTCODE = "postcode"; - public const string DB_ROOM_NAME = "room_name"; - public const string DB_UPDATED_BY = "updated_by"; - public const string DB_UPDATED_DATETIME = "updated_datetime"; - public const string DB_USER_ACCOUNTS_EXPIRE_DATETIME = "user_accounts_expire_datetime"; - public const string DB_USER_ADDRESS = "user_address"; - public const string DB_USER_ALIPAY_ACCOUNT = "user_alipay_account"; - public const string DB_USER_ALIPAY_ACCOUNT_IMG_PATH = "user_alipay_account_img_path"; - public const string DB_USER_ENG_NAME = "user_eng_name"; - public const string DB_USER_GRADE = "user_grade"; - public const string DB_USER_ICON_IMG_PATH = "user_icon_img_path"; - public const string DB_USER_IS_VALID_INDC = "user_is_valid_indc"; - public const string DB_USER_LOCAL_NAME = "user_local_name"; - public const string DB_USER_MOBILE = "user_mobile"; - public const string DB_USER_NAME = "user_name"; - public const string DB_USER_PASSWORD = "user_password"; - public const string DB_USER_REMARK = "user_remark"; - public const string DB_USER_TYPE = "user_type"; - public const string DB_USER_TYPE_END_DATETIME = "user_type_end_datetime"; - public const string DB_USER_WECHAT_ACCOUNT = "user_wechat_account"; - public const string DB_USER_WECHAT_ACCOUNT_IMG_PATH = "user_wechat_account_img_path"; - public const string DB_WELCOME_PAGE = "welcome_page"; + public string ProviderName { get; set; } - public static SecurityUserEntity GetInstance() + public static SecurityUserEntity GetInstance(string providerName) { - return new SecurityUserEntity(); + return new SecurityUserEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityUserEntity source) @@ -191,65 +192,120 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } + this.CreatedDatetime = source.CreatedDatetime; + this.CreatedBy = source.CreatedBy; + this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; + this.UserName = source.UserName; + this.UserLocalName = source.UserLocalName; + this.UserEngName = source.UserEngName; + this.CompanyName = source.CompanyName; + this.Industry = source.Industry; + this.UserPassword = source.UserPassword; + this.UserMobile = source.UserMobile; + this.UserAddress = source.UserAddress; + this.Postcode = source.Postcode; + this.Community = source.Community; + this.UserGrade = source.UserGrade; + this.UserType = source.UserType; + this.UserWechatAccount = source.UserWechatAccount; + this.UserAlipayAccount = source.UserAlipayAccount; + this.UserAlipayAccountImgPath = source.UserAlipayAccountImgPath; + this.UserWechatAccountImgPath = source.UserWechatAccountImgPath; + this.UserIconImgPath = source.UserIconImgPath; + this.UserAccountsExpireDatetime = source.UserAccountsExpireDatetime; + this.UserIsValidIndc = source.UserIsValidIndc; + this.IsForeceChangePasswordIndc = source.IsForeceChangePasswordIndc; + this.IsAccountsLockedIndc = source.IsAccountsLockedIndc; this.AccountsLockedDatetime = source.AccountsLockedDatetime; - this.BiometricCounter = source.BiometricCounter; + this.UserRemark = source.UserRemark; + this.WelcomePage = source.WelcomePage; + this.UserTypeEndDatetime = source.UserTypeEndDatetime; + this.RoomName = source.RoomName; + this.LastLoginDatetime = source.LastLoginDatetime; + this.ErrorLoginCount = source.ErrorLoginCount; this.BiometricCredentialId = source.BiometricCredentialId; + this.BiometricPublicKey = source.BiometricPublicKey; + this.BiometricCounter = source.BiometricCounter; this.BiometricDeviceName = source.BiometricDeviceName; this.BiometricEnrolledAt = source.BiometricEnrolledAt; this.BiometricLastUsedAt = source.BiometricLastUsedAt; - this.BiometricPublicKey = source.BiometricPublicKey; - this.Community = source.Community; - this.CompanyName = source.CompanyName; - this.CreatedBy = source.CreatedBy; - this.CreatedDatetime = source.CreatedDatetime; - this.ErrorLoginCount = source.ErrorLoginCount; - this.Industry = source.Industry; - this.IsAccountsLockedIndc = source.IsAccountsLockedIndc; - this.IsForeceChangePasswordIndc = source.IsForeceChangePasswordIndc; - this.LastLoginDatetime = source.LastLoginDatetime; - this.Postcode = source.Postcode; - this.RoomName = source.RoomName; - this.UpdatedBy = source.UpdatedBy; - this.UpdatedDatetime = source.UpdatedDatetime; - this.UserAccountsExpireDatetime = source.UserAccountsExpireDatetime; - this.UserAddress = source.UserAddress; - this.UserAlipayAccount = source.UserAlipayAccount; - this.UserAlipayAccountImgPath = source.UserAlipayAccountImgPath; - this.UserEngName = source.UserEngName; - this.UserGrade = source.UserGrade; - this.UserIconImgPath = source.UserIconImgPath; - this.UserIsValidIndc = source.UserIsValidIndc; - this.UserLocalName = source.UserLocalName; - this.UserMobile = source.UserMobile; - this.UserName = source.UserName; - this.UserPassword = source.UserPassword; - this.UserRemark = source.UserRemark; - this.UserType = source.UserType; - this.UserTypeEndDatetime = source.UserTypeEndDatetime; - this.UserWechatAccount = source.UserWechatAccount; - this.UserWechatAccountImgPath = source.UserWechatAccountImgPath; - this.WelcomePage = source.WelcomePage; 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_USER} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_USER} "; } - + 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_USER} 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_USER} 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_USER_NAME ; @@ -257,6 +313,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_USER} 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_USER_NAME ; + 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_USER} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityUserEntity Clone() { SecurityUserEntity result = new SecurityUserEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserLoginLogEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserLoginLogEntity.auto.cs index 97f1f5a..1e381c3 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserLoginLogEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserLoginLogEntity.auto.cs @@ -14,50 +14,51 @@ namespace CloudBuilder.Security.Entity { } - [Column("agent_user_name")] - public string? AgentUserName { get; set; } - [Column("created_by")] - public string CreatedBy { get; set; } [Column("created_datetime")] public DateTime CreatedDatetime { get; set; } - [Column("ip_address")] - public string? IpAddress { 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("login_log_id")] public long LoginLogId { get; set; } - [Column("updated_by")] - public string UpdatedBy { get; set; } - [Column("updated_datetime")] - public DateTime UpdatedDatetime { get; set; } [Column("user_name")] public string UserName { get; set; } + [Column("agent_user_name")] + public string? AgentUserName { get; set; } + [Column("ip_address")] + public string? IpAddress { get; set; } - public const string AGENT_USER_NAME = "AgentUserName"; - public const string CREATED_BY = "CreatedBy"; public const string CREATED_DATETIME = "CreatedDatetime"; - public const string IP_ADDRESS = "IpAddress"; - public const string LOGIN_LOG_ID = "LoginLogId"; - public const string UPDATED_BY = "UpdatedBy"; + public const string CREATED_BY = "CreatedBy"; public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string UPDATED_BY = "UpdatedBy"; + public const string LOGIN_LOG_ID = "LoginLogId"; public const string USER_NAME = "UserName"; + public const string AGENT_USER_NAME = "AgentUserName"; + public const string IP_ADDRESS = "IpAddress"; public const string DB_NAME_SECURITY_USER_LOGIN_LOG = "security_user_login_log"; - public const string DB_NAME_FIELDS="agent_user_name,created_by,created_datetime,ip_address,login_log_id,updated_by,updated_datetime,user_name"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,login_log_id,user_name,agent_user_name,ip_address"; - public const string DB_AGENT_USER_NAME = "agent_user_name"; - public const string DB_CREATED_BY = "created_by"; public const string DB_CREATED_DATETIME = "created_datetime"; - public const string DB_IP_ADDRESS = "ip_address"; - public const string DB_LOGIN_LOG_ID = "login_log_id"; - 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_UPDATED_BY = "updated_by"; + public const string DB_LOGIN_LOG_ID = "login_log_id"; public const string DB_USER_NAME = "user_name"; + public const string DB_AGENT_USER_NAME = "agent_user_name"; + public const string DB_IP_ADDRESS = "ip_address"; + public string ProviderName { get; set; } - public static SecurityUserLoginLogEntity GetInstance() + public static SecurityUserLoginLogEntity GetInstance(string providerName) { - return new SecurityUserLoginLogEntity(); + return new SecurityUserLoginLogEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityUserLoginLogEntity source) @@ -72,35 +73,90 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.AgentUserName = source.AgentUserName; - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; - this.IpAddress = source.IpAddress; - this.LoginLogId = source.LoginLogId; - this.UpdatedBy = source.UpdatedBy; + this.CreatedBy = source.CreatedBy; this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; + this.LoginLogId = source.LoginLogId; this.UserName = source.UserName; + this.AgentUserName = source.AgentUserName; + this.IpAddress = source.IpAddress; 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_USER_LOGIN_LOG} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_USER_LOGIN_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_SECURITY_USER_LOGIN_LOG} 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_USER_LOGIN_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_LOGIN_LOG_ID ; @@ -108,6 +164,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_USER_LOGIN_LOG} 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_LOGIN_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_SECURITY_USER_LOGIN_LOG} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityUserLoginLogEntity Clone() { SecurityUserLoginLogEntity result = new SecurityUserLoginLogEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserPreferenceEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserPreferenceEntity.auto.cs index 6e296ef..61106a3 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserPreferenceEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserPreferenceEntity.auto.cs @@ -14,44 +14,45 @@ namespace CloudBuilder.Security.Entity { } - [Column("created_by")] - public string CreatedBy { get; set; } [Column("created_datetime")] public DateTime CreatedDatetime { get; set; } - [Column("preference")] - public string? Preference { get; set; } - [Column("preference_key")] - public string PreferenceKey { 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("updated_by")] + public string UpdatedBy { get; set; } [Column("username")] public string Username { get; set; } + [Column("preference_key")] + public string PreferenceKey { get; set; } + [Column("preference")] + public string? Preference { get; set; } - public const string CREATED_BY = "CreatedBy"; public const string CREATED_DATETIME = "CreatedDatetime"; - public const string PREFERENCE = "Preference"; - public const string PREFERENCE_KEY = "PreferenceKey"; - public const string UPDATED_BY = "UpdatedBy"; + public const string CREATED_BY = "CreatedBy"; public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string UPDATED_BY = "UpdatedBy"; public const string USERNAME = "Username"; + public const string PREFERENCE_KEY = "PreferenceKey"; + public const string PREFERENCE = "Preference"; public const string DB_NAME_SECURITY_USER_PREFERENCE = "security_user_preference"; - public const string DB_NAME_FIELDS="created_by,created_datetime,preference,preference_key,updated_by,updated_datetime,username"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,username,preference_key,preference"; - public const string DB_CREATED_BY = "created_by"; public const string DB_CREATED_DATETIME = "created_datetime"; - public const string DB_PREFERENCE = "preference"; - public const string DB_PREFERENCE_KEY = "preference_key"; - 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_UPDATED_BY = "updated_by"; public const string DB_USERNAME = "username"; + public const string DB_PREFERENCE_KEY = "preference_key"; + public const string DB_PREFERENCE = "preference"; + public string ProviderName { get; set; } - public static SecurityUserPreferenceEntity GetInstance() + public static SecurityUserPreferenceEntity GetInstance(string providerName) { - return new SecurityUserPreferenceEntity(); + return new SecurityUserPreferenceEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityUserPreferenceEntity source) @@ -66,41 +67,104 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; - this.Preference = source.Preference; - this.PreferenceKey = source.PreferenceKey; - this.UpdatedBy = source.UpdatedBy; + this.CreatedBy = source.CreatedBy; this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; this.Username = source.Username; + this.PreferenceKey = source.PreferenceKey; + this.Preference = source.Preference; 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_USER_PREFERENCE} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_USER_PREFERENCE} "; } - + 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_USER_PREFERENCE} 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_USER_PREFERENCE} 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_PREFERENCE_KEY ; + if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_USERNAME ; 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_USER_PREFERENCE} 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_USERNAME ; + 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_USER_PREFERENCE} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityUserPreferenceEntity Clone() { SecurityUserPreferenceEntity result = new SecurityUserPreferenceEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserPreferenceEntityKey.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserPreferenceEntityKey.auto.cs index daa59be..b5a75a5 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserPreferenceEntityKey.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserPreferenceEntityKey.auto.cs @@ -5,8 +5,8 @@ namespace CloudBuilder.Security [TypeScript] public class SecurityUserPreferenceEntityKey { - public string PreferenceKey { get; set; } public string Username { get; set; } + public string PreferenceKey { get; set; } public override bool Equals(object obj) { @@ -15,8 +15,8 @@ namespace CloudBuilder.Security SecurityUserPreferenceEntityKey pkey = obj as SecurityUserPreferenceEntityKey; if (pkey == null) return false; - if (PreferenceKey != pkey.PreferenceKey) return false; if (Username != pkey.Username) return false; + if (PreferenceKey != pkey.PreferenceKey) return false; return true; } @@ -25,9 +25,9 @@ namespace CloudBuilder.Security public override string ToString() { string declareSql=""; - declareSql=declareSql+$"declare @__tkey_PreferenceKey_0 varchar(50) select @__tkey_PreferenceKey_0 ='{PreferenceKey}'; " ; declareSql=declareSql+$"declare @__tkey_Username_1 varchar(50) select @__tkey_Username_1 ='{Username}'; " ; + declareSql=declareSql+$"declare @__tkey_Username_0 varchar(50) select @__tkey_Username_0 ='{Username}'; " ; declareSql=declareSql+$"declare @__tkey_PreferenceKey_1 varchar(50) select @__tkey_PreferenceKey_1 ='{PreferenceKey}'; " ; return declareSql; } } } - /* builder.Entity().HasKey(c => new { c.PreferenceKey, c.Username}); */ + /* builder.Entity().HasKey(c => new { c.Username, c.PreferenceKey}); */ diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserViewEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserViewEntity.auto.cs index 3fc9fa1..e2d702f 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserViewEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserViewEntity.auto.cs @@ -14,40 +14,41 @@ namespace CloudBuilder.Security.Entity { } - [Column("actor_local_name")] - public string? ActorLocalName { get; set; } - [Column("actor_name")] - public string? ActorName { get; set; } + [Column("user_name")] + public string UserName { get; set; } [Column("user_local_name")] public string UserLocalName { get; set; } [Column("user_mobile")] public string? UserMobile { get; set; } - [Column("user_name")] - public string UserName { get; set; } [Column("welcome_page")] public string? WelcomePage { get; set; } + [Column("actor_name")] + public string? ActorName { get; set; } + [Column("actor_local_name")] + public string? ActorLocalName { get; set; } - public const string ACTOR_LOCAL_NAME = "ActorLocalName"; - public const string ACTOR_NAME = "ActorName"; + public const string USER_NAME = "UserName"; public const string USER_LOCAL_NAME = "UserLocalName"; public const string USER_MOBILE = "UserMobile"; - public const string USER_NAME = "UserName"; public const string WELCOME_PAGE = "WelcomePage"; + public const string ACTOR_NAME = "ActorName"; + public const string ACTOR_LOCAL_NAME = "ActorLocalName"; public const string DB_NAME_SECURITY_USER_VIEW = "security_user_view"; - public const string DB_NAME_FIELDS="actor_local_name,actor_name,user_local_name,user_mobile,user_name,welcome_page"; + public const string DB_NAME_FIELDS="user_name,user_local_name,user_mobile,welcome_page,actor_name,actor_local_name"; - public const string DB_ACTOR_LOCAL_NAME = "actor_local_name"; - public const string DB_ACTOR_NAME = "actor_name"; + public const string DB_USER_NAME = "user_name"; public const string DB_USER_LOCAL_NAME = "user_local_name"; public const string DB_USER_MOBILE = "user_mobile"; - public const string DB_USER_NAME = "user_name"; public const string DB_WELCOME_PAGE = "welcome_page"; + public const string DB_ACTOR_NAME = "actor_name"; + public const string DB_ACTOR_LOCAL_NAME = "actor_local_name"; + public string ProviderName { get; set; } - public static SecurityUserViewEntity GetInstance() + public static SecurityUserViewEntity GetInstance(string providerName) { - return new SecurityUserViewEntity(); + return new SecurityUserViewEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityUserViewEntity source) @@ -62,12 +63,12 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.ActorLocalName = source.ActorLocalName; - this.ActorName = source.ActorName; + this.UserName = source.UserName; this.UserLocalName = source.UserLocalName; this.UserMobile = source.UserMobile; - this.UserName = source.UserName; this.WelcomePage = source.WelcomePage; + this.ActorName = source.ActorName; + this.ActorLocalName = source.ActorLocalName; if (includeSystemFields) { @@ -75,23 +76,86 @@ namespace CloudBuilder.Security.Entity } 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_USER_VIEW} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_USER_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_USER_VIEW} 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_USER_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_ACTOR_LOCAL_NAME ; int offset = limit * (start - 1); + if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_USER_NAME ; 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_USER_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_USER_NAME ; 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_USER_VIEW} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityUserViewEntity Clone() { SecurityUserViewEntity result = new SecurityUserViewEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserWebLoginEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserWebLoginEntity.auto.cs index 5636737..db17bf4 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserWebLoginEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserWebLoginEntity.auto.cs @@ -14,6 +14,10 @@ namespace CloudBuilder.Security.Entity { } + [Column("session_id")] + public string SessionId { get; set; } + [Column("username")] + public string Username { get; set; } [Column("host_ip")] public string? HostIp { get; set; } [Column("host_user_agent")] @@ -26,36 +30,33 @@ namespace CloudBuilder.Security.Entity public string RefreshToken { get; set; } [Column("refresh_token_refreshed_time")] public DateTime RefreshTokenRefreshedTime { get; set; } - [Column("session_id")] - public string SessionId { get; set; } - [Column("username")] - public string Username { get; set; } + public const string SESSION_ID = "SessionId"; + public const string USERNAME = "Username"; public const string HOST_IP = "HostIp"; public const string HOST_USER_AGENT = "HostUserAgent"; public const string LOGIN_TIME = "LoginTime"; public const string LOGOUT_TIME = "LogoutTime"; public const string REFRESH_TOKEN = "RefreshToken"; public const string REFRESH_TOKEN_REFRESHED_TIME = "RefreshTokenRefreshedTime"; - public const string SESSION_ID = "SessionId"; - public const string USERNAME = "Username"; public const string DB_NAME_SECURITY_USER_WEB_LOGIN = "security_user_web_login"; - public const string DB_NAME_FIELDS="host_ip,host_user_agent,login_time,logout_time,refresh_token,refresh_token_refreshed_time,session_id,username"; + public const string DB_NAME_FIELDS="session_id,username,host_ip,host_user_agent,login_time,logout_time,refresh_token,refresh_token_refreshed_time"; + public const string DB_SESSION_ID = "session_id"; + public const string DB_USERNAME = "username"; public const string DB_HOST_IP = "host_ip"; public const string DB_HOST_USER_AGENT = "host_user_agent"; public const string DB_LOGIN_TIME = "login_time"; public const string DB_LOGOUT_TIME = "logout_time"; public const string DB_REFRESH_TOKEN = "refresh_token"; public const string DB_REFRESH_TOKEN_REFRESHED_TIME = "refresh_token_refreshed_time"; - public const string DB_SESSION_ID = "session_id"; - public const string DB_USERNAME = "username"; + public string ProviderName { get; set; } - public static SecurityUserWebLoginEntity GetInstance() + public static SecurityUserWebLoginEntity GetInstance(string providerName) { - return new SecurityUserWebLoginEntity(); + return new SecurityUserWebLoginEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityUserWebLoginEntity source) @@ -70,14 +71,14 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } + this.SessionId = source.SessionId; + this.Username = source.Username; this.HostIp = source.HostIp; this.HostUserAgent = source.HostUserAgent; this.LoginTime = source.LoginTime; this.LogoutTime = source.LogoutTime; this.RefreshToken = source.RefreshToken; this.RefreshTokenRefreshedTime = source.RefreshTokenRefreshedTime; - this.SessionId = source.SessionId; - this.Username = source.Username; if (includeSystemFields) { @@ -85,16 +86,71 @@ namespace CloudBuilder.Security.Entity } 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_USER_WEB_LOGIN} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_USER_WEB_LOGIN} "; } - + 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_USER_WEB_LOGIN} 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_USER_WEB_LOGIN} 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_SESSION_ID ; @@ -102,6 +158,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_USER_WEB_LOGIN} 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_SESSION_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_SECURITY_USER_WEB_LOGIN} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityUserWebLoginEntity Clone() { SecurityUserWebLoginEntity result = new SecurityUserWebLoginEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserWebPagePreferenceEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserWebPagePreferenceEntity.auto.cs index a06445d..e9f8679 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserWebPagePreferenceEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserWebPagePreferenceEntity.auto.cs @@ -14,52 +14,53 @@ namespace CloudBuilder.Security.Entity { } - [Column("created_by")] - public string CreatedBy { get; set; } [Column("created_datetime")] public DateTime CreatedDatetime { get; set; } - [Column("default_indc")] - public string? DefaultIndc { get; set; } - [Column("preference")] - public string? Preference { 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("username")] + public string Username { get; set; } [Column("preference_key")] public string PreferenceKey { get; set; } [Column("profile_name")] public string ProfileName { get; set; } - [Column("updated_by")] - public string UpdatedBy { get; set; } - [Column("updated_datetime")] - public DateTime UpdatedDatetime { get; set; } - [Column("username")] - public string Username { get; set; } + [Column("preference")] + public string? Preference { get; set; } + [Column("default_indc")] + public string? DefaultIndc { get; set; } - public const string CREATED_BY = "CreatedBy"; public const string CREATED_DATETIME = "CreatedDatetime"; - public const string DEFAULT_INDC = "DefaultIndc"; - public const string PREFERENCE = "Preference"; + public const string CREATED_BY = "CreatedBy"; + public const string UPDATED_DATETIME = "UpdatedDatetime"; + public const string UPDATED_BY = "UpdatedBy"; + public const string USERNAME = "Username"; public const string PREFERENCE_KEY = "PreferenceKey"; public const string PROFILE_NAME = "ProfileName"; - public const string UPDATED_BY = "UpdatedBy"; - public const string UPDATED_DATETIME = "UpdatedDatetime"; - public const string USERNAME = "Username"; + public const string PREFERENCE = "Preference"; + public const string DEFAULT_INDC = "DefaultIndc"; public const string DB_NAME_SECURITY_USER_WEB_PAGE_PREFERENCE = "security_user_web_page_preference"; - public const string DB_NAME_FIELDS="created_by,created_datetime,default_indc,preference,preference_key,profile_name,updated_by,updated_datetime,username"; + public const string DB_NAME_FIELDS="created_datetime,created_by,updated_datetime,updated_by,username,preference_key,profile_name,preference,default_indc"; - public const string DB_CREATED_BY = "created_by"; public const string DB_CREATED_DATETIME = "created_datetime"; - public const string DB_DEFAULT_INDC = "default_indc"; - public const string DB_PREFERENCE = "preference"; + 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_USERNAME = "username"; public const string DB_PREFERENCE_KEY = "preference_key"; public const string DB_PROFILE_NAME = "profile_name"; - public const string DB_UPDATED_BY = "updated_by"; - public const string DB_UPDATED_DATETIME = "updated_datetime"; - public const string DB_USERNAME = "username"; + public const string DB_PREFERENCE = "preference"; + public const string DB_DEFAULT_INDC = "default_indc"; + public string ProviderName { get; set; } - public static SecurityUserWebPagePreferenceEntity GetInstance() + public static SecurityUserWebPagePreferenceEntity GetInstance(string providerName) { - return new SecurityUserWebPagePreferenceEntity(); + return new SecurityUserWebPagePreferenceEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SecurityUserWebPagePreferenceEntity source) @@ -74,43 +75,106 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.CreatedBy = source.CreatedBy; this.CreatedDatetime = source.CreatedDatetime; - this.DefaultIndc = source.DefaultIndc; - this.Preference = source.Preference; + this.CreatedBy = source.CreatedBy; + this.UpdatedDatetime = source.UpdatedDatetime; + this.UpdatedBy = source.UpdatedBy; + this.Username = source.Username; this.PreferenceKey = source.PreferenceKey; this.ProfileName = source.ProfileName; - this.UpdatedBy = source.UpdatedBy; - this.UpdatedDatetime = source.UpdatedDatetime; - this.Username = source.Username; + this.Preference = source.Preference; + this.DefaultIndc = source.DefaultIndc; 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_USER_WEB_PAGE_PREFERENCE} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SECURITY_USER_WEB_PAGE_PREFERENCE} "; } - + 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_USER_WEB_PAGE_PREFERENCE} 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_USER_WEB_PAGE_PREFERENCE} 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_PREFERENCE_KEY ; + if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_USERNAME ; 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_USER_WEB_PAGE_PREFERENCE} 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_USERNAME ; + 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_USER_WEB_PAGE_PREFERENCE} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SecurityUserWebPagePreferenceEntity Clone() { SecurityUserWebPagePreferenceEntity result = new SecurityUserWebPagePreferenceEntity(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserWebPagePreferenceEntityKey.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserWebPagePreferenceEntityKey.auto.cs index 0e22370..54d56a2 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserWebPagePreferenceEntityKey.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SecurityUserWebPagePreferenceEntityKey.auto.cs @@ -5,9 +5,9 @@ namespace CloudBuilder.Security [TypeScript] public class SecurityUserWebPagePreferenceEntityKey { + public string Username { get; set; } public string PreferenceKey { get; set; } public string ProfileName { get; set; } - public string Username { get; set; } public override bool Equals(object obj) { @@ -16,9 +16,9 @@ namespace CloudBuilder.Security SecurityUserWebPagePreferenceEntityKey pkey = obj as SecurityUserWebPagePreferenceEntityKey; if (pkey == null) return false; + if (Username != pkey.Username) return false; if (PreferenceKey != pkey.PreferenceKey) return false; if (ProfileName != pkey.ProfileName) return false; - if (Username != pkey.Username) return false; return true; } @@ -27,9 +27,9 @@ namespace CloudBuilder.Security public override string ToString() { string declareSql=""; - declareSql=declareSql+$"declare @__tkey_PreferenceKey_0 varchar(50) select @__tkey_PreferenceKey_0 ='{PreferenceKey}'; " ; declareSql=declareSql+$"declare @__tkey_ProfileName_1 varchar(50) select @__tkey_ProfileName_1 ='{ProfileName}'; " ; declareSql=declareSql+$"declare @__tkey_Username_2 varchar(50) select @__tkey_Username_2 ='{Username}'; " ; + declareSql=declareSql+$"declare @__tkey_Username_0 varchar(50) select @__tkey_Username_0 ='{Username}'; " ; declareSql=declareSql+$"declare @__tkey_PreferenceKey_1 varchar(50) select @__tkey_PreferenceKey_1 ='{PreferenceKey}'; " ; declareSql=declareSql+$"declare @__tkey_ProfileName_2 varchar(50) select @__tkey_ProfileName_2 ='{ProfileName}'; " ; return declareSql; } } } - /* builder.Entity().HasKey(c => new { c.PreferenceKey, c.ProfileName, c.Username}); */ + /* builder.Entity().HasKey(c => new { c.Username, c.PreferenceKey, c.ProfileName}); */ diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SysTablePkeyViewEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SysTablePkeyViewEntity.auto.cs index 647e083..505d94c 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SysTablePkeyViewEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SysTablePkeyViewEntity.auto.cs @@ -14,40 +14,41 @@ namespace CloudBuilder.Security.Entity { } - [Column("column_name")] - public string? ColumnName { get; set; } - [Column("pk")] - public int Pk { get; set; } - [Column("pk_name")] - public string? PkName { get; set; } - [Column("table_name")] - public string TableName { get; set; } - [Column("table_owner")] - public string TableOwner { get; set; } [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 COLUMN_NAME = "ColumnName"; - public const string PK = "Pk"; - public const string PK_NAME = "PkName"; - public const string TABLE_NAME = "TableName"; - public const string TABLE_OWNER = "TableOwner"; 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="column_name,pk,pk_name,table_name,table_owner,table_qualifier"; + public const string DB_NAME_FIELDS="table_qualifier,table_owner,table_name,column_name,pk_name,pk"; - public const string DB_COLUMN_NAME = "column_name"; - public const string DB_PK = "pk"; - public const string DB_PK_NAME = "pk_name"; - public const string DB_TABLE_NAME = "table_name"; - public const string DB_TABLE_OWNER = "table_owner"; 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() + public static SysTablePkeyViewEntity GetInstance(string providerName) { - return new SysTablePkeyViewEntity(); + return new SysTablePkeyViewEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SysTablePkeyViewEntity source) @@ -62,12 +63,12 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.ColumnName = source.ColumnName; - this.Pk = source.Pk; - this.PkName = source.PkName; - this.TableName = source.TableName; - this.TableOwner = source.TableOwner; 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) { @@ -75,23 +76,86 @@ namespace CloudBuilder.Security.Entity } 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 override string GetSelectTopFrom(int limit, int start,string orderby,string orderbytag, string 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_COLUMN_NAME ; int offset = limit * (start - 1); + 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(); diff --git a/CloudBuilder/CloudBuilder.Security/Entity/SysTableSchemaViewEntity.auto.cs b/CloudBuilder/CloudBuilder.Security/Entity/SysTableSchemaViewEntity.auto.cs index 2a15450..9ec07c6 100644 --- a/CloudBuilder/CloudBuilder.Security/Entity/SysTableSchemaViewEntity.auto.cs +++ b/CloudBuilder/CloudBuilder.Security/Entity/SysTableSchemaViewEntity.auto.cs @@ -14,76 +14,77 @@ namespace CloudBuilder.Security.Entity { } - [Column("colid")] - public long Colid { get; set; } - [Column("field_default_value")] - public string FieldDefaultValue { get; set; } + [Column("table_name")] + public string TableName { get; set; } [Column("field_name")] public string? FieldName { get; set; } - [Column("find_by")] - public int FindBy { get; set; } - [Column("is_identity")] - public long IsIdentity { get; set; } - [Column("is_null_able")] - public string IsNullAble { get; set; } + [Column("type_name")] + public string? TypeName { get; set; } + [Column("type_of_name")] + public string? TypeOfName { get; set; } [Column("max_length")] public long MaxLength { get; set; } + [Column("scale",TypeName = "decimal(20,0)")] + public decimal Scale { get; set; } + [Column("is_null_able")] + public string IsNullAble { get; set; } + [Column("field_default_value")] + public string FieldDefaultValue { get; set; } + [Column("xtype")] + public string? Xtype { get; set; } + [Column("find_by")] + public int FindBy { get; set; } [Column("operation")] public int Operation { get; set; } [Column("pk")] public long Pk { get; set; } [Column("pk_name")] public string PkName { get; set; } - [Column("scale",TypeName = "decimal(20,0)")] - public decimal Scale { get; set; } - [Column("table_name")] - public string TableName { get; set; } - [Column("type_name")] - public string? TypeName { get; set; } - [Column("type_of_name")] - public string? TypeOfName { get; set; } - [Column("xtype")] - public string? Xtype { get; set; } + [Column("is_identity")] + public long IsIdentity { get; set; } + [Column("colid")] + public long Colid { get; set; } - public const string COLID = "Colid"; - public const string FIELD_DEFAULT_VALUE = "FieldDefaultValue"; + public const string TABLE_NAME = "TableName"; public const string FIELD_NAME = "FieldName"; - public const string FIND_BY = "FindBy"; - public const string IS_IDENTITY = "IsIdentity"; - public const string IS_NULL_ABLE = "IsNullAble"; + public const string TYPE_NAME = "TypeName"; + public const string TYPE_OF_NAME = "TypeOfName"; public const string MAX_LENGTH = "MaxLength"; + public const string SCALE = "Scale"; + public const string IS_NULL_ABLE = "IsNullAble"; + public const string FIELD_DEFAULT_VALUE = "FieldDefaultValue"; + public const string XTYPE = "Xtype"; + public const string FIND_BY = "FindBy"; public const string OPERATION = "Operation"; public const string PK = "Pk"; public const string PK_NAME = "PkName"; - public const string SCALE = "Scale"; - public const string TABLE_NAME = "TableName"; - public const string TYPE_NAME = "TypeName"; - public const string TYPE_OF_NAME = "TypeOfName"; - public const string XTYPE = "Xtype"; + public const string IS_IDENTITY = "IsIdentity"; + public const string COLID = "Colid"; public const string DB_NAME_SYS_TABLE_SCHEMA_VIEW = "sys_table_schema_view"; - public const string DB_NAME_FIELDS="colid,field_default_value,field_name,find_by,is_identity,is_null_able,max_length,operation,pk,pk_name,scale,table_name,type_name,type_of_name,xtype"; + public const string DB_NAME_FIELDS="table_name,field_name,type_name,type_of_name,max_length,scale,is_null_able,field_default_value,xtype,find_by,operation,pk,pk_name,is_identity,colid"; - public const string DB_COLID = "colid"; - public const string DB_FIELD_DEFAULT_VALUE = "field_default_value"; + public const string DB_TABLE_NAME = "table_name"; public const string DB_FIELD_NAME = "field_name"; - public const string DB_FIND_BY = "find_by"; - public const string DB_IS_IDENTITY = "is_identity"; - public const string DB_IS_NULL_ABLE = "is_null_able"; + public const string DB_TYPE_NAME = "type_name"; + public const string DB_TYPE_OF_NAME = "type_of_name"; public const string DB_MAX_LENGTH = "max_length"; + public const string DB_SCALE = "scale"; + public const string DB_IS_NULL_ABLE = "is_null_able"; + public const string DB_FIELD_DEFAULT_VALUE = "field_default_value"; + public const string DB_XTYPE = "xtype"; + public const string DB_FIND_BY = "find_by"; public const string DB_OPERATION = "operation"; public const string DB_PK = "pk"; public const string DB_PK_NAME = "pk_name"; - public const string DB_SCALE = "scale"; - public const string DB_TABLE_NAME = "table_name"; - public const string DB_TYPE_NAME = "type_name"; - public const string DB_TYPE_OF_NAME = "type_of_name"; - public const string DB_XTYPE = "xtype"; + public const string DB_IS_IDENTITY = "is_identity"; + public const string DB_COLID = "colid"; + public string ProviderName { get; set; } - public static SysTableSchemaViewEntity GetInstance() + public static SysTableSchemaViewEntity GetInstance(string providerName) { - return new SysTableSchemaViewEntity(); + return new SysTableSchemaViewEntity() { ProviderName = providerName }; } public virtual void CopyFrom(SysTableSchemaViewEntity source) @@ -98,21 +99,21 @@ namespace CloudBuilder.Security.Entity throw new NullReferenceException("Source entity is null."); } - this.Colid = source.Colid; - this.FieldDefaultValue = source.FieldDefaultValue; + this.TableName = source.TableName; this.FieldName = source.FieldName; - this.FindBy = source.FindBy; - this.IsIdentity = source.IsIdentity; - this.IsNullAble = source.IsNullAble; + this.TypeName = source.TypeName; + this.TypeOfName = source.TypeOfName; this.MaxLength = source.MaxLength; + this.Scale = source.Scale; + this.IsNullAble = source.IsNullAble; + this.FieldDefaultValue = source.FieldDefaultValue; + this.Xtype = source.Xtype; + this.FindBy = source.FindBy; this.Operation = source.Operation; this.Pk = source.Pk; this.PkName = source.PkName; - this.Scale = source.Scale; - this.TableName = source.TableName; - this.TypeName = source.TypeName; - this.TypeOfName = source.TypeOfName; - this.Xtype = source.Xtype; + this.IsIdentity = source.IsIdentity; + this.Colid = source.Colid; if (includeSystemFields) { @@ -120,23 +121,86 @@ namespace CloudBuilder.Security.Entity } 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_SCHEMA_VIEW} with(nolock) "; + } + public string GetSelectFromByBySqlServer() { return $" select {DB_NAME_FIELDS} from { DB_NAME_SYS_TABLE_SCHEMA_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_SCHEMA_VIEW} 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_SYS_TABLE_SCHEMA_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_COLID ; int offset = limit * (start - 1); + if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_TABLE_NAME ; 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_SCHEMA_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_NAME ; 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_SCHEMA_VIEW} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}"; + } + public SysTableSchemaViewEntity Clone() { SysTableSchemaViewEntity result = new SysTableSchemaViewEntity();