Lading51TrackJob.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Newtonsoft.Json;
  2. using Quartz;
  3. using RestSharp;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using XYY.Tool.QuotaReduction;
  9. using XYY.Tool.TimingTask.Model;
  10. namespace XYY.Tool.TimingTask.jobs
  11. {
  12. public class Lading51TrackJob : IJob
  13. {
  14. public class Lading51TrackResult
  15. {
  16. public string LadingBillNumber { get; set; }
  17. public string errorMessage { get; set; }
  18. }
  19. public Task Execute(IJobExecutionContext context)
  20. {
  21. string msg = string.Empty;
  22. var client = new RestClient(JobConfig.Lading51TrackApi);
  23. client.Timeout = -1;
  24. var request = new RestRequest(Method.POST);
  25. request.AddHeader("Authorization", "token 57AEDE5487260443D6BF2182D31286B1");
  26. request.AddHeader("Content-Type", "application/json");
  27. List<string> bodys = new List<string>() { };
  28. request.AddJsonBody(bodys);
  29. IRestResponse response = client.Execute(request);
  30. if (response.StatusCode == System.Net.HttpStatusCode.OK)
  31. {
  32. var result = JsonConvert.DeserializeObject<ApiJsonModel>(response.Content);
  33. if (result.success == true)
  34. {
  35. var apiData = JsonConvert.DeserializeObject<List<Lading51TrackResult>>(result.data.ToString());
  36. if (apiData.Count > 0)
  37. {
  38. msg = "51提单轨迹任务失败数据:" + string.Join(";\r\n", apiData.Select(x => x.LadingBillNumber + ":" + x.errorMessage));
  39. }
  40. else
  41. {
  42. msg = "51提单轨迹任务执行成功";
  43. }
  44. }
  45. }
  46. else
  47. {
  48. msg += "51提单轨迹任务接口调用失败!" + response.ErrorMessage ?? response.Content;
  49. }
  50. if (msg.Contains("失败")) { dingApiRequest.sendDingMessageToChat("Lading51TrackApi", msg); }
  51. return null;
  52. }
  53. }
  54. }