using System; using System.Collections.Generic; using System.Linq; using WX.CRM.BLL.Ord; using WX.CRM.BLL.RedisBL; using WX.CRM.BLL.Res; using WX.CRM.BLL.Soft; using WX.CRM.BLL.Util; using WX.CRM.IBLL.Ord; using WX.CRM.IBLL.RedisBL; using WX.CRM.IBLL.Res; using WX.CRM.IBLL.Soft; using WX.CRM.Model.Entity; using WX.CRM.Model.EntitySync; using WX.CRM.Model.QueryMap; namespace WX.CRM.WebHelper.RedisFactory { public class RedisFactory { //private bool isfromRedis = new CACHE_BL().GetValue_Parameter("Sys_IsFromRedis") == "true" ? true : false;//默认为true:从redis库查询数据 private bool isfromRedis = false; IReadOrWriteFromRedis redisBl = new ReadOrWriteFromRedis_BL(); IORD_MEMO_Q ord_memo_Q = new ORD_MEMO_BL(); IRES_CUSTOMER_Q customer_Q = new RES_CUSTOMER_BL(); ISOFT_USER_Q softUserQ = new SOFT_USER_BL(); IRES_CUSTOMERUSER_Q customeruser_q = new RES_CUSTOMERUSER_BL(); IRES_CUSTOMERDETAIL_Q customerdetail_Q = new RES_CUSTOMERDETAIL_BL(); CACHE_BL cache_BL = new CACHE_BL(); public List LoadMemo(string customerid, string isValid) { List list = new List(); if (!isfromRedis) { list = ord_memo_Q.GetAllMemoListByResId(int.MaxValue, customerid, isValid); return list; } list = redisBl.GetAll_CacheOrdMemo(customerid, out isfromRedis); if (!isfromRedis) list = ord_memo_Q.GetAllMemoListByResId(int.MaxValue, customerid, isValid); return list; } public RES_CUSTOMER GetInfo_Rescustomer(string customerid) { RES_CUSTOMER model = new RES_CUSTOMER(); if (!isfromRedis) { model = customer_Q.getResCustomerByResId(customerid); return model; } model = redisBl.GetInfo_Res_Customer(customerid, out isfromRedis); if (!isfromRedis) model = customer_Q.getResCustomerByResId(customerid); return model; } public List GetList_Rescustomer(string[] resids, string customerid) { List list = new List(); RES_RESOURCEMOBILE_BL resResourcemobile = new RES_RESOURCEMOBILE_BL(); var flag = false; var s = cache_BL.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Sys_ShowMobileStartDate); DateTime dt = DateTime.Now; if (!string.IsNullOrWhiteSpace(s) && s != "0") { flag = DateTime.TryParse(s, out dt); } if (!isfromRedis) { list = customer_Q.GetList_CustomerByResid(customerid); if (flag) { foreach (var resCustomer in list) { if (resCustomer.CTIME > dt) { resCustomer.LASTNUM3 = resResourcemobile.GetNumberByResId(resCustomer.RESID); } } } return list; } //list = redisBl.GetList_Res_Customer(resids, out isfromRedis); //if (!isfromRedis) // list = customer_Q.GetList_CustomerByResid(customerid); //if (flag) //{ // foreach (var resCustomer in list) // { // if (resCustomer.CTIME > dt) // { // resCustomer.LASTNUM3 = resResourcemobile.GetNumberByResId(resCustomer.RESID); // } // } //} return list; } public void Add_ResCustomer(RES_CUSTOMER entity) { redisBl.AddRedis_Res_Customer(entity, out isfromRedis); if (!isfromRedis) { #region redis 添加到待打包表 REDIS_CACHE_SSODATASYNC redisMoel1 = new REDIS_CACHE_SSODATASYNC(); redisMoel1.TABLETYPE = "res_customer"; redisMoel1.KEYS = entity.RESID; redisMoel1.OPTYPE = "A"; redisMoel1.TIME = DateTime.Now; redisMoel1.LASTSYNCTIME = DateTime.Now; redisMoel1.ERRNUM = 0; redisMoel1.ERRMSG = ""; new REDIS_CACHE_SSODATASYNC_BL().Create_RedisCacheSSODataSYNC(redisMoel1); #endregion } } public RES_CUSTOMERDETAIL GetInfo_Rescustomerdetail(string resid) { RES_CUSTOMERDETAIL model = new RES_CUSTOMERDETAIL(); if (!isfromRedis) { model = customerdetail_Q.GetModel_RES_CUSTOMERDETAIL(resid); return model; } model = redisBl.GetInfo_Res_CustomerDetail(resid, out isfromRedis); if (!isfromRedis) model = customerdetail_Q.GetModel_RES_CUSTOMERDETAIL(resid); return model; } public void Add_ResCustomerdetail(RES_CUSTOMERDETAIL entity) { redisBl.AddRedis_Res_CustomerDetail(entity, out isfromRedis); if (!isfromRedis) { #region redis 添加到待打包表 REDIS_CACHE_SSODATASYNC redisMoel1 = new REDIS_CACHE_SSODATASYNC(); redisMoel1.TABLETYPE = "res_customerdetail"; redisMoel1.KEYS = entity.RESID; redisMoel1.OPTYPE = "A"; redisMoel1.TIME = DateTime.Now; redisMoel1.LASTSYNCTIME = DateTime.Now; redisMoel1.ERRNUM = 0; redisMoel1.ERRMSG = ""; new REDIS_CACHE_SSODATASYNC_BL().Create_RedisCacheSSODataSYNC(redisMoel1); #endregion } } public List GetList_Rescustomeruser(string customerid, string[] resids) { List list = new List(); if (!isfromRedis) { list = customeruser_q.GetListByCustomerId(customerid); return list; } list = redisBl.GetAll_Res_Customeruser(resids, out isfromRedis); if (!isfromRedis) list = customeruser_q.GetListByCustomerId(customerid); return list; } public List GetList_Rescustomeruser_Username(string username) { List list = new List(); string resid = ""; SOFT_USER softuser = GetInfo_Softuser(username); if (softuser != null && !string.IsNullOrWhiteSpace(softuser.RESID)) { resid = softuser.RESID; list.Add(new RES_CUSTOMERUSER() { PKID = 0, RESID = softuser.RESID, USERNAME = username, CTIME = DateTime.Now }); } if (!isfromRedis) { list.AddRange(customeruser_q.GetListByUserName(username).Where(m => m.RESID != resid)); return list; } list.AddRange(redisBl.GetAll_Res_Customeruser_Username(new string[] { username }, out isfromRedis).Where(m => m.RESID != resid)); if (!isfromRedis) list.AddRange(customeruser_q.GetListByUserName(username).Where(m => m.RESID != resid)); return list; } public SOFT_USER GetInfo_Softuser(string username) { SOFT_USER model = new SOFT_USER(); if (!isfromRedis) { model = softUserQ.GetUser_userName(username); return model; } model = redisBl.GetInfo_Soft_User(username, out isfromRedis); if (!isfromRedis) model = softUserQ.GetUser_userName(username); return model; } public List GetList_SoftUser(string[] usernames) { List list = new List(); if (!isfromRedis) { list = softUserQ.GetUserList_userName(usernames); return list; } list = redisBl.GetList_Soft_User(usernames, out isfromRedis); if (!isfromRedis) list = softUserQ.GetUserList_userName(usernames); return list; } //public void Add_Gjscustomer(GJS_CUSTOMER entity) //{ // redisBl.AddRedis_Gjs_Customer(entity, out isfromRedis); // if (!isfromRedis) // { // #region redis 添加到待打包表 // REDIS_CACHE_SSODATASYNC redisMoel1 = new REDIS_CACHE_SSODATASYNC(); // redisMoel1.TABLETYPE = "gjs_customer"; // redisMoel1.KEYS = entity.TRADECODE; // redisMoel1.OPTYPE = "A"; // redisMoel1.TIME = DateTime.Now; // redisMoel1.LASTSYNCTIME = DateTime.Now; // redisMoel1.ERRNUM = 0; // redisMoel1.ERRMSG = ""; // new REDIS_CACHE_SSODATASYNC_BL().Create_RedisCacheSSODataSYNC(redisMoel1); // #endregion // } //} //public void Add_Gjscustomerboce(GJS_CUSTOMERBOCE entity) //{ // redisBl.AddRedis_Gjs_Customerboce(entity, out isfromRedis); // if (!isfromRedis) // { // #region redis 添加到待打包表 // REDIS_CACHE_SSODATASYNC redisMoel1 = new REDIS_CACHE_SSODATASYNC(); // redisMoel1.TABLETYPE = "gjs_customerboce"; // redisMoel1.KEYS = entity.TRADECODE; // redisMoel1.OPTYPE = "A"; // redisMoel1.TIME = DateTime.Now; // redisMoel1.LASTSYNCTIME = DateTime.Now; // redisMoel1.ERRNUM = 0; // redisMoel1.ERRMSG = ""; // new REDIS_CACHE_SSODATASYNC_BL().Create_RedisCacheSSODataSYNC(redisMoel1); // #endregion // } //} public void Delete_Cacheordmemo(decimal memoid) { redisBl.DeleteRedis_CacheOrdMemo(memoid, out isfromRedis); if (!isfromRedis) { #region redis 添加到待打包表 REDIS_CACHE_SSODATASYNC redisMoel1 = new REDIS_CACHE_SSODATASYNC(); redisMoel1.TABLETYPE = "cache_ord_memo"; redisMoel1.KEYS = memoid.ToString(); redisMoel1.OPTYPE = "D"; redisMoel1.TIME = DateTime.Now; redisMoel1.LASTSYNCTIME = DateTime.Now; redisMoel1.ERRNUM = 0; redisMoel1.ERRMSG = ""; new REDIS_CACHE_SSODATASYNC_BL().Create_RedisCacheSSODataSYNC(redisMoel1); #endregion } } public void Delete_Resid_memoid(decimal memoid, string resid) { redisBl.DeleteRedis_Resid_Memoid(resid, memoid, out isfromRedis); if (!isfromRedis) { #region redis 添加到待打包表 REDIS_CACHE_SSODATASYNC redisMoel1 = new REDIS_CACHE_SSODATASYNC(); redisMoel1.TABLETYPE = "resid_memoid_redis"; redisMoel1.KEYS = memoid.ToString(); redisMoel1.OPTYPE = "D"; redisMoel1.TIME = DateTime.Now; redisMoel1.LASTSYNCTIME = DateTime.Now; redisMoel1.ERRNUM = 0; redisMoel1.ERRMSG = ""; new REDIS_CACHE_SSODATASYNC_BL().Create_RedisCacheSSODataSYNC(redisMoel1); #endregion } } public bool AddRedis_Res_CallOutCustomer(RES_CALLOUTCUSTOMER entity) { if (!isfromRedis) return false; return redisBl.AddRedis_Res_CallOutCustomer(entity); } public bool RemoveRedis_Res_CallOutCustomer(string key) { if (!isfromRedis) return false; return redisBl.RemoveRedis_Res_CallOutCustomer(key); } } }