track/src/SJZY.Track.Repository/TrackPullConfigRepository.cs
2024-02-29 09:44:36 +08:00

73 lines
4.3 KiB
C#

using SJZY.Track.Domain.Aggregates.TrackContentAggregate;
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate;
using SJZY.Track.Domain.Dtos.Common;
using SJZY.Track.Domain.Dtos.TrackPull;
using SJZY.Track.Domain.VEntities;
namespace SJZY.Track.Repository;
public class TrackPullConfigRepository : BasicRepository<TrackPullConfigEntity>, ITrackPullConfigRepository,
IScopedDependency
{
public async Task<UnifyPageResultDto<GetTrackPullConfigPageOutputVO>> GetPageAsync(KeywordsInputVO input)
{
return await AsQueryable()
.LeftJoin<VSystemEntity>((trackPull, system) => trackPull.SubSystemId == system.Id && !system.IsDeleted)
.LeftJoin<VServiceProviderEntity>((trackPull, system, service) => trackPull.ServiceProviderId == service.Id && !service.IsDeleted)
.LeftJoin<TrackTemplateEntity>((trackPull, system, service, template) => trackPull.TrackTemplateId == template.Id && !template.IsDeleted)
.Filter(null, true)
.Where(trackPull => !trackPull.IsDeleted)
.WhereIF(input.SubSystemId.HasValue, trackPull => trackPull.SubSystemId == input.SubSystemId)
.WhereIF(!input.Keywords.IsNullOrWhiteSpace(), (trackPull, system, service, template) => service.Name.Contains(input.Keywords) || template.Name.Contains(input.Keywords))
.OrderByDescending(trackPull => trackPull.CreateTime)
.Select((trackPull, system, service, template) => new GetTrackPullConfigPageOutputVO
{
Id = trackPull.Id,
SubSystem = system.CnName,
ServiceProvider = service.Name,
TrackTemplate = template.Name,
CreateTime = trackPull.CreateTime
})
.ToPagedListAsync(input.PageIndex, input.PageSize);
}
public async Task<UnifyPageResultDto<GetTrackPullContentPageOutputVO>> GetContentPageAsync(GetTrackPullContentPageInputVO input)
{
return await Context.Queryable<TrackPullContentConfigEntity>()
.InnerJoin<TrackContentEntity>((pullContent, trackContent) => pullContent.TrackContentId == trackContent.Id)
.InnerJoin<TrackPullConfigEntity>((pullContent, trackContent, trackPull) => pullContent.TrackPullConfigId == trackPull.Id)
.InnerJoin<TrackTemplateContentEntity>((pullContent, trackContent, trackPull, templateContent) => trackPull.TrackTemplateId == templateContent.TrackTemplateId && pullContent.TrackContentId == templateContent.TrackContentId)
.Where(pullContent => pullContent.TrackPullConfigId == input.TrackPullConfigId)
.OrderBy((pullContent, trackContent, trackPull, templateContent) => templateContent.Sort)
.Select((pullContent, trackContent, trackPull, templateContent) => new GetTrackPullContentPageOutputVO
{
Id = pullContent.Id
}, true)
.Mapper(x =>
{
x.TrackKeywords = [.. x.TrackKeyword.Split(',')];
x.TrackKeywordsReverse = [.. x.TrackKeywordReverse.Split(',')];
})
.ToPagedListAsync(input.PageIndex, input.PageSize);
}
public async Task<GetTrackPullConfigDetailOutputVO> GetDetailAsync(int id)
{
return await AsQueryable()
.LeftJoin<VSystemEntity>((trackPull, system) => trackPull.SubSystemId == system.Id && !system.IsDeleted)
.LeftJoin<VServiceProviderEntity>((trackPull, system, service) => trackPull.ServiceProviderId == service.Id && !service.IsDeleted)
.LeftJoin<TrackTemplateEntity>((trackPull, system, service, template) => trackPull.TrackTemplateId == template.Id && !template.IsDeleted)
.InnerJoin<TrackPushPullParamsConfigEntity>((trackPull, system, service, template, paramsConfig) => trackPull.Id == paramsConfig.PullOrPushConfigId && !paramsConfig.IsPush && !paramsConfig.IsDeleted)
.Filter(null, true)
.Where(trackPull => trackPull.Id == id && !trackPull.IsDeleted)
.Select((trackPull, system, service, template, paramsConfig) => new GetTrackPullConfigDetailOutputVO
{
Id = trackPull.Id,
SubSystem = system.CnName,
ServiceProvider = service.Name,
TrackTemplate = template.Name
}, true)
.SingleAsync();
}
}