From e6077ce83df813f3308132c1d74dc559a5830384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=89=BE=E7=AB=B9?= Date: Tue, 27 Jul 2021 21:58:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E7=A8=8B=E5=9B=BE=E5=AE=A1=E6=89=B9?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AIStudio.Wpf.ADiagram.csproj | 1 + .../Demos/Flowchart/FlowchartService.cs | 106 ++++++++++++++---- .../Demos/Flowchart/FlowchartViewModel.cs | 8 +- .../Demos/Flowchart/ViewModels/FlowNode.xaml | 2 +- .../SelectableDesignerItemViewModelBase.cs | 17 ++- 5 files changed, 104 insertions(+), 30 deletions(-) diff --git a/AIStudio.Wpf.ADiagram/AIStudio.Wpf.ADiagram.csproj b/AIStudio.Wpf.ADiagram/AIStudio.Wpf.ADiagram.csproj index 742acc4..93b0d93 100644 --- a/AIStudio.Wpf.ADiagram/AIStudio.Wpf.ADiagram.csproj +++ b/AIStudio.Wpf.ADiagram/AIStudio.Wpf.ADiagram.csproj @@ -128,6 +128,7 @@ + diff --git a/AIStudio.Wpf.ADiagram/Demos/Flowchart/FlowchartService.cs b/AIStudio.Wpf.ADiagram/Demos/Flowchart/FlowchartService.cs index a2a3ddc..30ccad2 100644 --- a/AIStudio.Wpf.ADiagram/Demos/Flowchart/FlowchartService.cs +++ b/AIStudio.Wpf.ADiagram/Demos/Flowchart/FlowchartService.cs @@ -1,11 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Media; using Util.DiagramDesigner; +using Expression = org.mariuszgromada.math.mxparser.Expression; namespace AIStudio.Wpf.ADiagram.Demos.Flowchart { @@ -48,7 +47,9 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart } - + /// + /// 流程数据 + /// public static List FlowNodes { get; set; } @@ -108,7 +109,7 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart nextstep.PreStepId = new List(); nextstep.PreStepId.Add(step.Id.ToString()); } - } + } } var oAStartStep = oASteps.Single(p => p.Kind == NodeKinds.Start); @@ -126,7 +127,7 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart /// - /// 获取下一个节点 + /// 初始化步骤 /// /// /// @@ -161,13 +162,55 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart return outsteps; } + /// + /// 审批动作,因为是客户端模拟,假设每次都是该节点的审批人进行的操作 + /// + /// + /// + /// public static void Approve(FlowNode flowNode, int status, string remark = null) { switch (status) { case 100: + if (flowNode is MiddleFlowNode middleFlowNode) + { + if (string.IsNullOrEmpty(flowNode.Remark)) + { + remark = "审批人:" + remark; + } + else + { + remark = flowNode.Remark + "\r审批人:" + remark; + } + + if (middleFlowNode.ActType == "and")//如果是与签,那么要都审批通过 + { + if (middleFlowNode.UserIds != null && middleFlowNode.UserIds.Count > 1) + { + //实际情况不是这样的,这里只是演示,简化。 + int count = remark.Split("审批人:", StringSplitOptions.RemoveEmptyEntries).Length; + if (middleFlowNode.UserIds.Count != count) + { + SetStatus(flowNode, 1, remark); + return; + } + } + else if (middleFlowNode.RoleIds != null && middleFlowNode.RoleIds.Count > 1) + { + //实际情况不是这样的,这里只是演示,简化。 + int count = remark.Split("审批人:", StringSplitOptions.RemoveEmptyEntries).Length; + if (middleFlowNode.RoleIds.Count != count) + { + SetStatus(flowNode, 1, remark); + return; + } + } + } + + } + SetStatus(flowNode, status, remark); - flowNode.Color = Colors.Green.ToString(); if (!string.IsNullOrEmpty(flowNode.NextStepId)) { Next(flowNode.NextStepId); @@ -180,7 +223,7 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart } } break; - case 2: + case 2: if (Pre(flowNode)) { SetStatus(flowNode, status, remark); @@ -203,6 +246,10 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart } } + /// + /// 流向下一个节点 + /// + /// public static void Next(string stepid) { FlowNode nextNode = FlowNodes.FirstOrDefault(p => p.Id.ToString() == stepid); @@ -210,31 +257,37 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart switch (nextNode.Kind) { - case NodeKinds.Start: - SetStatus(nextNode, 100); - Next(nextNode.NextStepId); + case NodeKinds.Start: + SetStatus(nextNode, 100); + Next(nextNode.NextStepId); break; - case NodeKinds.End: - SetStatus(nextNode, 100); - MessageBox.Show("流程完成"); + case NodeKinds.End: + SetStatus(nextNode, 100); + MessageBox.Show("流程完成"); break; case NodeKinds.Decide: foreach (var step in nextNode.SelectNextStep) { try { - //暂未实现表达式比较 - step.Value.Replace("data.Flag", nextNode.Text); - //先按第一个表达式成立处理。 - SetStatus(nextNode, 100); - Next(step.Key); - break; + //按条件选择一个分支 + string express = step.Value.Replace("data.Flag", nextNode.Text); + Expression e = new Expression(express); + var result = e.calculate(); + if (result == 1) + { + SetStatus(nextNode, 100); + Next(step.Key); + return; + } } catch { } } + //如果表达式错了,就按第一个处理 + Next(nextNode.SelectNextStep.FirstOrDefault().Key); break; case NodeKinds.COBegin: - foreach (var step in nextNode.SelectNextStep) + foreach (var step in nextNode.SelectNextStep)//启动各个分支 { SetStatus(nextNode, 100); Next(step.Key); @@ -244,7 +297,7 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart foreach (var prestep in nextNode.PreStepId) { var step = FlowNodes.FirstOrDefault(p => p.Id.ToString() == prestep); - if (step.Status != 100) + if (step.Status != 100)//如果并行分支没有都完成,那么并行结束节点也未完成 { return; } @@ -255,6 +308,11 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart } } + /// + /// 流向上一个节点 + /// + /// + /// public static bool Pre(FlowNode flowNode) { if (flowNode.PreStepId != null && flowNode.PreStepId.Count == 1) @@ -270,6 +328,12 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart return false; } + /// + /// 设置颜色 + /// + /// + /// + /// public static void SetStatus(FlowNode flowNode, int status, string remark = null) { flowNode.Status = status; diff --git a/AIStudio.Wpf.ADiagram/Demos/Flowchart/FlowchartViewModel.cs b/AIStudio.Wpf.ADiagram/Demos/Flowchart/FlowchartViewModel.cs index c821ad8..6955e22 100644 --- a/AIStudio.Wpf.ADiagram/Demos/Flowchart/FlowchartViewModel.cs +++ b/AIStudio.Wpf.ADiagram/Demos/Flowchart/FlowchartViewModel.cs @@ -39,22 +39,22 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart DesignerItemViewModelBase start = new StartFlowNode() { Left = 100, Top = 0, Color = Colors.Yellow.ToString() }; DiagramViewModel.DirectAddItemCommand.Execute(start); - DesignerItemViewModelBase middle1 = new MiddleFlowNode() { Left = 100, Top = 100, Color = Colors.Yellow.ToString(), Text = "主管审批" }; + DesignerItemViewModelBase middle1 = new MiddleFlowNode() { Left = 100, Top = 100, Color = Colors.Yellow.ToString(), Text = "主管审批", UserIds= new List { "操作员1", "操作员2" }, ActType = "or" }; DiagramViewModel.DirectAddItemCommand.Execute(middle1); DesignerItemViewModelBase decide = new DecideFlowNode() { Left = 100, Top = 200, Color = Colors.Yellow.ToString(), Text = "5" }; DiagramViewModel.DirectAddItemCommand.Execute(decide); - DesignerItemViewModelBase middle2 = new MiddleFlowNode() { Left = 200, Top = 300, Color = Colors.Yellow.ToString(), Text = "分管领导" }; + DesignerItemViewModelBase middle2 = new MiddleFlowNode() { Left = 200, Top = 300, Color = Colors.Yellow.ToString(), Text = "分管领导", UserIds = new List { "操作员1", "操作员2" }, ActType = "and" }; DiagramViewModel.DirectAddItemCommand.Execute(middle2); DesignerItemViewModelBase cobegin = new COBeginFlowNode() { Left = 100, Top = 400, Color = Colors.Yellow.ToString() }; DiagramViewModel.DirectAddItemCommand.Execute(cobegin); - DesignerItemViewModelBase middle3 = new MiddleFlowNode() { Left = 100, Top = 500, Color = Colors.Yellow.ToString(), Text = "财务审批" }; + DesignerItemViewModelBase middle3 = new MiddleFlowNode() { Left = 100, Top = 500, Color = Colors.Yellow.ToString(), Text = "财务审批", UserIds = new List { "Admin" }, ActType = "or" }; DiagramViewModel.DirectAddItemCommand.Execute(middle3); - DesignerItemViewModelBase middle4 = new MiddleFlowNode() { Left = 200, Top = 500, Color = Colors.Yellow.ToString(), Text = "人力审批" }; + DesignerItemViewModelBase middle4 = new MiddleFlowNode() { Left = 200, Top = 500, Color = Colors.Yellow.ToString(), Text = "人力审批", RoleIds = new List { "操作员", "管理员" }, ActType = "or" }; DiagramViewModel.DirectAddItemCommand.Execute(middle4); DesignerItemViewModelBase coend = new COEndFlowNode() { Left = 100, Top = 600, Color = Colors.Yellow.ToString() }; diff --git a/AIStudio.Wpf.ADiagram/Demos/Flowchart/ViewModels/FlowNode.xaml b/AIStudio.Wpf.ADiagram/Demos/Flowchart/ViewModels/FlowNode.xaml index 341f993..5487a52 100644 --- a/AIStudio.Wpf.ADiagram/Demos/Flowchart/ViewModels/FlowNode.xaml +++ b/AIStudio.Wpf.ADiagram/Demos/Flowchart/ViewModels/FlowNode.xaml @@ -45,7 +45,7 @@ - + diff --git a/Util.DiagramDesigner/ViewModels/BaseViewModel/SelectableDesignerItemViewModelBase.cs b/Util.DiagramDesigner/ViewModels/BaseViewModel/SelectableDesignerItemViewModelBase.cs index 3ff4087..64472ec 100644 --- a/Util.DiagramDesigner/ViewModels/BaseViewModel/SelectableDesignerItemViewModelBase.cs +++ b/Util.DiagramDesigner/ViewModels/BaseViewModel/SelectableDesignerItemViewModelBase.cs @@ -209,22 +209,31 @@ namespace Util.DiagramDesigner { get { + var text = _text; + if (OutTextItem != null) + { + text = OutTextItem._text; + } if (FontViewModel.FontCase == FontCase.Upper) { - return _text?.ToUpper(); + return text?.ToUpper(); } else if (FontViewModel.FontCase == FontCase.Lower) { - return _text?.ToLower(); + return text?.ToLower(); } else { - return _text; + return text; } } set { - if (SetProperty(ref _text, value)) + if (OutTextItem != null) + { + OutTextItem.Text = value; + } + else if (SetProperty(ref _text, value)) { if (!string.IsNullOrEmpty(_text)) {