activiti学习之设置条件表达式

号外号外:麻烦点击左侧我正在参加博客之星评选,请您投票,给个五星好评,谢谢大家了!!!

1:场景分析

可能存在这样的场景,当一个任务节点处理时,录入了不同的信息,需要流转到不同的任务节点,假设请假如果是同意的话则继续流转到下一个审批人,如果是拒绝的话则直接结束。

2:测试

2.1:流程设计

  • 效果图

activiti学习之设置条件表达式_第1张图片

注意设置了同意的流向作为默认的流向,即当条件都不满足是使用该流向。

activiti学习之设置条件表达式_第2张图片

对应的xml信息如下:

<userTask id="usertask1" name="第一个请假审批" default="agreeFlowId" activiti:assignee="小赵">
    <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">falsemodeler:initiator-can-complete>
    extensionElements>
userTask>

注意其中的default="agreeFlowId"

  • xml

<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
    <process id="csdnUseConditionExpression.bpmn" name="csdnUseConditionExpression.bpmn" isExecutable="true">
        <startEvent id="startevent1" name="Start">startEvent>
        <userTask id="usertask1" name="第一个请假审批" default="agreeFlowId" activiti:assignee="小赵">
            <extensionElements>
                <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">falsemodeler:initiator-can-complete>
            extensionElements>
        userTask>
        <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1">sequenceFlow>
        <userTask id="usertask2" name="第二个请假审批" activiti:assignee="小马">
            <extensionElements>
                <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">falsemodeler:initiator-can-complete>
            extensionElements>
        userTask>
        <sequenceFlow id="agreeFlowId" name="同意" sourceRef="usertask1" targetRef="usertask2">
            <conditionExpression xsi:type="tFormalExpression">conditionExpression>
        sequenceFlow>
        <endEvent id="endevent1" name="End">endEvent>
        <sequenceFlow id="resuseFlowId" name="拒绝" sourceRef="usertask1" targetRef="endevent1">
            <conditionExpression xsi:type="tFormalExpression">conditionExpression>
        sequenceFlow>
        <sequenceFlow id="flow6" sourceRef="usertask2" targetRef="endevent1">sequenceFlow>
    process>
    <bpmndi:BPMNDiagram id="BPMNDiagram_csdnUseConditionExpression.bpmn">
        <bpmndi:BPMNPlane bpmnElement="csdnUseConditionExpression.bpmn" id="BPMNPlane_csdnUseConditionExpression.bpmn">
            <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
                <omgdc:Bounds height="35.0" width="35.0" x="190.0" y="270.0">omgdc:Bounds>
            bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
                <omgdc:Bounds height="55.0" width="105.0" x="400.0" y="260.0">omgdc:Bounds>
            bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
                <omgdc:Bounds height="55.0" width="105.0" x="710.0" y="190.0">omgdc:Bounds>
            bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
                <omgdc:Bounds height="35.0" width="35.0" x="745.0" y="340.0">omgdc:Bounds>
            bpmndi:BPMNShape>
            <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
                <omgdi:waypoint x="225.0" y="287.0">omgdi:waypoint>
                <omgdi:waypoint x="400.0" y="287.0">omgdi:waypoint>
            bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="agreeFlowId" id="BPMNEdge_agreeFlowId">
                <omgdi:waypoint x="452.0" y="260.0">omgdi:waypoint>
                <omgdi:waypoint x="762.0" y="245.0">omgdi:waypoint>
                <bpmndi:BPMNLabel>
                    <omgdc:Bounds height="14.0" width="100.0" x="497.0" y="229.0">omgdc:Bounds>
                bpmndi:BPMNLabel>
            bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="resuseFlowId" id="BPMNEdge_resuseFlowId">
                <omgdi:waypoint x="452.0" y="315.0">omgdi:waypoint>
                <omgdi:waypoint x="762.0" y="340.0">omgdi:waypoint>
                <bpmndi:BPMNLabel>
                    <omgdc:Bounds height="14.0" width="100.0" x="537.0" y="343.0">omgdc:Bounds>
                bpmndi:BPMNLabel>
            bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
                <omgdi:waypoint x="762.0" y="245.0">omgdi:waypoint>
                <omgdi:waypoint x="762.0" y="340.0">omgdi:waypoint>
            bpmndi:BPMNEdge>
        bpmndi:BPMNPlane>
    bpmndi:BPMNDiagram>
definitions>

2.2:部署

/**
 * 部署流程定义
 */
@Test
public void deploy() {
    Deployment deployment = repositoryService.createDeployment() // 创建部署
            .addClasspathResource("com/jh/activiti/csdnUseConditionExpression.bpmn20.xml") // 加载流程资源文件
            .name("csdn测试使用条件表达式") // 流程名称
            .deploy(); // 部署
    System.out.println("流程部署ID:" + deployment.getId());
    System.out.println("流程部署Name:" + deployment.getName());
}

activiti学习之设置条件表达式_第3张图片

在这里插入图片描述

2.3:启动流程实例

// 启动流程实例
@Test
public void startInstance() {
    runtimeService.startProcessInstanceByKey("csdnUseConditionExpression.bpmn");
}

在这里插入图片描述

在这里插入图片描述

2.4:完成任务并满足resuseFlowId

此时程序直接结束。

@Test
public void complete() {
    Map<String, Object> variablesMap = new HashMap<>();
    variablesMap.put("msg", "拒绝");
    taskService.complete("817506", variablesMap);
}

在这里插入图片描述

其他情况可以自行测试。

你可能感兴趣的:(activiti,activiti,条件表达式)