Browse Source

fixed: jumphandler

xf 1 year ago
parent
commit
3aaa7e9ebe

+ 37 - 0
src/Hotline.Application/Handlers/FlowEngine/JumpHandler.cs

@@ -0,0 +1,37 @@
+using Hotline.FlowEngine.Notifications;
+using Hotline.Orders;
+using Hotline.Settings;
+using MediatR;
+using Microsoft.Extensions.Logging;
+
+namespace Hotline.Application.Handlers.FlowEngine;
+
+public class JumpHandler : INotificationHandler<JumpNotify>
+{
+    private readonly IOrderDomainService _orderDomainService;
+    private readonly ILogger<JumpHandler> _logger;
+
+    public JumpHandler(
+        IOrderDomainService orderDomainService,
+        ILogger<JumpHandler> logger)
+    {
+        _orderDomainService = orderDomainService;
+        _logger = logger;
+    }
+
+    /// <summary>Handles a notification</summary>
+    /// <param name="notification">The notification</param>
+    /// <param name="cancellationToken">Cancellation token</param>
+    public async Task Handle(JumpNotify notification, CancellationToken cancellationToken)
+    {
+        var workflow = notification.Workflow;
+        var data = notification.Dto;
+
+        switch (workflow.ModuleCode)
+        {
+            case WorkflowModuleConsts.OrderManage:
+                await _orderDomainService.ManageFlowJumpAsync(workflow.Id, notification.FlowAssignMode, cancellationToken);
+                break;
+        }
+    }
+}

+ 1 - 1
src/Hotline/FlowEngine/Notifications/WorkflowNotify.cs

@@ -21,7 +21,7 @@ public record PreviousNotify(Workflow Workflow, PreviousWorkflowDto Dto) : INoti
 
 public record RecallNotify(Workflow Workflow, NextWorkflowDto Dto) : INotification;
 
-public record JumpNotify(Workflow Workflow, NextWorkflowDto Dto) : INotification;
+public record JumpNotify(Workflow Workflow, NextWorkflowDto Dto, FlowAssignMode FlowAssignMode) : INotification;
 
 public record EndWorkflowNotify(Workflow Workflow) : INotification;
 

+ 1 - 1
src/Hotline/FlowEngine/Workflows/WorkflowDomainService.cs

@@ -563,7 +563,7 @@ namespace Hotline.FlowEngine.Workflows
                 flowAssignMode.FlowAssignType, flowAssignMode.HandlerObjects);
             await _workflowRepository.UpdateAsync(workflow, cancellationToken);
 
-            await _mediator.Publish(new JumpNotify(workflow, dto), cancellationToken);
+            await _mediator.Publish(new JumpNotify(workflow, dto, flowAssignMode), cancellationToken);
         }
 
         /// <summary>

+ 9 - 0
src/Hotline/Orders/IOrderDomainService.cs

@@ -55,5 +55,14 @@ namespace Hotline.Orders
         /// 工单办理流程流转到结束节点
         /// </summary>
         Task ManageFlowEndAsync(string? orderId, CancellationToken cancellationToken);
+
+        /// <summary>
+        /// 流程跳转
+        /// </summary>
+        /// <param name="workflowId"></param>
+        /// <param name="assignMode"></param>
+        /// <param name="cancellationToken"></param>
+        /// <returns></returns>
+        Task ManageFlowJumpAsync(string workflowId, FlowAssignMode assignMode, CancellationToken cancellationToken);
     }
 }

+ 6 - 0
src/Hotline/Orders/Order.cs

@@ -342,6 +342,12 @@ namespace Hotline.Orders
             FiledTime = DateTime.Now;
         }
 
+        public void Jump()
+        {
+            Status = EOrderStatus.WaitForSign;
+            CompleteTime = null;
+        }
+
         #endregion
     }
 }

+ 29 - 0
src/Hotline/Orders/OrderDomainService.cs

@@ -161,6 +161,25 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
         await _orderRepository.UpdateAsync(order, cancellationToken);
     }
 
+    /// <summary>
+    /// 流程跳转
+    /// </summary>
+    /// <param name="workflowId"></param>
+    /// <param name="assignMode"></param>
+    /// <param name="cancellationToken"></param>
+    /// <returns></returns>
+    public async Task ManageFlowJumpAsync(string workflowId, FlowAssignMode assignMode, CancellationToken cancellationToken)
+    {
+        var order = await GetOrderByFlowIdAsync(workflowId, cancellationToken);
+        CheckOrderIfFiled(order);
+
+        order.Assign(assignMode.FlowAssignType, assignMode.GetHandlers());
+
+        order.Jump();
+
+        await _orderRepository.UpdateAsync(order, cancellationToken);
+    }
+
     #region private
 
     private async Task<Order> GetOrderAsync(string? orderId, CancellationToken cancellationToken)
@@ -173,6 +192,16 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
         return order;
     }
 
+    private async Task<Order> GetOrderByFlowIdAsync(string workflowId, CancellationToken cancellationToken)
+    {
+        if (string.IsNullOrEmpty(workflowId))
+            throw UserFriendlyException.SameMessage("无效流程编号");
+        var order = await _orderRepository.GetAsync(d => d.WorkflowId == workflowId, cancellationToken);
+        if (order == null)
+            throw new UserFriendlyException($"无效流程编号, workflowId: {workflowId}", "无效流程编号");
+        return order;
+    }
+
     private void CheckOrderIfFiled(Order order)
     {
         if (order.Status is EOrderStatus.Filed)