76 lines
2.7 KiB
C#
76 lines
2.7 KiB
C#
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
|
|
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
|
using SJZY.UserCenter.HttpApi.Services;
|
|
|
|
namespace SJZY.Track.Application.Services.ProvideServices;
|
|
|
|
/// <summary>
|
|
/// 订单服务
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "提供接口")]
|
|
[Route("/ProviderService")]
|
|
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/Upsert")]
|
|
public async Task<string> UpsertAsync(UpsertOrderInput input)
|
|
{
|
|
var order = await _orderRepository.GetFirstAsync(x =>
|
|
x.OrderType == input.OrderType && x.OrderNo == input.OrderNo);
|
|
if (order != default)
|
|
{
|
|
// 订单已存在则视为更新
|
|
await UpdateOrderAsync(input, order);
|
|
return "更新成功";
|
|
}
|
|
|
|
order = ObjectMapper.Map<UpsertOrderInput, OrderEntity>(input);
|
|
order.SubSystemId = CurrentUserRequest.SubSystemId;
|
|
order.OrderTemplates = ObjectMapper.Map<List<OrderTemplateInfo>, List<OrderTemplateEntity>>(input.Templates!);
|
|
order.OrderFlights = ObjectMapper.Map<List<OrderFlightInfo>, List<OrderFlightEntity>>(input.FlightInfos!);
|
|
|
|
await _orderRepository.CreateOrderAsync(order);
|
|
return "创建成功";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除订单
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="BusinessException"></exception>
|
|
[HttpPost("Order/Delete")]
|
|
public async Task<bool> DeleteOrderAsync(DeleteOrderInput input)
|
|
{
|
|
var orderId = await _orderRepository.GetFirstAsync(x =>
|
|
x.OrderType == input.OrderType && x.OrderNo == input.OrderNo, x => x.Id);
|
|
if (orderId == default)
|
|
{
|
|
throw new BusinessException(message: $"订单:{input.OrderNo}不存在");
|
|
}
|
|
|
|
await _orderRepository.DeleteOrderAsync(orderId);
|
|
|
|
return true;
|
|
}
|
|
|
|
private async Task UpdateOrderAsync(UpdateOrderInput input, OrderEntity order)
|
|
{
|
|
order = ObjectMapper.Map(input, order);
|
|
order.OrderTemplates = ObjectMapper.Map<List<OrderTemplateInfo>, List<OrderTemplateEntity>>(input.Templates!);
|
|
order.OrderFlights = ObjectMapper.Map<List<OrderFlightInfo>, List<OrderFlightEntity>>(input.FlightInfos!);
|
|
await _orderRepository.UpdateOrderAsync(order);
|
|
}
|
|
} |