xfe 1 tahun lalu
induk
melakukan
7d415e9a24

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

@@ -2222,18 +2222,6 @@ public class OrderController : BaseController
             HttpContext.RequestAborted);
     }
 
-    /// <summary>
-    /// 结束会签
-    /// </summary>
-    [HttpPost("cs-end")]
-    public async Task EndCountersign([FromBody] EndCountersignDto dto)
-    {
-        var order = await _orderDomainService.GetOrderAsync(dto.OrderId, cancellationToken: HttpContext.RequestAborted);
-        if (string.IsNullOrEmpty(order.WorkflowId))
-            throw new UserFriendlyException("该工单未开启流程");
-        await _workflowDomainService.EndCountersignAsync(order.WorkflowId, HttpContext.RequestAborted);
-    }
-
     /// <summary>
     /// 查询工单办理下一步可选节点(带推荐部门)
     /// </summary>

+ 1 - 0
src/Hotline.Share/Dtos/Org/OrgDto.cs

@@ -45,6 +45,7 @@ namespace Hotline.Share.Dtos.Org
         /// </summary>
         public string AreaName { get; set; }
 
+        public string OrgTypeText => OrgType.GetDescription();
     }
 
     public class UpdateOrgDto : AddOrgDto

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

@@ -135,12 +135,7 @@ namespace Hotline.FlowEngine.Workflows
         /// 创建开始节点
         /// </summary>
         WorkflowStep CreateStartStep(Workflow workflow, StepDefine startStepDefine, BasicWorkflowDto dto, List<Kv> handlers);
-
-        /// <summary>
-        /// 结束会签(会签未办理节点无需再办,由发起会签节点继续办理)
-        /// </summary>
-        Task EndCountersignAsync(string workflowId, CancellationToken cancellationToken);
-
+        
         /// <summary>
         /// 查询未完成节点
         /// </summary>

+ 4 - 0
src/Hotline/FlowEngine/Workflows/WorkflowCountersign.cs

@@ -131,6 +131,10 @@ namespace Hotline.FlowEngine.Workflows
         /// </summary>
         public bool? IsExpired { get; set; }
 
+
+        [SugarColumn(IsIgnore = true)]
+        public List<WorkflowCountersign> Children { get; set; }
+
         #region method
 
         /// <summary>

+ 61 - 45
src/Hotline/FlowEngine/Workflows/WorkflowDomainService.cs

@@ -837,39 +837,6 @@ namespace Hotline.FlowEngine.Workflows
             return startStep;
         }
 
-        /// <summary>
-        /// 结束会签
-        /// </summary>
-        public async Task EndCountersignAsync(string workflowId, CancellationToken cancellationToken)
-        {
-            var workflow = await GetWorkflowAsync(workflowId,
-                withSteps: true, withCountersigns: true, cancellationToken: cancellationToken);
-            var countersign = workflow.Countersigns.FirstOrDefault(d =>
-                    !d.IsCompleted() && d.StarterId == _sessionContext.RequiredUserId);
-            if (countersign is null) return;
-
-            //var countersignStartStep = workflow.Steps.FirstOrDefault(d => d.Id == countersign.StartStepId);
-            //if (countersignStartStep is null)
-            //    throw new UserFriendlyException($"未查询到会签对应开始节点, workflowId: {workflowId}, csId: {countersign.Id}");
-            ////结束step会签信息
-            //countersignStartStep.CountersignEnd();
-            ////todo
-            //updateSteps.Add(countersignStartStep);
-
-            ////结束会签
-            //countersign.End(currentStep.Id, currentStep.Code, currentStep.BusinessType,
-            //    _sessionContext.RequiredUserId, _sessionContext.UserName,
-            //    _sessionContext.RequiredOrgId, _sessionContext.OrgName,
-            //    _sessionContext.OrgAreaCode, _sessionContext.OrgAreaName);
-            //await _workflowCountersignRepository.UpdateAsync(currentCountersign, cancellationToken);
-
-
-            //todo thk: 以发起人/发起部门结束会签必须对应以发起人/发起部门开启会签限制
-            //todo 1.当前会签内未办节点处理为已办(默认办理意见xx结束会签)2.create new csEndStep(看做会签待办节点最后一个节点办理时)
-
-
-        }
-
         #region private method
 
         public async Task<WorkflowStep> CreateStartStepAsync(Workflow workflow, StepDefine startStepDefine,
@@ -1693,20 +1660,69 @@ namespace Hotline.FlowEngine.Workflows
             if (countersign is null)
                 throw new UserFriendlyException("无效会签编号");
 
-            //todo 1. 检查会签是否已结束 t: return 2.检查是否有嵌套会签 t: 一起结束 3.结束会签 4.trace 5.cp会签发起节点变为待办节点
+            //todo 1. 检查会签是否已结束 t: return 2.检查是否有嵌套会签 t: 一起结束 3.结束会签 4.trace 5.检查workflow会签状态,如果会签全结束需更新状态 6.cp会签发起节点变为待办节点
+            if (countersign.IsCompleted()) return;
 
-            /*
-             * //结束step会签信息
-                    countersignStartStep.CountersignEnd();
-                    updateSteps.Add(countersignStartStep);
+            countersign.Children = await _workflowCountersignRepository.Queryable()
+                .Where(d => d.WorkflowId == countersign.WorkflowId)
+                .ToTreeAsync(d => d.Children, d => d.ParentId, countersign.Id);
 
-                    //结束会签
-                    currentCountersign.End(currentStep.Id, currentStep.Code, currentStep.BusinessType,
-                        _sessionContext.RequiredUserId, _sessionContext.UserName,
-                        _sessionContext.RequiredOrgId, _sessionContext.OrgName,
-                        _sessionContext.OrgAreaCode, _sessionContext.OrgAreaName);
-                    await _workflowCountersignRepository.UpdateAsync(currentCountersign, cancellationToken);
-             */
+            var updateCountersigns = new List<WorkflowCountersign>();
+            EndCountersignWithCascade(countersign, ref updateCountersigns);
+
+            if (updateCountersigns.Any())
+            {
+                await _workflowCountersignRepository.UpdateRangeAsync(updateCountersigns, cancellationToken);
+
+                var workflow = await GetWorkflowAsync(countersign.WorkflowId, withCountersigns: true,
+                    cancellationToken: cancellationToken);
+
+                if (workflow.IsInCountersign && workflow.CheckIfCountersignOver())
+                    workflow.EndCountersign();
+                await _workflowRepository.UpdateAsync(workflow, cancellationToken);
+            }
+
+            //6.
+        }
+
+        /// <summary>
+        /// 结束会签(包含子项)
+        /// </summary>
+        /// <param name="countersign"></param>
+        /// <param name="updateCountersigns"></param>
+        private void EndCountersignWithCascade(WorkflowCountersign countersign, ref List<WorkflowCountersign> updateCountersigns)
+        {
+            if (countersign is null) return;
+            if (countersign.Children is not null && countersign.Children.Any())
+            {
+                foreach (var childCountersign in countersign.Children)
+                {
+                    EndCountersignWithCascade(childCountersign, ref updateCountersigns);
+                }
+            }
+            else
+            {
+                EndCountersign(countersign, ref updateCountersigns);
+            }
+        }
+
+        private void EndCountersign(WorkflowCountersign countersign, ref List<WorkflowCountersign> updateCountersigns)
+        {
+            //todo 1. trace? 先确定展现形式 2. end cs
+
+            /*
+            * //结束step会签信息
+                   countersignStartStep.CountersignEnd();
+                   updateSteps.Add(countersignStartStep);
+
+                   //结束会签
+                   currentCountersign.End(currentStep.Id, currentStep.Code, currentStep.BusinessType,
+                       _sessionContext.RequiredUserId, _sessionContext.UserName,
+                       _sessionContext.RequiredOrgId, _sessionContext.OrgName,
+                       _sessionContext.OrgAreaCode, _sessionContext.OrgAreaName);
+                   await _workflowCountersignRepository.UpdateAsync(currentCountersign, cancellationToken);
+            */
+            throw new NotImplementedException();
         }
 
         private WorkflowStep? GetStep(List<WorkflowStep> steps, string orgCode, string userId,

+ 2 - 12
src/Hotline/Settings/SystemOrganize.cs

@@ -3,7 +3,6 @@ using SqlSugar;
 using System.ComponentModel;
 using XF.Domain.Exceptions;
 using XF.Domain.Repository;
-using XF.Utility.EnumExtensions;
 
 namespace Hotline.Settings;
 
@@ -70,12 +69,11 @@ public class SystemOrganize : CreationSoftDeleteEntity
     /// </summary>
     public bool IsCenter { get; set; }
 
-    [SugarColumn(IsIgnore = true)] public List<SystemOrganize> Children { get; set; }
+    [SugarColumn(IsIgnore = true)] 
+    public List<SystemOrganize> Children { get; set; }
 
     public void InitOrgLevel() => Level = Id.CalcOrgLevel();
 
-    [SugarColumn(IsIgnore = true)]
-    public string OrgTypeText => OrgType.GetDescription();
 }
 
 public static class OrgExtensions
@@ -125,12 +123,4 @@ public static class OrgExtensions
             throw UserFriendlyException.SameMessage("无效部门编码");
         return orgId == OrgSeedData.CenterId;
     }
-
-    public static bool IsBelongCenter(this string orgId)
-    {
-        if (string.IsNullOrEmpty(orgId))
-            throw UserFriendlyException.SameMessage("无效部门编码");
-        var upperOrg = orgId.GetHigherOrgId();
-        return IsCenter(upperOrg);
-    }
 }