102 lines
3.3 KiB
C#
102 lines
3.3 KiB
C#
using SJZY.Track.Application.Dtos.ProvideServices;
|
|
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
|
|
|
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/CreateOrUpdate")]
|
|
public async Task<string> CreateOrUpdateOrderAsync(CreateOrderInput 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<CreateOrderInput, OrderEntity>(input);
|
|
order.SubSystemId = 1;
|
|
order.OrderTemplates = ObjectMapper.Map<List<OrderTemplateInfo>, List<OrderTemplateEntity>>(input.Templates);
|
|
order.OrderFlights = ObjectMapper.Map<List<OrderFligthInfo>, 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.SoftDeleteAsync(x => x.Id == orderId);
|
|
|
|
return true;
|
|
}
|
|
|
|
#region 轨迹订单明细
|
|
/// <summary>
|
|
/// 根据轨迹订单id获取轨迹订单明细列表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/Order/GetDetails")]
|
|
public async Task<List<TrackOrderDetailDto>> GetOrderDetails(GetOrderDetailsInput input)
|
|
{
|
|
return null;
|
|
}
|
|
#endregion
|
|
|
|
#region 轨迹订单列表
|
|
/// <summary>
|
|
/// 获取分页的轨迹订单
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/Order/GetTrackOrderList")]
|
|
public async Task<UnifyPageResultDto<TrackOrderDto>> GetPageTrackOrder(GetPageTrackOrderInput input)
|
|
{
|
|
|
|
|
|
return null;
|
|
}
|
|
#endregion
|
|
|
|
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<OrderFligthInfo>, List<OrderFlightEntity>>(input.FlightInfos);
|
|
await _orderRepository.UpdateOrderAsync(order);
|
|
}
|
|
} |