Skip to content

Commit

Permalink
增加产品属性前端显示字段,增加执行器的部分注释
Browse files Browse the repository at this point in the history
  • Loading branch information
SiasZhang committed Mar 18, 2023
1 parent 6be1902 commit 9b531f3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
3 changes: 2 additions & 1 deletion IoTSharp/Controllers/ProducesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public async Task<ApiResult<PagedData<ProduceDto>>> List([FromQuery] QueryDto m)
DefaultTimeout = c.DefaultTimeout,
Description = c.Description,
Name = c.Name,
Devices = c.Devices
Devices = c.Devices,
DefaultDeviceType = c.DefaultDeviceType
});
return new ApiResult<PagedData<ProduceDto>>(ApiCode.Success, "OK", data);
}
Expand Down
5 changes: 4 additions & 1 deletion IoTSharp/Dtos/ProduceDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ public class ProduceDto
public IdentityType DefaultIdentityType { get; set; } = IdentityType.AccessToken;
public string Description { get; set; }


public List<Device> Devices { get; set; }
/// <summary>
/// 默认设备类型
/// </summary>
public DeviceType DefaultDeviceType { get; set; }

}
}
24 changes: 20 additions & 4 deletions IoTSharp/FlowRuleEngine/FlowRuleProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ public async Task<List<FlowOperation>> RunFlowRules(Guid ruleid, object data, Gu
};

_allflowoperation.Add(startoperation);
//从“开始节点”上链接的线节点对象进行规则判断,通过线对象上的规则才能进行后续逻辑
var nextflows = await ProcessCondition(_allFlows, start.FlowId, data);
//获取到的通过规则判断的后续节点列表
if (nextflows != null)
{
var step = startoperation.Step + 1;
Expand All @@ -185,6 +187,7 @@ public async Task<List<FlowOperation>> RunFlowRules(Guid ruleid, object data, Gu
};

_allflowoperation.Add(flowOperation);
//执行节点逻辑
await Process(_allFlows, _allflowoperation, flowOperation.OperationId, data, deviceId);
}
return _allflowoperation;
Expand Down Expand Up @@ -227,6 +230,7 @@ public async Task Process(List<Flow> _allFlows, List<FlowOperation> _allflowoper
var flow = _allFlows.FirstOrDefault(c => c.bpmnid == peroperation.Flow.TargetId && c.FlowType != "label");
switch (flow.FlowType)
{
//线节点对象
case "bpmn:SequenceFlow":
{
var step = peroperation.Step + 1;
Expand All @@ -251,7 +255,7 @@ public async Task Process(List<Flow> _allFlows, List<FlowOperation> _allflowoper
}

break;

//中间执行器和脚本节点
case "bpmn:Task":
{
var step = peroperation.Step + 1;
Expand Down Expand Up @@ -287,6 +291,7 @@ public async Task Process(List<Flow> _allFlows, List<FlowOperation> _allflowoper
{
try
{
//执行器入口 Input上一个节点向当前节点的传参,DeviceId设备编号,ExecutorConfig当前节点在设计时的配置内容
var result = await executor.ExecuteAsync(new TaskActionInput()
{
Input = taskoperation.Data,
Expand Down Expand Up @@ -498,7 +503,7 @@ public async Task Process(List<Flow> _allFlows, List<FlowOperation> _allflowoper
}

break;

//结束节点
case "bpmn:EndEvent":


Expand Down Expand Up @@ -548,16 +553,25 @@ public async Task Process(List<Flow> _allFlows, List<FlowOperation> _allflowoper
}
}
}

/// <summary>
/// 调用规则引擎,判断当前节点后的连线中的规则是否通过校验,如果验证为真则返回满足条件的线对应的目标节点
/// </summary>
/// <param name="_allFlows">所有的节点</param>
/// <param name="flowId">当前节点</param>
/// <param name="data">进入到当前节点的数据传参</param>
/// <returns></returns>
public async Task<List<Flow>> ProcessCondition(List<Flow> _allFlows, Guid flowId, object data)
{

var tt = data.GetType();
var emptyflow = new List<Flow>();
//根据节点Id获取节点信息
var flow = _allFlows.FirstOrDefault(c => c.FlowId == flowId);
if (flow != null)
{
//根据节点Id获取到当前节点与以后节点的线对象列表(一个节点可以存在很多线对象关联到下一级节点)
var flows = _allFlows.Where(c => c.SourceId == flow?.bpmnid).ToList();
//没有逻辑的线节点对象
emptyflow = flows.Where(c => c.Conditionexpression == string.Empty|| c.Conditionexpression==null).ToList() ?? new List<Flow>();
var tasks = new BaseRuleTask()
{
Expand All @@ -566,7 +580,7 @@ public async Task<List<Flow>> ProcessCondition(List<Flow> _allFlows, Guid flowId
id = flow.bpmnid,
outgoing = new EditableList<BaseRuleFlow>()
};
foreach (var item in flows.Except(emptyflow))
foreach (var item in flows.Except(emptyflow))//排除掉没有逻辑的线节点
{
var rule = new BaseRuleFlow();
rule.id = item.bpmnid;
Expand All @@ -586,11 +600,13 @@ public async Task<List<Flow>> ProcessCondition(List<Flow> _allFlows, Guid flowId
var d = t?.ToObject<ExpandoObject>();
if (d != null)
{
//执行判断,利用规则引擎执行线对象中的规则
var result = await flowExcutor.Excute(new FlowExcuteEntity()
{
Params = d,
Task = tasks,
});
//筛选规则通过的线对象
var next = result.Where(c => c.IsSuccess).ToList();
foreach (var item in next)
{
Expand Down
28 changes: 28 additions & 0 deletions IoTSharp/FlowRuleEngine/SimpleFLowExcutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public class FlowExcuteEntity : IFlowEntity

public class SimpleFlowExcutor : IFlowExcutor<FlowExcuteEntity>
{
/// <summary>
/// 调用规则引擎处理线上的逻辑,判断是否为True,用来判断是否继续进行下一步节点
/// </summary>
/// <param name="Input"></param>
/// <returns></returns>
public async Task<List<RuleResultTree>> Excute(FlowExcuteEntity Input)
{
var mainRules = new Workflow
Expand All @@ -35,7 +40,30 @@ public async Task<List<RuleResultTree>> Excute(FlowExcuteEntity Input)
{
item.Rule.Operator = item.id;
}
//规则集合,可以参考RulesEngine.RulesEngine程序说明,其中需要的很多参数已经写死,只有Expression前端填写,如Age>18
/**
* //定义规则
var var rulesStr = @"[{
""WorkflowName"":""UserInputworkflow"",
""Rules"":[
. {
"RuleName"":"CheckAge"
"ErrorMessage"":""年龄必须大于18岁。"",
""ErrorType"":""Error"",
""RuleExpressionType"":"LambdaExpression"",
""Expression"":""Age > 18""
},
{
""RuleName"" :"CheckIDNoIsEmpty"",
""ErrorMessage”":""身份证号不可以为空."",
""ErrorType"":"Error"",
""RuleExpressionType"":""LambdaExpression"",
""Expression"":""IdNo != null""
}
}]";
**/
mainRules.Rules = Input.Task.outgoing.Select(c => c.Rule).ToList();
//调用规则引擎执行规则判断验证成功就会返回IsSuccess=true
var bre = new RulesEngine.RulesEngine(new[] { mainRules }, null);
return await bre.ExecuteAllRulesAsync(Input.Task.id, Input.Params);
}
Expand Down

0 comments on commit 9b531f3

Please sign in to comment.