using CRM.Core.Model.Entity;
using CRM.Core.Model.Enum;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using WX.CRM.Common;
using WX.CRM.Common.StockHelper;
namespace CRM.Core.BLL.Util
{
///
/// 缓存BL
///
public class CACHE_BL
{
#region 根据Model.Enum.Parameter 获取参数value
public string GetValue_Parameter(string key)
{
string cacheKey = "cache_Parameter_getList";
List modelist;
if (CacheHelper.Exists(cacheKey))
modelist = CacheHelper.Get>(cacheKey);
else
{
using (var db = new zxdContext())
{
modelist = db.BAS_PARAMETER.ToList();
CacheHelper.Set(cacheKey, modelist);
}
}
var model = modelist.FirstOrDefault(m => m.PARAKEY == key);
if (model == null)
return "";
return model.PARAVALUE;
}
///
/// 根据Model.Enum.Parameter 获取参数value
///
///
public string GetValue_Parameter(CRM.Core.Model.Enum.Parameter key)
{
string cacheKey = "cache_Parameter_getList";
List modelist;
if (CacheHelper.Exists(cacheKey))
modelist = CacheHelper.Get>(cacheKey);
else
{
using (CRM.Core.Model.Entity.zxdContext db = new CRM.Core.Model.Entity.zxdContext())
{
modelist = db.BAS_PARAMETER.ToList();
CacheHelper.Set(cacheKey, modelist);
}
}
string sss = key.ToString();
CRM.Core.Model.Entity.BAS_PARAMETER sysConfig = modelist.FirstOrDefault(m => m.PARAKEY == "Sys_Environment_DeptCode");
CRM.Core.Model.Entity.BAS_PARAMETER model = modelist.FirstOrDefault(m => m.PARAKEY == key.ToString() && m.DEPTCDOE == sysConfig.PARAVALUE);
if (model == null)
model = modelist.FirstOrDefault(m => m.PARAKEY == key.ToString() && (m.DEPTCDOE == "" || m.DEPTCDOE == null));
if (model == null)
return "";
return model.PARAVALUE;
}
public List GetDeptments()
{
var webapi = GetValue_Parameter(Parameter.Zxd_CoreApiUrl);
var url = $"{webapi}api/deptment/Depts";
var result = Utility.GetData(url, "", Encoding.UTF8);
var response = JsonConvert.DeserializeObject>>(result);
if (response.code == 0 && response.data != null)
{
return response.data.Where(x => x.SortNo > 0).OrderBy(x => x.SortNo).ToList();
}
return new List();
}
///
/// 根据系统参数分类获取系统参数列表
///
/// 系统参数分类
///
public List GetList_Parameter(CRM.Core.Model.Enum.ParameterGroup type)
{
string cacheKey = "cache_Parameter_getList";
List modelist;
if (CacheHelper.Exists(cacheKey))
modelist = CacheHelper.Get>(cacheKey);
else
{
using (CRM.Core.Model.Entity.zxdContext db = new CRM.Core.Model.Entity.zxdContext())
{
modelist = db.BAS_PARAMETER.ToList();
CacheHelper.Set(cacheKey, modelist);
}
}
List list = modelist.Where(m => m.GROUPID.Trim() == type.ToString().Trim()).ToList();
return list;
}
#endregion 根据Model.Enum.Parameter 获取参数value
#region 获取内部公司列表 cache_Company_getList
///
/// 获取公司列表
///
///
public List GetList_innerCompany()
{
string cacheKey = "cache_Company_getList";
if (CacheHelper.Exists(cacheKey))
return CacheHelper.Get>(cacheKey);
using (var db = new zxdContext())
{
List list = db.BAS_COMPANY.ToList();
CacheHelper.Set(cacheKey, list);
return list;
}
}
public List GetCompanyCode()
{
string cacheKey = "cache_Company_Code";
if (CacheHelper.Exists(cacheKey))
return CacheHelper.Get>(cacheKey);
using (var db = new zxdContext())
{
var list = db.Bas_CompanyChannel.ToList();
CacheHelper.Set(cacheKey, list);
return list;
}
}
public List GetCompanyVirtual()
{
var cacheKey = "cache_comapny_virtual";
if (CacheHelper.Exists(cacheKey))
return CacheHelper.Get>(cacheKey);
using (var db = new zxdContext())
{
var list = db.Bas_CompanyVirtual.Where(p => p.IsDelete == 0).OrderBy(p => p.Sort).ToList();
CacheHelper.Set(cacheKey, list);
return list;
}
}
public List GetCompanyWework()
{
var cacheKey = "cache_comapny_wework";
if (CacheHelper.Exists(cacheKey))
return CacheHelper.Get>(cacheKey);
using (var db = new zxdContext())
{
var list = db.Bas_CompanyWework.ToList();
CacheHelper.Set(cacheKey, list);
return list;
}
}
public List> GetDeptDownList()
{
var cacheKey = "cache_deptDownList";
if (CacheHelper.Exists(cacheKey))
return CacheHelper.Get>>(cacheKey);
var companyList = GetCompanyVirtual();
var channelList = companyList.Where(n => !string.IsNullOrWhiteSpace(n.Channel)).Select(n => Convert.ToInt32(n.Channel.Split(',').FirstOrDefault())).ToList();
var depts = ConvertChannelName(channelList);
var allChannel = new List>();
foreach (var company in depts)
{
var channel = new Dictionary
{
{ "name", company.title },
{ "value", company.id.ToString() }
};
allChannel.Add(channel);
}
CacheHelper.Set(cacheKey, allChannel, DateTime.Now.AddDays(1));
return allChannel;
}
#endregion 获取内部公司列表 cache_Company_getList
#region 获取短信类型
public List GetSmsTypeList()
{
string cacheKey = "cache_smsTypeList";
if (CacheHelper.Exists(cacheKey))
return CacheHelper.Get>(cacheKey);
using (var db = new zxdContext())
{
List msgType = db.SMS_MSGTYPE.ToList();
CacheHelper.Set(cacheKey, msgType);
return msgType;
}
}
public List GetSmsSubTypeList()
{
var cacheKey = "cache_smsSubTypeList";
if (CacheHelper.Exists(cacheKey))
return CacheHelper.Get>(cacheKey);
using (var db = new zxdContext())
{
var msgType = db.SMS_MSGSUBTYPE.ToList();
CacheHelper.Set(cacheKey, msgType);
return msgType;
}
}
public List GetSmsClientList()
{
var cacheKey = "cache_smsClientList";
if (CacheHelper.Exists(cacheKey))
return CacheHelper.Get>(cacheKey);
using (var db = new zxdContext())
{
var msgType = db.SMS_MSGTYPE_CLIENT.ToList();
CacheHelper.Set(cacheKey, msgType);
return msgType;
}
}
///
/// 获取短信类型 树形
///
///
public object GetSmsTypeTreeList()
{
string cacheKey = "cache_smsType_getTreeList";
if (CacheHelper.Exists(cacheKey))
return CacheHelper.Get