122 lines
5.0 KiB
C#
122 lines
5.0 KiB
C#
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
|
using SJZY.Track.Domain.Aggregates.TrackContentAggregate;
|
|
using SJZY.Track.Domain.Aggregates.TrackFlagAggregate;
|
|
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
|
|
using SJZY.Track.Domain.Aggregates.TrackStatusAggregate;
|
|
using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate;
|
|
using SJZY.Track.Domain.Dtos.Order;
|
|
using SJZY.Track.Domain.Dtos.TrackDetails;
|
|
using SJZY.Track.Domain.Dtos.TrackTemplate;
|
|
using SJZY.Track.Domain.Queries;
|
|
|
|
namespace SJZY.Track.Repository.Queries;
|
|
|
|
public class ProvideQueries : ISugarRepository, IProvideQueries,
|
|
ITransientDependency
|
|
{
|
|
public ISqlSugarClient Context { get; set; }
|
|
|
|
public ProvideQueries()
|
|
{
|
|
Context = SqlsugarScopeBasic.GetContextSafely("default");
|
|
}
|
|
|
|
public async Task<List<OrderTemplateLinkDto>> GetOrderTemplateLinksAsync(int orderType,
|
|
params string[] orderNumbers)
|
|
{
|
|
return await Context.Queryable<OrderEntity>()
|
|
.LeftJoin<OrderTemplateEntity>((a, b) => a.Id == b.OrderId)
|
|
.Where(a => a.OrderType == orderType && orderNumbers.Contains(a.OrderNo))
|
|
.Select((a, b) => new OrderTemplateLinkDto
|
|
{
|
|
OrderNo = a.OrderNo,
|
|
TemplateId = b.TrackTemplateId
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<List<OrderTemplateLinkDto>> GetOrderTemplateLinksAsync(int orderType, List<string> orderNumbers)
|
|
{
|
|
return await Context.Queryable<OrderEntity>()
|
|
.LeftJoin<OrderTemplateEntity>((a, b) => a.Id == b.OrderId)
|
|
.Where(a => a.OrderType == orderType && orderNumbers.Contains(a.OrderNo))
|
|
.Select((a, b) => new OrderTemplateLinkDto
|
|
{
|
|
OrderNo = a.OrderNo,
|
|
TemplateId = b.TrackTemplateId
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<List<OrderedTrackCodeDto>> GetOrderedTrackCodesAsync(List<int> templateIds)
|
|
{
|
|
return await Context.Queryable<TrackTemplateContentEntity>()
|
|
.LeftJoin<TrackContentEntity>((a, b) => a.TrackContentId == b.Id)
|
|
.Where(a => templateIds.Contains(a.TrackTemplateId))
|
|
.OrderBy(a => a.Sort)
|
|
.Select((a, b) => new OrderedTrackCodeDto
|
|
{
|
|
TemplateId = a.TrackTemplateId,
|
|
Code = b.Code,
|
|
IsExternal = a.IsExternal
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<MatchTrackContentDto?> MatchTrackContentAsync(int orderId, string code)
|
|
{
|
|
return await Context.Queryable<OrderTemplateEntity>()
|
|
.LeftJoin<TrackTemplateContentEntity>((x, a) => x.TrackTemplateId == a.TrackTemplateId)
|
|
.LeftJoin<TrackContentEntity>((x, a, b) => a.TrackContentId == b.Id)
|
|
.LeftJoin<TrackStatusEntity>((x, a, b, c) => b.TrackStatusId == c.Id)
|
|
.LeftJoin<TrackFlagEntity>((x, a, b, c, d) => b.TrackFlagId == d.Id)
|
|
.Where((x, a, b) => x.OrderId == orderId && b.Code == code)
|
|
.Select((x, a, b, c, d) => new MatchTrackContentDto
|
|
{
|
|
Content = b.Content,
|
|
EnContent = b.EnContent,
|
|
Status = c.Status,
|
|
IsCompleted = b.IsCompleted
|
|
})
|
|
.FirstAsync();
|
|
}
|
|
|
|
public async Task<List<string>> GetCanDeleteTrackCodesAsync(int orderId, List<string> trackCodes)
|
|
{
|
|
return await Context.Queryable<OrderTemplateEntity>()
|
|
.LeftJoin<TrackTemplateContentEntity>((x, a) => x.TrackTemplateId == a.TrackTemplateId && a.IsCanDelete)
|
|
.LeftJoin<TrackContentEntity>((x, a, b) => a.TrackContentId == b.Id)
|
|
.Where((x, a, b) => x.OrderId == orderId
|
|
&& trackCodes.Contains(b.Code))
|
|
.Select((x, a, b) => b.Code)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<List<string>> MapTrackCodesAsync(int upSubSystemId, int subSystemId, params string[] trackCodes)
|
|
{
|
|
// 根据上游code得到下游code
|
|
return await Context.Queryable<TrackContentMapEntity>()
|
|
.Where(x => x.SubSystemId == subSystemId && x.MapSubSystemId == upSubSystemId &&
|
|
trackCodes.Contains(x.MapTrackContentCode))
|
|
.Select(x => x.TrackContentCode)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<List<TrackPullContentConfigVO>> GetPullContentConfigsAsync(int serviceProviderId)
|
|
{
|
|
return await Context.Queryable<TrackPullConfigEntity>()
|
|
.LeftJoin<TrackPullContentConfigEntity>((a, b) => a.Id == b.TrackPullConfigId)
|
|
.Where(a => a.ServiceProviderId == serviceProviderId)
|
|
.Select(x => new TrackPullContentConfigVO
|
|
{
|
|
TrackContentId = 0,
|
|
TrackContentCodeValue = null,
|
|
TrackContentValue = null,
|
|
TrackKeyword = null,
|
|
TrackKeywordReverse = null,
|
|
TrackPlaceValue = null,
|
|
TrackStatusValue = null,
|
|
TrackTimeZone = null
|
|
}).ToListAsync();
|
|
}
|
|
} |