track/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs
2024-08-20 18:18:57 +08:00

205 lines
9.4 KiB
C#

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;
using SJZY.Track.Share.Enums;
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)
.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,
DateTimeFormat = trackPush.DateTimeFormat,
DateTimeFormatType =
trackPush.DateTimeFormatType == DateTimeFormatEnum.None
? null
: trackPush.DateTimeFormatType,
TimezoneFormat = trackPush.TimezoneFormat
}, true)
.SingleAsync();
}
public async Task<GetTrackPushContentDetailOutputVO> GetContentDetailAsync(int id)
{
return await Context.Queryable<TrackPushContentConfigEntity>()
.Where(pushContent => pushContent.Id == id)
.Select(pushContent => new GetTrackPushContentDetailOutputVO
{
Id = pushContent.Id
}, 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)
.LeftJoin<TrackContentEntity>((a, b, c, d) => b.TrackContentId == d.Id)
.LeftJoin<TrackContentEntity>((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<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();
}
/// <summary>
/// 查询轨迹推送关系
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<List<QueryTrackPullMappingsInfoVO>> QueryTrackPullMappingsAsync(
QueryTrackPullMappingsInputVO input)
{
var result = await Context.Queryable<TrackPushConfigEntity>()
.LeftJoin<TrackPushContentConfigEntity>((a, b) => a.Id == b.TrackPushConfigId && !b.IsDeleted)
.LeftJoin<TrackContentEntity>((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;
}
}