| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- using EyeSoft.Collections.Generic;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using NPOI.SS.Formula.Functions;
- 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.Search;
- using OASystem.Infrastructure.Repositories.System;
- 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 DynamicSearchService<Grp_DelegationInfo> _groupSearchService;
- private readonly DynamicSearchService<NewClientDataView> _clientSearchService;
- public SearchController(
- SqlSugarClient sqlSugar,
- DynamicSearchService<Grp_DelegationInfo> groupSearchService,
- DynamicSearchService<NewClientDataView> clientSearchService
- )
- {
- _sqlSugar = sqlSugar;
- _groupSearchService = groupSearchService;
- _clientSearchService = clientSearchService;
- }
- /// <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, $"搜索服务暂时不可用!"));
- }
- }
- }
- }
|