You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 line
3.6KB

  1. using GpsCardGatewayPosition.Model.Config;
  2. using Microsoft.Extensions.Logging;
  3. using Microsoft.Extensions.Options;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using TelpoDataService.Util.Clients;
  10. using TelpoDataService.Util.Entities.GpsCard;
  11. using TelpoDataService.Util;
  12. namespace GpsCardGatewayPosition.Service.Biz.Pay
  13. {
  14. public class PayLogic
  15. {
  16. private readonly ServiceConfig _configService;
  17. private readonly GpsCardAccessorClient<GpsPayLog> _payLogApiClient;
  18. private readonly ILogger<PayLogic> _logger;
  19. public PayLogic(IOptions<ServiceConfig> optConfigService, GpsCardAccessorClient<GpsPayLog> payLogApiClient,
  20. ILogger<PayLogic> logger)
  21. {
  22. _configService = optConfigService.Value;
  23. _payLogApiClient = payLogApiClient;
  24. _logger = logger;
  25. }
  26. public async Task<GpsPayLog> GetPayLogAsync(string messageId, string payId)
  27. {
  28. try
  29. {
  30. var alarm = await _payLogApiClient.GetByIdAsync(payId, new RequestHeader { RequestId = messageId }).ConfigureAwait(false);
  31. return alarm;
  32. }
  33. catch (Exception ex)
  34. {
  35. _logger.LogError($"根据{payId}获取指定支付信息失败, {ex.Message}, {ex.StackTrace}");
  36. return null;
  37. }
  38. }
  39. public async Task<bool> AddPayLogAsync(string messageId, GpsPayLog pay)
  40. {
  41. try
  42. {
  43. await _payLogApiClient.AddAsync(pay).ConfigureAwait(false);
  44. return true;
  45. }
  46. catch (Exception ex)
  47. {
  48. _logger.LogError($"新增支付信息发生异常:{ex.Message}, {ex.StackTrace}");
  49. }
  50. return false;
  51. }
  52. public async Task<bool> UpdatePayLogAsync(string messageId, GpsPayLog pay)
  53. {
  54. try
  55. {
  56. await _payLogApiClient.UpdateAsync(pay, new RequestHeader { RequestId = messageId }).ConfigureAwait(false);
  57. return true;
  58. }
  59. catch (Exception ex)
  60. {
  61. _logger.LogError($"更新支付信息发生异常:{ex.Message}, {ex.StackTrace}");
  62. }
  63. return false;
  64. }
  65. //public async Task UpdatePayLogAsync(string messageId, string PayId, decimal oLat, decimal oLng, decimal baiduLat, decimal baiduLng, decimal gLat, decimal gLng)
  66. //{
  67. // try
  68. // {
  69. // var pay = await _payLogApiClient.GetByIdAsync(PayId, new RequestHeader { RequestId = messageId }).ConfigureAwait(false);
  70. // if (pay != null)
  71. // {
  72. // pay.Olat = oLat;
  73. // pay.Olng = oLng;
  74. // pay.BaiduLat = baiduLat;
  75. // pay.BaiduLng = baiduLng;
  76. // pay.Glat = gLat;
  77. // pay.Glng = gLng;
  78. // _payLogApiClient.UpdateAsync(pay, new RequestHeader { RequestId = messageId });
  79. // }
  80. // }
  81. // catch (Exception ex)
  82. // {
  83. // _logger.LogError($"更新PayLog发生异常:{ex.Message}, {ex.StackTrace}");
  84. // }
  85. //}
  86. //public void SavePayLog(string messageId, GpsPayLog pay)
  87. //{
  88. // try
  89. // {
  90. // var url = _configService.TelpoDataUrl;
  91. // _payLogApiClient.AddAsync(pay, new RequestHeader { RequestId = messageId });
  92. // }
  93. // catch (Exception ex)
  94. // {
  95. // _logger.LogError($"保存PayLog发生异常:{ex.Message}, {ex.StackTrace}");
  96. // }
  97. //}
  98. }
  99. }