```
feat(workflow): 完善工作流草稿保存功能并优化数据库查询 - 添加事务处理确保数据一致性 - 集成流程模板查询和验证逻辑 - 实现流程实例创建和开始节点初始化 - 添加工作项记录并优化SQL查询结构 - 改进错误处理机制 ```main
parent
5fc02c54fd
commit
67425d76ef
|
|
@ -649,8 +649,8 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
// 执行查询,返回 List<long> 结果
|
// 执行查询,返回 List<long> 结果
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var allQuery = _sqlSugar.Queryable<IllegalConstructionAssessment, ZyFlowInstance, ZyFlowNode>(
|
var allQuery = _sqlSugar.Queryable<IllegalConstructionAssessment, ZyFlowInstance, ZyFlowNode>((t, i, n) =>
|
||||||
(t, i, n) => new JoinQueryInfos(
|
new JoinQueryInfos(
|
||||||
// 第一个左联:t(违建表) LEFT JOIN i(流程实例表) ON 业务编号匹配
|
// 第一个左联:t(违建表) LEFT JOIN i(流程实例表) ON 业务编号匹配
|
||||||
JoinType.Left, t.BusinessNumber == i.BusinessNo,
|
JoinType.Left, t.BusinessNumber == i.BusinessNo,
|
||||||
// 第二个左联:i(流程实例表) LEFT JOIN n(流程节点表) ON 当前节点ID匹配
|
// 第二个左联:i(流程实例表) LEFT JOIN n(流程节点表) ON 当前节点ID匹配
|
||||||
|
|
@ -666,7 +666,8 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
.Where(w => w.HandlerId == userId)
|
.Where(w => w.HandlerId == userId)
|
||||||
// 关键1:用WhereIF判断列表非空,避免IN()语法错误;用SqlFunc.Contains替代原生Contains
|
// 关键1:用WhereIF判断列表非空,避免IN()语法错误;用SqlFunc.Contains替代原生Contains
|
||||||
.WhereIF(nodeIdList != null && nodeIdList.Any(),
|
.WhereIF(nodeIdList != null && nodeIdList.Any(),
|
||||||
w => w.HandlerId == null && w.Status == "ToDo" && SqlFunc.ContainsArray(nodeIdList, w.NodeId))
|
w => w.HandlerId == null && w.Status == "ToDo" &&
|
||||||
|
SqlFunc.ContainsArray(nodeIdList, w.NodeId))
|
||||||
// 主查询与子查询的实例ID关联(原有逻辑,不变)
|
// 主查询与子查询的实例ID关联(原有逻辑,不变)
|
||||||
.Where(w => w.InstanceId == i.InstanceId)
|
.Where(w => w.InstanceId == i.InstanceId)
|
||||||
.Select(w => w.InstanceId)
|
.Select(w => w.InstanceId)
|
||||||
|
|
@ -1002,25 +1003,73 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
/// <exception cref="NotImplementedException"></exception>
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
public object SaveDraft(InitiateFlowRequestDto requestDto)
|
public object SaveDraft(InitiateFlowRequestDto requestDto)
|
||||||
{
|
{
|
||||||
requestDto.BusinessNo = _businessNoGenerator.GenerateBusinessNo("WF");
|
try
|
||||||
var attachmentPaths = string.Join(",", requestDto.Attachments);
|
|
||||||
var user = _auth.GetCurrentUser().User;
|
|
||||||
var illegalConstructionAssessment = new IllegalConstructionAssessment
|
|
||||||
{
|
{
|
||||||
Id = requestDto.BusinessNo,
|
UnitWork.Db.Ado.BeginTran();
|
||||||
Title = requestDto.Title,
|
requestDto.BusinessNo = _businessNoGenerator.GenerateBusinessNo("WF");
|
||||||
BusinessNumber = requestDto.BusinessNo,
|
var attachmentPaths = string.Join(",", requestDto.Attachments);
|
||||||
Attachments = requestDto.Attachments != null ? attachmentPaths : string.Empty,
|
var user = _auth.GetCurrentUser().User;
|
||||||
AcceptanceTime = DateTime.Now,
|
var illegalConstructionAssessment = new IllegalConstructionAssessment
|
||||||
Status = "Draft",
|
{
|
||||||
Type = requestDto.type,
|
Id = requestDto.BusinessNo,
|
||||||
CreateTime = DateTime.Now,
|
Title = requestDto.Title,
|
||||||
CreateUser = user.Name,
|
BusinessNumber = requestDto.BusinessNo,
|
||||||
UpdateTime = DateTime.Now,
|
Attachments = requestDto.Attachments != null ? attachmentPaths : string.Empty,
|
||||||
CreateUserId = user.Id
|
AcceptanceTime = DateTime.Now,
|
||||||
};
|
Status = "Draft",
|
||||||
_sqlSugar.Insertable(illegalConstructionAssessment).ExecuteCommand();
|
Type = requestDto.type,
|
||||||
return true;
|
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)
|
public dynamic Detail(string businessNo)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue