package com.test;
import java.util.List;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.taskmgmt.exe.TaskInstance;
public class Test1 {
//创建config对象(连接数据库)
private static JbpmConfiguration config = JbpmConfiguration.getInstance();
// JbpmConfiguration con=JbpmConfiguration.getInstance();
//创建jbpmContext对象
private static JbpmContext getContext(){
JbpmContext context = config.getCurrentJbpmContext();
if (context==null)
context = config.createJbpmContext();
return context;
}
//创建表(如果表存在就先删除)
public static void createTable(){
config.createSchema();
}
//发布流程(写数据库)
public static void deplydefine(){
//根据xml文件生成流程
ProcessDefinition pd = ProcessDefinition.parseXmlResource("simple/processdefinition.xml");
//发布
getContext().deployProcessDefinition(pd);
getContext().close();
}
//实例化流程
public static void newInstance(String name){
//得到“报帐"的流程定义
ProcessDefinition pd = getContext().getGraphSession().findLatestProcessDefinition("报账");
//创建"流程实例"
ProcessInstance pi = pd.createProcessInstance();
//把创始人保存起来
pi.getContextInstance().setVariable("initId", name);
//发信号,下一步
pi.getRootToken().signal();
getContext().close();
}
//写报销单:谁+报多少+原因
public static void write(String name,Float money,String msg){
//得到自己所有没有完成任务
List<TaskInstance> tis =
getContext().getTaskList(name);
// System.out.println(tis.size()+"");
for (TaskInstance ti:tis){
System.out.println(ti.getName()+"\t"+ti.getActorId());
if (ti.getName().equals("写报销单"))
{
System.out.println(ti.getActorId());
ti.getContextInstance().setVariable("money", money);
ti.getContextInstance().setVariable("msg", msg);
ti.end();//结束
}
}
getContext().close();
}
//部门同意否
public static void agree(int id, boolean f){
//根据编号找任务
TaskInstance ti = getContext().getTaskInstance(id);
if (f)
ti.end("同意");
else
ti.end("不同意");
getContext().close();
}
public static void main(String[] args) {
// getContext();
// createTable();
// deplydefine();
// newInstance("请假");
write("请假",100f,"国庆休假");
// agree(2, false);
}
}