1. 设计流程
2. 启动流程
@Autowired
private RuntimeService runtimeService;
@Autowired
private TaskService taskService;
@Autowired
private IdentityService identityService;
public void startLeaveProcess(){
// 用来设置启动流程的人员ID,引擎会自动把用户ID保存到activiti:initiator中
identityService.setAuthenticatedUserId("lgl");
// 设置流程变量
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("id","111");
// 启动流程
ProcessInstance procIns = runtimeService.startProcessInstanceByKey("process","111", vars);
System.out.println("流程启动:ID="+procIns.getId());
}
3. 查询主管代办任务
TaskQuery todoTaskQuery = taskService.createTaskQuery().taskCandidateGroup("manager")
.includeProcessVariables().active().orderByTaskCreateTime().desc();
// 查询列表
List<Task> todoList = todoTaskQuery.list();
for (Task task : todoList) {
task.getId();
task.getProcessVariables();
System.out.println(task.getTaskDefinitionKey());
}
4. 主管同意或拒绝
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("id","111222");
vars.put("pass",1);
taskService.complete(taskId, vars);