|
@@ -6,6 +6,7 @@ using NPOI.OpenXmlFormats.Dml.Diagram;
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
using NPOI.SS.UserModel;
|
|
|
using OASystem.Domain;
|
|
|
+using OASystem.Domain.AesEncryption;
|
|
|
using OASystem.Domain.Dtos;
|
|
|
using OASystem.Domain.Dtos.CRM;
|
|
|
using OASystem.Domain.Entities.Customer;
|
|
@@ -19,6 +20,7 @@ using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using System.ComponentModel.Design;
|
|
|
using System.Linq;
|
|
|
+using System.Runtime.Intrinsics.Arm;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Xml.Linq;
|
|
@@ -197,6 +199,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 客户资料初识初始化
|
|
|
/// </summary>
|
|
@@ -206,6 +209,338 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
{
|
|
|
Result result = new Result() { Code = -2, Msg = "未知错误" };
|
|
|
|
|
|
+ try
|
|
|
+ {
|
|
|
+ #region 交集
|
|
|
+ List<int> NewClientDataId1 = new List<int>();
|
|
|
+ List<int> NewClientDataId2 = new List<int>();
|
|
|
+ string NewClientDataId = "";
|
|
|
+ int state = 0;
|
|
|
+
|
|
|
+ #region 负责人
|
|
|
+ if (dto.OperationUserId != 21)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(dto.Userid))
|
|
|
+ {
|
|
|
+ dto.Userid = dto.OperationUserId.ToString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!string.IsNullOrWhiteSpace(dto.Userid))
|
|
|
+ {
|
|
|
+ string sql = string.Format(@"select u1.UsersId as UserId,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and u1.UsersId in ({0}) and u1.IsDel = 0", dto.Userid);
|
|
|
+ List<AscribedUser> ascribedUsers = await _sqlSugar.SqlQueryable<AscribedUser>(sql).ToListAsync();
|
|
|
+ if (ascribedUsers.Count != 0)
|
|
|
+ {
|
|
|
+ foreach (var ascribedUser in ascribedUsers)
|
|
|
+ {
|
|
|
+ if (ascribedUser.NewClientDataId != 0)
|
|
|
+ {
|
|
|
+ NewClientDataId1.Add(ascribedUser.NewClientDataId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result = new Result() { Code = -1, Msg = "暂无数据" };
|
|
|
+ }
|
|
|
+ state = -1;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 业务归属
|
|
|
+ if (!string.IsNullOrWhiteSpace(dto.Business))
|
|
|
+ {
|
|
|
+ string sql = string.Format(@"select d2.Id,d2.Name,d1.NewClientDataId from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and d1.SetDataId in ({0}) and d1.isdel = 0", dto.Business);
|
|
|
+ List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>(sql).ToListAsync();
|
|
|
+ if (AscribedDepartment.Count != 0)
|
|
|
+ {
|
|
|
+ foreach (var item in AscribedDepartment)
|
|
|
+ {
|
|
|
+ if (item.NewClientDataId != 0)
|
|
|
+ {
|
|
|
+ NewClientDataId2.Add(item.NewClientDataId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result = new Result() { Code = -1, Msg = "暂无数据" };
|
|
|
+ }
|
|
|
+ state = -1;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ List<int> intList = new List<int>();
|
|
|
+
|
|
|
+ if (NewClientDataId1.Count != 0 && NewClientDataId2.Count != 0)
|
|
|
+ {
|
|
|
+ intList = NewClientDataId1.Intersect(NewClientDataId2).ToList();
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (NewClientDataId1.Count != 0)
|
|
|
+ {
|
|
|
+ intList = NewClientDataId1;
|
|
|
+ }
|
|
|
+ else if (NewClientDataId2.Count != 0)
|
|
|
+ {
|
|
|
+ intList = NewClientDataId2;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ foreach (var item in intList)
|
|
|
+ {
|
|
|
+ NewClientDataId += item + ",";
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrWhiteSpace(NewClientDataId))
|
|
|
+ {
|
|
|
+ NewClientDataId = NewClientDataId.Substring(0, NewClientDataId.Length - 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ var clientDatas = await _sqlSugar.Queryable<Crm_NewClientData>().Where(x => x.IsDel == 0).ToListAsync();
|
|
|
+
|
|
|
+ string contact = dto.Contact,location = dto.Location,clientDto = dto.Client;
|
|
|
+ //aes 解密
|
|
|
+ foreach (var client in clientDatas)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(contact)) AesEncryptionHelper.Decrypt(client.Contact);
|
|
|
+ if (!string.IsNullOrEmpty(location)) AesEncryptionHelper.Decrypt(client.Location);
|
|
|
+ if (!string.IsNullOrEmpty(clientDto)) AesEncryptionHelper.Decrypt(client.Client);
|
|
|
+ }
|
|
|
+
|
|
|
+ string sqlWhere = string.Empty;
|
|
|
+
|
|
|
+ if (dto.PortType == 1)
|
|
|
+ {
|
|
|
+ clientDatas = clientDatas
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(contact), x => x.Contact.Contains(contact)) //联系人条件
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(location), x => x.Location.Contains(location)) //地区条件
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(clientDto), x => x.Client.Contains(clientDto)) //单位条件
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (dto.PortType == 2 || dto.PortType == 3)
|
|
|
+ {
|
|
|
+ clientDatas = clientDatas.Where(x => x.Contact.Contains(clientDto) || x.Location.Contains(clientDto) || x.Client.Contains(clientDto)).ToList();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (state == -1)
|
|
|
+ {
|
|
|
+ //intList
|
|
|
+
|
|
|
+ clientDatas = clientDatas.WhereIF(intList.Count > 0, x => intList.Contains(x.Id)).ToList();
|
|
|
+ }
|
|
|
+
|
|
|
+ #region 地市州条件
|
|
|
+ if (dto.Lvlid != 0)
|
|
|
+ {
|
|
|
+ clientDatas = clientDatas.Where(x => x.Lvlid == dto.Lvlid).ToList();
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 省域条件
|
|
|
+ if (dto.Range != 0)
|
|
|
+ {
|
|
|
+ string setDataSql = "select * from Sys_SetData where STid = 33 and isdel = 0 ";
|
|
|
+ switch (dto.Range)
|
|
|
+ {
|
|
|
+ case 419:
|
|
|
+ setDataSql += " and (Name like '%四%川%' or Name like '%成%都%')";
|
|
|
+ break;
|
|
|
+ case 421:
|
|
|
+ setDataSql += " and (Name like '%贵%州%' or Name like '%贵%阳%')";
|
|
|
+ break;
|
|
|
+ case 420:
|
|
|
+ setDataSql += " and (Name like '%云%南%' or Name like '%昆%明%')";
|
|
|
+ break;
|
|
|
+ case 423:
|
|
|
+ setDataSql += " and (Name like '%重庆%')";
|
|
|
+ break;
|
|
|
+ case 422:
|
|
|
+ setDataSql += " and (Name like '%西%藏%' or Name like '%拉%萨%')";
|
|
|
+ break;
|
|
|
+ case 578:
|
|
|
+ setDataSql += " and (Name like '%青%海%' or Name like '%西%宁%')";
|
|
|
+ break;
|
|
|
+ case 605:
|
|
|
+ setDataSql += " and (Name like '%陕%西%' or Name like '%西%安%')";
|
|
|
+ break;
|
|
|
+ case 606:
|
|
|
+ setDataSql += " and (Name like '%宁%夏%' or Name like '%银%川%')";
|
|
|
+ break;
|
|
|
+ case 625:
|
|
|
+ setDataSql += " and (Name like '%甘%肃%' or Name like '%兰%州%')";
|
|
|
+ break;
|
|
|
+ case 634:
|
|
|
+ setDataSql += " and (Name like '%新%疆%' or Name like '%乌%鲁%木%齐%')";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ var RangeSetDataList = _sqlSugar.SqlQueryable<Sys_SetData>(setDataSql).Select(x => x.Id).ToList();
|
|
|
+
|
|
|
+ clientDatas = clientDatas.WhereIF(RangeSetDataList.Count > 0, x => RangeSetDataList.Contains(x.Lvlid)).ToList();
|
|
|
+
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 客户类别
|
|
|
+ clientDatas = clientDatas.WhereIF(dto.Category > 0, x => x.Category == dto.Category).ToList();
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ int pIndex = dto.PageIndex * dto.PageSize - dto.PageSize + 1;
|
|
|
+ int pSize = dto.PageIndex * dto.PageSize;
|
|
|
+ int skip = (dto.PageIndex - 1) * dto.PageSize;
|
|
|
+
|
|
|
+ var pageData = clientDatas.OrderByDescending(x => x.CreateTime).Skip(skip).Take(dto.PageSize).ToList();
|
|
|
+
|
|
|
+ var NewClientDataView = _mapper.Map<List<NewClientDataView>>(pageData);
|
|
|
+ var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0).ToList();
|
|
|
+ int index = 1;
|
|
|
+ foreach (var item in NewClientDataView)
|
|
|
+ {
|
|
|
+ item.RowNumber = index;
|
|
|
+ item.CategoryStr = setDatas.Find(x => x.Id == item.Category)?.Name ?? "-";
|
|
|
+ item.LvlidStr = setDatas.Find(x => x.Id == item.Lvlid)?.Name ?? "-";
|
|
|
+ item.Weight = AesEncryptionHelper.Decrypt(item.Weight);
|
|
|
+ item.Client = AesEncryptionHelper.Decrypt(item.Client);
|
|
|
+ item.Contact = AesEncryptionHelper.Decrypt(item.Contact);
|
|
|
+ item.Job = AesEncryptionHelper.Decrypt(item.Job);
|
|
|
+ item.Telephone = AesEncryptionHelper.Decrypt(item.Telephone);
|
|
|
+ item.Phone = AesEncryptionHelper.Decrypt(item.Phone);
|
|
|
+ item.Location = AesEncryptionHelper.Decrypt(item.Location);
|
|
|
+ item.Remark = AesEncryptionHelper.Decrypt(item.Remark);
|
|
|
+
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+
|
|
|
+ #region 下拉框初始化数据
|
|
|
+ //负责人下拉框
|
|
|
+ var _Users = GetNewExistClient(dto.OperationUserId).Select(x => new { x.Id, Name = x.CnName }).ToList();
|
|
|
+
|
|
|
+ //省域数据
|
|
|
+ var _Province = setDatas.Where(u => u.STid == 42).Select(x => new { x.Id, x.Name }).ToList();
|
|
|
+
|
|
|
+ //客户级别数据
|
|
|
+ var _level = setDatas.Where(u => u.STid == 33).Select(x => new { x.Id, x.Name }).ToList();
|
|
|
+
|
|
|
+ //客户类别
|
|
|
+ var _CustomerClass = setDatas.Where(u => u.STid == 37).Select(x => new { x.Id, x.Name }).ToList();
|
|
|
+
|
|
|
+ //业务分类
|
|
|
+ var _ServiceClass = setDatas.Where(u => u.STid == 36).Select(x => new { x.Id, x.Name }).ToList();
|
|
|
+
|
|
|
+ #endregion
|
|
|
+ var groupNumber = await QueryNumberGroups();
|
|
|
+
|
|
|
+ if (NewClientDataView.Count > 0)
|
|
|
+ {
|
|
|
+ int count = clientDatas.Count;
|
|
|
+ float totalPage = (float)count / dto.PageSize;//总页数
|
|
|
+ if (totalPage == 0) totalPage = 1;
|
|
|
+ else totalPage = (int)Math.Ceiling((double)totalPage);
|
|
|
+
|
|
|
+ if (dto.PortType == 1)
|
|
|
+ {
|
|
|
+ foreach (var item in NewClientDataView)
|
|
|
+ {
|
|
|
+ List<AscribedUser> AscribedUser = await _sqlSugar.SqlQueryable<AscribedUser>
|
|
|
+ ("select u1.UsersId as UserId ,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and NewClientDataId=" + item.Id + " AND u1.ISDEL = 0").ToListAsync();
|
|
|
+ item.AscribedUser = AscribedUser;
|
|
|
+
|
|
|
+ List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>
|
|
|
+ ("select d2.Id,d2.Name,d1.NewClientDataId from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and NewClientDataId=" + item.Id + " AND d1.ISDEL = 0").ToListAsync();
|
|
|
+ item.AscribedDepartment = AscribedDepartment;
|
|
|
+ }
|
|
|
+
|
|
|
+ var Data = new
|
|
|
+ {
|
|
|
+ ClientTableData = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientDataView },
|
|
|
+ Users = _Users,
|
|
|
+ Province = _Province,
|
|
|
+ level = _level,
|
|
|
+ CustomerClass = _CustomerClass,
|
|
|
+ ServiceClass = _ServiceClass,
|
|
|
+ groupNumber = groupNumber.Data,
|
|
|
+ };
|
|
|
+ return result = new Result()
|
|
|
+ {
|
|
|
+ Code = 0,
|
|
|
+ Msg = "查询成功",
|
|
|
+ Data = Data
|
|
|
+ };
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (dto.PortType == 2 || dto.PortType == 3)
|
|
|
+ {
|
|
|
+
|
|
|
+ List<NewClientDataAndroidIOSView> newClientDataIOSViews = new List<NewClientDataAndroidIOSView>();
|
|
|
+ foreach (var item in NewClientDataView)
|
|
|
+ {
|
|
|
+
|
|
|
+ newClientDataIOSViews.Add(new NewClientDataAndroidIOSView()
|
|
|
+ {
|
|
|
+ RowNumber = item.RowNumber,
|
|
|
+ Id = item.Id,
|
|
|
+ Client = item.Client,
|
|
|
+ Contact = item.Contact,
|
|
|
+ Job = item.Job,
|
|
|
+ Telephone = item.Telephone,
|
|
|
+ Location = item.Location,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ result = new Result()
|
|
|
+ {
|
|
|
+ Code = 0,
|
|
|
+ Msg = "查询成功",
|
|
|
+ Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = newClientDataIOSViews },
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (dto.PortType == 2 || dto.PortType == 3)
|
|
|
+ {
|
|
|
+ var Data = new { pageCount = 0, totalPage = 0, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientDataView };
|
|
|
+ result = new Result() { Code = 0, Msg = "获取成功!", Data = Data };
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var Data = new
|
|
|
+ {
|
|
|
+
|
|
|
+ ClientTableData = new { pageCount = 0, totalPage = 0, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientDataView },
|
|
|
+ Users = _Users,
|
|
|
+ Province = _Province,
|
|
|
+ level = _level,
|
|
|
+ CustomerClass = _CustomerClass,
|
|
|
+ ServiceClass = _ServiceClass,
|
|
|
+ groupNumber = groupNumber.Data,
|
|
|
+ };
|
|
|
+ result = new Result() { Code = 0, Msg = "获取成功!", Data = Data };
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ result = new Result() { Code = -2, Msg = "未知错误" };
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 客户资料初识初始化
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<Result> QueryNewClientData1(NewClientDataQueryDto dto)
|
|
|
+ {
|
|
|
+ Result result = new Result() { Code = -2, Msg = "未知错误" };
|
|
|
+
|
|
|
try
|
|
|
{
|
|
|
#region 交集
|
|
@@ -806,6 +1141,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
NewClientDataView MapQueryData = null;
|
|
|
if (QueryData != null)
|
|
|
{
|
|
|
+ EncryptionProcessor.DecryptProperties(QueryData);
|
|
|
MapQueryData = _mapper.Map<NewClientDataView>(QueryData);
|
|
|
MapQueryData.AscribedUser = await _sqlSugar.SqlQueryable<AscribedUser>
|
|
|
("select u1.UsersId as UserId,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and NewClientDataId=" + dto.Id + " and u1.isdel = 0").ToListAsync();
|