diff --git a/src/modules/admin/ZhonTai.Admin.Contracts/Services/OnlineApp/Dto/SearchListOutput.cs b/src/modules/admin/ZhonTai.Admin.Contracts/Services/OnlineApp/Dto/SearchListOutput.cs new file mode 100644 index 0000000..f5e0e57 --- /dev/null +++ b/src/modules/admin/ZhonTai.Admin.Contracts/Services/OnlineApp/Dto/SearchListOutput.cs @@ -0,0 +1,34 @@ +namespace ZhonTai.Admin.Contracts.Services.OnlineApp.Dto; + +public class SearchListOutput +{ + /// + /// 网页类型 + /// + public int WebType { get; set; } + + /// + /// 主键Id + /// + public long Id { get; set; } + + /// + /// 网站名称 + /// + public string WebsiteName { get; set; } + + /// + /// 功能简介 + /// + public string FunctionIntro { get; set; } + + /// + /// 关键词 + /// + public string Keywords { get; set; } + + /// + /// 网址 + /// + public string WebsiteUrl { get; set; } +} \ No newline at end of file diff --git a/src/modules/admin/ZhonTai.Admin.Contracts/Services/Serach/ISerachService.cs b/src/modules/admin/ZhonTai.Admin.Contracts/Services/Serach/ISerachService.cs new file mode 100644 index 0000000..c78e2d6 --- /dev/null +++ b/src/modules/admin/ZhonTai.Admin.Contracts/Services/Serach/ISerachService.cs @@ -0,0 +1,15 @@ +using ZhonTai.Admin.Contracts.Services.OnlineApp.Dto; +using ZhonTai.Admin.Core.Dto; +using ZhonTai.Admin.Services.OnlineApp.Dto; + +namespace ZhonTai.Admin.Contracts.Services.Serach; + +public interface ISerachService +{ + /// + /// 搜索查询 + /// + /// + /// + Task> GetListBySearchAsync(string searchKeyword); +} \ No newline at end of file diff --git a/src/modules/admin/ZhonTai.Admin/Services/Search/SerachService.cs b/src/modules/admin/ZhonTai.Admin/Services/Search/SerachService.cs new file mode 100644 index 0000000..a999199 --- /dev/null +++ b/src/modules/admin/ZhonTai.Admin/Services/Search/SerachService.cs @@ -0,0 +1,190 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using FreeSql; +using MailKit.Search; +using ZhonTai.Admin.Core.Consts; +using ZhonTai.Admin.Core.Db; +using ZhonTai.Admin.Core.Dto; +using ZhonTai.Admin.Domain.UserClickStats; +using ZhonTai.Admin.Services.UserClickStats.Dto; +using ZhonTai.DynamicApi; +using ZhonTai.DynamicApi.Attributes; +using ZhonTai.Admin.Repositories; +using ZhonTai.Admin.Services.UserClickStats; +using ZhonTai.Admin.Domain.OnlineApp; +using Microsoft.AspNetCore.Mvc; +using StackExchange.Profiling.Internal; +using ZhonTai.Admin.Contracts.Domain.Board; +using ZhonTai.Admin.Contracts.Domain.TemplateCenter; +using ZhonTai.Admin.Contracts.Services.OnlineApp.Dto; +using ZhonTai.Admin.Contracts.Services.Serach; +using ZhonTai.Admin.Domain.Msg; +using ZhonTai.Admin.Domain.Org; +using ZhonTai.Admin.Domain.RemoteApp; +using ZhonTai.Admin.Domain.User; +using ZhonTai.Admin.Resources; +using ZhonTai.Admin.Services.OnlineApp.Dto; +using ZhonTai.Admin.Services.Org; +using ZhonTai.Admin.Services.User.Dto; + +namespace ZhonTai.Admin.Services.Search; + +/// +/// 搜索应用服务 +/// +[Order(300)] +[DynamicApi(Area = AdminConsts.AreaName)] +public partial class SerachService : BaseService, ISerachService, IDynamicApi +{ + private readonly AdminRepositoryBase _onlineAppRepository; + private readonly AdminRepositoryBase _userRepository; + private readonly OrgService _orgService; + private readonly AdminRepositoryBase _msgRepository; + private readonly AdminRepositoryBase _templateCenterRepository; + private readonly AdminRepositoryBase _remoteAppRepository; + private readonly AdminRepositoryBase _boardRepository; + private readonly AdminLocalizer _adminLocalizer; + + public SerachService( + AdminRepositoryBase onlineAppRepository, + AdminRepositoryBase userRepository, + OrgService orgService, + AdminRepositoryBase msgRepository, + AdminRepositoryBase templateCenterRepository, + AdminRepositoryBase boardRepository, + AdminRepositoryBase remoteAppRepository, + + AdminLocalizer adminLocalizer + ) + { + _onlineAppRepository = onlineAppRepository; + _adminLocalizer = adminLocalizer; + _userRepository = userRepository; + _msgRepository = msgRepository; + _templateCenterRepository = templateCenterRepository; + _remoteAppRepository = remoteAppRepository; + _boardRepository = boardRepository; + _orgService = orgService; + } + + /// + /// GetList + /// + /// > GetListBySearchAsync(string searchKeyword) + { + var seachResultList = new List(); + if (string.IsNullOrWhiteSpace(searchKeyword)) + { + return seachResultList; + } + + var orgs = await _orgService.GetSimpleListWithPathAsync(); + var orgDict = orgs.ToDictionary(a => a.Id, a => a.Path); + + var user = await _userRepository.Select + .Where(a => a.Id == User.Id) + .OrderByDescending(true, a => a.Id) + .IncludeMany(a => a.Orgs.Select(b => new OrgEntity { Id = b.Id })) + .FirstAsync(a => new UserGetPageOutput + { + Orgs = a.Orgs, + Sex = a.Staff.Sex + }); + + var orgPathList = user.OrgIds.Select(a => orgDict.GetValueOrDefault(a)).Where(a => a != null).ToList(); + user.OrgPaths = string.Join(" ; ", orgPathList); + + + // 查询消息 + var msgList = await _msgRepository.Select + .Where(a => a.Title.Contains(searchKeyword) || a.Content.Contains(searchKeyword)) + .OrderByDescending(true, a => a.CreatedTime).ToListAsync(); + + foreach (var item in msgList) + { + seachResultList.Add(new SearchListOutput() + { + WebType = 1, + Id = item.Id, + WebsiteName = item.Title, + }); + } + + // 查询在线应用 + var onlineList = await _onlineAppRepository.Select + .Where(a => a.WebsiteName.Contains(searchKeyword) || + a.Keywords.Contains(searchKeyword) || + a.WebsiteUrl.Contains(searchKeyword) || + a.FunctionIntro.Contains(searchKeyword) || + a.Keywords.Contains(searchKeyword)) + .WhereIf(user.OrgPaths.Contains("WGQ"), a => a.ApplicableSite == "WGQ" || a.ApplicableSite == "CN") + .WhereIf(user.OrgPaths.Contains("FX"), a => a.ApplicableSite == "FX" || a.ApplicableSite == "CN") + .WhereIf(user.OrgPaths.Contains("WX"), a => a.ApplicableSite == "WX" || a.ApplicableSite == "CN") + .OrderByDescending(true, c => c.Id) + .ToListAsync(); + + foreach (var online in onlineList) + { + seachResultList.Add(new SearchListOutput() + { + WebType = 10, + Id = online.Id, + WebsiteName = online.WebsiteName, + WebsiteUrl = online.WebsiteUrl, + FunctionIntro = online.FunctionIntro, + Keywords = online.Keywords, + }); + } + + // 查询模板中心 + var templateList = await _templateCenterRepository.Select.Where(a=> a.Name.Contains(searchKeyword) || a.FunctionIntro.Contains(searchKeyword) || a.Keywords.Contains(searchKeyword)|| a.FileUrl.Contains(searchKeyword)).ToListAsync(); + foreach (var item in templateList) + { + seachResultList.Add(new SearchListOutput() + { + WebType = 20, + Id = item.Id, + WebsiteName = item.Name, + WebsiteUrl = item.FileUrl, + FunctionIntro = item.FunctionIntro, + Keywords = item.Keywords, + }); + } + + // 查询远程访问链接 + var remoteList = await _remoteAppRepository.Select.Where(a => a.Name.Contains(searchKeyword) || a.IpAddress.Contains(searchKeyword)).ToListAsync(); + foreach (var item in remoteList) + { + seachResultList.Add(new SearchListOutput() + { + WebType = 30, + Id = item.Id, + WebsiteName = item.Name, + WebsiteUrl = item.IpAddress, + }); + } + + // 在线看板 + var boardList = await _boardRepository.Select.From() + .InnerJoin(a => a.t2.BoardId == a.t1.Id) + .Where(a => a.t2.UserId == User.Id) + .Where(a=> a.t1.Name.Contains(searchKeyword) || a.t1.Keywords.Contains(searchKeyword) || a.t1.Description.Contains(searchKeyword) || a.t1.Url.Contains(searchKeyword)) + .ToListAsync(); + foreach (var item in boardList) + { + seachResultList.Add(new SearchListOutput() + { + WebType = 40, + Id = item.Id, + WebsiteName = item.Name, + WebsiteUrl = item.Url, + FunctionIntro = item.Description, + Keywords = item.Keywords, + }); + } + + return seachResultList; + } +} \ No newline at end of file