条件节点支持SQL语句判断

dev
嵇文龙 2 months ago
parent 6909573c58
commit 070ac9d183

@ -64,21 +64,25 @@ public class FlowChild
public const string Exclusive = "exclusive";//互斥条件
public const string FORK = "fork"; //会签开始节点
public const string JOIN = "join"; //会签结束节点
/// <summary>
/// 动态节点
/// </summary>
public const string Dynamic = "dynamic";
/// <summary>
/// 节点Id
/// </summary>
public string Id { get; set; }
public string Id { get; set; } = string.Empty;
/// <summary>
/// 上级Id
/// </summary>
public string Pid { get; set; }
public string? Pid { get; set; }
/// <summary>
/// 节点类型 start end condition exclusive
/// </summary>
public string Type { get; set; }
public string Type { get; set; } = string.Empty;
/// <summary>
/// 节点名称
@ -88,11 +92,11 @@ public class FlowChild
/// <summary>
/// 子节点
/// </summary>
public FlowChild Child { get; set; }
public FlowChild? Child { get; set; }
/// <summary>
/// 子节点列表
/// </summary>
public List<FlowChild> Children { get; set; }
public List<FlowChild>? Children { get; set; }
/// <summary>
/// 审批类型 指定user role
/// </summary>
@ -157,7 +161,7 @@ public class FlowChild
/// </summary>
public FlowGroupConditions? Conditions { get; set; }
/// <summary>
/// 是否使用SQL语句条件
/// 是否使用SQL语句条件(默认为否)
/// </summary>
public bool UseSQL { get; set; }
/// <summary>

@ -622,7 +622,7 @@ public class FlowInstanceService : ServiceBase, IFlowInstanceService
protected virtual FlowRuntime CreateRuntimeService(FlowInstance instance)
{
return new FlowRuntime(instance, Db, null, User);
return new FlowRuntime(instance, Db, null);
}
public DataResult<FlowInstanceRes> GetFlowInstanceInfo(string id)

@ -1,5 +1,5 @@
using DS.Module.Core.Data;
using DS.Module.Core.Extensions;
using DS.Module.UserModule;
using DS.WMS.Core.Flow.Dtos;
using DS.WMS.Core.Flow.Entity;
using Mapster;
@ -13,22 +13,31 @@ namespace DS.WMS.Core.Flow.Method;
/// </summary>
public class FlowRuntime
{
public FlowRuntime(FlowInstance instance, ISqlSugarClient _db) : this(instance, _db, null, null)
ISqlSugarClient db { get; set; }
ISqlSugarClient tenantDb { get; set; }
/// <summary>
/// 构造函数
/// </summary>
/// <param name="instance"></param>
/// <param name="_db"></param>
public FlowRuntime(FlowInstance instance, ISqlSugarClient _db) : this(instance, _db, null)
{
}
/// <summary>
/// 构造函数
/// </summary>
public FlowRuntime(FlowInstance instance, ISqlSugarClient _db, ISqlSugarClient tenantDb, IUser user)
public FlowRuntime(FlowInstance instance, ISqlSugarClient _db, ISqlSugarClient? tenantDb)
{
ArgumentNullException.ThrowIfNull(instance, nameof(instance));
db = _db;
BusinessId = instance.BusinessId;
ColumnView = instance.ColumnView;
this.tenantDb = tenantDb;
this.user = user;
InitNodes(instance.Content); //获取工作流模板内容的json对象;
ReadJson(instance.Content); //获取工作流模板内容的json对象;
CurrentNodeId = instance.ActivityId == "" ? StartNodeId : instance.ActivityId;
CurrentNodeType = GetNodeType(CurrentNodeId);
@ -48,7 +57,7 @@ public class FlowRuntime
else
{
NextNodeId = GetNextNodeId(CurrentNodeId); //下一个节点
if (string.IsNullOrEmpty(NextNodeId) && CurrentNodeType == 3)
if (string.IsNullOrEmpty(NextNodeId) && CurrentNodeType == 3)
{
//当前节点类型为开始节点,且没有下一级节点,则认为应跳出工作流
ShouldSkip = true;
@ -56,27 +65,25 @@ public class FlowRuntime
else
{
NextNodeType = GetNodeType(NextNodeId);
}
}
}
}
/// <summary>
/// 业务ID
/// </summary>
public long BusinessId { get; set; }
public string ColumnView { get; set; }
ISqlSugarClient db { get; set; }
ISqlSugarClient tenantDb { get; set; }
IUser user { get; set; }
/// <summary>
/// 查询对象名
/// </summary>
public string ColumnView { get; set; }
/// <summary>
/// 是否应跳过工作流执行
/// </summary>
public bool ShouldSkip { get; private set; }
///// <summary>
///// 运行实例的Id
///// </summary>
//public long FlowInstanceId { get; set; }
/// <summary>
/// 开始节点的ID
/// </summary>
@ -122,6 +129,9 @@ public class FlowRuntime
/// </summary>
public List<FlowChild> ChildNodes { get; set; }
/// <summary>
/// 备注
/// </summary>
public string? Note { get; set; }
/// <summary>
@ -129,9 +139,9 @@ public class FlowRuntime
/// </summary>
/// <param name="schemeContentJson"></param>
/// <returns></returns>
private void InitNodes(string schemeContentJson)
private void ReadJson(string schemeContentJson)
{
ChildNodes = new List<FlowChild>();
ChildNodes = [];
var root = JsonConvert.DeserializeObject<FlowRoot>(schemeContentJson);
if (root.Type == FlowChild.START)
@ -177,8 +187,7 @@ public class FlowRuntime
// var childs = new List<FlowChild>();
}
private List<FlowChild> GetFlowConditions(FlowChild parent)
private static List<FlowChild> GetFlowConditions(FlowChild parent)
{
var conditionNodes = new List<FlowChild>();
if (parent.Children != null)
@ -192,16 +201,15 @@ public class FlowRuntime
return conditionNodes;
}
/// <summary>
/// 获取下一个节点
/// <param name="nodeId"></param>
/// </summary>
private string? GetNextNodeId(string nodeId = null)
private string? GetNextNodeId(string? nodeId = null)
{
if (nodeId == null)
{
return ChildNodes.Where(x => x.Pid == "root").First().Id;
return ChildNodes.Where(x => x.Pid == "root").First()?.Id;
}
else
{
@ -219,7 +227,7 @@ public class FlowRuntime
}
else
{
return ChildNodes.Where(x => x.Id == "end").First().Id;
return ChildNodes.Where(x => x.Id == "end").First()?.Id;
}
}
}
@ -233,15 +241,30 @@ public class FlowRuntime
{
var conditionNodes = GetFlowConditions(parent);
var conditionId = string.Empty;
ISqlSugarClient sugarClient = tenantDb ?? db;
for (int i = 0; i < conditionNodes.Count; i++)
{
var conditionNode = conditionNodes[i];
if (i == conditionNodes.Count - 1)
{
conditionId = conditionNodes[i].Id;
conditionId = conditionNode.Id;
}
else if (conditionNode.UseSQL)
{
var scalar = sugarClient.Ado.GetScalar(conditionNode.SQLText,
new SugarParameter(nameof(BaseModel<long>.Id), BusinessId));
if (scalar != null && (scalar is int count && count > 0 || scalar is bool boolValue && boolValue))
{
conditionId = conditionNode.Id;
break;
}
}
else
{
var nodeSection = conditionNodes[i].Conditions;
var nodeSection = conditionNode.Conditions;
var list = new List<ConditionalCollections>();
var conditionList = new List<KeyValuePair<WhereType, ConditionalModel>>(nodeSection.Conditions.Count);
@ -297,15 +320,11 @@ public class FlowRuntime
if (list.Count == 0) //跳过默认条件
continue;
//string json = JsonConvert.SerializeObject(list);
//db.Utilities.JsonToConditionalModels(json);
List<IConditionalModel> conditionalModels = [.. list];
ISqlSugarClient sugarClient = tenantDb ?? db;
List<IConditionalModel> conditionalModels = [.. list];
var exists = sugarClient.Queryable<object>().AS(ColumnView).Where("Id=@Id", new { Id = BusinessId }).Where(conditionalModels).Any();
if (exists)
{
conditionId = conditionNodes[i].Id;
conditionId = conditionNode.Id;
break;
}
}
@ -350,7 +369,6 @@ public class FlowRuntime
}
}
/// <summary>
/// 转换FlowRoot
/// </summary>
@ -431,6 +449,7 @@ public class FlowRuntime
return -1;
}
/// <summary>
/// 转换SqlSugar 条件操作符
/// </summary>
@ -438,37 +457,29 @@ public class FlowRuntime
/// <returns></returns>
private static ConditionalType GetConditionalType(string conditionalType)
{
switch (conditionalType)
return conditionalType switch
{
//等于
case "equal":
return ConditionalType.Equal;
"equal" => ConditionalType.Equal,
//不等于
case "not_equal":
return ConditionalType.NoEqual;
"not_equal" => ConditionalType.NoEqual,
//大于
case "GreaterThan":
return ConditionalType.GreaterThan;
"GreaterThan" => ConditionalType.GreaterThan,
//大于等于
case "GreaterThanOrEqual":
return ConditionalType.GreaterThanOrEqual;
"GreaterThanOrEqual" => ConditionalType.GreaterThanOrEqual,
//小于
case "LessThan":
return ConditionalType.LessThan;
"LessThan" => ConditionalType.LessThan,
//小于等于
case "LessThanOrEqual":
return ConditionalType.GreaterThanOrEqual;
"LessThanOrEqual" => ConditionalType.GreaterThanOrEqual,
//包含
case "contains":
return ConditionalType.In;
"contains" => ConditionalType.In,
//不包含
case "not_contain":
return ConditionalType.NotIn;
"not_contain" => ConditionalType.NotIn,
//默认
default:
return ConditionalType.Equal;
}
_ => ConditionalType.Equal,
};
}
/// <summary>
/// 获取节点类型 0会签开始,1会签结束,2一般节点,3开始节点,4流程运行结束
/// </summary>
@ -476,39 +487,23 @@ public class FlowRuntime
/// <returns></returns>
public int GetNodeType(string nodeId)
{
switch (ChildNodes.Where(x => x.Id == nodeId).First().Type)
return ChildNodes.Where(x => x.Id == nodeId).First().Type switch
{
//会签开始节点
case FlowChild.Approval:
return 0;
FlowChild.Approval => 0,
//会签结束节点
case FlowChild.JOIN:
return 1;
FlowChild.JOIN => 1,
//结束节点
case FlowChild.END:
return 4;
FlowChild.END => 4,
//开始节点
case FlowChild.START:
return 3;
FlowChild.START => 3,
//互斥条件
FlowChild.Exclusive => 5,
//互斥条件
case FlowChild.Exclusive:
return 5;
FlowChild.Dynamic => 6,
//一般节点
default:
return 2;
}
}
//获取上一个节点
private FlowChild GetPreNode(string nodeId = null)
{
var child = ChildNodes.Where(x => x.Pid == nodeId).First();
if (child.IsNull())
{
throw new Exception("无法找到上一个点");
}
return child;
_ => 2,
};
}
/// <summary>

@ -767,7 +767,6 @@ namespace DS.WMS.Core.Invoice.Method
/// <param name="invoice">发票</param>
protected virtual Task PostSaveAsync(TEntity invoice) => Task.CompletedTask;
/// <summary>
/// 删除发票
/// </summary>

@ -5,7 +5,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<Project>
<PropertyGroup>
<_PublishTargetUrl>D:\Publish\DS8\FeeApi</_PublishTargetUrl>
<History>True|2024-09-23T10:07:54.7222163Z||;True|2024-09-23T17:23:57.7568406+08:00||;True|2024-09-23T16:28:49.3169826+08:00||;True|2024-09-23T15:57:31.8052490+08:00||;True|2024-09-23T11:47:21.1445419+08:00||;True|2024-09-23T09:24:36.0732229+08:00||;True|2024-09-21T11:59:19.0549926+08:00||;True|2024-09-21T11:24:32.4451752+08:00||;True|2024-09-21T10:39:11.5297411+08:00||;True|2024-09-20T18:24:31.7827684+08:00||;True|2024-09-19T17:55:53.1666689+08:00||;True|2024-09-19T17:42:47.9061485+08:00||;True|2024-09-19T16:08:21.7225571+08:00||;False|2024-09-19T14:15:42.9318446+08:00||;True|2024-09-19T11:20:03.5567568+08:00||;True|2024-09-18T11:35:18.1509724+08:00||;True|2024-09-18T09:08:59.1152574+08:00||;True|2024-09-14T15:48:22.9374486+08:00||;True|2024-09-14T15:42:19.0503983+08:00||;True|2024-09-14T11:51:53.3339222+08:00||;True|2024-09-14T11:41:38.3542237+08:00||;True|2024-09-14T11:19:13.1037012+08:00||;True|2024-09-13T14:31:12.4598160+08:00||;True|2024-09-13T10:44:56.1241214+08:00||;False|2024-09-13T10:44:26.6088271+08:00||;False|2024-09-13T10:44:06.1615137+08:00||;False|2024-09-13T10:43:19.2432517+08:00||;False|2024-09-13T10:38:18.1663387+08:00||;True|2024-09-06T18:49:17.9435308+08:00||;True|2024-09-06T17:01:39.6646353+08:00||;True|2024-09-06T10:27:36.9990456+08:00||;True|2024-09-06T09:48:23.4236094+08:00||;True|2024-09-05T13:57:23.8452431+08:00||;True|2024-09-05T10:21:34.6675149+08:00||;True|2024-09-05T09:12:44.5610882+08:00||;True|2024-09-04T10:07:38.3707398+08:00||;True|2024-09-04T09:52:47.0574599+08:00||;True|2024-09-03T16:41:23.7516960+08:00||;True|2024-09-03T15:22:31.8718097+08:00||;True|2024-09-03T10:01:09.7656702+08:00||;False|2024-09-03T09:46:46.8956531+08:00||;True|2024-09-02T17:07:41.0268500+08:00||;True|2024-09-02T13:50:22.0203254+08:00||;True|2024-09-02T13:34:23.3441546+08:00||;True|2024-08-30T11:25:14.7431645+08:00||;True|2024-08-29T16:38:26.3491372+08:00||;True|2024-08-29T16:32:31.8580864+08:00||;False|2024-08-29T16:30:41.4763198+08:00||;True|2024-08-09T09:18:05.8484398+08:00||;True|2024-08-09T08:45:38.7858906+08:00||;True|2024-08-05T11:37:07.3133020+08:00||;True|2024-07-24T16:45:58.2272340+08:00||;True|2024-07-24T15:48:52.0128987+08:00||;True|2024-07-23T17:41:01.7494842+08:00||;True|2024-07-23T17:25:11.8773492+08:00||;True|2024-07-23T17:07:16.5460273+08:00||;True|2024-07-22T08:59:23.3235603+08:00||;True|2024-07-12T17:35:11.1225017+08:00||;True|2024-07-11T11:40:17.3581147+08:00||;True|2024-07-04T17:20:50.0175739+08:00||;True|2024-07-02T11:26:14.2092751+08:00||;True|2024-07-02T09:21:51.3513605+08:00||;True|2024-07-01T17:47:56.0407256+08:00||;True|2024-07-01T16:42:55.7374984+08:00||;True|2024-07-01T15:49:58.9266967+08:00||;True|2024-07-01T14:35:48.1117178+08:00||;True|2024-07-01T11:41:52.2969338+08:00||;True|2024-07-01T11:13:02.6561160+08:00||;True|2024-06-28T15:28:43.1470725+08:00||;True|2024-06-28T15:16:20.1999596+08:00||;True|2024-06-28T15:14:56.2534743+08:00||;True|2024-06-28T15:02:41.3033806+08:00||;True|2024-06-28T13:37:28.2462742+08:00||;True|2024-06-28T11:06:30.7400535+08:00||;True|2024-06-26T15:24:17.1939896+08:00||;True|2024-06-26T14:33:06.3530466+08:00||;True|2024-06-26T09:45:24.4055568+08:00||;True|2024-06-25T15:45:57.6052473+08:00||;True|2024-06-25T10:17:17.7408916+08:00||;False|2024-06-25T10:16:23.5639654+08:00||;False|2024-06-25T10:15:28.3857721+08:00||;False|2024-06-25T10:10:59.5536995+08:00||;False|2024-06-25T10:07:10.4050937+08:00||;True|2024-06-24T15:22:18.2672769+08:00||;True|2024-06-24T15:01:04.8153621+08:00||;False|2024-06-24T15:00:29.9618848+08:00||;True|2024-06-24T14:07:19.9401637+08:00||;False|2024-06-24T14:06:36.1250570+08:00||;True|2024-06-21T15:13:57.4273503+08:00||;True|2024-06-21T15:04:37.8218608+08:00||;True|2024-06-21T14:12:48.0266638+08:00||;True|2024-06-21T13:52:30.0950155+08:00||;True|2024-06-20T11:02:42.9508506+08:00||;True|2024-06-19T11:43:01.1899282+08:00||;True|2024-06-19T11:23:01.2938141+08:00||;True|2024-06-18T08:51:21.6222152+08:00||;True|2024-06-17T09:20:35.0804494+08:00||;True|2024-06-17T08:41:58.1319484+08:00||;True|2024-06-17T08:38:09.0137102+08:00||;True|2024-06-14T15:19:45.7395180+08:00||;</History>
<History>True|2024-09-24T00:59:56.1995425Z||;True|2024-09-23T18:07:54.7222163+08:00||;True|2024-09-23T17:23:57.7568406+08:00||;True|2024-09-23T16:28:49.3169826+08:00||;True|2024-09-23T15:57:31.8052490+08:00||;True|2024-09-23T11:47:21.1445419+08:00||;True|2024-09-23T09:24:36.0732229+08:00||;True|2024-09-21T11:59:19.0549926+08:00||;True|2024-09-21T11:24:32.4451752+08:00||;True|2024-09-21T10:39:11.5297411+08:00||;True|2024-09-20T18:24:31.7827684+08:00||;True|2024-09-19T17:55:53.1666689+08:00||;True|2024-09-19T17:42:47.9061485+08:00||;True|2024-09-19T16:08:21.7225571+08:00||;False|2024-09-19T14:15:42.9318446+08:00||;True|2024-09-19T11:20:03.5567568+08:00||;True|2024-09-18T11:35:18.1509724+08:00||;True|2024-09-18T09:08:59.1152574+08:00||;True|2024-09-14T15:48:22.9374486+08:00||;True|2024-09-14T15:42:19.0503983+08:00||;True|2024-09-14T11:51:53.3339222+08:00||;True|2024-09-14T11:41:38.3542237+08:00||;True|2024-09-14T11:19:13.1037012+08:00||;True|2024-09-13T14:31:12.4598160+08:00||;True|2024-09-13T10:44:56.1241214+08:00||;False|2024-09-13T10:44:26.6088271+08:00||;False|2024-09-13T10:44:06.1615137+08:00||;False|2024-09-13T10:43:19.2432517+08:00||;False|2024-09-13T10:38:18.1663387+08:00||;True|2024-09-06T18:49:17.9435308+08:00||;True|2024-09-06T17:01:39.6646353+08:00||;True|2024-09-06T10:27:36.9990456+08:00||;True|2024-09-06T09:48:23.4236094+08:00||;True|2024-09-05T13:57:23.8452431+08:00||;True|2024-09-05T10:21:34.6675149+08:00||;True|2024-09-05T09:12:44.5610882+08:00||;True|2024-09-04T10:07:38.3707398+08:00||;True|2024-09-04T09:52:47.0574599+08:00||;True|2024-09-03T16:41:23.7516960+08:00||;True|2024-09-03T15:22:31.8718097+08:00||;True|2024-09-03T10:01:09.7656702+08:00||;False|2024-09-03T09:46:46.8956531+08:00||;True|2024-09-02T17:07:41.0268500+08:00||;True|2024-09-02T13:50:22.0203254+08:00||;True|2024-09-02T13:34:23.3441546+08:00||;True|2024-08-30T11:25:14.7431645+08:00||;True|2024-08-29T16:38:26.3491372+08:00||;True|2024-08-29T16:32:31.8580864+08:00||;False|2024-08-29T16:30:41.4763198+08:00||;True|2024-08-09T09:18:05.8484398+08:00||;True|2024-08-09T08:45:38.7858906+08:00||;True|2024-08-05T11:37:07.3133020+08:00||;True|2024-07-24T16:45:58.2272340+08:00||;True|2024-07-24T15:48:52.0128987+08:00||;True|2024-07-23T17:41:01.7494842+08:00||;True|2024-07-23T17:25:11.8773492+08:00||;True|2024-07-23T17:07:16.5460273+08:00||;True|2024-07-22T08:59:23.3235603+08:00||;True|2024-07-12T17:35:11.1225017+08:00||;True|2024-07-11T11:40:17.3581147+08:00||;True|2024-07-04T17:20:50.0175739+08:00||;True|2024-07-02T11:26:14.2092751+08:00||;True|2024-07-02T09:21:51.3513605+08:00||;True|2024-07-01T17:47:56.0407256+08:00||;True|2024-07-01T16:42:55.7374984+08:00||;True|2024-07-01T15:49:58.9266967+08:00||;True|2024-07-01T14:35:48.1117178+08:00||;True|2024-07-01T11:41:52.2969338+08:00||;True|2024-07-01T11:13:02.6561160+08:00||;True|2024-06-28T15:28:43.1470725+08:00||;True|2024-06-28T15:16:20.1999596+08:00||;True|2024-06-28T15:14:56.2534743+08:00||;True|2024-06-28T15:02:41.3033806+08:00||;True|2024-06-28T13:37:28.2462742+08:00||;True|2024-06-28T11:06:30.7400535+08:00||;True|2024-06-26T15:24:17.1939896+08:00||;True|2024-06-26T14:33:06.3530466+08:00||;True|2024-06-26T09:45:24.4055568+08:00||;True|2024-06-25T15:45:57.6052473+08:00||;True|2024-06-25T10:17:17.7408916+08:00||;False|2024-06-25T10:16:23.5639654+08:00||;False|2024-06-25T10:15:28.3857721+08:00||;False|2024-06-25T10:10:59.5536995+08:00||;False|2024-06-25T10:07:10.4050937+08:00||;True|2024-06-24T15:22:18.2672769+08:00||;True|2024-06-24T15:01:04.8153621+08:00||;False|2024-06-24T15:00:29.9618848+08:00||;True|2024-06-24T14:07:19.9401637+08:00||;False|2024-06-24T14:06:36.1250570+08:00||;True|2024-06-21T15:13:57.4273503+08:00||;True|2024-06-21T15:04:37.8218608+08:00||;True|2024-06-21T14:12:48.0266638+08:00||;True|2024-06-21T13:52:30.0950155+08:00||;True|2024-06-20T11:02:42.9508506+08:00||;True|2024-06-19T11:43:01.1899282+08:00||;True|2024-06-19T11:23:01.2938141+08:00||;True|2024-06-18T08:51:21.6222152+08:00||;True|2024-06-17T09:20:35.0804494+08:00||;True|2024-06-17T08:41:58.1319484+08:00||;True|2024-06-17T08:38:09.0137102+08:00||;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>
Loading…
Cancel
Save