using Hotline.Share.Dtos.FlowEngine; using Hotline.Share.Enums.FlowEngine; using SqlSugar; namespace Hotline.FlowEngine.Workflows; public class WorkflowStep : StepBasicEntity { [SugarColumn(ColumnDataType = "json", IsJson = true)] public List NextSteps { get; set; } /// /// 被指派办理对象(依据不同指派方式可能为:orgCode或userId),该字段subStep才会存在,stepBox不存在 /// 采用list类型,兼容多个办理对象可以办理同一个节点的场景 /// [SugarColumn(ColumnDataType = "json", IsJson = true)] public List Handlers { get; set; } = new(); /// /// 前一级节点Id(stepBox此字段为上级stepBoxId,step为上级stepId),汇总节点无此字段(因可能有多个上级来源) /// [SugarColumn(IsNullable = true)] public string? PreviousId { get; set; } /// /// 主办 /// public bool IsMain { get; set; } public EWorkflowStepStatus Status { get; set; } = EWorkflowStepStatus.Assigned; /// /// stepBox此字段无效,记录stepBox与其下subSteps关系 /// [SugarColumn(IsNullable = true)] public string? ParentId { get; set; } [SugarColumn(IsIgnore = true)] public List Steps { get; set; } = new(); #region 会签 /// /// 发起会签生成会签Id(不发起会签节点无此字段) /// [SugarColumn(IsNullable = true)] public string? StartCountersignId { get; set; } /// /// 会签id /// [SugarColumn(IsNullable = true)] public string? CountersignId { get; set; } /// /// 当前节点发起的会签是否已结束,冗余(未发起会签的节点此字段为null) /// /// 发起的会签结束以后更新,如果有子会签,则所有子会签都结束以后才会更新此字段 /// /// public bool? IsStartedCountersignComplete { get; set; } /// /// 节点会签状态 /// public EStepCountersignStatus StepCountersignStatus { get; set; } /// /// 发起会签节点code(冗余) /// [SugarColumn(IsNullable = true)] public string? CountersignStartStepCode { get; set; } /// /// 会签汇总节点code(冗余) /// [SugarColumn(IsNullable = true)] public string? CountersignEndStepCode { get; set; } /// /// 是否处于会签流程中 /// [SugarColumn(IsIgnore = true)] public bool IsInCountersign => !string.IsNullOrEmpty(CountersignId); /// /// 是否发起过会签 /// [SugarColumn(IsIgnore = true)] public bool HasStartedCountersign => !string.IsNullOrEmpty(StartCountersignId); #endregion #region Method /// /// 接办 /// /// /// public void Accept(string userId, string? userName, string orgCode, string? orgName) { AcceptUserId = userId; AcceptUserName = userName; AcceptTime = DateTime.Now; AcceptOrgCode = orgCode; AcceptOrgName = orgName; Status = EWorkflowStepStatus.Accepted; } /// /// 节点办理完成 /// /// /// /// /// public void Complete(string userId, string userName, string orgCode, string orgName, string nextStepCode) { UserId = userId; UserName = userName; OrgCode = orgCode; OrgName = orgName; CompleteTime = DateTime.Now; Status = EWorkflowStepStatus.Completed; if (StepType is not EStepType.End or EStepType.Start) NextSteps.First(d => d.Code == nextStepCode).Selected = true; } /// /// 检查stepBox状态,如果子节点全都办理,则stepBox办理完成 /// public void CheckStepBoxStatusAndUpdate() { if (Status is not EWorkflowStepStatus.Completed && Steps.All(d => d.Status is EWorkflowStepStatus.Completed)) { Status = EWorkflowStepStatus.Completed; CompleteTime = Steps.Max(d => d.CompleteTime); } } /// /// 会签结束 /// public void CountersignComplete() => IsStartedCountersignComplete = true; /// /// 开启会签 /// public void StartCountersign(string startCountersignId) { StartCountersignId = startCountersignId; IsStartedCountersignComplete = false; } /// /// step设置为可接办状态 /// public void SetAssigned() => Status = EWorkflowStepStatus.Assigned; /// /// 依据当前节点获取下一节点会签状态 /// /// public EStepCountersignStatus GetNextStepCountersignStatus() { if (HasStartedCountersign) { return EStepCountersignStatus.InCountersign; } return IsInCountersign ? EStepCountersignStatus.OuterCountersign : EStepCountersignStatus.None; } /// /// 重置节点,只清除办理痕迹(退回场景,将上一级节点重置等待重新办理) /// public void Reset() { SetAssigned(); NextHandlers = new(); NextMainHandler = null; NextStepCode = string.Empty; AcceptSms = default; Opinion = string.Empty; Additions = new(); UserId = null; UserName = null; OrgCode = null; OrgName = null; CompleteTime = null; AcceptUserId = null; AcceptUserName = null; AcceptOrgCode = null; AcceptOrgName = null; AcceptTime = null; } //过期:业务调整为由下级节点配置决定当前办理节点能否发起会签 ///// ///// 检查该节点是否应该发起会签(办理时确认是否应该作为发起会签节点处理) ///// ///// //public bool ShouldStartCountersign(int handlerCount) //{ // if (StepType is EStepType.End) return false; // //需求:按角色指派默认不发起会签 // if (HandlerType is EHandlerType.Role) return false; // return handlerCount > 1; //} #endregion }