using Newtonsoft.Json; using SJZY.Track.Application.Dtos.ProvideServices; using SJZY.Track.Domain; using SJZY.Track.Domain.OrderAggregate; using SJZY.UserCenter.HttpApi.Services; namespace SJZY.Track.Application.Services.ProvideServices; /// /// 订单服务 /// [ApiExplorerSettings(GroupName = "提供接口")] public class OrderService: ApplicationService { private readonly IOrderRepository _orderRepository; public OrderService(IOrderRepository orderRepository) { _orderRepository = orderRepository; } /// /// 创建订单 /// /// /// /// [HttpPost("Order/Create")] public async Task CreateOrderAsync(CreateOrderInput input) { if (await _orderRepository.IsAnyAsync(x => x.OrderType == input.NoInfo.NoType && x.OrderNo == input.NoInfo.OrderNo)) { throw new BusinessException(message: $"单号:{input.NoInfo.OrderNo}已存在"); } var order = new OrderEntity { CustomId = input.ClientId, OrderDetails = JsonConvert.SerializeObject(input.Details), OrderNo = input.NoInfo.OrderNo, OrderType = input.NoInfo.NoType, SubSystemId = CurrentUserRequest.SubSystemId }; using var tran = TransactionHelper.GetReadCommitted(); // 创建订单 var orderId = await _orderRepository.InsertReturnIdentityAsync(order); // 创建订单模板 var templates = input.Templates.Select(x => new OrderTemplateEntity { OrderId = orderId, ServiceProviderId = x.ServiceProviderId, TrackTemplateId = x.TemplateId }).ToList(); await _orderRepository.CreateOrderTemplatesAsync(templates); tran.Complete(); return true; } /// /// 关联订单 /// /// /// [HttpPost("Order/Link")] public async Task LinkOrderAsync(LinkOrderInput input) { // var distinctOrderNos = input.LinkedOrderInfos.Distinct().ToList(); // // var links = input.LinkedOrderInfos.Select(x => new OrderLinkEntity // { // LinkOrderId = x., // OrderId = 0 // }) // _orderRepository.LinkOrderAsync(); return true; } }