SqlServer and MySql
This commit is contained in:
1 parent
42405492b6
commit
011e60afa9
53 files changed
+3419
-1238
No files matched your search
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user