activiti6官方示例笔记

概述

要想学习 activiti工作流, 入门便是学习官方的示例。下边我将基于官方的 demo 做一遍流程,考虑自己的业务该如何基于 activiti 设计逻辑。

工作流要素:

  • 流程
  • 表单
  • 用户

有了以上 3 大要素,流程便可以流转。

  • 表单绑定在流程节点上,用来输入当前流程信息
  • 用户绑定在流程节点上,用来处理当前流程任务

下载安装

首先到 官方 下载 activiti6.0.0。

activiti7 感兴趣的可以看 这里

activiti6官方示例笔记_第1张图片

然后将 war 包置于 tomcat/webapps 目录下,启动 tomcat 即可。

应用 说明 地址 帐号/密码
activiti-app 流程、表单、用户、发布、任务... http://localhost:8080/activiti-app admin/test
activiti-admin 平台管理查看流程平台运行详情 http://localhost:8080/activiti-admin admin/admin
activiti-rest rest-api 接口应用 http://localhost:8080/activiti-rest kermit/kermit

用户管理

登录 http://localhost:8080/activit...

activiti6官方示例笔记_第2张图片

  • Kickstart App:主要用于流程模型管理、表单管理及应用(App)管理,一个应用可以包含多个流程模型,应用可发布给其他用户使用。
  • Task App:用于管理整个 activiti-app 的任务,在该功能里面也可以启动流程
  • Idenity management:身份信息管理,可以管理用户、用户组等数据

创建用户

activiti6官方示例笔记_第3张图片

创建过程如下,注意 id 即是登录帐号。依次分别创建 3 个帐号用户审批流程。

activiti6官方示例笔记_第4张图片

流程定义

在主界面点击 Kickstart App 进入流程定义页面。

activiti6官方示例笔记_第5张图片

activiti6官方示例笔记_第6张图片

activiti6官方示例笔记_第7张图片

上图中模拟了一个请假流程,但是流程的执行需要人来参与,所以下边我们进行流程和帐号绑定。
选定流程节点后点击 Assignment 属性,会有弹窗进行绑定。

activiti6官方示例笔记_第8张图片

同理,将其他节点进行绑定。然后保存关闭即可,可以看到一个流程已创建完毕。

动态表单

之前的都是基本演示,假设我们需要复杂的表单,那么可以在流程节点上绑定表单即可,这里做下动态表单的基本演示。

  1. 选中流程节点,编辑 Referenced form, 动态创建节点关联表单。

activiti6官方示例笔记_第9张图片

  1. 编辑表单字段

activiti6官方示例笔记_第10张图片

  1. 保存表单

activiti6官方示例笔记_第11张图片

这样在流程中我们就可以通过表单流转复杂的信息了,大家可以实践下,下边的流程就不演示了。

流程发布

activiti6官方示例笔记_第12张图片

将应用和我们之前创建的流程绑定。

activiti6官方示例笔记_第13张图片

activiti6官方示例笔记_第14张图片

然后点击发布流程

activiti6官方示例笔记_第15张图片

发布完成后回到首页可以看到发布结果

activiti6官方示例笔记_第16张图片

流程测试

  1. 登录 zhangsan 帐号创建请假任务

activiti6官方示例笔记_第17张图片

activiti6官方示例笔记_第18张图片

activiti6官方示例笔记_第19张图片

查看流程当前流转状态。

activiti6官方示例笔记_第20张图片

点击 complete, 任务流转到下一个流程节点。

  1. 登录 lisi 审批

activiti6官方示例笔记_第21张图片

activiti6官方示例笔记_第22张图片

  1. 同理,登录 wangwu 审批,流程结束。

activiti6官方示例笔记_第23张图片

流程管理

登录 http://localhost:8080/activit...

配置应用服务节点

activiti6官方示例笔记_第24张图片

配置后即可查看历史流程记录

activiti6官方示例笔记_第25张图片

持久化

tomcat 重启后,activiti 相关的数据会重置,如果想持久化,可以把数据持久化到 MySQL

首先删除 3 个 war 包,避免重启覆盖我们修改的配置

activiti-app 持久化

修改 activiti-app/WEB-INF/classes/META-INF/activiti-app/activiti-app.properties。修改后的配置文件如下(需要手动创建 activiti6ui 库,下边几个项目类似):

#
# SECURITY
#
security.rememberme.key=testkey

#
# DATABASE
#

# datasource.driver=org.h2.Driver
# datasource.url=jdbc:h2:mem:activiti;DB_CLOSE_DELAY=-1

datasource.driver=com.mysql.jdbc.Driver
datasource.url=jdbc:mysql://127.0.0.1:3306/activiti6ui?characterEncoding=UTF-8

datasource.username=root
datasource.password=root

# hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.dialect=org.hibernate.dialect.MySQLDialect
#hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
#hibernate.dialect=org.hibernate.dialect.SQLServerDialect
#hibernate.dialect=org.hibernate.dialect.DB2Dialect
#hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

#
# EMAIL
#

#email.enabled=true
#email.host=localhost
#email.port=1025
#email.useCredentials=false
#email.username=
#email.password=

# The base url that will be used to create urls in emails.
#email.base.url=http://localhost:9999/activiti-app

#[email protected]
#email.from.default.name=Activiti
#[email protected]

#
# ACTIVITI
#

activiti.process-definitions.cache.max=500

#
# DEFAULT ADMINISTRATOR ACCOUNT
#

admin.email=admin
admin.password=test
admin.lastname=Administrator

admin.group=Superusers

# The maximum file upload limit. Set to -1 to set to 'no limit'. Expressed in bytes
file.upload.max.size=104857600

# For development purposes, data folder is created inside the sources ./data folder
contentstorage.fs.rootFolder=data/
contentstorage.fs.createRoot=true
contentstorage.fs.depth=4
contentstorage.fs.blockSize=1024

activiti-admin 持久化

修改 activiti-admin/WEB-INF/classes/META-INF/activiti-admin/activiti-admin.properties。修改后的配置文件如下:

# security configuration (this key should be unique for your application, and kept secret)
security.rememberme.key=activitis3cr3tk3y



# H2 example (default)

#datasource.driver=org.h2.Driver
#datasource.url=jdbc:h2:tcp://localhost/activitiadmin

# MySQL example

datasource.driver=com.mysql.jdbc.Driver
datasource.url=jdbc:mysql://127.0.0.1:3306/activitiadmin?characterEncoding=UTF-8

#datasource.driver=org.postgresql.Driver
#datasource.url=jdbc:postgresql://localhost:5432/activitiadmin

#datasource.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
#datasource.url=jdbc:sqlserver://localhost:1433;databaseName=activitiadmin

#datasource.driver=oracle.jdbc.driver.OracleDriver
#datasource.url=jdbc:oracle:thin:@localhost:1521:ACTIVITIADMIN

#datasource.driver=com.ibm.db2.jcc.DB2Driver
#datasource.url=jdbc:db2://localhost:50000/activitiadmin

datasource.username=root
datasource.password=root

# JNDI CONFIG

# If uncommented, the datasource will be looked up using the configured JNDI name.
# This will have preference over any datasource configuration done below that doesn't use JNDI
#
# Eg for JBoss: java:jboss/datasources/activitiDS
#
#datasource.jndi.name=jdbc/activitiDS

# Set whether the lookup occurs in a J2EE container, i.e. if the prefix "java:comp/env/" needs to be added if the JNDI
# name doesn't already contain it. Default is "true".
#datasource.jndi.resourceRef=true

#hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.dialect=org.hibernate.dialect.MySQLDialect
#hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
#hibernate.dialect=org.hibernate.dialect.SQLServerDialect
#hibernate.dialect=org.hibernate.dialect.DB2Dialect
#hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
#hibernate.show_sql=false
#hibernate.generate_statistics=false

#
# Connection pool (see http://www.mchange.com/projects/c3p0/#configuration)
#

#datasource.min-pool-size=5
#datasource.max-pool-size=100
#datasource.acquire-increment=5
# test query for H2, MySQL, PostgreSQL and Microsoft SQL Server
#datasource.preferred-test-query=select 1
# test query for Oracle
#datasource.preferred-test-query=SELECT 1 FROM DUAL
# test query for DB2
#datasource.preferred-test-query=SELECT current date FROM sysibm.sysdummy1
#datasource.test-connection-on-checkin=true
#datasource.test-connection-on-checkout=true
#datasource.max-idle-time=1800
#datasource.max-idle-time-excess-connections=1800

#
# Cluster settings
#

# This a period of time, expressed in milliseconds, that indicates
# when a node is deemed to be inactive and is removed from the list
# of nodes of a cluster (nor will it appear in the 'monitoring' section of the application).
#
# When a node is properly shut down, it will send out an event indicating
# it is shut down. From that point on, the data will be kept in memory for the amount
# of time indicated here.
# When a node is not properly shut down (eg hardware failure), this is the period of time
# before removal, since the time the last event is received.
#
# Make sure the value here is higher than the sending interval of the nodes, to avoid
# that nodes incorrectly removed.
#
# By default 10 minutes
cluster.monitoring.max.inactive.time=600000

# A cron expression that configures when the check for inactive nodes is made.
# When executed, this will mark any node that hasn't been active for 'cluster.monitoring.max.inactive.time'
# seconds, as an inactive node. Default: every 5 minutes.
cluster.monitoring.inactive.check.cronexpression=0 0/5 * * * ?

# REST endpoint config
rest.app.name=Activiti app
rest.app.description=Activiti app Rest config
rest.app.host=http://localhost
rest.app.port=8080
rest.app.contextroot=activiti-app
rest.app.restroot=api
rest.app.user=admin
rest.app.password=test

# Passwords for rest endpoints and master configs are stored encrypted in the database using AES/CBC/PKCS5PADDING
# It needs a 128-bit initialization vector (http://en.wikipedia.org/wiki/Initialization_vector)
# and a 128-bit secret key represented as 16 ascii characters below
#
# Do note that if these properties are changed after passwords have been saved, all existing passwords
# will not be able to be decrypted and the password would need to be reset in the UI.
security.encryption.credentialsIVSpec=j8kdO2hejA9lKmm6
security.encryption.credentialsSecretSpec=9FGl73ngxcOoJvmL

# BPMN 2.0 Modeler config

modeler.url=https://activiti.alfresco.com/activiti-app/api/

# Enable multi tenant support, disabled by default
#multi-tenant.enabled=true

由于该项目下没有 mysql 驱动包,手动复制 activiti-app/WEB-INF/lib/mysql-connector-java-5.1.30.jaractiviti-admin/WEB-INF/lib 下。

activiti-rest 持久化

修改 activiti-rest/WEB-INF/classes/db.properties, 修改后的配置文件如下:

# db=h2
# jdbc.driver=org.h2.Driver
# jdbc.url=jdbc:h2:mem:activiti;DB_CLOSE_DELAY=-1
# jdbc.username=sa
# jdbc.password=

db=MySQL
datasource.driver=com.mysql.jdbc.Driver
datasource.url=jdbc:mysql://127.0.0.1:3306/activiti6ui?characterEncoding=UTF-8
datasource.username=root
datasource.password=root
hibernate.dialect=org.hibernate.dialect.MySQLDialect

同样,将 activiti-app/WEB-INF/lib/mysql-connector-java-5.1.30.jar 复制到 activiti-rest/WEB-INF/lib

启动 Tomcat, 按照默认 url 和帐号访问 3 个项目即可

最后

官方 activiti6 前端是基于 angular 编写的,UI 也不太符合国人习惯,大家可以基于官方设计重写 UI 即可。欢迎大家关注公众号【当我遇上你】。

你可能感兴趣的:(activiti,工作流)