前言:当我们创建流程图以后,如何用流程对象运行这个流程呢,activity工作流工作主要使用的实例对象有ProcessInstance,Task,ProcessDefinition,HistoricActivityInstance 对象
以这个流程为例子,用测试用例的方式走完这个流程
启动流程
IdentityService 这个用来定义用户组,用户信息,删除用户等
RuntimeService 执行部署的流程节点
package com.thinkgem.jeesite.modules.oa.actest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.activiti.engine.IdentityService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.thinkgem.jeesite.modules.oa.dao.StandardWorkFlowDao;
public class CardTest {
static ClassPathXmlApplicationContext wac;
private static IdentityService identityService;
private static RuntimeService runtimeService;
static StandardWorkFlowDao standardWorkFlowDao;
private static TaskService taskService;
static{
String[] config = new String[]{"spring-context.xml","spring-context-activiti.xml"};
System.out.println("文件加载中。。。。");
wac = new ClassPathXmlApplicationContext(config);
identityService = wac
.getBean(IdentityService.class);
runtimeService = wac
.getBean(RuntimeService.class);
taskService = wac
.getBean(TaskService.class);
}
/*
* 启动工作流
* **/
@Test
public void startProcess() {
// 角色启动流程
identityService.setAuthenticatedUserId("thinkgem");
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("title", "卡片试流程测试");
//StandardWorkFlow flow = new StandardWorkFlow();
String procDefKey = "hqprocess";
String businessTable = "STANDARD_WORKFLOW";
String businessId = "card001";
ProcessInstance procIns = runtimeService.startProcessInstanceByKey(procDefKey, businessTable+":"+businessId, vars);
System.out.println("procIns:"+procIns);
}
/*
* 会签
* **/
@Test
public void approveProcess() {
// 添加审批通过的意见
//getTaskId:26e20b0ffd344795a10c8f228dadbcdb
//getProcInsId:f613e760050342d899105bdfd9bf4d08
//getComment:[同意] 我的审批测试20191106
//vars:{pass=1}
String taskId = "135666cb999e4e068ed016dbdc9c7194";
String processInstanceId = "884c3042fbad41189945813264369932";
String message = "[同意] 我的审批测试20191108_card";
// 添加审批意见
taskService.addComment(taskId, processInstanceId, message);
// 审批铜鼓
Map<String,Object> var = new HashMap<String,Object>();
var.put("pass", "1");
List<String> childUser = new ArrayList<String>();
childUser.add("zhansan");
childUser.add("lisi");
childUser.add("wanger");
var.put("ChildUserList", childUser);
taskService.complete(taskId, var);
}
/*
* 子流程
* **/
//张三
@Test
public void approveSonFlow() {
String taskId = "6da9cddb71ed409db113976ff2e2a48e";
String processInstanceId = "884c3042fbad41189945813264369932";
String message = "[同意] 我的审批测试20191108_card111";
// 添加审批意见
taskService.addComment(taskId, processInstanceId, message);
// 审批铜鼓
Map<String,Object> var = new HashMap<String,Object>();
taskService.complete(taskId, var);
}
//lisi
@Test
public void approveSonFlow1() {
String taskId = "0aa878316f5c4eda9b7645dc5a28a9bd";
String processInstanceId = "884c3042fbad41189945813264369932";
String message = "[同意] 我的审批测试20191108_card222";
// 添加审批意见
taskService.addComment(taskId, processInstanceId, message);
// 审批铜鼓
Map<String,Object> var = new HashMap<String,Object>();
taskService.complete(taskId, var);
}
//wanger
@Test
public void approveSonFlow2() {
String taskId = "1a9709a8a93e4fa68ec1ed5bda907810";
String processInstanceId = "884c3042fbad41189945813264369932";
String message = "[同意] 我的审批测试20191108_card111";
// 添加审批意见
taskService.addComment(taskId, processInstanceId, message);
// 审批铜鼓
Map<String,Object> var = new HashMap<String,Object>();
taskService.complete(taskId, var);
}
// 初审
@Test
public void completeProcess() {
String taskId = "f81862bc3eee45c9aec7f97dfbe9dbd0";
String processInstanceId = "f613e760050342d899105bdfd9bf4d08";
String message = "[同意] 我的审批测试_初审";
// 添加审批意见
taskService.addComment(taskId, processInstanceId, message);
// 审批铜鼓
Map<String,Object> var = new HashMap<String,Object>();
var.put("pass", "1");
taskService.complete(taskId, var);
}
/*
* 驳回测试
* **/
@Test
public void backFlow() {
String taskId = "e6826f819db64ad39feca21686dc3b06";
String processInstanceId = "d4e6a6828d8c42d8aac33d605b45cbd8";
String message = "[驳回] 驳回测试";
// 添加审批意见
taskService.addComment(taskId, processInstanceId, message);
// 审批铜鼓
Map<String,Object> var = new HashMap<String,Object>();
var.put("pass", "0");
taskService.complete(taskId, var);
}
}