refactor(workflow): 重构工作流引擎中的审核流程处理逻辑
- 移除硬编码的审核科角色ID配置数组 - 简化工作项处理流程,移除不必要的审核结果判断分支 - 优化并行节点处理逻辑,统一调用流程处理方法 - 更新未完成和已完成实例查询条件,移除基于角色ID的筛选 - 简化并行节点工作项创建逻辑,直接使用节点角色ID - 重构会签完成判断逻辑,简化数据库查询条件 - 移除重复的方法定义,统一使用单一实现main
parent
097dac13af
commit
a785ac0d1e
|
|
@ -19,18 +19,6 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
|||
|
||||
private readonly BusinessNoGenerator _businessNoGenerator;
|
||||
|
||||
// 配置:5个审核科角色ID(需与sys_role表对应,自行修改为实际值)
|
||||
private readonly List<long> _auditDeptRoleIds = new()
|
||||
{
|
||||
1, // 政策法规科
|
||||
2, // 详细规划科
|
||||
3, // 空间规划科
|
||||
4, // 开发利用科
|
||||
5 // 工程科
|
||||
};
|
||||
|
||||
// 配置:执法监督科角色ID(需与sys_role表对应,自行修改为实际值)
|
||||
private const long _supervisionDeptRoleId = 6;
|
||||
|
||||
public WorkflowEngineApp(ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<SysCategoryType> repository,
|
||||
IAuth auth, BusinessNoGenerator businessNoGenerator) : base(unitWork, repository, auth)
|
||||
|
|
@ -199,47 +187,41 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
|||
if (flowInstance == null || currentNode == null)
|
||||
throw new Exception("流程实例或流程节点不存在");
|
||||
|
||||
if (requestDto.AuditResult is "Pass")
|
||||
// 步骤3:更新当前工作项为已完成
|
||||
workitem.Status = "Done";
|
||||
workitem.HandleTime = DateTime.Now;
|
||||
workitem.Comment = string.IsNullOrEmpty(requestDto.Comment) ? "处理完成" : requestDto.Comment;
|
||||
_sqlSugar.Updateable(workitem).ExecuteCommand();
|
||||
|
||||
// 生成下一节点数据
|
||||
// 步骤4:按节点类型分支处理核心逻辑
|
||||
switch (currentNode.NodeType)
|
||||
{
|
||||
// 步骤3:更新当前工作项为已完成
|
||||
workitem.Status = "Done";
|
||||
workitem.HandleTime = DateTime.Now;
|
||||
workitem.Comment = string.IsNullOrEmpty(requestDto.Comment) ? "处理完成" : requestDto.Comment;
|
||||
_sqlSugar.Updateable(workitem).ExecuteCommand();
|
||||
// 普通节点:执法监督科转发
|
||||
//case "Common" when currentNode.NodeName == "执法监督科转发":
|
||||
case "Common":
|
||||
FlowToNextNode(flowInstance.InstanceId, currentNode, userId, userName, workitem.Comment);
|
||||
break;
|
||||
|
||||
// 生成下一节点数据
|
||||
// 步骤4:按节点类型分支处理核心逻辑
|
||||
switch (currentNode.NodeType)
|
||||
{
|
||||
// 普通节点:执法监督科转发
|
||||
case "Common" when currentNode.NodeName == "执法监督科转发":
|
||||
FlowToNextNode(flowInstance.InstanceId, currentNode, userId, userName, workitem.Comment);
|
||||
break;
|
||||
case "Parallel":
|
||||
ProcessParallelAudit(flowInstance.InstanceId, currentNode.NodeId, userId, userName, requestDto);
|
||||
ProcessSummaryNode(flowInstance, currentNode, userId, userName);
|
||||
break;
|
||||
|
||||
// 并行节点:5个审核科会签 // todo
|
||||
case "Parallel" when _auditDeptRoleIds.Contains(currentNode.RoleId):
|
||||
ProcessParallelAudit(flowInstance.InstanceId, currentNode.NodeId, userId, userName, requestDto);
|
||||
break;
|
||||
// 分支节点:汇总(归档/退回区县)
|
||||
case "Branch" when currentNode.NodeName == "汇总判断":
|
||||
ProcessSummaryNode(flowInstance, currentNode, userId, userName);
|
||||
break;
|
||||
|
||||
// 分支节点:汇总(归档/退回区县)
|
||||
case "Branch" when currentNode.NodeName == "汇总判断":
|
||||
ProcessSummaryNode(flowInstance, currentNode, userId, userName);
|
||||
break;
|
||||
|
||||
// 结束节点:流程归档完成
|
||||
case "End":
|
||||
CompleteFlowInstance(flowInstance);
|
||||
break;
|
||||
}
|
||||
|
||||
// 提交事务
|
||||
UnitWork.Db.Ado.CommitTran();
|
||||
return true;
|
||||
}
|
||||
else // Reject todo 考虑驳回之后,怎么回到上一个节点
|
||||
{
|
||||
return true;
|
||||
// 结束节点:流程归档完成
|
||||
case "End":
|
||||
CompleteFlowInstance(flowInstance);
|
||||
break;
|
||||
}
|
||||
|
||||
// 提交事务
|
||||
UnitWork.Db.Ado.CommitTran();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -478,10 +460,12 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
|||
// 未办结逻辑:
|
||||
// 1. 当前用户参与过(处理过/待处理)
|
||||
// 2. 流程状态不是"Completed"(未完成)
|
||||
var unfinishedInstanceIds = _sqlSugar.Queryable<ZyFlowWorkitem, ZyFlowInstance>((w, i) => new JoinQueryInfos(
|
||||
JoinType.Inner, w.InstanceId == i.InstanceId))
|
||||
.Where((w, i) => (w.HandlerId == userId || (w.Status == "Draft" && _auditDeptRoleIds.Contains(w.NodeId)))
|
||||
&& i.Status != "Completed")
|
||||
var unfinishedInstanceIds = _sqlSugar
|
||||
.Queryable<ZyFlowWorkitem, ZyFlowInstance>((w, i)
|
||||
=> new JoinQueryInfos(JoinType.Inner, w.InstanceId == i.InstanceId))
|
||||
.Where((w, i)
|
||||
=> (w.HandlerId == userId || w.Status == "Draft")
|
||||
&& i.Status != "Completed")
|
||||
.Select((w, i) => i.InstanceId)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
|
@ -556,7 +540,7 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
|||
// 2. 流程状态是"Completed"(已完成)
|
||||
var completedInstanceIds = _sqlSugar.Queryable<ZyFlowWorkitem, ZyFlowInstance>((w, i) => new JoinQueryInfos(
|
||||
JoinType.Inner, w.InstanceId == i.InstanceId))
|
||||
.Where((w, i) => (w.HandlerId == userId || (w.Status == "Draft" && _auditDeptRoleIds.Contains(w.NodeId)))
|
||||
.Where((w, i) => (w.HandlerId == userId || w.Status == "Draft")
|
||||
&& i.Status == "Completed")
|
||||
.Select((w, i) => i.InstanceId)
|
||||
.Distinct()
|
||||
|
|
@ -732,10 +716,7 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
|||
// 并行节点(5个审核科):为每个审核科创建工作项
|
||||
if (nextNode.NodeType == "Parallel")
|
||||
{
|
||||
foreach (var roleId in _auditDeptRoleIds)
|
||||
{
|
||||
CreateAuditDeptWorkitem(instanceId, nextNode, roleId);
|
||||
}
|
||||
CreateAuditDeptWorkitem(instanceId, nextNode);
|
||||
}
|
||||
// 普通节点/分支节点:创建单个工作项
|
||||
else
|
||||
|
|
@ -794,6 +775,15 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
|||
}
|
||||
}
|
||||
|
||||
private bool IsAllAuditCompleted(long instanceId)
|
||||
{
|
||||
// 有一个 Pending
|
||||
var auditsCount = _sqlSugar.Queryable<ZyFlowParallelAudit>()
|
||||
.Where(a => a.InstanceId == instanceId)
|
||||
.Count();
|
||||
return auditsCount == 5;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理汇总节点(归档/退回区县)
|
||||
/// </summary>
|
||||
|
|
@ -855,12 +845,12 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
|||
/// <summary>
|
||||
/// 为审核科创建工作项
|
||||
/// </summary>
|
||||
private void CreateAuditDeptWorkitem(long instanceId, ZyFlowNode parallelNode, long roleId)
|
||||
private void CreateAuditDeptWorkitem(long instanceId, ZyFlowNode parallelNode)
|
||||
{
|
||||
// 获取科室用户信息
|
||||
var userInfo = GetRoleFirstUserInfo(roleId);
|
||||
var userInfo = GetRoleFirstUserInfo(parallelNode.RoleId);
|
||||
if (userInfo.userId <= 0 || string.IsNullOrEmpty(userInfo.userName))
|
||||
throw new Exception($"审核科角色【{roleId}】未配置有效用户");
|
||||
throw new Exception($"审核科角色【{parallelNode.RoleId}】未配置有效用户");
|
||||
|
||||
// 创建工作项
|
||||
var workitem = new ZyFlowWorkitem
|
||||
|
|
@ -929,18 +919,6 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
|||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断所有审核科是否完成会签
|
||||
/// </summary>
|
||||
private bool IsAllAuditCompleted(long instanceId)
|
||||
{
|
||||
var auditResults = _sqlSugar.Queryable<ZyFlowParallelAudit>()
|
||||
.Where(a => a.InstanceId == instanceId)
|
||||
.ToList();
|
||||
|
||||
// 条件:会签记录数=5个审核科 且 无待审核状态
|
||||
return auditResults.Count == _auditDeptRoleIds.Count && !auditResults.Any(a => a.AuditResult == "Pending");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户所属科室名称
|
||||
|
|
|
|||
Loading…
Reference in New Issue