routine update

This commit is contained in:
yubaolee 2018-03-21 17:36:31 +08:00
parent 33f02fdeec
commit 9edd6930b4
9 changed files with 201 additions and 496 deletions

View File

@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenAuth.App.Flow
namespace OpenAuth.App.Flow
{
public class FlowLine
/// <summary>
/// 流程连线
/// </summary>
public class FlowLine
{
public string id { get; set; }
public string type { get; set; }

View File

@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenAuth.App.Flow
namespace OpenAuth.App.Flow
{
/// <summary>
/// 流程节点
/// </summary>
public class FlowNode
{
public const string START = "start round mix";
@ -18,6 +15,30 @@ namespace OpenAuth.App.Flow
public string type { get; set; }
/// <summary>
/// 节点的附加数据项
/// </summary>
/// <value>The set information.</value>
public Setinfo setInfo { get; set; }
}
public class Setinfo
{
public Nodedesignatedata NodeDesignateData { get; set; }
public string NodeCode { get; set; }
public string NodeName { get; set; }
}
/// <summary>
/// 节点执行人
/// </summary>
public class Nodedesignatedata
{
public string[] users { get; set; }
public string[] role { get; set; }
public string[] org { get; set; }
}
}

View File

@ -1,32 +1,31 @@
using System;
using System.Collections.Generic;
using Infrastructure;
using OpenAuth.Repository.Domain;
namespace OpenAuth.App.Flow
{
public class FlowRuntime
public class FlowRuntime
{
private FlowRuntimeModel _runtimeModel = null;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="schemeContent">流程模板</param>
/// <param name="currentNodeId">当前节点</param>
/// <param name="frmData">表单数据</param>
public FlowRuntime(FlowRuntimeInitModel flowRuntimeInitModel)
/// <param name="instance"></param>
public FlowRuntime(FlowInstance instance)
{
_runtimeModel = new FlowRuntimeModel();
dynamic schemeContentJson = flowRuntimeInitModel.schemeContent.ToJson();//获取工作流模板内容的json对象;
dynamic schemeContentJson = instance.SchemeContent.ToJson();//获取工作流模板内容的json对象;
_runtimeModel.schemeContentJson = schemeContentJson;//模板流程json对象
_runtimeModel.nodeDictionary = GetNodeDictionary(schemeContentJson);//节点集合
_runtimeModel.lineDictionary = GetLineDictionary(schemeContentJson);//线条集合
_runtimeModel.currentNodeId = (flowRuntimeInitModel.currentNodeId == "" ? _runtimeModel.startNodeId : flowRuntimeInitModel.currentNodeId);
_runtimeModel.currentNodeType = GetNodeStatus(_runtimeModel.currentNodeId);
_runtimeModel.frmData = flowRuntimeInitModel.frmData;
// flowRuntimeInitModel.frmData = GetNodeFrmData(getFrmData);
_runtimeModel.nodes = GetNodeDictionary(schemeContentJson);//节点集合
_runtimeModel.lines = GetLineDictionary(schemeContentJson);//线条集合
_runtimeModel.currentNodeId = (instance.ActivityId == "" ? _runtimeModel.startNodeId : instance.ActivityId);
_runtimeModel.currentNodeType = GetNodeType(_runtimeModel.currentNodeId);
//todo:要获取表单数据
// _runtimeModel.frmData = flowRuntimeInitModel.frmData;
if (_runtimeModel.currentNodeType == 0 || _runtimeModel.currentNodeType == 4)
{
@ -35,13 +34,12 @@ namespace OpenAuth.App.Flow
}
else
{
_runtimeModel.nextNodeId = GetNextNode(flowRuntimeInitModel.frmData);//下一个节点
_runtimeModel.nextNodeType = GetNodeStatus(_runtimeModel.nextNodeId);
_runtimeModel.nextNodeId = GetNextNode(_runtimeModel.frmData);//下一个节点
_runtimeModel.nextNodeType = GetNodeType(_runtimeModel.nextNodeId);
}
_runtimeModel.previousId = flowRuntimeInitModel.previousId;
_runtimeModel.flowInstanceId = flowRuntimeInitModel.processId.ToString();
_runtimeModel.previousId = instance.PreviousId;
_runtimeModel.flowInstanceId = instance.Id;
}
@ -51,16 +49,16 @@ namespace OpenAuth.App.Flow
/// </summary>
/// <param name="schemeContentJson"></param>
/// <returns></returns>
private Dictionary<string, dynamic> GetNodeDictionary(dynamic schemeContentJson)
private Dictionary<string, FlowNode> GetNodeDictionary(dynamic schemeContentJson)
{
Dictionary<string, dynamic> nodeDictionary = new Dictionary<string, dynamic>();
Dictionary<string, FlowNode> nodeDictionary = new Dictionary<string, FlowNode>();
foreach (var item in schemeContentJson.Flow.nodes)
{
if (!nodeDictionary.ContainsKey(item.id.Value))
{
nodeDictionary.Add(item.id.Value, item);
}
if (item.type == "startround")
if (item.type == FlowNode.START)
{
this._runtimeModel.startNodeId = item.id.Value;
}
@ -72,15 +70,14 @@ namespace OpenAuth.App.Flow
/// </summary>
/// <param name="schemeContentJson"></param>
/// <returns></returns>
private Dictionary<string, List<dynamic>> GetLineDictionary(dynamic schemeContentJson)
private Dictionary<string, List<FlowLine>> GetLineDictionary(dynamic schemeContentJson)
{
Dictionary<string, List<dynamic>> lineDictionary = new Dictionary<string, List<dynamic>>();
Dictionary<string, List<FlowLine>> lineDictionary = new Dictionary<string, List<FlowLine>>();
foreach (var item in schemeContentJson.Flow.lines)
{
if (!lineDictionary.ContainsKey(item.from.Value))
{
List<dynamic> d = new List<dynamic>();
d.Add(item);
List<FlowLine> d = new List<FlowLine> { item };
lineDictionary.Add(item.from.Value, d);
}
else
@ -95,15 +92,14 @@ namespace OpenAuth.App.Flow
/// </summary>
/// <param name="schemeContentJson"></param>
/// <returns></returns>
private Dictionary<string, List<dynamic>> GetToLineDictionary(dynamic schemeContentJson)
private Dictionary<string, List<FlowLine>> GetToLineDictionary(dynamic schemeContentJson)
{
Dictionary<string, List<dynamic>> lineDictionary = new Dictionary<string, List<dynamic>>();
Dictionary<string, List<FlowLine>> lineDictionary = new Dictionary<string, List<FlowLine>>();
foreach (var item in schemeContentJson.Flow.lines)
{
if (!lineDictionary.ContainsKey(item.to.Value))
{
List<dynamic> d = new List<dynamic>();
d.Add(item);
List<FlowLine> d = new List<FlowLine> { item };
lineDictionary.Add(item.to.Value, d);
}
else
@ -113,153 +109,42 @@ namespace OpenAuth.App.Flow
}
return lineDictionary;
}
/// <summary>
/// 工作流流转条件比较函数
/// </summary>
/// <param name="frmvalue">表单数据</param>
/// <param name="operation"></param>
/// <param name="paramValue"></param>
/// <returns></returns>
private bool LineCompared(string frmvalue, string operation, string paramValue)
{
bool res = false;
switch (operation)
{
case "Equal"://等于
if (decimal.Parse(frmvalue) == decimal.Parse(paramValue))
{
res = true;
}
break;
case "NotEqual"://不等于
if (decimal.Parse(frmvalue) != decimal.Parse(paramValue))
{
res = true;
}
break;
case "Greater"://大于
if (decimal.Parse(frmvalue) > decimal.Parse(paramValue))
{
res = true;
}
break;
case "GreaterThan"://大于等于
if (decimal.Parse(frmvalue) >= decimal.Parse(paramValue))
{
res = true;
}
break;
case "Less"://小于
if (decimal.Parse(frmvalue) < decimal.Parse(paramValue))
{
res = true;
}
break;
case "LessThan"://小于等于
if (decimal.Parse(frmvalue) <= decimal.Parse(paramValue))
{
res = true;
}
break;
case "Null"://为空
if (string.IsNullOrEmpty(frmvalue))
{
res = true;
}
break;
case "NotNull"://不为空
if (!string.IsNullOrEmpty(frmvalue))
{
res = true;
}
break;
case "Like"://包含
if (frmvalue.IndexOf(paramValue) != -1)
{
res = true;
}
break;
case "NotLike"://不包含
if (frmvalue.IndexOf(paramValue) == -1)
{
res = true;
}
break;
}
return res;
}
/// <summary>
/// 获取下一个节点
/// </summary>
/// <param name="frmData">表单数据(用于判断流转条件)</param>
private string GetNextNode(string frmData,string nodeId = null)
private string GetNextNode(string frmData, string nodeId = null)
{
try
List<FlowLine> LineList = null;
if (nodeId == null)
{
List<dynamic> LineList = null;
if (nodeId == null)
{
LineList = runtimeModel.lineDictionary[runtimeModel.currentNodeId];
}
else
{
LineList = runtimeModel.lineDictionary[nodeId];
}
if (LineList.Count == 1)
{
return LineList[0].to.Value;
}
else if (frmData != "")
{
frmData = frmData.ToLower();//统一转小写
var frmDataJson = frmData.ToJObject();//获取数据内容
bool flag = false;
foreach (var item in LineList)//轮训该节点所有连接的线路
{
if (item.setInfo == null)//表示该线路没有设置条件,所以流转到下一个节点
{
return item.to.Value;
}
foreach (var _item in item.setInfo.ConditionValueJson)//轮询该线条上的所有条件
{
if (!string.IsNullOrEmpty(frmDataJson[_item.ParamName.Value.ToLower()].Value))
{
string frmvalue = frmDataJson[_item.ParamName.Value.ToLower()].ToString();
string operation = _item.Operation.Value;
string paramValue = _item.ParamValue.Value;
bool compareValue = LineCompared(frmvalue, operation, paramValue);
LineList = runtimeModel.lines[runtimeModel.currentNodeId];
}
else
{
LineList = runtimeModel.lines[nodeId];
}
if (LineList.Count == 1) //只有一条流程
{
return LineList[0].to;
}
if (_item.Operation.Value == "AND")
{
flag = compareValue;
if (!compareValue)
{
break;
}
}
else
{
if (compareValue)
{
flag = compareValue;
}
}
}
}
if (flag)//如果满足条件,
{
return item.to.Value;
}
}
}
return "-1";//表示寻找不到节点
}
catch
if (frmData != "") //有分支的情况
{
throw;
frmData = frmData.ToLower();//统一转小写
var frmDataJson = frmData.ToJObject();//获取数据内容
bool flag = false;
foreach (var item in LineList)//轮训该节点所有连接的线路
{
return item.to;
}
}
return "-1";//表示寻找不到节点
}
#endregion
@ -276,52 +161,35 @@ namespace OpenAuth.App.Flow
/// 获取实例接下来运行的状态
/// </summary>
/// <returns>-1无法运行,0会签开始,1会签结束,2一般节点,4流程运行结束</returns>
public int GetStatus()
public int GetNextNodeType()
{
if (_runtimeModel.nextNodeId != "-1")
{
if (_runtimeModel.nextNode.type == "shuntnode")//会签开始节点
{
return 0;
}
else if (_runtimeModel.nextNode.type == "confluencenode")//会签结束节点
{
return 1;
}
else if (_runtimeModel.nextNode.type == "endround")//结束节点
{
return 4;
}
else
{
return 2;
}
}
else
{
return -1;
return GetNodeType(_runtimeModel.nextNodeId);
}
return -1;
}
/// <summary>
/// 获取节点类型 0会签开始,1会签结束,2一般节点,开始节点,4流程运行结束
/// </summary>
/// <param name="nodeId"></param>
/// <returns></returns>
public int GetNodeStatus(string nodeId)
public int GetNodeType(string nodeId)
{
if (_runtimeModel.nodeDictionary[nodeId].type == "shuntnode")//会签开始节点
if (_runtimeModel.nodes[nodeId].type == "shuntnode")//会签开始节点
{
return 0;
}
else if (_runtimeModel.nodeDictionary[nodeId].type == "confluencenode")//会签结束节点
else if (_runtimeModel.nodes[nodeId].type == "confluencenode")//会签结束节点
{
return 1;
}
else if (_runtimeModel.nodeDictionary[nodeId].type == "endround")//结束节点
else if (_runtimeModel.nodes[nodeId].type == FlowNode.END)//结束节点
{
return 4;
}
else if (_runtimeModel.nodeDictionary[nodeId].type == "startround")//开始节点
else if (_runtimeModel.nodes[nodeId].type == FlowNode.START)//开始节点
{
return 3;
}
@ -337,23 +205,16 @@ namespace OpenAuth.App.Flow
/// <returns></returns>
public List<string> GetCountersigningNodeIdList(string shuntnodeId)
{
try
List<string> list = new List<string>();
List<FlowLine> listline = _runtimeModel.lines[shuntnodeId];
foreach (var item in listline)
{
List<string> list = new List<string>();
List<dynamic> listline = _runtimeModel.lineDictionary[shuntnodeId];
foreach (var item in listline)
{
list.Add(item.to.Value);
}
return list;
}
catch
{
throw;
list.Add(item.to);
}
return list;
}
/// <summary>
/// 通过节点Id获取下一个节点Id
@ -362,18 +223,11 @@ namespace OpenAuth.App.Flow
/// <returns></returns>
public string GetNextNodeByNodeId(string nodeId)
{
try
{
string frmData = "";
// frmData = GetNodeFrmData(_getFrmData, nodeId);
return GetNextNode(frmData, nodeId);
}
catch
{
throw;
}
string frmData = "";
// frmData = GetNodeFrmData(_getFrmData, nodeId);
return GetNextNode(frmData, nodeId);
}
/// <summary>
/// 节点会签审核
@ -381,7 +235,7 @@ namespace OpenAuth.App.Flow
/// <param name="nodeId"></param>
/// <param name="flag"></param>
/// <returns>-1不通过,1等待,其它通过</returns>
public string NodeConfluence(string nodeId, bool flag,string userId, string description = "")
public string NodeConfluence(string nodeId, bool flag, string userId, string description = "")
{
string res = "-1";
try
@ -398,16 +252,16 @@ namespace OpenAuth.App.Flow
string _nextNodeId = GetNextNodeByNodeId(nodeId);//获取下一个节点
if (_nextNodeId != "-1")
{
Dictionary<string, List<dynamic>> toLines = GetToLineDictionary(_runtimeModel.schemeContentJson);
Dictionary<string, List<FlowLine>> toLines = GetToLineDictionary(_runtimeModel.schemeContentJson);
int allnum = toLines[_nextNodeId].Count;
int i = 0;
foreach (var item in _runtimeModel.schemeContentJson.Flow.nodes)
{
if (item.id.Value == _nextNodeId)
{
if(item.setInfo.NodeConfluenceType.Value == "")//0所有步骤通过 todo:先用空格
if (item.setInfo.NodeConfluenceType.Value == "")//0所有步骤通过 todo:先用空格
{
if(flag)
if (flag)
{
if (item.setInfo.ConfluenceOk == null)
{
@ -429,7 +283,7 @@ namespace OpenAuth.App.Flow
}
}
}
else if(item.setInfo.NodeConfluenceType.Value == "1")//1一个步骤通过即可
else if (item.setInfo.NodeConfluenceType.Value == "1")//1一个步骤通过即可
{
if (flag)
{
@ -510,12 +364,12 @@ namespace OpenAuth.App.Flow
{
MakeTagNode(_nextNodeId, 1, userId);
_runtimeModel.nextNodeId = res;
_runtimeModel.nextNodeType = GetNodeStatus(res);
_runtimeModel.nextNodeType = GetNodeType(res);
}
else
{
_runtimeModel.nextNodeId = _nextNodeId;
_runtimeModel.nextNodeType = GetNodeStatus(_nextNodeId);
_runtimeModel.nextNodeType = GetNodeType(_nextNodeId);
}
return res;
}
@ -546,7 +400,7 @@ namespace OpenAuth.App.Flow
{
try
{
dynamic _node = _runtimeModel.nodeDictionary[nodeId];
dynamic _node = _runtimeModel.nodes[nodeId];
if (_node.setInfo != null)
{
if (_node.setInfo.NodeRejectType.Value == "0")
@ -561,7 +415,7 @@ namespace OpenAuth.App.Flow
{
return _node.setInfo.NodeRejectStep.Value;
}
else
else
{
return "";
}

View File

@ -1,27 +0,0 @@
namespace OpenAuth.App.Flow
{
public class FlowRuntimeInitModel
{
/// <summary>
/// GUID
/// </summary>
public string processId { get; set; }
/// <summary>
/// 工作流模板内容
/// </summary>
public string schemeContent { get; set; }
/// <summary>
/// 当前运行节点(默认开始节点)
/// </summary>
public string currentNodeId { get; set; }
/// <summary>
/// 提交的表单数据
/// </summary>
public string frmData { get; set; }
/// <summary>
/// 上一个节点
/// </summary>
public string previousId { get; set; }
}
}

View File

@ -24,7 +24,7 @@ namespace OpenAuth.App.Flow
/// <summary>
/// 当前节点的对象
/// </summary>
public dynamic currentNode { get { return this.nodeDictionary[this.currentNodeId]; } }
public dynamic currentNode { get { return nodes[currentNodeId]; } }
/// <summary>
/// 下一个节点
/// </summary>
@ -32,11 +32,12 @@ namespace OpenAuth.App.Flow
/// <summary>
/// 下一个节点类型
/// </summary>
/// <value>The type of the next node.</value>
public int nextNodeType { get; set; }
/// <summary>
/// 下一个节点对象
/// </summary>
public FlowNode nextNode { get { return nodeDictionary[this.nextNodeId]; } }
public FlowNode nextNode { get { return nodes[nextNodeId]; } }
/// <summary>
/// 上一个节点
@ -46,11 +47,11 @@ namespace OpenAuth.App.Flow
/// <summary>
/// 实例节点集合
/// </summary>
public Dictionary<string, FlowNode> nodeDictionary { get; set; }
public Dictionary<string, FlowNode> nodes { get; set; }
/// <summary>
/// 流转的线段集合
/// </summary>
public Dictionary<string, List<dynamic>> lineDictionary { get; set; }
public Dictionary<string, List<FlowLine>> lines { get; set; }
/// <summary>
/// 模板json数据

View File

@ -15,99 +15,8 @@ namespace OpenAuth.App
/// </summary>
public class FlowInstanceApp :BaseApp<FlowInstance>
{
#region
/// <summary>
/// 获取实例进程信息实体
/// </summary>
/// <param name="keyVlaue">The key vlaue.</param>
/// <returns>FlowInstance.</returns>
public FlowInstance GetEntity(string keyVlaue)
{
try
{
return UnitWork.FindSingle<FlowInstance>(u =>u.Id == keyVlaue);
}
catch
{
throw;
}
}
#endregion
#region
/// <summary>
/// 存储工作流实例进程(编辑草稿用)
/// </summary>
/// <param name="flowInstance"></param>
/// <param name="wfOperationHistoryEntity"></param>
/// <returns></returns>
public int SaveProcess(string processId, FlowInstance flowInstance, FlowInstanceOperationHistory wfOperationHistoryEntity = null)
{
try
{
if (string.Empty ==(flowInstance.Id))
{
UnitWork.Add(flowInstance);
}
else
{
flowInstance.Id = (processId);
UnitWork.Update(flowInstance);
}
if (wfOperationHistoryEntity != null)
{
wfOperationHistoryEntity.InstanceId = processId;
UnitWork.Add(wfOperationHistoryEntity);
}
UnitWork.Save();
return 1;
}
catch
{
throw;
}
}
/// <summary>
/// 存储工作流实例进程(创建实例进程)
/// </summary>
/// <param name="flowRuntimeModel"></param>
/// <param name="flowInstance"></param>
/// <param name="processOperationHistoryEntity"></param>
/// <returns></returns>
public int SaveProcess(FlowRuntimeModel flowRuntimeModel, FlowInstance flowInstance, FlowInstanceOperationHistory processOperationHistoryEntity, FlowInstanceTransitionHistory processTransitionHistoryEntity)
{
try
{
if (string.Empty == (flowInstance.Id))
{
flowInstance.Id = (string)(flowRuntimeModel.flowInstanceId);
UnitWork.Add(flowInstance);
}
else
{
flowInstance.Id =(flowInstance.Id);
UnitWork.Update(flowInstance);
}
processOperationHistoryEntity.InstanceId = flowInstance.Id;
UnitWork.Add(processOperationHistoryEntity);
if (processTransitionHistoryEntity != null)
{
processTransitionHistoryEntity.InstanceId = flowInstance.Id;
UnitWork.Add(processTransitionHistoryEntity);
}
UnitWork.Save();
return 1;
}
catch
{
throw;
}
}
/// <summary>
/// 存储工作流实例进程(审核驳回重新提交)
/// </summary>
@ -197,82 +106,61 @@ namespace OpenAuth.App
/// <param name="description">备注</param>
/// <param name="frmData">表单数据信息</param>
/// <returns></returns>
public bool CreateInstance(string processId, string schemeInfoId, FlowInstance FlowInstance, string frmData = null)
public bool CreateInstance(FlowInstance flowInstance, string frmData = null)
{
try
if (frmData == null)
{
FlowScheme FlowScheme = UnitWork.FindSingle<FlowScheme>(u => u.Id == schemeInfoId);
FlowRuntimeInitModel flowRuntimeInitModel = new FlowRuntimeInitModel()
{
schemeContent = FlowScheme.SchemeContent,
currentNodeId = "",
frmData = frmData,
processId = processId
};
FlowRuntime wfruntime = null;
if (frmData == null)
{
throw new Exception("自定义表单需要提交表单数据");
}
else
{
wfruntime = new FlowRuntime(flowRuntimeInitModel);
}
var user = AuthUtil.GetCurrentUser();
#region
FlowInstance.ActivityId = wfruntime.runtimeModel.nextNodeId;
FlowInstance.ActivityType = wfruntime.GetStatus();//-1无法运行,0会签开始,1会签结束,2一般节点,4流程运行结束
FlowInstance.ActivityName = wfruntime.runtimeModel.nextNode.name;
FlowInstance.PreviousId = wfruntime.runtimeModel.currentNodeId;
FlowInstance.SchemeType = FlowScheme.SchemeType;
FlowInstance.FrmType = FlowScheme.FrmType;
FlowInstance.Disabled = 0;//正式运行
FlowInstance.CreateUserId = user.User.Id.ToString();
FlowInstance.CreateUserName = user.User.Account;
FlowInstance.MakerList = (wfruntime.GetStatus() != 4 ? GetMakerList(wfruntime) : "");//当前节点可执行的人信息
FlowInstance.IsFinish = (wfruntime.GetStatus() == 4 ? 1 : 0);
FlowInstance.SchemeContent = FlowScheme.SchemeContent;
#endregion
#region
FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory();
processOperationHistoryEntity.Content = "【创建】" + user.User.Name + "创建了一个流程进程【" + FlowInstance.Code + "/" + FlowInstance.CustomName + "】";
#endregion
#region
FlowInstanceTransitionHistory processTransitionHistoryEntity = new FlowInstanceTransitionHistory();
processTransitionHistoryEntity.FromNodeId = wfruntime.runtimeModel.currentNodeId;
processTransitionHistoryEntity.FromNodeName = wfruntime.runtimeModel.currentNode.name.Value;
processTransitionHistoryEntity.FromNodeType = wfruntime.runtimeModel.currentNodeType;
processTransitionHistoryEntity.ToNodeId = wfruntime.runtimeModel.nextNodeId;
processTransitionHistoryEntity.ToNodeName = wfruntime.runtimeModel.nextNode.name;
processTransitionHistoryEntity.ToNodeType = wfruntime.runtimeModel.nextNodeType;
processTransitionHistoryEntity.TransitionSate = 0;
processTransitionHistoryEntity.IsFinish = (processTransitionHistoryEntity.ToNodeType == 4 ? 1 : 0);
#endregion
#region
//List<WFDelegateRecord> delegateRecordEntitylist = GetDelegateRecordList(schemeInfoId, FlowInstance.Code, FlowInstance.CustomName, FlowInstance.MakerList);
//FlowInstance.MakerList += delegateUserList;
#endregion
SaveProcess(wfruntime.runtimeModel, FlowInstance, processOperationHistoryEntity, processTransitionHistoryEntity);
return true;
throw new Exception("自定义表单需要提交表单数据");
}
catch
var wfruntime = new FlowRuntime(flowInstance);
var user = AuthUtil.GetCurrentUser();
#region
flowInstance.ActivityId = wfruntime.runtimeModel.nextNodeId;
flowInstance.ActivityType = wfruntime.GetNextNodeType();//-1无法运行,0会签开始,1会签结束,2一般节点,4流程运行结束
flowInstance.ActivityName = wfruntime.runtimeModel.nextNode.name;
flowInstance.PreviousId = wfruntime.runtimeModel.currentNodeId;
flowInstance.CreateUserId = user.User.Id;
flowInstance.CreateUserName = user.User.Account;
flowInstance.MakerList = (wfruntime.GetNextNodeType() != 4 ? GetMakerList(wfruntime) : "");//当前节点可执行的人信息
flowInstance.IsFinish = (wfruntime.GetNextNodeType() == 4 ? 1 : 0);
#endregion
#region
FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory
{
throw;
}
InstanceId = flowInstance.Id,
Content = "【创建】"
+ user.User.Name
+ "创建了一个流程进程【"
+ flowInstance.Code + "/"
+ flowInstance.CustomName + "】"
};
#endregion
#region
FlowInstanceTransitionHistory processTransitionHistoryEntity = new FlowInstanceTransitionHistory
{
InstanceId = flowInstance.Id,
FromNodeId = wfruntime.runtimeModel.currentNodeId,
FromNodeName = wfruntime.runtimeModel.currentNode.name.Value,
FromNodeType = wfruntime.runtimeModel.currentNodeType,
ToNodeId = wfruntime.runtimeModel.nextNodeId,
ToNodeName = wfruntime.runtimeModel.nextNode.name,
ToNodeType = wfruntime.runtimeModel.nextNodeType,
TransitionSate = 0
};
processTransitionHistoryEntity.IsFinish = (processTransitionHistoryEntity.ToNodeType == 4 ? 1 : 0);
#endregion
UnitWork.Add(flowInstance);
UnitWork.Add(processOperationHistoryEntity);
UnitWork.Add(processTransitionHistoryEntity);
UnitWork.Save();
return true;
}
/// <summary>
@ -286,17 +174,11 @@ namespace OpenAuth.App
try
{
string _sqlstr = "", _dbbaseId = "";
FlowInstance FlowInstance = GetEntity(processId);
FlowInstance FlowInstance = Get(processId);
FlowInstanceOperationHistory FlowInstanceOperationHistory = new FlowInstanceOperationHistory();//操作记录
FlowInstanceTransitionHistory processTransitionHistoryEntity = null;//流转记录
FlowRuntimeInitModel flowRuntimeInitModel = new FlowRuntimeInitModel()
{
currentNodeId = FlowInstance.ActivityId,
previousId = FlowInstance.PreviousId,
processId = processId
};
FlowRuntime wfruntime = new FlowRuntime(flowRuntimeInitModel);
FlowRuntime wfruntime = new FlowRuntime(FlowInstance);
#region
@ -309,10 +191,10 @@ namespace OpenAuth.App
string _makerList = "";
foreach (string item in _nodelist)
{
_makerList = GetMakerList(wfruntime.runtimeModel.nodeDictionary[item], wfruntime.runtimeModel.flowInstanceId);
_makerList = GetMakerList(wfruntime.runtimeModel.nodes[item], wfruntime.runtimeModel.flowInstanceId);
if (_makerList != "-1")
{
var id = AuthUtil.GetCurrentUser().User.Id.ToString();
var id = AuthUtil.GetCurrentUser().User.Id;
foreach (string one in _makerList.Split(','))
{
if (id == one || id.IndexOf(one) != -1)
@ -328,18 +210,17 @@ namespace OpenAuth.App
{
if (flag)
{
FlowInstanceOperationHistory.Content = "【" + "todo name" + "】【" + wfruntime.runtimeModel.nodeDictionary[_VerificationNodeId].name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】同意,备注:" + description;
FlowInstanceOperationHistory.Content = "【" + "todo name" + "】【" + wfruntime.runtimeModel.nodes[_VerificationNodeId].name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】同意,备注:" + description;
}
else
{
FlowInstanceOperationHistory.Content = "【" + "todo name" + "】【" + wfruntime.runtimeModel.nodeDictionary[_VerificationNodeId].name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】不同意,备注:" + description;
FlowInstanceOperationHistory.Content = "【" + "todo name" + "】【" + wfruntime.runtimeModel.nodes[_VerificationNodeId].name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】不同意,备注:" + description;
}
string _Confluenceres = wfruntime.NodeConfluence(_VerificationNodeId, flag, AuthUtil.GetCurrentUser().User.Id.ToString(), description);
string _Confluenceres = wfruntime.NodeConfluence(_VerificationNodeId, flag, AuthUtil.GetCurrentUser().User.Id, description);
var _data = new
{
SchemeContent = wfruntime.runtimeModel.schemeContentJson.ToString(),
frmData = wfruntime.runtimeModel.frmData
SchemeContent = wfruntime.runtimeModel.schemeContentJson.ToString(), wfruntime.runtimeModel.frmData
};
switch (_Confluenceres)
{
@ -390,7 +271,7 @@ namespace OpenAuth.App
{
if (flag)
{
wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, 1, AuthUtil.GetCurrentUser().User.Id.ToString(), description);
wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, 1, AuthUtil.GetCurrentUser().User.Id, description);
FlowInstance.PreviousId = FlowInstance.ActivityId;
FlowInstance.ActivityId = wfruntime.runtimeModel.nextNodeId;
FlowInstance.ActivityType = wfruntime.runtimeModel.nextNodeType;//-1无法运行,0会签开始,1会签结束,2一般节点,4流程运行结束
@ -431,8 +312,7 @@ namespace OpenAuth.App
}
var data = new
{
SchemeContent = wfruntime.runtimeModel.schemeContentJson.ToString(),
frmData = wfruntime.runtimeModel.frmData
SchemeContent = wfruntime.runtimeModel.schemeContentJson.ToString(), wfruntime.runtimeModel.frmData
};
}
#endregion
@ -457,16 +337,11 @@ namespace OpenAuth.App
{
try
{
FlowInstance FlowInstance = GetEntity(processId);
FlowInstanceOperationHistory FlowInstanceOperationHistory = new FlowInstanceOperationHistory();
FlowInstance flowInstance = Get(processId);
FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory();
FlowInstanceTransitionHistory processTransitionHistoryEntity = null;
FlowRuntimeInitModel flowRuntimeInitModel = new FlowRuntimeInitModel()
{
currentNodeId = FlowInstance.ActivityId,
previousId = FlowInstance.PreviousId,
processId = processId
};
FlowRuntime wfruntime = new FlowRuntime(flowRuntimeInitModel);
FlowRuntime wfruntime = new FlowRuntime(flowInstance);
string resnode = "";
@ -479,14 +354,14 @@ namespace OpenAuth.App
resnode = nodeId;
}
wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, 0, AuthUtil.GetUserName(), description);
FlowInstance.IsFinish = 4;//4表示驳回需要申请者重新提交表单
flowInstance.IsFinish = 4;//4表示驳回需要申请者重新提交表单
if (resnode != "")
{
FlowInstance.PreviousId = FlowInstance.ActivityId;
FlowInstance.ActivityId = resnode;
FlowInstance.ActivityType = wfruntime.GetNodeStatus(resnode);//-1无法运行,0会签开始,1会签结束,2一般节点,4流程运行结束
FlowInstance.ActivityName = wfruntime.runtimeModel.nodeDictionary[resnode].name;
FlowInstance.MakerList = GetMakerList(wfruntime.runtimeModel.nodeDictionary[resnode], FlowInstance.PreviousId);//当前节点可执行的人信息
flowInstance.PreviousId = flowInstance.ActivityId;
flowInstance.ActivityId = resnode;
flowInstance.ActivityType = wfruntime.GetNodeType(resnode);//-1无法运行,0会签开始,1会签结束,2一般节点,4流程运行结束
flowInstance.ActivityName = wfruntime.runtimeModel.nodes[resnode].name;
flowInstance.MakerList = GetMakerList(wfruntime.runtimeModel.nodes[resnode], flowInstance.PreviousId);//当前节点可执行的人信息
#region
processTransitionHistoryEntity = new FlowInstanceTransitionHistory();
processTransitionHistoryEntity.FromNodeId = wfruntime.runtimeModel.currentNodeId;
@ -502,11 +377,11 @@ namespace OpenAuth.App
var data = new
{
SchemeContent = wfruntime.runtimeModel.schemeContentJson.ToString(),
frmData = (FlowInstance.FrmType == 0 ? wfruntime.runtimeModel.frmData : null)
frmData = (flowInstance.FrmType == 0 ? wfruntime.runtimeModel.frmData : null)
};
FlowInstanceOperationHistory.Content = "【" + "todo name" + "】【" + wfruntime.runtimeModel.currentNode.name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】驳回,备注:" + description;
flowInstanceOperationHistory.Content = "【" + "todo name" + "】【" + wfruntime.runtimeModel.currentNode.name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】驳回,备注:" + description;
SaveProcess(FlowInstance, FlowInstanceOperationHistory, processTransitionHistoryEntity);
SaveProcess(flowInstance, flowInstanceOperationHistory, processTransitionHistoryEntity);
return true;
}
catch
@ -536,23 +411,20 @@ namespace OpenAuth.App
string _makerList = "";
foreach (string item in _nodelist)
{
_makerList = GetMakerList(wfruntime.runtimeModel.nodeDictionary[item], wfruntime.runtimeModel.flowInstanceId);
_makerList = GetMakerList(wfruntime.runtimeModel.nodes[item], wfruntime.runtimeModel.flowInstanceId);
if (_makerList == "-1")
{
throw (new Exception("无法寻找到会签节点的审核者,请查看流程设计是否有问题!"));
}
else if (_makerList == "1")
if (_makerList == "1")
{
throw (new Exception("会签节点的审核者不能为所有人,请查看流程设计是否有问题!"));
}
else
if (makerList != "")
{
if (makerList != "")
{
makerList += ",";
}
makerList += _makerList;
makerList += ",";
}
makerList += _makerList;
}
}
else
@ -722,19 +594,11 @@ namespace OpenAuth.App
throw;
}
}
public void Add(FlowInstance instance)
{
Repository.Add(instance);
}
public void Update(FlowInstance flowScheme)
{
Repository.Update(u => u.Id == flowScheme.Id, u => new FlowInstance
{
//todo:要修改的
});
Repository.Update(u => u.Id == flowScheme.Id, u => new FlowInstance());
}
public TableData Load(QueryFlowInstanceListReq request)

View File

@ -108,7 +108,6 @@
<Compile Include="CategoryApp.cs" />
<Compile Include="Define.cs" />
<Compile Include="Flow\FlowRuntime.cs" />
<Compile Include="Flow\FlowRuntimeInitModel.cs" />
<Compile Include="Flow\FlowRuntimeModel.cs" />
<Compile Include="Flow\FlowLine.cs" />
<Compile Include="Flow\FlowNode.cs" />

View File

@ -47,8 +47,7 @@ namespace OpenAuth.Mvc.Controllers
{
try
{
App.Add(obj);
App.CreateInstance(obj, null);
}
catch (Exception ex)
{

View File

@ -25,10 +25,7 @@ namespace OpenAuth.UnitTest
[TestMethod]
public void AddProcessInstance()
{
string name = "请假" + DateTime.Now.ToString("yy-mm-dd_HH_mm_ss");
string str ="{\"Code\":\"请病假\",\"CustomName\":\""+name+"\",\"wfLevel1\":\"1\",\"wfLevel2\":\"2\",\"wfLevel3\":\"3\",\"Description\":\"&nbsp;\",\"EnabledMark\":1,\"wfLevel\":\"2\"}";
string frmData ="{\"4fcd4c6f-eb6b-6a6d-eb4e-7948763c5bba\":\"\",\"88061dda-642e-bcdb-909b-cea2bbe5ad69\":\"&nbsp;\"}";
_runApp.CreateInstance(string.Empty, (string)("5f0ca3df-390a-4bd7-aecb-5304bf2d191c"), str.ToObject<FlowInstance>(), frmData);
}
}