您的位置:首页 > 其它

流程变量的设置与获取

2017-02-14 17:18 218 查看


以上是设计的工作流,如上图中的黑点所示的token一样,在整个流程执行过程中,流程携带的参数放在token的集合中,我们称这样的token叫做流程变量。

// 流程变量的查询与获取,也就是我们在petri网中所说的token变量
// /1.创建流程变量
ProcessEngine process = Configuration.getProcessEngine();
// ****************************************************************
// 设置流程变量的方式一
String name = "报销金额";
int value = 1000;
process.getExecutionService().setVariable("报销流程.60001", name, value);

// 方式二
Map<String, String> map = new HashMap<String, String>();
map.put("报销金额", "500");
map.put("报销量", "20");
process.getExecutionService().setVariables("报销流程.6001", map);

// 方式三 在启动报销流程时设置流程变量
Map<String, Object> map1 = new HashMap<String, Object>();
map1.put("key4", "value4");
map1.put("key5", "value5");
process.getExecutionService().startProcessInstanceByKey("报销流程", map1);

// 方式四 在执行任务时设置流程变量
String taskId = "100004";
Map<String, Object> map2 = new HashMap<String, Object>();
map2.put("key6", "value6");
process.getTaskService().completeTask(taskId, "to task2", map2);
// ****************************************************************
// 获取流程变量
// 方式一:获取単个的流程变量
Set<String> variableNames = process.getExecutionService()
.getVariableNames("报销流程");
for (String na : variableNames) {
Object variable = process.getTaskService().getVariable("报销流程", na);
}
// 方式二:获取批量的流程变量
Set<String> variableNames2 = process.getTaskService().getVariableNames(
taskId);
Map<String, Object> variables = process.getTaskService().getVariables(
taskId, variableNames2);
for (Iterator it = variables.entrySet().iterator(); it.hasNext(); it
.next()) {
Entry<String, Object> next = (Entry<String, Object>) it.next();
String key = next.getKey();
Object object = next.getValue();
}
// ****************************************************************
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: