Преглед на файлове

fix: 接收工单退回结果 增加未开启流程判断

xf преди 11 месеца
родител
ревизия
49ed0183e0

+ 10 - 4
src/Hotline.Application/FlowEngine/IWorkflowApplication.cs

@@ -43,10 +43,16 @@ namespace Hotline.Application.FlowEngine
         Task RecallAsync(RecallDto dto, DateTime? expiredTime, CancellationToken cancellationToken);
 
         /// <summary>
-        /// 跳转至结束节点(无视流程模板配置直接跳至结束节点)
+        /// 办理至结束节点(无视流程模板配置,操作人需是当前节点办理对象)
         /// </summary>
-        Task HandleToEndAsync(ISessionContext current, string workflowId, string opinion, List<FileDto> file,
-            EReviewResult? reviewResult = EReviewResult.Unknown, CancellationToken cancellationToken = default);
+        Task HandleToEndAsync(ISessionContext current, string workflowId, string opinion, List<FileDto> files,
+            EReviewResult reviewResult = EReviewResult.Unknown, CancellationToken cancellationToken = default);
+
+        /// <summary>
+        /// 跳转至结束节点(无视流程模板配置以及当前办理对象)
+        /// </summary>
+        Task JumpToEndAsync(ISessionContext current, string workflowId, string opinion, List<FileDto> files,
+            EReviewResult reviewResult = EReviewResult.Unknown, CancellationToken cancellationToken = default);
 
         ////////
 
@@ -84,7 +90,7 @@ namespace Hotline.Application.FlowEngine
         Task<(WorkflowStep currentStep, WorkflowStep prevStep, bool isOrgToCenter, bool isSecondToFirstOrgLevel)>
             GetPreviousInformationAsync(string workflowId, string operatorId, string operatorOrgId,
                 CancellationToken cancellationToken);
-        
+
         /// <summary>
         /// 开启流程直接归档
         /// </summary>

+ 40 - 8
src/Hotline.Application/FlowEngine/WorkflowApplication.cs

@@ -320,7 +320,7 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
     /// 无视流程模板配置直接将当前节点办理至结束节点
     /// </summary>
     public async Task HandleToEndAsync(ISessionContext current, string workflowId, string opinion, List<FileDto> files,
-        EReviewResult? reviewResult = EReviewResult.Unknown, CancellationToken cancellationToken = default)
+        EReviewResult reviewResult = EReviewResult.Unknown, CancellationToken cancellationToken = default)
     {
         var workflow = await _workflowDomainService.GetWorkflowAsync(workflowId, withDefine: true, withSteps: true,
             cancellationToken: cancellationToken);
@@ -334,22 +334,54 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
             NextStepName = endStepDefine.Name,
             FlowDirection = EFlowDirection.OrgToFile,
             BusinessType = endStepDefine.BusinessType,
+            ReviewResult = reviewResult,
             Opinion = opinion,
             Files = files
         };
         await NextAsync(dto, current, cancellationToken: cancellationToken);
+    }
+
+    /// <summary>
+    /// 跳转至结束节点(无视流程模板配置以及当前办理对象,直接跳至结束节点)
+    /// </summary>
+    public async Task JumpToEndAsync(ISessionContext current, string workflowId, string opinion, List<FileDto> files,
+        EReviewResult reviewResult = EReviewResult.Unknown, CancellationToken cancellationToken = default)
+    {
+        var workflow = await _workflowDomainService.GetWorkflowAsync(workflowId, withDefine: true, withSteps: true,
+            cancellationToken: cancellationToken);
+        var endStepDefine = workflow.WorkflowDefinition.FindEndStepDefine();
+        if (endStepDefine is null)
+            throw new UserFriendlyException("未正确配置结束节点");
 
         //var currentStep = workflow.GetActualStep();
         //if (currentStep is null)
         //    throw new UserFriendlyException("未找到实际办理节点");
 
-        //await _workflowDomainService.EndAsync(workflow,
-        //    new BasicWorkflowDto
-        //    {
-        //        Opinion = opinion,
-        //        Files = files
-        //    },
-        //    endStepDefine, currentStep, reviewResult, isProvince, cancellationToken: cancellationToken);
+        var dto = new BasicWorkflowDto
+        {
+            NextStepCode = endStepDefine.Code,
+            NextStepName = endStepDefine.Name,
+            FlowDirection = EFlowDirection.OrgToFile,
+            BusinessType = endStepDefine.BusinessType,
+            ReviewResult = reviewResult,
+            Opinion = opinion,
+            Files = files
+        };
+
+        var unhandleSteps = workflow.Steps
+            .Where(d => d.Status != EWorkflowStepStatus.Handled).ToList();
+
+        //todo 结束会签
+
+        foreach (var unhandleStep in unhandleSteps)
+        {
+            await _workflowDomainService.HandleStepAsync(current, unhandleStep, workflow, dto, null,
+                null, null, cancellationToken);
+        }
+        await _workflowStepRepository.UpdateRangeAsync(unhandleSteps, cancellationToken);
+
+        await _workflowDomainService.EndAsync(workflow, dto,
+            endStepDefine, unhandleSteps.First(), current, cancellationToken);
     }
 
     /// <summary>

+ 33 - 13
src/Hotline.Application/Subscribers/DatasharingSubscriber.cs

@@ -113,10 +113,24 @@ namespace Hotline.Application.Subscribers
                 await _orderRepository.UpdateAsync(order, cancellationToken);
                 if (dto.Result is 1)
                 {
-                    if (!string.IsNullOrEmpty(order.WorkflowId))
+                    var current = SessionContextCreator.CreateSessionContext(dto.Source);
+                    if (string.IsNullOrEmpty(order.WorkflowId))
                     {
-                        var current = SessionContextCreator.CreateSessionContext(dto.Source);
-                        await _workflowApplication.HandleToEndAsync(current, order.WorkflowId, "省工单同意退回", null, EReviewResult.Approval, cancellationToken);
+                        var startDto = new StartWorkflowDto
+                        {
+                            DefinitionModuleCode = WorkflowModuleConsts.OrderHandle,
+                            Title = order.Title,
+                            Opinion = dto.Reason ?? "省工单同意退回",
+                        };
+                        await _workflowApplication.StartToEndAsync(startDto, current, order.Id, order.ExpiredTime,
+                            cancellationToken);
+                    }
+                    else
+                    {
+                        //await _workflowApplication.HandleToEndAsync(current, order.WorkflowId, "省工单同意退回", null,
+                        //    EReviewResult.Approval, cancellationToken);
+                        await _workflowApplication.JumpToEndAsync(current, order.WorkflowId, dto.Reason ?? "省工单同意退回",
+                            null, cancellationToken: cancellationToken);
                     }
                 }
             }
@@ -146,7 +160,9 @@ namespace Hotline.Application.Subscribers
             }
             else
             {
-                await _workflowApplication.HandleToEndAsync(current, order.WorkflowId, dto.Opinion, null,
+                //await _workflowApplication.HandleToEndAsync(current, order.WorkflowId, dto.Opinion, null,
+                //    cancellationToken: cancellationToken);
+                await _workflowApplication.JumpToEndAsync(current, order.WorkflowId, dto.Opinion, null,
                     cancellationToken: cancellationToken);
             }
         }
@@ -318,7 +334,8 @@ namespace Hotline.Application.Subscribers
                 Kv orgProcessingResults = null;
                 if (!string.IsNullOrEmpty(processingResult))
                 {
-                    var dicData = await _systemDicDataRepository.GetAsync(x => x.DicTypeCode == SysDicTypeConsts.VisitSatisfaction && x.DicDataValue == processingResult, cancellationToken);
+                    var dicData = await _systemDicDataRepository.GetAsync(x => x.DicTypeCode == SysDicTypeConsts.VisitSatisfaction &&
+                                                                               x.DicDataValue == processingResult, cancellationToken);
                     if (dicData != null)
                     {
                         orgProcessingResults = new Kv();
@@ -331,7 +348,7 @@ namespace Hotline.Application.Subscribers
                         orderVisit.VisitState = Share.Enums.Order.EVisitState.Visited;
                         orderVisit.VisitTime = dto.VisitTime;
                         orderVisit.VisitType = dto.VisitType;
-                        orderVisit.IsCanHandle = false;
+                        orderVisit.IsCanHandle = orgProcessingResults.Key == "2";
                         orderVisit.IsCanAiVisit = false;
                         orderVisit.NowEvaluate = orgProcessingResults;
                         await _orderVisitRepository.UpdateAsync(orderVisit, cancellationToken);
@@ -518,7 +535,10 @@ namespace Hotline.Application.Subscribers
                 var orderDelay = await _orderDelayRepository.GetAsync(x => x.OrderId == order.Id && x.DelayState == EDelayState.Examining, cancellationToken);
                 var current = SessionContextCreator.CreateSessionContext(dto.Source);
                 await _workflowApplication.HandleToEndAsync(current, orderDelay.WorkflowId, dto.Opinion, dto.Files,
-                    dto.IsPass ? Share.Enums.FlowEngine.EReviewResult.Approval : Share.Enums.FlowEngine.EReviewResult.Failed, cancellationToken);
+                    dto.IsPass ? EReviewResult.Approval : EReviewResult.Failed, cancellationToken);
+
+                //await _workflowApplication.JumpToEndAsync(current, orderDelay.WorkflowId, dto.Opinion, dto.Files,
+                //    dto.IsPass ? EReviewResult.Approval : EReviewResult.Failed, cancellationToken);
             }
         }
 
@@ -534,12 +554,12 @@ namespace Hotline.Application.Subscribers
             if (string.IsNullOrEmpty(order.WorkflowId))
                 throw new UserFriendlyException($"该工单未开启流程,orderId: {dto.OrderId}");
 
-            if (dto.Files != null && dto.Files.Any())
-            {
-                order.FileJson = await _fileRepository.AddFileAsync(dto.Files, order.Id, order.WorkflowId,
-                    cancellationToken);
-                await _orderRepository.FileAsync(order, cancellationToken);
-            }
+            //if (dto.Files != null && dto.Files.Any())
+            //{
+            //    order.FileJson = await _fileRepository.AddFileAsync(dto.Files, order.Id, order.WorkflowId,
+            //        cancellationToken);
+            //    await _orderRepository.FileAsync(order, cancellationToken);
+            //}
 
             var current = SessionContextCreator.CreateSessionContext(dto.Source);
             switch (dto.FinishType)

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

@@ -436,15 +436,15 @@ public partial class Workflow
     /// <summary>
     /// 流程结束
     /// </summary>
-    public void Complete(EReviewResult? reviewResult = EReviewResult.Unknown)
+    public void Complete(EReviewResult reviewResult = EReviewResult.Unknown)
     {
-        if (FlowType is EFlowType.Review && !reviewResult.HasValue)
-            throw new UserFriendlyException("无审核结果");
+        //if (FlowType is EFlowType.Review && !reviewResult.HasValue)
+        //    throw new UserFriendlyException("无审核结果");
 
         Status = EWorkflowStatus.Completed;
         EndTime = DateTime.Now;
         if (FlowType is EFlowType.Review && ReviewResult is EReviewResult.Unknown)
-            ReviewResult = reviewResult.Value;
+            ReviewResult = reviewResult;
 
         ClearHandlers();