243 lines
11 KiB
C#
243 lines
11 KiB
C#
using System.Linq.Expressions;
|
|
using Fake.Domain.Entities.Auditing;
|
|
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.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<VAppEntity>((trackPull, system) => trackPull.AppKey == system.AppKey)
|
|
.LeftJoin<VServiceProviderEntity>((trackPull, system, service) => trackPull.ServiceProviderCode == service.Code)
|
|
.WhereIF(!input.AppKey.IsNullOrWhiteSpace(), trackPull => trackPull.AppKey == input.AppKey)
|
|
.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,
|
|
AppKey = system.AppKey,
|
|
App = system.Name,
|
|
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)
|
|
.Where(pullContent => pullContent.TrackPullConfigId == input.TrackPullConfigId)
|
|
.OrderBy(pullContent => pullContent.CreateTime)
|
|
.Select(
|
|
(pullContent, trackContent) =>
|
|
new GetTrackPullContentPageOutputVO
|
|
{
|
|
Id = pullContent.Id,
|
|
TrackPlaceValue = pullContent.TrackPlaceValue
|
|
}, 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<VAppEntity>((trackPull, system) => trackPull.AppKey == system.AppKey)
|
|
.LeftJoin<VServiceProviderEntity>((trackPull, system, service) => trackPull.ServiceProviderCode == service.Code)
|
|
.Where(trackPull => trackPull.Id == id)
|
|
.Select(
|
|
(trackPull, system, service) => new GetTrackPullConfigDetailOutputVO
|
|
{
|
|
Id = trackPull.Id,
|
|
App = system.Name,
|
|
AppKey = system.AppKey,
|
|
ServiceProviderId = service.Id,
|
|
ServiceProviderCode = service.Code,
|
|
OrderNoName = trackPull.OrderNoName,
|
|
ParseMethod = (int)trackPull.ParseMethod,
|
|
TrackIsoTimeName = trackPull.TrackIsoTimeName,
|
|
TrackTimeName = trackPull.TrackTimeName,
|
|
TrackTimeZoneName = trackPull.TrackTimeZoneName,
|
|
TrackContentCodeName = trackPull.TrackContentCodeName,
|
|
TrackContentName = trackPull.TrackContentName,
|
|
TrackPlaceName = trackPull.TrackPlaceName,
|
|
TrackStatusName = trackPull.TrackStatusName,
|
|
OrderPath = trackPull.OrderPath,
|
|
TrackDetailsPath = trackPull.TrackDetailsPath,
|
|
StartTrackCode = trackPull.StartTrackCode,
|
|
EndTrackCode = trackPull.EndTrackCode,
|
|
SilenceBeforeStart = trackPull.SilenceBeforeStart,
|
|
SilenceAfterEnd = trackPull.SilenceAfterEnd
|
|
}, 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<PagedResult<GetTrackPullPriorityPageOutputVO>> GetPriorityPageAsync(GetTrackPullPriorityPageInputVO input)
|
|
{
|
|
return await Context.Queryable<TrackPullPriorityEntity>()
|
|
.LeftJoin<VUserEntity>((x, creator) => x.CreateUserId == creator.UserId)
|
|
.LeftJoin<VUserEntity>((x, creator, modifier) => x.UpdateUserId == modifier.UserId)
|
|
.Where(x => x.TrackPullConfigId == input.TrackPullConfigId)
|
|
.OrderByDescending(x => x.Priority)
|
|
.Select((x, creator, modifier) => new GetTrackPullPriorityPageOutputVO
|
|
{
|
|
Id = x.Id,
|
|
Customer = x.Customer,
|
|
OrderType = x.OrderType,
|
|
Priority = x.Priority,
|
|
PullInterval = x.PullInterval,
|
|
CreateTime = x.CreateTime,
|
|
CreateUser = creator.Name,
|
|
UpdateUser = modifier.Name,
|
|
UpdateTime = x.UpdateTime
|
|
})
|
|
.ToPagedListAsync(input.PageIndex, input.PageSize);
|
|
}
|
|
|
|
public async Task<GetTrackPullPriorityDetailOutputVO> GetPriorityDetailAsync(int id)
|
|
{
|
|
return await Context.Queryable<TrackPullPriorityEntity>()
|
|
.Where(x => x.Id == id)
|
|
.Select(x => new GetTrackPullPriorityDetailOutputVO
|
|
{
|
|
Id = x.Id,
|
|
TrackPullConfigId = x.TrackPullConfigId,
|
|
Customer = x.Customer,
|
|
OrderType = x.OrderType,
|
|
Priority = x.Priority,
|
|
PullInterval = x.PullInterval
|
|
})
|
|
.SingleAsync();
|
|
}
|
|
|
|
public async Task<bool> InsertContentAsync(TrackPullContentConfigEntity insertObj)
|
|
{
|
|
return await Context.Insertable(insertObj).ExecuteCommandAsync() > 0;
|
|
}
|
|
|
|
public async Task<bool> InsertPriorityAsync(TrackPullPriorityEntity 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<bool> SoftDeletePriorityAsync(Expression<Func<TrackPullPriorityEntity, bool>> whereExpression)
|
|
{
|
|
return await Context.Updateable<TrackPullPriorityEntity>()
|
|
.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<TrackPullPriorityEntity> GetPriorityByIdAsync(int id)
|
|
{
|
|
return await Context.Queryable<TrackPullPriorityEntity>().InSingleAsync(id);
|
|
}
|
|
|
|
public async Task<bool> UpdateContentAsync(TrackPullContentConfigEntity updateObj)
|
|
{
|
|
return await Context.Updateable(updateObj).ExecuteCommandHasChangeAsync();
|
|
}
|
|
|
|
public async Task<bool> UpdatePriorityAsync(TrackPullPriorityEntity 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<bool> IsPriorityAnyAsync(Expression<Func<TrackPullPriorityEntity, bool>> whereExpression)
|
|
{
|
|
return await Context.Queryable<TrackPullPriorityEntity>().Where(whereExpression).AnyAsync();
|
|
}
|
|
|
|
public async Task<int> FindIdAsync(string appKey, string serviceProviderCode)
|
|
{
|
|
return await AsQueryable()
|
|
.Where(trackPull => trackPull.AppKey == appKey
|
|
&& trackPull.ServiceProviderCode == serviceProviderCode)
|
|
.Select(trackPull => trackPull.Id)
|
|
.FirstAsync();
|
|
}
|
|
}
|