| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135 |
- 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))
- .Select(x => new { x.DIId, x.TicketCode, x.ClientName,x.CustTicketInfos })
- .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 airLookupOld = airInfos
- .GroupBy(x => x.DIId)
- .ToDictionary(
- g => g.Key,
- g => g.Select(x => x?.TicketCode?.Trim())
- .Where(code => !string.IsNullOrWhiteSpace(code))
- .Distinct()
- .ToList()
- );
- var airLookupNew = airInfos
- .GroupBy(x => x.DIId)
- .ToDictionary(
- g => g.Key,
- g => g.SelectMany(x => x.CustTicketInfos?.Select(y => y.TicketCode.Trim()) ?? Enumerable.Empty<string>())
- .Where(code => !string.IsNullOrWhiteSpace(code))
- .Distinct()
- .ToList()
- );
- var airLookup = airLookupOld
- .Concat(airLookupNew)
- .GroupBy(kvp => kvp.Key)
- .ToDictionary(
- g => g.Key,
- g => g.SelectMany(kvp => kvp.Value)
- .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", 20 },
- { "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, $"搜索服务暂时不可用!"));
- }
- }
- }
- }
|