|
@@ -207,16 +207,20 @@ namespace Hotline.FlowEngine.Workflows
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 查询工作流包含当前用户办理权限(是否可办理)
|
|
|
+ /// 查询工作流包含当前用户结束会签权限(是否可结束)
|
|
|
/// </summary>
|
|
|
- public async Task<(Workflow, bool, bool)> GetWorkflowHandlePermissionAsync(
|
|
|
+ public async Task<(Workflow, bool)> GetWorkflowHandlePermissionAsync(
|
|
|
string workflowId, string userId, string orgCode, CancellationToken cancellationToken = default)
|
|
|
{
|
|
|
- var workflow = await GetWorkflowAsync(workflowId, withSteps: true, withSupplements: true,
|
|
|
- withCountersigns: true, cancellationToken: cancellationToken);
|
|
|
- var canHandle = workflow.CanHandle(userId, orgCode);
|
|
|
- var canEndCountersign = workflow.Countersigns.Any(d => !d.IsCompleted() && d.StarterId == userId);
|
|
|
- return (workflow, canHandle, canEndCountersign);
|
|
|
+ var workflow = await GetWorkflowAsync(workflowId, withSteps: true, withCountersigns: true,
|
|
|
+ cancellationToken: cancellationToken);
|
|
|
+ var upCompletedCountersign = workflow.Countersigns.FirstOrDefault(d=> !d.IsCompleted() && d.StarterId == userId);
|
|
|
+ if(upCompletedCountersign is null) return (workflow, false);
|
|
|
+
|
|
|
+ var existCountersignEndStep = workflow.Steps.Exists(d =>
|
|
|
+ d.IsCountersignEndStep && d.CountersignStartStepId == upCompletedCountersign.StartStepId);
|
|
|
+ var canEndCountersign = !existCountersignEndStep;
|
|
|
+ return (workflow, canEndCountersign);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -1665,39 +1669,44 @@ namespace Hotline.FlowEngine.Workflows
|
|
|
|
|
|
var workflow = await GetWorkflowAsync(countersign.WorkflowId, withSteps: true, withTraces: true,
|
|
|
withCountersigns: true, cancellationToken: cancellationToken);
|
|
|
+ if (!workflow.IsInCountersign)
|
|
|
+ throw new UserFriendlyException("该流程未处于会签中");
|
|
|
|
|
|
- var startStep = workflow.Steps.Find(d => d.StartCountersignId == countersignId);
|
|
|
- if (startStep is null)
|
|
|
+ var startCountersignStep = workflow.Steps.Find(d => d.StartCountersignId == countersignId);
|
|
|
+ if (startCountersignStep is null)
|
|
|
throw new UserFriendlyException("未查询到发起会签节点");
|
|
|
- if (startStep.IsStartedCountersignEnd)
|
|
|
+ if (startCountersignStep.IsStartedCountersignEnd)
|
|
|
throw new UserFriendlyException("该会签已汇总");
|
|
|
-
|
|
|
+
|
|
|
var updateCountersigns = new List<WorkflowCountersign>();
|
|
|
- EndCountersignWithCascade(countersign, workflow.Countersigns, ref updateCountersigns);
|
|
|
+ EndCountersignWithCascade(countersign, workflow.Countersigns, startCountersignStep.BusinessType, ref updateCountersigns);
|
|
|
|
|
|
if (updateCountersigns.Any())
|
|
|
{
|
|
|
var updateSteps = new List<WorkflowStep>();
|
|
|
var updateTraces = new List<WorkflowTrace>();
|
|
|
- HandleStepsWithCascade(startStep, workflow.Steps, workflow.Traces, ref updateSteps, ref updateTraces);
|
|
|
+ HandleStepsByTerminalCs(startCountersignStep, workflow.Steps, workflow.Traces, ref updateSteps, ref updateTraces);
|
|
|
if (updateSteps.Any())
|
|
|
- await _workflowStepRepository.UpdateRangeAsync(updateSteps, cancellationToken);
|
|
|
+ await _workflowStepRepository.RemoveRangeAsync(updateSteps, cancellationToken);
|
|
|
if (updateTraces.Any())
|
|
|
await _workflowTraceRepository.UpdateRangeAsync(updateTraces, cancellationToken);
|
|
|
|
|
|
- if (workflow.IsInCountersign && workflow.CheckIfCountersignOver())
|
|
|
+ if (workflow.CheckIfCountersignOver())
|
|
|
workflow.EndCountersign();
|
|
|
- await _workflowRepository.UpdateAsync(workflow, cancellationToken);
|
|
|
|
|
|
await _workflowCountersignRepository.UpdateRangeAsync(updateCountersigns, cancellationToken);
|
|
|
}
|
|
|
|
|
|
//cp会签发起节点变为待办节点
|
|
|
+ //todo 1. create terminal trace 2. 撤回至startStep
|
|
|
+ var newPrevStep = await CreatePrevStepAsync(workflow, startCountersignStep, cancellationToken);
|
|
|
+ await _workflowStepRepository.RemoveAsync(startCountersignStep, cancellationToken: cancellationToken);
|
|
|
|
|
|
|
|
|
+ await _workflowRepository.UpdateAsync(workflow, cancellationToken);
|
|
|
}
|
|
|
|
|
|
- private void HandleStepsWithCascade(WorkflowStep step, List<WorkflowStep> steps, List<WorkflowTrace> traces, ref List<WorkflowStep> updateSteps, ref List<WorkflowTrace> updateTraces)
|
|
|
+ private void HandleStepsByTerminalCs(WorkflowStep step, List<WorkflowStep> steps, List<WorkflowTrace> traces, ref List<WorkflowStep> updateSteps, ref List<WorkflowTrace> updateTraces)
|
|
|
{
|
|
|
if (step == null) return;
|
|
|
var nextSteps = steps.Where(d => d.PrevStepId == step.Id && d.Status != EWorkflowStepStatus.Handled).ToList();
|
|
@@ -1705,18 +1714,39 @@ namespace Hotline.FlowEngine.Workflows
|
|
|
{
|
|
|
foreach (var nextStep in nextSteps)
|
|
|
{
|
|
|
- HandleStepsWithCascade(nextStep, steps, traces, ref updateSteps, ref updateTraces);
|
|
|
+ HandleStepsByTerminalCs(nextStep, steps, traces, ref updateSteps, ref updateTraces);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- EndStep(step, ref updateSteps, ref updateTraces);
|
|
|
+ EndStepByTeminalCs(step, traces, ref updateSteps, ref updateTraces);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void EndStep(WorkflowStep step, ref List<WorkflowStep> updateSteps, ref List<WorkflowTrace> updateTraces)
|
|
|
+ private void EndStepByTeminalCs(WorkflowStep step, List<WorkflowTrace> traces, ref List<WorkflowStep> updateSteps, ref List<WorkflowTrace> updateTraces)
|
|
|
{
|
|
|
- //todo 1. traces 2. status 3. csStatus
|
|
|
+ var opinion = $"该会签未办理完成,由{_sessionContext.OrgName}的{_sessionContext.UserName}手动结束";
|
|
|
+ if (step.IsStartCountersign)
|
|
|
+ {
|
|
|
+ step.CountersignEnd();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (step.Status is not EWorkflowStepStatus.Handled)
|
|
|
+ {
|
|
|
+ step.Handle(_sessionContext.RequiredUserId, _sessionContext.UserName,
|
|
|
+ _sessionContext.RequiredOrgId, _sessionContext.OrgName,
|
|
|
+ _sessionContext.OrgAreaCode, _sessionContext.OrgAreaName,
|
|
|
+ _sessionContext.OrgIsCenter, null);
|
|
|
+ step.Opinion = opinion;
|
|
|
+ }
|
|
|
+ updateSteps.Add(step);
|
|
|
+
|
|
|
+ var trace = traces.FirstOrDefault(d => d.StepId == step.Id);
|
|
|
+ if (trace != null)
|
|
|
+ {
|
|
|
+ _mapper.Map(step, trace);
|
|
|
+ updateTraces.Add(trace);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -1724,7 +1754,8 @@ namespace Hotline.FlowEngine.Workflows
|
|
|
/// </summary>
|
|
|
/// <param name="countersign"></param>
|
|
|
/// <param name="updateCountersigns"></param>
|
|
|
- private void EndCountersignWithCascade(WorkflowCountersign countersign, List<WorkflowCountersign> countersigns, ref List<WorkflowCountersign> updateCountersigns)
|
|
|
+ private void EndCountersignWithCascade(WorkflowCountersign countersign, List<WorkflowCountersign> countersigns,
|
|
|
+ EBusinessType businessType, ref List<WorkflowCountersign> updateCountersigns)
|
|
|
{
|
|
|
if (countersign is null) return;
|
|
|
|
|
@@ -1733,19 +1764,25 @@ namespace Hotline.FlowEngine.Workflows
|
|
|
{
|
|
|
foreach (var childCountersign in childCountersigns)
|
|
|
{
|
|
|
- EndCountersignWithCascade(childCountersign, countersigns, ref updateCountersigns);
|
|
|
+ EndCountersignWithCascade(childCountersign, countersigns, businessType, ref updateCountersigns);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- EndCountersign(countersign, ref updateCountersigns);
|
|
|
+ EndCountersign(countersign, countersigns, businessType, ref updateCountersigns);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void EndCountersign(WorkflowCountersign countersign, ref List<WorkflowCountersign> updateCountersigns)
|
|
|
+ private void EndCountersign(WorkflowCountersign countersign, List<WorkflowCountersign> countersigns,
|
|
|
+ EBusinessType businessType, ref List<WorkflowCountersign> updateCountersigns)
|
|
|
{
|
|
|
//todo 1. trace? 先确定展现形式 2. end cs
|
|
|
|
|
|
+ countersign.End(null, null, businessType,
|
|
|
+ _sessionContext.RequiredUserId, _sessionContext.UserName,
|
|
|
+ _sessionContext.RequiredOrgId, _sessionContext.OrgName,
|
|
|
+ _sessionContext.OrgAreaCode, _sessionContext.OrgAreaName);
|
|
|
+
|
|
|
/*
|
|
|
* //结束step会签信息
|
|
|
countersignStartStep.CountersignEnd();
|
|
@@ -1759,8 +1796,7 @@ namespace Hotline.FlowEngine.Workflows
|
|
|
await _workflowCountersignRepository.UpdateAsync(currentCountersign, cancellationToken);
|
|
|
*/
|
|
|
|
|
|
- updateCountersigns.Add();
|
|
|
- throw new NotImplementedException();
|
|
|
+ updateCountersigns.Add(countersign);
|
|
|
}
|
|
|
|
|
|
private WorkflowStep? GetStep(List<WorkflowStep> steps, string orgCode, string userId,
|