add 关联订单接口
This commit is contained in:
parent
05637db671
commit
4c4cdd6326
@ -3,6 +3,7 @@
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<NoWarn>$(NoWarn);CS1591;CS0436;NU1803</NoWarn>
|
||||
<!-- <WarningsAsErrors>Nullable</WarningsAsErrors>-->
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
||||
@ -1,15 +1,31 @@
|
||||
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SJZY.Track.Application.Dtos.ProvideServices;
|
||||
|
||||
public class LinkOrderInput
|
||||
{
|
||||
/// <summary>
|
||||
/// false解绑,true关联,必填
|
||||
/// false解绑,true关联
|
||||
/// </summary>
|
||||
[Required]
|
||||
public bool IsLink { get; set; }
|
||||
|
||||
public NoInfo NoInfo { get; set; }
|
||||
/// <summary>
|
||||
/// 订单类型,必填
|
||||
/// </summary>
|
||||
[Required]
|
||||
public int OrderType { get; set; }
|
||||
|
||||
public List<NoInfo> LinkedOrderInfos { get; set; }
|
||||
/// <summary>
|
||||
/// 订单号,必填
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string OrderNo { get; set; }
|
||||
|
||||
[Required] public int LinkOrderType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关联的单号
|
||||
/// </summary>
|
||||
public List<string> LinkOrderNos { get; set; } = new();
|
||||
}
|
||||
@ -71,24 +71,58 @@ public class OrderService : ApplicationService
|
||||
[HttpPost("Order/Link")]
|
||||
public async Task<bool> LinkOrderAsync(LinkOrderInput input)
|
||||
{
|
||||
//todo:去重
|
||||
var distinctOrderInfos = input.LinkedOrderInfos.Distinct().ToList();
|
||||
|
||||
if (await _orderRepository.IsAnyAsync(x => x.IsEqual(input.NoInfo)))
|
||||
if (!await _orderRepository.IsAnyAsync(x => x.OrderType == input.OrderType && x.OrderNo == input.OrderNo))
|
||||
{
|
||||
throw new BusinessException(message: $"单号:{input.OrderNo}不存在");
|
||||
}
|
||||
|
||||
// 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();
|
||||
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<bool> 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<bool> 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;
|
||||
}
|
||||
|
||||
@ -17,4 +17,18 @@ public interface IOrderRepository : IBasicRepository<OrderEntity>
|
||||
/// <param name="templateEntities"></param>
|
||||
/// <returns></returns>
|
||||
Task CreateOrderTemplatesAsync(List<OrderTemplateEntity> templateEntities);
|
||||
|
||||
/// <summary>
|
||||
/// 关联订单
|
||||
/// </summary>
|
||||
/// <param name="orderLinkEntities"></param>
|
||||
/// <returns></returns>
|
||||
Task LinkOrderAsync(List<OrderLinkEntity> orderLinkEntities);
|
||||
|
||||
/// <summary>
|
||||
/// 解除订单关联关系
|
||||
/// </summary>
|
||||
/// <param name="linkIds"></param>
|
||||
/// <returns></returns>
|
||||
Task UnLinkByIdsAsync(List<int> linkIds);
|
||||
}
|
||||
@ -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}]";
|
||||
}
|
||||
}
|
||||
@ -18,4 +18,14 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
|
||||
{
|
||||
await Context.Insertable(templateEntities).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
public async Task LinkOrderAsync(List<OrderLinkEntity> orderLinkEntities)
|
||||
{
|
||||
await Context.Insertable(orderLinkEntities).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
public async Task UnLinkByIdsAsync(List<int> linkIds)
|
||||
{
|
||||
await Context.Deleteable(linkIds).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="../../common.props"/>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user