activiti6官方示例筆記


概述

要想學習 activiti工作流, 入門便是學習官方的示例。下邊我將基於官方的 demo 做一遍流程,考慮自己的業務該如何基於 activiti 設計邏輯。

工作流要素:

  • 流程
  • 表單
  • 用戶

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

  • 表單綁定在流程節點上,用來輸入當前流程信息
  • 用戶綁定在流程節點上,用來處理當前流程任務

下載安裝

首先到 官方 下載 activiti6.0.0。

activiti7 感興趣的可以看 這里

然后將 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/activiti-app/#/

  • Kickstart App:主要用於流程模型管理、表單管理及應用(App)管理,一個應用可以包含多個流程模型,應用可發布給其他用戶使用。
  • Task App:用於管理整個 activiti-app 的任務,在該功能里面也可以啟動流程
  • Idenity management:身份信息管理,可以管理用戶、用戶組等數據

創建用戶

創建過程如下,注意 id 即是登錄帳號。依次分別創建 3 個帳號用戶審批流程。

流程定義

在主界面點擊 Kickstart App 進入流程定義頁面。

上圖中模擬了一個請假流程,但是流程的執行需要人來參與,所以下邊我們進行流程和帳號綁定。
選定流程節點后點擊 Assignment 屬性,會有彈窗進行綁定。

同理,將其他節點進行綁定。然后保存關閉即可,可以看到一個流程已創建完畢。

動態表單

之前的都是基本演示,假設我們需要復雜的表單,那么可以在流程節點上綁定表單即可,這里做下動態表單的基本演示。

  1. 選中流程節點,編輯 Referenced form, 動態創建節點關聯表單。

  1. 編輯表單字段

  1. 保存表單

這樣在流程中我們就可以通過表單流轉復雜的信息了,大家可以實踐下,下邊的流程就不演示了。

流程發布

將應用和我們之前創建的流程綁定。

然后點擊發布流程

發布完成后回到首頁可以看到發布結果

流程測試

  1. 登錄 zhangsan 帳號創建請假任務

查看流程當前流轉狀態。

點擊 complete, 任務流轉到下一個流程節點。

  1. 登錄 lisi 審批

  1. 同理,登錄 wangwu 審批,流程結束。

流程管理

登錄 http://localhost:8080/activiti-admin/#/login

配置應用服務節點

配置后即可查看歷史流程記錄

持久化

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.from.default=no-reply@activiti.alfresco.com
#email.from.default.name=Activiti
#email.feedback.default=activiti@alfresco.com

#
# 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 即可。歡迎大家關注公眾號【當我遇上你】


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM