SendRemindCaseInfoHandler.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using MapsterMapper;
  2. using MediatR;
  3. using Sharing.Notifications.XieTong;
  4. using Sharing.Province.Dtos.XieTong.Send;
  5. using Sharing.Province.XieTong.Receive;
  6. using XF.Domain.Repository;
  7. namespace Sharing.Province.Handlers.XieTong
  8. {
  9. /// <summary>
  10. /// 服务工单催单
  11. /// </summary>
  12. public class SendRemindCaseInfoHandler : INotificationHandler<SendRemindCaseInfoNotification>
  13. {
  14. private readonly IChannelConfigurationManager _channelConfigurationManager;
  15. private readonly PusherProvider _pusherProvider;
  16. private readonly IMapper _mapper;
  17. private readonly IRepository<RemindCaseInfo> _remindCaseInfoRepository;
  18. /// <summary>
  19. ///
  20. /// </summary>
  21. /// <param name="channelConfigurationManager"></param>
  22. /// <param name="pusherProvider"></param>
  23. /// <param name="mapper"></param>
  24. /// <param name="remindCaseInfoRepository"></param>
  25. public SendRemindCaseInfoHandler(IChannelConfigurationManager channelConfigurationManager, PusherProvider pusherProvider, IMapper mapper
  26. , IRepository<RemindCaseInfo> remindCaseInfoRepository)
  27. {
  28. _channelConfigurationManager = channelConfigurationManager;
  29. _pusherProvider = pusherProvider;
  30. _mapper = mapper;
  31. _remindCaseInfoRepository = remindCaseInfoRepository;
  32. }
  33. /// <summary>
  34. /// 服务工单催单
  35. /// </summary>
  36. /// <param name="notification"></param>
  37. /// <param name="cancellationToken"></param>
  38. /// <returns></returns>
  39. public async Task Handle(SendRemindCaseInfoNotification notification, CancellationToken cancellationToken = default)
  40. {
  41. var pusher = _pusherProvider.CreatePusher(_channelConfigurationManager);
  42. var dataReceive = _mapper.Map<RemindCaseInfoInfo>(notification.Data);
  43. var request = new SendRemindCaseInfoRequest();
  44. request.ForeachClass(dataReceive);
  45. request.SetData(dataReceive);
  46. var response = await pusher.PushSendRemindCaseInfoAsync(request, cancellationToken);
  47. //如果推送成功修改数据状态
  48. if (response != null)
  49. {
  50. if (response.Code == "1")
  51. notification.Data.SyncState = "1";
  52. else
  53. notification.Data.SyncState = "2";
  54. notification.Data.ReturnResult = Newtonsoft.Json.JsonConvert.SerializeObject(response);
  55. await _remindCaseInfoRepository.UpdateAsync(notification.Data);
  56. }
  57. }
  58. }
  59. }