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