2399 lines
95 KiB
C#
2399 lines
95 KiB
C#
using CRM.Core.DTO;
|
||
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using WX.CRM.BLL.Application.UserComBox;
|
||
using WX.CRM.BLL.Base;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.IBLL.Util;
|
||
using WX.CRM.Model.Entity;
|
||
using WX.CRM.Model.Enum;
|
||
using StackExchange.Redis;
|
||
using System.IO;
|
||
|
||
namespace WX.CRM.BLL.Util
|
||
{
|
||
/// <summary>
|
||
/// 缓存BL
|
||
/// </summary>
|
||
public class CACHE_BL : ICACHE_Q
|
||
{
|
||
#region excel数据导入字典
|
||
|
||
/// <summary>
|
||
/// excel数据导入字典
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<BAS_EXCELIMPORTDICT> GetList_ExcelImportDict(EnumExcelDataType excelDataType)
|
||
{
|
||
var list = GetList_ExcelImportDict();
|
||
var typeid = excelDataType.ToString();
|
||
list = list.Where(m => m.TYPEID.Equals(typeid)).OrderBy(m => m.SORTID).ToList();
|
||
//foreach (var item in list)
|
||
//{
|
||
// item.ColumnIndex = -1;
|
||
//}
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// excel数据导入字典
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<BAS_EXCELIMPORTDICT> GetList_ExcelImportDict(EnumExcelDataType excelDataType, decimal isNew)
|
||
{
|
||
var list = GetList_ExcelImportDict();
|
||
var typeid = excelDataType.ToString();
|
||
list = list.Where(m => m.TYPEID.Equals(typeid)).Where(m => m.ISNEW == isNew).OrderBy(m => m.SORTID).ToList();
|
||
//foreach (var item in list)
|
||
//{
|
||
// item.ColumnIndex = -1;
|
||
//}
|
||
return list;
|
||
}
|
||
|
||
public List<BAS_EXCELIMPORTDICT> GetList_ExcelImportDict()
|
||
{
|
||
string cacheKey = "cache_excelImportDict_getList";
|
||
List<BAS_EXCELIMPORTDICT> list;
|
||
if (CacheHelper.Exists(cacheKey))
|
||
list = CacheHelper.Get<List<BAS_EXCELIMPORTDICT>>(cacheKey);
|
||
else
|
||
using (var db = new crmContext())
|
||
{
|
||
list = db.BAS_EXCELIMPORTDICT.ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
#endregion excel数据导入字典
|
||
|
||
#region excel数据导入类型
|
||
|
||
/// <summary>
|
||
/// 获取excel数据导入类型
|
||
/// </summary>
|
||
/// <param name="excelDataType">数据导入类型</param>
|
||
/// <returns></returns>
|
||
public BAS_EXCELIMPORTTYPE GetModel_ExcelImportType(EnumExcelDataType excelDataType)
|
||
{
|
||
//string cacheKey = "cache_excelImportType_getList";
|
||
//List<BAS_EXCELIMPORTTYPE> list;
|
||
//if (CacheHelper.Exists(cacheKey))
|
||
// list = CacheHelper.Get<List<BAS_EXCELIMPORTTYPE>>(cacheKey);
|
||
//else
|
||
// using (var db = new qhContext())
|
||
// {
|
||
// list = db.BAS_EXCELIMPORTTYPE.ToList();
|
||
// CacheHelper.Set(cacheKey, list);
|
||
// }
|
||
//string typeid = excelDataType.ToString();
|
||
//return list.FirstOrDefault(m => m.TYPECODE.Equals(typeid));
|
||
var list = GetList_ExcelImportType();
|
||
var typeid = excelDataType.ToString();
|
||
return list.FirstOrDefault(p => p.TYPECODE.Equals(typeid));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取excel数据导入类型列表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<BAS_EXCELIMPORTTYPE> GetList_ExcelImportType()
|
||
{
|
||
string cacheKey = "cache_excelImportType_getList";
|
||
List<BAS_EXCELIMPORTTYPE> list;
|
||
if (CacheHelper.Exists(cacheKey))
|
||
list = CacheHelper.Get<List<BAS_EXCELIMPORTTYPE>>(cacheKey);
|
||
else
|
||
using (var db = new crmContext())
|
||
{
|
||
list = db.BAS_EXCELIMPORTTYPE.ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
#endregion excel数据导入类型
|
||
|
||
#region 工单样式列表
|
||
|
||
/// <summary>
|
||
/// 工单样式列表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<ORD_MEMOSTYLE> GetList_MemoStyle()
|
||
{
|
||
string cacheKey = "cache_MemoStyle_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<ORD_MEMOSTYLE>>(cacheKey);
|
||
using (crmContext db = new crmContext())
|
||
{
|
||
List<ORD_MEMOSTYLE> list = db.ORD_MEMOSTYLE.ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion 工单样式列表
|
||
|
||
#region 获取通用数据小类(通过 Model.Enum.ComType查询)
|
||
|
||
/// <summary>
|
||
/// 获取通用数据小类
|
||
/// </summary>
|
||
/// <param name="type">Model.Enum.ComType</param>
|
||
/// <returns></returns>
|
||
public List<BAS_SUBCOMTYPE> GetList_SubComType(WX.CRM.Model.Enum.ComType type)
|
||
{
|
||
//string cacheKey1 = "cache_ComType_getList";
|
||
string cacheKey2 = "cache_SubComType_getList";
|
||
//List<Model.Entity.BAS_COMTYPE> comTypeList;
|
||
List<WX.CRM.Model.Entity.BAS_SUBCOMTYPE> subComtypeList;
|
||
//if (CacheHelper.Exists(cacheKey1))
|
||
// comTypeList = CacheHelper.Get<List<Model.Entity.BAS_COMTYPE>>(cacheKey1);
|
||
//else
|
||
//{
|
||
// using (Model.Entity.crmContext db = new Model.Entity.crmContext())
|
||
// {
|
||
// comTypeList = db.BAS_COMTYPE.ToList();
|
||
// CacheHelper.Set(cacheKey1, comTypeList);
|
||
// }
|
||
//}
|
||
if (CacheHelper.Exists(cacheKey2))
|
||
subComtypeList = CacheHelper.Get<List<WX.CRM.Model.Entity.BAS_SUBCOMTYPE>>(cacheKey2);
|
||
else
|
||
{
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
subComtypeList = db.BAS_SUBCOMTYPE.ToList();
|
||
CacheHelper.Set(cacheKey2, subComtypeList);
|
||
}
|
||
}
|
||
return subComtypeList.Where(m => m.TYPECODE == type.ToString()).OrderBy(m => m.SUBTYPECODE).ToList();
|
||
}
|
||
|
||
public List<BAS_SUBCOMTYPE> GetList_SubComType(string typeCode)
|
||
{
|
||
//string cacheKey1 = "cache_ComType_getList";
|
||
string cacheKey2 = "cache_SubComType_getList";
|
||
//List<Model.Entity.BAS_COMTYPE> comTypeList
|
||
List<WX.CRM.Model.Entity.BAS_SUBCOMTYPE> subComtypeList;
|
||
//if (CacheHelper.Exists(cacheKey1))
|
||
// comTypeList = CacheHelper.Get<List<Model.Entity.BAS_COMTYPE>>(cacheKey1);
|
||
//else
|
||
//{
|
||
// using (Model.Entity.crmContext db = new Model.Entity.crmContext())
|
||
// {
|
||
// comTypeList = db.BAS_COMTYPE.ToList();
|
||
// CacheHelper.Set(cacheKey1, comTypeList);
|
||
// }
|
||
//}
|
||
if (CacheHelper.Exists(cacheKey2))
|
||
subComtypeList = CacheHelper.Get<List<WX.CRM.Model.Entity.BAS_SUBCOMTYPE>>(cacheKey2);
|
||
else
|
||
{
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
subComtypeList = db.BAS_SUBCOMTYPE.ToList();
|
||
CacheHelper.Set(cacheKey2, subComtypeList);
|
||
}
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(typeCode))
|
||
{
|
||
return subComtypeList.Where(m => m.TYPECODE == typeCode).ToList();
|
||
}
|
||
return subComtypeList;
|
||
}
|
||
|
||
#endregion 获取通用数据小类(通过 Model.Enum.ComType查询)
|
||
|
||
#region 角色查询
|
||
|
||
/// <summary>
|
||
/// 获取工单小类信息
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<BAS_ROLE> GetList_Role()
|
||
{
|
||
string cacheKey = "cache_Role_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<WX.CRM.Model.Entity.BAS_ROLE>>(cacheKey);
|
||
using (crmContext db = new crmContext())
|
||
{
|
||
List<BAS_ROLE> list = db.BAS_ROLE.ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取角色编码
|
||
/// </summary>
|
||
/// <param name="roleIds">角色ID数组</param>
|
||
/// <returns></returns>
|
||
public string Get_RoleCodes(decimal[] roleIds)
|
||
{
|
||
List<BAS_ROLE> roleList = GetList_Role().Where(m => roleIds.Contains(m.ROLEID)).ToList();
|
||
StringBuilder codes = new StringBuilder();
|
||
foreach (BAS_ROLE role in roleList)
|
||
{
|
||
codes.AppendFormat("[{0}]", role.CODE);
|
||
}
|
||
return codes.ToString();
|
||
}
|
||
|
||
public List<BAS_INNERUSERROLE> GetUserRole()
|
||
{
|
||
var key = "cache_User_Role";
|
||
if (CacheHelper.Exists(key))
|
||
return CacheHelper.Get<List<BAS_INNERUSERROLE>>(key);
|
||
using (var db = new crmContext())
|
||
{
|
||
var list = db.BAS_INNERUSERROLE.ToList();
|
||
CacheHelper.Set(key, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 特殊权限表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<BAS_RIGHT_LEVEL> GetRightLevel()
|
||
{
|
||
var key = "cache_BAS_RIGHT_LEVEL";
|
||
if (CacheHelper.Exists(key))
|
||
return CacheHelper.Get<List<BAS_RIGHT_LEVEL>>(key);
|
||
using (var db = new crmContext())
|
||
{
|
||
var list = db.BAS_RIGHT_LEVEL.ToList();
|
||
CacheHelper.Set(key, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 特殊权限详细表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<BAS_RIGHT_LEVEL_DETAIL> GetRightLevelDetail()
|
||
{
|
||
var key = "cache_BAS_RIGHT_LEVEL_DETAIL";
|
||
if (CacheHelper.Exists(key))
|
||
return CacheHelper.Get<List<BAS_RIGHT_LEVEL_DETAIL>>(key);
|
||
using (var db = new crmContext())
|
||
{
|
||
var list = db.BAS_RIGHT_LEVEL_DETAIL.ToList();
|
||
CacheHelper.Set(key, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion 角色查询
|
||
|
||
#region 获取工单小类信息 (只查询可显示)
|
||
|
||
/// <summary>
|
||
/// 获取工单小类信息 (只查询可显示)
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<ORD_MEMOSUBTYPE> GetList_MemoSubType(int type = 1)
|
||
{
|
||
string cacheKey = "cache_MemoSubType_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<WX.CRM.Model.Entity.ORD_MEMOSUBTYPE>>(cacheKey);
|
||
using (crmContext db = new crmContext())
|
||
{
|
||
List<ORD_MEMOSUBTYPE> list = null;
|
||
if (type == 0)
|
||
list = db.ORD_MEMOSUBTYPE.OrderBy(m => m.CTIME).ToList<ORD_MEMOSUBTYPE>();
|
||
else
|
||
list = db.ORD_MEMOSUBTYPE.Where(m => m.ISSHOW == 1).OrderBy(m => m.CTIME).ToList<ORD_MEMOSUBTYPE>();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion 获取工单小类信息 (只查询可显示)
|
||
|
||
#region 获取工单大类(只查询可显示)
|
||
|
||
/// <summary>
|
||
/// 获取工单大类(只查询可显示)
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<ORD_MEMOTYPE> GetList_MemoType(int type = 1)
|
||
{
|
||
string cacheKey = "cache_MemoType_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<WX.CRM.Model.Entity.ORD_MEMOTYPE>>(cacheKey);
|
||
using (crmContext db = new crmContext())
|
||
{
|
||
List<ORD_MEMOTYPE> list = null;
|
||
if (type == 0)
|
||
list = db.ORD_MEMOTYPE.OrderBy(m => m.CTIME).ToList<ORD_MEMOTYPE>();
|
||
else
|
||
list = db.ORD_MEMOTYPE.OrderBy(m => m.CTIME).Where(m => m.ISSHOW == 1).ToList<ORD_MEMOTYPE>();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion 获取工单大类(只查询可显示)
|
||
|
||
#region 根据Model.Enum.Parameter 获取参数value
|
||
|
||
public string GetValue_Parameter(string key)
|
||
{
|
||
string cacheKey = "cache_Parameter_getList";
|
||
List<WX.CRM.Model.Entity.BAS_PARAMETER> modelist;
|
||
if (CacheHelper.Exists(cacheKey))
|
||
modelist = CacheHelper.Get<List<WX.CRM.Model.Entity.BAS_PARAMETER>>(cacheKey);
|
||
else
|
||
{
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
modelist = db.BAS_PARAMETER.ToList();
|
||
CacheHelper.Set(cacheKey, modelist);
|
||
}
|
||
}
|
||
WX.CRM.Model.Entity.BAS_PARAMETER model = modelist.FirstOrDefault(m => m.PARAKEY == key);
|
||
if (model == null)
|
||
return "";
|
||
return model.PARAVALUE;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据Model.Enum.Parameter 获取参数value
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public string GetValue_Parameter(WX.CRM.Model.Enum.Parameter key)
|
||
{
|
||
string cacheKey = "cache_Parameter_getList";
|
||
List<WX.CRM.Model.Entity.BAS_PARAMETER> modelist;
|
||
if (CacheHelper.Exists(cacheKey))
|
||
modelist = CacheHelper.Get<List<WX.CRM.Model.Entity.BAS_PARAMETER>>(cacheKey);
|
||
else
|
||
{
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
modelist = db.BAS_PARAMETER.ToList();
|
||
CacheHelper.Set(cacheKey, modelist);
|
||
}
|
||
}
|
||
WX.CRM.Model.Entity.BAS_PARAMETER sysConfig = modelist.FirstOrDefault(m => m.PARAKEY == "Sys_Environment_DeptCode");
|
||
WX.CRM.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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据系统参数分类获取系统参数列表
|
||
/// </summary>
|
||
/// <param name="type">系统参数分类</param>
|
||
/// <returns></returns>
|
||
public List<BAS_PARAMETER> GetList_Parameter(WX.CRM.Model.Enum.ParameterGroup type)
|
||
{
|
||
string cacheKey = "cache_Parameter_getList";
|
||
List<WX.CRM.Model.Entity.BAS_PARAMETER> modelist;
|
||
if (CacheHelper.Exists(cacheKey))
|
||
modelist = CacheHelper.Get<List<WX.CRM.Model.Entity.BAS_PARAMETER>>(cacheKey);
|
||
else
|
||
{
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
modelist = db.BAS_PARAMETER.ToList();
|
||
CacheHelper.Set(cacheKey, modelist);
|
||
}
|
||
}
|
||
List<WX.CRM.Model.Entity.BAS_PARAMETER> list = modelist.Where(m => m.GROUPID.Trim() == type.ToString().Trim()).ToList();
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据参数分类和参数值获取参数名
|
||
/// </summary>
|
||
/// <param name="paravalue">参数值</param>
|
||
/// <param name="type">参数分类</param>
|
||
/// <returns></returns>
|
||
public string GetParaNameByParavalue(string paravalue, ParameterGroup type)
|
||
{
|
||
string cacheKey = "cache_Parameter_getParaNameByParavalue";
|
||
List<BAS_PARAMETER> modelist;
|
||
if (CacheHelper.Exists(cacheKey))
|
||
modelist = CacheHelper.Get<List<BAS_PARAMETER>>(cacheKey);
|
||
else
|
||
{
|
||
using (crmContext db = new crmContext())
|
||
{
|
||
modelist = db.BAS_PARAMETER.ToList();
|
||
CacheHelper.Set(cacheKey, modelist);
|
||
}
|
||
}
|
||
string sss = paravalue.Trim();
|
||
BAS_PARAMETER model = modelist.FirstOrDefault(m => m.PARAVALUE == sss && m.GROUPID == type.ToString());
|
||
if (model == null)
|
||
return "";
|
||
return model.PARANAME;
|
||
}
|
||
|
||
#endregion 根据Model.Enum.Parameter 获取参数value
|
||
|
||
#region 电话验证码redis缓存业务
|
||
|
||
// 设置验证码
|
||
public void SetVerify(string phone, string verifyCode)
|
||
{
|
||
try
|
||
{
|
||
var redisUrl = System.Configuration.ConfigurationManager.AppSettings["RedisPath"]; // Redis 的连接配置,根据实际情况修改
|
||
ConfigurationOptions config = ConfigurationOptions.Parse(redisUrl);
|
||
var redisAuth = System.Configuration.ConfigurationManager.AppSettings["RedisAuth"];
|
||
if (redisAuth != null && redisAuth != "")
|
||
{
|
||
config.Password = System.Configuration.ConfigurationManager.AppSettings["RedisAuth"];
|
||
}
|
||
var redis = ConnectionMultiplexer.Connect(config);
|
||
|
||
// 获取 Redis 数据库
|
||
var db = redis.GetDatabase();
|
||
var redisVerifyCode = db.HashSet("verifyHash", phone, verifyCode);
|
||
db.KeyExpire("verifyHash", TimeSpan.FromMinutes(5));
|
||
// 关闭 Redis 连接
|
||
redis.Close();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex);
|
||
}
|
||
}
|
||
|
||
// 判断验证码是否正确
|
||
public bool JudgeVerify(string phone, string verifyCode)
|
||
{
|
||
var redisUrl = System.Configuration.ConfigurationManager.AppSettings["RedisPath"]; // Redis 的连接配置,根据实际情况修改
|
||
ConfigurationOptions config = ConfigurationOptions.Parse(redisUrl);
|
||
var redisAuth = System.Configuration.ConfigurationManager.AppSettings["RedisAuth"];
|
||
if (redisAuth != null && redisAuth != "")
|
||
{
|
||
config.Password = System.Configuration.ConfigurationManager.AppSettings["RedisAuth"];
|
||
}
|
||
var redis = ConnectionMultiplexer.Connect(config);
|
||
|
||
var db = redis.GetDatabase();
|
||
var redisVerifyCode = db.HashGet("verifyHash", phone);
|
||
redis.Close();
|
||
if (verifyCode == redisVerifyCode) return true;
|
||
return false;
|
||
}
|
||
|
||
#endregion 电话验证码redis缓存业务
|
||
|
||
#region 获取公司业务列表
|
||
|
||
/// <summary>
|
||
/// 获取公司业务列表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<WX.CRM.Model.Entity.BAS_BUSINESS> GetList_Business()
|
||
{
|
||
string cacheKey = "cache_Business_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<WX.CRM.Model.Entity.BAS_BUSINESS>>(cacheKey);
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
var list = db.BAS_BUSINESS.ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion 获取公司业务列表
|
||
|
||
#region 获取内部公司列表 cache_Company_getList
|
||
|
||
/// <summary>
|
||
/// 获取公司列表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<WX.CRM.Model.Entity.BAS_COMPANY> GetList_innerCompany()
|
||
{
|
||
string cacheKey = "cache_Company_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<WX.CRM.Model.Entity.BAS_COMPANY>>(cacheKey);
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
List<WX.CRM.Model.Entity.BAS_COMPANY> list = db.BAS_COMPANY.Where(m => m.ISOUTERAGENT == 0).OrderBy(m => m.CTIME).ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion 获取内部公司列表 cache_Company_getList
|
||
|
||
#region 获取销售组树形 cache_InnerGroup_getTreeList
|
||
|
||
/// <summary>
|
||
/// 获取新销售组树形 1 全部 2 业务部门 3 其他部门
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public object GetTreeList_InnerGroup(bool hasUser = false, string filter = "", int type = 1)
|
||
{
|
||
var saleName = "sale_";
|
||
if (type == 4 || type == 5)
|
||
{
|
||
saleName = "";
|
||
}
|
||
string cacheKey = $"cache_InnerGroup_getTreeList{hasUser}{filter}";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<object>(cacheKey);
|
||
List<object> objList = new List<object>();
|
||
using (var db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
List<WX.CRM.Model.Entity.BAS_SALESDEPARTMENT> salesDeptList = db.BAS_SALESDEPARTMENT.Where(n => n.IS_DELETED != 1).ToList();
|
||
List<WX.CRM.Model.Entity.BAS_INNERGROUP> innerGroupList = db.BAS_INNERGROUP.Where(n => n.IS_DELETED != 1).ToList();
|
||
List<BAS_INNERUSER> innerUserList = db.BAS_INNERUSER.Where(n => n.ISDISMISS != 1 && n.ISHIDE != 1).ToList();
|
||
List<BAS_INNERUSERGROUP> userDeptList = db.BAS_INNERUSERGROUP.ToList();
|
||
var firstNodeList = salesDeptList.Where(n => n.DEPARTMENT_PARENTID == 0 || n.DEPARTMENT_PARENTID == null).ToList();
|
||
var i = 0;
|
||
foreach (var saleDpt in firstNodeList)
|
||
{
|
||
var obj = new DropModel
|
||
{
|
||
id = saleName + saleDpt.SALEDEPTID,
|
||
state = "open",
|
||
text = saleDpt.DEPTNAME,
|
||
children = null,
|
||
isspecial = saleDpt.IS_PROFESSION,
|
||
iconCls = "icon-deptmini",
|
||
relateId = saleDpt.DEPARTMENT_ID,
|
||
orginId = saleDpt.SALEDEPTID,
|
||
filterId = new List<decimal> { saleDpt.SALEDEPTID },
|
||
type = 1
|
||
};
|
||
BuildChildNode(innerUserList, userDeptList, salesDeptList, innerGroupList, obj, i++, hasUser, filter, saleName, type);
|
||
objList.Add(obj);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(filter))
|
||
{
|
||
List<decimal> filterIdList = new List<decimal>();
|
||
filterIdList.AddRange(innerUserList.Where(n => n.EID.ToString().Contains(filter) || n.UNAME.Contains(filter)).Select(n => n.PKID));
|
||
filterIdList.AddRange(salesDeptList.Where(n => n.DEPTNAME.ToString().Contains(filter)).Select(n => n.SALEDEPTID));
|
||
filterIdList.AddRange(innerGroupList.Where(n => n.GNAME.ToString().Contains(filter)).Select(n => n.GID));
|
||
foreach (var item in objList)
|
||
{
|
||
BuildFilterTree((DropModel)item, filterIdList);
|
||
}
|
||
}
|
||
//CacheHelper.Set(cacheKey, objList);
|
||
return objList;
|
||
}
|
||
}
|
||
|
||
public void BuildFilterTree(DropModel qobject, List<decimal> filterIdList)
|
||
{
|
||
var childRen = qobject.children;
|
||
if (childRen == null)
|
||
{
|
||
return;
|
||
}
|
||
List<DropModel> child = new List<DropModel>();
|
||
foreach (var c in childRen)
|
||
{
|
||
var isCantain = false;
|
||
foreach (var filter in filterIdList)
|
||
{
|
||
if (c.filterId.Contains(filter))
|
||
{
|
||
isCantain = true;
|
||
break;
|
||
}
|
||
}
|
||
if (isCantain)
|
||
{
|
||
qobject.state = "open";
|
||
child.Add(c);
|
||
BuildFilterTree(c, filterIdList);
|
||
}
|
||
}
|
||
qobject.children = child;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 递归 构建 树形结构 todo 要是数据不合法可能会有死循环出现
|
||
/// </summary>
|
||
/// <param name="salesDeptList"></param>
|
||
/// <param name="innerGroupList"></param>
|
||
/// <param name="qobject"></param>
|
||
/// <param name="deptId"></param>
|
||
/// <param name="i"></param>
|
||
public static void BuildChildNode(List<BAS_INNERUSER> innerUserList, List<BAS_INNERUSERGROUP> userDeptList, List<BAS_SALESDEPARTMENT> salesDeptList,
|
||
List<BAS_INNERGROUP> innerGroupList, DropModel qobject, int i, bool hasUser, string filter, string saleName, int type)
|
||
{
|
||
if (qobject.relateId == null)
|
||
{
|
||
//return;
|
||
}
|
||
var childList = salesDeptList.Where(n => n.DEPARTMENT_PARENTID == qobject.relateId && n.DEPARTMENT_PARENTID != null).OrderBy(n => n.DEPARTMENT_SORT).ToList();
|
||
|
||
if (i == 0 || i == 1)
|
||
{
|
||
qobject.state = type != 5 || qobject.state == "open" ? "open" : "closed";
|
||
}
|
||
var j = 0;
|
||
foreach (var c in childList)
|
||
{
|
||
if (qobject.children == null)
|
||
{
|
||
qobject.children = new List<DropModel>();
|
||
}
|
||
var state = "open";
|
||
if (c.IS_PROFESSION == 0 || type == 5)
|
||
{
|
||
state = "closed";
|
||
}
|
||
var cObject = new DropModel
|
||
{
|
||
id = saleName + c.SALEDEPTID,
|
||
state = state,
|
||
text = c.DEPTNAME,
|
||
iconCls = "icon-otherdeptmini",
|
||
children = null,
|
||
isspecial = c.IS_PROFESSION,
|
||
relateId = c.DEPARTMENT_ID,
|
||
orginId = c.SALEDEPTID,
|
||
filterId = new List<decimal> { c.SALEDEPTID },
|
||
type = 1
|
||
};
|
||
|
||
BuildChildNode(innerUserList, userDeptList, salesDeptList, innerGroupList, cObject, ++j, hasUser, filter, saleName, type);
|
||
qobject.children.Add(cObject);
|
||
}
|
||
var pobjId = qobject.id;
|
||
if (!string.IsNullOrWhiteSpace(saleName))
|
||
{
|
||
pobjId = qobject.id.Replace(saleName, "");
|
||
}
|
||
var groupList = innerGroupList.Where(n => n.SALEDEPTID == Convert.ToDecimal(pobjId)).OrderBy(n => n.DEPARTMENT_SORT).ToList();
|
||
List<DropModel> gchildList = new List<DropModel>();
|
||
foreach (var g in groupList)
|
||
{
|
||
if (qobject.children == null)
|
||
{
|
||
qobject.children = new List<DropModel>();
|
||
}
|
||
var id = g.GID.ToString();
|
||
if (hasUser)
|
||
{
|
||
id = saleName + g.GID;
|
||
}
|
||
var cObject = new DropModel
|
||
{
|
||
id = id,
|
||
text = g.GNAME,
|
||
state = "closed",
|
||
attributes = g.DEPTID.ToString(),
|
||
iconCls = "icon-groupmini",
|
||
isspecial = g.IS_PROFESSION,
|
||
orginId = g.GID,
|
||
relateId = g.GID,
|
||
filterId = new List<decimal> { g.GID },
|
||
type = 2
|
||
};
|
||
if (hasUser)
|
||
{
|
||
BuildUserList(innerUserList, userDeptList, g.GID, cObject, type);
|
||
}
|
||
if (cObject.children == null || cObject.children.Count() == 0)
|
||
{
|
||
cObject.state = null;
|
||
}
|
||
qobject.children.Add(cObject);
|
||
}
|
||
if (qobject.children != null)
|
||
{
|
||
var specialList = qobject.children.Where(n => n.isspecial == null || n.isspecial == 1 || n.isspecial == 3).ToList();
|
||
var commonList = qobject.children.Where(n => (n.isspecial != null && n.isspecial == 0) || n.isspecial == 3).ToList();
|
||
if (commonList.Count > 0)
|
||
{
|
||
qobject.isspecial = 0;
|
||
}
|
||
if (specialList.Count > 0)
|
||
{
|
||
qobject.isspecial = 1;
|
||
}
|
||
if (commonList.Count > 0 && specialList.Count > 0)
|
||
{
|
||
qobject.isspecial = 3;
|
||
}
|
||
}
|
||
if (qobject.isspecial > 0 && qobject.type == 1)
|
||
{
|
||
qobject.iconCls = "icon-deptmini";
|
||
}
|
||
if (hasUser)
|
||
{
|
||
var qobjId = qobject.id;
|
||
if (!string.IsNullOrWhiteSpace(saleName))
|
||
{
|
||
qobjId = qobject.id.Replace(saleName, "");
|
||
}
|
||
BuildUserList(innerUserList, userDeptList, Convert.ToDecimal(qobjId), qobject, type);
|
||
}
|
||
if (qobject.children != null)
|
||
{
|
||
qobject.children = qobject.children.OrderByDescending(n => n.isspecial).ToList();
|
||
var childFilter = qobject.children.Select(n => n.filterId).ToList();
|
||
foreach (var f in childFilter)
|
||
{
|
||
qobject.filterId.AddRange(f);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
qobject.state = "open";
|
||
}
|
||
if (qobject.children == null || qobject.children.Count() == 0)
|
||
{
|
||
qobject.state = null;
|
||
}
|
||
}
|
||
|
||
private static void BuildUserList(List<BAS_INNERUSER> innerUserList, List<BAS_INNERUSERGROUP> userDeptList, decimal? deptId, DropModel qobject, int type)
|
||
{
|
||
var res = new List<DropModel>();
|
||
var employeeIds = userDeptList.Where(n => (n.DEPTID == deptId && n.GID == null) || n.GID == deptId).Select(n => n.INNERUSERID).ToList();
|
||
var childUserList = innerUserList.Where(x => x.EMPLOYEE_ID != null && employeeIds.Contains(x.PKID)).ToList();
|
||
foreach (var u in childUserList)
|
||
{
|
||
var cid = u.PKID.ToString();
|
||
var orginId = u.PKID;
|
||
if (type == 5)
|
||
{
|
||
cid = u.EID.ToString();
|
||
orginId = u.EID;
|
||
}
|
||
var cObject = new DropModel
|
||
{
|
||
id = cid,
|
||
text = u.UNAME,
|
||
iconCls = "icon-usermini",
|
||
children = null,
|
||
orginId = orginId,
|
||
filterId = new List<decimal> { u.PKID },
|
||
type = 3
|
||
};
|
||
res.Add(cObject);
|
||
}
|
||
if (res.Count > 0)
|
||
{
|
||
if (qobject.children == null)
|
||
{
|
||
qobject.children = new List<DropModel>();
|
||
}
|
||
qobject.children.AddRange(res);
|
||
qobject.filterId.AddRange(qobject.children.Select(n => n.orginId).ToList());
|
||
}
|
||
}
|
||
|
||
public object GetInneruserTree(bool hasUser = true)
|
||
{
|
||
string cacheKey = $"cache_InnerUser_getTreeList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<InneruserTreeDto>>(cacheKey);
|
||
List<InneruserTreeDto> objList = new List<InneruserTreeDto>();
|
||
using (var db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
List<WX.CRM.Model.Entity.BAS_SALESDEPARTMENT> salesDeptList = db.BAS_SALESDEPARTMENT.Where(n => n.IS_DELETED != 1).ToList();
|
||
List<WX.CRM.Model.Entity.BAS_INNERGROUP> innerGroupList = db.BAS_INNERGROUP.Where(n => n.IS_DELETED != 1).ToList();
|
||
List<BAS_INNERUSER> innerUserList = db.BAS_INNERUSER.Where(n => n.ISDISMISS != 1).ToList();
|
||
List<BAS_INNERUSERGROUP> userDeptList = db.BAS_INNERUSERGROUP.ToList();
|
||
var firstNodeList = salesDeptList.Where(n => n.DEPARTMENT_PARENTID == 0 || n.DEPARTMENT_PARENTID == null).ToList();
|
||
foreach (var saleDpt in firstNodeList)
|
||
{
|
||
var item = new InneruserTreeDto
|
||
{
|
||
value = saleDpt.SALEDEPTID,
|
||
name = saleDpt.DEPTNAME,
|
||
relateId = saleDpt.DEPARTMENT_ID,
|
||
children = new List<InneruserTreeDto>()
|
||
};
|
||
BuildUserChildNode(innerUserList, userDeptList, salesDeptList, innerGroupList, item, hasUser);
|
||
objList.Add(item);
|
||
}
|
||
}
|
||
return objList;
|
||
}
|
||
|
||
public void BuildUserChildNode(List<BAS_INNERUSER> innerUserList, List<BAS_INNERUSERGROUP> userDeptList, List<BAS_SALESDEPARTMENT> salesDeptList,
|
||
List<BAS_INNERGROUP> innerGroupList, InneruserTreeDto qobject, bool hasUser)
|
||
{
|
||
var childList = salesDeptList.Where(n => n.DEPARTMENT_PARENTID == qobject.relateId && n.DEPARTMENT_PARENTID != null).OrderBy(n => n.DEPARTMENT_SORT).ToList();
|
||
foreach (var c in childList)
|
||
{
|
||
var cObject = new InneruserTreeDto
|
||
{
|
||
value = c.SALEDEPTID,
|
||
name = c.DEPTNAME,
|
||
relateId = c.DEPARTMENT_ID,
|
||
children = new List<InneruserTreeDto>()
|
||
};
|
||
BuildUserChildNode(innerUserList, userDeptList, salesDeptList, innerGroupList, cObject, hasUser);
|
||
qobject.children.Add(cObject);
|
||
}
|
||
var groupList = innerGroupList.Where(n => n.SALEDEPTID == Convert.ToDecimal(qobject.value)).OrderBy(n => n.DEPARTMENT_SORT).ToList();
|
||
List<InneruserTreeDto> gchildList = new List<InneruserTreeDto>();
|
||
foreach (var g in groupList)
|
||
{
|
||
var id = g.GID.ToString();
|
||
var cObject = new InneruserTreeDto
|
||
{
|
||
value = g.GID,
|
||
name = g.GNAME,
|
||
relateId = g.DEPARTMENT_ID,
|
||
children = new List<InneruserTreeDto>()
|
||
};
|
||
if (hasUser)
|
||
{
|
||
BuildUserList(innerUserList, userDeptList, g.GID, cObject);
|
||
}
|
||
qobject.children.Add(cObject);
|
||
}
|
||
if (hasUser)
|
||
{
|
||
BuildUserList(innerUserList, userDeptList, Convert.ToDecimal(qobject.value), qobject);
|
||
}
|
||
}
|
||
|
||
private static void BuildUserList(List<BAS_INNERUSER> innerUserList, List<BAS_INNERUSERGROUP> userDeptList, decimal? deptId, InneruserTreeDto qobject)
|
||
{
|
||
var res = new List<InneruserTreeDto>();
|
||
var employeeIds = userDeptList.Where(n => (n.DEPTID == deptId && n.GID == null) || n.GID == deptId).Select(n => n.INNERUSERID).ToList();
|
||
var childUserList = innerUserList.Where(x => employeeIds.Contains(x.PKID)).ToList();
|
||
foreach (var u in childUserList)
|
||
{
|
||
var cObject = new InneruserTreeDto
|
||
{
|
||
value = u.EID,
|
||
name = u.UNAME,
|
||
relateId = u.PKID
|
||
};
|
||
res.Add(cObject);
|
||
}
|
||
if (res.Count > 0)
|
||
{
|
||
qobject.children.AddRange(res);
|
||
}
|
||
}
|
||
|
||
#endregion 获取销售组树形 cache_InnerGroup_getTreeList
|
||
|
||
#region 获取销售组树形(只显示销售组) cache_InnerGroup_getTreeList
|
||
|
||
/// <summary>
|
||
/// 获取销售组树形(去除系统组和隐藏组)
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public object GetTreeListIsSale_InnerGroup()
|
||
{
|
||
string cacheKey = "cache_InnerGroupIsSale_getTreeList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<object>(cacheKey);
|
||
using (var db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
WX.CRM.Model.Entity.BAS_COMPANY companyList = db.BAS_COMPANY.OrderBy(m => m.COMPANYID).FirstOrDefault();
|
||
List<WX.CRM.Model.Entity.BAS_SALESDEPARTMENT> salesDeptList = db.BAS_SALESDEPARTMENT.ToList();
|
||
List<WX.CRM.Model.Entity.BAS_INNERGROUP> innerGroupList = db.BAS_INNERGROUP.Where(m => m.ISSALEDEPT == 1).ToList();
|
||
List<object> obj = new List<object>();
|
||
List<object> childObj = null;
|
||
List<object> groupObj = null;
|
||
int i = 0;
|
||
int j = 0;
|
||
|
||
childObj = new List<object>();
|
||
j = 0;
|
||
foreach (WX.CRM.Model.Entity.BAS_SALESDEPARTMENT saleDpt in salesDeptList.Where(m => m.COMPANYID == companyList.COMPANYID))
|
||
{
|
||
groupObj = new List<object>();
|
||
foreach (WX.CRM.Model.Entity.BAS_INNERGROUP inGrp in innerGroupList.Where(x => x.SALEDEPTID == saleDpt.SALEDEPTID))
|
||
{
|
||
groupObj.Add(new { id = inGrp.GID, text = inGrp.GNAME, attributes = inGrp.DEPTID, iconCls = "icon-redmini" });
|
||
}
|
||
childObj.Add(new { id = "sale_" + saleDpt.SALEDEPTID, state = (groupObj.Count == 0 || j == 0 ? "open" : "closed"), text = saleDpt.DEPTNAME, children = groupObj.Count == 0 ? null : groupObj });
|
||
j++;
|
||
}
|
||
obj.Add(new { id = "com_" + companyList.COMPANYID, state = (childObj.Count == 0 || i == 0 ? "open" : "closed"), text = companyList.COMPANYNAME, children = childObj.Count == 0 ? null : childObj });
|
||
CacheHelper.Set(cacheKey, obj);
|
||
return obj;
|
||
}
|
||
}
|
||
|
||
#endregion 获取销售组树形(只显示销售组) cache_InnerGroup_getTreeList
|
||
|
||
#region 获取销售部树形结构 cache_saleDepartMent_getTreeList
|
||
/// <summary>
|
||
/// 旧的层级关系
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
|
||
public object GetTreeList_saleDepartMent_Old()
|
||
{
|
||
string cacheKey = "cache_saleDepartMent_getTreeList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<object>(cacheKey);
|
||
using (crmContext db = new crmContext())
|
||
{
|
||
List<BAS_COMPANY> companyList = db.BAS_COMPANY.ToList();
|
||
List<BAS_SALESDEPARTMENT> salesDeptList = db.BAS_SALESDEPARTMENT.ToList();
|
||
List<object> obj = new List<object>();
|
||
foreach (BAS_COMPANY model in companyList)
|
||
{
|
||
obj.Add(new { id = "-" + model.COMPANYID, text = model.COMPANYNAME, children = GetTreeChildList_old(salesDeptList, model.COMPANYID) });
|
||
}
|
||
CacheHelper.Set(cacheKey, obj);
|
||
return obj;
|
||
}
|
||
}
|
||
|
||
private List<object> GetTreeChildList_old(List<BAS_SALESDEPARTMENT> salesDeptList, decimal companyId)
|
||
{
|
||
List<object> obj = new List<object>();
|
||
foreach (BAS_SALESDEPARTMENT model in salesDeptList.Where(m => m.COMPANYID == companyId))
|
||
{
|
||
obj.Add(new { id = model.SALEDEPTID, text = model.DEPTNAME });
|
||
}
|
||
return obj;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 新树形结构
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public object GetTreeList_saleDepartMent()
|
||
{
|
||
string cacheKey = "cache_saleDepartMent_getTreeList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<object>(cacheKey);
|
||
using (crmContext db = new crmContext())
|
||
{
|
||
List<BAS_SALESDEPARTMENT> salesDeptList = db.BAS_SALESDEPARTMENT.Where(n => n.IS_DELETED != 1).ToList();
|
||
var companyList = salesDeptList.Where(n => n.DEPARTMENT_PARENTID == 0 || n.DEPARTMENT_PARENTID == null).ToList();
|
||
List<object> obj = new List<object>();
|
||
foreach (BAS_SALESDEPARTMENT model in companyList)
|
||
{
|
||
obj.Add(new { id = "-" + model.SALEDEPTID, text = model.DEPTNAME, children = GetTreeChildList(salesDeptList, model.DEPARTMENT_ID) });
|
||
}
|
||
CacheHelper.Set(cacheKey, obj);
|
||
return obj;
|
||
}
|
||
}
|
||
|
||
private List<object> GetTreeChildList(List<BAS_SALESDEPARTMENT> salesDeptList, decimal? companyId)
|
||
{
|
||
List<object> obj = new List<object>();
|
||
if (companyId == null)
|
||
{
|
||
return obj;
|
||
}
|
||
foreach (BAS_SALESDEPARTMENT model in salesDeptList.Where(m => m.DEPARTMENT_PARENTID == companyId))
|
||
{
|
||
obj.Add(new { id = model.SALEDEPTID, text = model.DEPTNAME, children = GetTreeChildList(salesDeptList, model.DEPARTMENT_ID) });
|
||
}
|
||
return obj;
|
||
}
|
||
|
||
public Dictionary<decimal?, string> BuildDepartMentShowText(List<decimal?> deptIdList)
|
||
{
|
||
deptIdList = deptIdList.Where(n => n.HasValue).Distinct().ToList();
|
||
Dictionary<decimal?, string> result = new Dictionary<decimal?, string>();
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
List<WX.CRM.Model.Entity.BAS_SALESDEPARTMENT> salesDeptList = db.BAS_SALESDEPARTMENT.Where(n => n.IS_DELETED != 1).ToList();
|
||
foreach (var deptId in deptIdList)
|
||
{
|
||
var res = BuildParentDepartMentShow(deptId, salesDeptList, "");
|
||
result.Add(deptId, res.Trim('/'));
|
||
}
|
||
return result;
|
||
}
|
||
}
|
||
|
||
public string BuildParentDepartMentShow(decimal? depetId, List<WX.CRM.Model.Entity.BAS_SALESDEPARTMENT> salesDeptList, string str)
|
||
{
|
||
if (depetId == null)
|
||
{
|
||
return str;
|
||
}
|
||
var parentDept = salesDeptList.Where(n => n.DEPARTMENT_ID == depetId).FirstOrDefault();
|
||
if (parentDept != null)
|
||
{
|
||
str = $"{parentDept.DEPTNAME}/{str}";
|
||
return BuildParentDepartMentShow(parentDept.DEPARTMENT_PARENTID, salesDeptList, str);
|
||
}
|
||
return str;
|
||
}
|
||
|
||
#endregion 获取销售部树形结构 cache_saleDepartMent_getTreeList
|
||
|
||
#region 获取tree数据列表 cache_innerDepartment_getTreeList
|
||
|
||
/// <summary>
|
||
/// 获取tree数据列表(type可以传空,默认折叠部分节点,传1不折叠)
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public object GetTreeList_innerDepartment(string type)
|
||
{
|
||
string cacheKey = "cache_innerDepartment_getTreeList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<object>(cacheKey);
|
||
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
List<WX.CRM.Model.Entity.BAS_INNERDEPARTMENT> innerDepartment = db.BAS_INNERDEPARTMENT.ToList();
|
||
List<object> obj = new List<object>();
|
||
obj.Add(new { id = 0, text = "公司部门", children = GetTreeChildList(type, innerDepartment, 0) });
|
||
CacheHelper.Set(cacheKey, obj);
|
||
return obj;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取子节点
|
||
/// </summary>
|
||
/// <param name="innerDepartment"></param>
|
||
/// <param name="parentId"></param>
|
||
/// <returns></returns>
|
||
private object GetTreeChildList(string type, List<WX.CRM.Model.Entity.BAS_INNERDEPARTMENT> innerDepartment, decimal parentId)
|
||
{
|
||
List<object> obj = null;
|
||
object childObj = null;
|
||
object grandchildObj = null;
|
||
int i = 0;
|
||
bool isClosed = true;
|
||
if (!string.IsNullOrWhiteSpace(type) && type == "1")
|
||
{
|
||
isClosed = false;
|
||
}
|
||
|
||
foreach (WX.CRM.Model.Entity.BAS_INNERDEPARTMENT model in innerDepartment.FindAll(m => m.PARENTID == parentId))
|
||
{
|
||
if (obj == null)
|
||
obj = new List<object>();
|
||
grandchildObj = GetTreeChildList(type, innerDepartment, model.DEPTID);
|
||
if (grandchildObj != null)
|
||
childObj = new { id = model.DEPTID, state = i == 0 ? "open" : "closed", text = model.DEPTNAME, children = grandchildObj };
|
||
else
|
||
childObj = new { id = model.DEPTID, text = model.DEPTNAME, children = grandchildObj };
|
||
obj.Add(childObj);
|
||
if (isClosed)
|
||
i++;
|
||
}
|
||
return obj;
|
||
}
|
||
|
||
#endregion 获取tree数据列表 cache_innerDepartment_getTreeList
|
||
|
||
#region 获取部门信息
|
||
|
||
/// <summary>
|
||
/// 获取部门信息
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public Dictionary<decimal, string> GetDictionary_InnerDepartMent()
|
||
{
|
||
string cacheKey = "cache_InnerDepartMent_getDic";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<Dictionary<decimal, string>>(cacheKey);
|
||
using (WX.CRM.Model.Entity.crmContext db = new crmContext())
|
||
{
|
||
List<BAS_INNERDEPARTMENT> list = db.BAS_INNERDEPARTMENT.ToList();
|
||
Dictionary<decimal, string> dic = new Dictionary<decimal, string>();
|
||
foreach (var model in list)
|
||
{
|
||
dic.Add(model.DEPTID, model.DEPTNAME);
|
||
}
|
||
CacheHelper.Set(cacheKey, dic);
|
||
return dic;
|
||
}
|
||
}
|
||
|
||
#endregion 获取部门信息
|
||
|
||
#region 获取tree数据列表(包括了挂在部门里面的销售组) cache_DeptGroup_getTreeList
|
||
|
||
/// <summary>
|
||
/// 获取tree数据列表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public object GetDeptGroupTreeList_DeptGroup()
|
||
{
|
||
string cacheKey = "cache_DeptGroup_getTreeList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<object>(cacheKey);
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
List<WX.CRM.Model.Entity.BAS_INNERDEPARTMENT> innerDepartment = db.BAS_INNERDEPARTMENT.ToList();
|
||
List<WX.CRM.Model.Entity.BAS_INNERGROUP> innerGroup = db.BAS_INNERGROUP.ToList();
|
||
List<object> obj = new List<object>();
|
||
obj.Add(new { id = 0, text = "公司部门", children = GetDeptGroupTreeChildList(innerDepartment, innerGroup, 0) });
|
||
CacheHelper.Set(cacheKey, obj);
|
||
return obj;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取子节点
|
||
/// </summary>
|
||
/// <param name="innerDepartment"></param>
|
||
/// <param name="parentId"></param>
|
||
/// <returns></returns>
|
||
private object GetDeptGroupTreeChildList(List<WX.CRM.Model.Entity.BAS_INNERDEPARTMENT> innerDepartment, List<WX.CRM.Model.Entity.BAS_INNERGROUP> innerGroup, decimal parentId)
|
||
{
|
||
List<object> obj = null;
|
||
object childObj = null;
|
||
object grandchildObj = null;
|
||
int i = 0;
|
||
foreach (WX.CRM.Model.Entity.BAS_INNERDEPARTMENT model in innerDepartment.FindAll(m => m.PARENTID == parentId))
|
||
{
|
||
if (obj == null)
|
||
obj = new List<object>();
|
||
grandchildObj = GetDeptGroupTreeChildList(innerDepartment, innerGroup, model.DEPTID);
|
||
if (grandchildObj != null)
|
||
childObj = new { id = model.DEPTID, state = i == 0 ? "open" : "closed", text = model.DEPTNAME, children = grandchildObj };
|
||
else
|
||
childObj = new { id = model.DEPTID, text = model.DEPTNAME, children = grandchildObj };
|
||
obj.Add(childObj);
|
||
i++;
|
||
}
|
||
foreach (WX.CRM.Model.Entity.BAS_INNERGROUP model in innerGroup.FindAll(m => m.DEPTID == parentId))
|
||
{
|
||
if (obj == null)
|
||
obj = new List<object>();
|
||
obj.Add(new { id = "g_" + model.SALEDEPTID, text = model.GNAME, iconCls = "icon-redmini" });
|
||
}
|
||
return obj;
|
||
}
|
||
|
||
#endregion 获取tree数据列表(包括了挂在部门里面的销售组) cache_DeptGroup_getTreeList
|
||
|
||
#region 获取短信类型
|
||
|
||
public List<SMS_MSGTYPE> GetSmsTypeList()
|
||
{
|
||
string cacheKey = "cache_smsTypeList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<SMS_MSGTYPE>>(cacheKey);
|
||
using (var db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
List<SMS_MSGTYPE> msgType = db.SMS_MSGTYPE.ToList();
|
||
CacheHelper.Set(cacheKey, msgType);
|
||
return msgType;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取短信类型 树形
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public object GetSmsTypeTreeList()
|
||
{
|
||
string cacheKey = "cache_smsType_getTreeList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<object>(cacheKey);
|
||
using (var db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
List<SMS_MSGTYPE> msgType = db.SMS_MSGTYPE.ToList();
|
||
List<SMS_MSGSUBTYPE> msgSubType = db.SMS_MSGSUBTYPE.ToList();
|
||
var obj = new List<object>();
|
||
foreach (var model in msgType)
|
||
{
|
||
obj.Add(new { id = "-" + model.TYPECODE, text = model.TYPENAME, children = GetSmsTypeTreeChildList(msgSubType, model.TYPECODE) });
|
||
}
|
||
CacheHelper.Set(cacheKey, obj);
|
||
return obj;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取短信crm短信类型 树形(根据短信大类)
|
||
/// </summary>
|
||
/// <param name="typeCode">短信大类</param>
|
||
/// <returns></returns>
|
||
public object GetSmsCrmTreeList()
|
||
{
|
||
string cacheKey = "cache_smsCrmType_getTreeList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<object>(cacheKey);
|
||
using (var db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
List<SMS_MSGTYPE> msgType = db.SMS_MSGTYPE.Where(m => m.TYPECODE == "CRMSMS0001").ToList();
|
||
List<SMS_MSGSUBTYPE> msgSubType = db.SMS_MSGSUBTYPE.ToList();
|
||
var obj = new List<object>();
|
||
foreach (var model in msgType)
|
||
{
|
||
obj.Add(new { id = "-" + model.TYPECODE, text = model.TYPENAME, children = GetSmsTypeTreeChildList(msgSubType, model.TYPECODE) });
|
||
}
|
||
CacheHelper.Set(cacheKey, obj);
|
||
return obj;
|
||
}
|
||
}
|
||
|
||
private List<object> GetSmsTypeTreeChildList(List<SMS_MSGSUBTYPE> msgSubType, string parentId)
|
||
{
|
||
var obj = new List<object>();
|
||
foreach (var model in msgSubType.Where(m => m.TYPECODE == parentId))
|
||
{
|
||
obj.Add(new { id = model.SUBTYPEID, typeCode = model.TYPECODE, subTypeCode = model.SUBTYPECODE, text = model.SUBTYPENAME });
|
||
}
|
||
return obj;
|
||
}
|
||
|
||
#endregion 获取短信类型
|
||
|
||
#region 员工
|
||
|
||
public Dictionary<decimal, string> GetList_Inneruser()
|
||
{
|
||
string cacheKey = "cache_Inneruser_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<Dictionary<decimal, string>>(cacheKey);
|
||
using (crmContext db = new crmContext())
|
||
{
|
||
Dictionary<decimal, string> dic = new Dictionary<decimal, string>();
|
||
List<BAS_INNERUSER> list = db.BAS_INNERUSER.ToList();
|
||
foreach (var item in list)
|
||
{
|
||
dic.Add(item.PKID, item.EID.ToString() + "-" + item.UNAME);
|
||
}
|
||
CacheHelper.Set(cacheKey, dic);
|
||
return dic;
|
||
}
|
||
}
|
||
|
||
public List<BAS_INNERUSER> GetUserList()
|
||
{
|
||
var cacheKey = "cache_user_list";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<BAS_INNERUSER>>(cacheKey);
|
||
using (var db = new crmContext())
|
||
{
|
||
var list = db.BAS_INNERUSER.Where(m => m.ISHIDE == 0).ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
public IList<IDictionary<string, object>> GetUserNameAndIdList()
|
||
{
|
||
IList<IDictionary<string, object>> res = new List<IDictionary<string, object>>();
|
||
var cacheKey = "cache_select_showbox_list";
|
||
if (!CacheHelper.TryGet(cacheKey, ref res))
|
||
{
|
||
res = new List<IDictionary<string, object>>();
|
||
using (var db = new crmContext())
|
||
{
|
||
var list = db.BAS_INNERUSER.Where(m => m.ISHIDE == 0).ToList();
|
||
foreach (var item in list)
|
||
{
|
||
IDictionary<string, object> r = new Dictionary<string, object>();
|
||
r.Add("uname", item.UNAME);
|
||
r.Add("eid", item.EID);
|
||
res.Add(r);
|
||
}
|
||
CacheHelper.Set(cacheKey, res);
|
||
}
|
||
}
|
||
return res;
|
||
}
|
||
|
||
#endregion 员工
|
||
#region 组
|
||
|
||
public List<BAS_INNERGROUP> GetGroupList()
|
||
{
|
||
var cacheKey = "cache_group_list";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<BAS_INNERGROUP>>(cacheKey);
|
||
using (var db = new crmContext())
|
||
{
|
||
var list = db.BAS_INNERGROUP.OrderBy(m => m.CTIME).ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion 组
|
||
#region 员工组关系
|
||
|
||
/// <summary>
|
||
/// 员工组关系
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<BAS_INNERUSERGROUP> GetList_InnerUserGroup()
|
||
{
|
||
string cacheKey = "cache_InnerUserGroup_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<BAS_INNERUSERGROUP>>(cacheKey);
|
||
using (crmContext db = new crmContext())
|
||
{
|
||
List<BAS_INNERUSERGROUP> list = db.BAS_INNERUSERGROUP.ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据 组获取员工ID
|
||
/// </summary>
|
||
/// <param name="groups"></param>
|
||
/// <returns></returns>
|
||
public string GetUserIds_ByGorups(string groups)
|
||
{
|
||
List<BAS_INNERUSERGROUP> list = null;
|
||
if (string.IsNullOrWhiteSpace(groups))
|
||
list = GetList_InnerUserGroup();//group为空返回所有
|
||
else
|
||
{
|
||
decimal[] groupdIds = OperationUtil.ConvertToDecimal(groups.Trim().Split(','));
|
||
list = GetList_InnerUserGroup().Where(m => groupdIds.Contains(m.GID.Value)).ToList();
|
||
}
|
||
|
||
string ids = "-1";
|
||
foreach (var item in list)
|
||
{
|
||
ids += "," + item.INNERUSERID;
|
||
}
|
||
return ids;
|
||
}
|
||
|
||
#endregion 员工组关系
|
||
|
||
#region 销售部列表
|
||
|
||
public List<BAS_SALESDEPARTMENT> GetList_SalesDepartMent()
|
||
{
|
||
string cacheKey = "cache_SalesDepartMent_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<WX.CRM.Model.Entity.BAS_SALESDEPARTMENT>>(cacheKey);
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
var list = db.BAS_SALESDEPARTMENT.OrderBy(m => m.CREATIONDATE).ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
public List<BAS_BUSINESSLINES> GetList_BusinessLines()
|
||
{
|
||
string cacheKey = "cache_SGetList_BusinessLines_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<WX.CRM.Model.Entity.BAS_BUSINESSLINES>>(cacheKey);
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
var list = db.BAS_BUSINESSLINES.OrderBy(m => m.BUSINESSID).ToList();
|
||
CacheHelper.Set(cacheKey, list, DateTime.Now.AddMinutes(30));
|
||
return list;
|
||
}
|
||
}
|
||
|
||
public List<BAS_BUSINESSCHANNEL> GetList_BusinessChannels()
|
||
{
|
||
var cacheKey = "cache_GetList_BusinessChannels";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<BAS_BUSINESSCHANNEL>>(cacheKey);
|
||
using (var db = new crmContext())
|
||
{
|
||
var list = db.BAS_BUSINESSCHANNEL.ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
public Dictionary<string, List<BAS_BUSINESSLINES>> GetList_OrderDeptBusiness()
|
||
{
|
||
string cacheKey = "cache_saleCodeLineMap_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<Dictionary<string, List<BAS_BUSINESSLINES>>>(cacheKey);
|
||
var deptList = GetList_SalesDepartMent().Where(n => n.CHANNELDEF.HasValue).ToList();
|
||
Dictionary<string, List<BAS_BUSINESSLINES>> res = new Dictionary<string, List<BAS_BUSINESSLINES>>();
|
||
UserServices userservices = new UserServices(new CACHE_BL());
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
var ch = decimal.Parse(Utility.GetSettingOrNullByKey("Channel"));
|
||
var businessList = GetList_BusinessLines();
|
||
//var deptCodeList = GetList_SalesDepartMent().Where(n => filterIds.Contains(n.SALEDEPTID) && n.CHANNELDEF != null).Select(n => n.SALEDEPTCODE).ToList();
|
||
var defaultBusiness = db.BAS_BUSINESSCHANNEL.FirstOrDefault(n => n.MINCHANNEL <= ch && n.MAXCHANNEL >= ch);
|
||
if (defaultBusiness != null)
|
||
{
|
||
var defaultLine = businessList.FirstOrDefault(n => n.BUSINESSID == defaultBusiness.BUSINESSID);
|
||
res.Add("default", new List<BAS_BUSINESSLINES> { defaultLine });
|
||
}
|
||
foreach (var item in deptList)
|
||
{
|
||
List<decimal> ALLdeptIDS = new List<decimal>();
|
||
List<decimal> ALLgidS = new List<decimal>();
|
||
//向下遍历
|
||
userservices.GetAllDeptIDOrGidByDeptStr(item.SALEDEPTID.ToString(), ref ALLdeptIDS, ref ALLgidS);
|
||
var pardeptList = userservices.GetParentDeptId(item.SALEDEPTID);
|
||
ALLdeptIDS.AddRange(pardeptList);
|
||
var busDeptList = db.BAS_BUSINESSDEPARTMENT.Where(n => ALLdeptIDS.Contains(n.DEPTID)).ToList();
|
||
var lineList = businessList.Where(n => busDeptList.Select(m => m.BUSINESSID).Contains(n.BUSINESSID)).ToList();
|
||
if (!res.ContainsKey(item.SALEDEPTCODE))
|
||
{
|
||
res.Add(item.SALEDEPTCODE, lineList);
|
||
}
|
||
}
|
||
CacheHelper.Set(cacheKey, res);
|
||
}
|
||
return res;
|
||
}
|
||
|
||
#endregion 销售部列表
|
||
#region 业务线关系
|
||
|
||
/// <summary>
|
||
/// 业务线部门关系表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<BAS_BUSINESSDEPARTMENT> GetList_BussinessDepartMent()
|
||
{
|
||
string cacheKey = "cache_BussinessDepartMent_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<WX.CRM.Model.Entity.BAS_BUSINESSDEPARTMENT>>(cacheKey);
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
var list = db.BAS_BUSINESSDEPARTMENT.OrderBy(m => m.CTIME).ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 业务线
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<BAS_BUSINESSLINES> GetList_BussinessLine()
|
||
{
|
||
string cacheKey = "cache_GetList_BussinessLine_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<WX.CRM.Model.Entity.BAS_BUSINESSLINES>>(cacheKey);
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
var list = db.BAS_BUSINESSLINES.OrderBy(m => m.CTIME).ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
public List<DeptLineMap> GetList_deptLineMap()
|
||
{
|
||
string cacheKey = "cache_GetList_deptLineMap";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
{
|
||
return CacheHelper.Get<List<DeptLineMap>>(cacheKey);
|
||
}
|
||
else
|
||
{
|
||
var lineDept = GetList_BussinessDepartMent();
|
||
var saleList = GetList_SalesDepartMent();
|
||
List<DeptLineMap> res = new List<DeptLineMap>();
|
||
foreach (var item in lineDept)
|
||
{
|
||
var dept = saleList.FirstOrDefault(n => n.SALEDEPTID == item.DEPTID);
|
||
if (dept == null)
|
||
{
|
||
continue;
|
||
}
|
||
var newMap = new DeptLineMap
|
||
{
|
||
deptid = new List<decimal> { item.BUSINESSID },
|
||
saleId = item.DEPTID,
|
||
deptName = dept.DEPTNAME
|
||
};
|
||
//res.Add(newMap);
|
||
BuildSaleLine(res, saleList, newMap);
|
||
}
|
||
CacheHelper.Set(cacheKey, res);
|
||
return res;
|
||
}
|
||
}
|
||
|
||
public void BuildSaleLine(List<DeptLineMap> res, List<BAS_SALESDEPARTMENT> deptList, DeptLineMap nowItem)
|
||
{
|
||
if (!res.Exists(n => n.saleId == nowItem.saleId))
|
||
{
|
||
res.Add(nowItem);
|
||
}
|
||
var dept = deptList.FirstOrDefault(n => n.SALEDEPTID == nowItem.saleId);
|
||
var parentItem = deptList.FirstOrDefault(n => n.DEPARTMENT_ID == dept.DEPARTMENT_PARENTID && dept.DEPARTMENT_PARENTID.HasValue);
|
||
if (parentItem == null)
|
||
{
|
||
return;
|
||
}
|
||
if (parentItem != null)
|
||
{
|
||
var parMap = res.FirstOrDefault(n => n.saleId == parentItem.SALEDEPTID);
|
||
var nextMap = new DeptLineMap();
|
||
if (parMap == null)
|
||
{
|
||
nextMap = new DeptLineMap
|
||
{
|
||
saleId = parentItem.SALEDEPTID,
|
||
deptid = nowItem.deptid,
|
||
deptName = parentItem.DEPTNAME
|
||
};
|
||
}
|
||
else
|
||
{
|
||
var deptids = new List<decimal>();
|
||
deptids.AddRange(parMap.deptid);
|
||
deptids.AddRange(nowItem.deptid);
|
||
//parMap.deptid.AddRange(nowItem.deptid);
|
||
parMap.deptid = deptids.Distinct().ToList();
|
||
nextMap.deptid = parMap.deptid;
|
||
nextMap.saleId = parMap.saleId;
|
||
}
|
||
BuildSaleLine(res, deptList, nextMap);
|
||
}
|
||
}
|
||
|
||
#endregion 业务线关系
|
||
#region 菜单缓存
|
||
|
||
/// <summary>
|
||
/// 菜单缓存
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<BAS_LEFTMEMU> GetList_LeftMemu()
|
||
{
|
||
string cacheKey = "cache_LeftMemu_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<BAS_LEFTMEMU>>(cacheKey);
|
||
using (var db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
var list = db.BAS_LEFTMEMU.ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 模块导航菜单缓存
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<BAS_MODULEMENU> GetList_ModuleMenu()
|
||
{
|
||
string cacheKey = "cache_ModuleMenu_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<BAS_MODULEMENU>>(cacheKey);
|
||
using (var db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
var list = db.BAS_MODULEMENU.OrderBy(m => m.SORTID).ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion 菜单缓存
|
||
|
||
#region 获取软件活动信息
|
||
|
||
/// <summary>
|
||
/// 获取软件活动信息
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<SOFT_ACTIVE> GetList_SoftProduct()
|
||
{
|
||
string cacheKey = "cache_softproduct_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<WX.CRM.Model.Entity.SOFT_ACTIVE>>(cacheKey);
|
||
using (crmContext db = new crmContext())
|
||
{
|
||
List<SOFT_ACTIVE> list = db.SOFT_ACTIVE.ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion 获取软件活动信息
|
||
|
||
#region 桌面信息缓存
|
||
|
||
/// <summary>
|
||
/// 获取最新开户信息(五分钟过期)
|
||
/// </summary>
|
||
/// <param name="userId">根据用户来存储</param>
|
||
/// <returns></returns>
|
||
public List<CSVR_MSGOPENACCOUNT> GetNewOpenAccountList(decimal userId)
|
||
{
|
||
string cacheKey = "cache_msgOpenAccountList" + userId.ToString();
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<CSVR_MSGOPENACCOUNT>>(cacheKey);
|
||
using (var db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
List<CSVR_MSGOPENACCOUNT> list = db.CSVR_MSGOPENACCOUNT.Where(m => m.SALESID == userId).OrderByDescending(m => m.CTIME).Take(10).ToList();
|
||
|
||
CacheHelper.Set(cacheKey, list, DateTime.Now.AddMinutes(5), false);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取最近通话记录(五分钟过期)
|
||
/// </summary>
|
||
/// <param name="eid">用户工号</param>
|
||
/// <returns></returns>
|
||
public List<CSVR_CALLINLOG> GetCallInLogList(decimal eid)
|
||
{
|
||
string cacheKey = "cache_callInLogList" + eid.ToString();
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<CSVR_CALLINLOG>>(cacheKey);
|
||
using (var db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
List<CSVR_CALLINLOG> list = db.CSVR_CALLINLOG.Where(m => m.SALESEID == eid).OrderByDescending(m => m.CTIME).Take(10).ToList();
|
||
CacheHelper.Set(cacheKey, list, DateTime.Now.AddMinutes(5), false);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取最近通话记录(五分钟过期)
|
||
/// </summary>
|
||
/// <param name="eid">用户工号</param>
|
||
/// <returns></returns>
|
||
public List<CSVR_TODAYRECORD> GetCallLogList(decimal eid)
|
||
{
|
||
string cacheKey = "cache_callLogList" + eid.ToString();
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<CSVR_TODAYRECORD>>(cacheKey);
|
||
using (var db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
List<CSVR_TODAYRECORD> list = db.CSVR_TODAYRECORD.Where(m => m.SALESEID == eid).OrderByDescending(m => m.CTIME).Take(10).ToList();
|
||
CacheHelper.Set(cacheKey, list, DateTime.Now.AddMinutes(5), false);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion 桌面信息缓存
|
||
|
||
#region l2 产品
|
||
|
||
public List<L2Soft_ProductDetail> GetProductDetail()
|
||
{
|
||
string cacheKey = "cache_L2SoftProduct_getList";
|
||
List<L2Soft_ProductDetail> list;
|
||
if (CacheHelper.Exists(cacheKey))
|
||
list = CacheHelper.Get<List<L2Soft_ProductDetail>>(cacheKey);
|
||
else
|
||
using (crmContext db = new crmContext())
|
||
{
|
||
var queryData = (from a in db.L2_SOFT_BIGPRODUCT
|
||
select new L2Soft_ProductDetail()
|
||
{
|
||
PRODUCTID = a.PRODUCTID,
|
||
PRODUCTCODE = a.PRODUCTCODE,
|
||
PRODUCTNAME = a.PRODUCTNAME,
|
||
ISDISABLED = a.ISDISABLED,
|
||
USECLIENT = a.USECLIENT,
|
||
GROUPID = a.GROUPID,
|
||
softProduct = (from b in db.L2_SOFT_PRODUCT
|
||
where b.BIGPRODUCTID == a.PRODUCTID
|
||
select new L2Soft_Product()
|
||
{
|
||
PRODUCTID = b.PRODUCTID,
|
||
PRODUCTCODE = b.PRODUCTCODE,
|
||
PRODUCTNAME = b.PRODUCTNAME,
|
||
PRICE = b.PRICE,
|
||
DAYS = b.DAYS,
|
||
ISDISABLED = b.ISDISABLED,
|
||
softModule = (from c in db.L2_SOFT_PRODUCTMODULE
|
||
join d
|
||
in db.L2_SOFT_MODULE on c.MODULEID equals d.MODULEID
|
||
where c.PRODUCTID == b.PRODUCTID
|
||
select new L2Soft_Module()
|
||
{
|
||
MODULEID = d.MODULEID,
|
||
MODULENAME = d.MODULENAME,
|
||
DEFAULTDAYS = d.DEFAULTDAYS
|
||
})
|
||
})
|
||
}
|
||
);
|
||
list = queryData.ToList();
|
||
}
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// L2产品大类
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<L2_SOFT_BIGPRODUCT> GetBigProductList()
|
||
{
|
||
List<L2_SOFT_BIGPRODUCT> list;
|
||
string cacheKey = "cache_L2SoftBigProduct_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
list = CacheHelper.Get<List<L2_SOFT_BIGPRODUCT>>(cacheKey);
|
||
else
|
||
using (var contex = new Model.Entity.crmContext())
|
||
{
|
||
list = contex.L2_SOFT_BIGPRODUCT.ToList();
|
||
}
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// L2产品小类
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<L2_SOFT_PRODUCT> GetSProductList()
|
||
{
|
||
List<L2_SOFT_PRODUCT> list;
|
||
string cacheKey = "cache_L2SoftSProduct_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
list = CacheHelper.Get<List<L2_SOFT_PRODUCT>>(cacheKey);
|
||
else
|
||
using (var contex = new Model.Entity.crmContext())
|
||
{
|
||
list = contex.L2_SOFT_PRODUCT.ToList();
|
||
}
|
||
return list;
|
||
}
|
||
|
||
public List<SOFT_MODULE> GetAllModule()
|
||
{
|
||
List<SOFT_MODULE> list;
|
||
string cacheKey = "cache_L2SoftModel_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
list = CacheHelper.Get<List<SOFT_MODULE>>(cacheKey);
|
||
else
|
||
using (var contex = new Model.Entity.crmContext())
|
||
{
|
||
list = contex.SOFT_MODULE.ToList();
|
||
}
|
||
return list;
|
||
}
|
||
|
||
#endregion l2 产品
|
||
|
||
#region 录音分类
|
||
|
||
public List<CSVR_RECORDTYPE> GetList_RecordType()
|
||
{
|
||
List<CSVR_RECORDTYPE> list;
|
||
string cacheKey = "cache_RecordType_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
list = CacheHelper.Get<List<CSVR_RECORDTYPE>>(cacheKey);
|
||
else
|
||
using (var contex = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
list = contex.CSVR_RECORDTYPE.ToList();
|
||
}
|
||
return list;
|
||
}
|
||
|
||
#endregion 录音分类
|
||
|
||
#region 获取资源类型
|
||
|
||
public IList<RES_RESOURCETYPE> GetResourceType()
|
||
{
|
||
var cacheKey = "cache_resourcetype_getlist";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<RES_RESOURCETYPE>>(cacheKey);
|
||
using (crmContext db = new crmContext())
|
||
{
|
||
var list = db.RES_RESOURCETYPE.ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion 获取资源类型
|
||
|
||
#region 获取资源活动信息
|
||
|
||
/// <summary>
|
||
/// 获取软件活动信息
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<RES_ACTIVITY> GetList_ResActivity()
|
||
{
|
||
string cacheKey = "cache_resactivity_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<WX.CRM.Model.Entity.RES_ACTIVITY>>(cacheKey);
|
||
using (crmContext db = new crmContext())
|
||
{
|
||
List<RES_ACTIVITY> list = db.RES_ACTIVITY.ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion 获取资源活动信息
|
||
#region 房间
|
||
|
||
public List<WX.CRM.Model.Entity.BAS_ROOM> GetRoomList()
|
||
{
|
||
string cacheKey = "cache_Room_getList";
|
||
List<WX.CRM.Model.Entity.BAS_ROOM> modelist;
|
||
if (CacheHelper.Exists(cacheKey))
|
||
modelist = CacheHelper.Get<List<WX.CRM.Model.Entity.BAS_ROOM>>(cacheKey);
|
||
else
|
||
{
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
modelist = db.BAS_ROOM.ToList();
|
||
CacheHelper.Set(cacheKey, modelist);
|
||
}
|
||
}
|
||
return modelist;
|
||
}
|
||
|
||
#endregion 房间
|
||
|
||
public List<CSVR_CALLOUTPARA> GetList_CallOutPara()
|
||
{
|
||
List<CSVR_CALLOUTPARA> list;
|
||
string cacheKey = "cache_GetList_CallOutPara";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
list = CacheHelper.Get<List<CSVR_CALLOUTPARA>>(cacheKey);
|
||
else
|
||
using (var contex = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
list = contex.CSVR_CALLOUTPARA.ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
#region 获取主管信息
|
||
|
||
public IList<BAS_GROUPLEADER> GetGroupleaders()
|
||
{
|
||
string cacheKey = "cache_Groupleader_list";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<BAS_GROUPLEADER>>(cacheKey);
|
||
using (crmContext db = new crmContext())
|
||
{
|
||
List<BAS_GROUPLEADER> list = new BAS_GROUPLEADER_BL().GetList(string.Empty, string.Empty);
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion 获取主管信息
|
||
|
||
#region 获取部门经理ID
|
||
|
||
public decimal GetDeptManager(decimal gid)
|
||
{
|
||
var roles = GetList_Role();
|
||
var BMZG = roles.FirstOrDefault(p => p.CODE == "BMZG");
|
||
if (BMZG == null)
|
||
return 0;
|
||
var userRole = GetUserRole().Where(p => p.ROLEID == BMZG.ROLEID);
|
||
var userGroup = GetList_InnerUserGroup().FirstOrDefault(p => userRole.Select(m => m.INNERUSERID).Contains(p.INNERUSERID) && p.GID == gid);
|
||
if (userGroup == null)
|
||
return 0;
|
||
return userGroup.INNERUSERID;
|
||
}
|
||
|
||
#endregion 获取部门经理ID
|
||
|
||
#region 获取actionlogconfig信息
|
||
|
||
public IList<BAS_ACTIONLOGCONFIG> GetActionLogConfig()
|
||
{
|
||
string cacheKey = "cache_actionlogconfig_list";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<BAS_ACTIONLOGCONFIG>>(cacheKey);
|
||
using (var db = new crmContext())
|
||
{
|
||
var list = new BAS_ACTIONLOGCONFIG_BL().GetList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list.ToList();
|
||
}
|
||
}
|
||
|
||
#endregion 获取actionlogconfig信息
|
||
|
||
#region 获取期货产品信息
|
||
|
||
/// <summary>
|
||
/// 获取产品信息
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<QH_PRODUCT> GetList_QH_Product()
|
||
{
|
||
string cacheKey = "cache_QH_product_getList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<Model.Entity.QH_PRODUCT>>(cacheKey);
|
||
using (crmContext db = new crmContext())
|
||
{
|
||
List<QH_PRODUCT> list = db.QH_PRODUCT.ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion 获取期货产品信息
|
||
|
||
#region
|
||
|
||
public Dictionary<decimal, decimal> GetResSalesgroup()
|
||
{
|
||
var cacheKey = "cache_Res_SalesGroup";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<Dictionary<decimal, decimal>>(cacheKey);
|
||
using (var db = new crmContext())
|
||
{
|
||
var arr = new List<decimal>() { 1493850899, 1617255440 };
|
||
var list = db.RES_SALESGROUP_DETAIL.Where(p => arr.Contains(p.GROUPID)).ToDictionary(p => p.INNERUSERID, p => p.GROUPID);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 省
|
||
|
||
public List<BAS_PROVINCE> GetProvince()
|
||
{
|
||
var cacheKey = "cache_Province";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<BAS_PROVINCE>>(cacheKey);
|
||
using (var db = new crmContext())
|
||
{
|
||
var list = db.BAS_PROVINCE.ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 市
|
||
|
||
public List<BAS_CITY> GetCity()
|
||
{
|
||
var cacheKey = "cache_City";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<BAS_CITY>>(cacheKey);
|
||
using (var db = new crmContext())
|
||
{
|
||
var list = db.BAS_CITY.ToList();
|
||
CacheHelper.Set(cacheKey, list);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
public Dictionary<int, string> GetAiHgrecordStatusnameKV()
|
||
{
|
||
Dictionary<int, string> Ai_hgrecord_statusnameKV = new Dictionary<int, string>();
|
||
Ai_hgrecord_statusnameKV.Add(-1, "忽略不做AI外呼");
|
||
Ai_hgrecord_statusnameKV.Add(0, "尚未进行AI外呼");
|
||
Ai_hgrecord_statusnameKV.Add(1, "等待AI外呼");
|
||
Ai_hgrecord_statusnameKV.Add(2, "AI外呼需人工介入");
|
||
Ai_hgrecord_statusnameKV.Add(5, "AI外呼成功");
|
||
Ai_hgrecord_statusnameKV.Add(4, "电子回访成功");
|
||
Ai_hgrecord_statusnameKV.Add(9, "人工回访成功");
|
||
return Ai_hgrecord_statusnameKV;
|
||
}
|
||
|
||
public List<AI_CallTaskConfigDto> GetAiConfig()
|
||
{
|
||
var cacheKey = "AiCallConfig";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<AI_CallTaskConfigDto>>(cacheKey);
|
||
return new List<AI_CallTaskConfigDto>();
|
||
}
|
||
|
||
#region 获取员工当前部门渠道
|
||
|
||
public string GetCurChannel(decimal userId)
|
||
{
|
||
var groups = GetGroupList();
|
||
var ug = GetList_InnerUserGroup();
|
||
var depment = GetList_SalesDepartMent();
|
||
|
||
var uginfo = ug.Find(p => p.INNERUSERID == userId);
|
||
if (uginfo != null)
|
||
{
|
||
var group = groups.Find(p => p.GID == uginfo.GID);
|
||
if (group != null)
|
||
{
|
||
var dep = depment.Find(p => p.SALEDEPTID == group.SALEDEPTID);
|
||
if (dep != null)
|
||
{
|
||
if (dep.CHANNELDEF.HasValue)
|
||
return dep.CHANNELDEF.Value.ToString();
|
||
}
|
||
}
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
public List<Dictionary<string, string>> GetDeptDownList()
|
||
{
|
||
var cacheKey = "cache_deptDownList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<List<Dictionary<string, string>>>(cacheKey);
|
||
var companyList = GetList_BusinessLines();
|
||
var list = GetDeptNameMapList();
|
||
var allChannel = new List<Dictionary<string, string>>();
|
||
foreach (var item in companyList)
|
||
{
|
||
var company = list.FirstOrDefault(n => n.id == item.BUSINESSID);
|
||
if (company != null)
|
||
{
|
||
var channel = new Dictionary<string, string>
|
||
{
|
||
{ "name", company.title },
|
||
{ "value", company.id.ToString() }
|
||
};
|
||
allChannel.Add(channel);
|
||
}
|
||
}
|
||
CacheHelper.Set(cacheKey, allChannel, DateTime.Now.AddDays(1));
|
||
return allChannel;
|
||
}
|
||
|
||
#endregion
|
||
#region 获取全部事业部相关配置
|
||
|
||
public List<DeptMapModel> GetDeptNameMapList()
|
||
{
|
||
List<DeptMapModel> list;
|
||
string cacheKey = "cache_GetList_GetDeptNameMapList";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
{
|
||
list = CacheHelper.Get<List<DeptMapModel>>(cacheKey);
|
||
}
|
||
else
|
||
{
|
||
var webapi = GetValue_Parameter(Parameter.ZXD_CORE_WEBAPI);
|
||
var url = $"{webapi}/Api/Deptment/Depts";
|
||
var dataJson = Utility.GetData(url, "", Encoding.UTF8);
|
||
var result = JsonConvert.DeserializeObject<DeptMapApiModel>(dataJson);
|
||
CacheHelper.Set(cacheKey, result.data, DateTime.Now.AddMinutes(30));
|
||
return result.data;
|
||
}
|
||
return list;
|
||
}
|
||
|
||
public Dictionary<int, string> ConvertChannelName(List<DeptMapModel> list, List<int> channelList)
|
||
{
|
||
Dictionary<int, string> res = new Dictionary<int, string>();
|
||
channelList = channelList.Distinct().ToList();
|
||
foreach (var channel in channelList)
|
||
{
|
||
foreach (var item in list)
|
||
{
|
||
foreach (var ch in item.deptmentCampains)
|
||
{
|
||
if (channel >= ch.startCampainId && channel <= ch.endCampainId)
|
||
{
|
||
if (res.ContainsKey(channel))
|
||
{
|
||
continue;
|
||
}
|
||
res.Add(channel, item.title);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return res;
|
||
}
|
||
|
||
public List<DeptChannelModel> ConvertChannelName(List<int> channelList)
|
||
{
|
||
var list = GetDeptNameMapList();
|
||
List<DeptChannelModel> res = new List<DeptChannelModel>();
|
||
Dictionary<int, string> res1 = new Dictionary<int, string>();
|
||
channelList = channelList.Distinct().ToList();
|
||
foreach (var channel in channelList)
|
||
{
|
||
foreach (var item in list)
|
||
{
|
||
foreach (var ch in item.deptmentCampains)
|
||
{
|
||
if (channel >= ch.startCampainId && channel <= ch.endCampainId)
|
||
{
|
||
res.Add(new DeptChannelModel
|
||
{
|
||
channel = channel,
|
||
title = item.title,
|
||
code = item.code,
|
||
id = item.id,
|
||
groupId = item.groupId.HasValue ? item.groupId.Value : 0
|
||
});
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return res;
|
||
}
|
||
|
||
public List<DeptMentReturnModel> GetUserDeptNameByEid(List<decimal> eidList)
|
||
{
|
||
eidList = eidList.Distinct().ToList();
|
||
List<DeptMentReturnModel> res = new List<DeptMentReturnModel>();
|
||
if (eidList.Count() == 0)
|
||
{
|
||
return res;
|
||
}
|
||
try
|
||
{
|
||
var url = GetValue_Parameter(Parameter.Core_ZxdService_WebApi);
|
||
url = $"{url}Api/SSO/GetDeptNameByEid";
|
||
var para = $"eidList={string.Join(",", eidList)}";
|
||
var data = Utility.GetData(url, para, Encoding.Default);
|
||
var apiData = Utility.ToObject<CRMApiData<List<DeptMentReturnModel>>>(data);
|
||
if (apiData.Code == 0)
|
||
{
|
||
res = apiData.Data;
|
||
}
|
||
else
|
||
{
|
||
throw new Exception(apiData.Message);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error($"获取SSO事业部失败{ex.Message}");
|
||
}
|
||
return res;
|
||
}
|
||
|
||
#endregion
|
||
#region 手机号新加密
|
||
|
||
public string GetPhonePublicKey()
|
||
{
|
||
var cacheKey = "PhonePublicKey";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<string>(cacheKey);
|
||
else
|
||
{
|
||
var phoneSetting = GetValue_Parameter("phoneSetting");
|
||
var set = JsonConvert.DeserializeObject<PhoneSetting>(phoneSetting);
|
||
// 读取PEM文件
|
||
string pemFilePath = $"{AppDomain.CurrentDomain.BaseDirectory}/{set.publicKey}";
|
||
string pemContent = File.ReadAllText(pemFilePath);
|
||
MSecurityHelper sHelper = new MSecurityHelper();
|
||
var publicKey = sHelper.PemToXml(pemContent, false);
|
||
CacheHelper.Set(cacheKey, publicKey);
|
||
return publicKey;
|
||
}
|
||
}
|
||
|
||
public string GetPhonePrivateKey()
|
||
{
|
||
var cacheKey = "PhonePrivateKey";
|
||
if (CacheHelper.Exists(cacheKey))
|
||
return CacheHelper.Get<string>(cacheKey);
|
||
else
|
||
{
|
||
var phoneSetting = GetValue_Parameter("phoneSetting");
|
||
var set = JsonConvert.DeserializeObject<PhoneSetting>(phoneSetting);
|
||
// 读取PEM文件
|
||
string pemFilePath = $"{AppDomain.CurrentDomain.BaseDirectory}/{set.privateKey}";
|
||
string pemContent = File.ReadAllText(pemFilePath);
|
||
MSecurityHelper sHelper = new MSecurityHelper();
|
||
var publicKey = sHelper.PemToXml(pemContent, true);
|
||
CacheHelper.Set(cacheKey, publicKey);
|
||
return publicKey;
|
||
}
|
||
}
|
||
|
||
public string GetUMid(string phone)
|
||
{
|
||
try
|
||
{
|
||
var phoneSetting = GetValue_Parameter("phoneSetting");
|
||
if (!string.IsNullOrWhiteSpace(phoneSetting))
|
||
{
|
||
var set = JsonConvert.DeserializeObject<PhoneSetting>(phoneSetting);
|
||
MSecurityHelper sHelper = new MSecurityHelper();
|
||
phone = phone.TrimStart('0').Replace(" ", "");
|
||
var jsonbody = new
|
||
{
|
||
name = set.key,
|
||
mobile = phone
|
||
};
|
||
var publickey = GetPhonePublicKey();
|
||
var privatekey = GetPhonePrivateKey();
|
||
var content = sHelper.content(jsonbody.ToJson(), publickey); //解密操作
|
||
var sign = sHelper.sign(content, privatekey);
|
||
var headers = new Dictionary<string, string>();
|
||
headers.Add("content", content);
|
||
headers.Add("sign", sign);
|
||
var postdata = new
|
||
{
|
||
name = set.key,
|
||
content = content,
|
||
sign = sign
|
||
};
|
||
var url = $"{set.url.Trim('/')}/encrypt";
|
||
//需要做成配置
|
||
LogHelper.Info($"开始请求接口{postdata.ToJson()}");
|
||
var urlResult = Utility.PostAjaxData(url, postdata.ToJson(), headers, Encoding.UTF8);
|
||
var signdata = JsonConvert.DeserializeObject<SignReturnData>(urlResult);
|
||
var resultdata = sHelper.decyptSign(signdata.sign, signdata.content, publickey, privatekey);
|
||
LogHelper.Info($"解密手机号得到{resultdata}");
|
||
var middata = JsonConvert.DeserializeObject<MidData>(resultdata);
|
||
if (middata != null && middata.code == 200)
|
||
{
|
||
return middata.data;
|
||
}
|
||
else
|
||
{
|
||
throw new Exception($"获取新的手机号失败Middata{resultdata}");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
throw new Exception($"获取新的手机号失败没有配置");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error($"获取新的手机号失败{ex.Message}");
|
||
throw ex;
|
||
}
|
||
}
|
||
public string GetPhone(string umid)
|
||
{
|
||
try
|
||
{
|
||
var phoneSetting = GetValue_Parameter("phoneSetting");
|
||
if (!string.IsNullOrWhiteSpace(phoneSetting))
|
||
{
|
||
var set = JsonConvert.DeserializeObject<PhoneSetting>(phoneSetting);
|
||
MSecurityHelper sHelper = new MSecurityHelper();
|
||
var jsonbody = new
|
||
{
|
||
name = set.key,
|
||
key = umid
|
||
};
|
||
var publickey = GetPhonePublicKey();
|
||
var privatekey = GetPhonePrivateKey();
|
||
var content = sHelper.content(jsonbody.ToJson(), publickey); //解密操作
|
||
var sign = sHelper.sign(content, privatekey);
|
||
var headers = new Dictionary<string, string>();
|
||
headers.Add("content", content);
|
||
headers.Add("sign", sign);
|
||
var postdata = new
|
||
{
|
||
name = set.key,
|
||
content = content,
|
||
sign = sign
|
||
};
|
||
var url = $"{set.url.Trim('/')}/decrypt";
|
||
//需要做成配置
|
||
LogHelper.Info($"开始请求接口{postdata.ToJson()}");
|
||
var urlResult = Utility.PostAjaxData(url, postdata.ToJson(), headers, Encoding.UTF8);
|
||
var signdata = JsonConvert.DeserializeObject<SignReturnData>(urlResult);
|
||
var resultdata = sHelper.decyptSign(signdata.sign, signdata.content, publickey, privatekey);
|
||
LogHelper.Info($"解密手机号得到{resultdata}");
|
||
var middata = JsonConvert.DeserializeObject<MidData>(resultdata);
|
||
if (middata != null && middata.code == 200)
|
||
{
|
||
return middata.data;
|
||
}
|
||
else
|
||
{
|
||
throw new Exception($"获取新的手机号失败Middata{resultdata}");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
throw new Exception($"获取新的手机号失败没有配置");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error($"获取新的手机号失败{ex.Message}");
|
||
throw ex;
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
|
||
#region 手机号加解密
|
||
|
||
public class PhoneSetting
|
||
{
|
||
public string key { get; set; }
|
||
public string url { get; set; }
|
||
public string publicKey { get; set; }
|
||
public string privateKey { get; set; }
|
||
}
|
||
|
||
#endregion
|
||
|
||
public class CRMApiData<T>
|
||
{
|
||
public int Code { get; set; }
|
||
public string Message { get; set; }
|
||
public T Data { get; set; }
|
||
}
|
||
|
||
public class DeptMentReturnModel
|
||
{
|
||
public decimal? Eid { get; set; }
|
||
public int? DeptId { get; set; }
|
||
public string DeptName { get; set; }
|
||
public int? SaleDeptId { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 下拉列表构建
|
||
/// </summary>
|
||
public class DropModel
|
||
{
|
||
public string id { get; set; }
|
||
public string state { get; set; }
|
||
public string text { get; set; }
|
||
public string attributes { get; set; }
|
||
public string iconCls { get; set; }
|
||
|
||
/// <summary>
|
||
/// 是否特殊 1 为专业部门 0为其他部门 3同为专业部门和其他部门
|
||
/// </summary>
|
||
public decimal? isspecial { get; set; }
|
||
|
||
/// <summary>
|
||
/// db Id
|
||
/// </summary>
|
||
public decimal orginId { get; set; }
|
||
|
||
/// <summary>
|
||
/// 下级Id
|
||
/// </summary>
|
||
public List<decimal> filterId { get; set; } = new List<decimal>();
|
||
|
||
/// <summary>
|
||
/// 关联id
|
||
/// </summary>
|
||
public decimal? relateId { get; set; }
|
||
|
||
/// <summary>
|
||
/// 1 部门 2 销售组 3 人员
|
||
/// </summary>
|
||
public decimal type { get; set; } = 1;
|
||
|
||
public List<DropModel> children { get; set; }
|
||
}
|
||
} |