学习jbpm
根据是视频敲的代码,
jbpm 版本是4.4
如果代码有侵权的话 联系作者。。
嘿嘿。。
先来张 jpdl的图片
这个就是我们要实现的小流程
jbpm 4.4 的环境的配置我 就不截图了
这个就是test.jpdl.xml
代码如下
<?xml version="1.0" encoding="UTF-8"?> <process name="test" key="test" xmlns="http://jbpm.org/4.4/jpdl"> <start name="start1" g="227,67,48,48"> <transition name="提交的科长" to="科长审批" g="-52,-22"/> </start> <task assignee="张三" name="科长审批" g="210,169,92,52"> <transition name="提交到主任" to="主任审批" g="-52,-22"/> </task> <task assignee="李四" name="主任审批" g="207,294,92,52"> <transition name="通过" to="end1" g="-58,-21"/> </task> <end name="end1" g="233,407,48,48"/> </process>
默认的配置:jbpm.cfg.xml
<?xml version="1.0" encoding="UTF-8"?> <jbpm-configuration> <import resource="jbpm.default.cfg.xml" /> <import resource="jbpm.businesscalendar.cfg.xml" /> <import resource="jbpm.tx.hibernate.cfg.xml" /> <import resource="jbpm.jpdl.cfg.xml" /> <import resource="jbpm.bpmn.cfg.xml" /> <import resource="jbpm.identity.cfg.xml" /> <!-- Job executor is excluded for running the example test cases. --> <!-- To enable timers and messages in production use, this should be included. --> <!-- <import resource="jbpm.jobexecutor.cfg.xml" /> --> </jbpm-configuration>
配置与数据库相对应的 jbpm.hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/jbmp ?useUnicode=true&characterEncoding=UTF-8</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">123456</property> <property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.format_sql">true</property> <mapping resource="jbpm.repository.hbm.xml" /> <mapping resource="jbpm.execution.hbm.xml" /> <mapping resource="jbpm.history.hbm.xml" /> <mapping resource="jbpm.task.hbm.xml" /> <mapping resource="jbpm.identity.hbm.xml" /> </session-factory> </hibernate-configuration>
helloword 的代码如下
//部署流程 public void deploy(){ ProcessEngine proEngine=Configuration.getProcessEngine(); RepositoryService repositoryService= proEngine.getRepositoryService(); repositoryService.createDeployment() .addResourceFromClasspath("test.jpdl.xml").deploy(); } //创建流程实例 public void createInstance(){ ProcessEngine processEngine=Configuration.getProcessEngine(); ExecutionService executionService=processEngine.getExecutionService(); ProcessInstance processInstance=executionService.startProcessInstanceByKey("test"); System.out.println("流程实例ID=="+processInstance.getId()); } //获取对应的人员的任务 public void getTask(){ System.out.println("aaa"); ProcessEngine processEngine =Configuration.getProcessEngine() ; TaskService taskService=processEngine.getTaskService(); List<Task> tasks=taskService.findPersonalTasks("张三"); //List<Task> tasks=taskService.findPersonalTasks("李四"); Task task= tasks.get(0); System.out.println("任务数量==="+tasks.size()); System.out.println("任务名词==="+task.getActivityName()); System.out.println("任务人员==="+task.getAssignee()+"任务id=="+task.getId()); } //查询流程实例当前所在的节点 public void getCurrectActivity(){ ProcessEngine processEngine = Configuration.getProcessEngine(); ExecutionService executionService=processEngine.getExecutionService(); String activityName=executionService.createProcessInstanceQuery() .processInstanceId("test.10001").uniqueResult() .findActiveActivityNames().toString(); System.out.println("当前任务所在节点id"+activityName); } //完成任务 public void completeTask(){ ProcessEngine processEngine= Configuration.getProcessEngine(); TaskService taskService=processEngine.getTaskService(); // taskService.completeTask("10002"); 对李三 taskService.completeTask("20001");//对李四 }