NodeHelper.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using XYY.Data.Model.Standard.Tracking;
  6. using XYY.Core.Standard.Mvc;
  7. namespace XYY.Service.Standard.TrackingService
  8. {
  9. public static class NodeHelper
  10. {
  11. public static ApiJsonModel<PostTrackingRequest> Convert(PostTrackingRequest postTrackingRequest)
  12. {
  13. string url = "http://wms.xingyunyi.cn/api/TrackingMore/ConvertTracking";
  14. #if DEBUG
  15. url = "http://localhost:22707/api/TrackingMore/ConvertTracking";
  16. #endif
  17. string josnMessage = Newtonsoft.Json.JsonConvert.SerializeObject(postTrackingRequest);
  18. RestSharp.RestClient client = new RestSharp.RestClient(url);
  19. //5秒超时
  20. client.Timeout = 5000;
  21. RestSharp.RestRequest request = new RestSharp.RestRequest(method: RestSharp.Method.POST);
  22. var r = new
  23. {
  24. TrackingNumber = postTrackingRequest.TrackingNumber,
  25. List = postTrackingRequest.List.Select(x => new
  26. {
  27. StatusString = x.Event,
  28. TriggerTime = x.TragetTime,
  29. Location = x.Location
  30. })
  31. };
  32. request.AddJsonBody(r);
  33. var response = client.Execute(request);
  34. if (response.StatusCode == System.Net.HttpStatusCode.OK)
  35. {
  36. var d = Newtonsoft.Json.JsonConvert.DeserializeObject<PostTrackingRequest>(response.Content);
  37. return ApiJsonModel<PostTrackingRequest>.OK(d);
  38. }
  39. else
  40. {
  41. return ApiJsonModel<PostTrackingRequest>.Error((response.ErrorMessage ?? response.Content), null);
  42. }
  43. }
  44. public static int ConvertIntStatus(string status)
  45. {
  46. if (status == "delivered")
  47. {
  48. return 7;
  49. }
  50. else if (status == "pickup")
  51. {
  52. return 4;
  53. }
  54. else if (status == "exception")
  55. {
  56. return 6;
  57. }
  58. else if (status == "undelivered")
  59. {
  60. return 10;
  61. }
  62. else
  63. {
  64. return 4;
  65. }
  66. }
  67. }
  68. }