Activiti 数据库表结构 | 开发文档 表结构说明
ExecutionListener,TaskListener流程监听 和任务监听 - 码农教程 ExecutionListener,TaskListener流程监听 和任务监听 区别
Activiti User Guide 官网
Activiti7 的基本介绍 - 简书 activiti基本介绍
提交审批
请假流程启动成功实例id::5
ApprovalTaskListener--notify调用
ApprovalTaskListener--findTaskCandidateUsers调用
执行【员工申请】环节,流程推动到【上级审核】环节
流程启动实例id::5
实例id 为5
编辑审批内容参数
{
"processInstanceId": "5",
"submitUserId": "1001",
"remark": "",
"evection": {
"id": null,
"evectionName": "请假申请单",
"num": 2,
"beginDate": null,
"endDate": null,
"destination": null,
"reson": null,
"submitUserId": "1001"
}
}
我的待办列表 同意或驳回{
"processInstanceId": "5",
"auditOpinion": "无意见",
"auditResults": true,
"auditUserId": "1002",
"auditUserRealName": "李四",
"approvalType": ""
}
参数说明
审批通过 、拒绝 (执行 taskService.complete)会优先调监听TaskListener
监听方法
package com.shan.listeners;
import com.shan.utils.ConstantUtils;
import com.shan.utils.SpringContextUtils;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import java.util.Arrays;
import java.util.List;
public class ApprovalTaskListener implements TaskListener {
private static final long serialVersionUID = 1993617150122957396L;
@Override
public void notify(DelegateTask delegateTask) {
System.out.println("ApprovalTaskListener--notify调用:" + delegateTask.getEventName());
//create创建流程时 会获取一级审批人并设置审批人
if (EVENTNAME_CREATE.equals(delegateTask.getEventName())) {
// 获取当前任务节点的审批人
List list = findTaskCandidateUsers(delegateTask);
delegateTask.addCandidateUsers(list);
}
//每次complete时 会更新审批进度 加1
if (EVENTNAME_COMPLETE.equals(delegateTask.getEventName())) {
// 维护审批进度 正常是runtimeService实例 不知道为啥spring容器加载的名称是runtimeServiceBean
RuntimeService runtimeService = SpringContextUtils.getBean("runtimeServiceBean", RuntimeService.class);
Integer approvalProgress = delegateTask.getVariable("approvalProgress", Integer.class);
runtimeService.setVariable(delegateTask.getProcessInstanceId(), "approvalProgress", approvalProgress + 1);
}
}
private List findTaskCandidateUsers(DelegateTask delegateTask) {
System.out.println("ApprovalTaskListener--findTaskCandidateUsers调用");
// 流程图任务节点id
String taskDefinitionKey = delegateTask.getTaskDefinitionKey();
// 获取当前任务节点的审批人
String currentTaskApprover;
if (ConstantUtils.TASK_FIRST.equals(taskDefinitionKey)) {
currentTaskApprover = delegateTask.getVariable("firstApproval", String.class);
} else if (ConstantUtils.TASK_SECOND.equals(taskDefinitionKey)) {
currentTaskApprover = delegateTask.getVariable("secondApproval", String.class);
} else if (ConstantUtils.TASK_THIRD.equals(taskDefinitionKey)) {
currentTaskApprover = delegateTask.getVariable("thirdApproval", String.class);
} else if (ConstantUtils.TASK_FOURTH.equals(taskDefinitionKey)) {
currentTaskApprover = delegateTask.getVariable("fourthApproval", String.class);
} else {
throw new RuntimeException("ERROR");
}
return Arrays.asList(currentTaskApprover.split(","));
}
}
package com.shan.listeners;
import com.shan.service.EvectionService;
import com.shan.utils.ConstantUtils;
import com.shan.utils.SpringContextUtils;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import java.util.HashMap;
import java.util.Map;
public class ApprovalExecutionListener implements ExecutionListener {
private static final long serialVersionUID = -283012834369688647L;
@Override
public void notify(DelegateExecution execution) {
System.out.println("ApprovalExecutionListener审批通过调用notify:" + execution.getEventName());
//审批结束会进此方法 改审通过状态 并调业务方法入库
if ("end".equals(execution.getEventName())) {
System.out.println("ApprovalExecutionListener审批通过调用:" + execution.getEventName());
RuntimeService runtimeService = SpringContextUtils.getBean("runtimeServiceBean", RuntimeService.class);
String processInstanceId = execution.getProcessInstanceId();
// 维护状态值
Map map = new HashMap<>();
map.put("state", ConstantUtils.APPROVAL_STATE[4][0]);
map.put("stateValue", ConstantUtils.APPROVAL_STATE[4][1]);
runtimeService.setVariablesLocal(processInstanceId, map);
String approvalType = runtimeService.getVariable(processInstanceId, "approvalType", String.class);
System.out.println("ApprovalExecutionListener审批通过调用" + processInstanceId);
System.out.println(approvalType);
//保存业务数据EvectionService
EvectionService evectionService = SpringContextUtils.getBean("evectionServiceImpl", EvectionService.class);
evectionService.saveEvection(processInstanceId);
}
}
}
我的已办列表
具体代码就不贴了
解決idea中 actiBPM插件之.bpmn文件中文乱码问题1.修改IDEA编辑器编码为utf8File->Settings->Editor->File Encodings,都改为UTF-8
2.在IDEA安装bin目录下,找到idea.exe.vmoptions和idea64.exe.vmoptions两个文件,打开编辑分别在文本最末端添加下面代码
-Dfile.encoding=UTF-8
3.有人使用了上面的两个方法都无法解决乱码问题,原因在于你并没有改IDEA运行时的vmoptions)
idea路径Help->Edit Custom VM Options
重启idea 即可恢复正常
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)