GenerateCustomerQuotationJob.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using XYY.Tool.QuotaReduction;
  11. using XYY.Tool.TimingTask.Model;
  12. namespace XYY.Tool.TimingTask.jobs
  13. {
  14. public class GenerateCustomerQuotationJob : IJob
  15. {
  16. public Task Execute(IJobExecutionContext context)
  17. {
  18. var result = GenerateQuotationRequest();
  19. if (!result.Item1)
  20. {
  21. dingApiRequest.sendDingMessageToChat("GenerateCustomerQuotationJob", "\r\n -->生成数据任务异常:" + result.Item2);
  22. }
  23. return null;
  24. }
  25. private Tuple<bool, string> GenerateQuotationRequest()
  26. {
  27. var client = new RestClient(JobConfig.GenerateQuotationApi);
  28. client.Timeout = -1;
  29. var request = new RestRequest(Method.GET);
  30. request.AddHeader("Authorization", "token 57AEDE5487260443D6BF2182D31286B1");
  31. IRestResponse response = client.Execute(request);
  32. if (response.StatusCode == System.Net.HttpStatusCode.OK)
  33. {
  34. var responseData = JsonConvert.DeserializeObject<ApiJsonModel>(response.Content);
  35. return JsonConvert.DeserializeObject<Tuple<bool, string>>(responseData.data.ToString());
  36. }
  37. else
  38. {
  39. return Tuple.Create<bool, string>(false, "生成客户报价数据接口:GenerateQuotation,请求异常");
  40. }
  41. }
  42. }
  43. public class GenerateCustomerFileJob : IJob
  44. {
  45. public Task Execute(IJobExecutionContext context)
  46. {
  47. var result = GenerateCustomerFileRequest();
  48. if (!result.Item1)
  49. {
  50. dingApiRequest.sendDingMessageToChat("GenerateCustomerFileJob", "\r\n -->生成报价文件任务异常:" + result.Item2);
  51. }
  52. return null;
  53. }
  54. private Tuple<bool, string> GenerateCustomerFileRequest()
  55. {
  56. var client = new RestClient(JobConfig.GenerateCustomerFileApi);
  57. client.Timeout = -1;
  58. var request = new RestRequest(Method.GET);
  59. request.AddHeader("Authorization", "token 57AEDE5487260443D6BF2182D31286B1");
  60. IRestResponse response = client.Execute(request);
  61. if (response.StatusCode == System.Net.HttpStatusCode.OK)
  62. {
  63. var responseData = JsonConvert.DeserializeObject<ApiJsonModel>(response.Content);
  64. return JsonConvert.DeserializeObject<Tuple<bool, string>>(responseData.data.ToString());
  65. }
  66. else
  67. {
  68. return Tuple.Create<bool, string>(false, "生成报价文件接口:GenerateCustomerFile,请求异常");
  69. }
  70. }
  71. }
  72. public class GenerateZipFileJob : IJob
  73. {
  74. public Task Execute(IJobExecutionContext context)
  75. {
  76. var result = GenerateZipFileRequest();
  77. if (!result.Item1)
  78. {
  79. dingApiRequest.sendDingMessageToChat("GenerateZipFileJob", "\r\n -->发送报价文件任务异常:" + result.Item2);
  80. }
  81. return null;
  82. }
  83. private Tuple<bool, string> GenerateZipFileRequest()
  84. {
  85. var client = new RestClient(JobConfig.GenerateZipFileApi);
  86. client.Timeout = -1;
  87. var request = new RestRequest(Method.GET);
  88. request.AddHeader("Authorization", "token 57AEDE5487260443D6BF2182D31286B1");
  89. IRestResponse response = client.Execute(request);
  90. if (response.StatusCode == System.Net.HttpStatusCode.OK)
  91. {
  92. var responseData = JsonConvert.DeserializeObject<ApiJsonModel>(response.Content);
  93. return JsonConvert.DeserializeObject<Tuple<bool, string>>(responseData.data.ToString());
  94. }
  95. else
  96. {
  97. return Tuple.Create<bool, string>(false, "生成客户报价数据接口:GenerateQuotation,请求异常");
  98. }
  99. }
  100. }
  101. }