128 lines
4.4 KiB
C#
128 lines
4.4 KiB
C#
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
|
|
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
|
using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate;
|
|
using SJZY.Track.Domain.Dtos.Order;
|
|
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;
|
|
private readonly ITrackDetailsRepository _trackDetailsRepository;
|
|
|
|
public OrderService(IOrderRepository orderRepository,
|
|
ITrackDetailsRepository trackDetailsRepository
|
|
)
|
|
{
|
|
_orderRepository = orderRepository;
|
|
_trackDetailsRepository = trackDetailsRepository;
|
|
}
|
|
|
|
/// <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;
|
|
}
|
|
|
|
#region 轨迹订单明细
|
|
|
|
/// <summary>
|
|
/// 根据轨迹订单id获取轨迹订单明细列表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/Order/GetDetails")]
|
|
public async Task<List<TrackOrderDetailDto>> GetOrderDetails(GetOrderDetailsInput input)
|
|
{
|
|
var trackDetails = await _trackDetailsRepository.GetListAsync(input.OrderId);
|
|
if (!trackDetails.IsNullOrEmpty())
|
|
{
|
|
var list = ObjectMapper.Map<List<TrackDetailsIndex>, List<TrackOrderDetailDto>>(trackDetails);
|
|
int id = 1;
|
|
list.ForEach(a =>
|
|
{
|
|
a.Id = id++;
|
|
});
|
|
return list;
|
|
}
|
|
|
|
return new List<TrackOrderDetailDto>();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 轨迹订单列表
|
|
|
|
/// <summary>
|
|
/// 获取分页的轨迹订单
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/Order/GetTrackOrderList")]
|
|
public async Task<UnifyPageResultDto<TrackOrderDto>> GetPageTrackOrder(GetPageTrackOrderInput input)
|
|
{
|
|
var vo = ObjectMapper.Map<GetPageTrackOrderInput, GetPageTrackOrderInputVO>(input);
|
|
var pageList = await _orderRepository.GetPageTrackOrder(vo);
|
|
var pageResultDto =
|
|
ObjectMapper.Map<UnifyPageResultDto<TrackOrderVO>, UnifyPageResultDto<TrackOrderDto>>(pageList);
|
|
return pageResultDto;
|
|
}
|
|
|
|
#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<OrderFlightInfo>, List<OrderFlightEntity>>(input.FlightInfos!);
|
|
await _orderRepository.UpdateOrderAsync(order);
|
|
}
|
|
} |