change 拆分订单关联服务
This commit is contained in:
parent
ee80cb1353
commit
14933065e4
@ -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<AbpAutoMapperOptions>(options =>
|
||||
{
|
||||
options.AddMaps<ApplicationModule>(true);
|
||||
});
|
||||
Configure<AbpAutoMapperOptions>(options => { options.AddMaps<ApplicationModule>(true); });
|
||||
|
||||
Configure<AbpAspNetCoreMvcOptions>(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<AbpHttpClientBuilderOptions>(options =>
|
||||
{
|
||||
|
||||
options.ProxyClientActions.Add(async (remoteName, serviceProvider, httpClient) =>
|
||||
{
|
||||
//如果设置Token,前端需要传入Token 否则引发异常
|
||||
@ -70,6 +65,5 @@ namespace SJZY.Track.Application
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
3
src/SJZY.Track.Application/GlobalUsings.cs
Normal file
3
src/SJZY.Track.Application/GlobalUsings.cs
Normal file
@ -0,0 +1,3 @@
|
||||
// Global using directives
|
||||
|
||||
global using SJZY.Track.Domain;
|
||||
@ -0,0 +1,84 @@
|
||||
using SJZY.Track.Application.Dtos.ProvideServices;
|
||||
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
||||
|
||||
namespace SJZY.Track.Application.Services.ProvideServices;
|
||||
|
||||
/// <summary>
|
||||
/// 订单关联服务
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "提供接口")]
|
||||
public class OrderLinkService
|
||||
{
|
||||
private readonly IOrderRepository _orderRepository;
|
||||
private readonly IBasicQuery<OrderLinkEntity> _orderLinkQuery;
|
||||
|
||||
public OrderLinkService(IBasicQuery<OrderLinkEntity> orderLinkQuery, IOrderRepository orderRepository)
|
||||
{
|
||||
_orderLinkQuery = orderLinkQuery;
|
||||
_orderRepository = orderRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关联订单
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Order/Link")]
|
||||
public async Task<bool> 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<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;
|
||||
}
|
||||
}
|
||||
@ -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<OrderLinkEntity> _orderLinkQuery;
|
||||
|
||||
public OrderService(IOrderRepository orderRepository, IBasicQuery<OrderLinkEntity> orderLinkQuery)
|
||||
public OrderService(IOrderRepository orderRepository)
|
||||
{
|
||||
_orderRepository = orderRepository;
|
||||
_orderLinkQuery = orderLinkQuery;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -62,68 +59,4 @@ public class OrderService : ApplicationService
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关联订单
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Order/Link")]
|
||||
public async Task<bool> 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<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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user