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 gh => CacheHelp.cacheHoteldGroups.Where(x => x.ParentId == 1).ToList(); public static List HoteldGroupsinfo { get { List HoteldGroupsinfos = new List(); 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 cacheView_UserInfo => GetCachesys(new View_UserInfo(), sysUserInfoListKey); public static List cachesysMACLogs => GetCachesys(new View_MAClog(), sysMACLogs); public static List cacheSysErrorInfo => GetCachesys(new ErrorInfo(), sysErrorInfoListKey); public static List cacheSysApp => GetCachesys(new ApplicationDomain(), sysAppsListKey); public static List cacheSysGsInfo => GetCachesys(new GsInfo(), sysGsInfoListKey, "exec Findgsall"); public static List cacheSysAutho => GetCachesys(new Authority(), sysAuthorityLisKey); public static List cacheSysAuthoStatusType => GetCachesys(new AuthoStatusType(), sysAuthoStatusTypeLisKey); public static List cacheSysOrganization => GetCachesys(new Organization(), sysOrganizationLisKey); public static List cacheSysOrgAuthority => GetCachesys(new OrgAuthority(), sysOrgAuthorityLisKey); public static List cacheSysOrgUser => GetCachesys(new OrgUsers(), sysOrgUserLisKey); public static ISugarQueryable cacheSysUserAutho => SqlSugarBase.Db.Queryable(); //GetCachesys(new UserAuthoes(), sysUserAuthoLisKey); //从视图View_UserInfo读取信息,包括人员信息和部分所属组织信息。 public static List cacheSysUserInfo => GetCachesys(new View_UserInfo(), sysUserInfoListKey); public static List cacheSysAppAutho => GetCachesys(new AppAutho(), sysAppAuthoListKey); public static List cacheView_UOA => GetCachesys(new View_UOA(), sysView_UOAListKey); /// /// GetCachesys(new View_UA(), sysView_UAListKey); /// public static List cacheView_AppAutho => GetCachesys(new View_AppAutho(), sysView_AppAuthoListKey); public static List cacheHotels => GetCachesys(new Hotels(), sysHotelsListKey, "select * FROM Hotels ORDER BY CreateTime DESC"); public static List cacheHosts => GetCachesys(new Hosts(), sysHostsListKey); public static List cacheHoteldGroups => GetCachesys(new HotelGroups(), sysHoteldGroupsListKey); public static int cacheDbLogs => GetCachesys(new int(), sysDbLogListKey, "select count(*) FROM DbLog")[0]; public static string cacheAppversions => BaseCacheHelpRedis.GetCache(Appversions, delegate { return DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"); }); private static List GetCachesys(T model, string strkey, string SQL = "") { return BaseCacheHelpRedis.GetCache(strkey, delegate { List result = new List(); 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(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 keysList = new List(); 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); } } }