Camunda流程设计器

2023-12-21  本文已影响0人  追风还是少年

Camunda Modeler设计器变量使用el表达式,如:${}

事件

image.png

开始事件:

    public String startProcess(StartProcessBo startProcessBo) {
        identityService.setAuthenticatedUserId(startProcessBo.getUserId());
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(
                startProcessBo.getDefinitionKey(),
                startProcessBo.getBusinessKey(),
                startProcessBo.getVariables()
        );
        return processInstance.getProcessInstanceId();
    }

User Task

image.png

send task

image.png

(1)在同一流程定义中发送消息

@Slf4j
@Component("sendMessage")
public class SendMessage implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) throws Exception {
        execution.getProcessEngineServices().getRuntimeService()
                .createMessageCorrelation("messageName").processInstanceBusinessKey(execution.getBusinessKey()).correlate();
    }
}

(2)一个流程定义发送消息,另一个流程定义接收消息
启动流程

public class Test{
StartProcessBo startProcessBo = new StartProcessBo();     
startProcessBo.setBusinessKey(String.valueOf(carOrderCollectDetect.getOrderCollectId()));
startProcessBo.setDefinitionKey(carDetectDefinitionKey);
VariableMap variableMap = Variables.createVariables();
variableMap.put("test","test");
bpmFormService.startProcess(startProcessBo);
}
@Slf4j
@Component("sendMessageHandler")
public class SendMessageHandler implements JavaDelegate {

    @Override
    public void execute(DelegateExecution execution) throws Exception {

        execution.getProcessEngineServices().getRuntimeService()
                .createMessageCorrelation("messageName").processInstanceBusinessKey(execution.getBusinessKey()).correlate();

    }
}

会签

同一个审批节点,需要多个人审批:

${nrOfInstances == nrOfCompletedInstances}

${nrOfCompletedInstances == nrOfInstances || !approve }

runtimeService.createProcessInstanceModification(processInstanceId)
                .startBeforeActivity(activityId)
                .setVariable("user",user)
                .execute();

nrOfInstances 实例的数目
nrOfCompletedInstances 完成实例的数目
nrOfActiveInstances 未完成实例的数目
loopCounter 循环计数器,办理人在列表中的索引。

事务

默认是同步调用,service task 抛出异常会回滚到上一个user task,如果需要不回滚到上一个user task,需要配置service task 为异步延续,只要就只回滚当前service task

上一篇下一篇

猜你喜欢

热点阅读