UserCashRecordDbconn.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.MainModels;
  5. namespace MySystem
  6. {
  7. public class UserCashRecordDbconn
  8. {
  9. public readonly static UserCashRecordDbconn Instance = new UserCashRecordDbconn();
  10. #region 获取单个字段
  11. public UserCashRecord Get(int Id)
  12. {
  13. // string key = "UserCashRecord:" + Id;
  14. // if (RedisDbconn.Instance.Exists(key))
  15. // {
  16. // UserCashRecord obj = RedisDbconn.Instance.Get<UserCashRecord>(key);
  17. // if (obj != null)
  18. // {
  19. // return obj;
  20. // }
  21. // }
  22. WebCMSEntities db = new WebCMSEntities();
  23. UserCashRecord orderPro = db.UserCashRecord.FirstOrDefault(m => m.Id == Id);
  24. if (orderPro != null)
  25. {
  26. // RedisDbconn.Instance.Set(key, orderPro);
  27. // RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  28. }
  29. return orderPro;
  30. }
  31. #endregion
  32. #region 获取列表
  33. public List<int> GetList(int UserId, int pageNum = 1, int pageSize = 10)
  34. {
  35. string key = "UserCashRecordList:" + UserId;
  36. List<int> list = new List<int>();
  37. // if (RedisDbconn.Instance.Exists(key))
  38. // {
  39. // list = RedisDbconn.Instance.GetList<int>(key, pageNum, pageSize);
  40. // if (list.Count > 0)
  41. // {
  42. // return list;
  43. // }
  44. // }
  45. WebCMSEntities db = new WebCMSEntities();
  46. var mysqllist = db.UserCashRecord.Select(m => new { m.Id, m.UserId }).Where(m => m.UserId == UserId).OrderByDescending(m => m.Id).ToList();
  47. if (mysqllist.Count > 0)
  48. {
  49. RedisDbconn.Instance.Clear(key);
  50. foreach (var sub in mysqllist)
  51. {
  52. list.Add(sub.Id);
  53. RedisDbconn.Instance.AddRightList(key, sub.Id);
  54. }
  55. }
  56. db.Dispose();
  57. return list;
  58. }
  59. #endregion
  60. }
  61. }