track/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs
2024-03-23 14:12:02 +08:00

170 lines
8.2 KiB
C#

using System.Linq.Expressions;
using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.Track.Domain.Aggregates.TrackContentAggregate;
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
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;
using SJZY.Track.Repository.VData.Entitys;
namespace SJZY.Track.Repository.Repositories;
public class TrackPushConfigRepository : BasicRepository<TrackPushConfigEntity>, ITrackPushConfigRepository,
IScopedDependency
{
public async Task<UnifyPageResultDto<GetTrackPushConfigPageOutputVO>> GetPageAsync(KeywordsInputVO input)
{
return await AsQueryable()
.LeftJoin<VSystemEntity>((trackPush, system) => trackPush.SubSystemId == system.Id && !system.IsDeleted)
.LeftJoin<VExternalSubjectEntity>((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<UnifyPageResultDto<GetTrackPushContentPageOutputVO>> GetContentPageAsync(
GetTrackPushContentPageInputVO input)
{
return await Context.Queryable<TrackPushContentConfigEntity>()
.InnerJoin<TrackContentEntity>((pushContent, trackContent) => pushContent.TrackContentId == trackContent.Id)
.LeftJoin<VEnumValueInfoEntity>((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<GetTrackPushConfigDetailOutputVO> GetDetailAsync(int id)
{
return await AsQueryable()
.LeftJoin<VSystemEntity>((trackPush, system) => trackPush.SubSystemId == system.Id && !system.IsDeleted)
.LeftJoin<VExternalSubjectEntity>((trackPush, system, externalSubject) =>
trackPush.CustomId == externalSubject.Id && !externalSubject.IsDeleted)
.LeftJoin<VServiceProviderEntity>((trackPush, system, externalSubject, service) =>
trackPush.ServiceProviderId == service.Id && !service.IsDeleted)
.InnerJoin<TrackPushPullParamsConfigEntity>((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)
.SingleAsync();
}
public async Task<GetTrackPushContentDetailOutputVO> GetContentDetailAsync(int id)
{
return await Context.Queryable<TrackPushContentConfigEntity>()
.InnerJoin<TrackContentEntity>((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<bool> SoftDeleteContentAsync(Expression<Func<TrackPushContentConfigEntity, bool>> whereExpression)
{
return await Context.Updateable<TrackPushContentConfigEntity>()
.Where(whereExpression)
.SetColumns(nameof(ISoftDeleteBasicEntity.IsDeleted), true)
.ExecuteCommandHasChangeAsync();
}
public async Task<bool> IsContentAnyAsync(Expression<Func<TrackPushContentConfigEntity, bool>> whereExpression)
{
return await Context.Queryable<TrackPushContentConfigEntity>().Where(whereExpression).AnyAsync();
}
public async Task<bool> InsertContentAsync(TrackPushContentConfigEntity insertObj)
{
return await Context.Insertable(insertObj).ExecuteCommandAsync() > 0;
}
public async Task<TrackPushContentConfigEntity> GetContentByIdAsync(int id)
{
return await Context.Queryable<TrackPushContentConfigEntity>().InSingleAsync(id);
}
public async Task<bool> UpdateContentAsync(TrackPushContentConfigEntity updateObj)
{
return await Context.Updateable(updateObj).ExecuteCommandHasChangeAsync();
}
public async Task<List<TrackPushContentConfigVO>> GetContentListAsync(int configId)
{
return await Context.Queryable<TrackPushConfigEntity>()
.LeftJoin<TrackPushContentConfigEntity>((a, b) => a.Id == b.TrackPushConfigId)
.LeftJoin<VServiceProviderEntity>((a, b, c) => a.ServiceProviderId == c.Id)
.Where(a => a.Id == configId)
.OrderBy((a, b) => b.Sort)
.Select((a, b, c) => new TrackPushContentConfigVO
{
IsAutoPush = a.IsAutoPush,
IsCanUpdate = a.IsCanUpdate,
ServiceProviderCode = c.Code,
ExpandFieldsValue = b.ExpandFieldsValue,
OrderType = b.OrderNoType,
TrackContentCodeValue = b.TrackContentCodeValue,
TrackContentId = b.TrackContentId,
TrackContentValue = b.TrackContentValue,
TrackEnContentValue = b.TrackEnContentValue,
TrackStatusValue = b.TrackStatusValue,
TrackTimeZone = b.TrackTimeZone
})
.ToListAsync();
}
public async Task<List<TrackPushContentConfigEntity>> GetContentListAsync(
Expression<Func<TrackPushContentConfigEntity, bool>> whereExpression)
{
return await Context.Queryable<TrackPushContentConfigEntity>().Where(whereExpression).ToListAsync();
}
public async Task<bool> UpdateContentRangeAsync(List<TrackPushContentConfigEntity> updateObjs)
{
return await Context.Updateable(updateObjs).ExecuteCommandHasChangeAsync();
}
public async Task<T> ContentMaxAsync<T>(Expression<Func<TrackPushContentConfigEntity, T>> columns,
Expression<Func<TrackPushContentConfigEntity, bool>> whereExpression)
{
return await Context.Queryable<TrackPushContentConfigEntity>().Where(whereExpression).MaxAsync(columns);
}
public async Task<bool> UpdateContentAsync(Expression<Func<TrackPushContentConfigEntity, bool>> columns,
Expression<Func<TrackPushContentConfigEntity, bool>> whereExpression)
{
return await Context.Updateable<TrackPushContentConfigEntity>().SetColumns(columns).Where(whereExpression)
.ExecuteCommandHasChangeAsync();
}
}