test #4
@ -49,26 +49,80 @@ public class ProvideQueries : SqlSugarRootlessRepository<TrackCenterDbContext>,
|
|||||||
public async Task<List<OrderWithServiceProviderVO>> FindOrderWithServiceProviderAsync(string appKey,
|
public async Task<List<OrderWithServiceProviderVO>> FindOrderWithServiceProviderAsync(string appKey,
|
||||||
List<string> orderNos)
|
List<string> orderNos)
|
||||||
{
|
{
|
||||||
return await Context.Queryable<OrderEntity>()
|
var orderRows = await Context.Queryable<OrderEntity>()
|
||||||
.InnerJoin<OrderPullStatusEntity>((a, b) => a.Id == b.OrderId)
|
.InnerJoin<OrderPullStatusEntity>((a, b) => a.Id == b.OrderId)
|
||||||
.LeftJoin<TrackPullConfigEntity>((a, b, c) =>
|
|
||||||
a.AppKey == c.AppKey && a.ServiceProviderCode == c.ServiceProviderCode)
|
|
||||||
.LeftJoin<TrackPullPriorityEntity>((a, b, c, d) => c.Id == d.TrackPullConfigId && a.Customer == d.Customer)
|
|
||||||
.WhereIF(!appKey.IsNullOrWhiteSpace(), a => a.AppKey == appKey)
|
.WhereIF(!appKey.IsNullOrWhiteSpace(), a => a.AppKey == appKey)
|
||||||
.Where((a, b) => !a.IsCompleted && orderNos.Contains(a.OrderNo)
|
.Where((a, b) => !a.IsCompleted && orderNos.Contains(a.OrderNo)
|
||||||
&& b.StartTime <= DateTime.Now && b.EndTime >= DateTime.Now)
|
&& b.StartTime <= DateTime.Now && b.EndTime >= DateTime.Now)
|
||||||
.Select((a, b, c, d) => new OrderWithServiceProviderVO
|
.Select((a, b) => new
|
||||||
{
|
{
|
||||||
OrderNo = d.OrderNoType == TrackOrderNoType.客户单号 ? a.OrderNo :
|
CustomerOrderNo = a.OrderNo,
|
||||||
d.OrderNoType == TrackOrderNoType.跟踪单号 ? a.TrackNo :
|
a.TrackNo,
|
||||||
d.OrderNoType == TrackOrderNoType.其他单号 ? a.ThirdPartyOrderNumber : a.OrderNo,
|
a.ThirdPartyOrderNumber,
|
||||||
TrackNo = a.TrackNo,
|
a.Customer,
|
||||||
OtherNo = a.ThirdPartyOrderNumber,
|
a.OrderType,
|
||||||
OrderType = a.OrderType,
|
a.AppKey,
|
||||||
AppKey = a.AppKey,
|
|
||||||
ServiceProviderCode = b.ServiceProviderCode,
|
ServiceProviderCode = b.ServiceProviderCode,
|
||||||
})
|
})
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
if (orderRows.Count == 0) return [];
|
||||||
|
|
||||||
|
var appKeys = orderRows.Select(x => x.AppKey).Distinct().ToList();
|
||||||
|
var serviceProviderCodes = orderRows.Select(x => x.ServiceProviderCode).Distinct().ToList();
|
||||||
|
|
||||||
|
// 拉取优先级:精确客户优先于 * 兜底;同级按 Priority 升序
|
||||||
|
var priorities = await Context.Queryable<TrackPullConfigEntity>()
|
||||||
|
.InnerJoin<TrackPullPriorityEntity>((c, d) => c.Id == d.TrackPullConfigId)
|
||||||
|
.Where((c, d) => appKeys.Contains(c.AppKey) && serviceProviderCodes.Contains(c.ServiceProviderCode))
|
||||||
|
.Select((c, d) => new
|
||||||
|
{
|
||||||
|
c.AppKey,
|
||||||
|
c.ServiceProviderCode,
|
||||||
|
c.OrderType,
|
||||||
|
d.Customer,
|
||||||
|
d.OrderNoType,
|
||||||
|
d.Priority,
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return orderRows.Select(o =>
|
||||||
|
{
|
||||||
|
var matched = priorities
|
||||||
|
.Where(p => p.AppKey == o.AppKey
|
||||||
|
&& p.ServiceProviderCode == o.ServiceProviderCode
|
||||||
|
&& p.OrderType == o.OrderType
|
||||||
|
&& (p.Customer == o.Customer || p.Customer == GlobalConst.All))
|
||||||
|
.OrderBy(p => p.Customer == o.Customer ? 0 : 1)
|
||||||
|
.ThenBy(p => p.Priority)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
return new OrderWithServiceProviderVO
|
||||||
|
{
|
||||||
|
OrderNo = ResolvePullOrderNo(matched?.OrderNoType, o.CustomerOrderNo, o.TrackNo,
|
||||||
|
o.ThirdPartyOrderNumber),
|
||||||
|
TrackNo = o.TrackNo,
|
||||||
|
OtherNo = o.ThirdPartyOrderNumber,
|
||||||
|
OrderType = o.OrderType,
|
||||||
|
AppKey = o.AppKey,
|
||||||
|
ServiceProviderCode = o.ServiceProviderCode,
|
||||||
|
};
|
||||||
|
}).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 按拉取优先级配置的单号类型解析下游拉取主单号。
|
||||||
|
/// </summary>
|
||||||
|
private static string ResolvePullOrderNo(TrackOrderNoType? orderNoType, string customerOrderNo, string? trackNo,
|
||||||
|
string? otherNo)
|
||||||
|
{
|
||||||
|
return orderNoType switch
|
||||||
|
{
|
||||||
|
TrackOrderNoType.客户单号 => customerOrderNo,
|
||||||
|
TrackOrderNoType.跟踪单号 => trackNo.IsNullOrWhiteSpace() ? customerOrderNo : trackNo!,
|
||||||
|
TrackOrderNoType.其他单号 => otherNo.IsNullOrWhiteSpace() ? customerOrderNo : otherNo!,
|
||||||
|
_ => customerOrderNo,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -153,7 +207,7 @@ public class ProvideQueries : SqlSugarRootlessRepository<TrackCenterDbContext>,
|
|||||||
TrackPullConfigVo config,
|
TrackPullConfigVo config,
|
||||||
int pageIndex, int pageSize = 1000)
|
int pageIndex, int pageSize = 1000)
|
||||||
{
|
{
|
||||||
return await Context.Queryable<OrderEntity>()
|
var rows = await Context.Queryable<OrderEntity>()
|
||||||
.InnerJoin<OrderPullStatusEntity>((a, b) => a.Id == b.OrderId)
|
.InnerJoin<OrderPullStatusEntity>((a, b) => a.Id == b.OrderId)
|
||||||
.Where((a, b) => b.ServiceProviderCode == config.ServiceProviderCode
|
.Where((a, b) => b.ServiceProviderCode == config.ServiceProviderCode
|
||||||
&& a.AppKey == config.AppKey
|
&& a.AppKey == config.AppKey
|
||||||
@ -162,20 +216,28 @@ public class ProvideQueries : SqlSugarRootlessRepository<TrackCenterDbContext>,
|
|||||||
&& b.EndTime >= DateTime.Now
|
&& b.EndTime >= DateTime.Now
|
||||||
)
|
)
|
||||||
.WhereIF(config.Customer != GlobalConst.All, a => a.Customer == config.Customer)
|
.WhereIF(config.Customer != GlobalConst.All, a => a.Customer == config.Customer)
|
||||||
.Select((a, b) => new OrderWithServiceProviderVO
|
.Select((a, b) => new
|
||||||
{
|
{
|
||||||
OrderNo = config.OrderNoType == TrackOrderNoType.客户单号 ? a.OrderNo :
|
CustomerOrderNo = a.OrderNo,
|
||||||
config.OrderNoType == TrackOrderNoType.跟踪单号 ? a.TrackNo :
|
a.TrackNo,
|
||||||
config.OrderNoType == TrackOrderNoType.其他单号 ? a.ThirdPartyOrderNumber : a.OrderNo,
|
a.ThirdPartyOrderNumber,
|
||||||
TrackNo = a.TrackNo,
|
a.OrderType,
|
||||||
OtherNo = a.ThirdPartyOrderNumber,
|
a.AppKey,
|
||||||
OrderType = a.OrderType,
|
|
||||||
AppKey = a.AppKey,
|
|
||||||
ServiceProviderCode = b.ServiceProviderCode
|
ServiceProviderCode = b.ServiceProviderCode
|
||||||
})
|
})
|
||||||
.Skip((pageIndex - 1) * pageSize)
|
.Skip((pageIndex - 1) * pageSize)
|
||||||
.Take(pageSize)
|
.Take(pageSize)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
return rows.Select(o => new OrderWithServiceProviderVO
|
||||||
|
{
|
||||||
|
OrderNo = ResolvePullOrderNo(config.OrderNoType, o.CustomerOrderNo, o.TrackNo, o.ThirdPartyOrderNumber),
|
||||||
|
TrackNo = o.TrackNo,
|
||||||
|
OtherNo = o.ThirdPartyOrderNumber,
|
||||||
|
OrderType = o.OrderType,
|
||||||
|
AppKey = o.AppKey,
|
||||||
|
ServiceProviderCode = o.ServiceProviderCode
|
||||||
|
}).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<TrackContentVO?> GetTrackContentAsync(string appKey, string trackCode)
|
public async Task<TrackContentVO?> GetTrackContentAsync(string appKey, string trackCode)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user