PosMachinesDbconn.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.Models.Main1;
  5. namespace MySystem
  6. {
  7. public class PosMachinesDbconn
  8. {
  9. public readonly static PosMachinesDbconn Instance = new PosMachinesDbconn();
  10. #region 获取单个字段
  11. public PosMachines Get(int Id)
  12. {
  13. // string key = "PosMachines:" + Id;
  14. // if (RedisDbconn.Instance.Exists(key))
  15. // {
  16. // PosMachines obj = RedisDbconn.Instance.Get<PosMachines>(key);
  17. // if (obj != null)
  18. // {
  19. // return obj;
  20. // }
  21. // }
  22. WebCMSEntities db = new WebCMSEntities();
  23. PosMachines order = db.PosMachines.FirstOrDefault(m => m.Id == Id);
  24. if (order != null)
  25. {
  26. // RedisDbconn.Instance.Set(key, order);
  27. // RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  28. }
  29. db.Dispose();
  30. return order;
  31. }
  32. public PosMachines Get(string PosSn)
  33. {
  34. string key = "PosMachines:" + PosSn;
  35. if (RedisDbconn.Instance.Exists(key))
  36. {
  37. PosMachines obj = RedisDbconn.Instance.Get<PosMachines>(key);
  38. if (obj != null)
  39. {
  40. return obj;
  41. }
  42. }
  43. WebCMSEntities db = new WebCMSEntities();
  44. PosMachines order = db.PosMachines.FirstOrDefault(m => m.PosSn == PosSn);
  45. if (order != null)
  46. {
  47. RedisDbconn.Instance.Set(key, order);
  48. RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  49. }
  50. return order;
  51. }
  52. #endregion
  53. #region 获取列表
  54. public List<int> GetList(int MerchantId, int pageNum = 1, int pageSize = 10)
  55. {
  56. // string key = "PosMachineList:" + MerchantId;
  57. // List<int> list = new List<int>();
  58. // if (RedisDbconn.Instance.Exists(key))
  59. // {
  60. // list = RedisDbconn.Instance.GetList<int>(key, pageNum, pageSize);
  61. // if (list.Count > 0)
  62. // {
  63. // return list;
  64. // }
  65. // }
  66. int skip = (pageNum - 1) * pageSize;
  67. WebCMSEntities db = new WebCMSEntities();
  68. List<int> newlist = new List<int>();
  69. var mysqllist = db.PosMachines.Select(m => new { m.Id, m.BindMerchantId, m.DeviceKind }).Where(m => m.BindMerchantId == MerchantId && m.DeviceKind == "2").OrderByDescending(m => m.Id).Skip(skip).Take(pageSize).ToList();
  70. if (mysqllist.Count > 0)
  71. {
  72. foreach (var sub in mysqllist)
  73. {
  74. newlist.Add(sub.Id);
  75. }
  76. }
  77. db.Dispose();
  78. return newlist;
  79. }
  80. #endregion
  81. }
  82. }