xf 2 роки тому
батько
коміт
ae19fe5e24

+ 1 - 1
src/Hotline.Api/Controllers/KnowledgeController.cs

@@ -619,7 +619,7 @@ namespace Hotline.Api.Controllers
 
             dto.DefinitionCode = definition.Code;
             dto.Title = knowledge.Title;
-            var workflowId = await _workflowApplication.StartWorkflowAsync(dto, HttpContext.RequestAborted);
+            var workflowId = await _workflowApplication.StartWorkflowAsync(dto, id, HttpContext.RequestAborted);
 
             //知识审批主表
             await _knowledgeDomainService.AddWorkFlow(id, workflowId, eKnowledgeApplyType, HttpContext.RequestAborted);

+ 1 - 1
src/Hotline.Api/Controllers/OrderController.cs

@@ -210,7 +210,7 @@ public class OrderController : BaseController
             throw UserFriendlyException.SameMessage("未配置流程模板");
         dto.DefinitionCode = definition.Code;
         dto.Title = order.Title;
-        var workflowId = await _workflowApplication.StartWorkflowAsync(dto, HttpContext.RequestAborted);
+        var workflowId = await _workflowApplication.StartWorkflowAsync(dto, order.Id, HttpContext.RequestAborted);
         order.StartManageFlow(workflowId);
         await _orderRepository.UpdateAsync(order, HttpContext.RequestAborted);
     }

+ 1 - 1
src/Hotline.Api/Controllers/PbxController.cs

@@ -257,7 +257,7 @@ namespace Hotline.Api.Controllers
                     throw UserFriendlyException.SameMessage("未配置流程模板");
                 startWorkflowDto.DefinitionCode = definition.Code;
                 startWorkflowDto.Title = dto.Reason;
-                telRest.WorkflowId = await _workflowApplication.StartWorkflowAsync(startWorkflowDto, HttpContext.RequestAborted);
+                telRest.WorkflowId = await _workflowApplication.StartWorkflowAsync(startWorkflowDto, telRest.Id, HttpContext.RequestAborted);
             }
             await _telRestRepository.AddAsync(telRest, HttpContext.RequestAborted);
         }

+ 1 - 1
src/Hotline.Application/FlowEngine/IWorkflowApplication.cs

@@ -8,7 +8,7 @@ namespace Hotline.Application.FlowEngine
 {
     public interface IWorkflowApplication
     {
-        Task<string> StartWorkflowAsync(StartWorkflowDto dto, CancellationToken cancellationToken = default);
+        Task<string> StartWorkflowAsync(StartWorkflowDto dto, string? externalId = null, CancellationToken cancellationToken = default);
 
         /// <summary>
         /// 流转至下一节点(节点办理)

+ 2 - 2
src/Hotline.Application/FlowEngine/WorkflowApplication.cs

@@ -52,7 +52,7 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
         _sessionContext = sessionContext;
     }
 
-    public async Task<string> StartWorkflowAsync(StartWorkflowDto dto, CancellationToken cancellationToken = default)
+    public async Task<string> StartWorkflowAsync(StartWorkflowDto dto, string? externalId = null, CancellationToken cancellationToken = default)
     {
         if (string.IsNullOrEmpty(dto.DefinitionCode) && string.IsNullOrEmpty(dto.DefinitionModuleCode))
             throw new UserFriendlyException("非法参数");
@@ -66,7 +66,7 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
             throw new UserFriendlyException("该模板不可用");
 
         var nextStepBoxDefine = _workflowDomainService.GetStepBoxDefine(definition, dto.NextStepCode);
-        var workflow = await _workflowDomainService.CreateWorkflowAsync(definition, dto.Title, cancellationToken);
+        var workflow = await _workflowDomainService.CreateWorkflowAsync(definition, dto.Title, externalId, cancellationToken);
 
         var flowAssignMode = await GetFlowAssignModeAsync(nextStepBoxDefine,
             dto.NextHandlers.Select(d => d.Id).ToList(), cancellationToken);

+ 1 - 1
src/Hotline.Application/Handlers/FlowEngine/AcceptWorkflowHandler.cs

@@ -29,7 +29,7 @@ namespace Hotline.Application.Handlers.FlowEngine
             switch (workflow.ModuleCode)
             {
                 case WorkflowModuleConsts.OrderManage:
-                    await _orderDomainService.AcceptAsync(notification.Workflow.Id, cancellationToken);
+                    await _orderDomainService.AcceptAsync(notification.Workflow.ExternalId, cancellationToken);
                     break;
             }
         }

+ 1 - 1
src/Hotline.Application/Handlers/FlowEngine/EndWorkflowHandler.cs

@@ -42,7 +42,7 @@ public class EndWorkflowHandler : INotificationHandler<EndWorkflowNotify>
                 break;
 
             case WorkflowModuleConsts.OrderManage:
-                await _orderDomainService.ManageFlowEndAsync(workflow.Id, cancellationToken);
+                await _orderDomainService.ManageFlowEndAsync(workflow.ExternalId, cancellationToken);
                 break;
 
         }

+ 1 - 1
src/Hotline.Application/Handlers/FlowEngine/NextStepHandler.cs

@@ -42,7 +42,7 @@ public class NextStepHandler : INotificationHandler<NextStepNotify>
             case WorkflowModuleConsts.OrderManage:
                 await _orderDomainService.ManageFlowNextAsync(
                     notification.FlowAssignMode, notification.IsCountersignEnd, notification.IsCountersignStart,
-                    workflow.Id, workflow.CurrentStepTime, workflow.CurrentStepName, workflow.ExpiredTime,
+                    workflow.ExternalId, workflow.CurrentStepTime, workflow.CurrentStepName, workflow.ExpiredTime,
                     cancellationToken);
                 break;
         }

+ 1 - 1
src/Hotline.Application/Handlers/FlowEngine/OrderFinalManageHandler.cs

@@ -23,7 +23,7 @@ namespace Hotline.Application.Handlers.FlowEngine
         /// <param name="cancellationToken">Cancellation token</param>
         public async Task Handle(OrderFinalManageNotify notification, CancellationToken cancellationToken)
         {
-            await _orderDomainService.FinalManageAsync(notification.Workflow.Id, cancellationToken);
+            await _orderDomainService.FinalManageAsync(notification.Workflow.ExternalId, cancellationToken);
         }
     }
 }

+ 1 - 1
src/Hotline.Application/Handlers/FlowEngine/OrderRecallFinalManageHandler.cs

@@ -18,6 +18,6 @@ public class OrderRecallFinalManageHandler : INotificationHandler<OrderRecallFin
     /// <param name="cancellationToken">Cancellation token</param>
     public async Task Handle(OrderRecallFinalManageNotify notification, CancellationToken cancellationToken)
     {
-        await _orderDomainService.RecallFinalManageAsync(notification.Workflow.Id, cancellationToken);
+        await _orderDomainService.RecallFinalManageAsync(notification.Workflow.ExternalId, cancellationToken);
     }
 }

+ 1 - 1
src/Hotline.Application/Handlers/FlowEngine/StartWorkflowHandler.cs

@@ -34,7 +34,7 @@ namespace Hotline.Application.Handlers.FlowEngine
                 case WorkflowModuleConsts.OrderManage:
                     await _orderDomainService.ManageFlowNextAsync(notification.FlowAssignMode,
                         false, notification.IsCountersignStart,
-                        workflow.Id, workflow.CurrentStepTime, workflow.CurrentStepName, workflow.ExpiredTime, cancellationToken);
+                        workflow.ExternalId, workflow.CurrentStepTime, workflow.CurrentStepName, workflow.ExpiredTime, cancellationToken);
                     break;
             }
         }

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

@@ -7,7 +7,7 @@ namespace Hotline.FlowEngine.Workflows
 {
     public interface IWorkflowDomainService
     {
-        Task<Workflow> CreateWorkflowAsync(Definition definition, string title, CancellationToken cancellationToken);
+        Task<Workflow> CreateWorkflowAsync(Definition definition, string title, string? externalId = null, CancellationToken cancellationToken = default);
 
         /// <summary>
         /// 进行流程的开始节点

+ 5 - 4
src/Hotline/FlowEngine/Workflows/Workflow.cs

@@ -87,10 +87,11 @@ public class Workflow : CreationEntity
     [SugarColumn(ColumnDataType = "varchar(1000)", IsJson = true)]
     public List<string> HandlerOrgs { get; set; } = new();
 
-    ///// <summary>
-    ///// 外部业务唯一标识
-    ///// </summary>
-    //public string ExternalId { get; set; }
+    /// <summary>
+    /// 外部业务唯一标识
+    /// </summary>
+    [SugarColumn(IsNullable = true)]
+    public string? ExternalId { get; set; }
 
     [Navigate(NavigateType.OneToOne, nameof(DefinitionId))]
     public Definition Definition { get; set; }

+ 3 - 2
src/Hotline/FlowEngine/Workflows/WorkflowDomainService.cs

@@ -54,7 +54,7 @@ namespace Hotline.FlowEngine.Workflows
             _logger = logger;
         }
 
-        public async Task<Workflow> CreateWorkflowAsync(Definition definition, string title, CancellationToken cancellationToken)
+        public async Task<Workflow> CreateWorkflowAsync(Definition definition, string title, string externalId, CancellationToken cancellationToken)
         {
             var workflow = new Workflow
             {
@@ -70,6 +70,7 @@ namespace Hotline.FlowEngine.Workflows
                 Traces = new(),
                 Definition = definition,
                 AssignTime = DateTime.Now,
+                ExternalId = externalId,
             };
 
             await _workflowRepository.AddAsync(workflow, cancellationToken);
@@ -127,7 +128,7 @@ namespace Hotline.FlowEngine.Workflows
             await _workflowRepository.UpdateAsync(workflow, cancellationToken);
 
             //publish
-            _mediator.Publish(new StartWorkflowNotify(workflow, dto, isStartCountersign, flowAssignMode));
+            await _mediator.Publish(new StartWorkflowNotify(workflow, dto, isStartCountersign, flowAssignMode), cancellationToken);
         }
 
         public async Task<Workflow> GetWorkflowAsync(string workflowId,

+ 6 - 11
src/Hotline/Orders/IOrderDomainService.cs

@@ -16,21 +16,18 @@ namespace Hotline.Orders
         /// <summary>
         /// 归档
         /// </summary>
-        Task FileAsync(string workflowId, CancellationToken cancellationToken);
+        Task FileAsync(string? orderId, CancellationToken cancellationToken);
 
         /// <summary>
         /// 接办工单(查看详情视为接办)
         /// </summary>
-        /// <param name="workflowId"></param>
-        /// <param name="cancellationToken"></param>
-        /// <returns></returns>
-        Task AcceptAsync(string workflowId, CancellationToken cancellationToken);
+        Task AcceptAsync(string? orderId, CancellationToken cancellationToken);
 
         /// <summary>
         /// 工单办理流程流转(每个节点办理都会触发)
         /// </summary>
         Task ManageFlowNextAsync(FlowAssignMode assignMode, bool isCountersignEnd, bool isCountersignStart,
-            string workflowId, DateTime? currentStepTime, string? CurrentStepName, DateTime expiredTime, CancellationToken cancellationToken);
+            string? orderId, DateTime? currentStepTime, string? CurrentStepName, DateTime expiredTime, CancellationToken cancellationToken);
 
         /// <summary>
         /// 工单最终办理(此完结流程并未结束)
@@ -40,19 +37,17 @@ namespace Hotline.Orders
         /// 实际办理部门指:1.第一个汇总节点的前一个非汇总节点代表的办理部门 2.汇总以后如果再次开启会签需将工单回退到未办理完结的状态重新等待下一个汇总节点
         /// </remarks>
         /// <returns></returns>
-        Task FinalManageAsync(string workflowId, CancellationToken cancellationToken);
+        Task FinalManageAsync(string? orderId, CancellationToken cancellationToken);
 
         /// <summary>
         /// 撤回最终办理(汇总以后又重新指派到非汇总汇总节点办理的场景)
         /// </summary>
         /// <returns></returns>
-        Task RecallFinalManageAsync(string workflowId, CancellationToken cancellationToken);
+        Task RecallFinalManageAsync(string? orderId, CancellationToken cancellationToken);
 
         /// <summary>
         /// 工单办理流程流转到结束节点
         /// </summary>
-        /// <param name="workflowId"></param>
-        /// <returns></returns>
-        Task ManageFlowEndAsync(string workflowId, CancellationToken cancellationToken);
+        Task ManageFlowEndAsync(string? orderId, CancellationToken cancellationToken);
     }
 }

+ 27 - 23
src/Hotline/Orders/OrderDomainService.cs

@@ -46,11 +46,9 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
     /// <summary>
     /// 归档
     /// </summary>
-    public async Task FileAsync(string workflowId, CancellationToken cancellationToken)
+    public async Task FileAsync(string? orderId, CancellationToken cancellationToken)
     {
-        var order = await _orderRepository.GetAsync(d => d.WorkflowId == workflowId, cancellationToken);
-        if (order == null)
-            throw new UserFriendlyException($"无效工单流程编号, workflowId: {workflowId}", "无效工单编号");
+        var order = await GetOrderAsync(orderId, cancellationToken);
         if (order.Status is EOrderStatus.Filed) return;
         order.Status = EOrderStatus.Filed;
         await _orderRepository.UpdateAsync(order, cancellationToken);
@@ -59,12 +57,10 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
     /// <summary>
     /// 接办工单(查看详情视为接办)
     /// </summary>
-    /// <param name="workflowId"></param>
-    /// <param name="cancellationToken"></param>
-    /// <returns></returns>
-    public async Task AcceptAsync(string workflowId, CancellationToken cancellationToken)
+    public async Task AcceptAsync(string? orderId, CancellationToken cancellationToken)
     {
-        var order = await GetOrderAsync(workflowId, cancellationToken);
+        var order = await GetOrderAsync(orderId, cancellationToken);
+        CheckOrderIfFiled(order);
         order.Accept();
         await _orderRepository.UpdateAsync(order, cancellationToken);
     }
@@ -74,11 +70,12 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
     /// </summary>
     public async Task ManageFlowNextAsync(FlowAssignMode assignMode,
         bool isCountersignEnd, bool isCountersignStart,
-        string workflowId, DateTime? currentStepTime, string? CurrentStepName, DateTime expiredTime,
+        string? orderId, DateTime? currentStepTime, string? CurrentStepName, DateTime expiredTime,
         CancellationToken cancellationToken)
     {
         _logger.LogInformation($"{nameof(ManageFlowNextAsync)}");
-        var order = await GetOrderAsync(workflowId, cancellationToken);
+        var order = await GetOrderAsync(orderId, cancellationToken);
+        CheckOrderIfFiled(order);
 
         _logger.LogInformation($"{nameof(ManageFlowNextAsync)}, before: order.AssignUserIds: {string.Join(',', order.AssignUserIds)}, order.AssignOrgs: {string.Join(',', order.AssignOrgCodes)}");
         //更新指派信息
@@ -101,9 +98,10 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
     /// 实际办理部门指:1.第一个汇总节点的前一个非汇总节点代表的办理部门 2.汇总以后如果再次开启会签需将工单回退到未办理完结的状态重新等待下一个汇总节点
     /// </remarks>
     /// <returns></returns>
-    public async Task FinalManageAsync(string workflowId, CancellationToken cancellationToken)
+    public async Task FinalManageAsync(string? orderId, CancellationToken cancellationToken)
     {
-        var order = await GetOrderAsync(workflowId, cancellationToken);
+        var order = await GetOrderAsync(orderId, cancellationToken);
+        CheckOrderIfFiled(order);
         order.FinalManage();
         await _orderRepository.UpdateAsync(order, cancellationToken);
     }
@@ -112,9 +110,10 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
     /// 取消最终办理(汇总以后又重新指派到非汇总汇总节点办理的场景)
     /// </summary>
     /// <returns></returns>
-    public async Task RecallFinalManageAsync(string workflowId, CancellationToken cancellationToken)
+    public async Task RecallFinalManageAsync(string? orderId, CancellationToken cancellationToken)
     {
-        var order = await GetOrderAsync(workflowId, cancellationToken);
+        var order = await GetOrderAsync(orderId, cancellationToken);
+        CheckOrderIfFiled(order);
         order.RecallFinalManage();
         await _orderRepository.UpdateAsync(order, cancellationToken);
     }
@@ -122,25 +121,30 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
     /// <summary>
     /// 工单办理流程流转到结束节点
     /// </summary>
-    /// <param name="workflowId"></param>
-    /// <returns></returns>
-    public async Task ManageFlowEndAsync(string workflowId, CancellationToken cancellationToken)
+    public async Task ManageFlowEndAsync(string? orderId, CancellationToken cancellationToken)
     {
-        var order = await GetOrderAsync(workflowId, cancellationToken);
+        var order = await GetOrderAsync(orderId, cancellationToken);
+        CheckOrderIfFiled(order);
         order.Filed();
         await _orderRepository.UpdateAsync(order, cancellationToken);
     }
 
     #region private
 
-    private async Task<Order> GetOrderAsync(string workflowId, CancellationToken cancellationToken)
+    private async Task<Order> GetOrderAsync(string? orderId, CancellationToken cancellationToken)
     {
-        var order = await _orderRepository.GetAsync(d => d.WorkflowId == workflowId, cancellationToken);
+        if (string.IsNullOrEmpty(orderId))
+            throw UserFriendlyException.SameMessage("无效工单编号");
+        var order = await _orderRepository.GetAsync(orderId, cancellationToken);
         if (order == null)
-            throw new UserFriendlyException($"无效工单流程编号, workflowId: {workflowId}", "无效工单编号");
+            throw new UserFriendlyException($"无效工单编号, orderId: {orderId}", "无效工单编号");
+        return order;
+    }
+
+    private void CheckOrderIfFiled(Order order)
+    {
         if (order.Status is EOrderStatus.Filed)
             throw UserFriendlyException.SameMessage("工单已归档");
-        return order;
     }
 
     private string GenerateNewOrderNo()