123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- 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<PageUpdateInfo>(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<PageUpdateInfo> GetPageList(string Kind = "default")
- {
- string key = "PageUpdateInfo:" + Kind;
- List<PageUpdateInfo> list = new List<PageUpdateInfo>();
- if (RedisDbconn.Instance.Exists(key))
- {
- list = RedisDbconn.Instance.GetList<PageUpdateInfo>(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<AppBottomNavs> GetAppNavList(string Kind = "default")
- {
- string key = "AppBottomNavs:" + Kind;
- List<AppBottomNavs> list = new List<AppBottomNavs>();
- if (RedisDbconn.Instance.Exists(key))
- {
- list = RedisDbconn.Instance.GetList<AppBottomNavs>(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<AppVersion> GetAppVersionList(string Kind = "default")
- {
- string key = "AppVersion:" + Kind;
- List<AppVersion> list = new List<AppVersion>();
- if (RedisDbconn.Instance.Exists(key))
- {
- list = RedisDbconn.Instance.GetList<AppVersion>(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<FileUpdateInfo> GetFileList(string Kind = "default")
- {
- string key = "FileUpdateInfo:" + Kind;
- List<FileUpdateInfo> list = new List<FileUpdateInfo>();
- if (RedisDbconn.Instance.Exists(key))
- {
- list = RedisDbconn.Instance.GetList<FileUpdateInfo>(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
- }
- }
|