Compare commits
No commits in common. "f27860a60320c608cda3e8ae7edc101dae661419" and "59eec5bcfb04fba8a6db6c5320c963d27fc4e45b" have entirely different histories.
f27860a603
...
59eec5bcfb
@ -49,80 +49,26 @@ 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)
|
||||||
{
|
{
|
||||||
var orderRows = await Context.Queryable<OrderEntity>()
|
return 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) => new
|
.Select((a, b, c, d) => new OrderWithServiceProviderVO
|
||||||
{
|
{
|
||||||
CustomerOrderNo = a.OrderNo,
|
OrderNo = d.OrderNoType == TrackOrderNoType.客户单号 ? a.OrderNo :
|
||||||
a.TrackNo,
|
d.OrderNoType == TrackOrderNoType.跟踪单号 ? a.TrackNo :
|
||||||
a.ThirdPartyOrderNumber,
|
d.OrderNoType == TrackOrderNoType.其他单号 ? a.ThirdPartyOrderNumber : a.OrderNo,
|
||||||
a.Customer,
|
TrackNo = a.TrackNo,
|
||||||
a.OrderType,
|
OtherNo = a.ThirdPartyOrderNumber,
|
||||||
a.AppKey,
|
OrderType = a.OrderType,
|
||||||
|
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>
|
||||||
@ -207,7 +153,7 @@ public class ProvideQueries : SqlSugarRootlessRepository<TrackCenterDbContext>,
|
|||||||
TrackPullConfigVo config,
|
TrackPullConfigVo config,
|
||||||
int pageIndex, int pageSize = 1000)
|
int pageIndex, int pageSize = 1000)
|
||||||
{
|
{
|
||||||
var rows = await Context.Queryable<OrderEntity>()
|
return 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
|
||||||
@ -216,28 +162,20 @@ 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
|
.Select((a, b) => new OrderWithServiceProviderVO
|
||||||
{
|
{
|
||||||
CustomerOrderNo = a.OrderNo,
|
OrderNo = config.OrderNoType == TrackOrderNoType.客户单号 ? a.OrderNo :
|
||||||
a.TrackNo,
|
config.OrderNoType == TrackOrderNoType.跟踪单号 ? a.TrackNo :
|
||||||
a.ThirdPartyOrderNumber,
|
config.OrderNoType == TrackOrderNoType.其他单号 ? a.ThirdPartyOrderNumber : a.OrderNo,
|
||||||
a.OrderType,
|
TrackNo = a.TrackNo,
|
||||||
a.AppKey,
|
OtherNo = a.ThirdPartyOrderNumber,
|
||||||
|
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