重构订单关联
This commit is contained in:
parent
8bc1c4917d
commit
b49678b77f
@ -29,6 +29,13 @@ public class LinkOrderInput
|
||||
[Required]
|
||||
public string OrderNo { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 关联子系统id
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Range(1, int.MaxValue)]
|
||||
public int LinkSubSystemId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关联单类型
|
||||
/// </summary>
|
||||
|
||||
@ -3,7 +3,6 @@ using SJZY.Track.Application.Contract.Dtos.ProvideServices;
|
||||
using SJZY.Track.Application.Contract.Events;
|
||||
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
||||
using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate;
|
||||
using SJZY.Track.Domain.Queries;
|
||||
|
||||
namespace SJZY.Track.Application.Services.ProvideServices;
|
||||
|
||||
@ -13,7 +12,6 @@ namespace SJZY.Track.Application.Services.ProvideServices;
|
||||
public partial class OrderService
|
||||
{
|
||||
private readonly ICapPublisher _capPublisher;
|
||||
private readonly IBasicQuery<OrderLinkEntity> _orderLinkQuery;
|
||||
private readonly ITrackDetailsEsRepository _trackDetailsEsRepository;
|
||||
|
||||
/// <summary>
|
||||
@ -49,7 +47,7 @@ public partial class OrderService
|
||||
if (!input.IsLink)
|
||||
{
|
||||
// 解绑
|
||||
await UnLinkOrderAsync(input);
|
||||
await UnLinkOrderAsync(input, orderId);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -63,9 +61,8 @@ public partial class OrderService
|
||||
private async Task DoLinkOrderAsync(LinkOrderInput input, int orderId)
|
||||
{
|
||||
// 获取已关联的订单
|
||||
var linkOrderNos = await _orderLinkQuery.GetListAsync(x =>
|
||||
x.OrderType == input.OrderType && x.OrderNo == input.OrderNo && x.LinkOrderType == input.LinkOrderType,
|
||||
x => x.LinkOrderNo);
|
||||
var linkOrderNos =
|
||||
await _orderRepository.GetLinkedOrdersAsync(orderId, input.LinkSubSystemId, input.LinkOrderType);
|
||||
|
||||
// 计算出未关联的订单
|
||||
var noLinkOrderNos = input.LinkOrderNos.Except(linkOrderNos).ToList();
|
||||
@ -92,11 +89,7 @@ public partial class OrderService
|
||||
await _orderRepository.LinkOrderAsync(existedOrders.Select(x => new OrderLinkEntity
|
||||
{
|
||||
OrderId = orderId,
|
||||
OrderNo = input.OrderNo,
|
||||
OrderType = input.OrderType,
|
||||
LinkOrderId = x.Id,
|
||||
LinkOrderNo = x.OrderNo,
|
||||
LinkOrderType = input.LinkOrderType
|
||||
}).ToList());
|
||||
|
||||
var tracks = await _trackDetailsEsRepository.GetListAsync(orderId);
|
||||
@ -135,12 +128,10 @@ public partial class OrderService
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UnLinkOrderAsync(LinkOrderInput input)
|
||||
private async Task UnLinkOrderAsync(LinkOrderInput input, int orderId)
|
||||
{
|
||||
var unLinkIds = await _orderLinkQuery.GetListAsync(x =>
|
||||
x.OrderType == input.OrderType && x.OrderNo == input.OrderNo &&
|
||||
x.LinkOrderType == input.LinkOrderType && input.LinkOrderNos.Contains(x.LinkOrderNo),
|
||||
x => x.Id);
|
||||
var unLinkIds = await _orderRepository.GetLinkedOrdersAsync(orderId, input.LinkSubSystemId, input.LinkOrderType,
|
||||
input.LinkOrderNos);
|
||||
|
||||
// real del
|
||||
await _orderRepository.UnLinkByIdsAsync(unLinkIds);
|
||||
|
||||
@ -4,7 +4,6 @@ using SJZY.Track.Application.Contract.Dtos.ProvideServices;
|
||||
using SJZY.Track.Application.Contract.Services.ProvideServices;
|
||||
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
||||
using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate;
|
||||
using SJZY.Track.Domain.Queries;
|
||||
using SJZY.UserCenter.HttpApi.Services;
|
||||
|
||||
namespace SJZY.Track.Application.Services.ProvideServices;
|
||||
@ -19,7 +18,7 @@ public partial class OrderService : ApplicationService, IOrderService
|
||||
private readonly IOrderOperationRecordEsRepository _orderOperationRecordEsRepository;
|
||||
private readonly IOrderRepository _orderRepository;
|
||||
|
||||
public OrderService(IOrderRepository orderRepository, IBasicQuery<OrderLinkEntity> orderLinkQuery,
|
||||
public OrderService(IOrderRepository orderRepository,
|
||||
ICapPublisher capPublisher, ITrackDetailsEsRepository trackDetailsEsRepository,
|
||||
IOrderOperationRecordEsRepository orderOperationRecordEsRepository)
|
||||
{
|
||||
@ -27,7 +26,6 @@ public partial class OrderService : ApplicationService, IOrderService
|
||||
_orderOperationRecordEsRepository = orderOperationRecordEsRepository;
|
||||
_trackDetailsEsRepository = trackDetailsEsRepository;
|
||||
_capPublisher = capPublisher;
|
||||
_orderLinkQuery = orderLinkQuery;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -62,6 +62,27 @@ public interface IOrderRepository : IBasicRepository<OrderEntity>
|
||||
/// <returns></returns>
|
||||
Task<List<LinkedOrderVO>> GetLinkedOrdersAsync(int[] orderId);
|
||||
|
||||
/// <summary>
|
||||
/// 根据订单id,获取指定子系统下指定订单类型的关联订单集合
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <param name="linkSubSystemId"></param>
|
||||
/// <param name="linkOrderType"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<string>> GetLinkedOrdersAsync(int orderId, int linkSubSystemId, int linkOrderType);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 找已经存在的关联订单
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <param name="linkSubSystemId"></param>
|
||||
/// <param name="linkOrderType"></param>
|
||||
/// <param name="linkOrderNos"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<int>> GetLinkedOrdersAsync(int orderId, int linkSubSystemId, int linkOrderType,
|
||||
List<string> linkOrderNos);
|
||||
|
||||
/// <summary>
|
||||
/// 关联订单
|
||||
/// </summary>
|
||||
|
||||
@ -24,31 +24,6 @@ public class OrderLinkEntity : ICreateBaicEntity, ISoftDeleteBasicEntity, IEntit
|
||||
[SugarColumn(ColumnName = "LinkOrderId")]
|
||||
public int LinkOrderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 订单类型
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "OrderType")]
|
||||
public int OrderType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 订单号
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "OrderNo")]
|
||||
public string OrderNo { get; set; } = null!;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 关联的订单类型
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "LinkOrderType")]
|
||||
public int LinkOrderType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关联的订单号
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "LinkOrderNo")]
|
||||
public string LinkOrderNo { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 创建人
|
||||
/// </summary>
|
||||
|
||||
@ -191,6 +191,26 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetLinkedOrdersAsync(int orderId, int linkSubSystemId, int linkOrderType)
|
||||
{
|
||||
return await Context.Queryable<OrderLinkEntity>()
|
||||
.LeftJoin<OrderEntity>((a, b) => a.LinkOrderId == b.Id)
|
||||
.Where((a, b) => orderId == a.OrderId && b.SubSystemId == linkSubSystemId && b.OrderType == linkOrderType)
|
||||
.Select((a, b) => b.OrderNo)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<int>> GetLinkedOrdersAsync(int orderId, int linkSubSystemId, int linkOrderType,
|
||||
List<string> linkOrderNos)
|
||||
{
|
||||
return await Context.Queryable<OrderLinkEntity>()
|
||||
.LeftJoin<OrderEntity>((a, b) => a.LinkOrderId == b.Id)
|
||||
.Where((a, b) => orderId == a.OrderId && b.SubSystemId == linkSubSystemId && b.OrderType == linkOrderType
|
||||
&& linkOrderNos.Contains(b.OrderNo))
|
||||
.Select((a, b) => b.Id)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task LinkOrderAsync(List<OrderLinkEntity> orderLinkEntities)
|
||||
{
|
||||
await Context.Insertable(orderLinkEntities).ExecuteCommandAsync();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user