浏览代码

主协办

xfe 4 月之前
父节点
当前提交
7ca32081f7
共有 1 个文件被更改,包括 60 次插入38 次删除
  1. 60 38
      src/Hotline.Api/Controllers/OrderController.cs

+ 60 - 38
src/Hotline.Api/Controllers/OrderController.cs

@@ -770,11 +770,11 @@ public class OrderController : BaseController
     {
         //var query = _orderApplication.GetPublishedOrder(dto);
         //return (await query.ToFixedListAsync(dto.QueryIndex, 200, HttpContext.RequestAborted))
-            //.Adapt<List<PublishedDto>>();
-            var orderPublishs = await _orderApplication.GetPublishedOrder(dto)
-                .ToPageListWithoutTotalAsync(dto, HttpContext.RequestAborted);
+        //.Adapt<List<PublishedDto>>();
+        var orderPublishs = await _orderApplication.GetPublishedOrder(dto)
+            .ToPageListWithoutTotalAsync(dto, HttpContext.RequestAborted);
 
-            return _mapper.Map<IReadOnlyList<PublishedDto>>(orderPublishs);
+        return _mapper.Map<IReadOnlyList<PublishedDto>>(orderPublishs);
     }
 
     /// <summary>
@@ -4037,41 +4037,22 @@ public class OrderController : BaseController
                 nextDto.StepId = startStep.Id;
                 nextDto.HandlerType = EHandlerType.OrgLevel;
                 nextDto.FlowDirection = EFlowDirection.CenterToOrg;
-
-                if (orderHandleFlowDto?.SecondaryOrgs != null && orderHandleFlowDto.SecondaryOrgs.Any())
-                {
-                    var maxOrgLevel = orderHandleFlowDto.SecondaryOrgs.MaxBy(d => d.Level)!.Level;
-                    for (int i = 1; i < maxOrgLevel; i++)
-                    {
-                        var handleOrgs = orderHandleFlowDto.SecondaryOrgs.Where(d => d.Level == i).ToList();
-                        nextDto
-                    }
-
-                }
-
-                var levelOneOrgs = orderHandleFlowDto.SecondaryOrgs.Where(d => d.Level == 1).ToList();
-                if (levelOneOrgs.Any())
-                {
-                    //中心会签
-                    nextDto.IsStartCountersign = true;
-                    var handlers = levelOneOrgs.Select(d => new FlowStepHandler
+                var nextHandleOrgs = orderHandleFlowDto.SecondaryOrgs
+                    .Where(d => d.Level == 1 && d.Id.StartsWith(OrgSeedData.CenterId))
+                    .ToList();
+                if (nextHandleOrgs.Any())
+                    nextDto.NextHandlers.AddRange(nextHandleOrgs.Select(d => new FlowStepHandler
                     {
                         Key = d.Id,
                         Value = d.Name,
                         OrgId = d.Id,
-                        OrgName = d.Name,
-                    });
-                    nextDto.NextHandlers.AddRange(handlers);
-                }
-                else
-                {
-
-                }
-
-
-                await _workflowDomainService.NextAsync(_sessionContext, nextDto, order.ExpiredTime,
-                    isAutoFillSummaryOpinion, cancellationToken);
+                        OrgName = d.Name
+                    }));
+                nextDto.IsStartCountersign = nextDto.NextHandlers.Count > 1;
 
+                await HandleNextInMainAndSecondaryAsync(_sessionContext, workflow.WorkflowDefinition,
+                    orderHandleFlowDto.SecondaryOrgs, nextDto, order.ExpiredTime, isAutoFillSummaryOpinion,
+                    cancellationToken);
 
                 break;
             default:
@@ -4079,13 +4060,54 @@ public class OrderController : BaseController
         }
     }
 
-    private Task HandleNextMainAndSecondaryAsync(List<OrgDto> orgs, string currentOrgId, int currentOrgLevel,
-        CancellationToken cancellation)
+    private async Task HandleNextInMainAndSecondaryAsync(ISessionContext current, WorkflowDefinition definition, List<OrgDto> orgs,
+      NextWorkflowDto? flowDto, DateTime? expiredTime, bool isAutoFillSummaryOpinion, CancellationToken cancellation)
     {
-        var nextHandleOrgs = orgs.Where(d => d.Level == currentOrgLevel+1 && d.Id.StartsWith(currentOrgId)).ToList();
-        if(nextHandleOrgs.Any())
+        if (flowDto is null) return;
+        var nextSteps = await _workflowDomainService.NextAsync(current, flowDto, expiredTime,
+            isAutoFillSummaryOpinion, cancellation);
+
+        foreach (var nextStep in nextSteps)
         {
+            var nextStepHandlerOrgId = nextStep?.HandlerOrgId;
+            if (string.IsNullOrEmpty(nextStepHandlerOrgId))
+                throw new UserFriendlyException($"数据异常, 待办部门id为空, stepId: {nextStep.Id}");
+            var nextStepHandlerOrgLevel = nextStepHandlerOrgId.CalcOrgLevel();
+            var nextHandlers = orgs.Where(d => d.Level == nextStepHandlerOrgLevel && d.Id.StartsWith(nextStepHandlerOrgId))
+                .Select(d => new FlowStepHandler
+                {
+                    Key = d.Id,
+                    Value = d.Name,
+                    OrgId = d.Id,
+                    OrgName = d.Name
+                })
+                .ToList();
+            if (nextHandlers.Any())
+            {
+                var nextStepDefine = definition.FindStepDefines(nextStep.NextSteps.Select(d => d.Code))
+                    .FirstOrDefault(d =>
+                        d.HandlerType == EHandlerType.OrgLevel &&
+                        d.HandlerTypeItems.Any(x => x.Key == nextStepHandlerOrgLevel.ToString()));
+                if (nextStepDefine == null)
+                    throw new UserFriendlyException($"流程模板未配置该部门等级, defineId: {definition.Id}, level: {nextStepHandlerOrgLevel}");
+
+                var nextDto = new NextWorkflowDto
+                {
+                    WorkflowId = flowDto.WorkflowId,
+                    StepId = nextStep.Id,
+                    NextStepCode = nextStepDefine.Code,
+                    NextStepName = nextStepDefine.Name,
+                    FlowDirection = EFlowDirection.OrgToOrg,
+                    HandlerType = nextStepDefine.HandlerType,
+                    StepType = nextStepDefine.StepType,
+                    IsSms = false,
+                    NextHandlers = nextHandlers,
+                    IsStartCountersign = nextHandlers.Count > 1,
+                    BusinessType = nextStepDefine.BusinessType,
+                };
 
+                await HandleNextInMainAndSecondaryAsync(current, definition, orgs, nextDto, expiredTime, isAutoFillSummaryOpinion, cancellation);
+            }
         }
     }