214 lines
9.2 KiB
C#
214 lines
9.2 KiB
C#
|
|
using Models;
|
|||
|
|
using Models.ApiModei;
|
|||
|
|
using Models.ModelItems;
|
|||
|
|
using Models.View;
|
|||
|
|
using Org.BouncyCastle.Utilities;
|
|||
|
|
using Services.Manager;
|
|||
|
|
using Services.Tool;
|
|||
|
|
using SqlSugar;
|
|||
|
|
using StackExchange.Redis;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Diagnostics;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using static Services.Cache.CacheHelp;
|
|||
|
|
|
|||
|
|
namespace Services.Cache
|
|||
|
|
{
|
|||
|
|
public class CacheHelp
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
public enum syskey
|
|||
|
|
{
|
|||
|
|
sysAuthorityListKey,
|
|||
|
|
sysHotelsListKey,
|
|||
|
|
sysGsInfoListKey,
|
|||
|
|
sysAuthoStatusTypeListKey,
|
|||
|
|
sysOrganizationListKey,
|
|||
|
|
sysOrgAuthorityListKey,
|
|||
|
|
sysOrgUserListKey,
|
|||
|
|
sysErrorInfoListKey,
|
|||
|
|
sysUserAuthoListKey,
|
|||
|
|
sysAppsListKey,
|
|||
|
|
sysUserInfoListKey,
|
|||
|
|
sysAppAuthoListKey,
|
|||
|
|
sysHoteldGroupsListKey,
|
|||
|
|
sysView_UOAListKey,
|
|||
|
|
sysView_UAListKey,
|
|||
|
|
sysDbLogListKey,
|
|||
|
|
sysHostsListKey,
|
|||
|
|
Appversions,
|
|||
|
|
sysMACLogs,
|
|||
|
|
sysALLqxListKey,
|
|||
|
|
sysQxIfoListKey,
|
|||
|
|
sysView_AppAuthoListKey,
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
private static readonly string sysHotelsListKey = "autho_sysHotelsListKey";
|
|||
|
|
private static readonly string sysHostsListKey = "autho_sysHostsListKey";
|
|||
|
|
private static readonly string sysHoteldGroupsListKey = "autho_sysHoteldGroupsListKey";
|
|||
|
|
private static readonly string Appversions = "autho_Appversions";
|
|||
|
|
private static readonly string sysView_UOAListKey = "autho_sysView_UOAListKey";
|
|||
|
|
private static readonly string sysView_UAListKey = "autho_sysView_UAListKey";
|
|||
|
|
private static readonly string sysView_AppAuthoListKey = "autho_sysView_AppAuthoListKey";
|
|||
|
|
private static readonly string sysAuthorityLisKey = "autho_sysAuthorityListKey";
|
|||
|
|
private static readonly string sysAuthoStatusTypeLisKey = "autho_sysAuthoStatusTypeListKey";
|
|||
|
|
private static readonly string sysOrganizationLisKey = "autho_sysOrganizationListKey";
|
|||
|
|
private static readonly string sysOrgAuthorityLisKey = "autho_sysOrgAuthorityListKey";
|
|||
|
|
private static readonly string sysOrgUserLisKey = "autho_sysOrgUserListKey";
|
|||
|
|
private static readonly string sysUserAuthoLisKey = "autho_sysUserAuthoListKey";
|
|||
|
|
private static readonly string sysAppsListKey = "autho_sysAppsListKey";
|
|||
|
|
private static readonly string sysErrorInfoListKey = "autho_sysErrorInfoListKey";
|
|||
|
|
private static readonly string sysMACLogs = "autho_sysMACLogs";
|
|||
|
|
private static readonly string sysView_MAClog = "autho_sysView_MAClog";
|
|||
|
|
private static readonly string sysGsInfoListKey = "autho_sysGsInfoListKey";
|
|||
|
|
private static readonly string sysQxIfoListKey = "autho_sysQxIfoListKey";
|
|||
|
|
private static readonly string sysUserInfoListKey = "autho_sysUserInfoListKey";
|
|||
|
|
private static readonly string sysAppAuthoListKey = "autho_sysAppAuthoListKey";
|
|||
|
|
private static readonly string sysDbLogListKey = "autho_sysDbLogListKey";
|
|||
|
|
|
|||
|
|
//酒店信息
|
|||
|
|
public static List<HotelGroups> gh => CacheHelp.cacheHoteldGroups.Where(x => x.ParentId == 1).ToList();
|
|||
|
|
public static List<ReturnResult> HoteldGroupsinfo
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
List<ReturnResult> HoteldGroupsinfos = new List<ReturnResult>();
|
|||
|
|
foreach (var item in gh)
|
|||
|
|
{
|
|||
|
|
var data = CacheHelp.cacheHoteldGroups.Where(x => x.ParentId == item.Id).ToList();
|
|||
|
|
data.Insert(0, item);
|
|||
|
|
HoteldGroupsinfos.Add(new ReturnResult()
|
|||
|
|
{
|
|||
|
|
Message = SyncHotelServer.FindHotel(item.Id).Count,
|
|||
|
|
Status = item.Id
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
return HoteldGroupsinfos;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public static List<View_UserInfo> cacheView_UserInfo => GetCachesys(new View_UserInfo(), sysUserInfoListKey);
|
|||
|
|
public static List<View_MAClog> cachesysMACLogs => GetCachesys(new View_MAClog(), sysMACLogs);
|
|||
|
|
public static List<ErrorInfo> cacheSysErrorInfo => GetCachesys(new ErrorInfo(), sysErrorInfoListKey);
|
|||
|
|
public static List<ApplicationDomain> cacheSysApp => GetCachesys(new ApplicationDomain(), sysAppsListKey);
|
|||
|
|
public static List<GsInfo> cacheSysGsInfo => GetCachesys(new GsInfo(), sysGsInfoListKey, "exec Findgsall");
|
|||
|
|
|
|||
|
|
|
|||
|
|
public static List<Authority> cacheSysAutho => GetCachesys(new Authority(), sysAuthorityLisKey);
|
|||
|
|
|
|||
|
|
public static List<AuthoStatusType> cacheSysAuthoStatusType => GetCachesys(new AuthoStatusType(), sysAuthoStatusTypeLisKey);
|
|||
|
|
|
|||
|
|
public static List<Organization> cacheSysOrganization => GetCachesys(new Organization(), sysOrganizationLisKey);
|
|||
|
|
|
|||
|
|
public static List<OrgAuthority> cacheSysOrgAuthority => GetCachesys(new OrgAuthority(), sysOrgAuthorityLisKey);
|
|||
|
|
|
|||
|
|
public static List<OrgUsers> cacheSysOrgUser => GetCachesys(new OrgUsers(), sysOrgUserLisKey);
|
|||
|
|
|
|||
|
|
public static ISugarQueryable<UserAuthoes> cacheSysUserAutho => SqlSugarBase.Db.Queryable<UserAuthoes>();
|
|||
|
|
//GetCachesys(new UserAuthoes(), sysUserAuthoLisKey);
|
|||
|
|
|
|||
|
|
//从视图View_UserInfo读取信息,包括人员信息和部分所属组织信息。
|
|||
|
|
public static List<View_UserInfo> cacheSysUserInfo => GetCachesys(new View_UserInfo(), sysUserInfoListKey);
|
|||
|
|
|
|||
|
|
public static List<AppAutho> cacheSysAppAutho => GetCachesys(new AppAutho(), sysAppAuthoListKey);
|
|||
|
|
public static List<View_UOA> cacheView_UOA => GetCachesys(new View_UOA(), sysView_UOAListKey);
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// GetCachesys(new View_UA(), sysView_UAListKey);
|
|||
|
|
/// </summary>
|
|||
|
|
public static List<View_AppAutho> cacheView_AppAutho => GetCachesys(new View_AppAutho(), sysView_AppAuthoListKey);
|
|||
|
|
public static List<Hotels> cacheHotels => GetCachesys(new Hotels(), sysHotelsListKey, "select * FROM Hotels ORDER BY CreateTime DESC");
|
|||
|
|
public static List<Hosts> cacheHosts => GetCachesys(new Hosts(), sysHostsListKey);
|
|||
|
|
public static List<HotelGroups> cacheHoteldGroups => GetCachesys(new HotelGroups(), sysHoteldGroupsListKey);
|
|||
|
|
public static int cacheDbLogs => GetCachesys(new int(), sysDbLogListKey, "select count(*) FROM DbLog")[0];
|
|||
|
|
public static string cacheAppversions => BaseCacheHelpRedis.GetCache<string>(Appversions, delegate
|
|||
|
|
{
|
|||
|
|
return DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
|
|||
|
|
});
|
|||
|
|
private static List<T> GetCachesys<T>(T model, string strkey, string SQL = "")
|
|||
|
|
{
|
|||
|
|
return BaseCacheHelpRedis.GetCache(strkey, delegate
|
|||
|
|
{
|
|||
|
|
List<T> result = new List<T>();
|
|||
|
|
|
|||
|
|
string sql = string.Empty;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var tablename = (model.GetType().Name == "UserAutho" ? "UserAuthoes" : model.GetType().Name == "OrgUser" ? "OrgUsers" : model.GetType().Name);
|
|||
|
|
//模型复数 未设置 现在修改查询
|
|||
|
|
sql = "select * from " + tablename;
|
|||
|
|
if (!string.IsNullOrEmpty(SQL))
|
|||
|
|
{
|
|||
|
|
sql = SQL;
|
|||
|
|
}
|
|||
|
|
//authorityDB.Database.CommandTimeout = int.MaxValue;
|
|||
|
|
//SqlSugarBase.Db.Ado.CommandTimeOut = int.MaxValue;
|
|||
|
|
result = SqlSugarBase.Db.Ado.SqlQuery<T>(sql).ToList();
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
LogHelp.WriteExceptionLog(ex, sql);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return result;
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
public static void Removesys(syskey? syskeys)
|
|||
|
|
{
|
|||
|
|
if (syskeys != null)
|
|||
|
|
{
|
|||
|
|
BaseCacheHelpRedis.ClearCache("autho_" + syskeys);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
//for (int i = 0; i <= (int)syskey.sysView_AppAuthoListKey; i++)
|
|||
|
|
//{
|
|||
|
|
// syskeys = (syskey)i;
|
|||
|
|
// BaseCacheHelpRedis.ClearCache("autho_" + syskeys);
|
|||
|
|
//}
|
|||
|
|
RemovesysEnumAll();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private static void RemovesysEnumAll()
|
|||
|
|
{
|
|||
|
|
//取到所有枚举变量的字符串,并加前缀。
|
|||
|
|
List<string> keysList = new List<string>();
|
|||
|
|
syskey syskeys;
|
|||
|
|
for (int i = 0; i <= (int)syskey.sysView_AppAuthoListKey; i++)
|
|||
|
|
{
|
|||
|
|
syskeys = (syskey)i;
|
|||
|
|
keysList.Add("autho_" + syskeys);
|
|||
|
|
}
|
|||
|
|
BaseCacheHelpRedis.ClearCacheList(keysList);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static void Removesyss(syskey? syskeys)
|
|||
|
|
{
|
|||
|
|
if (syskeys != null)
|
|||
|
|
{
|
|||
|
|
BaseCacheHelpRedis.ClearCache("authority_" + syskeys);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i <= (int)syskey.sysView_AppAuthoListKey; i++)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
syskeys = (syskey)i;
|
|||
|
|
BaseCacheHelpRedis.ClearCache("authority_autho_" + syskeys.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public static void Updatesys(syskey? syskeys)
|
|||
|
|
{
|
|||
|
|
//HoteldGroupsinfo = null;
|
|||
|
|
Removesys(null);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|