123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- using Hotline.Share.Enums.FlowEngine;
- using SqlSugar;
- namespace Hotline.FlowEngine.Workflows;
- public class WorkflowStep : StepBasicEntity
- {
- [SugarColumn(ColumnDataType = "varchar(2000)", IsJson = true)]
- public List<NextStep> NextSteps { get; set; }
- /// <summary>
- /// 被指派办理对象(依据不同指派方式可能为:depCode或userId),该字段subStep才会存在,stepBox不存在
- /// 改为list,兼容多个办理对象可以办理同一个节点的场景
- /// </summary>
- [SugarColumn(ColumnDataType = "varchar(1000)", IsJson = true)]
- public List<string> HandlerIds { get; set; } = new();
- /// <summary>
- /// 前一级节点Id(stepBox此字段为上级stepBoxId,step为上级stepId),汇总节点无此字段(可能有多个上级来源)
- /// </summary>
- [SugarColumn(IsNullable = true)]
- public string? PreviousId { get; set; }
- /// <summary>
- /// 主办
- /// </summary>
- public bool IsMain { get; set; }
- public EWorkflowStepStatus Status { get; set; } = EWorkflowStepStatus.Assigned;
- /// <summary>
- /// stepBox此字段无效,记录stepBox与其下subSteps关系
- /// </summary>
- [SugarColumn(IsNullable = true)]
- public string? ParentId { get; set; }
- [SugarColumn(IsIgnore = true)]
- public List<WorkflowStep> Steps { get; set; } = new();
- #region 会签
- /// <summary>
- /// 发起会签生成会签Id(不发起会签节点无此字段)
- /// </summary>
- [SugarColumn(IsNullable = true)]
- public string? StartCountersignId { get; set; }
- /// <summary>
- /// 会签id
- /// </summary>
- [SugarColumn(IsNullable = true)]
- public string? CountersignId { get; set; }
- /// <summary>
- /// 当前节点发起的会签是否已结束,冗余(未发起会签的节点此字段为null)
- /// <remarks>
- /// 发起的会签结束以后更新,如果有子会签,则所有子会签都结束以后才会更新此字段
- /// </remarks>
- /// </summary>
- public bool? IsStartedCountersignComplete { get; set; }
- /// <summary>
- /// 节点会签状态
- /// </summary>
- public EStepCountersignStatus StepCountersignStatus { get; set; }
- /// <summary>
- /// 发起会签节点code,冗余(不支持发起会签节点无此字段)
- /// </summary>
- public string? CountersignStartCode { get; set; }
- /// <summary>
- /// 会签汇总节点code,冗余(不支持发起会签节点无此字段)
- /// </summary>
- public string? CountersignEndCode { get; set; }
- /// <summary>
- /// 是否处于会签流程中
- /// </summary>
- [SugarColumn(IsIgnore = true)]
- public bool IsInCountersign => !string.IsNullOrEmpty(CountersignId);
- /// <summary>
- /// 是否发起过会签
- /// </summary>
- [SugarColumn(IsIgnore = true)]
- public bool HasStartCountersign => !string.IsNullOrEmpty(StartCountersignId);
- #endregion
- #region Method
- /// <summary>
- /// 接办
- /// </summary>
- /// <param name="userId"></param>
- /// <param name="userName"></param>
- 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;
- }
- /// <summary>
- /// 节点办理完成
- /// </summary>
- /// <param name="userId"></param>
- /// <param name="userName"></param>
- /// <param name="orgCode"></param>
- /// <param name="orgName"></param>
- public void StepComplete(string userId, string userName, string orgCode, string orgName, string nextStepCode)
- {
- UserId = userId;
- UserName = userName;
- OrgCode = orgCode;
- OrgName = orgName;
- CompleteTime = DateTime.Now;
- Status = EWorkflowStepStatus.Completed;
- NextSteps.First(d => d.Code == nextStepCode).Selected = true;
- }
- /// <summary>
- /// 检查stepBox状态,如果子节点全都办理,则stepBox办理完成
- /// </summary>
- 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);
- }
- }
- /// <summary>
- /// 会签结束
- /// </summary>
- public void CountersignComplete() => IsStartedCountersignComplete = true;
- /// <summary>
- /// 开启会签
- /// </summary>
- public void StartCountersign(string startCountersignId)
- {
- StartCountersignId = startCountersignId;
- IsStartedCountersignComplete = false;
- }
- /// <summary>
- /// step设置为可接办状态
- /// </summary>
- public void SetAssigned() => Status = EWorkflowStepStatus.Assigned;
- /// <summary>
- /// 依据当前节点获取下一节点会签状态
- /// </summary>
- /// <returns></returns>
- public EStepCountersignStatus GetNextStepCountersignStatus()
- {
- if (HasStartCountersign)
- {
- return EStepCountersignStatus.InCountersign;
- }
- return IsInCountersign ? EStepCountersignStatus.OuterCountersign : EStepCountersignStatus.None;
- }
- #endregion
- }
|