Selaa lähdekoodia

客户名单 新增根据UserId获取相关客户单位信息 接口

Lyyyi 2 päivää sitten
vanhempi
commit
0e6ce95f11

+ 62 - 5
OASystem/OASystem.Api/Controllers/MarketCustomerResourcesController.cs

@@ -1,5 +1,6 @@
 using Aspose.Cells;
 using EyeSoft.Extensions;
+using NPOI.SS.Formula.Functions;
 using OASystem.API.OAMethodLib;
 using OASystem.Domain.AesEncryption;
 using OASystem.Domain.Attributes;
@@ -9,6 +10,7 @@ using OASystem.Infrastructure.Repositories.CRM;
 using OASystem.RedisRepository;
 using System.Collections;
 using System.Data;
+using System.Diagnostics;
 using System.Net;
 using UAParser;
 
@@ -1285,6 +1287,65 @@ namespace OASystem.API.Controllers
             return Ok(jw);
         }
 
+        [HttpGet("UserId")]
+        public async Task<IActionResult> SearchClientByUserId(int userId)
+        {
+            var sw = Stopwatch.StartNew();
+            var jw = JsonView(true);
+            if (!await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == userId).AnyAsync())
+            {
+                jw.Code = StatusCodes.Status400BadRequest;
+                jw.Msg = $"请传入有效的UserId";
+                return Ok(jw);
+            }
+
+            var expression = Expressionable.Create<Crm_NewClientData>().And(x => x.IsDel == 0);
+
+            //获取个人的客户
+            if (userId != 21)
+            {
+                var userList = _clientDataRepository.GetNewExistClient(userId).Select(x => x.Id);
+                var newClientData = _sqlSugar.Queryable<Crm_ClientDataAndUser>()
+                    .Where(x => x.IsDel == 0 && userList.Contains(x.usersId))
+                    .Select(x => x.NewClientDataId)
+                    .Distinct()
+                    .ToList();
+                expression = expression.And(x => newClientData.Contains(x.Id));
+            }
+
+            string field = "Id,Client";
+            var newClitnData = _sqlSugar.Queryable<Crm_NewClientData>()
+                .Where(expression.ToExpression())
+                .Select(field)
+                .ToList();
+            foreach (var item in newClitnData)
+            {
+                EncryptionProcessor.DecryptProperties(item);
+            }
+
+            var matches = newClitnData
+                    .Where(fullString => !string.IsNullOrWhiteSpace(fullString.Client))
+                    .OrderByDescending(x => x.Id)
+                    .Select(x => new { x.Id, x.Client })
+                    .DistinctBy(x => x.Client)
+                    .ToList();
+
+            if (matches.Any())
+            {
+                jw.Data = matches;
+                jw.Count = matches.Count();
+            }
+            else
+            {
+                jw.Code = 201;
+                jw.Msg = "empty list";
+                jw.Data = new List<string>(1);
+            }
+
+            sw.Stop();
+            jw.Msg = $"操作成功!耗时:{sw.Elapsed.TotalMilliseconds}ms.";
+            return Ok(jw);
+        }
 
         [HttpPost]
         public async Task<IActionResult> QueryUnlockDropList()
@@ -1311,8 +1372,6 @@ namespace OASystem.API.Controllers
             return Ok(jw);
         }
 
-
-
         [HttpPost]
         public IActionResult InsertDataExcel(InsertDataExcelDto dto)
         {
@@ -1430,7 +1489,7 @@ namespace OASystem.API.Controllers
 
             // 获取表头(第一行作为列名)
             int headerRowIndex = 0; // 假设第一行是表头
-            Row headerRow = worksheet.Cells.Rows[headerRowIndex];
+            Aspose.Cells.Row headerRow = worksheet.Cells.Rows[headerRowIndex];
             int colCount = worksheet.Cells.MaxDataColumn + 1;
 
             // 动态存储列名
@@ -1594,8 +1653,6 @@ namespace OASystem.API.Controllers
         }
 
         #region 回滚数据记录
-
-
         //[HttpPost]
         //public async Task<IActionResult> actionResult()
         //{