using System.Linq.Expressions; 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.Repositories; public class TrackPullConfigRepository : BasicRepository, ITrackPullConfigRepository, IScopedDependency { public async Task> GetPageAsync(KeywordsInputVO input) { return await AsQueryable() .LeftJoin((trackPull, system) => trackPull.SubSystemId == system.Id && !system.IsDeleted) .LeftJoin((trackPull, system, service) => trackPull.ServiceProviderId == service.Id && !service.IsDeleted) .LeftJoin((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> GetContentPageAsync(GetTrackPullContentPageInputVO input) { return await Context.Queryable() .InnerJoin((pullContent, trackContent) => pullContent.TrackContentId == trackContent.Id) .InnerJoin((pullContent, trackContent, trackPull) => pullContent.TrackPullConfigId == trackPull.Id) .InnerJoin((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) .ToPagedListAsync(input.PageIndex, input.PageSize); } public async Task GetDetailAsync(int id) { return await AsQueryable() .LeftJoin((trackPull, system) => trackPull.SubSystemId == system.Id && !system.IsDeleted) .LeftJoin((trackPull, system, service) => trackPull.ServiceProviderId == service.Id && !service.IsDeleted) .LeftJoin((trackPull, system, service, template) => trackPull.TrackTemplateId == template.Id && !template.IsDeleted) .InnerJoin((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(); } public async Task GetContentDetailAsync(int id) { return await Context.Queryable() .InnerJoin((pullContent, trackContent) => pullContent.TrackContentId == trackContent.Id) .Where(pullContent => pullContent.Id == id) .Select((pullContent, trackContent) => new GetTrackPullContentDetailOutputVO { Id = pullContent.Id, Code = trackContent.Code + "-" + trackContent.Content, }, true) .Mapper(x => { x.TrackKeywords = x.TrackKeyword?.Split(',').ToList(); x.TrackKeywordReverses = x.TrackKeywordReverse?.Split(',').ToList(); }) .SingleAsync(); } public async Task InsertParamsAsync(TrackPushPullParamsConfigEntity insertObj) { return await Context.Insertable(insertObj).ExecuteCommandAsync() > 0; } public async Task InsertContentRangeAsync(List insertObjs) { return await Context.Insertable(insertObjs).ExecuteCommandAsync() > 0; } public async Task GetParamsSingleAsync(Expression> whereExpression) { return await Context.Queryable().SingleAsync(whereExpression); } public async Task UpdateParamsAsync(TrackPushPullParamsConfigEntity updateObj) { return await Context.Updateable(updateObj).ExecuteCommandHasChangeAsync(); } public async Task SoftDeleteContentAsync(Expression> whereExpression) { return await Context.Updateable() .Where(whereExpression) .SetColumns(nameof(ISoftDeleteBasicEntity.IsDeleted), true) .ExecuteCommandHasChangeAsync(); } public async Task SoftDeleteParamsAsync(Expression> whereExpression) { return await Context.Updateable() .Where(whereExpression) .SetColumns(nameof(ISoftDeleteBasicEntity.IsDeleted), true) .ExecuteCommandHasChangeAsync(); } public async Task GetContentByIdAsync(int id) { return await Context.Queryable().InSingleAsync(id); } public async Task UpdateContentAsync(TrackPullContentConfigEntity updateObj) { return await Context.Updateable(updateObj).ExecuteCommandHasChangeAsync(); } public async Task IsContentAnyAsync(Expression> whereExpression) { return await Context.Queryable().Where(whereExpression).AnyAsync(); } }