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