83 lines
2.5 KiB
C#
83 lines
2.5 KiB
C#
using Newtonsoft.Json;
|
|
using SJZY.Track.Application.Dtos.ProvideServices;
|
|
using SJZY.Track.Domain;
|
|
using SJZY.Track.Domain.OrderAggregate;
|
|
using SJZY.UserCenter.HttpApi.Services;
|
|
|
|
namespace SJZY.Track.Application.Services.ProvideServices;
|
|
|
|
/// <summary>
|
|
/// 订单服务
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "提供接口")]
|
|
public class OrderService: ApplicationService
|
|
{
|
|
private readonly IOrderRepository _orderRepository;
|
|
|
|
public OrderService(IOrderRepository orderRepository)
|
|
{
|
|
_orderRepository = orderRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建订单
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="BusinessException"></exception>
|
|
[HttpPost("Order/Create")]
|
|
public async Task<bool> CreateOrderAsync(CreateOrderInput input)
|
|
{
|
|
if (await _orderRepository.IsAnyAsync(x =>
|
|
x.OrderType == input.NoInfo.NoType && x.OrderNo == input.NoInfo.OrderNo))
|
|
{
|
|
throw new BusinessException(message: $"单号:{input.NoInfo.OrderNo}已存在");
|
|
}
|
|
|
|
var order = new OrderEntity
|
|
{
|
|
CustomId = input.ClientId,
|
|
OrderDetails = JsonConvert.SerializeObject(input.Details),
|
|
OrderNo = input.NoInfo.OrderNo,
|
|
OrderType = input.NoInfo.NoType,
|
|
SubSystemId = CurrentUserRequest.SubSystemId
|
|
};
|
|
|
|
using var tran = TransactionHelper.GetReadCommitted();
|
|
|
|
// 创建订单
|
|
var orderId = await _orderRepository.InsertReturnIdentityAsync(order);
|
|
|
|
// 创建订单模板
|
|
var templates = input.Templates.Select(x => new OrderTemplateEntity
|
|
{
|
|
OrderId = orderId,
|
|
ServiceProviderId = x.ServiceProviderId,
|
|
TrackTemplateId = x.TemplateId
|
|
}).ToList();
|
|
await _orderRepository.CreateOrderTemplatesAsync(templates);
|
|
tran.Complete();
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关联订单
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Order/Link")]
|
|
public async Task<bool> LinkOrderAsync(LinkOrderInput input)
|
|
{
|
|
// var distinctOrderNos = input.LinkedOrderInfos.Distinct().ToList();
|
|
//
|
|
// var links = input.LinkedOrderInfos.Select(x => new OrderLinkEntity
|
|
// {
|
|
// LinkOrderId = x.,
|
|
// OrderId = 0
|
|
// })
|
|
// _orderRepository.LinkOrderAsync();
|
|
|
|
return true;
|
|
}
|
|
} |