一、画图
申请人Main-config / Assignee:#{username}
第二节点的 部门主管和部门副主管 Candidate users 为#{usernames}
二、部署流程
把.pbmn结尾和.png结尾的两个文件打包成.zip结尾的压缩文件,然后把打包完成的zip文件放到resources资源包下边
//创建流程核心代码
private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//demo1.启动运行进行部署流程
@Test
public void demo1() {
RepositoryService repositoryService = this.processEngine.getRepositoryService();
String name = "请假流程002号文件";
ZipInputStream zipInputStream = new ZipInputStream(this.getClass().getResourceAsStream("/qingjia.zip"));
repositoryService.createDeployment().name(name).addZipInputStream(zipInputStream).deploy();
System.out.println("===========success===========");
}
//demo2.拿到流程定义的key,因为部署流程时没有写死默认的任务处理人,也没有加监听所以这里需要涌动赋值
@Test
public void demo2() {
RuntimeService runtimeService = this.processEngine.getRuntimeService();
String processDefinitionKey = "qingjia";
Map
variables.put("username", "张三");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, variables );
System.out.println(processInstance.getId()+" "+processInstance.getName()+" "+processInstance.getDeploymentId());
}
//demo3.拿到taskid为张三数据的id,为下边节点设置候选人
@Test
public void demo3() {
TaskService taskService = this.processEngine.getTaskService();
String taskId = "65003";
Map
variables.put("usernames", "李四,王五,赵六");
taskService.complete(taskId,variables );
}
//上一步demo3走完时,会在act_ru_task表中产生两条assignee_字段为null的数据接下来demo4这一步是为了给当前的审批人赋值
@Test
public void demo4() {
TaskService taskService = this.processEngine.getTaskService();
String taskId = "57520";
String userId = "王五";
taskService.setAssignee(taskId, userId);
}
//demo4走完后进行demo5,这一步审批通过当前的节点并未下一节点任务处理人赋值
@Test
public void demo5() {
TaskService taskService = this.processEngine.getTaskService();
String taskId = "57520";
Map
variables.put("username", "孙七");
taskService.complete(taskId,variables );
}
//走完demo5时候因为是并行网关,还没有结束,所以还会有一条在act_ru_task表中assignee_字段为null的数据
//这里根据流程实例id查询出还有哪些任务没有完成,并直接审批通过,这样的数据不会报错,在历史表里assignee_依旧为null
@Test
public void demo6() {
TaskService taskService = this.processEngine.getTaskService();
String processInstanceId = "50001";
List
for (Task task : list) {
taskService.complete(task.getId());
}
}
//运行demo7,之前步骤走完,就到了下一个节点,这个节点因为在demo5中走完后已经付完了值,所以拿过他的任务id直接运行整个任务就可以结束
@Test
public void demo7() {
TaskService taskService = this.processEngine.getTaskService();
String taskId = "22518";
taskService.complete(taskId);
}
//demo8查看当前人员待办流程,张三就是当前代办人
@Test
public void demo8() {
TaskService taskService = this.processEngine.getTaskService();
String assignee = "张三";
List
for (Task task : list) {
System.out.println("流程任务id: "+task.getId());
System.out.println("流程实例id: "+task.getProcessInstanceId());
System.out.println("流程任务节点 "+task.getName());
System.out.println("流程任务人: "+task.getAssignee());
System.out.println("====================================");
}
}
//查看获取已办未办结流程,首先取得当前人员已办理完的但流程未结束的流程实例id
@Test
public void demo9(){
HistoryService historyService = this.processEngine.getHistoryService();
List
List
.includeProcessVariables().orderByHistoricTaskInstanceEndTime().desc().list();
}
//查看已办结流程
@Test
public void demo10(){
Set
List
}
//查看流程图,得到当前办理人节点
@Test
public void demo11() {
//获取流程的定义id
String processDefinitionId = "qingjia:1:4";
BpmnModel bpmnModel = this.processEngine.getRepositoryService().getBpmnModel(processDefinitionId);
//设置图片格式
String imageType = "png";
//获取执行实例id
String executionId = "27501";
//获取当前获得节点
List
//封装设置导出模式
InputStream inputStream = this.processEngine.getProcessEngineConfiguration().getProcessDiagramGenerator().generateDiagram(bpmnModel, imageType, highLightedActivities,highLightedActivities, "宋体","宋体",null,1.0);
//设置导出位置
File file = new File("d:/abc.png");
OutputStream outputStream = null;
try {
outputStream = new FileOutputStream(file);
IOUtils.copy(inputStream, outputStream);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
outputStream.close();
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
//activiti抄送,运行test方法后会在act_ru_task 表中出现一条数据,审批通过任务id为:2505 的task后 这条抄送也跟着完成,在act_hi_taskinst 表中根据任务发起人名称可以查询到任务
@Test
public void test(){
TaskService taskService = this.processEngine.getTaskService();
Task newTask = taskService.newTask();
newTask.setName("总经理");
newTask.setAssignee("康熙");
//父任务节点id
newTask.setParentTaskId("2505");
taskService.saveTask(newTask);
System.out.println("==========success============");
}