欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

activiti获取连线属性

程序员文章站 2022-07-04 20:27:25
...

今天有一个需求,如下图人提问所示


activiti获取连线属性



属性封装如下

//启动流程实例
    public void startProcess(CustomizeProcessVo customizeProcessVo) {
        //基本参数设置
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("customizeProcessVo", customizeProcessVo);
        //启动人不为空
        if (!StringUtils.isEmpty(customizeProcessVo.getApplyUserId().toString())) {
            identityService.setAuthenticatedUserId(customizeProcessVo.getApplyUserId().toString());
            variables.put("currentUserId", customizeProcessVo.getApplyUserId());
            runtimeService.startProcessInstanceByKey(customizeProcessVo.getPdKey(), customizeProcessVo.getBusinessKey(), variables);
        } else {
            runtimeService.startProcessInstanceByKey(customizeProcessVo.getPdKey(), customizeProcessVo.getBusinessKey(), variables);//error:Unknown property used in expression: ${currentUserId} --表示开始一定是发起人
        }
    }

然后下文是如何获取当前任务的连线条件的内容

public Object getSeqConditionByTaskId(String taskId) {
        Object value = null;
        Process process = null;
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        //processDefinitionId 对应表ACT_RE_PROCDEF主键信息
        String processDefinitionId = runtimeService.createProcessInstanceQuery().processInstanceId(//
                taskService.createTaskQuery().taskId(taskId).singleResult().getProcessInstanceId())//
                .singleResult().getProcessDefinitionId();
        CustomizeProcessVo customizeProcessVo = (CustomizeProcessVo) runtimeService.getVariable(task.getExecutionId(), "customizeProcessVo");
        //获取bpmnModel对象
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
        //获取对应key值的process
        for (Process pro : bpmnModel.getProcesses()) {
            if (pro.getId().equals(customizeProcessVo.getPdKey())) {
                process = pro;
            }
        }
        //获取所有的FlowElement信息
        Collection<FlowElement> flowElements = process.getFlowElements();
        for (FlowElement flowElement : flowElements) {
            //如果是任务节点
            if (flowElement instanceof UserTask) {
                UserTask userTask = (UserTask) flowElement;
                //获取入线信息
                List<SequenceFlow> incomingFlows = userTask.getIncomingFlows();
                for (SequenceFlow sequenceFlow : incomingFlows) {
                    if (sequenceFlow.getConditionExpression() != null) {
                        logger.info("连线表达式{}" + sequenceFlow.getName() + "连线名称{}" + sequenceFlow.getConditionExpression() + "连线下一位处理人{}" + sequenceFlow.getTargetRef());
                        for (String key : customizeProcessVo.getInstanceVars().keySet()) {
                            if (sequenceFlow.getConditionExpression().contains(key)) {
                                value = customizeProcessVo.getInstanceVars().get(key);
                                logger.info("用户输入的此节点变量值{}" + value);
                            }
                        }
                    }
                }
            }
        }
        return value;
    }

运行结果日志如下

2018-04-09 20:43:35.230  INFO 17164 --- [nio-2001-exec-3] c.d.s.base.workflow.act.ActService       : 连线表达式{}大于5时连线名称{}${audit>5}连线下一位处理人{}usertask2
2018-04-09 20:43:35.230  INFO 17164 --- [nio-2001-exec-3] c.d.s.base.workflow.act.ActService       : 用户输入的此节点变量值{}6
2018-04-09 20:43:35.230  INFO 17164 --- [nio-2001-exec-3] c.d.s.base.workflow.act.ActService       : 连线表达式{}小于5时连线名称{}${audit<5}连线下一位处理人{}usertask3
2018-04-09 20:43:35.230  INFO 17164 --- [nio-2001-exec-3] c.d.s.base.workflow.act.ActService       : 用户输入的此节点变量值{}6
2018-04-09 20:43:35.230  INFO 17164 --- [nio-2001-exec-3] c.d.s.base.workflow.act.ActService       : 连线表达式{}驳回连线名称{}${outcome=='驳回'}连线下一位处理人{}usertask3
2018-04-09 20:43:35.230  INFO 17164 --- [nio-2001-exec-3] c.d.s.base.workflow.act.ActService       : 连线表达式{}批准连线名称{}${audit=='批准'}连线下一位处理人{}usertask4
2018-04-09 20:43:35.230  INFO 17164 --- [nio-2001-exec-3] c.d.s.base.workflow.act.ActService       : 用户输入的此节点变量值{}6
2018-04-09 20:43:35.230  INFO 17164 --- [nio-2001-exec-3] c.d.s.base.workflow.act.ActService       : 连线表达式{}批准连线名称{}${audit=='批准'}连线下一位处理人{}usertask5
2018-04-09 20:43:35.230  INFO 17164 --- [nio-2001-exec-3] c.d.s.base.workflow.act.ActService       : 用户输入的此节点变量值{}6
2018-04-09 20:43:35.230  INFO 17164 --- [nio-2001-exec-3] c.d.s.base.workflow.act.ActService       : 连线表达式{}批准连线名称{}${audit=='批准'}连线下一位处理人{}usertask5
2018-04-09 20:43:35.230  INFO 17164 --- [nio-2001-exec-3] c.d.s.base.workflow.act.ActService       : 用户输入的此节点变量值{}6

方法返回的结果如下

6

bpmn内容如下

<?xml version="1.0" encoding="UTF-8"?>
<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="dyWYprocess" name="test process" isExecutable="true">
    <startEvent id="startevent0" name="开始" activiti:initiator="${currentUserId}"></startEvent>
    <userTask id="usertask1" name="发起人查看" activiti:assignee="${currentUserId}"></userTask>
    <sequenceFlow id="flow1" sourceRef="startevent0" targetRef="usertask1"></sequenceFlow>
    <userTask id="usertask2" name="德莱文(人)" activiti:assignee="SP1U158"></userTask>
    <sequenceFlow id="flow2" name="大于5时" sourceRef="exclusivegateway1" targetRef="usertask2">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${audit>5}]]></conditionExpression>
    </sequenceFlow>
    <userTask id="usertask3" name="诸葛亮(人)" activiti:assignee="SP1U161"></userTask>
    <sequenceFlow id="flow3" name="小于5时" sourceRef="exclusivegateway1" targetRef="usertask3">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${audit<5}]]></conditionExpression>
    </sequenceFlow>
    <userTask id="usertask4" name="(云寓)部门" activiti:assignee="SP1D1"></userTask>
    <sequenceFlow id="flow4" name="批准" sourceRef="usertask2" targetRef="usertask4">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${audit=='批准'}]]></conditionExpression>
    </sequenceFlow>
    <userTask id="usertask5" name="(角色)总裁" activiti:assignee="SP1R12"></userTask>
    <sequenceFlow id="flow5" name="批准" sourceRef="usertask4" targetRef="usertask5">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${audit=='批准'}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow6" name="批准" sourceRef="usertask3" targetRef="usertask5">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${audit=='批准'}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow7" name="驳回" sourceRef="usertask5" targetRef="usertask3">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${outcome=='驳回'}]]></conditionExpression>
    </sequenceFlow>
    <endEvent id="endevent0" name="End"></endEvent>
    <sequenceFlow id="flow8" name="批准" sourceRef="usertask5" targetRef="endevent0">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${audit=='批准'}]]></conditionExpression>
    </sequenceFlow>
    <endEvent id="endevent2" name="End"></endEvent>
    <sequenceFlow id="flow9" name="拒绝" sourceRef="usertask4" targetRef="endevent2">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${audit=='拒绝'}]]></conditionExpression>
    </sequenceFlow>
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
    <sequenceFlow id="flow10" sourceRef="usertask1" targetRef="exclusivegateway1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_dyWYprocess">
    <bpmndi:BPMNPlane bpmnElement="dyWYprocess" id="BPMNPlane_dyWYprocess">
      <bpmndi:BPMNShape bpmnElement="startevent0" id="BPMNShape_startevent0">
        <omgdc:Bounds height="35.0" width="35.0" x="50.0" y="290.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55.0" width="105.0" x="120.0" y="280.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
        <omgdc:Bounds height="55.0" width="105.0" x="390.0" y="170.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
        <omgdc:Bounds height="55.0" width="105.0" x="390.0" y="360.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4">
        <omgdc:Bounds height="55.0" width="105.0" x="540.0" y="170.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask5" id="BPMNShape_usertask5">
        <omgdc:Bounds height="55.0" width="105.0" x="700.0" y="306.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent0" id="BPMNShape_endevent0">
        <omgdc:Bounds height="35.0" width="35.0" x="850.0" y="316.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent2" id="BPMNShape_endevent2">
        <omgdc:Bounds height="35.0" width="35.0" x="690.0" y="180.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
        <omgdc:Bounds height="40.0" width="40.0" x="270.0" y="288.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="85.0" y="307.0"></omgdi:waypoint>
        <omgdi:waypoint x="120.0" y="307.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="290.0" y="288.0"></omgdi:waypoint>
        <omgdi:waypoint x="290.0" y="197.0"></omgdi:waypoint>
        <omgdi:waypoint x="390.0" y="197.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="16.0" width="55.0" x="290.0" y="249.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="290.0" y="328.0"></omgdi:waypoint>
        <omgdi:waypoint x="289.0" y="387.0"></omgdi:waypoint>
        <omgdi:waypoint x="390.0" y="387.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="16.0" width="55.0" x="290.0" y="328.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="495.0" y="197.0"></omgdi:waypoint>
        <omgdi:waypoint x="540.0" y="197.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="16.0" width="32.0" x="495.0" y="197.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="592.0" y="225.0"></omgdi:waypoint>
        <omgdi:waypoint x="752.0" y="306.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="16.0" width="32.0" x="625.0" y="275.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
        <omgdi:waypoint x="495.0" y="387.0"></omgdi:waypoint>
        <omgdi:waypoint x="752.0" y="361.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="16.0" width="32.0" x="570.0" y="369.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
        <omgdi:waypoint x="752.0" y="361.0"></omgdi:waypoint>
        <omgdi:waypoint x="752.0" y="524.0"></omgdi:waypoint>
        <omgdi:waypoint x="442.0" y="524.0"></omgdi:waypoint>
        <omgdi:waypoint x="442.0" y="415.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="16.0" width="32.0" x="543.0" y="509.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
        <omgdi:waypoint x="805.0" y="333.0"></omgdi:waypoint>
        <omgdi:waypoint x="850.0" y="333.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="16.0" width="32.0" x="805.0" y="333.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9">
        <omgdi:waypoint x="645.0" y="197.0"></omgdi:waypoint>
        <omgdi:waypoint x="690.0" y="197.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="16.0" width="32.0" x="645.0" y="197.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
        <omgdi:waypoint x="225.0" y="307.0"></omgdi:waypoint>
        <omgdi:waypoint x="270.0" y="308.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

图bpmn如下

activiti获取连线属性


自定义流程类如下

package com.dy.common.service.vo.workflow;

import com.dy.common.base.result.Pagination;
import com.dy.common.base.validation.*;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Map;

/**
 * Created by Liuyc on 2018/3/24.
 */
public class CustomizeProcessVo implements Serializable {

    /** 自定义流程ID */
    @NotNull(groups = {Update.class, Two.class})
    private Long customizeProcessId;

    /** 服务商ID */
    @NotNull(groups = {Create.class, Update.class, SearchPage.class})
    private Long spId;

    /** 流程类别 */
    @NotNull(groups = {Create.class, Update.class})
    private Short pdType;

    /** 流程名称 */
    private String pdName;

    /** 流程KEY */
    @NotEmpty(groups = {Create.class, Update.class})
    private String pdKey;

    /** 是否首先 */
    private Boolean first;

    /** 自定义流程JSON */
    @NotEmpty(groups = {One.class})
    private String flowJson;

    /*==============================S查询条件S==============================*/
    @NotNull(groups = {SearchPage.class})
    private Pagination page;
    /*==============================E查询条件E==============================*/

    /*==============================S流程启动参数S==============================*/
    /** 业务主键(如合同ID、物业合同ID、工作联系单ID,格式:CONTRACT_{id}、PROPERTY_CONTRACT_{id}、WORKSHEET_{id}) */
    @NotEmpty(groups = {Two.class})
    private String businessKey;

    /** 发起人用户ID */
    @NotNull(groups = {Two.class})
    private Long applyUserId;

    /** 实例启动变量 */
    private Map<String, Object> instanceVars;
    /*==============================S流程启动参数S==============================*/

    public Long getCustomizeProcessId() {
        return customizeProcessId;
    }

    public void setCustomizeProcessId(Long customizeProcessId) {
        this.customizeProcessId = customizeProcessId;
    }

    public Long getSpId() {
        return spId;
    }

    public void setSpId(Long spId) {
        this.spId = spId;
    }

    public Short getPdType() {
        return pdType;
    }

    public void setPdType(Short pdType) {
        this.pdType = pdType;
    }

    public String getPdName() {
        return pdName;
    }

    public void setPdName(String pdName) {
        this.pdName = pdName;
    }

    public String getPdKey() {
        return pdKey;
    }

    public void setPdKey(String pdKey) {
        this.pdKey = pdKey;
    }

    public Boolean getFirst() {
        return first;
    }

    public void setFirst(Boolean first) {
        this.first = first;
    }

    public String getFlowJson() {
        return flowJson;
    }

    public void setFlowJson(String flowJson) {
        this.flowJson = flowJson;
    }

    public Pagination getPage() {
        return page;
    }

    public void setPage(Pagination page) {
        this.page = page;
    }

    public String getBusinessKey() {
        return businessKey;
    }

    public void setBusinessKey(String businessKey) {
        this.businessKey = businessKey;
    }

    public Long getApplyUserId() {
        return applyUserId;
    }

    public void setApplyUserId(Long applyUserId) {
        this.applyUserId = applyUserId;
    }

    public Map<String, Object> getInstanceVars() {
        return instanceVars;
    }

    public void setInstanceVars(Map<String, Object> instanceVars) {
        this.instanceVars = instanceVars;
    }
}

相关标签: bpmn工作流