SnapshotHandler.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using DotNetCore.CAP;
  2. using Hotline.Caching.Interfaces;
  3. using Hotline.Orders;
  4. using Hotline.Settings;
  5. using Hotline.Share.Dtos.Order;
  6. using Hotline.Share.Dtos.Snapshot;
  7. using Hotline.Share.Mq;
  8. using Hotline.Share.Tools;
  9. using Hotline.Snapshot;
  10. using Hotline.Snapshot.Interfaces;
  11. using Hotline.Snapshot.Notifications;
  12. using MediatR;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using XF.Domain.Dependency;
  19. namespace Hotline.Application.Snapshot.Notifications;
  20. public class SnapshotHandler : ICapSubscribe, IScopeDependency
  21. {
  22. private readonly ISnapshotApplication _snapshotApplication;
  23. public SnapshotHandler(ISnapshotApplication snapshotApplication)
  24. {
  25. _snapshotApplication = snapshotApplication;
  26. }
  27. /// <summary>
  28. /// 推送成功后发送的延迟消息;
  29. /// 延迟检查网格员是否回复了工单;
  30. /// <param name="message"></param>
  31. /// <param name="cancellationToken"></param>
  32. /// <returns></returns>
  33. [CapSubscribe(EventNames.GuiderSystemReplyDelay)]
  34. public async Task PostGuiderSystemDelayedNotificationHandler(PostGuiderSystemDelayed message, CancellationToken cancellationToken)
  35. {
  36. await _snapshotApplication.GuiderSystemReplyDelayAsync(message.OrderId, cancellationToken);
  37. }
  38. /// <summary>
  39. /// 工单归档后生成红包数据
  40. /// </summary>
  41. /// <param name="dto"></param>
  42. /// <param name="cancellationToken"></param>
  43. [CapSubscribe(EventNames.HotlineOrderFiled)]
  44. public async void SnapshotOrderEndAsync(OrderFlowDto dto, CancellationToken cancellationToken)
  45. {
  46. await _snapshotApplication.AddRedPardAsync(dto.Order.Id, cancellationToken);
  47. }
  48. }
  49. /// <summary>
  50. /// 网格员办结事件处理
  51. /// 把网格员信息回填到系统中, 和小程序账号绑定
  52. /// </summary>
  53. public class GuiderSystemFieldNotificationHandler : INotificationHandler<GuiderSystemFieldNotification>
  54. {
  55. private readonly ISnapshotApplication _snapshotApplication;
  56. public GuiderSystemFieldNotificationHandler(ISnapshotApplication snapshotApplication1)
  57. {
  58. _snapshotApplication = snapshotApplication1;
  59. }
  60. public async Task Handle(GuiderSystemFieldNotification notification, CancellationToken cancellationToken)
  61. {
  62. await _snapshotApplication.SyncGuiderInfoAsync(notification.OrderId, cancellationToken);
  63. await _snapshotApplication.SyncCommunityInfoAsync(notification.CommunityInfo, cancellationToken);
  64. }
  65. }
  66. /// <summary>
  67. /// 推送网格员系统
  68. /// </summary>
  69. public class SnapshotPushNotificationHandler : INotificationHandler<PostGuiderSystemNotification>
  70. {
  71. private readonly ISnapshotApplication _snapshotApplication;
  72. public SnapshotPushNotificationHandler(ISnapshotApplication snapshotApplication)
  73. {
  74. _snapshotApplication = snapshotApplication;
  75. }
  76. public async Task Handle(PostGuiderSystemNotification notification, CancellationToken cancellationToken)
  77. {
  78. await _snapshotApplication.PostOrderGuiderSystemAsync(notification.OrderId, cancellationToken);
  79. }
  80. }