MysqlDbconn.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using System.Linq;
  5. using MySystem.BsModels;
  6. namespace MySystem
  7. {
  8. public class MysqlDbconn
  9. {
  10. public readonly static MysqlDbconn Instance = new MysqlDbconn();
  11. #region 获取单个字段
  12. public PageUpdateInfo GetPage(string pageName, string Kind = "default")
  13. {
  14. string key = "PageUpdateInfo:" + Kind + ":" + pageName;
  15. string FileName = pageName + ".html";
  16. if (RedisDbconn.Instance.Exists(key))
  17. {
  18. PageUpdateInfo obj = RedisDbconn.Instance.Get<PageUpdateInfo>(key);
  19. if (obj != null)
  20. {
  21. return obj;
  22. }
  23. }
  24. WebCMSEntities db = new WebCMSEntities();
  25. PageUpdateInfo page = db.PageUpdateInfo.FirstOrDefault(m => m.ModulePath == FileName && m.SeoKeyword == Kind);
  26. if (page != null)
  27. {
  28. RedisDbconn.Instance.Set(key, page);
  29. }
  30. return page;
  31. }
  32. #endregion
  33. #region 获取列表
  34. public List<PageUpdateInfo> GetPageList(string Kind = "default")
  35. {
  36. string key = "PageUpdateInfo:" + Kind;
  37. List<PageUpdateInfo> list = new List<PageUpdateInfo>();
  38. if (RedisDbconn.Instance.Exists(key))
  39. {
  40. list = RedisDbconn.Instance.GetList<PageUpdateInfo>(key, 1, 10000);
  41. if (list.Count > 0)
  42. {
  43. return list;
  44. }
  45. }
  46. WebCMSEntities db = new WebCMSEntities();
  47. var mysqllist = db.PageUpdateInfo.Where(m => m.SeoKeyword == Kind).ToList();
  48. RedisDbconn.Instance.Clear(key);
  49. RedisDbconn.Instance.AddList(key, mysqllist.ToArray());
  50. db.Dispose();
  51. return list;
  52. }
  53. public List<AppBottomNavs> GetAppNavList(string Kind = "default")
  54. {
  55. string key = "AppBottomNavs:" + Kind;
  56. List<AppBottomNavs> list = new List<AppBottomNavs>();
  57. if (RedisDbconn.Instance.Exists(key))
  58. {
  59. list = RedisDbconn.Instance.GetList<AppBottomNavs>(key, 1, 1000);
  60. if (list.Count > 0)
  61. {
  62. return list;
  63. }
  64. }
  65. WebCMSEntities db = new WebCMSEntities();
  66. int test = 0;
  67. if (Kind.EndsWith("test"))
  68. {
  69. test = 1;
  70. }
  71. var mysqllist = db.AppBottomNavs.Where(m => m.SeoKeyword == Kind && m.QueryCount == test).OrderByDescending(m => m.Sort).ThenBy(m => m.Id).ToList();
  72. RedisDbconn.Instance.Clear(key);
  73. RedisDbconn.Instance.AddList(key, mysqllist.ToArray());
  74. db.Dispose();
  75. return mysqllist;
  76. }
  77. public List<AppVersion> GetAppVersionList(string Kind = "default")
  78. {
  79. string key = "AppVersion:" + Kind;
  80. List<AppVersion> list = new List<AppVersion>();
  81. if (RedisDbconn.Instance.Exists(key))
  82. {
  83. list = RedisDbconn.Instance.GetList<AppVersion>(key, 1, 10000);
  84. if (list.Count > 0)
  85. {
  86. return list;
  87. }
  88. }
  89. WebCMSEntities db = new WebCMSEntities();
  90. var mysqllist = db.AppVersion.Where(m => m.SeoKeyword == Kind).ToList();
  91. RedisDbconn.Instance.Clear(key);
  92. RedisDbconn.Instance.AddList(key, mysqllist.ToArray());
  93. db.Dispose();
  94. return list;
  95. }
  96. public List<FileUpdateInfo> GetFileList(string Kind = "default")
  97. {
  98. string key = "FileUpdateInfo:" + Kind;
  99. List<FileUpdateInfo> list = new List<FileUpdateInfo>();
  100. if (RedisDbconn.Instance.Exists(key))
  101. {
  102. list = RedisDbconn.Instance.GetList<FileUpdateInfo>(key, 1, 100000);
  103. if (list.Count > 0)
  104. {
  105. return list;
  106. }
  107. }
  108. WebCMSEntities db = new WebCMSEntities();
  109. var mysqllist = db.FileUpdateInfo.Where(m => m.SeoKeyword == Kind).ToList();
  110. RedisDbconn.Instance.Clear(key);
  111. RedisDbconn.Instance.AddList(key, mysqllist.ToArray());
  112. db.Dispose();
  113. return list;
  114. }
  115. #endregion
  116. }
  117. }