using SJZY.Track.Domain.Aggregates.TrackContentAggregate; using SJZY.Track.Domain.Aggregates.TrackPullAggregate; using SJZY.Track.Domain.Aggregates.TrackPushAggregate; using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate; using SJZY.Track.Domain.Dtos.Common; using SJZY.Track.Domain.Dtos.TrackPush; using SJZY.Track.Domain.VEntities; using SJZY.Track.Repository.VData.Entitys; using System.Linq.Expressions; 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) .LeftJoin((trackPush, system, externalSubject, template) => SqlFunc.SplitIn(trackPush.TrackTemplateId, template.Id.ToString()) && !template.IsDeleted) .Filter(null, true) .Where(trackPush => !trackPush.IsDeleted) .WhereIF(input.SubSystemId.HasValue, trackPush => trackPush.SubSystemId == input.SubSystemId) .WhereIF(!input.Keywords.IsNullOrWhiteSpace(), (trackPush, system, externalSubject, template) => externalSubject.Abbreviation.Contains(input.Keywords) || externalSubject.Name.Contains(input.Keywords) || template.Name.Contains(input.Keywords)) .OrderByDescending(trackPush => trackPush.CreateTime) .Select((trackPush, system, externalSubject, template) => new GetTrackPushConfigPageOutputVO { Id = trackPush.Id, SubSystem = system.CnName, CustomName = externalSubject.Abbreviation, TrackTemplate = SqlFunc.Subqueryable() .Where(template => SqlFunc.SplitIn(trackPush.TrackTemplateId, template.Id.ToString()) && !template.IsDeleted) .SelectStringJoin(template => template.Name, ","), CreateTime = trackPush.CreateTime }) .Distinct() .ToPagedListAsync(input.PageIndex, input.PageSize); } public async Task> GetContentPageAsync(GetTrackPushContentPageInputVO input) { return await Context.Queryable() .InnerJoin((pushContent, trackContent) => pushContent.TrackContentId == trackContent.Id) .Where(pushContent => pushContent.TrackPushConfigId == input.TrackPushConfigId) .OrderBy((pushContent, trackContent) => pushContent.Sort) .Select((pushContent, trackContent) => new GetTrackPushContentPageOutputVO { Id = pushContent.Id, Sort = pushContent.Sort }, 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) .InnerJoin((trackPush, system, externalSubject, service, paramsConfig) => trackPush.Id == paramsConfig.PullOrPushConfigId && paramsConfig.IsPush && !paramsConfig.IsDeleted) .Filter(null, true) .Where(trackPush => trackPush.Id == id && !trackPush.IsDeleted) .Select((trackPush, system, externalSubject, service, paramsConfig) => new GetTrackPushConfigDetailOutputVO { Id = trackPush.Id, SubSystem = system.CnName, CustomName = externalSubject.Abbreviation, ServiceProvider = service.Name, }, true) .Mapper(x => { x.TrackTemplateIds = x.TrackTemplateId.Split(',').Select(int.Parse).ToList(); }) .SingleAsync(); } public async Task GetContentDetailAsync(int id) { return await Context.Queryable() .InnerJoin((pushContent, trackContent) => pushContent.TrackContentId == trackContent.Id) .Where(pushContent => pushContent.Id == id) .Select((pushContent, trackContent) => new GetTrackPushContentDetailOutputVO { Id = pushContent.Id, Code = trackContent.Code + "-" + trackContent.Content, }, 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(); } }