SearchController.cs 27 KB

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