track/src/TrackCenter.Repository/Repositories/TrackPullConfigRepository.cs
2025-07-30 22:00:02 +08:00

169 lines
7.7 KiB
C#

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<TrackPullConfigEntity>, ITrackPullConfigRepository,
IScopedDependency
{
public async Task<PagedResult<GetTrackPullConfigPageOutputVO>> GetPageAsync(KeywordsInputVO input)
{
return await Context.Queryable<TrackPullConfigEntity>()
.LeftJoin<VSystemEntity>((trackPull, system) => trackPull.SubSystemId == system.Id)
.LeftJoin<VServiceProviderEntity>((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<PagedResult<GetTrackPullContentPageOutputVO>> GetContentPageAsync(
GetTrackPullContentPageInputVO input)
{
return await Context.Queryable<TrackPullContentConfigEntity>()
.InnerJoin<TrackContentEntity>((pullContent, trackContent) => pullContent.TrackContentId == trackContent.Id)
.LeftJoin<VEnumValueInfoEntity>((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<List<GetTrackPullContentListCacheVO>> GetContentListCacheAsync(int trackPullConfigId)
{
return await Context.Queryable<TrackPullContentConfigEntity>()
.InnerJoin<TrackContentEntity>((pullContent, trackContent) => pullContent.TrackContentId == trackContent.Id)
.LeftJoin<TrackStatusEntity>((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<string>()
: x.TrackKeyword!.Split(',').ToList();
x.TrackKeywordReverses = x.TrackKeywordReverse.IsNullOrWhiteSpace()
? new List<string>()
: x.TrackKeywordReverse!.Split(',').ToList();
x.TrackStatusValues = x.TrackStatusValue.IsNullOrWhiteSpace()
? new List<string>()
: x.TrackStatusValue!.Split(',').ToList();
})
.ToListAsync();
}
public async Task<GetTrackPullConfigDetailOutputVO?> GetDetailAsync(int id)
{
return await AsQueryable()
.LeftJoin<VSystemEntity>((trackPull, system) => trackPull.SubSystemId == system.Id)
.LeftJoin<VServiceProviderEntity>((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<GetTrackPullContentDetailOutputVO> GetContentDetailAsync(int id)
{
return await Context.Queryable<TrackPullContentConfigEntity>()
.InnerJoin<TrackContentEntity>((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<string>()
: x.TrackKeyword!.Split(',').ToList();
x.TrackKeywordReverses = x.TrackKeywordReverse.IsNullOrWhiteSpace()
? new List<string>()
: x.TrackKeywordReverse!.Split(',').ToList();
x.TrackStatusValues = x.TrackStatusValue.IsNullOrWhiteSpace()
? new List<string>()
: x.TrackStatusValue!.Split(',').ToList();
})
.SingleAsync();
}
public async Task<bool> InsertContentAsync(TrackPullContentConfigEntity insertObj)
{
return await Context.Insertable(insertObj).ExecuteCommandAsync() > 0;
}
public async Task<bool> SoftDeleteContentAsync(Expression<Func<TrackPullContentConfigEntity, bool>> whereExpression)
{
return await Context.Updateable<TrackPullContentConfigEntity>()
.Where(whereExpression)
.SetColumns(nameof(ISoftDelete.IsDeleted), true)
.ExecuteCommandHasChangeAsync();
}
public async Task<TrackPullContentConfigEntity> GetContentByIdAsync(int id)
{
return await Context.Queryable<TrackPullContentConfigEntity>().InSingleAsync(id);
}
public async Task<bool> UpdateContentAsync(TrackPullContentConfigEntity updateObj)
{
return await Context.Updateable(updateObj).ExecuteCommandHasChangeAsync();
}
public async Task<bool> IsContentAnyAsync(Expression<Func<TrackPullContentConfigEntity, bool>> whereExpression)
{
return await Context.Queryable<TrackPullContentConfigEntity>().Where(whereExpression).AnyAsync();
}
public async Task<int> FindIdAsync(int subSystemId, string serviceProviderCode)
{
return await AsQueryable()
.LeftJoin<VServiceProviderEntity>((trackPull, service) => trackPull.ServiceProviderId == service.Id)
.Where((trackPull, service) => trackPull.SubSystemId == subSystemId && service.Code == serviceProviderCode)
.Select(trackPull => trackPull.Id)
.FirstAsync();
}
}