|
@@ -16,6 +16,7 @@ using OASystem.Domain.Enums;
|
|
|
using OASystem.Domain.ViewModels.CRM;
|
|
|
using OASystem.Domain.ViewModels.JuHeExchangeRate;
|
|
|
using OASystem.Domain.ViewModels.QiYeWeChat;
|
|
|
+using OASystem.Infrastructure.Tools;
|
|
|
using SqlSugar;
|
|
|
using System;
|
|
|
using System.Collections;
|
|
@@ -353,7 +354,6 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
-
|
|
|
var NewClientDataView = new List<NewClientDataView>();
|
|
|
var count = 0;
|
|
|
string contact = dto.Contact, location = dto.Location, clientDto = dto.Client;
|
|
@@ -1399,57 +1399,236 @@ namespace OASystem.Infrastructure.Repositories.CRM
|
|
|
return userArr;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/// <summary>
|
|
|
- /// 公司客户名单 缓存
|
|
|
+ /// 客户资料
|
|
|
+ /// excel download
|
|
|
/// </summary>
|
|
|
- /// <param name="opType">操作类型 1 获取全部 2 单条详情 3 添加 4 修改 5 删除</param>
|
|
|
- /// <param name="data"></param>
|
|
|
+ /// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<List<Crm_NewClientData>> NewClientDataRedis(int opType, Crm_NewClientData data = null)
|
|
|
+ public async Task<DataTable> NewClientDataExcelDownload(NewClientDataExcelDownloadDto dto)
|
|
|
{
|
|
|
- var datas = new List<Crm_NewClientData>();
|
|
|
- var opTypes = new List<int>() { 1, 2, 3, 4 };
|
|
|
- if (!opTypes.Any(x => x == opType)) return datas;
|
|
|
-
|
|
|
- var keyName = $"newClientDataStr";
|
|
|
- var newClientJson = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>(keyName);//string 取
|
|
|
- if (!string.IsNullOrEmpty(newClientJson)) datas = JsonConvert.DeserializeObject<List<Crm_NewClientData>>(newClientJson);
|
|
|
- if (opType == 1) //查询全部
|
|
|
+ var dt = new DataTable();
|
|
|
+
|
|
|
+ try
|
|
|
{
|
|
|
- if (datas != null && datas.Count > 0) return datas;
|
|
|
+ #region 交集
|
|
|
+ List<int> NewClientDataId1 = new List<int>();
|
|
|
+ List<int> NewClientDataId2 = new List<int>();
|
|
|
+ int state = 0;
|
|
|
|
|
|
- datas = await _sqlSugar.Queryable<Crm_NewClientData>().Where(x => x.IsDel == 0).ToListAsync();
|
|
|
- foreach (var item in datas) EncryptionProcessor.DecryptProperties(item);
|
|
|
+ #region 负责人
|
|
|
+ if (dto.OperationUserId != 21)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(dto.Userid))
|
|
|
+ {
|
|
|
+ dto.Userid = dto.OperationUserId.ToString();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- else if (opType == 2) //单条数据
|
|
|
- {
|
|
|
- if (datas != null && datas.Count > 0) return datas.Where(x => x.Id == data.Id).ToList();
|
|
|
+ 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 ascribedUser1 in ascribedUsers)
|
|
|
+ {
|
|
|
+ if (ascribedUser1.NewClientDataId != 0)
|
|
|
+ {
|
|
|
+ NewClientDataId1.Add(ascribedUser1.NewClientDataId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dt = null;
|
|
|
+ }
|
|
|
+ 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
|
|
|
+ {
|
|
|
+ dt = null;
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ if (dto.OperationUserId == 21)
|
|
|
+ {
|
|
|
+ intList = NewClientDataId2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (state == -1)
|
|
|
+ {
|
|
|
+ if (intList.Count < 1) intList.Add(-1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 省域条件
|
|
|
+ var rangeSetDataList = new List<int>();
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ rangeSetDataList = _sqlSugar.SqlQueryable<Sys_SetData>(setDataSql).Select(x => x.Id).ToList();
|
|
|
+
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ var NewClientDataView = new List<NewClientDataExcelDownloadView>();
|
|
|
+ var count = 0;
|
|
|
+ string contact = dto.Contact, location = dto.Location, clientDto = dto.Client;
|
|
|
+
|
|
|
+ var isSelectSearch = false;
|
|
|
+ var searchDataIds = new List<int>();
|
|
|
+ if (string.IsNullOrEmpty(contact) || string.IsNullOrEmpty(location) || string.IsNullOrEmpty(clientDto))
|
|
|
+ {
|
|
|
+ isSelectSearch = true;
|
|
|
+ var searchClientDatas = await _sqlSugar.Queryable<Crm_NewClientData>()
|
|
|
+ .Where(x => x.IsDel == 0)
|
|
|
+ .Select(x => new Crm_NewClientData() { Id = x.Id, Client = x.Client, Location = x.Location, Contact = x.Contact })
|
|
|
+ .ToListAsync();
|
|
|
+
|
|
|
+ foreach (var item in searchClientDatas) EncryptionProcessor.DecryptProperties(item);
|
|
|
+
|
|
|
+ if (dto.PortType == 1)
|
|
|
+ {
|
|
|
+ searchDataIds = searchClientDatas
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(contact), x => !string.IsNullOrEmpty(x.Contact) && x.Contact.Contains(contact)) //联系人条件
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(location), x => !string.IsNullOrEmpty(x.Location) && x.Location.Contains(location)) //地区条件
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(clientDto), x => !string.IsNullOrEmpty(x.Client) && x.Client.Contains(clientDto)) //单位条件
|
|
|
+ .Select(x => x.Id)
|
|
|
+ .ToList();
|
|
|
+ }
|
|
|
+ else if (dto.PortType == 2 || dto.PortType == 3)
|
|
|
+ {
|
|
|
+ searchDataIds = searchClientDatas
|
|
|
+ .Where(x => (!string.IsNullOrEmpty(x.Contact) && x.Contact.Contains(clientDto)) ||
|
|
|
+ (!string.IsNullOrEmpty(x.Location) && x.Location.Contains(clientDto)) ||
|
|
|
+ (!string.IsNullOrEmpty(x.Client) && x.Client.Contains(clientDto)))
|
|
|
+ .Select(x => x.Id)
|
|
|
+ .ToList();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (searchDataIds.Count < 1) searchDataIds.Add(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ var clientDatas = await _sqlSugar.Queryable<Crm_NewClientData>()
|
|
|
+ .Where(x => x.IsDel == 0)
|
|
|
+ .WhereIF(state == -1 && intList.Count > 0, x => intList.Contains(x.Id))
|
|
|
+ .WhereIF(dto.Lvlid != 0, x => x.Lvlid == dto.Lvlid) //地市州条件
|
|
|
+ .WhereIF(rangeSetDataList.Count > 0, x => rangeSetDataList.Contains(x.Lvlid)) //省域条件
|
|
|
+ .WhereIF(dto.Category > 0, x => x.Category == dto.Category) //客户类别
|
|
|
+ .WhereIF(isSelectSearch && searchDataIds.Count > 0, x => searchDataIds.Contains(x.Id)) //条件模糊查询
|
|
|
+ .OrderByDescending(x => x.CreateTime)
|
|
|
+ .ToListAsync();
|
|
|
+
|
|
|
+ NewClientDataView = _mapper.Map<List<NewClientDataExcelDownloadView>>(clientDatas);
|
|
|
+
|
|
|
+
|
|
|
+ if (!NewClientDataView.Any()) return dt;
|
|
|
+
|
|
|
+ var userDatas = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
|
|
|
+ var setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0).ToListAsync();
|
|
|
+ var 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 u1.ISDEL = 0").ToListAsync();
|
|
|
+
|
|
|
+ var 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 d1.ISDEL = 0").ToListAsync();
|
|
|
+
|
|
|
+ int index = 1;
|
|
|
+ foreach (var item in NewClientDataView)
|
|
|
+ {
|
|
|
+ EncryptionProcessor.DecryptProperties(item); //解密
|
|
|
+
|
|
|
+ item.RowNumber = index;
|
|
|
+ item.CreateUserName = userDatas.Find(x => x.Id == item.CreateUserId)?.CnName ?? "-";
|
|
|
+ item.CategoryStr = setDatas.Find(x => x.Id == item.Category)?.Name ?? "-";
|
|
|
+ item.LvlidStr = setDatas.Find(x => x.Id == item.Lvlid)?.Name ?? "-";
|
|
|
+ var currAscribedUser = ascribedUser.Where(x => x.NewClientDataId == item.Id).ToList();
|
|
|
+ if (currAscribedUser.Any()) item.AscribedUserLable = string.Join("、", currAscribedUser.Select(x => x.CnName).ToList());
|
|
|
+
|
|
|
+ var currAscribedDepartment = ascribedDepartment.Where(x => x.NewClientDataId == item.Id).ToList();
|
|
|
+ if (currAscribedDepartment.Any()) item.AscribedDepartmentLable = string.Join("、", currAscribedDepartment.Select(x => x.Name).ToList());
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+
|
|
|
+ dt = CommonFun.ToDataTableArray(NewClientDataView);
|
|
|
+ return dt;
|
|
|
|
|
|
- datas = await _sqlSugar.Queryable<Crm_NewClientData>().Where(x => x.IsDel == 0).ToListAsync();
|
|
|
- foreach (var item in datas) EncryptionProcessor.DecryptProperties(item);
|
|
|
- await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync(keyName, JsonConvert.SerializeObject(datas));//string 存
|
|
|
- return datas.Where(x => x.Id == data.Id).ToList();
|
|
|
- }
|
|
|
- else if (opType == 3) //添加
|
|
|
- {
|
|
|
- datas.Add(data);
|
|
|
- }
|
|
|
- else if (opType == 4) //修改
|
|
|
- {
|
|
|
- var updData = datas.Where(x => x.Id != data.Id).FirstOrDefault();
|
|
|
- if (updData != null) datas.Remove(updData);
|
|
|
- datas.Add(data);
|
|
|
}
|
|
|
- else if (opType == 5) //删除
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- var delData = datas.Where(x => x.Id == data.Id).FirstOrDefault();
|
|
|
- if (delData != null) datas.Remove(delData);
|
|
|
+ return dt;
|
|
|
}
|
|
|
-
|
|
|
- await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync(keyName, JsonConvert.SerializeObject(datas));//string 存
|
|
|
-
|
|
|
- return datas;
|
|
|
}
|
|
|
}
|
|
|
}
|