前言:
我出现该报错是我在 根据指定的流程定义 ID 启动一个新的流程实例,并在启动时传入一些新的变量值时出现的
// 发起流程实例
ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDef.getId(), newVariables);
我的bomn2.0文件:
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="diagram_Process_1710123622327" targetNamespace="ikun" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
<bpmn2:process id="Process_1710123622327" name="ikun" isExecutable="true">
<bpmn2:startEvent id="Event_14zxk8j" flowable:formKey="key_58a92b83-10f3-4003-be9b-3f43c478bb75" />
<bpmn2:sequenceFlow id="Flow_1sud4do" sourceRef="Event_14zxk8j" targetRef="Activity_1254awb" />
<bpmn2:userTask xmlns:flowable="http://flowable.org/bpmn" id="Activity_1254awb" name="组长审批" flowable:dataType="INITIATOR" flowable:assignee="${approval}" flowable:text="指定上级组长">
<bpmn2:extensionElements>
<flowable:executionListener class="com.inspur.flowable.listener.ExamineGetLeaderListener" event="start" />
</bpmn2:extensionElements>
</bpmn2:userTask>
<bpmn2:sequenceFlow id="Flow_1vhizt3" sourceRef="Activity_1254awb" targetRef="Gateway_0kxtssc" />
<bpmn2:exclusiveGateway id="Gateway_0kxtssc" />
<bpmn2:sequenceFlow id="Flow_04uwvkf" name="组长同意" sourceRef="Gateway_0kxtssc" targetRef="Activity_018x1yl">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${option=='agree'}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:userTask xmlns:flowable="http://flowable.org/bpmn" id="Activity_018x1yl" name="领导审批" flowable:dataType="INITIATOR" flowable:assignee="${approval1}" flowable:text="指定领导审批" />
<bpmn2:exclusiveGateway id="Gateway_1ay5wrw" />
<bpmn2:sequenceFlow id="Flow_0ezv6qv" sourceRef="Activity_018x1yl" targetRef="Gateway_1ay5wrw" />
<bpmn2:sequenceFlow id="Flow_1gb0817" name="领导同意" sourceRef="Gateway_1ay5wrw" targetRef="Activity_0kqo19g">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${option=='agree'}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:serviceTask id="Activity_0kqo19g" name="审批同意" flowable:class="com.inspur.flowable.listener.ExamineAgreeListener" />
<bpmn2:serviceTask id="Activity_0vxr5jv" name="审批拒绝" flowable:class="com.inspur.flowable.listener.ExamineRejectListener" />
<bpmn2:sequenceFlow id="Flow_1ytr4ta" name="组长拒绝" sourceRef="Gateway_0kxtssc" targetRef="Activity_0vxr5jv">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${option=='reject'}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="Flow_0bfixm8" name="领导拒绝" sourceRef="Gateway_1ay5wrw" targetRef="Activity_0vxr5jv">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${option=='reject'}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:endEvent id="Event_0mfhcyf" name="结束">
<bpmn2:extensionElements>
<flowable:executionListener class="com.inspur.flowable.listener.ExamineRevokeProcess" event="start" />
</bpmn2:extensionElements>
</bpmn2:endEvent>
<bpmn2:sequenceFlow id="Flow_0dpu5x9" sourceRef="Activity_0kqo19g" targetRef="Event_0mfhcyf" />
<bpmn2:sequenceFlow id="Flow_1n3zyta" sourceRef="Activity_0vxr5jv" targetRef="Event_0mfhcyf" />
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_Process_1710123622327">
<bpmndi:BPMNPlane id="BPMNPlane_Process_1710123622327" bpmnElement="Process_1710123622327">
</bpmn2:definitions>
我已经将审批人设置成了:${approval} 但是在我启动的时候报错了 就是以上错误
原来 你在启动流程实例的时候 就必须将 approval对应的值放到流程变量里面 才不会报错
我的代码:
Map<String, Object> variables = new HashMap<>();
variables.put("examineId", examineId);
//获取bpmn规则
BpmnModel bpmnModel = repositoryService.getBpmnModel(deploymentId);
List<UserTask> flowElementsOfType = bpmnModel.getMainProcess().findFlowElementsOfType(UserTask.class);
// 匹配 ${} 格式的表达式
String regex = "\\$\\{(.*?)\\}";
Pattern pattern = Pattern.compile(regex);
SysUser sysUser = SecurityUtils.getLoginUser().getSysUser();
for (UserTask userTask : flowElementsOfType) {
//获取流程图里面设置的表达式或者值
String assignee = userTask.getAssignee();
if (assignee == null) {
// 获取候选用户
assignee = userTask.getCandidateUsers().toString();
}
Matcher matcher = pattern.matcher(assignee);
while (matcher.find()) {
// 获取表达式里面的值 类似${approval}里面的approval
String expressionValue = matcher.group(1);
if (expressionValue.equals(PROJECT_MANAGE.getApproveCode())) {
//处理项目审批节点
handlePROJECT_MANAGEApprove(sysUser, expressionValue, PROJECT_MANAGE.getApproveCode(), variables);
} else if (expressionValue.equals(DEPARTMENT_MANAGER.getApproveCode())) {
//处理部门经理审批节点
handleDEPARTMENT_MANAGERApprove(sysUser, expressionValue, DEPARTMENT_MANAGER.getApproveCode(), variables);
} else if (expressionValue.equals(SUPERIOR_LEADER.getApproveCode())) {
//处理上级领导审批节点
handleSUPERIOR_LEADERApprove(sysUser, expressionValue, SUPERIOR_LEADER.getApproveCode(), variables);
}
}
}
ProcessInstance processInstance = processService.startProcessByDefId(deploymentId, variables);
在这里 我是根据bpmn文件里面设置的表达式 动态的将审批人信息set到流程变量里面 最后再启动流程实例就行了