1.会签任务
执行监听
流程图
开始任务前置JAVA代码
//获取我的节点
Task task = taskService.createTaskQuery().taskAssignee(loginName).processInstanceId(processInstance.getId()).singleResult();
//将相关变量放入节点本地变量,查询历史各节点信息时使用
taskService.setVariablesLocal(task.getId(), map);
//完成节点
taskService.complete(task.getId(), map);
//因为图中配置了监听器,后面开始进入监听器
执行监听器逻辑代码
流程图中有配置java类的全路径
public class MultInstancesStartListener implements ExecutionListener {
@Override
public void notify(DelegateExecution execution) {
List<String> assigneeList = new ArrayList<>();
assigneeList.add("lj");
assigneeList.add("gw");
assigneeList.add("hmxs");
execution.setVariable("assigneeList", assigneeList);
execution.setVariable("up", 0);
}
}
多实例、任务监听器
流程图-常规–多实例
完成条件:
${nrOfCompletedInstances == nrOfInstances}
存这些变量的表:
act_ru_variable
变量说明:
1.nrOfInstances 实例总数。
2.nrOfCompletedInstances 当前还没有完成的实例 nr是number单词缩写 。
3.loopCounter 已经循环的次数。
4.nrOfActiveInstances 已经完成的实例个数。
流程图-监听器
任务监听器逻辑代码
public class MultInstancesCompleteListener implements TaskListener {
@Override
public void notify(DelegateTask delegateTask) {
DelegateExecution execution = delegateTask.getExecution();
Object type = delegateTask.getVariableLocal("type");
if(type != null){
if(StringUtils.equals(type.toString(), "act_common_approve_001")){
Object up = execution.getVariable("up");
if(up != null){
Integer integer_up = Integer.valueOf(up.toString());
execution.setVariable("up", integer_up+1);
}
}
}
}
}
gateway表达式
批准:
返回:
2.超时非中断
定时边界事件(非中断)
时间格式为 ISO 8601日期格式与持续时间格式
格式说明
3.超时转派
4.定时捕获
.说明
5.子流程调用
调用方
被调用方
6.服务任务流程
调用Java类
流程图配置
Java代码
可以在流程中传递变量
public class ServerListener1 implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {
execution.getProcessDefinitionId();
execution.getProcessInstanceId();
execution.setVariable("name", "ttz");
}
}
public class ServerListener2 implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {
Object name = execution.getVariable("name");
System.err.println(name);
}
}
7.流程回退
流程图配置
创建时候的监听:
监听图配置
创建时候的监听的Java代码
public class TKSetBackParamListener implements TaskListener {
private Expression backMsgKey;
private TaskService taskService = SpringUtils.getBean(TaskService.class);
private RuntimeService runtimeService = SpringUtils.getBean(RuntimeService.class);
private RepositoryService repositoryService = SpringUtils.getBean(RepositoryService.class);
@Override
public void notify(DelegateTask delegateTask) {
String backMsgKey = this.backMsgKey.getValue(delegateTask).toString();
String processInstanceId = delegateTask.getProcessInstanceId();
runtimeService.setVariable(processInstanceId, "backMsgKey", this.backMsgKey.getValue(delegateTask).toString());
}
}
结束时候的监听:
监听图配置
结束时候的监听的Java代码
public class TKOffBackParamListener implements TaskListener {
private RuntimeService runtimeService = SpringUtils.getBean(RuntimeService.class);
@Override
public void notify(DelegateTask delegateTask) {
String processInstanceId = delegateTask.getProcessInstanceId();
this.runtimeService.setVariable(processInstanceId, "backMsgKey", null);
}
}
消息中间事件捕获:
回退Java代码
ProcessInstance processInstance = this.runtimeService.createProcessInstanceQuery()
.processInstanceId(instanceId)
.singleResult();
Object o = runtimeService.getVariable(instanceId, "backMsgKey");
String backMsgKey = "";
if(o != null){
backMsgKey = o.toString();
}
if(StringUtils.isBlank(backMsgKey)){
return AjaxResult.error();
}
Execution execution = this.runtimeService.createExecutionQuery()
.messageEventSubscriptionName(backMsgKey)
.processInstanceId(instanceId)
.singleResult();
this.runtimeService.messageEventReceived(backMsgKey, execution.getId());
回退流程图
8.任务节点监听
create
//完成节点
taskService.complete(task.getId(), map);
后进入监听
public class TKCreateListener implements TaskListener {
private Expression param;
@Override
public void notify(DelegateTask delegateTask) {
System.err.println("Create, param=["+param.getValue(delegateTask).toString()+"]");
}
}
assignment
//检查任务的受理人
taskService.claim(taskId, loginName);
后进入监听
public class TKAssignmentListener implements TaskListener {
private Expression param;
@Override
public void notify(DelegateTask delegateTask) {
System.err.println("Assignment, param=["+param.getValue(delegateTask).toString()+"]");
}
}
complete
taskService.complete(taskId, map);
执行后进入监听
public class TKCompleteListener implements TaskListener {
private Expression param;
@Override
public void notify(DelegateTask delegateTask) {
System.err.println("Complete, param=["+param.getValue(delegateTask).toString()+"]");
}
}
紧接着进入 delete
public class TKDeleteListener implements TaskListener {
private Expression param;
@Override
public void notify(DelegateTask delegateTask) {
System.err.println("Delete, param=["+param.getValue(delegateTask).toString()+"]");
}
}