85 lines
3.3 KiB
C#
85 lines
3.3 KiB
C#
using DotNetCore.CAP;
|
|
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
|
|
using SJZY.Track.Application.Contract.Services;
|
|
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
|
using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate;
|
|
using SJZY.Track.Domain.Queries;
|
|
using SJZY.UserCenter.HttpApi.Services;
|
|
|
|
namespace SJZY.Track.Application.Services.ProvideServices;
|
|
|
|
/// <summary>
|
|
/// 订单服务
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "提供接口")]
|
|
[Route("/ProviderService")]
|
|
public partial class OrderService : ApplicationService, IOrderService
|
|
{
|
|
private readonly IOrderRepository _orderRepository;
|
|
|
|
public OrderService(IOrderRepository orderRepository, IBasicQuery<OrderLinkEntity> orderLinkQuery,
|
|
ICapPublisher capPublisher, ITrackDetailsRepository trackDetailsRepository)
|
|
{
|
|
_orderRepository = orderRepository;
|
|
_trackDetailsRepository = trackDetailsRepository;
|
|
_capPublisher = capPublisher;
|
|
_orderLinkQuery = orderLinkQuery;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增、更新订单(存在就更新)
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Order/Upsert")]
|
|
public async Task<UnifyResultDto> UpsertAsync(UpsertOrderInput input)
|
|
{
|
|
if (input.Templates.Count == 0) throw new BusinessException(message: "至少有一个模板");
|
|
var order = await _orderRepository.GetFirstAsync(x =>
|
|
x.OrderType == input.OrderType && x.OrderNo == input.OrderNo);
|
|
if (order != default)
|
|
{
|
|
// 订单已存在则视为更新
|
|
await UpdateOrderAsync(input, order);
|
|
|
|
return new UnifyResultDto() { Code = "200", Msg = "操作成功", Data = "创建成功" };
|
|
}
|
|
|
|
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 new UnifyResultDto() { Code = "200", Msg = "操作成功", Data = "新增成功" };
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除订单
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="BusinessException"></exception>
|
|
[HttpPost("Order/Delete")]
|
|
public async Task<UnifyResultDto> 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 new UnifyResultDto(true, 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);
|
|
}
|
|
} |