SearchController.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. using EyeSoft.Collections.Generic;
  2. using Humanizer;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.Mvc;
  5. using NPOI.SS.Formula.Functions;
  6. using NPOI.Util;
  7. using OASystem.API.OAMethodLib;
  8. using OASystem.API.OAMethodLib.DeepSeekAPI;
  9. using OASystem.API.OAMethodLib.GenericSearch;
  10. using OASystem.Domain.AesEncryption;
  11. using OASystem.Domain.Entities.Customer;
  12. using OASystem.Domain.Entities.Financial;
  13. using OASystem.Domain.Entities.Groups;
  14. using OASystem.Domain.ViewModels.Groups;
  15. using OASystem.Domain.ViewModels.Search;
  16. using OASystem.Infrastructure.Repositories.CRM;
  17. using OASystem.Infrastructure.Repositories.Groups;
  18. using OASystem.Infrastructure.Repositories.System;
  19. using static iTextSharp.text.pdf.AcroFields;
  20. namespace OASystem.API.Controllers
  21. {
  22. /// <summary>
  23. /// 搜索
  24. /// </summary>
  25. [Route("api/search")]
  26. [ApiController]
  27. public class SearchController : ControllerBase
  28. {
  29. private readonly SqlSugarClient _sqlSugar;
  30. private readonly DelegationInfoRepository _groupRep;
  31. private readonly DynamicSearchService<Grp_DelegationInfo> _groupSearchService;
  32. private readonly DynamicSearchService<NewClientDataView> _clientSearchService;
  33. private readonly DynamicSearchService<InvitationAIInvNameView> _invAISearchService;
  34. private readonly NewClientDataRepository _clientDataRepository;
  35. public SearchController(
  36. SqlSugarClient sqlSugar,
  37. DelegationInfoRepository groupRep,
  38. DynamicSearchService<Grp_DelegationInfo> groupSearchService,
  39. DynamicSearchService<NewClientDataView> clientSearchService,
  40. DynamicSearchService<InvitationAIInvNameView> invAISearchService,
  41. NewClientDataRepository clientDataRepository
  42. )
  43. {
  44. _sqlSugar = sqlSugar;
  45. _groupRep = groupRep;
  46. _groupSearchService = groupSearchService;
  47. _clientSearchService = clientSearchService;
  48. _clientDataRepository = clientDataRepository;
  49. _invAISearchService = invAISearchService;
  50. }
  51. /// <summary>
  52. /// 接团信息 关键字输入提示(单字段)
  53. /// </summary>
  54. /// <param name="keyword">关键字</param>
  55. /// <returns></returns>
  56. [HttpGet("group/{keyword}")]
  57. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  58. public async Task<IActionResult> GroupKeywordSearch(string keyword)
  59. {
  60. try
  61. {
  62. // 验证请求参数
  63. if (string.IsNullOrEmpty(keyword))
  64. {
  65. return Ok(JsonView(true, $"暂无数据!"));
  66. }
  67. var searchRequest = new DynamicSearchRequest
  68. {
  69. Keyword = keyword,
  70. RequireAllSingleChars = true,
  71. PageIndex = 1,
  72. PageSize = 999999,
  73. FieldWeights = new Dictionary<string, int>
  74. {
  75. { "TeamName", 10 },
  76. //{ "ClientUnit", 8 },
  77. //{ "ClientName", 6 }
  78. },
  79. Filters = new List<SearchFilter>()
  80. {
  81. new(){Field = "IsDel",Operator="eq",Value="0" }
  82. },
  83. OrderBy = "TeamName",
  84. ReturnFields = new List<string>() { "TeamName" }
  85. };
  86. // 验证字段配置
  87. var validation = _groupSearchService.ValidateFieldConfig(
  88. searchRequest.FieldWeights,
  89. searchRequest.ReturnFields);
  90. if (!validation.IsValid)
  91. {
  92. return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
  93. }
  94. var result = await _groupSearchService.SearchAsync(searchRequest);
  95. if (result.Success)
  96. {
  97. var data = result.Items.Select(x => new { x.Data.Id, x.Data.TeamName }).ToList();
  98. return Ok(JsonView(true, result.Message, data, data.Count));
  99. }
  100. return Ok(JsonView(true, result.Message));
  101. }
  102. catch (Exception ex)
  103. {
  104. return Ok(JsonView(true, $"搜索服务暂时不可用!"));
  105. }
  106. }
  107. /// <summary>
  108. /// 客户资料 关键字输入提示(多字段)
  109. /// </summary>
  110. /// <param name="userId">关键字</param>
  111. /// <param name="keyword">关键字</param>
  112. /// <returns></returns>
  113. [HttpGet("group/{userId}/{keyword}")]
  114. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  115. public async Task<IActionResult> ClientKeywordSearch(int userId, string keyword)
  116. {
  117. try
  118. {
  119. // 验证请求参数
  120. if (string.IsNullOrEmpty(keyword))
  121. {
  122. return Ok(JsonView(true, $"暂无数据!"));
  123. }
  124. //查询有权限的数据
  125. var clientIds = await _sqlSugar
  126. .Queryable<Crm_ClientDataAndUser>()
  127. .Where(x => x.IsDel == 0 && x.usersId == userId)
  128. .Select(x => x.NewClientDataId)
  129. .ToListAsync();
  130. if (clientIds == null || clientIds.Count < 1)
  131. {
  132. return Ok(JsonView(true, $"暂无数据!"));
  133. }
  134. var data = _sqlSugar.Queryable<Crm_NewClientData>()
  135. .Where(x => x.IsDel == 0 && clientIds.Contains(x.Id))
  136. .OrderByDescending(x => x.CreateTime)
  137. .Select(x => new NewClientDataView()
  138. {
  139. Id = x.Id,
  140. Client = x.Client,
  141. Contact = x.Contact,
  142. Job = x.Job,
  143. Telephone = x.Telephone,
  144. Location = x.Location,
  145. })
  146. .ToList();
  147. int index = 0;
  148. data.ForEach(x =>
  149. {
  150. index++;
  151. x.RowNumber = index;
  152. x.Client = AesEncryptionHelper.Decrypt(x.Client);
  153. x.Contact = AesEncryptionHelper.Decrypt(x.Contact);
  154. x.Job = AesEncryptionHelper.Decrypt(x.Job);
  155. x.Telephone = AesEncryptionHelper.Decrypt(x.Telephone);
  156. x.Location = AesEncryptionHelper.Decrypt(x.Location);
  157. });
  158. var searchRequest = new DynamicSearchRequest
  159. {
  160. Keyword = keyword,
  161. RequireAllSingleChars = true,
  162. PageIndex = 1,
  163. PageSize = 999999,
  164. FieldWeights = new Dictionary<string, int>
  165. {
  166. { "Client", 10 },
  167. { "Contact", 8 },
  168. { "Location", 6 }
  169. },
  170. OrderBy = "CreateTime"
  171. };
  172. // 验证字段配置
  173. var validation = _clientSearchService.ValidateFieldConfig(
  174. searchRequest.FieldWeights,
  175. searchRequest.ReturnFields);
  176. if (!validation.IsValid)
  177. {
  178. return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
  179. }
  180. var result = _clientSearchService.SearchDataSource(searchRequest, data);
  181. if (result.Success)
  182. {
  183. var view = result.Items.Select(x => x.Data).ToList();
  184. int resetIndex = 0;
  185. view.ForEach(x =>
  186. {
  187. resetIndex++;
  188. x.RowNumber = resetIndex;
  189. });
  190. return Ok(JsonView(true, result.Message, view, view.Count));
  191. }
  192. return Ok(JsonView(true, "暂无数据"));
  193. }
  194. catch (Exception ex)
  195. {
  196. return Ok(JsonView(true, $"搜索服务暂时不可用!"));
  197. }
  198. }
  199. /// <summary>
  200. /// 客户资料
  201. /// </summary>
  202. /// <param name="userId">关键字</param>
  203. /// <param name="keyword">关键字</param>
  204. /// <returns></returns>
  205. [HttpGet("ClientKeywordSearch/{userId}/{keyword}")]
  206. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  207. public async Task<IActionResult> ClientKeywordSearchAll(int userId, string keyword)
  208. {
  209. try
  210. {
  211. // 验证请求参数
  212. if (string.IsNullOrEmpty(keyword))
  213. {
  214. return Ok(JsonView(true, $"暂无数据!"));
  215. }
  216. var userIds = _clientDataRepository.GetNewExistClient(userId).Select(x => x.Id).ToList();
  217. //查询有权限的数据(包括负责用户)
  218. var clientIds = await _sqlSugar
  219. .Queryable<Crm_ClientDataAndUser>()
  220. .Where(x => x.IsDel == 0 && userIds.Contains(x.usersId))
  221. .Select(x => x.NewClientDataId)
  222. .ToListAsync();
  223. if (clientIds == null || clientIds.Count < 1)
  224. {
  225. return Ok(JsonView(true, $"暂无数据!"));
  226. }
  227. var data = _sqlSugar.Queryable<Crm_NewClientData>()
  228. .Where(x => x.IsDel == 0 && clientIds.Contains(x.Id))
  229. .OrderByDescending(x => x.CreateTime)
  230. .Select(x => new NewClientDataView()
  231. {
  232. Id = x.Id,
  233. Client = x.Client,
  234. Contact = x.Contact,
  235. Job = x.Job,
  236. Telephone = x.Telephone,
  237. Location = x.Location,
  238. })
  239. .ToList();
  240. int index = 0;
  241. data.ForEach(x =>
  242. {
  243. index++;
  244. x.RowNumber = index;
  245. x.Client = AesEncryptionHelper.Decrypt(x.Client);
  246. x.Contact = AesEncryptionHelper.Decrypt(x.Contact);
  247. x.Job = AesEncryptionHelper.Decrypt(x.Job);
  248. x.Telephone = AesEncryptionHelper.Decrypt(x.Telephone);
  249. x.Location = AesEncryptionHelper.Decrypt(x.Location);
  250. });
  251. var searchRequest = new DynamicSearchRequest
  252. {
  253. Keyword = keyword,
  254. RequireAllSingleChars = true,
  255. PageIndex = 1,
  256. PageSize = 999999,
  257. FieldWeights = new Dictionary<string, int>
  258. {
  259. { "Client", 10 },
  260. { "Contact", 8 },
  261. { "Location", 6 }
  262. },
  263. OrderBy = "CreateTime"
  264. };
  265. // 验证字段配置
  266. var validation = _clientSearchService.ValidateFieldConfig(
  267. searchRequest.FieldWeights,
  268. searchRequest.ReturnFields);
  269. if (!validation.IsValid)
  270. {
  271. return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
  272. }
  273. var result = _clientSearchService.SearchDataSource(searchRequest, data);
  274. if (result.Success)
  275. {
  276. var view = result.Items.Select(x => x.Data).ToList();
  277. int resetIndex = 0;
  278. view.ForEach(x =>
  279. {
  280. resetIndex++;
  281. x.RowNumber = resetIndex;
  282. });
  283. return Ok(JsonView(true, result.Message, view, view.Count));
  284. }
  285. return Ok(JsonView(true, "暂无数据"));
  286. }
  287. catch (Exception ex)
  288. {
  289. return Ok(JsonView(true, $"搜索服务暂时不可用!"));
  290. }
  291. }
  292. /// <summary>
  293. /// 团组、会务流程 关键字输入提示(智能版)
  294. /// </summary>
  295. /// <param name="keyword">关键字</param>
  296. /// <returns></returns>
  297. [HttpGet]
  298. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  299. public async Task<IActionResult> ProcessKeywordSearch(string keyword)
  300. {
  301. try
  302. {
  303. // 验证请求参数
  304. if (string.IsNullOrEmpty(keyword))
  305. {
  306. return Ok(JsonView(true, $"暂无数据!"));
  307. }
  308. var searchRequest = new DynamicSearchRequest
  309. {
  310. Keyword = keyword,
  311. RequireAllSingleChars = true,
  312. PageIndex = 1,
  313. PageSize = 999999,
  314. FieldWeights = new Dictionary<string, int>
  315. {
  316. { "TeamName", 10 }
  317. },
  318. Filters = new List<SearchFilter>()
  319. {
  320. new(){Field = "IsDel",Operator="eq",Value="0" }
  321. },
  322. OrderBy = "VisitDate",
  323. ReturnFields = new List<string>() { "TeamName" }
  324. };
  325. // 验证字段配置
  326. var validation = _groupSearchService.ValidateFieldConfig(
  327. searchRequest.FieldWeights,
  328. searchRequest.ReturnFields);
  329. if (!validation.IsValid)
  330. {
  331. return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
  332. }
  333. var result = await _groupSearchService.SearchAsync(searchRequest);
  334. if (result.Success)
  335. {
  336. var data = new List<dynamic>();
  337. foreach (var item in result.Items)
  338. {
  339. data.Add(new
  340. {
  341. item.Data.Id,
  342. item.Data.TeamName,
  343. });
  344. }
  345. return Ok(JsonView(true, result.Message, data, data.Count));
  346. }
  347. return Ok(JsonView(true, result.Message));
  348. }
  349. catch (Exception ex)
  350. {
  351. return Ok(JsonView(true, $"搜索服务暂时不可用!"));
  352. }
  353. }
  354. /// <summary>
  355. /// 团组会务成本 关键字输入提示(智能版)
  356. /// </summary>
  357. /// <param name="keyword">关键字</param>
  358. /// <returns></returns>
  359. [HttpGet("ConferenceAffairsKeywordSearch/{keyword}")]
  360. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  361. public async Task<IActionResult> ConferenceAffairsKeywordSearch(string keyword)
  362. {
  363. try
  364. {
  365. // 验证请求参数
  366. if (string.IsNullOrEmpty(keyword))
  367. {
  368. return Ok(JsonView(true, $"暂无数据!"));
  369. }
  370. var hwIds = _sqlSugar.Queryable<Sys_SetData>()
  371. .Where(x => x.IsDel == 0 && x.STid == 10 && x.Name.Contains("会务活动"))
  372. .Select(x => x.Id)
  373. .ToList();
  374. var object_hwIds = hwIds.ConvertAll<object>(x => x);
  375. var searchRequest = new DynamicSearchRequest
  376. {
  377. Keyword = keyword,
  378. RequireAllSingleChars = true,
  379. PageIndex = 1,
  380. PageSize = 999999,
  381. FieldWeights = new Dictionary<string, int>
  382. {
  383. { "TeamName", 10 }
  384. },
  385. Filters = new List<SearchFilter>()
  386. {
  387. new(){Field = "IsDel",Operator="eq",Value="0" },
  388. new(){Field = "TeamDid",Operator="in",Values=object_hwIds }
  389. },
  390. OrderBy = "VisitDate",
  391. ReturnFields = new List<string>() { "TeamName" }
  392. };
  393. // 验证字段配置
  394. var validation = _groupSearchService.ValidateFieldConfig(
  395. searchRequest.FieldWeights,
  396. searchRequest.ReturnFields);
  397. if (!validation.IsValid)
  398. {
  399. return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
  400. }
  401. var result = await _groupSearchService.SearchAsync(searchRequest);
  402. if (result.Success)
  403. {
  404. var data = new List<dynamic>();
  405. foreach (var item in result.Items)
  406. {
  407. data.Add(new
  408. {
  409. item.Data.Id,
  410. item.Data.TeamName,
  411. });
  412. }
  413. return Ok(JsonView(true, result.Message, data, data.Count));
  414. }
  415. return Ok(JsonView(true, result.Message));
  416. }
  417. catch (Exception ex)
  418. {
  419. return Ok(JsonView(true, $"搜索服务暂时不可用!"));
  420. }
  421. }
  422. /// <summary>
  423. /// 团组各项费用录入 关键字输入提示(智能版)
  424. /// 76 酒店预订
  425. /// 79 车/导游地接
  426. /// 80 签证
  427. /// 81 邀请/公务活动
  428. /// 82 团组客户保险
  429. /// 85 机票预订
  430. /// 98 其他款项
  431. /// 285 收款退还
  432. /// 1015 超支费用
  433. /// 1081 文档下载
  434. /// 1466 会务相关
  435. /// </summary>
  436. /// <param name="userId">用户Id</param>
  437. /// <param name="feeType">费用类型</param>
  438. /// <param name="keyword">关键字</param>
  439. /// <returns></returns>
  440. [HttpGet("GroupFeeKeywordSearch/{userId}/{feeType}/{keyword}")]
  441. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  442. public async Task<IActionResult> GroupFeeKeywordSearch(int userId, int feeType, string keyword)
  443. {
  444. try
  445. {
  446. #region 参数验证
  447. // 基本参数验证
  448. if (userId <= 0)
  449. return Ok(JsonView(false, "用户ID必须大于0!"));
  450. if (feeType <= 0)
  451. return Ok(JsonView(false, "费用类型必须大于0!"));
  452. // 验证用户是否存在
  453. var userExists = await _sqlSugar.Queryable<Sys_Users>()
  454. .Where(x => x.IsDel == 0 && x.Id == userId)
  455. .AnyAsync();
  456. if (!userExists)
  457. {
  458. return Ok(JsonView(false, "用户不存在或已被删除"));
  459. }
  460. // 验证费用类型是否有效
  461. var feeTypeExists = await _sqlSugar.Queryable<Sys_SetData>()
  462. .Where(x => x.IsDel == 0 && x.STid == 16 && x.Id == feeType)
  463. .AnyAsync();
  464. if (!feeTypeExists)
  465. {
  466. return Ok(JsonView(false, "无效的费用类型"));
  467. }
  468. // 验证关键字
  469. if (string.IsNullOrWhiteSpace(keyword))
  470. {
  471. return Ok(JsonView(false, "请输入搜索关键字"));
  472. }
  473. #endregion
  474. #region 获取用户有权限的团组ID
  475. // 获取用户有权限访问的团组ID列表
  476. var authorizedGroupIds = await _sqlSugar.Queryable<Grp_GroupsTaskAssignment>()
  477. .Where(x => x.IsDel == 0 && x.UId == userId && x.CTId == feeType)
  478. .Select(x => x.DIId)
  479. .Distinct()
  480. .ToListAsync();
  481. if (!authorizedGroupIds.Any())
  482. {
  483. return Ok(JsonView(true, "暂无数据", new List<object>(), 0));
  484. }
  485. #endregion
  486. #region 构建搜索请求
  487. var searchRequest = new DynamicSearchRequest
  488. {
  489. Keyword = keyword.Trim(),
  490. RequireAllSingleChars = true,
  491. PageIndex = 1,
  492. PageSize = 20, // 限制返回数量,提高性能
  493. FieldWeights = new Dictionary<string, int>
  494. {
  495. { "TeamName", 10 }
  496. },
  497. Filters = new List<SearchFilter>
  498. {
  499. new SearchFilter { Field = "IsDel", Operator = "eq", Value = "0" },
  500. new SearchFilter { Field = "Id", Operator = "in", Values = authorizedGroupIds.ConvertAll<object>(x => x) }
  501. },
  502. OrderBy = "VisitDate", // 添加排序方向
  503. ReturnFields = new List<string> { "Id", "TeamName" } // 添加ID字段
  504. };
  505. #endregion
  506. #region 字段配置验证
  507. var validation = _groupSearchService.ValidateFieldConfig(
  508. searchRequest.FieldWeights,
  509. searchRequest.ReturnFields);
  510. if (!validation.IsValid)
  511. {
  512. return Ok(JsonView(false, $"字段配置错误: {validation.Message}"));
  513. }
  514. #endregion
  515. #region 执行搜索
  516. var result = await _groupSearchService.SearchAsync(searchRequest);
  517. if (!result.Success)
  518. {
  519. return Ok(JsonView(false, result.Message ?? "搜索失败"));
  520. }
  521. if (result.Items == null || !result.Items.Any())
  522. {
  523. return Ok(JsonView(true, "未找到匹配的团组", new List<object>(), 0));
  524. }
  525. #endregion
  526. #region 构建返回数据
  527. var responseData = result.Items
  528. .Where(item => item.Data != null)
  529. .Select(item => new
  530. {
  531. Id = item.Data.Id,
  532. TeamName = item.Data.TeamName
  533. })
  534. .Where(x => !string.IsNullOrWhiteSpace(x.TeamName)) // 过滤空名称
  535. .Distinct() // 去重
  536. .ToList();
  537. #endregion
  538. return Ok(JsonView(true, "搜索成功", responseData, responseData.Count));
  539. }
  540. catch (Exception ex)
  541. {
  542. // 记录日志(实际项目中应该使用日志框架)
  543. // _logger.LogError(ex, "团组费用关键字搜索失败,用户ID: {UserId}, 费用类型: {FeeType}", userId, feeType);
  544. // 生产环境中不要返回详细的错误信息
  545. return Ok(JsonView(false, "搜索服务暂时不可用,请稍后重试"));
  546. }
  547. }
  548. /// <summary>
  549. /// 三公-接团信息 关键字输入提示(单字段)
  550. /// </summary>
  551. /// <param name="currUserId">用户名称ID</param>
  552. /// <param name="keyword">关键字</param>
  553. /// <returns></returns>
  554. [HttpGet("GroupEnterExitCostKeywordSearch/{currUserId}/{keyword}")]
  555. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  556. public async Task<IActionResult> GroupEnterExitCostKeywordSearch(int currUserId,string keyword)
  557. {
  558. try
  559. {
  560. // 验证请求参数
  561. if (currUserId < 1)
  562. {
  563. return Ok(JsonView(true, $"请传入有效的用户ID!"));
  564. }
  565. if (string.IsNullOrEmpty(keyword))
  566. {
  567. return Ok(JsonView(true, $"暂无数据!"));
  568. }
  569. var searchRequest = new DynamicSearchRequest
  570. {
  571. Keyword = keyword,
  572. RequireAllSingleChars = true,
  573. PageIndex = 1,
  574. PageSize = 30,
  575. FieldWeights = new Dictionary<string, int>
  576. {
  577. { "TeamName", 10 },
  578. //{ "ClientUnit", 8 },
  579. //{ "ClientName", 6 }
  580. },
  581. Filters = new List<SearchFilter>()
  582. {
  583. new(){Field = "IsDel",Operator="eq",Value="0" }
  584. },
  585. OrderBy = "TeamName",
  586. ReturnFields = new List<string>() { "TeamName" }
  587. };
  588. // 验证字段配置
  589. var validation = _groupSearchService.ValidateFieldConfig(
  590. searchRequest.FieldWeights,
  591. searchRequest.ReturnFields);
  592. if (!validation.IsValid)
  593. {
  594. return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
  595. }
  596. var result = await _groupSearchService.SearchAsync(searchRequest);
  597. if (result.Success)
  598. {
  599. var groupIds = result.Items.Select(x => x.Data.Id).ToList();
  600. var isNullDatas = _sqlSugar.Queryable<Grp_EnterExitCost>()
  601. .Where(x => x.IsDel == 0 && groupIds.Contains(x.DiId))
  602. .Select(x => x.DiId)
  603. .Distinct()
  604. .ToList();
  605. var isViewDatas = _sqlSugar.Queryable<Grp_EnterExitCostPermission>()
  606. .Where(x1 => x1.IsDel == 0 && x1.UserId == currUserId && groupIds.Contains(x1.GroupId))
  607. .Select(x1 => x1.GroupId)
  608. .Distinct()
  609. .ToList();
  610. var provCityDatas = await _groupRep.ProvinceCityBasicSource();
  611. var data = result.Items.Select(x =>
  612. {
  613. int groupId = x.Data.Id;
  614. int cityId = x.Data.CityId;
  615. bool isNull = !isNullDatas.Where(x => x == groupId).Any();
  616. bool isView = isViewDatas.Where(x => x == groupId).Any();
  617. var provinceId = 122; //默认四川
  618. if (provinceId > 0)
  619. {
  620. var parentId = _groupRep.FindParentIdByChildId(provCityDatas, cityId);
  621. if (parentId != null)
  622. {
  623. provinceId = (int)parentId;
  624. }
  625. }
  626. return new
  627. {
  628. x.Data.Id,
  629. groupName = x.Data.TeamName,
  630. provinceId,
  631. isNull,
  632. isView,
  633. };
  634. }).ToList();
  635. return Ok(JsonView(true, result.Message, data, data.Count));
  636. }
  637. return Ok(JsonView(true, result.Message));
  638. }
  639. catch (Exception ex)
  640. {
  641. return Ok(JsonView(true, $"搜索服务暂时不可用!"));
  642. }
  643. }
  644. /// <summary>
  645. /// 商邀AI invName关键字输入提示(单字段)
  646. /// </summary>
  647. /// <param name="keyword">关键字</param>
  648. /// <returns></returns>
  649. [HttpGet("InvAIKeywordSearch/{keyword}")]
  650. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  651. public async Task<IActionResult> InvAIKeywordSearch(string keyword)
  652. {
  653. try
  654. {
  655. // 验证请求参数 _invAISearchService
  656. if (string.IsNullOrEmpty(keyword))
  657. {
  658. return Ok(JsonView(true, $"暂无数据!"));
  659. }
  660. var invNames = await GeneralMethod.InvitationAIInvName();
  661. var searchRequest = new DynamicSearchRequest
  662. {
  663. Keyword = keyword,
  664. RequireAllSingleChars = true,
  665. PageIndex = 1,
  666. PageSize = 999999,
  667. FieldWeights = new Dictionary<string, int>
  668. {
  669. { "Name", 10 },
  670. },
  671. OrderBy = "SortTime"
  672. };
  673. // 验证字段配置
  674. var validation = _invAISearchService.ValidateFieldConfig(
  675. searchRequest.FieldWeights,
  676. searchRequest.ReturnFields);
  677. if (!validation.IsValid)
  678. {
  679. return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
  680. }
  681. var result = _invAISearchService.SearchDataSource(searchRequest, invNames);
  682. if (result.Success)
  683. {
  684. var view = result.Items.Select(x => x.Data).ToList();
  685. return Ok(JsonView(true, result.Message, view, view.Count));
  686. }
  687. return Ok(JsonView(true, "暂无数据"));
  688. }
  689. catch (Exception ex)
  690. {
  691. return Ok(JsonView(true, $"搜索服务暂时不可用!"));
  692. }
  693. }
  694. /// <summary>
  695. /// 商邀AI ClientName 关键字输入提示(单字段)
  696. /// </summary>
  697. /// <param name="keyword">关键字</param>
  698. /// <returns></returns>
  699. [HttpGet("InvAIClientKeywordSearch/{keyword}")]
  700. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  701. public async Task<IActionResult> InvAIClientKeywordSearch(string keyword)
  702. {
  703. try
  704. {
  705. // 验证请求参数 _invAISearchService
  706. if (string.IsNullOrEmpty(keyword))
  707. {
  708. return Ok(JsonView(true, $"暂无数据!"));
  709. }
  710. var invNames = await GeneralMethod.InvitationAIClientName();
  711. var data = invNames.Select(x =>
  712. {
  713. return new InvitationAIInvNameView
  714. {
  715. Name = x,
  716. SortTime = DateTime.Now
  717. };
  718. }).ToList();
  719. var searchRequest = new DynamicSearchRequest
  720. {
  721. Keyword = keyword,
  722. RequireAllSingleChars = true,
  723. PageIndex = 1,
  724. PageSize = 999999,
  725. FieldWeights = new Dictionary<string, int>
  726. {
  727. { "Name", 10 },
  728. },
  729. OrderBy = "SortTime"
  730. };
  731. // 验证字段配置
  732. var validation = _invAISearchService.ValidateFieldConfig(
  733. searchRequest.FieldWeights,
  734. searchRequest.ReturnFields);
  735. if (!validation.IsValid)
  736. {
  737. return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
  738. }
  739. var result = _invAISearchService.SearchDataSource(searchRequest, data);
  740. if (result.Success)
  741. {
  742. var view = result.Items.Select(x => x.Data.Name).ToList();
  743. if (view.Count == 0)
  744. {
  745. return Ok(JsonView(true, "暂无数据"));
  746. }
  747. return Ok(JsonView(true, result.Message, view, view.Count));
  748. }
  749. return Ok(JsonView(true, "暂无数据"));
  750. }
  751. catch (Exception ex)
  752. {
  753. return Ok(JsonView(true, $"搜索服务暂时不可用!"));
  754. }
  755. }
  756. /// <summary>
  757. /// 商邀AI CountryName 关键字输入提示(单字段)
  758. /// </summary>
  759. /// <param name="keyword">关键字</param>
  760. /// <returns></returns>
  761. [HttpGet("InvAICountryKeywordSearch/{keyword}")]
  762. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  763. public async Task<IActionResult> InvAICountryKeywordSearch(string keyword)
  764. {
  765. try
  766. {
  767. // 验证请求参数 _invAISearchService
  768. if (string.IsNullOrEmpty(keyword))
  769. {
  770. return Ok(JsonView(true, $"暂无数据!"));
  771. }
  772. var countryNames = await GeneralMethod.InvitationAICountryName();
  773. var data = countryNames.Select(x =>
  774. {
  775. return new InvitationAIInvNameView
  776. {
  777. Name = x,
  778. SortTime = DateTime.Now
  779. };
  780. }).ToList();
  781. var searchRequest = new DynamicSearchRequest
  782. {
  783. Keyword = keyword,
  784. RequireAllSingleChars = true,
  785. PageIndex = 1,
  786. PageSize = 999999,
  787. FieldWeights = new Dictionary<string, int>
  788. {
  789. { "Name", 10 },
  790. },
  791. OrderBy = "SortTime"
  792. };
  793. // 验证字段配置
  794. var validation = _invAISearchService.ValidateFieldConfig(
  795. searchRequest.FieldWeights,
  796. searchRequest.ReturnFields);
  797. if (!validation.IsValid)
  798. {
  799. return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
  800. }
  801. var result = _invAISearchService.SearchDataSource(searchRequest, data);
  802. if (result.Success)
  803. {
  804. var view = result.Items.Select(x => x.Data.Name).ToList();
  805. if (view.Count == 0)
  806. {
  807. return Ok(JsonView(true, "暂无数据"));
  808. }
  809. return Ok(JsonView(true, result.Message, view, view.Count));
  810. }
  811. return Ok(JsonView(true, "暂无数据"));
  812. }
  813. catch (Exception ex)
  814. {
  815. return Ok(JsonView(true, $"搜索服务暂时不可用!"));
  816. }
  817. }
  818. }
  819. }