using System.Linq.Expressions; using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.Track.Domain.Aggregates.TrackContentAggregate; using SJZY.Track.Domain.Aggregates.TrackPushAggregate; using SJZY.Track.Domain.Dtos.Common; using SJZY.Track.Domain.Dtos.TrackPush; using SJZY.Track.Domain.Enums; using SJZY.Track.Domain.VEntities; namespace SJZY.Track.Repository.Repositories; public class TrackPushConfigRepository : BasicRepository, ITrackPushConfigRepository, IScopedDependency { public async Task> GetPageAsync(KeywordsInputVO input) { return await AsQueryable() .LeftJoin((trackPush, system) => trackPush.SubSystemId == system.Id && !system.IsDeleted) .LeftJoin((trackPush, system, externalSubject) => trackPush.CustomId == externalSubject.Id && !externalSubject.IsDeleted) .Filter(null, true) .Where(trackPush => !trackPush.IsDeleted) .WhereIF(input.SubSystemId.HasValue, trackPush => trackPush.SubSystemId == input.SubSystemId) .WhereIF(!input.Keywords.IsNullOrWhiteSpace(), (trackPush, system, externalSubject) => externalSubject.Abbreviation.Contains(input.Keywords!) || externalSubject.Name.Contains(input.Keywords!)) .OrderByDescending(trackPush => trackPush.CreateTime) .Select((trackPush, system, externalSubject) => new GetTrackPushConfigPageOutputVO { Id = trackPush.Id, SubSystemId = system.Id, SubSystem = system.CnName, CustomName = externalSubject.Abbreviation, CreateTime = trackPush.CreateTime }) .ToPagedListAsync(input.PageIndex, input.PageSize); } public async Task> GetContentPageAsync( GetTrackPushContentPageInputVO input) { return await Context.Queryable() .InnerJoin((pushContent, trackContent) => pushContent.TrackContentId == trackContent.Id) .LeftJoin((pushContent, trackContent, enumValue) => enumValue.Property == EnumPropertyEnums.单号类型.GetDescription() && pushContent.OrderNoType == enumValue.Enumkey && !enumValue.IsDeleted) .Where(pushContent => pushContent.TrackPushConfigId == input.TrackPushConfigId) .OrderBy(pushContent => pushContent.Sort) .Select((pushContent, trackContent, enumValue) => new GetTrackPushContentPageOutputVO { Id = pushContent.Id, Sort = pushContent.Sort, OrderNoType = enumValue.Disp }, true) .ToPagedListAsync(input.PageIndex, input.PageSize); } public async Task GetDetailAsync(int id) { return await AsQueryable() .LeftJoin((trackPush, system) => trackPush.SubSystemId == system.Id && !system.IsDeleted) .LeftJoin((trackPush, system, externalSubject) => trackPush.CustomId == externalSubject.Id && !externalSubject.IsDeleted) .LeftJoin((trackPush, system, externalSubject, service) => trackPush.ServiceProviderId == service.Id && !service.IsDeleted) .Filter(null, true) .Where(trackPush => trackPush.Id == id && !trackPush.IsDeleted) .Select((trackPush, system, externalSubject, service) => new GetTrackPushConfigDetailOutputVO { Id = trackPush.Id, SubSystem = system.CnName, CustomName = externalSubject.Abbreviation, ServiceProvider = service.Name, }, true) .SingleAsync(); } public async Task GetContentDetailAsync(int id) { return await Context.Queryable() .Where(pushContent => pushContent.Id == id) .Select(pushContent => new GetTrackPushContentDetailOutputVO { Id = pushContent.Id }, true) .SingleAsync(); } public async Task SoftDeleteContentAsync(Expression> whereExpression) { return await Context.Updateable() .Where(whereExpression) .SetColumns(nameof(ISoftDeleteBasicEntity.IsDeleted), true) .ExecuteCommandHasChangeAsync(); } public async Task IsContentAnyAsync(Expression> whereExpression) { return await Context.Queryable().Where(whereExpression).AnyAsync(); } public async Task InsertContentAsync(TrackPushContentConfigEntity insertObj) { return await Context.Insertable(insertObj).ExecuteCommandAsync() > 0; } public async Task GetContentByIdAsync(int id) { return await Context.Queryable().InSingleAsync(id); } public async Task UpdateContentAsync(TrackPushContentConfigEntity updateObj) { return await Context.Updateable(updateObj).ExecuteCommandHasChangeAsync(); } public async Task> GetContentListAsync(int configId) { return await Context.Queryable() .LeftJoin((a, b) => a.Id == b.TrackPushConfigId) .LeftJoin((a, b, c) => a.ServiceProviderId == c.Id) .LeftJoin((a, b, c, d) => b.TrackContentId == d.Id) .LeftJoin((a, b, c, d, e) => b.SwapTrackContentId == e.Id) .Where(a => a.Id == configId) .OrderBy((a, b) => b.Sort) .Select((a, b, c, d, e) => new TrackPushContentConfigVO { IsAutoPush = a.IsAutoPush, IsCanUpdate = a.IsCanUpdate, IsAllPush = a.IsAllPush, ServiceProviderCode = c.Code, OrderType = b.OrderNoType, TrackCode = d.Code, SwapTrackCode = e.Code, TrackContentCodeValue = b.TrackContentCodeValue, TrackContentValue = b.TrackContentValue, TrackEnContentValue = b.TrackEnContentValue, TrackStatusValue = b.TrackStatusValue, TrackTimeZone = b.TrackTimeZone, ExpandFieldsValue = b.ExpandFieldsValue, }) .ToListAsync(); } public async Task> GetContentListAsync( Expression> whereExpression) { return await Context.Queryable().Where(whereExpression).ToListAsync(); } public async Task UpdateContentRangeAsync(List updateObjs) { return await Context.Updateable(updateObjs).ExecuteCommandHasChangeAsync(); } public async Task ContentMaxAsync(Expression> columns, Expression> whereExpression) { return await Context.Queryable().Where(whereExpression).MaxAsync(columns); } public async Task UpdateContentAsync(Expression> columns, Expression> whereExpression) { return await Context.Updateable().SetColumns(columns).Where(whereExpression) .ExecuteCommandHasChangeAsync(); } /// /// 查询轨迹推送关系 /// /// /// public async Task> QueryTrackPullMappingsAsync(QueryTrackPullMappingsInputVO input) { var result = await Context.Queryable().LeftJoin((a, b) => a.Id == b.TrackPushConfigId && !b.IsDeleted) .LeftJoin((a, b, c) => b.TrackContentId == c.Id && !c.IsDeleted) .Where((a, b, c) => !a.IsDeleted) .Where((a, b, c) => a.SubSystemId == input.SubsystemsId && a.CustomId == input.CustomerId) .Select((a, b, c) => new QueryTrackPullMappingsInfoVO { Code = c.Code, OrderType = b.OrderNoType, ServiceCode = b.TrackContentCodeValue, Status = b.TrackStatusValue, Content = b.TrackContentValue, ContentEn = b.TrackEnContentValue }) .ToListAsync(); return result; } }