MoreThanOneTicketGrpc.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. };
  47. or.Boxs.AddRange(message.Order.Boxs.Select(x => new MTOROrderRequestBox
  48. {
  49. BoxId = x.Id,
  50. BoxNumber = x.BoxNumber,
  51. Height =Convert.ToDouble(x.Height),
  52. Length = Convert.ToDouble(x.Length),
  53. Weight = Convert.ToDouble(x.Weight),
  54. Width = Convert.ToDouble(x.Width)
  55. }));
  56. var result = await client.CreateAsync(or);
  57. _logger.LogInformation(result.LabelPath);
  58. }
  59. catch (Exception ex)
  60. {
  61. Console.WriteLine(ex.Message);
  62. _logger.LogError("草稿订单转换失败${message} {request}", ex.Message, message);
  63. }
  64. }
  65. }
  66. }