赞
踩
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.1.9.RELEASE</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <groupId>com.mk</groupId>
- <artifactId>flowable</artifactId>
- <version>1.0-SNAPSHOT</version>
- <name>flowable</name>
- <description>flowable</description>
-
- <properties>
- <java.version>1.8</java.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>druid-spring-boot-starter</artifactId>
- <version>1.1.20</version>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>org.mybatis.spring.boot</groupId>
- <artifactId>mybatis-spring-boot-starter</artifactId>
- <version>2.1.0</version>
- </dependency>
- <dependency>
- <groupId>org.flowable</groupId>
- <artifactId>flowable-spring-boot-starter</artifactId>
- <version>6.5.0</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-devtools</artifactId>
- <scope>runtime</scope>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <version>1.3.168</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-
- </project>

application.yml
- spring:
- application:
- name: flowable
- profiles:
- active: dev
- jackson:
- time-zone: GMT+8
- date-format: yyyy-MM-dd HH:mm:ss
- default-property-inclusion: ALWAYS
- datasource:
- type: com.alibaba.druid.pool.DruidDataSource
- driver-class-name: com.mysql.jdbc.Driver
- url: "jdbc:mysql://localhost:3306/flowable?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false"
- username: "root"
- password: "admin"
- druid:
- initial-size: 10
- max-active: 100
- min-idle: 10
- max-wait: 60000
- pool-prepared-statements: true
- max-pool-prepared-statement-per-connection-size: 20
- time-between-eviction-runs-millis: 60000
- min-evictable-idle-time-millis: 300000
- validation-query: SELECT 1 FROM DUAL
- test-while-idle: true
- test-on-borrow: false
- test-on-return: false
- filter:
- stat:
- log-slow-sql: true
- slow-sql-millis: 1000
- merge-sql: true
- enabled: true
- wall:
- config:
- multi-statement-allow: true
- stat-view-servlet:
- enabled: true
- servlet:
- multipart:
- max-file-size: 10MB
- max-request-size: 10MB
- mvc:
- date-format: yyyy-MM-dd HH:mm:ss
-
- server:
- port: 8008
-
- mybatis:
- mapper-locations: classpath*:mapper/*.xml
- type-aliases-package: com.mk.flowable.entity
- configuration:
- map-underscore-to-camel-case: true
- configuration-properties:
- prefix:
- blobType: BLOB
- boolValue: TRUE

- package com.mk.flowable.service;
-
- import org.apache.commons.lang3.StringUtils;
- import org.flowable.bpmn.model.BpmnModel;
- import org.flowable.bpmn.model.EndEvent;
- import org.flowable.bpmn.model.FlowElement;
- import org.flowable.common.engine.impl.identity.Authentication;
- import org.flowable.engine.HistoryService;
- import org.flowable.engine.RepositoryService;
- import org.flowable.engine.RuntimeService;
- import org.flowable.engine.TaskService;
- import org.flowable.engine.runtime.ProcessInstance;
- import org.flowable.identitylink.api.IdentityLinkInfo;
- import org.flowable.task.api.Task;
- import org.springframework.stereotype.Service;
-
- import javax.annotation.Resource;
- import java.util.*;
- import java.util.stream.Collectors;
-
- @Service
- public class FlowableService {
-
- @Resource
- private TaskService taskService;
-
- @Resource
- private RepositoryService repositoryService;
-
- @Resource
- private RuntimeService runtimeService;
-
- @Resource
- private HistoryService historyService;
-
-
- public ProcessInstance start(String processDefinitionKey, String userId) {
-
- Map<String, Object> variables = new HashMap<>();
- variables.put("userName", userId);
-
- variables.put("_ACTIVITI_SKIP_EXPRESSION_ENABLED", true);//允许执行跳过表达式
- Authentication.setAuthenticatedUserId(userId);
- ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, variables);
- Authentication.setAuthenticatedUserId(null);
-
- return processInstance;
- }
-
- public ProcessInstance get(String processInstanceId){
-
- ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
- return processInstance;
- }
-
- public List<Task> listTask(String processInstanceId) {
- List<org.flowable.task.api.Task> tasks = taskService.createTaskQuery().processInstanceId(processInstanceId).list();
- return tasks;
- }
-
- public Task getTask(String taskId) {
- Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
- return task;
- }
-
- public void complete(String taskId, Map<String, Object> variables) {
-
- taskService.complete(taskId, variables);
- }
-
- public void move(Task task, String activityName) {
-
- runtimeService.createChangeActivityStateBuilder()
- .processInstanceId(task.getProcessInstanceId())
- .moveActivityIdsToSingleActivityId(
- Arrays.asList(task.getTaskDefinitionKey()),
- activityName)
- .changeState();
- }
-
-
- public List<EndEvent> getEnd(String processDefinitionId) {
-
- BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
- List<EndEvent> endEvents = bpmnModel.getProcesses().stream().flatMap(v->v.findFlowElementsOfType(EndEvent.class).stream()).collect(Collectors.toList());
- return endEvents;
- }
-
- public FlowElement getFlowElement(Task task) {
-
- BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
- FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionId());
- return flowElement;
- }
-
-
- public Map<String, Object> getVariables(String taskId) {
-
- Map<String, Object> variables = taskService.getVariables(taskId);
- return variables;
- }
-
- public List<String> getCandidateUsers(String taskId) {
-
- Task task = taskService.createTaskQuery().taskId(taskId).includeIdentityLinks().singleResult();
- List<? extends IdentityLinkInfo> linkInfos = task.getIdentityLinks();
- List<String> candidateUsers = linkInfos.stream().filter(v -> "candidate".equals(v.getType())).map(IdentityLinkInfo::getUserId)
- .filter(StringUtils::isNotBlank).collect(Collectors.toList());
- return candidateUsers;
- }
-
- public List<String> getCandidatGroups(String taskId) {
-
- Task task = taskService.createTaskQuery().taskId(taskId).includeIdentityLinks().singleResult();
- List<? extends IdentityLinkInfo> linkInfos = task.getIdentityLinks();
- List<String> candidateUsers = linkInfos.stream().filter(v -> "candidate".equals(v.getType())).map(IdentityLinkInfo::getGroupId)
- .filter(StringUtils::isNotBlank).collect(Collectors.toList());
- return candidateUsers;
- }
-
-
- }

结束事件监听
- package com.mk.flowable.listener;
-
- import lombok.extern.slf4j.Slf4j;
- import org.flowable.engine.delegate.DelegateExecution;
- import org.flowable.engine.delegate.ExecutionListener;
-
-
-
- @Slf4j
- public class EndListener implements ExecutionListener {
- @Override
- public void notify(DelegateExecution execution) {
-
- }
- }
任务监听
- package com.mk.flowable.listener;
-
- import org.flowable.engine.delegate.TaskListener;
- import org.flowable.task.service.delegate.DelegateTask;
-
- public class FirstTaskListener implements TaskListener {
-
- @Override
- public void notify(DelegateTask delegateTask) {
-
-
-
- }
-
- }
自动节点委托
- package com.mk.flowable.service;
-
- import org.flowable.engine.delegate.DelegateExecution;
- import org.flowable.engine.delegate.JavaDelegate;
-
-
- public class AutoExeService implements JavaDelegate {
-
- public void execute(DelegateExecution execution) {
-
- }
- }
testFlowable.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="testFlowable" name="testFlowable" isExecutable="true">
- <startEvent id="startevent1" name="Start"></startEvent>
- <endEvent id="endevent1" name="End">
- <extensionElements>
- <activiti:executionListener event="end" class="com.mk.flowable.listener.EndListener"></activiti:executionListener>
- </extensionElements>
- </endEvent>
- <serviceTask id="servicetask1" name="Service Task1" activiti:class="com.mk.flowable.service.AutoExeService">
- <documentation>{"data":"es"}</documentation>
- </serviceTask>
- <serviceTask id="servicetask2" name="Service Task2" activiti:class="com.mk.flowable.service.AutoExeService"></serviceTask>
- <serviceTask id="servicetask3" name="Service Task3" activiti:class="com.mk.flowable.service.AutoExeService"></serviceTask>
- <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask0"></sequenceFlow>
- <sequenceFlow id="flow2" sourceRef="servicetask1" targetRef="servicetask2"></sequenceFlow>
- <sequenceFlow id="flow3" sourceRef="servicetask2" targetRef="servicetask3"></sequenceFlow>
- <sequenceFlow id="flow4" sourceRef="servicetask3" targetRef="endevent1"></sequenceFlow>
- <userTask id="usertask0" name="User Task0" activiti:assignee="${userName}"></userTask>
- <sequenceFlow id="flow5" sourceRef="usertask0" targetRef="servicetask1"></sequenceFlow>
- </process>
- <bpmndi:BPMNDiagram id="BPMNDiagram_testFlowable">
- <bpmndi:BPMNPlane bpmnElement="testFlowable" id="BPMNPlane_testFlowable">
- <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
- <omgdc:Bounds height="35.0" width="35.0" x="30.0" y="180.0"></omgdc:Bounds>
- </bpmndi:BPMNShape>
- <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
- <omgdc:Bounds height="35.0" width="35.0" x="730.0" y="180.0"></omgdc:Bounds>
- </bpmndi:BPMNShape>
- <bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
- <omgdc:Bounds height="55.0" width="105.0" x="280.0" y="170.0"></omgdc:Bounds>
- </bpmndi:BPMNShape>
- <bpmndi:BPMNShape bpmnElement="servicetask2" id="BPMNShape_servicetask2">
- <omgdc:Bounds height="55.0" width="105.0" x="430.0" y="170.0"></omgdc:Bounds>
- </bpmndi:BPMNShape>
- <bpmndi:BPMNShape bpmnElement="servicetask3" id="BPMNShape_servicetask3">
- <omgdc:Bounds height="55.0" width="105.0" x="580.0" y="170.0"></omgdc:Bounds>
- </bpmndi:BPMNShape>
- <bpmndi:BPMNShape bpmnElement="usertask0" id="BPMNShape_usertask0">
- <omgdc:Bounds height="55.0" width="105.0" x="120.0" y="170.0"></omgdc:Bounds>
- </bpmndi:BPMNShape>
- <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
- <omgdi:waypoint x="65.0" y="197.0"></omgdi:waypoint>
- <omgdi:waypoint x="120.0" y="197.0"></omgdi:waypoint>
- </bpmndi:BPMNEdge>
- <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
- <omgdi:waypoint x="385.0" y="197.0"></omgdi:waypoint>
- <omgdi:waypoint x="430.0" y="197.0"></omgdi:waypoint>
- </bpmndi:BPMNEdge>
- <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
- <omgdi:waypoint x="535.0" y="197.0"></omgdi:waypoint>
- <omgdi:waypoint x="580.0" y="197.0"></omgdi:waypoint>
- </bpmndi:BPMNEdge>
- <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
- <omgdi:waypoint x="685.0" y="197.0"></omgdi:waypoint>
- <omgdi:waypoint x="730.0" y="197.0"></omgdi:waypoint>
- </bpmndi:BPMNEdge>
- <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
- <omgdi:waypoint x="225.0" y="197.0"></omgdi:waypoint>
- <omgdi:waypoint x="280.0" y="197.0"></omgdi:waypoint>
- </bpmndi:BPMNEdge>
- </bpmndi:BPMNPlane>
- </bpmndi:BPMNDiagram>
- </definitions>

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。