MoreThanOneTicketGrpc.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using XYY.gRpc.Order;
  7. using XYY.Model.Standard.MpsOrder;
  8. using XYY.TaskTrack.Standard;
  9. using Microsoft.Extensions.Logging;
  10. namespace XYY.WindowsService.ReshMQ.Works
  11. {
  12. public interface IMoreThanOneTicketGrpc : IBaseConsumer<OrderMpsOrderSubModel>
  13. {
  14. }
  15. public class MoreThanOneTicketGrpc : IMoreThanOneTicketGrpc
  16. {
  17. OrderGrpcChannel orderGrpcChannel;
  18. public MoreThanOneTicketGrpc(OrderGrpcChannel orderGrpcChannel, ILogger<MoreThanOneTicketGrpc> logger)
  19. {
  20. this.orderGrpcChannel = orderGrpcChannel;
  21. _logger = logger;
  22. }
  23. private readonly ILogger<MoreThanOneTicketGrpc> _logger;
  24. public async Task Consume(OrderMpsOrderSubModel message)
  25. {
  26. try
  27. {
  28. var client = new MoreThanOneTicketOrders.MoreThanOneTicketOrdersClient(orderGrpcChannel.Channel);
  29. var or = new MTOROrderRequest
  30. {
  31. ChannelId = message.Order.ChannelId,
  32. ChannelName = message.Order.ChannelName,
  33. City = message.Order.ReceiverCity,
  34. CountryCode = message.Order.ReceiverCountry,
  35. CustomerId = message.Order.CustomerId,
  36. CustomerOrderNo = message.Order.CustomerOrderNumber,
  37. ZipCode = message.Order.ReceiverZipCode,
  38. DraftOrderId = message.Order.DraftOrderId,
  39. MpsOrderId = message.Order.Id,
  40. Name = message.Order.ReceiverName,
  41. Phone = message.Order.ReceiverPhone ?? string.Empty,
  42. State = message.Order.ReceiverState ?? string.Empty,
  43. Stree = message.Order.ReceiverStreet1,
  44. Weight = message.Order.Weight,
  45. ReceiverCompany=message.Order.ReceiverCompanyName ?? string.Empty,
  46. ReceiverEmail=message.Order.ReceiverEmail ?? string.Empty,
  47. };
  48. or.Boxs.AddRange(message.Order.Boxs.Select(x => new MTOROrderRequestBox
  49. {
  50. BoxId = x.Id,
  51. BoxNumber = x.BoxNumber,
  52. Height =Convert.ToDouble(x.Height),
  53. Length = Convert.ToDouble(x.Length),
  54. Weight = Convert.ToDouble(x.Weight),
  55. Width = Convert.ToDouble(x.Width)
  56. }));
  57. var result = await client.CreateAsync(or);
  58. _logger.LogInformation(result.LabelPath);
  59. }
  60. catch (Exception ex)
  61. {
  62. Console.WriteLine(ex.Message);
  63. _logger.LogError("草稿订单转换失败${message} {request}", ex.Message, message);
  64. }
  65. }
  66. }
  67. }