| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109 |
- using EyeSoft.Collections.Generic;
- using Humanizer;
- 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;
- using OASystem.Domain.Entities.Customer;
- using OASystem.Domain.Entities.Financial;
- using OASystem.Domain.Entities.Groups;
- using OASystem.Domain.ViewModels.Groups;
- using OASystem.Domain.ViewModels.Search;
- using OASystem.Infrastructure.Repositories.CRM;
- using OASystem.Infrastructure.Repositories.Groups;
- using OASystem.Infrastructure.Repositories.System;
- using System.Diagnostics;
- using static iTextSharp.text.pdf.AcroFields;
- namespace OASystem.API.Controllers
- {
- /// <summary>
- /// 搜索
- /// </summary>
- [Route("api/search")]
- [ApiController]
- public class SearchController : ControllerBase
- {
- private readonly SqlSugarClient _sqlSugar;
- private readonly DelegationInfoRepository _groupRep;
- private readonly DynamicSearchService<Grp_DelegationInfo> _groupSearchService;
- private readonly DynamicSearchService<NewClientDataView> _clientSearchService;
- private readonly DynamicSearchService<InvitationAIInvNameView> _invAISearchService;
- private readonly DynamicSearchService<AirInfo> _airSearchService;
- private readonly NewClientDataRepository _clientDataRepository;
- public SearchController(
- SqlSugarClient sqlSugar,
- DelegationInfoRepository groupRep,
- DynamicSearchService<Grp_DelegationInfo> groupSearchService,
- DynamicSearchService<NewClientDataView> clientSearchService,
- DynamicSearchService<InvitationAIInvNameView> invAISearchService,
- DynamicSearchService<AirInfo> airSearchService,
- NewClientDataRepository clientDataRepository
- )
- {
- _sqlSugar = sqlSugar;
- _groupRep = groupRep;
- _clientDataRepository = clientDataRepository;
- _groupSearchService = groupSearchService;
- _clientSearchService = clientSearchService;
- _airSearchService = airSearchService;
- _invAISearchService = invAISearchService;
- }
- /// <summary>
- /// 接团信息 关键字输入提示(单字段)
- /// </summary>
- /// <param name="keyword">关键字</param>
- /// <returns></returns>
- [HttpGet("group/{keyword}")]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GroupKeywordSearch(string keyword)
- {
- try
- {
- // 验证请求参数
- if (string.IsNullOrEmpty(keyword))
- {
- return Ok(JsonView(true, $"暂无数据!"));
- }
- var searchRequest = new DynamicSearchRequest
- {
- Keyword = keyword,
- RequireAllSingleChars = true,
- PageIndex = 1,
- PageSize = 999999,
- FieldWeights = new Dictionary<string, int>
- {
- { "TeamName", 10 },
- //{ "ClientUnit", 8 },
- //{ "ClientName", 6 }
- },
- Filters = new List<SearchFilter>()
- {
- new(){Field = "IsDel",Operator="eq",Value="0" }
- },
- OrderBy = "TeamName",
- ReturnFields = new List<string>() { "TeamName" }
- };
- // 验证字段配置
- var validation = _groupSearchService.ValidateFieldConfig(
- searchRequest.FieldWeights,
- searchRequest.ReturnFields);
- if (!validation.IsValid)
- {
- return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
- }
- var result = await _groupSearchService.SearchAsync(searchRequest);
- if (result.Success)
- {
- var data = result.Items.Select(x => new { x.Data.Id, x.Data.TeamName }).ToList();
- return Ok(JsonView(true, result.Message, data, data.Count));
- }
- return Ok(JsonView(true, result.Message));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(true, $"搜索服务暂时不可用!"));
- }
- }
- /// <summary>
- /// 客户资料 关键字输入提示(多字段)
- /// </summary>
- /// <param name="userId">关键字</param>
- /// <param name="keyword">关键字</param>
- /// <returns></returns>
- [HttpGet("group/{userId}/{keyword}")]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> ClientKeywordSearch(int userId, string keyword)
- {
- try
- {
- // 验证请求参数
- if (string.IsNullOrEmpty(keyword))
- {
- return Ok(JsonView(true, $"暂无数据!"));
- }
- //查询有权限的数据
- var clientIds = await _sqlSugar
- .Queryable<Crm_ClientDataAndUser>()
- .Where(x => x.IsDel == 0 && x.usersId == userId)
- .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,
- 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,
- 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="keyword">关键字</param>
- /// <returns></returns>
- [HttpGet]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> ProcessKeywordSearch(string keyword)
- {
- try
- {
- // 验证请求参数
- if (string.IsNullOrEmpty(keyword))
- {
- return Ok(JsonView(true, $"暂无数据!"));
- }
- var searchRequest = new DynamicSearchRequest
- {
- Keyword = keyword,
- RequireAllSingleChars = true,
- PageIndex = 1,
- PageSize = 999999,
- FieldWeights = new Dictionary<string, int>
- {
- { "TeamName", 10 }
- },
- Filters = new List<SearchFilter>()
- {
- new(){Field = "IsDel",Operator="eq",Value="0" }
- },
- OrderBy = "VisitDate",
- ReturnFields = new List<string>() { "TeamName" }
- };
- // 验证字段配置
- var validation = _groupSearchService.ValidateFieldConfig(
- searchRequest.FieldWeights,
- searchRequest.ReturnFields);
- if (!validation.IsValid)
- {
- return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
- }
- var result = await _groupSearchService.SearchAsync(searchRequest);
- if (result.Success)
- {
- var data = new List<dynamic>();
- foreach (var item in result.Items)
- {
- data.Add(new
- {
- item.Data.Id,
- item.Data.TeamName,
- });
- }
- return Ok(JsonView(true, result.Message, data, data.Count));
- }
- return Ok(JsonView(true, result.Message));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(true, $"搜索服务暂时不可用!"));
- }
- }
- /// <summary>
- /// 团组会务成本 关键字输入提示(智能版)
- /// </summary>
- /// <param name="keyword">关键字</param>
- /// <returns></returns>
- [HttpGet("ConferenceAffairsKeywordSearch/{keyword}")]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> ConferenceAffairsKeywordSearch(string keyword)
- {
- try
- {
- // 验证请求参数
- if (string.IsNullOrEmpty(keyword))
- {
- return Ok(JsonView(true, $"暂无数据!"));
- }
- var hwIds = _sqlSugar.Queryable<Sys_SetData>()
- .Where(x => x.IsDel == 0 && x.STid == 10 && x.Name.Contains("会务活动"))
- .Select(x => x.Id)
- .ToList();
- var object_hwIds = hwIds.ConvertAll<object>(x => x);
- var searchRequest = new DynamicSearchRequest
- {
- Keyword = keyword,
- RequireAllSingleChars = true,
- PageIndex = 1,
- PageSize = 999999,
- FieldWeights = new Dictionary<string, int>
- {
- { "TeamName", 10 }
- },
- Filters = new List<SearchFilter>()
- {
- new(){Field = "IsDel",Operator="eq",Value="0" },
- new(){Field = "TeamDid",Operator="in",Values=object_hwIds }
- },
- OrderBy = "VisitDate",
- ReturnFields = new List<string>() { "TeamName" }
- };
- // 验证字段配置
- var validation = _groupSearchService.ValidateFieldConfig(
- searchRequest.FieldWeights,
- searchRequest.ReturnFields);
- if (!validation.IsValid)
- {
- return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
- }
- var result = await _groupSearchService.SearchAsync(searchRequest);
- if (result.Success)
- {
- var data = new List<dynamic>();
- foreach (var item in result.Items)
- {
- data.Add(new
- {
- item.Data.Id,
- item.Data.TeamName,
- });
- }
- return Ok(JsonView(true, result.Message, data, data.Count));
- }
- return Ok(JsonView(true, result.Message));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(true, $"搜索服务暂时不可用!"));
- }
- }
- #region 团组费用-机票费用
- /// <summary>
- /// 团组机票费用基本信息
- /// </summary>
- /// <param name="groupIds"></param>
- /// <returns></returns>
- private async Task<List<AirInfo>> GetAirInfos(List<int> groupIds)
- {
- // 1. 查询
- var groupInfos = await _sqlSugar.Queryable<Grp_DelegationInfo>()
- .Where(x => x.IsDel == 0 && groupIds.Contains(x.Id))
- .Select(x => new { x.Id, x.TeamName })
- .ToListAsync();
- var airInfos = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
- .Where(x => x.IsDel == 0 && groupIds.Contains(x.DIId) && !string.IsNullOrEmpty(x.TicketCode))
- .Select(x => new { x.DIId, x.TicketCode, x.ClientName })
- .ToListAsync();
- // 2. 解析客户名称ID
- var clientIds = new HashSet<int>();
- foreach (var item in airInfos)
- {
- if (string.IsNullOrWhiteSpace(item.ClientName))
- continue;
- var ids = item.ClientName.Split(',')
- .Select(s => s.Trim())
- .Where(s => int.TryParse(s, out _))
- .Select(int.Parse);
- foreach (var id in ids)
- {
- clientIds.Add(id);
- }
- }
- // 3. 批量查询客户名称
- var clientNames = new Dictionary<int, string>();
- if (clientIds.Any())
- {
- var nameInfos = await _sqlSugar.Queryable<Crm_DeleClient>()
- .Where(x => x.IsDel == 0 && clientIds.Contains(x.Id) &&
- !string.IsNullOrEmpty(x.FirstName) && !string.IsNullOrEmpty(x.LastName))
- .Select(x => new { x.Id, x.FirstName, x.LastName })
- .ToListAsync();
- clientNames = nameInfos.ToDictionary(
- x => x.Id,
- x => AesEncryptionHelper.Decrypt(x.LastName) + AesEncryptionHelper.Decrypt(x.FirstName)
- );
- }
- // 4. 构建 ClientName 到客户名称列表的映射(预解析)
- var clientNameCache = new Dictionary<string, List<string>>();
- foreach (var item in airInfos)
- {
- if (string.IsNullOrWhiteSpace(item.ClientName))
- continue;
- if (!clientNameCache.ContainsKey(item.ClientName))
- {
- var ids = item.ClientName.Split(',')
- .Select(s => s.Trim())
- .Where(s => int.TryParse(s, out _))
- .Select(int.Parse)
- .ToList();
- var names = ids.SelectMany(id =>
- clientNames.ContainsKey(id)
- ? new[] { clientNames[id] }
- : Array.Empty<string>()
- ).ToList();
- clientNameCache[item.ClientName] = names;
- }
- }
- // 5. 构建分组数据
- var airLookup = airInfos
- .GroupBy(x => x.DIId)
- .ToDictionary(g => g.Key, g => g.Select(x => x.TicketCode).Distinct().ToList());
- var clientLookup = airInfos
- .Where(x => !string.IsNullOrEmpty(x.ClientName) && clientNameCache.ContainsKey(x.ClientName))
- .GroupBy(x => x.DIId)
- .ToDictionary(g => g.Key, g => g.SelectMany(x => clientNameCache[x.ClientName]).Distinct().ToList());
- // 6. 组装结果
- var result = groupInfos.Select(group => new AirInfo
- {
- Id = group.Id,
- TeamName = group.TeamName,
- TicketCodes = airLookup.GetValueOrDefault(group.Id, new List<string>()),
- Clients = clientLookup.GetValueOrDefault(group.Id, new List<string>())
- }).ToList();
- return result;
- }
- public class AirInfo
- {
- public int Id { get; set; }
- public string TeamName { get; set; }
- public string TicketCodesLabel => string.Join("、", TicketCodes);
- public string ClientsLabel => string.Join("、", Clients);
- public List<string> TicketCodes { get; set; }
- public List<string> Clients { get; set; }
- }
- #endregion
- /// <summary>
- /// 团组各项费用录入 关键字输入提示(智能版)
- /// 76 酒店预订
- /// 79 车/导游地接
- /// 80 签证
- /// 81 邀请/公务活动
- /// 82 团组客户保险
- /// 85 机票预订
- /// 98 其他款项
- /// 285 收款退还
- /// 1015 超支费用
- /// 1081 文档下载
- /// 1466 会务相关
- /// </summary>
- /// <param name="userId">用户Id</param>
- /// <param name="feeType">费用类型</param>
- /// <param name="keyword">关键字</param>
- /// <returns></returns>
- [HttpGet("GroupFeeKeywordSearch/{userId}/{feeType}/{keyword}")]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GroupFeeKeywordSearch(int userId, int feeType, string keyword)
- {
- var stopwatch = Stopwatch.StartNew();
- try
- {
- #region 参数验证
- // 基本参数验证
- if (userId <= 0)
- return Ok(JsonView(false, "用户ID必须大于0!"));
- if (feeType <= 0)
- return Ok(JsonView(false, "费用类型必须大于0!"));
- // 验证用户是否存在
- var userExists = await _sqlSugar.Queryable<Sys_Users>()
- .Where(x => x.IsDel == 0 && x.Id == userId)
- .AnyAsync();
- if (!userExists) return Ok(JsonView(false, "用户不存在或已被删除"));
- // 验证费用类型是否有效
- var feeTypeExists = await _sqlSugar.Queryable<Sys_SetData>()
- .Where(x => x.IsDel == 0 && x.STid == 16 && x.Id == feeType)
- .AnyAsync();
- if (!feeTypeExists) return Ok(JsonView(false, "无效的费用类型"));
- // 验证关键字
- if (string.IsNullOrWhiteSpace(keyword)) return Ok(JsonView(false, "请输入搜索关键字"));
- #endregion
- #region 获取用户有权限的团组ID
- // 获取用户有权限访问的团组ID列表
- var authorizedGroupIds = await _sqlSugar.Queryable<Grp_GroupsTaskAssignment>()
- .Where(x => x.IsDel == 0 && x.UId == userId && x.CTId == feeType)
- .Select(x => x.DIId)
- .Distinct()
- .ToListAsync();
- if (!authorizedGroupIds.Any()) return Ok(JsonView(true, "暂无数据", new List<object>(), 0));
- #endregion
- // 类型等于 85 时单独处理
- if (feeType == 85)
- {
- var airInfos = await GetAirInfos(authorizedGroupIds);
- if (airInfos == null) return Ok(JsonView(false, "获取机票费用信息失败"));
- var airSearchReq = new DynamicSearchRequest()
- {
- Keyword = keyword.Trim(),
- RequireAllSingleChars = true,
- PageIndex = 1,
- PageSize = 20, // 限制返回数量,提高性能
- FieldWeights = new Dictionary<string, int>
- {
- { "TeamName", 10 },
- { "TicketCodesLabel", 10 },
- { "ClientsLabel", 10 }
- }
- };
- var airResult = _airSearchService.SearchDataSource(airSearchReq, airInfos);
- if (!airResult.Success)
- {
- return Ok(JsonView(false, airResult.Message ?? "搜索失败"));
- }
- if (airResult.Items == null || !airResult.Items.Any())
- {
- return Ok(JsonView(true, "未找到匹配的团组", new List<object>(), 0));
- }
- var airRespData = airResult.Items
- .Where(item => item.Data != null)
- .Select(item => new
- {
- item.Data.Id,
- item.Data.TeamName,
- item.Data.TicketCodes,
- item.Data.Clients,
- })
- .Where(x => !string.IsNullOrWhiteSpace(x.TeamName)) // 过滤空名称
- .Distinct() // 去重
- .ToList();
- stopwatch.Stop();
- return Ok(JsonView(true, $"搜索成功,耗时:{stopwatch.ElapsedMilliseconds}ms", airRespData, airRespData.Count));
- }
- #region 构建搜索请求
- var searchRequest = new DynamicSearchRequest
- {
- Keyword = keyword.Trim(),
- RequireAllSingleChars = true,
- PageIndex = 1,
- PageSize = 20, // 限制返回数量,提高性能
- FieldWeights = new Dictionary<string, int>
- {
- { "TeamName", 10 }
- },
- Filters = new List<SearchFilter>
- {
- new SearchFilter { Field = "IsDel", Operator = "eq", Value = "0" },
- new SearchFilter { Field = "Id", Operator = "in", Values = authorizedGroupIds.ConvertAll<object>(x => x) }
- },
- OrderBy = "VisitDate", // 添加排序方向
- ReturnFields = new List<string> { "Id", "TeamName" } // 添加ID字段
- };
- #endregion
- #region 字段配置验证
- var validation = _groupSearchService.ValidateFieldConfig(
- searchRequest.FieldWeights,
- searchRequest.ReturnFields);
- if (!validation.IsValid)
- {
- return Ok(JsonView(false, $"字段配置错误: {validation.Message}"));
- }
- #endregion
- #region 执行搜索
- var result = await _groupSearchService.SearchAsync(searchRequest);
- if (!result.Success)
- {
- return Ok(JsonView(false, result.Message ?? "搜索失败"));
- }
- if (result.Items == null || !result.Items.Any())
- {
- return Ok(JsonView(true, "未找到匹配的团组", new List<object>(), 0));
- }
- #endregion
- #region 构建返回数据
- var responseData = result.Items
- .Where(item => item.Data != null)
- .Select(item => new
- {
- Id = item.Data.Id,
- TeamName = item.Data.TeamName
- })
- .Where(x => !string.IsNullOrWhiteSpace(x.TeamName)) // 过滤空名称
- .Distinct() // 去重
- .ToList();
- #endregion
- stopwatch.Stop();
- return Ok(JsonView(true, $"搜索成功,耗时:{stopwatch.ElapsedMilliseconds} ms", responseData, responseData.Count));
- }
- catch (Exception ex)
- {
- // 记录日志(实际项目中应该使用日志框架)
- // _logger.LogError(ex, "团组费用关键字搜索失败,用户ID: {UserId}, 费用类型: {FeeType}", userId, feeType);
- // 生产环境中不要返回详细的错误信息
- return Ok(JsonView(false, "搜索服务暂时不可用,请稍后重试"));
- }
- }
- /// <summary>
- /// 三公-接团信息 关键字输入提示(单字段)
- /// </summary>
- /// <param name="currUserId">用户名称ID</param>
- /// <param name="keyword">关键字</param>
- /// <returns></returns>
- [HttpGet("GroupEnterExitCostKeywordSearch/{currUserId}/{keyword}")]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GroupEnterExitCostKeywordSearch(int currUserId,string keyword)
- {
- try
- {
- // 验证请求参数
- if (currUserId < 1)
- {
- return Ok(JsonView(true, $"请传入有效的用户ID!"));
- }
- if (string.IsNullOrEmpty(keyword))
- {
- return Ok(JsonView(true, $"暂无数据!"));
- }
- var searchRequest = new DynamicSearchRequest
- {
- Keyword = keyword,
- RequireAllSingleChars = true,
- PageIndex = 1,
- PageSize = 30,
- FieldWeights = new Dictionary<string, int>
- {
- { "TeamName", 10 },
- //{ "ClientUnit", 8 },
- //{ "ClientName", 6 }
- },
- Filters = new List<SearchFilter>()
- {
- new(){Field = "IsDel",Operator="eq",Value="0" }
- },
- OrderBy = "TeamName",
- ReturnFields = new List<string>() { "TeamName" }
- };
- // 验证字段配置
- var validation = _groupSearchService.ValidateFieldConfig(
- searchRequest.FieldWeights,
- searchRequest.ReturnFields);
- if (!validation.IsValid)
- {
- return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
- }
- var result = await _groupSearchService.SearchAsync(searchRequest);
- if (result.Success)
- {
- var groupIds = result.Items.Select(x => x.Data.Id).ToList();
- var isNullDatas = _sqlSugar.Queryable<Grp_EnterExitCost>()
- .Where(x => x.IsDel == 0 && groupIds.Contains(x.DiId))
- .Select(x => x.DiId)
- .Distinct()
- .ToList();
- var isViewDatas = _sqlSugar.Queryable<Grp_EnterExitCostPermission>()
- .Where(x1 => x1.IsDel == 0 && x1.UserId == currUserId && groupIds.Contains(x1.GroupId))
- .Select(x1 => x1.GroupId)
- .Distinct()
- .ToList();
- var provCityDatas = await _groupRep.ProvinceCityBasicSource();
- var data = result.Items.Select(x =>
- {
- int groupId = x.Data.Id;
- int cityId = x.Data.CityId;
- bool isNull = !isNullDatas.Where(x => x == groupId).Any();
- bool isView = isViewDatas.Where(x => x == groupId).Any();
- var provinceId = 122; //默认四川
- if (provinceId > 0)
- {
- var parentId = _groupRep.FindParentIdByChildId(provCityDatas, cityId);
- if (parentId != null)
- {
- provinceId = (int)parentId;
- }
- }
- return new
- {
- x.Data.Id,
- groupName = x.Data.TeamName,
- provinceId,
- isNull,
- isView,
- };
- }).ToList();
- return Ok(JsonView(true, result.Message, data, data.Count));
- }
- return Ok(JsonView(true, result.Message));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(true, $"搜索服务暂时不可用!"));
- }
- }
- /// <summary>
- /// 商邀AI invName关键字输入提示(单字段)
- /// </summary>
- /// <param name="keyword">关键字</param>
- /// <returns></returns>
- [HttpGet("InvAIKeywordSearch/{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, $"搜索服务暂时不可用!"));
- }
- }
- /// <summary>
- /// 商邀AI ClientName 关键字输入提示(单字段)
- /// </summary>
- /// <param name="keyword">关键字</param>
- /// <returns></returns>
- [HttpGet("InvAIClientKeywordSearch/{keyword}")]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> InvAIClientKeywordSearch(string keyword)
- {
- try
- {
- // 验证请求参数 _invAISearchService
- if (string.IsNullOrEmpty(keyword))
- {
- return Ok(JsonView(true, $"暂无数据!"));
- }
- var invNames = await GeneralMethod.InvitationAIClientName();
- var data = invNames.Select(x =>
- {
- return new InvitationAIInvNameView
- {
- Name = x,
- SortTime = DateTime.Now
- };
- }).ToList();
- 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, data);
- if (result.Success)
- {
- var view = result.Items.Select(x => x.Data.Name).ToList();
- if (view.Count == 0)
- {
- return Ok(JsonView(true, "暂无数据"));
- }
- return Ok(JsonView(true, result.Message, view, view.Count));
- }
- return Ok(JsonView(true, "暂无数据"));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(true, $"搜索服务暂时不可用!"));
- }
- }
- /// <summary>
- /// 商邀AI CountryName 关键字输入提示(单字段)
- /// </summary>
- /// <param name="keyword">关键字</param>
- /// <returns></returns>
- [HttpGet("InvAICountryKeywordSearch/{keyword}")]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> InvAICountryKeywordSearch(string keyword)
- {
- try
- {
- // 验证请求参数 _invAISearchService
- if (string.IsNullOrEmpty(keyword))
- {
- return Ok(JsonView(true, $"暂无数据!"));
- }
- var countryNames = await GeneralMethod.InvitationAICountryName();
- var data = countryNames.Select(x =>
- {
- return new InvitationAIInvNameView
- {
- Name = x,
- SortTime = DateTime.Now
- };
- }).ToList();
- 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, data);
- if (result.Success)
- {
- var view = result.Items.Select(x => x.Data.Name).ToList();
- if (view.Count == 0)
- {
- return Ok(JsonView(true, "暂无数据"));
- }
- return Ok(JsonView(true, result.Message, view, view.Count));
- }
- return Ok(JsonView(true, "暂无数据"));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(true, $"搜索服务暂时不可用!"));
- }
- }
- }
- }
|