add 搜索相关接口
This commit is contained in:
parent
86246ca5fc
commit
b0986a7454
@ -0,0 +1,34 @@
|
||||
namespace ZhonTai.Admin.Contracts.Services.OnlineApp.Dto;
|
||||
|
||||
public class SearchListOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 网页类型
|
||||
/// </summary>
|
||||
public int WebType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主键Id
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网站名称
|
||||
/// </summary>
|
||||
public string WebsiteName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 功能简介
|
||||
/// </summary>
|
||||
public string FunctionIntro { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关键词
|
||||
/// </summary>
|
||||
public string Keywords { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网址
|
||||
/// </summary>
|
||||
public string WebsiteUrl { get; set; }
|
||||
}
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 搜索查询
|
||||
/// </summary>
|
||||
/// <param name="searchKeyword"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<SearchListOutput>> GetListBySearchAsync(string searchKeyword);
|
||||
}
|
190
src/modules/admin/ZhonTai.Admin/Services/Search/SerachService.cs
Normal file
190
src/modules/admin/ZhonTai.Admin/Services/Search/SerachService.cs
Normal file
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 搜索应用服务
|
||||
/// </summary>
|
||||
[Order(300)]
|
||||
[DynamicApi(Area = AdminConsts.AreaName)]
|
||||
public partial class SerachService : BaseService, ISerachService, IDynamicApi
|
||||
{
|
||||
private readonly AdminRepositoryBase<OnlineAppEntity> _onlineAppRepository;
|
||||
private readonly AdminRepositoryBase<UserEntity> _userRepository;
|
||||
private readonly OrgService _orgService;
|
||||
private readonly AdminRepositoryBase<MsgEntity> _msgRepository;
|
||||
private readonly AdminRepositoryBase<TemplateCenterEntity> _templateCenterRepository;
|
||||
private readonly AdminRepositoryBase<RemoteAppEntity> _remoteAppRepository;
|
||||
private readonly AdminRepositoryBase<BoardEntity> _boardRepository;
|
||||
private readonly AdminLocalizer _adminLocalizer;
|
||||
|
||||
public SerachService(
|
||||
AdminRepositoryBase<OnlineAppEntity> onlineAppRepository,
|
||||
AdminRepositoryBase<UserEntity> userRepository,
|
||||
OrgService orgService,
|
||||
AdminRepositoryBase<MsgEntity> msgRepository,
|
||||
AdminRepositoryBase<TemplateCenterEntity> templateCenterRepository,
|
||||
AdminRepositoryBase<BoardEntity> boardRepository,
|
||||
AdminRepositoryBase<RemoteAppEntity> remoteAppRepository,
|
||||
|
||||
AdminLocalizer adminLocalizer
|
||||
)
|
||||
{
|
||||
_onlineAppRepository = onlineAppRepository;
|
||||
_adminLocalizer = adminLocalizer;
|
||||
_userRepository = userRepository;
|
||||
_msgRepository = msgRepository;
|
||||
_templateCenterRepository = templateCenterRepository;
|
||||
_remoteAppRepository = remoteAppRepository;
|
||||
_boardRepository = boardRepository;
|
||||
_orgService = orgService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GetList
|
||||
/// </summary>
|
||||
/// <returns></returns
|
||||
public async Task<List<SearchListOutput>> GetListBySearchAsync(string searchKeyword)
|
||||
{
|
||||
var seachResultList = new List<SearchListOutput>();
|
||||
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<BoardUserEntity>()
|
||||
.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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user