SnapshotHandler.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. using DotNetCore.CAP;
  2. using Hotline.Authentications;
  3. using Hotline.Caching.Interfaces;
  4. using Hotline.Caching.Services;
  5. using Hotline.FlowEngine.Notifications;
  6. using Hotline.Orders;
  7. using Hotline.Repository.SqlSugar.Orders;
  8. using Hotline.Settings;
  9. using Hotline.Share.Dtos.FlowEngine;
  10. using Hotline.Share.Dtos.Order;
  11. using Hotline.Share.Dtos.Snapshot;
  12. using Hotline.Share.Enums.FlowEngine;
  13. using Hotline.Share.Mq;
  14. using Hotline.Share.Tools;
  15. using Hotline.Snapshot;
  16. using Hotline.Snapshot.Notifications;
  17. using MediatR;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. using Hotline.Application.OrderApp;
  24. using Hotline.FlowEngine.Workflows;
  25. using XF.Domain.Dependency;
  26. using XF.Domain.Exceptions;
  27. using Microsoft.Extensions.Logging;
  28. using Hotline.Orders.Notifications;
  29. using Hotline.Snapshot.IRepository;
  30. using Hotline.Snapshot.Contracts;
  31. using Hotline.FlowEngine.WorkflowModules;
  32. using XF.Domain.Entities;
  33. using Hotline.Share.Enums.Snapshot;
  34. using Hotline.Application.Snapshot.Contracts;
  35. namespace Hotline.Application.Snapshot.Notifications;
  36. public class SnapshotHandler : ICapSubscribe, IScopeDependency
  37. {
  38. private readonly ISnapshotApplication _snapshotApplication;
  39. private readonly ISnapshotBulletinApplication _snapshotBulletinApplication;
  40. public SnapshotHandler(ISnapshotApplication snapshotApplication, ISnapshotBulletinApplication snapshotBulletinApplication)
  41. {
  42. _snapshotApplication = snapshotApplication;
  43. _snapshotBulletinApplication = snapshotBulletinApplication;
  44. }
  45. /// <summary>
  46. /// 推送成功后发送的延迟消息;
  47. /// 延迟检查网格员是否回复了工单;
  48. /// <param name="message"></param>
  49. /// <param name="cancellationToken"></param>
  50. /// <returns></returns>
  51. [CapSubscribe(EventNames.GuiderSystemReplyDelay)]
  52. public async Task PostGuiderSystemDelayedNotificationHandler(PostGuiderSystemDelayed message, CancellationToken cancellationToken)
  53. {
  54. await _snapshotApplication.GuiderSystemReplyDelayAsync(message.OrderId, cancellationToken);
  55. }
  56. /// <summary>
  57. /// 通知公告审核通过
  58. /// </summary>
  59. /// <param name="bulletinId"></param>
  60. /// <param name="token"></param>
  61. /// <returns></returns>
  62. [CapSubscribe(EventNames.BulletinIsPass)]
  63. public async Task BulletinIsPassHandler(string bulletinId, CancellationToken token)
  64. {
  65. await _snapshotBulletinApplication.NotifyUserAsync(bulletinId, token);
  66. }
  67. }
  68. /// <summary>
  69. /// 工单归档后生成红包数据
  70. /// </summary>
  71. public class SnapshotOrderFiledNotificationHandler : INotificationHandler<SnapshotOrderFiledNotification>
  72. {
  73. private readonly ISnapshotApplication _snapshotApplication;
  74. private readonly IOrderSnapshotRepository _orderSnapshotRepository;
  75. private readonly ILogger<SnapshotOrderFiledNotificationHandler> _logger;
  76. public SnapshotOrderFiledNotificationHandler(ISnapshotApplication snapshotApplication, ILogger<SnapshotOrderFiledNotificationHandler> logger, IOrderSnapshotRepository orderSnapshotRepository)
  77. {
  78. _snapshotApplication = snapshotApplication;
  79. _logger = logger;
  80. _orderSnapshotRepository = orderSnapshotRepository;
  81. }
  82. public async Task Handle(SnapshotOrderFiledNotification notification, CancellationToken cancellationToken)
  83. {
  84. try
  85. {
  86. if (_orderSnapshotRepository.HasOrder(notification.OrderId))
  87. await _snapshotApplication.AddRedPardAsync(notification.OrderId, cancellationToken);
  88. }
  89. catch (Exception e)
  90. {
  91. _logger.LogError(e, "工单归档后生成红包数据失败");
  92. }
  93. }
  94. }
  95. /// <summary>
  96. /// 网格员办结事件处理
  97. /// 把网格员信息回填到系统中, 和小程序账号绑定
  98. /// 同步社区信息
  99. /// </summary>
  100. public class GuiderSystemFieldNotificationHandler : INotificationHandler<GuiderSystemFieldNotification>
  101. {
  102. private readonly ISnapshotApplication _snapshotApplication;
  103. private readonly IOrderApplication _orderApplication;
  104. private readonly ILogger<GuiderSystemFieldNotificationHandler> _logger;
  105. public GuiderSystemFieldNotificationHandler(
  106. ISnapshotApplication snapshotApplication1,
  107. IOrderApplication orderApplication,
  108. ILogger<GuiderSystemFieldNotificationHandler> logger)
  109. {
  110. _snapshotApplication = snapshotApplication1;
  111. _orderApplication = orderApplication;
  112. _logger = logger;
  113. }
  114. public async Task Handle(GuiderSystemFieldNotification notification, CancellationToken cancellationToken)
  115. {
  116. try
  117. {
  118. await _snapshotApplication.SyncGuiderInfoAsync(notification.OrderSnapshot.Id, cancellationToken);
  119. await _snapshotApplication.SyncCommunityInfoAsync(notification.CommunityInfo, cancellationToken);
  120. }
  121. catch (Exception e)
  122. {
  123. _logger.LogError(e, "网格员办结同步数据失败");
  124. }
  125. //流程流转至派单组
  126. await _orderApplication.HandleFromWanggeyuanToMaskAsync(notification.OrderSnapshot.Id, string.Empty, cancellationToken);
  127. }
  128. }
  129. /// <summary>
  130. /// 推送网格员系统
  131. /// </summary>
  132. public class SnapshotPushNotificationHandler : INotificationHandler<PostGuiderSystemNotification>
  133. {
  134. private readonly ISnapshotApplication _snapshotApplication;
  135. public SnapshotPushNotificationHandler(ISnapshotApplication snapshotApplication)
  136. {
  137. _snapshotApplication = snapshotApplication;
  138. }
  139. public async Task Handle(PostGuiderSystemNotification notification, CancellationToken cancellationToken)
  140. {
  141. await _snapshotApplication.PostOrderGuiderSystemAsync(notification.OrderId, cancellationToken);
  142. }
  143. }
  144. public class AddOrderSpecialHandler : INotificationHandler<AddOrderSpecialNotify>
  145. {
  146. private readonly IOrderSnapshotApplication _orderSnapshotApplication;
  147. private readonly ISystemSettingCacheManager _systemSettingCacheManager;
  148. public AddOrderSpecialHandler(IOrderSnapshotApplication orderSnapshotApplication, ISystemSettingCacheManager systemSettingCacheManager)
  149. {
  150. _orderSnapshotApplication = orderSnapshotApplication;
  151. _systemSettingCacheManager = systemSettingCacheManager;
  152. }
  153. public async Task Handle(AddOrderSpecialNotify notification, CancellationToken cancellationToken)
  154. {
  155. if (notification.SourceChannel.Contains("随手拍") && _systemSettingCacheManager.Snapshot == true)
  156. {
  157. var item = notification.Reasons.FirstOrDefault();
  158. if (item == null) return;
  159. await _orderSnapshotApplication.UpdateSpecialReasonAsync(notification.OrderId, item.ErrorId, item.ErrorName);
  160. }
  161. }
  162. }
  163. public class SnapshotStartWorkFlow : INotificationHandler<StartWorkflowNotify>
  164. {
  165. private readonly ISnapshotPointsDomainService _snapshotPointsDomainService;
  166. private readonly ISystemSettingCacheManager _sysSetting;
  167. public SnapshotStartWorkFlow(ISnapshotPointsDomainService snapshotPointsDomainService, ILogger<SnapshotStartWorkFlow> logger, ISystemSettingCacheManager sysSetting)
  168. {
  169. _snapshotPointsDomainService = snapshotPointsDomainService;
  170. _logger = logger;
  171. _sysSetting = sysSetting;
  172. }
  173. private readonly ILogger<SnapshotStartWorkFlow> _logger;
  174. /// <summary>
  175. /// 用户提交工单后,启动工作流, 给用户加积分
  176. /// </summary>
  177. /// <param name="notification"></param>
  178. /// <param name="cancellationToken"></param>
  179. /// <returns></returns>
  180. /// <exception cref="NotImplementedException"></exception>
  181. public async Task Handle(StartWorkflowNotify notification, CancellationToken cancellationToken)
  182. {
  183. try
  184. {
  185. if (_sysSetting.Snapshot == false || notification.Workflow.ModuleCode != WorkflowModuleConsts.OrderHandle) return;
  186. await _snapshotPointsDomainService.AddPointsAsync(notification.Workflow.ExternalId, EPointsSource.Report, ESnapshotSMSStatus.Agree, 0);
  187. }
  188. catch (Exception e)
  189. {
  190. _logger.LogError("增加用户上报积分失败", e);
  191. }
  192. }
  193. }