diff --git a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/LinkOrderInput.cs b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/LinkOrderInput.cs
index 583aab71..28b17b97 100644
--- a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/LinkOrderInput.cs
+++ b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/LinkOrderInput.cs
@@ -29,6 +29,13 @@ public class LinkOrderInput
[Required]
public string OrderNo { get; set; } = null!;
+ ///
+ /// 关联子系统id
+ ///
+ [Required]
+ [Range(1, int.MaxValue)]
+ public int LinkSubSystemId { get; set; }
+
///
/// 关联单类型
///
diff --git a/src/SJZY.Track.Application/Services/ProvideServices/OrderService.Link.cs b/src/SJZY.Track.Application/Services/ProvideServices/OrderService.Link.cs
index eb999633..52a2885f 100644
--- a/src/SJZY.Track.Application/Services/ProvideServices/OrderService.Link.cs
+++ b/src/SJZY.Track.Application/Services/ProvideServices/OrderService.Link.cs
@@ -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 _orderLinkQuery;
private readonly ITrackDetailsEsRepository _trackDetailsEsRepository;
///
@@ -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);
diff --git a/src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs b/src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs
index 3df4aa48..fd7f723e 100644
--- a/src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs
+++ b/src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs
@@ -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 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;
}
///
diff --git a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/IOrderRepository.cs b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/IOrderRepository.cs
index 5747b6eb..1f48970f 100644
--- a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/IOrderRepository.cs
+++ b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/IOrderRepository.cs
@@ -62,6 +62,27 @@ public interface IOrderRepository : IBasicRepository
///
Task> GetLinkedOrdersAsync(int[] orderId);
+ ///
+ /// 根据订单id,获取指定子系统下指定订单类型的关联订单集合
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> GetLinkedOrdersAsync(int orderId, int linkSubSystemId, int linkOrderType);
+
+
+ ///
+ /// 找已经存在的关联订单
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> GetLinkedOrdersAsync(int orderId, int linkSubSystemId, int linkOrderType,
+ List linkOrderNos);
+
///
/// 关联订单
///
diff --git a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderLinkEntity.cs b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderLinkEntity.cs
index 4527282a..65b43567 100644
--- a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderLinkEntity.cs
+++ b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderLinkEntity.cs
@@ -24,31 +24,6 @@ public class OrderLinkEntity : ICreateBaicEntity, ISoftDeleteBasicEntity, IEntit
[SugarColumn(ColumnName = "LinkOrderId")]
public int LinkOrderId { get; set; }
- ///
- /// 订单类型
- ///
- [SugarColumn(ColumnName = "OrderType")]
- public int OrderType { get; set; }
-
- ///
- /// 订单号
- ///
- [SugarColumn(ColumnName = "OrderNo")]
- public string OrderNo { get; set; } = null!;
-
-
- ///
- /// 关联的订单类型
- ///
- [SugarColumn(ColumnName = "LinkOrderType")]
- public int LinkOrderType { get; set; }
-
- ///
- /// 关联的订单号
- ///
- [SugarColumn(ColumnName = "LinkOrderNo")]
- public string LinkOrderNo { get; set; } = null!;
-
///
/// 创建人
///
diff --git a/src/SJZY.Track.Repository/Repositories/OrderRepository.cs b/src/SJZY.Track.Repository/Repositories/OrderRepository.cs
index 8a466f0a..f6b351f7 100644
--- a/src/SJZY.Track.Repository/Repositories/OrderRepository.cs
+++ b/src/SJZY.Track.Repository/Repositories/OrderRepository.cs
@@ -191,6 +191,26 @@ public class OrderRepository : BasicRepository, IOrderRepository, I
.ToListAsync();
}
+ public async Task> GetLinkedOrdersAsync(int orderId, int linkSubSystemId, int linkOrderType)
+ {
+ return await Context.Queryable()
+ .LeftJoin((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> GetLinkedOrdersAsync(int orderId, int linkSubSystemId, int linkOrderType,
+ List linkOrderNos)
+ {
+ return await Context.Queryable()
+ .LeftJoin((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 orderLinkEntities)
{
await Context.Insertable(orderLinkEntities).ExecuteCommandAsync();