Przeglądaj źródła

商邀AI 新增联想搜索接口、数据清洗

Lyyyi 6 dni temu
rodzic
commit
0e0f06abd6

+ 19 - 24
OASystem/OASystem.Api/Controllers/ResourceController.cs

@@ -2281,25 +2281,20 @@ Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _m
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> InvitationAIInit()
         {
-            // 预定义 UnionAll 查询
-            var query1 = _sqlSugar.Queryable<Grp_DelegationInfo>()
-                .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.TeamName))
-                .Select(x => new InvitationAIInvNameView { Id = x.Id, Name = x.TeamName, Source = 1, SortTime = x.VisitDate });
-
-            var query2 = _sqlSugar.Queryable<Res_InvitationAI>()
-                .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.InvName))
-                .Select(x => new InvitationAIInvNameView { Id = x.Id, Name = x.InvName, Source = 2, SortTime = x.CreateTime });
-
-            var itemNames = await _sqlSugar.UnionAll(query1, query2)
-                .OrderByDescending(x => x.SortTime)
-                .Select(x => new { x.Id, x.Name, x.Source }) 
-                .ToListAsync();
+            var itemNames = await GeneralMethod.InvitationAIInvName();
 
             var invDatas = await _sqlSugar.Queryable<Crm_NewClientData>()
                 .Where(x => x.IsDel == 0)
+                .Where(x => !x.Client.Contains("-") && x.Client != null)
                 .Select(x => x.Client)
                 .ToListAsync();
 
+            invDatas = invDatas
+                .Where(c => !string.IsNullOrWhiteSpace(c)) // 确保非空
+                .Select(c => c.Replace(" ", ""))           // 去除所有空格
+                .Distinct()                                // 炼金:去重
+                .ToList();
+
             var countries = await _sqlSugar.Queryable<Sys_Countries>()
                 .Where(x => x.IsDel == 0)
                 .Select(x => x.Name_CN)
@@ -2321,9 +2316,8 @@ Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _m
             });
         }
 
-
         /// <summary>
-        /// 商邀资料AI 混元AI查询资料
+        /// 商邀资料AI 细聊列表
         /// </summary>
         /// <returns></returns>
         [HttpGet("{name}")]
@@ -2334,18 +2328,19 @@ Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _m
             if (string.IsNullOrWhiteSpace(name) )
                 return Ok(JsonView(false, "请传入有效的名称!"));
 
-            var infos = await _sqlSugar.Queryable<Res_InvitationAI>()
+            var info = await _sqlSugar.Queryable<Res_InvitationAI>()
                 .Where(x => x.IsDel == 0 && x.InvName == name)
-                .Select(x => new { 
-                    x.Id,
-                    x.InvName,
-                    x.GroupId,
-                    x.AiCrawledDetails,
-                    Entry = x.Entries.FirstOrDefault(),
-                })
                 .FirstAsync();
 
-            return Ok(JsonView(true, $"查询成功!", infos));
+            var view = new
+            {
+                info.Id,
+                info.InvName,
+                info.GroupId,
+                info.AiCrawledDetails,
+                Entry = info.Entries.FirstOrDefault(),
+            };
+            return Ok(JsonView(true, $"查询成功!", view));
         }
 
         /// <summary>

+ 64 - 0
OASystem/OASystem.Api/Controllers/SearchController.cs

@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using NPOI.SS.Formula.Functions;
 using NPOI.Util;
+using OASystem.API.OAMethodLib;
 using OASystem.API.OAMethodLib.DeepSeekAPI;
 using OASystem.API.OAMethodLib.GenericSearch;
 using OASystem.Domain.AesEncryption;
@@ -30,6 +31,7 @@ namespace OASystem.API.Controllers
         private readonly DelegationInfoRepository _groupRep;
         private readonly DynamicSearchService<Grp_DelegationInfo> _groupSearchService;
         private readonly DynamicSearchService<NewClientDataView> _clientSearchService;
+        private readonly DynamicSearchService<InvitationAIInvNameView> _invAISearchService;
         private readonly NewClientDataRepository _clientDataRepository;
 
         public SearchController(
@@ -37,6 +39,7 @@ namespace OASystem.API.Controllers
             DelegationInfoRepository groupRep,
             DynamicSearchService<Grp_DelegationInfo> groupSearchService,
             DynamicSearchService<NewClientDataView> clientSearchService,
+            DynamicSearchService<InvitationAIInvNameView> invAISearchService,
             NewClientDataRepository clientDataRepository
            )
         {
@@ -45,6 +48,7 @@ namespace OASystem.API.Controllers
             _groupSearchService = groupSearchService;
             _clientSearchService = clientSearchService;
             _clientDataRepository = clientDataRepository;
+            _invAISearchService = invAISearchService;
         }
 
         /// <summary>
@@ -735,5 +739,65 @@ namespace OASystem.API.Controllers
                 return Ok(JsonView(true, $"搜索服务暂时不可用!"));
             }
         }
+
+
+        /// <summary>
+        /// 商邀AI 关键字输入提示(单字段)
+        /// </summary>
+        /// <param name="keyword">关键字</param>
+        /// <returns></returns>
+        [HttpGet("ClientKeywordSearch/{keyword}")]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> InvAIKeywordSearch(string keyword)
+        {
+            try
+            {
+                // 验证请求参数 _invAISearchService
+                if (string.IsNullOrEmpty(keyword))
+                {
+                    return Ok(JsonView(true, $"暂无数据!"));
+                }
+
+                var invNames = await GeneralMethod.InvitationAIInvName();
+
+                var searchRequest = new DynamicSearchRequest
+                {
+                    Keyword = keyword,
+                    RequireAllSingleChars = true,
+                    PageIndex = 1,
+                    PageSize = 999999,
+                    FieldWeights = new Dictionary<string, int>
+                    {
+                        { "Name", 10 },
+                    },
+                    OrderBy = "SortTime"
+                };
+
+                // 验证字段配置
+                var validation = _invAISearchService.ValidateFieldConfig(
+                    searchRequest.FieldWeights,
+                    searchRequest.ReturnFields);
+
+                if (!validation.IsValid)
+                {
+                    return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
+                }
+
+                var result = _invAISearchService.SearchDataSource(searchRequest, invNames);
+
+                if (result.Success)
+                {
+                    var view = result.Items.Select(x => x.Data).ToList();
+
+                    return Ok(JsonView(true, result.Message, view, view.Count));
+                }
+
+                return Ok(JsonView(true, "暂无数据"));
+            }
+            catch (Exception ex)
+            {
+                return Ok(JsonView(true, $"搜索服务暂时不可用!"));
+            }
+        }
     }
 }

+ 31 - 0
OASystem/OASystem.Api/OAMethodLib/GeneralMethod.cs

@@ -1331,6 +1331,37 @@ namespace OASystem.API.OAMethodLib
             public int UserId { get; set; }
             public string UserName { get; set; }
         }
+        #endregion
+
+        #region 商邀AI invName 整合
+
+        /// <summary>
+        /// 商邀AI invName 整合
+        /// </summary>
+        /// <returns></returns>
+        public static async Task<List<InvitationAIInvNameView>> InvitationAIInvName()
+        {
+            // 预定义 UnionAll 查询
+            var query1 = _sqlSugar.Queryable<Grp_DelegationInfo>()
+                .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.TeamName))
+                .Select(x => new InvitationAIInvNameView { Id = x.Id, Name = x.TeamName, Source = 1, SortTime = x.VisitDate });
+
+            var query2 = _sqlSugar.Queryable<Res_InvitationAI>()
+                .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.InvName))
+                .Select(x => new InvitationAIInvNameView { Id = x.Id, Name = x.InvName, Source = 2, SortTime = x.CreateTime });
+
+            var unionQuery = _sqlSugar.UnionAll(query1, query2);
+
+            return await _sqlSugar.Queryable(unionQuery)
+                    .PartitionBy(it => it.Name)            // 按 Name 分组
+                    .OrderBy(it => it.Source)              // 优先级:Source=1 会排在 Source=2 之前
+                    .OrderByDescending(it => it.SortTime)  // 同 Source 下保留最新时间
+                    .Select(it => it)                      // 此时 SqlSugar 会自动应用 RowNumber == 1 的过滤
+                    .ToListAsync();
+        }
+
+
+
         #endregion
 
         #endregion