Browse Source

Merge branch 'develop' of http://132.232.92.186:3000/XinXiBu/OA2023 into develop

yuanrf 3 months ago
parent
commit
c09ac0a1b9

+ 35 - 66
OASystem/OASystem.Infrastructure/Repositories/CRM/NewClientDataRepository.cs

@@ -22,6 +22,7 @@ using System.Collections;
 using System.Collections.Generic;
 using System.ComponentModel.Design;
 using System.Diagnostics;
+using System.Diagnostics.Contracts;
 using System.Linq;
 using System.Runtime.Intrinsics.Arm;
 using System.Text;
@@ -347,69 +348,56 @@ namespace OASystem.Infrastructure.Repositories.CRM
                 var NewClientDataView = new List<NewClientDataView>();
                 var count = 0;
                 string contact = dto.Contact, location = dto.Location, clientDto = dto.Client;
-                if (string.IsNullOrEmpty(contact) && string.IsNullOrEmpty(location) && string.IsNullOrEmpty(clientDto)) //数据库分页
-                {
-                    RefAsync<int> total = 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) //客户类别
-                    .OrderByDescending(x => x.CreateTime)
-                    .ToPageListAsync(pageIndex, pageSize, total);
-
-                    NewClientDataView = _mapper.Map<List<NewClientDataView>>(clientDatas);
-                    count = total;
 
-                }
-                else //代码层分页
+                var isSelectSearch = false;
+                var searchDataIds = new List<int>();
+                if (string.IsNullOrEmpty(contact) || string.IsNullOrEmpty(location) || string.IsNullOrEmpty(clientDto))
                 {
-                    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) //客户类别
-                    .OrderByDescending(x => x.CreateTime)
-                    .ToListAsync();
-                   
-                    if (!string.IsNullOrEmpty(contact) || !string.IsNullOrEmpty(location) || !string.IsNullOrEmpty(clientDto))
-                    {
-                        foreach (var data in clientDatas)
-                        {
-                            //EncryptionProcessor.DecryptProperties(data);
-                            if (!string.IsNullOrEmpty(contact)) data.Contact = AesEncryptionHelper.Decrypt(data.Contact);
-                            if (!string.IsNullOrEmpty(location)) data.Location = AesEncryptionHelper.Decrypt(data.Location);
-                            if (!string.IsNullOrEmpty(clientDto)) data.Client = AesEncryptionHelper.Decrypt(data.Client);
+                    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)
                     {
-                        clientDatas = clientDatas
+                        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)
                     {
-                        clientDatas = clientDatas.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))).ToList();
+                        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();
                     }
 
-                    int pIndex = dto.PageIndex * dto.PageSize - dto.PageSize + 1;
-                    int pSize = dto.PageIndex * dto.PageSize;
-                    int skip = (dto.PageIndex - 1) * dto.PageSize;
-                    count = clientDatas.Count;
-                    var pageData = clientDatas.OrderByDescending(x => x.CreateTime).Skip(skip).Take(dto.PageSize).ToList();
-                    NewClientDataView = _mapper.Map<List<NewClientDataView>>(pageData);
+                    if (searchDataIds.Count < 1) searchDataIds.Add(0);
                 }
 
+                RefAsync<int> total = 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)
+                .ToPageListAsync(pageIndex, pageSize, total);
+
+                NewClientDataView = _mapper.Map<List<NewClientDataView>>(clientDatas);
+                count = total;
+
+
                 var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0).ToList();
                 
                 #region 下拉框初始化数据
@@ -443,16 +431,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
                         int index = 1;
                         foreach (var item in NewClientDataView)
                         {
-                            //EncryptionProcessor.DecryptProperties(item); //解密
-
-                            item.Wechat = AesEncryptionHelper.Decrypt(item.Wechat);
-                            item.Job = AesEncryptionHelper.Decrypt(item.Job);
-                            item.Phone = AesEncryptionHelper.Decrypt(item.Phone);
-                            item.Telephone = AesEncryptionHelper.Decrypt(item.Telephone);
-                            item.Remark = AesEncryptionHelper.Decrypt(item.Remark);
-                             if(string.IsNullOrEmpty(contact)) item.Contact = AesEncryptionHelper.Decrypt(item.Contact);
-                            if (string.IsNullOrEmpty(clientDto)) item.Client = AesEncryptionHelper.Decrypt(item.Client);
-                            if (string.IsNullOrEmpty(location)) item.Location = AesEncryptionHelper.Decrypt(item.Location);
+                            EncryptionProcessor.DecryptProperties(item); //解密
 
                             item.RowNumber = index;
                             item.CategoryStr = setDatas.Find(x => x.Id == item.Category)?.Name ?? "-";
@@ -505,16 +484,6 @@ namespace OASystem.Infrastructure.Repositories.CRM
                                 Location = AesEncryptionHelper.Decrypt(item.Location),
                             });
 
-                            //newClientDataIOSViews.Add(new NewClientDataAndroidIOSView()
-                            //{
-                            //    RowNumber = index,
-                            //    Id = item.Id,
-                            //    Client = item.Client,
-                            //    Contact = item.Contact,
-                            //    Job = item.Job,
-                            //    Telephone = item.Telephone,
-                            //    Location = item.Location,
-                            //});
                             index++;
                         }