115 lines
6.2 KiB
C#
115 lines
6.2 KiB
C#
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<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)
|
|
.LeftJoin<TrackTemplateEntity>((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<TrackTemplateEntity>()
|
|
.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<UnifyPageResultDto<GetTrackPushContentPageOutputVO>> GetContentPageAsync(GetTrackPushContentPageInputVO input)
|
|
{
|
|
return await Context.Queryable<TrackPushContentConfigEntity>()
|
|
.InnerJoin<TrackContentEntity>((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<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)
|
|
.Mapper(x => { x.TrackTemplateIds = x.TrackTemplateId.Split(',').Select(int.Parse).ToList(); })
|
|
.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();
|
|
}
|
|
} |