activiti自定义流程节点

activiti

为满足用户自定义流程,这里采用排他网关将所有流程节点相连接并设置好连线参数,用户可以自行配置每一节点后下一步的参数,达到流程配置的目的

依赖

 
        org.springframework.boot
        spring-boot-starter-parent
        2.1.5.RELEASE
    
    
        UTF-8
        UTF-8
        1.8
    
    
        
            org.springframework.boot
            spring-boot-starter
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.activiti
            activiti-spring-boot-starter-basic
            6.0.0
        
        
            org.activiti
            activiti-bpmn-layout
            6.0.0.RC1
        
        
            org.activiti
            activiti-spring
            6.0.0
        
        
            commons-io
            commons-io
            2.2
        
        
            mysql
            mysql-connector-java
        
    

代码

package com.sws.activiti.controller;

import org.activiti.bpmn.BpmnAutoLayout;
import org.activiti.bpmn.model.*;
import org.activiti.engine.IdentityService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@RestController
@RequestMapping("/activiti")
public class ActivitiController {
    
    @Autowired
    private RuntimeService runtimeService;
    
    @Autowired
    private RepositoryService repositoryService;

    @RequestMapping("/start_activiti")
    public void startActiviti() throws IOException {
        BpmnModel model = new BpmnModel();
        org.activiti.bpmn.model.Process process = new org.activiti.bpmn.model.Process();
        model.addProcess(process);

        String bpmId = "my-process";
        process.setId(bpmId);
        process.addFlowElement(createStartEvent());
//        process.addFlowElement(createUserTask("task1", "First task", "fred"));
//        process.addFlowElement(createUserTask("task2", "Second task", "john"));
        int nodeNum = 7;
        for(int i=1;i

配置

spring.datasource.url=jdbc:mysql://192.168.153.131:3306/activiti?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver


spring.activiti.check-process-definitions=false
spring.activiti.process-definition-location-prefix= classpath:/processes/

取人规则

每个节点配置对应的取人规则,需要在对应的节点上绑定Task监听器来获取人员

  • id

  • rule_cd

  • remote_rule_cd

    • 远程规则cd
  • rule_type

    • every_one
    • user_fix
    • user_apply
    • dept_duty
    • dept_apply
    • dept_fix
    • office_duty
    • office_apply
    • office_fix
  • company_cd

  • user_cd

  • orgn_cd

人员

  • 所有人

    • rule_type
      • every_one
  • 固定人员

    • rule_type
      • user_fix
    • user_cd
      • xxx
  • 提交人

    • rule_type
      • user_apply
  • 责任部门

    • rule_type
      • dept_duty
    • level
      • 3
  • 申报部门

    • rule_type
      • dept_apply
    • level
      • 3
  • 固定部门

    • rule_type
      • dept_fix
    • level
      • 3
    • orgn_cd
      • xxx
  • 责任科室

    • rule_type
      • office_duty
    • level
      • 4
  • 申报科室

    • rule_type
      • office_apply
    • level
      • 4
  • 固定科室

    • rule_type
      • office_fix
    • level
      • 4
    • orgn_cd
      • xxx

流程选取

用户配置多个流程,可以通过juel以及优先级等方法来匹配需要的流程

  • id
  • company_cd
  • process_cd
  • is_default
    • 一个公司仅一个
  • juel
    • 需要解析juel表达式
package com.sws.activiti.controller;

import com.sws.activiti.dto.Factor;
import de.odysseus.el.ExpressionFactoryImpl;
import de.odysseus.el.util.SimpleContext;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.el.ExpressionFactory;
import javax.el.ValueExpression;


@RestController
@RequestMapping("/juel")
public class JuelController {


    @RequestMapping("/test")
    public void testJuel(@RequestBody Factor factor) throws NoSuchMethodException {
        ExpressionFactory factory = new ExpressionFactoryImpl();
        //de.odysseus.el.util provides包提供即时可用的子类ELContext
        //创建上下文对象context
        SimpleContext context = new SimpleContext();
        factory.createValueExpression(context, "#{factor}", Factor.class).setValue(context, factor);
        ValueExpression expr2 = factory.createValueExpression(context, "${factor.level>10 || factor.type==\"xxx\"}", Boolean.class);
        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++");
        System.out.println(expr2.getValue(context).toString());
        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++");
    }
}

        
            de.odysseus.juel
            juel-spi
            2.2.7
        
        
            de.odysseus.juel
            juel-api
            2.2.7
        
        
            de.odysseus.juel
            juel-impl
            2.2.7
        

你可能感兴趣的:(activiti)