using SJZY.Track.Application.Dtos.ProvideServices; using SJZY.Track.Domain.Aggregates.OrderAggregate; namespace SJZY.Track.Application.Services.ProvideServices; /// /// 订单服务 /// [ApiExplorerSettings(GroupName = "提供接口")] public class OrderService : ApplicationService { private readonly IOrderRepository _orderRepository; public OrderService(IOrderRepository orderRepository) { _orderRepository = orderRepository; } /// /// 创建订单,订单已存在则视为更新 /// /// /// /// [HttpPost("Order/CreateOrUpdate")] public async Task 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(input); order.SubSystemId = 1; order.OrderTemplates = ObjectMapper.Map, List>(input.Templates); order.OrderFlights = ObjectMapper.Map, List>(input.FlightInfos); await _orderRepository.CreateOrderAsync(order); return "创建成功"; } /// /// 删除订单 /// /// /// /// [HttpPost("Order/Delete")] public async Task 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 轨迹订单明细 /// /// 根据轨迹订单id获取轨迹订单明细列表 /// /// /// [HttpPost("/Order/GetDetails")] public async Task> GetOrderDetails(GetOrderDetailsInput input) { return null; } #endregion #region 轨迹订单列表 /// /// 获取分页的轨迹订单 /// /// /// [HttpPost("/Order/GetTrackOrderList")] public async Task> GetPageTrackOrder(GetPageTrackOrderInput input) { return null; } #endregion private async Task UpdateOrderAsync(UpdateOrderInput input, OrderEntity order) { order = ObjectMapper.Map(input, order); order.OrderTemplates = ObjectMapper.Map, List>(input.Templates); order.OrderFlights = ObjectMapper.Map, List>(input.FlightInfos); await _orderRepository.UpdateOrderAsync(order); } }