```
feat(workflow): 完善工作流草稿保存功能并优化数据库查询 - 添加事务处理确保数据一致性 - 集成流程模板查询和验证逻辑 - 实现流程实例创建和开始节点初始化 - 添加工作项记录并优化SQL查询结构 - 改进错误处理机制 ```main
parent
5fc02c54fd
commit
67425d76ef
|
|
@ -648,9 +648,9 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
|||
.Select(zy => zy.NodeId)
|
||||
// 执行查询,返回 List<long> 结果
|
||||
.ToList();
|
||||
|
||||
var allQuery = _sqlSugar.Queryable<IllegalConstructionAssessment, ZyFlowInstance, ZyFlowNode>(
|
||||
(t, i, n) => new JoinQueryInfos(
|
||||
|
||||
var allQuery = _sqlSugar.Queryable<IllegalConstructionAssessment, ZyFlowInstance, ZyFlowNode>((t, i, n) =>
|
||||
new JoinQueryInfos(
|
||||
// 第一个左联:t(违建表) LEFT JOIN i(流程实例表) ON 业务编号匹配
|
||||
JoinType.Left, t.BusinessNumber == i.BusinessNo,
|
||||
// 第二个左联:i(流程实例表) LEFT JOIN n(流程节点表) ON 当前节点ID匹配
|
||||
|
|
@ -665,8 +665,9 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
|||
// 子查询过滤条件:仅修改Contains + 加nodeIdList非空判断
|
||||
.Where(w => w.HandlerId == userId)
|
||||
// 关键1:用WhereIF判断列表非空,避免IN()语法错误;用SqlFunc.Contains替代原生Contains
|
||||
.WhereIF(nodeIdList != null && nodeIdList.Any(),
|
||||
w => w.HandlerId == null && w.Status == "ToDo" && SqlFunc.ContainsArray(nodeIdList, w.NodeId))
|
||||
.WhereIF(nodeIdList != null && nodeIdList.Any(),
|
||||
w => w.HandlerId == null && w.Status == "ToDo" &&
|
||||
SqlFunc.ContainsArray(nodeIdList, w.NodeId))
|
||||
// 主查询与子查询的实例ID关联(原有逻辑,不变)
|
||||
.Where(w => w.InstanceId == i.InstanceId)
|
||||
.Select(w => w.InstanceId)
|
||||
|
|
@ -1002,25 +1003,73 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
|||
/// <exception cref="NotImplementedException"></exception>
|
||||
public object SaveDraft(InitiateFlowRequestDto requestDto)
|
||||
{
|
||||
requestDto.BusinessNo = _businessNoGenerator.GenerateBusinessNo("WF");
|
||||
var attachmentPaths = string.Join(",", requestDto.Attachments);
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
var illegalConstructionAssessment = new IllegalConstructionAssessment
|
||||
try
|
||||
{
|
||||
Id = requestDto.BusinessNo,
|
||||
Title = requestDto.Title,
|
||||
BusinessNumber = requestDto.BusinessNo,
|
||||
Attachments = requestDto.Attachments != null ? attachmentPaths : string.Empty,
|
||||
AcceptanceTime = DateTime.Now,
|
||||
Status = "Draft",
|
||||
Type = requestDto.type,
|
||||
CreateTime = DateTime.Now,
|
||||
CreateUser = user.Name,
|
||||
UpdateTime = DateTime.Now,
|
||||
CreateUserId = user.Id
|
||||
};
|
||||
_sqlSugar.Insertable(illegalConstructionAssessment).ExecuteCommand();
|
||||
return true;
|
||||
UnitWork.Db.Ado.BeginTran();
|
||||
requestDto.BusinessNo = _businessNoGenerator.GenerateBusinessNo("WF");
|
||||
var attachmentPaths = string.Join(",", requestDto.Attachments);
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
var illegalConstructionAssessment = new IllegalConstructionAssessment
|
||||
{
|
||||
Id = requestDto.BusinessNo,
|
||||
Title = requestDto.Title,
|
||||
BusinessNumber = requestDto.BusinessNo,
|
||||
Attachments = requestDto.Attachments != null ? attachmentPaths : string.Empty,
|
||||
AcceptanceTime = DateTime.Now,
|
||||
Status = "Draft",
|
||||
Type = requestDto.type,
|
||||
CreateTime = DateTime.Now,
|
||||
CreateUser = user.Name,
|
||||
UpdateTime = DateTime.Now,
|
||||
CreateUserId = user.Id
|
||||
};
|
||||
_sqlSugar.Insertable(illegalConstructionAssessment).ExecuteCommand();
|
||||
var template = _sqlSugar.Queryable<ZyFlowTemplate>()
|
||||
.Where(t => t.FlowCode == requestDto.FlowCode && t.IsEnabled == true)
|
||||
.First();
|
||||
if (template == null)
|
||||
throw new Exception($"流程模板【{requestDto.FlowCode}】不存在或未启用");
|
||||
|
||||
// 步骤2:查询流程开始节点(区县提交)
|
||||
var startNode = _sqlSugar.Queryable<ZyFlowNode>()
|
||||
.Where(n => n.TemplateId == template.TemplateId && n.NodeType == "Start" && n.NodeName == "区县提交")
|
||||
.First();
|
||||
if (startNode == null)
|
||||
throw new Exception("流程开始节点【区县提交】不存在,请配置节点");
|
||||
var flowInstance = new ZyFlowInstance
|
||||
{
|
||||
TemplateId = template.TemplateId,
|
||||
FlowCode = template.FlowCode,
|
||||
BusinessNo = requestDto.BusinessNo,
|
||||
Status = "Draft", // 已提交
|
||||
CurrentNodeId = startNode.NodeId,
|
||||
InitiatorId = user.Id,
|
||||
InitiatorName = user.Name,
|
||||
CreateTime = DateTime.Now
|
||||
};
|
||||
var instanceId = _sqlSugar.Insertable(flowInstance).ExecuteReturnIdentity();
|
||||
// 步骤4:插入开始节点工作项(直接标记为已完成)
|
||||
// 开始节点无ToDo
|
||||
var startWorkitem = new ZyFlowWorkitem
|
||||
{
|
||||
InstanceId = instanceId,
|
||||
NodeId = startNode.NodeId,
|
||||
NodeName = startNode.NodeName,
|
||||
HandlerId = user.Id,
|
||||
HandlerName = user.Name,
|
||||
Status = "Draft", // 已完成
|
||||
ReceiveTime = DateTime.Now,
|
||||
HandleTime = DateTime.Now,
|
||||
Comment = "区县拟办"
|
||||
};
|
||||
_sqlSugar.Insertable(startWorkitem).ExecuteCommand();
|
||||
UnitWork.Db.Ado.CommitTran();
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
UnitWork.Db.Ado.RollbackTran();
|
||||
}
|
||||
}
|
||||
|
||||
public dynamic Detail(string businessNo)
|
||||
|
|
|
|||
Loading…
Reference in New Issue