using System.Linq.Expressions; using Fake.Domain.Entities.Auditing; using InterfaceForward.Domain.Shared.Helpers; using TrackCenter.Domain.Aggregates.TrackContentAggregate; using TrackCenter.Domain.Aggregates.TrackPullAggregate; using TrackCenter.Domain.Aggregates.TrackStatusAggregate; using TrackCenter.Domain.Dtos.Common; using TrackCenter.Domain.Dtos.TrackPull; using TrackCenter.Domain.Enums; using TrackCenter.Domain.VEntities; namespace TrackCenter.Repository.Repositories; public class TrackPullConfigRepository : BasicRepository, ITrackPullConfigRepository, IScopedDependency { public async Task> GetPageAsync(KeywordsInputVO input) { return await Context.Queryable() .LeftJoin((trackPull, system) => trackPull.SubSystemId == system.Id) .LeftJoin((trackPull, system, service) => trackPull.ServiceProviderId == service.Id) .WhereIF(input.SubSystemId.HasValue, trackPull => trackPull.SubSystemId == input.SubSystemId) .WhereIF(!input.Keywords.IsNullOrWhiteSpace(), (trackPull, system, service) => service.Name.Contains(input.Keywords!)) .OrderByDescending(trackPull => trackPull.CreateTime) .Select((trackPull, system, service) => new GetTrackPullConfigPageOutputVO { Id = trackPull.Id, SubSystemId = system.Id, SubSystem = system.CnName, ServiceProvider = service.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) .LeftJoin((pullContent, trackContent, enumValue) => enumValue.Property == EnumPropertyEnums.轨迹发生地.GetDescription() && pullContent.TrackPlaceValue == enumValue.Enumkey) .Where(pullContent => pullContent.TrackPullConfigId == input.TrackPullConfigId) .OrderBy(pullContent => pullContent.CreateTime) .Select( (pullContent, trackContent, enumValue) => new GetTrackPullContentPageOutputVO { Id = pullContent.Id, TrackPlaceValue = enumValue.Disp }, true) .ToPagedListAsync(input.PageIndex, input.PageSize); } public async Task> GetContentListCacheAsync(int trackPullConfigId) { return await Context.Queryable() .InnerJoin((pullContent, trackContent) => pullContent.TrackContentId == trackContent.Id) .LeftJoin((pullContent, trackContent, trackStutas) => trackContent.TrackStatusId == trackStutas.Id) .Where(pullContent => pullContent.TrackPullConfigId == trackPullConfigId) .Select( (pullContent, trackContent, trackStutas) => new GetTrackPullContentListCacheVO { TrackContentCode = trackContent.Code, }, true) .Mapper(x => { x.TrackKeywords = x.TrackKeyword.IsNullOrWhiteSpace() ? new List() : x.TrackKeyword!.Split(',').ToList(); x.TrackKeywordReverses = x.TrackKeywordReverse.IsNullOrWhiteSpace() ? new List() : x.TrackKeywordReverse!.Split(',').ToList(); x.TrackStatusValues = x.TrackStatusValue.IsNullOrWhiteSpace() ? new List() : x.TrackStatusValue!.Split(',').ToList(); }) .ToListAsync(); } public async Task GetDetailAsync(int id) { return await AsQueryable() .LeftJoin((trackPull, system) => trackPull.SubSystemId == system.Id) .LeftJoin((trackPull, system, service) => trackPull.ServiceProviderId == service.Id) .Where(trackPull => trackPull.Id == id) .Select( (trackPull, system, service) => new GetTrackPullConfigDetailOutputVO { Id = trackPull.Id, SubSystem = system.CnName, SubSystemId = system.Id, ServiceProviderId = service.Id, ServiceProviderCode = service.Code, }, true) .FirstAsync(); } 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, TrackTimePlaceValue = pullContent.TrackZonePlaceValue, }, true) .Mapper(x => { x.TrackKeywords = x.TrackKeyword.IsNullOrWhiteSpace() ? new List() : x.TrackKeyword!.Split(',').ToList(); x.TrackKeywordReverses = x.TrackKeywordReverse.IsNullOrWhiteSpace() ? new List() : x.TrackKeywordReverse!.Split(',').ToList(); x.TrackStatusValues = x.TrackStatusValue.IsNullOrWhiteSpace() ? new List() : x.TrackStatusValue!.Split(',').ToList(); }) .SingleAsync(); } public async Task InsertContentAsync(TrackPullContentConfigEntity insertObj) { return await Context.Insertable(insertObj).ExecuteCommandAsync() > 0; } public async Task SoftDeleteContentAsync(Expression> whereExpression) { return await Context.Updateable() .Where(whereExpression) .SetColumns(nameof(ISoftDelete.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(); } public async Task FindIdAsync(int subSystemId, string serviceProviderCode) { return await AsQueryable() .LeftJoin((trackPull, service) => trackPull.ServiceProviderId == service.Id) .Where((trackPull, service) => trackPull.SubSystemId == subSystemId && service.Code == serviceProviderCode) .Select(trackPull => trackPull.Id) .FirstAsync(); } }