Browse Source

列表查询优化

LEIYI 4 months ago
parent
commit
c84c6f645d

+ 21 - 13
OASystem/OASystem.Infrastructure/Repositories/CRM/NewClientDataRepository.cs

@@ -19,6 +19,7 @@ using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.ComponentModel.Design;
+using System.Diagnostics;
 using System.Linq;
 using System.Runtime.Intrinsics.Arm;
 using System.Text;
@@ -300,22 +301,29 @@ namespace OASystem.Infrastructure.Repositories.CRM
                 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)
+
+                Stopwatch stopwatch = Stopwatch.StartNew();
+
+                if (!string.IsNullOrEmpty(contact) || !string.IsNullOrEmpty(location) || !string.IsNullOrEmpty(clientDto))
                 {
-                    if (!string.IsNullOrEmpty(contact)) AesEncryptionHelper.Decrypt(client.Contact);
-                    if (!string.IsNullOrEmpty(location)) AesEncryptionHelper.Decrypt(client.Location);
-                    if (!string.IsNullOrEmpty(clientDto)) AesEncryptionHelper.Decrypt(client.Client);
+                    foreach (var client in clientDatas)
+                    {
+                        if (!string.IsNullOrEmpty(contact)) client.Contact = AesEncryptionHelper.Decrypt(client.Contact);
+                        if (!string.IsNullOrEmpty(location)) client.Location = AesEncryptionHelper.Decrypt(client.Location);
+                        if (!string.IsNullOrEmpty(clientDto)) client.Client = AesEncryptionHelper.Decrypt(client.Client);
+                    }
                 }
-                
+                stopwatch.Stop();
                 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)) //单位条件
+                        .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)) //单位条件
                         .ToList();
 
                 }
@@ -402,13 +410,13 @@ namespace OASystem.Infrastructure.Repositories.CRM
                     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);
+                    if (string.IsNullOrEmpty(contact)) item.Contact = AesEncryptionHelper.Decrypt(item.Contact);
+                    if (string.IsNullOrEmpty(location)) item.Location = AesEncryptionHelper.Decrypt(item.Location);
+                    if (string.IsNullOrEmpty(clientDto)) item.Client = AesEncryptionHelper.Decrypt(item.Client);
 
                     index++;
                 }
@@ -465,7 +473,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
                         return result = new Result()
                         {
                             Code = 0,
-                            Msg = "查询成功",
+                            Msg = $"查询成功!解密耗时: {stopwatch.ElapsedMilliseconds} 毫秒",
                             Data = Data
                         };
 
@@ -492,7 +500,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
                         result = new Result()
                         {
                             Code = 0,
-                            Msg = "查询成功",
+                            Msg = $"查询成功!解密耗时: {stopwatch.ElapsedMilliseconds} 毫秒",
                             Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = newClientDataIOSViews },
                         };
                     }