diff --git a/common.props b/common.props
index 6dfdd8fe..492bcb09 100644
--- a/common.props
+++ b/common.props
@@ -3,6 +3,7 @@
latest
enable
enable
+ $(NoWarn);CS1591;CS0436;NU1803
diff --git a/src/SJZY.Track.Application/ApplicationModule.cs b/src/SJZY.Track.Application/ApplicationModule.cs
index 899bceee..ba3bc813 100644
--- a/src/SJZY.Track.Application/ApplicationModule.cs
+++ b/src/SJZY.Track.Application/ApplicationModule.cs
@@ -1,6 +1,5 @@
using SJZY.Expand.ABP.Core.Localization;
using SJZY.Track.Application.Localization;
-using SJZY.Track.Domain;
using SJZY.UserCenter.Contracts;
using SJZY.UserCenter.SharedModel;
using Volo.Abp.AspNetCore.Mvc;
@@ -26,14 +25,11 @@ namespace SJZY.Track.Application
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
- Configure(options =>
- {
- options.AddMaps(true);
- });
+ Configure(options => { options.AddMaps(true); });
Configure(options =>
{
- options.ConventionalControllers.Create(typeof(ApplicationModule).Assembly);//创建动态api
+ options.ConventionalControllers.Create(typeof(ApplicationModule).Assembly); //创建动态api
});
//添加虚拟文件系统
@@ -60,7 +56,6 @@ namespace SJZY.Track.Application
var configuration = context.Services.GetConfiguration();
PreConfigure(options =>
{
-
options.ProxyClientActions.Add(async (remoteName, serviceProvider, httpClient) =>
{
//如果设置Token,前端需要传入Token 否则引发异常
@@ -70,6 +65,5 @@ namespace SJZY.Track.Application
});
});
}
-
}
-}
+}
\ No newline at end of file
diff --git a/src/SJZY.Track.Application/Dtos/ProvideServices/LinkOrderInput.cs b/src/SJZY.Track.Application/Dtos/ProvideServices/LinkOrderInput.cs
index 460c506d..ae3dfd9d 100644
--- a/src/SJZY.Track.Application/Dtos/ProvideServices/LinkOrderInput.cs
+++ b/src/SJZY.Track.Application/Dtos/ProvideServices/LinkOrderInput.cs
@@ -1,15 +1,31 @@
-using SJZY.Track.Domain.Aggregates.OrderAggregate;
+using System.ComponentModel.DataAnnotations;
namespace SJZY.Track.Application.Dtos.ProvideServices;
public class LinkOrderInput
{
///
- /// false解绑,true关联,必填
+ /// false解绑,true关联
///
+ [Required]
public bool IsLink { get; set; }
- public NoInfo NoInfo { get; set; }
+ ///
+ /// 订单类型,必填
+ ///
+ [Required]
+ public int OrderType { get; set; }
- public List LinkedOrderInfos { get; set; }
+ ///
+ /// 订单号,必填
+ ///
+ [Required]
+ public string OrderNo { get; set; }
+
+ [Required] public int LinkOrderType { get; set; }
+
+ ///
+ /// 关联的单号
+ ///
+ public List LinkOrderNos { get; set; } = new();
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Application/GlobalUsings.cs b/src/SJZY.Track.Application/GlobalUsings.cs
new file mode 100644
index 00000000..63eef9f8
--- /dev/null
+++ b/src/SJZY.Track.Application/GlobalUsings.cs
@@ -0,0 +1,3 @@
+// Global using directives
+
+global using SJZY.Track.Domain;
\ No newline at end of file
diff --git a/src/SJZY.Track.Application/Services/ProvideServices/OrderLinkService.cs b/src/SJZY.Track.Application/Services/ProvideServices/OrderLinkService.cs
new file mode 100644
index 00000000..f729f6b1
--- /dev/null
+++ b/src/SJZY.Track.Application/Services/ProvideServices/OrderLinkService.cs
@@ -0,0 +1,84 @@
+using SJZY.Track.Application.Dtos.ProvideServices;
+using SJZY.Track.Domain.Aggregates.OrderAggregate;
+
+namespace SJZY.Track.Application.Services.ProvideServices;
+
+///
+/// 订单关联服务
+///
+[ApiExplorerSettings(GroupName = "提供接口")]
+public class OrderLinkService
+{
+ private readonly IOrderRepository _orderRepository;
+ private readonly IBasicQuery _orderLinkQuery;
+
+ public OrderLinkService(IBasicQuery orderLinkQuery, IOrderRepository orderRepository)
+ {
+ _orderLinkQuery = orderLinkQuery;
+ _orderRepository = orderRepository;
+ }
+
+ ///
+ /// 关联订单
+ ///
+ ///
+ ///
+ [HttpPost("Order/Link")]
+ public async Task LinkOrderAsync(LinkOrderInput input)
+ {
+ if (!await _orderRepository.IsAnyAsync(x => x.OrderType == input.OrderType && x.OrderNo == input.OrderNo))
+ {
+ throw new BusinessException(message: $"单号:{input.OrderNo}不存在");
+ }
+
+ if (input.LinkOrderNos.Count < 1 || input.LinkOrderType == 0) return true;
+
+ // 单号去重
+ input.LinkOrderNos = input.LinkOrderNos.Distinct().ToList();
+
+ // 解绑
+ if (!input.IsLink) return await UnLinkOrderAsync(input);
+
+ // 关联订单
+ return await DoLinkOrderAsync(input);
+ }
+
+ private async Task DoLinkOrderAsync(LinkOrderInput input)
+ {
+ // 获取已关联的订单
+ var linkOrderNos = await _orderLinkQuery.GetListAsync(x =>
+ x.OrderType == input.OrderType && x.OrderNo == input.OrderNo && x.LinkOrderType == input.LinkOrderType,
+ x => x.LinkOrderNo);
+
+ // 计算出未关联的订单
+ var noLinkOrderNos = input.LinkOrderNos.Except(linkOrderNos);
+
+ // 过滤掉不存在的订单
+ var canLinkOrderNos = await _orderRepository.GetListAsync(x =>
+ x.OrderType == input.LinkOrderType && noLinkOrderNos.Contains(x.OrderNo),
+ x => x.OrderNo);
+
+ await _orderRepository.LinkOrderAsync(canLinkOrderNos.Select(x => new OrderLinkEntity
+ {
+ OrderNo = input.OrderNo,
+ OrderType = input.OrderType,
+ LinkOrderNo = x,
+ LinkOrderType = input.LinkOrderType
+ }).ToList());
+
+ return true;
+ }
+
+ private async Task UnLinkOrderAsync(LinkOrderInput input)
+ {
+ 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);
+
+ // real del
+ await _orderRepository.UnLinkByIdsAsync(unLinkIds);
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs b/src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs
index cb0f68ef..e40ed43e 100644
--- a/src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs
+++ b/src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs
@@ -1,6 +1,5 @@
using Newtonsoft.Json;
using SJZY.Track.Application.Dtos.ProvideServices;
-using SJZY.Track.Domain;
using SJZY.Track.Domain.Aggregates.OrderAggregate;
using SJZY.UserCenter.HttpApi.Services;
@@ -13,12 +12,10 @@ namespace SJZY.Track.Application.Services.ProvideServices;
public class OrderService : ApplicationService
{
private readonly IOrderRepository _orderRepository;
- private readonly IBasicQuery _orderLinkQuery;
- public OrderService(IOrderRepository orderRepository, IBasicQuery orderLinkQuery)
+ public OrderService(IOrderRepository orderRepository)
{
_orderRepository = orderRepository;
- _orderLinkQuery = orderLinkQuery;
}
///
@@ -62,34 +59,4 @@ public class OrderService : ApplicationService
return true;
}
-
- ///
- /// 关联订单
- ///
- ///
- ///
- [HttpPost("Order/Link")]
- public async Task LinkOrderAsync(LinkOrderInput input)
- {
- //todo:去重
- var distinctOrderInfos = input.LinkedOrderInfos.Distinct().ToList();
-
- if (await _orderRepository.IsAnyAsync(x => x.IsEqual(input.NoInfo)))
- {
- }
-
- // var links = input.LinkedOrderInfos.Select(x => new OrderLinkEntity
- // {
- // OrderNo = x.OrderNo,
- // OrderType = x.NoType
- // }).ToList();
- //
- // foreach (var link in links)
- // {
- // if (await _orderLinkQuery.IsAnyAsync(x => x.))
- // }
- // _orderRepository.LinkOrderAsync();
-
- return true;
- }
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/IOrderRepository.cs b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/IOrderRepository.cs
index fb130780..d187933a 100644
--- a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/IOrderRepository.cs
+++ b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/IOrderRepository.cs
@@ -17,4 +17,18 @@ public interface IOrderRepository : IBasicRepository
///
///
Task CreateOrderTemplatesAsync(List templateEntities);
+
+ ///
+ /// 关联订单
+ ///
+ ///
+ ///
+ Task LinkOrderAsync(List orderLinkEntities);
+
+ ///
+ /// 解除订单关联关系
+ ///
+ ///
+ ///
+ Task UnLinkByIdsAsync(List linkIds);
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderEntity.cs b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderEntity.cs
index 2faa141f..e474f40e 100644
--- a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderEntity.cs
+++ b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderEntity.cs
@@ -89,4 +89,15 @@ public struct NoInfo
[Required]
[MaxLength(100)]
public string OrderNo { get; set; }
+
+ public NoInfo(int noType, string orderNo)
+ {
+ NoType = noType;
+ OrderNo = orderNo;
+ }
+
+ public override string ToString()
+ {
+ return $"[订单类型: {NoType}, 订单号: {OrderNo}]";
+ }
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Repository/OrderRepository.cs b/src/SJZY.Track.Repository/OrderRepository.cs
index 77d83641..9b64b010 100644
--- a/src/SJZY.Track.Repository/OrderRepository.cs
+++ b/src/SJZY.Track.Repository/OrderRepository.cs
@@ -18,4 +18,14 @@ public class OrderRepository : BasicRepository, IOrderRepository, I
{
await Context.Insertable(templateEntities).ExecuteCommandAsync();
}
+
+ public async Task LinkOrderAsync(List orderLinkEntities)
+ {
+ await Context.Insertable(orderLinkEntities).ExecuteCommandAsync();
+ }
+
+ public async Task UnLinkByIdsAsync(List linkIds)
+ {
+ await Context.Deleteable(linkIds).ExecuteCommandAsync();
+ }
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Repository/SJZY.Track.Repository.csproj b/src/SJZY.Track.Repository/SJZY.Track.Repository.csproj
index e4341712..d75f4b08 100644
--- a/src/SJZY.Track.Repository/SJZY.Track.Repository.csproj
+++ b/src/SJZY.Track.Repository/SJZY.Track.Repository.csproj
@@ -1,9 +1,7 @@
-
+
net7.0
- enable
- enable
True