using System; using System.Collections.Generic; using System.Linq; using MySystem.MainModels; namespace MySystem { public class UserCashRecordDbconn { public readonly static UserCashRecordDbconn Instance = new UserCashRecordDbconn(); #region 获取单个字段 public UserCashRecord Get(int Id) { // string key = "UserCashRecord:" + Id; // if (RedisDbconn.Instance.Exists(key)) // { // UserCashRecord obj = RedisDbconn.Instance.Get(key); // if (obj != null) // { // return obj; // } // } WebCMSEntities db = new WebCMSEntities(); UserCashRecord orderPro = db.UserCashRecord.FirstOrDefault(m => m.Id == Id); if (orderPro != null) { // RedisDbconn.Instance.Set(key, orderPro); // RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400)); } return orderPro; } #endregion #region 获取列表 public List GetList(int UserId, int pageNum = 1, int pageSize = 10) { string key = "UserCashRecordList:" + UserId; List list = new List(); // if (RedisDbconn.Instance.Exists(key)) // { // list = RedisDbconn.Instance.GetList(key, pageNum, pageSize); // if (list.Count > 0) // { // return list; // } // } WebCMSEntities db = new WebCMSEntities(); var mysqllist = db.UserCashRecord.Select(m => new { m.Id, m.UserId }).Where(m => m.UserId == UserId).OrderByDescending(m => m.Id).ToList(); if (mysqllist.Count > 0) { RedisDbconn.Instance.Clear(key); foreach (var sub in mysqllist) { list.Add(sub.Id); RedisDbconn.Instance.AddRightList(key, sub.Id); } } db.Dispose(); return list; } #endregion } }