using System; using System.Collections.Generic; using Library; using System.Linq; using MySystem.BsModels; namespace MySystem { public class MysqlDbconn { public readonly static MysqlDbconn Instance = new MysqlDbconn(); #region 获取单个字段 public PageUpdateInfo GetPage(string pageName, string Kind = "default") { string key = "PageUpdateInfo:" + Kind + ":" + pageName; string FileName = pageName + ".html"; if (RedisDbconn.Instance.Exists(key)) { PageUpdateInfo obj = RedisDbconn.Instance.Get(key); if (obj != null) { return obj; } } WebCMSEntities db = new WebCMSEntities(); PageUpdateInfo page = db.PageUpdateInfo.FirstOrDefault(m => m.ModulePath == FileName && m.SeoKeyword == Kind); if (page != null) { RedisDbconn.Instance.Set(key, page); } return page; } #endregion #region 获取列表 public List GetPageList(string Kind = "default") { string key = "PageUpdateInfo:" + Kind; List list = new List(); if (RedisDbconn.Instance.Exists(key)) { list = RedisDbconn.Instance.GetList(key, 1, 10000); if (list.Count > 0) { return list; } } WebCMSEntities db = new WebCMSEntities(); var mysqllist = db.PageUpdateInfo.Where(m => m.SeoKeyword == Kind).ToList(); RedisDbconn.Instance.Clear(key); RedisDbconn.Instance.AddList(key, mysqllist.ToArray()); db.Dispose(); return list; } public List GetAppNavList(string Kind = "default") { string key = "AppBottomNavs:" + Kind; List list = new List(); if (RedisDbconn.Instance.Exists(key)) { list = RedisDbconn.Instance.GetList(key, 1, 1000); if (list.Count > 0) { return list; } } WebCMSEntities db = new WebCMSEntities(); int test = 0; if (Kind.EndsWith("test")) { test = 1; } var mysqllist = db.AppBottomNavs.Where(m => m.SeoKeyword == Kind && m.QueryCount == test).OrderByDescending(m => m.Sort).ThenBy(m => m.Id).ToList(); RedisDbconn.Instance.Clear(key); RedisDbconn.Instance.AddList(key, mysqllist.ToArray()); db.Dispose(); return mysqllist; } public List GetAppVersionList(string Kind = "default") { string key = "AppVersion:" + Kind; List list = new List(); if (RedisDbconn.Instance.Exists(key)) { list = RedisDbconn.Instance.GetList(key, 1, 10000); if (list.Count > 0) { return list; } } WebCMSEntities db = new WebCMSEntities(); var mysqllist = db.AppVersion.Where(m => m.SeoKeyword == Kind).ToList(); RedisDbconn.Instance.Clear(key); RedisDbconn.Instance.AddList(key, mysqllist.ToArray()); db.Dispose(); return list; } public List GetFileList(string Kind = "default") { string key = "FileUpdateInfo:" + Kind; List list = new List(); if (RedisDbconn.Instance.Exists(key)) { list = RedisDbconn.Instance.GetList(key, 1, 100000); if (list.Count > 0) { return list; } } WebCMSEntities db = new WebCMSEntities(); var mysqllist = db.FileUpdateInfo.Where(m => m.SeoKeyword == Kind).ToList(); RedisDbconn.Instance.Clear(key); RedisDbconn.Instance.AddList(key, mysqllist.ToArray()); db.Dispose(); return list; } #endregion } }