jbpm工作流之简单请假流程例子(源码)

来源:互联网 发布:java初级学生管理系统 编辑:程序博客网 时间:2024/05/10 03:44

1.下载并安装插件

2.创建简单的请假流程图

3.部署

4.发布

5.源码如下

package com.tbg.leave;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.net.ssl.HostnameVerifier;
import org.jbpm.api.Configuration;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.history.HistoryActivityInstance;
import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.api.history.HistoryTask;
import org.jbpm.api.task.Task;
import org.jbpm.test.JbpmTestCase;


public class LeaveMap extends LeaveConfig{
//部署
public void deploy(){
super.startUp();
repositoryService.createDeployment().addResourceFromClasspath("leave.jpdl.xml").deploy();

System.out.println("部署成功");
}
//发布
public void createInstance(){
super.startUp();
Map<String, Object> map=new HashMap<String, Object>();
map.put("owner", "王五");
map.put("day", 6);
map.put("liyou", "有事情回家");
map.put("starttime", "2014-8-09");
map.put("stoptimne", "2014-09-14");
ProcessInstance processInstance=executionService.startProcessInstanceByKey("leave", map);
List<ProcessDefinition> list=repositoryService.createProcessDefinitionQuery().list();
for (ProcessDefinition processDefinition : list) {
System.out.println(processDefinition.getDeploymentId());
}
super.print("流程实例ID", processInstance.getId());
super.print("流程名称", processInstance.getName());
}
//查看所有流程实例
public void lookall(){
super.startUp();
List<ProcessDefinition> processDefinitionList=repositoryService.createProcessDefinitionQuery().list();
for (ProcessDefinition processDefinition : processDefinitionList) {
System.out.println("1:"+processDefinition.getId());
}
   List<ProcessInstance> processInstanceList=executionService.createProcessInstanceQuery().list();
   for (ProcessInstance processInstance : processInstanceList) {
System.out.println("2:"+processInstance.getId());
}
}
//查看结点
public void getCurrectActivity(){
super.startUp();
String currecName=executionService.createProcessInstanceQuery().processInstanceId("leave.400001").uniqueResult().findActiveActivityNames().toString();
//String yuany=executionService.getVariable("leave.290001", "yuany").toString();
System.out.println("当前结点:"+currecName);

}
//查看历史流程
public void gethistory(){
super.startUp();
List<HistoryProcessInstance> historyProcessInstances = historyServcie.createHistoryProcessInstanceQuery().list();
//Set<String> variableNames = historyServcie.getVariableNames("leave.400001");
//System.out.println(variableNames);
//Map map = (Map) historyServcie.getVariables("leave.400001", variableNames);
//System.out.println(map.get("liyou"));
//Map map = (Map) historyServcie.getVariable("leave.400001", "map");
// System.out.println(map.size());
//String day=(String) map.get("day");
//String days=historyServcie.getVariable("leave.400001", "day").toString();
for (HistoryProcessInstance historypro : historyProcessInstances) {
for (HistoryProcessInstance historyProcessInstance : historyProcessInstances) {
//String days=executionService.getVariables("leave.400001","day").toString();
System.out.println("=========================================开始===================================================");
System.out.println("ProcessDefinitionId::" + historyProcessInstance.getProcessDefinitionId());
System.out.println("ProcessInstanceId::" + historyProcessInstance.getProcessInstanceId());
System.out.println("EndActivityName::" + historyProcessInstance.getEndActivityName());
System.out.println("getState::" + historyProcessInstance.getState());
//String taskId = historyProcessInstance.getProcessInstanceId();
Set<String> variableNames = historyServcie.getVariableNames(historyProcessInstance.getProcessInstanceId());
Map map = (Map) historyServcie.getVariables(historyProcessInstance.getProcessInstanceId(), variableNames);
System.out.println(variableNames+"=================环境变量====================");
System.out.println("type:"+map.get("day"));
System.out.println("dollars:"+map.get("owner"));
System.out.println("=========================================结束===================================================");
/*Iterator it = getVariables.entrySet().iterator();
while(it.hasNext()){
Map.Entry m = (Map.Entry)it.next();
System.out.println((m.getKey().toString()+ m.getValue().toString()));
}*/
}

}
}
public void geihistory2(){
List<HistoryActivityInstance>histActInsts=historyServcie.createHistoryActivityInstanceQuery().processDefinitionId("leave").activityName("a").list();
for (HistoryActivityInstance historyActivityInstance : histActInsts) {
System.out.println(historyActivityInstance.getExecutionId());
}
}
//老板查看
public void finboss(){
super.startUp();
List<Task> tasks=taskService.findPersonalTasks("boss");
for (Task task : tasks) {
System.out.println("任务名称:"+task.getActivityName()+"\t"+"任务人员:"+task.getAssignee()+"\t"+"流程实例ID:"+task.getExecutionId()+"\t"+"任务ID:"+task.getId()+"\t"+task.getProgress());
}
}
//提交请假
public void submits(){
super.startUp();
//taskService.completeTask("330001","批准");

taskService.completeTask("420002","批准");
}
//得到信息
public void getmessage(){
super.startUp();
String days=executionService.getVariable("leave.400001","day").toString();
super.print("日期是:", days);
}

}










package com.tgb.jbpm;


import org.jbpm.api.Configuration;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.HistoryService;
import org.jbpm.api.IdentityService;
import org.jbpm.api.ManagementService;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.RepositoryService;
import org.jbpm.api.TaskService;
import junit.framework.TestCase;


public class JnpmTestCase extends TestCase{
protected RepositoryService repositoryService; //部署流程服务

protected ExecutionService executionService; //流程执行服务 

protected TaskService taskService ; //任务服务

protected HistoryService historyServcie; //历史服务

protected ManagementService managermentService; //流程管理服务

protected IdentityService identityService; //身份认证服务



protected void startUp(){
ProcessEngine processEngine =  Configuration.getProcessEngine();
repositoryService = processEngine.getRepositoryService();
executionService = processEngine.getExecutionService();
taskService = processEngine.getTaskService();
historyServcie = processEngine.getHistoryService();
managermentService = processEngine.getManagementService();
identityService = processEngine.getIdentityService();
}

public void print(String name,String value){
System.out.println(name + "=============" + value);
}
}

0 0
原创粉丝点击