Explorar o código

++市场客户资料

yuanrf hai 1 semana
pai
achega
2ee2562f6d
Modificáronse 1 ficheiros con 120 adicións e 6 borrados
  1. 120 6
      OASystem/OASystem.Api/Controllers/SearchController.cs

+ 120 - 6
OASystem/OASystem.Api/Controllers/SearchController.cs

@@ -11,6 +11,7 @@ using OASystem.Domain.Entities.Groups;
 using OASystem.Domain.ViewModels.Search;
 using OASystem.Infrastructure.Repositories.System;
 using static iTextSharp.text.pdf.AcroFields;
+using OASystem.Infrastructure.Repositories.CRM;
 
 namespace OASystem.API.Controllers
 {
@@ -24,15 +25,19 @@ namespace OASystem.API.Controllers
         private readonly SqlSugarClient _sqlSugar;
         private readonly DynamicSearchService<Grp_DelegationInfo> _groupSearchService;
         private readonly DynamicSearchService<NewClientDataView> _clientSearchService;
+
+        private readonly NewClientDataRepository _clientDataRepository;
         public SearchController(
             SqlSugarClient sqlSugar,
            DynamicSearchService<Grp_DelegationInfo> groupSearchService,
-           DynamicSearchService<NewClientDataView> clientSearchService
+           DynamicSearchService<NewClientDataView> clientSearchService,
+           NewClientDataRepository clientDataRepository
            )
         {
             _sqlSugar = sqlSugar;
             _groupSearchService = groupSearchService;
             _clientSearchService = clientSearchService;
+            _clientDataRepository = clientDataRepository;
         }
 
         /// <summary>
@@ -108,7 +113,7 @@ namespace OASystem.API.Controllers
         /// <returns></returns>
         [HttpGet("group/{userId}/{keyword}")]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> ClientKeywordSearch(int userId,string keyword)
+        public async Task<IActionResult> ClientKeywordSearch(int userId, string keyword)
         {
             try
             {
@@ -132,7 +137,115 @@ namespace OASystem.API.Controllers
                 var data = _sqlSugar.Queryable<Crm_NewClientData>()
                     .Where(x => x.IsDel == 0 && clientIds.Contains(x.Id))
                     .OrderByDescending(x => x.CreateTime)
-                    .Select(x => new NewClientDataView (){
+                    .Select(x => new NewClientDataView()
+                    {
+                        Id = x.Id,
+                        Client = x.Client,
+                        Contact = x.Contact,
+                        Job = x.Job,
+                        Telephone = x.Telephone,
+                        Location = x.Location,
+                    })
+                    .ToList();
+                int index = 0;
+                data.ForEach(x =>
+                {
+                    index++;
+                    x.RowNumber = index;
+                    x.Client = AesEncryptionHelper.Decrypt(x.Client);
+                    x.Contact = AesEncryptionHelper.Decrypt(x.Contact);
+                    x.Job = AesEncryptionHelper.Decrypt(x.Job);
+                    x.Telephone = AesEncryptionHelper.Decrypt(x.Telephone);
+                    x.Location = AesEncryptionHelper.Decrypt(x.Location);
+                });
+
+
+                var searchRequest = new DynamicSearchRequest
+                {
+                    Keyword = keyword,
+                    RequireAllSingleChars = true,
+                    PageIndex = 1,
+                    PageSize = 999999,
+                    FieldWeights = new Dictionary<string, int>
+                    {
+                        { "Client", 10 },
+                        { "Contact", 8 },
+                        { "Location", 6 }
+                    },
+                    OrderBy = "CreateTime"
+                };
+
+                // 验证字段配置
+                var validation = _clientSearchService.ValidateFieldConfig(
+                    searchRequest.FieldWeights,
+                    searchRequest.ReturnFields);
+
+                if (!validation.IsValid)
+                {
+                    return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
+                }
+
+                var result = _clientSearchService.SearchDataSource(searchRequest, data);
+
+                if (result.Success)
+                {
+                    var view = result.Items.Select(x => x.Data).ToList();
+
+                    int resetIndex = 0;
+                    view.ForEach(x =>
+                    {
+                        resetIndex++;
+                        x.RowNumber = resetIndex;
+                    });
+
+                    return Ok(JsonView(true, result.Message, view, view.Count));
+                }
+
+                return Ok(JsonView(true, "暂无数据"));
+            }
+            catch (Exception ex)
+            {
+                return Ok(JsonView(true, $"搜索服务暂时不可用!"));
+            }
+
+        }
+
+
+        /// <summary>
+        /// 客户资料
+        /// </summary>
+        /// <param name="userId">关键字</param>
+        /// <param name="keyword">关键字</param>
+        /// <returns></returns>
+        [HttpGet("ClientKeywordSearch/{userId}/{keyword}")]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> ClientKeywordSearchAll(int userId, string keyword)
+        {
+            try
+            {
+                // 验证请求参数
+                if (string.IsNullOrEmpty(keyword))
+                {
+                    return Ok(JsonView(true, $"暂无数据!"));
+                }
+
+                var userIds = _clientDataRepository.GetNewExistClient(userId).Select(x => x.Id).ToList();
+                //查询有权限的数据(包括负责用户)
+                var clientIds = await _sqlSugar
+                    .Queryable<Crm_ClientDataAndUser>()
+                    .Where(x => x.IsDel == 0 && userIds.Contains(x.usersId))
+                    .Select(x => x.NewClientDataId)
+                    .ToListAsync();
+                if (clientIds == null || clientIds.Count < 1)
+                {
+                    return Ok(JsonView(true, $"暂无数据!"));
+                }
+
+                var data = _sqlSugar.Queryable<Crm_NewClientData>()
+                    .Where(x => x.IsDel == 0 && clientIds.Contains(x.Id))
+                    .OrderByDescending(x => x.CreateTime)
+                    .Select(x => new NewClientDataView()
+                    {
                         Id = x.Id,
                         Client = x.Client,
                         Contact = x.Contact,
@@ -179,14 +292,15 @@ namespace OASystem.API.Controllers
                     return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
                 }
 
-                var result = _clientSearchService.SearchDataSource(searchRequest,data);
+                var result = _clientSearchService.SearchDataSource(searchRequest, data);
 
                 if (result.Success)
                 {
                     var view = result.Items.Select(x => x.Data).ToList();
 
                     int resetIndex = 0;
-                    view.ForEach(x => {
+                    view.ForEach(x =>
+                    {
                         resetIndex++;
                         x.RowNumber = resetIndex;
                     });
@@ -194,7 +308,7 @@ namespace OASystem.API.Controllers
                     return Ok(JsonView(true, result.Message, view, view.Count));
                 }
 
-                return Ok(JsonView(true,"暂无数据"));
+                return Ok(JsonView(true, "暂无数据"));
             }
             catch (Exception ex)
             {