TG.WXCRM.V4/WebHelper/RedisFactory/RedisFactory.cs

328 lines
12 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.Common;
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;
private IReadOrWriteFromRedis redisBl = new ReadOrWriteFromRedis_BL();
private IORD_MEMO_Q ord_memo_Q = new ORD_MEMO_BL();
private IRES_CUSTOMER_Q customer_Q = new RES_CUSTOMER_BL();
private ISOFT_USER_Q softUserQ = new SOFT_USER_BL();
private IRES_CUSTOMERUSER_Q customeruser_q = new RES_CUSTOMERUSER_BL();
private IRES_CUSTOMERDETAIL_Q customerdetail_Q = new RES_CUSTOMERDETAIL_BL();
private CACHE_BL cache_BL = new CACHE_BL();
public List<ORD_MemoQuery> LoadMemo(string customerid, string isValid)
{
List<ORD_MemoQuery> list = new List<ORD_MemoQuery>();
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<RES_CUSTOMER> GetList_Rescustomer(string[] resids, string customerid)
{
List<RES_CUSTOMER> list = new List<RES_CUSTOMER>();
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)
{
PhoneLogModel phoneLogModel = new PhoneLogModel
{
Method = System.Reflection.MethodBase.GetCurrentMethod().Name,
userid = 0
};
resCustomer.LASTNUM3 = resResourcemobile.GetNumberByResId(resCustomer.RESID, phoneLogModel);
}
}
}
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 redis
}
}
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 redis
}
}
public List<SOFT_USER> GetList_Rescustomeruser(string customerid, string[] resids)
{
List<SOFT_USER> list = new List<SOFT_USER>();
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<RES_CUSTOMERUSER> GetList_Rescustomeruser_Username(string username)
{
List<RES_CUSTOMERUSER> list = new List<RES_CUSTOMERUSER>();
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<SOFT_USER> GetList_SoftUser(string[] usernames)
{
List<SOFT_USER> list = new List<SOFT_USER>();
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 redis
}
}
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 redis
}
}
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);
}
}
}