瀏覽代碼

应急管理局业务拆分成消息

tangjiang 9 月之前
父節點
當前提交
76f63ee381

+ 12 - 93
src/Hotline.Api/Controllers/OrderController.cs

@@ -7,8 +7,9 @@ using Hotline.Application.Orders;
 using Hotline.Application.Quality;
 using Hotline.Caching.Interfaces;
 using Hotline.CallCenter.Configs;
-using Hotline.ContingencyManagement;
+using Hotline.ContingencyManagement.Notifies;
 using Hotline.Enterprise;
+using Hotline.EventBus;
 using Hotline.File;
 using Hotline.FlowEngine.Definitions;
 using Hotline.FlowEngine.WorkflowModules;
@@ -27,7 +28,6 @@ using Hotline.Settings;
 using Hotline.Settings.Hotspots;
 using Hotline.Settings.TimeLimits;
 using Hotline.Share.Dtos;
-using Hotline.Share.Dtos.ContingencyManagement;
 using Hotline.Share.Dtos.Enterprise;
 using Hotline.Share.Dtos.FlowEngine;
 using Hotline.Share.Dtos.FlowEngine.Workflow;
@@ -125,8 +125,7 @@ public class OrderController : BaseController
     private readonly ICallApplication _callApplication;
     private readonly IOptionsSnapshot<CallCenterConfiguration> _callcenterOptions;
     private readonly IOrderSendBackAuditApplication _orderSendBackAuditApplication;
-    private readonly IRepository<ContingencyManagementOrders> _contingencyManagementOrdersRepository;
-    private readonly IRepository<ContingencyManagementHotspot> _contingencyManagementHotspotRepository;
+    private readonly Publisher _publisher;
 
     public OrderController(
         IOrderDomainService orderDomainService,
@@ -185,8 +184,7 @@ public class OrderController : BaseController
         IOptionsSnapshot<CallCenterConfiguration> callcenterOptions,
         IRepository<OrderModifyingRecords> orderModifyingRecordsRepository,
         IOrderSendBackAuditApplication orderSendBackAuditApplication,
-        IRepository<ContingencyManagementOrders> contingencyManagementOrdersRepository,
-        IRepository<ContingencyManagementHotspot> contingencyManagementHotspotRepository
+        Publisher publisher
         )
     {
         _orderDomainService = orderDomainService;
@@ -245,8 +243,7 @@ public class OrderController : BaseController
         _callApplication = callApplication;
         _callcenterOptions = callcenterOptions;
         _orderSendBackAuditApplication = orderSendBackAuditApplication;
-        _contingencyManagementOrdersRepository = contingencyManagementOrdersRepository;
-        _contingencyManagementHotspotRepository = contingencyManagementHotspotRepository;
+        _publisher = publisher;
     }
     #endregion 
 
@@ -322,50 +319,12 @@ public class OrderController : BaseController
                     publishPublishOrder.Order = _mapper.Map<OrderDto>(order);
                     await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderPublishOrder, publishPublishOrder);
 
+                    //推应急管理局
+                    //是否开启
                     var isOpenContingencyManagement = _systemSettingCacheManager.GetSetting(SettingConstants.IsOpenContingencyManagement)?.SettingValue[0];
                     if (isOpenContingencyManagement == "true")
-                    {
-                        try
-                        {
-                            //应急管理局业务处理
-                            //是否是指定热点
-                            if (await _contingencyManagementHotspotRepository.AnyAsync(p => p.Id == order.HotspotId, HttpContext.RequestAborted))
-                            {
-                                var orderData = await _contingencyManagementOrdersRepository.GetAsync(p => p.Id == order.Id, HttpContext.RequestAborted);
-                                //不存在新增
-                                if (orderData == null)
-                                {
-                                    orderData = new ContingencyManagementOrders();
-                                    orderData = _mapper.Map<ContingencyManagementOrders>(order);
-                                    orderData.Id = order.Id;
-                                    orderData.ArrangementOpinion = order.ActualOpinion;
-                                    orderData.ArrangeTitle = order.Title;
-                                    orderData.ArrangeContent = order.Content;
-                                    orderData.PushState = "0";
-                                    await _contingencyManagementOrdersRepository.AddAsync(orderData, HttpContext.RequestAborted);
-                                }
-                                else
-                                {
-                                    //存在修改
-                                    _mapper.Map(order, orderData);
-                                    orderData.ArrangementOpinion = order.ActualOpinion;
-                                    orderData.ArrangeTitle = order.Title;
-                                    orderData.ArrangeContent = order.Content;
-                                    orderData.PushState = "0";
-                                    await _contingencyManagementOrdersRepository.UpdateAsync(orderData, HttpContext.RequestAborted);
-                                }
-                                //推送消息
-                                var pushaData = _mapper.Map<ContingencyManagementOrdersDto>(orderData);
-                                pushaData.Id = orderData.Id;
-                                //推送消息
-                                await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderContingencyManagement,
-                                 pushaData, Hotline.Share.Mq.EventNames.HotlineOrderContingencyManagementState);
-                            }
-                        }
-                        catch (Exception)
-                        {
-                        }
-                    }
+                        await _publisher.PublishAsync(new ContingencyManagementNotify(order), PublishStrategy.ParallelNoWait, HttpContext.RequestAborted);
+
                     var orderVisit = new OrderVisit();
                     orderVisit.No = order.No;
                     orderVisit.OrderId = order.Id;
@@ -500,51 +459,11 @@ public class OrderController : BaseController
         }
         await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderPublishOrder, publishPublishOrder);
 
+        //推应急管理局
+        //是否开启
         var isOpenContingencyManagement = _systemSettingCacheManager.GetSetting(SettingConstants.IsOpenContingencyManagement)?.SettingValue[0];
         if (isOpenContingencyManagement == "true")
-        {
-            try
-            {
-                //应急管理局业务处理
-                //是否是指定热点
-                if (await _contingencyManagementHotspotRepository.AnyAsync(p => p.Id == order.HotspotId, HttpContext.RequestAborted))
-                {
-                    var orderData = await _contingencyManagementOrdersRepository.GetAsync(p => p.Id == order.Id, HttpContext.RequestAborted);
-                    //不存在新增
-                    if (orderData == null)
-                    {
-                        orderData = new ContingencyManagementOrders();
-                        orderData = _mapper.Map<ContingencyManagementOrders>(order);
-                        orderData.Id = order.Id;
-                        orderData.ArrangementOpinion = dto.ArrangeOpinion;
-                        orderData.ArrangeTitle = dto.ArrangeTitle;
-                        orderData.ArrangeContent = dto.ArrangeContent;
-                        orderData.PushState = "0";
-                        await _contingencyManagementOrdersRepository.AddAsync(orderData, HttpContext.RequestAborted);
-                    }
-                    else
-                    {
-                        //存在修改
-                        _mapper.Map(order, orderData);
-                        orderData.ArrangementOpinion = dto.ArrangeOpinion;
-                        orderData.ArrangeTitle = dto.ArrangeTitle;
-                        orderData.ArrangeContent = dto.ArrangeContent;
-                        orderData.PushState = "0";
-                        await _contingencyManagementOrdersRepository.UpdateAsync(orderData, HttpContext.RequestAborted);
-                    }
-                    var pushaData = _mapper.Map<ContingencyManagementOrdersDto>(orderData);
-                    pushaData.Id = order.Id;
-                    pushaData.CreationTime = order.CreationTime;
-                    //推送消息
-                    await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderContingencyManagement,
-                     pushaData, Hotline.Share.Mq.EventNames.HotlineOrderContingencyManagementState, HttpContext.RequestAborted);
-
-                }
-            }
-            catch (Exception)
-            {
-            }
-        }
+            await _publisher.PublishAsync(new ContingencyManagementNotify(order), PublishStrategy.ParallelNoWait, HttpContext.RequestAborted);
 
         var orderVisit = new OrderVisit();
         orderVisit.No = order.No;

+ 77 - 0
src/Hotline.Application/ContingencyManagement/ContingencyManagementNotifyHandler.cs

@@ -0,0 +1,77 @@
+using DotNetCore.CAP;
+using Hotline.ContingencyManagement;
+using Hotline.ContingencyManagement.Notifies;
+using Hotline.EventBus;
+using Hotline.Share.Dtos.ContingencyManagement;
+using MapsterMapper;
+using MediatR;
+using XF.Domain.Repository;
+
+namespace Hotline.Application.ContingencyManagement
+{
+    [HandlerInject(AppScopes = EAppScope.YiBin)]
+    public class ContingencyManagementNotifyHandler : INotificationHandler<ContingencyManagementNotify>
+    {
+        private readonly IRepository<ContingencyManagementOrders> _contingencyManagementOrdersRepository;
+        private readonly IRepository<ContingencyManagementHotspot> _contingencyManagementHotspotRepository;
+        private readonly IMapper _mapper;
+        private readonly ICapPublisher _capPublisher;
+
+        public ContingencyManagementNotifyHandler(
+              IRepository<ContingencyManagementOrders> contingencyManagementOrdersRepository,
+              IRepository<ContingencyManagementHotspot> contingencyManagementHotspotRepository,
+              IMapper mapper,
+              ICapPublisher capPublisher)
+        {
+            _contingencyManagementOrdersRepository = contingencyManagementOrdersRepository;
+            _contingencyManagementHotspotRepository = contingencyManagementHotspotRepository;
+            _mapper = mapper;
+            _capPublisher = capPublisher;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="notification"></param>
+        /// <param name="cancellationToken"></param>
+        /// <returns></returns>
+        public async Task Handle(ContingencyManagementNotify notification, CancellationToken cancellationToken)
+        {
+            var order = notification.dto;
+            //应急管理局业务处理
+            //是否是指定热点
+            if (await _contingencyManagementHotspotRepository.AnyAsync(p => p.Id == order.HotspotId, cancellationToken))
+            {
+                var orderData = await _contingencyManagementOrdersRepository.GetAsync(p => p.Id == order.Id, cancellationToken);
+                //不存在新增
+                if (orderData == null)
+                {
+                    orderData = new ContingencyManagementOrders();
+                    orderData = _mapper.Map<ContingencyManagementOrders>(order);
+                    orderData.Id = order.Id;
+                    orderData.ArrangementOpinion = order.ActualOpinion;
+                    orderData.ArrangeTitle = order.Title;
+                    orderData.ArrangeContent = order.Content;
+                    orderData.PushState = "0";
+                    await _contingencyManagementOrdersRepository.AddAsync(orderData, cancellationToken);
+                }
+                else
+                {
+                    //存在修改
+                    _mapper.Map(order, orderData);
+                    orderData.ArrangementOpinion = order.ActualOpinion;
+                    orderData.ArrangeTitle = order.Title;
+                    orderData.ArrangeContent = order.Content;
+                    orderData.PushState = "0";
+                    await _contingencyManagementOrdersRepository.UpdateAsync(orderData, cancellationToken);
+                }
+                //推送消息
+                var pushaData = _mapper.Map<ContingencyManagementOrdersDto>(orderData);
+                pushaData.Id = orderData.Id;
+                //推送消息
+                await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderContingencyManagement,
+                 pushaData, Hotline.Share.Mq.EventNames.HotlineOrderContingencyManagementState);
+            }
+        }
+    }
+}

+ 6 - 0
src/Hotline/ContingencyManagement/Notifies/ContingencyManagementNotify.cs

@@ -0,0 +1,6 @@
+using MediatR;
+
+namespace Hotline.ContingencyManagement.Notifies
+{
+    public record ContingencyManagementNotify(Hotline.Orders.Order dto) : INotification;
+}