zoukankan      html  css  js  c++  java
  • activiti5初识

    因工作需要,接手新的项目,其中用到了activiti实现的工作流,特意去大致学习下,特此记录下。

    1.acticiti5框架说明及表结构介绍

    Activiti5工作流引擎框架: 它实际上是一个javaEE的半成品项目(企业一般用它来做二次开发).
    -- dao层.
    -- service层.
    -- 它有数据库表(24表). Activiti5.18,所有表都是以act开头
    -- Activiti5底层用得持久层框架是MyBatis3,
    它有自己的数据库表,提供了七个核心业务服务类.

    ACT_RE_* :'RE' 表示 repository(存储库)。资源库流程规则表。这个前缀的表包含了流程定义和流程静态资源(图片、规则 等)

    act_re_deployment 部署信息表
    act_re_model 流程设计模型部署表
    act_re_prodef

    流程定义数据表

    ACT_RU_* :'RU’ 表示 runtime(运行时)。运行时数据库表。这些运行时的表,

    包含流程实例、任务、变量、异步任务 等运行中的数据。

    这样运行时表可以一直很小数据很快。

    act_ru_execution 运行时流程执行实例表
    act_ru_identitylink 运行时流程人员表,主要存储任务节点与参与者的相关信息
    act_ru_lask 运行时任务节点表
    act_ru_variable 运行时流程变量数据表

    ACT_ID_* :'ID' 表示 identity(身份)。组织机构表。

    这些表包含了身份信息,比如用户、组 等。

    act_id_group 用户组信息表
    act_id_info 用户扩展信息表
     act_id_membership  用户与用户组对应信息表
     act_id_user  用户信息表

    ACT_HI_* :'HI' 表示 history(历史)。历史数据库表。这些表包含历史数据,

    比如历史流程实例,变量、任务 等。

    act_hi_actinst 历史节点表
    act_hi_attachment 历史附件表
    act_hi_comment 历史意见表
    act_hi_identitylink 历史流程人员表
    act_hi_detail 历史详情表,提供历史变量查询
    act_hi_procinst 历史流程实例表
    act_hi_tasking 历史任务实例表
    act_hi_varinst 历史变量表

    ACT_GE_* :'GE' 表示 general(普遍的)。通用数据表。

    用于不同场景下,如存放资源文件。

    act_ge_bytearry 二进制数据表
    act_ge_property

    属性数据表,
    存储整个流程引擎级别的数据,初始化表

     还有一个log表act_evt_log

    2.下载及安装使用

    官网地址:http://www.activiti.org

    下载 activiti-5.18.0.zip

    解压后:

    database : (数据库相关)存放了Activiti框架的sql语句.
    docs: api文档、用户指南、xsd
    libs: 存放了自己所有的jar.
    wars: web应用.

    1)安装数据库,生成表

    执行以下脚本

    -- activiti.mysql55.create.engine.sql
    -- activiti.mysql55.create.history.sql
    -- activiti.mysql.create.identity.sql

    2)集成spring

    引用maven

    <dependency>
    <groupId>org.activiti</groupId>
    <artifactId>activiti-engine</artifactId>
    <version>5.18.0</version>
    </dependency>
    <dependency>
    <groupId>org.activiti</groupId>
    <artifactId>activiti-spring</artifactId>
    <version>5.18.0</version>
    </dependency>
    3)配置activiti.xml配置,配置jdbc,及上一步生成的库的链接路径,注入activiti服务接口
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd">

    <!-- 加载activiti引擎 -->

    <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
    <!-- 连接数据的配置 -->
    <property name="jdbcDriver" value="${jdbc.driverClassName}"></property>
    <property name="jdbcUrl" value="${jdbc.url}"></property>
    <property name="jdbcUsername" value="${jdbc.username}"></property>
    <property name="jdbcPassword" value="${jdbc.password}"></property>
    <property name="activityFontName" value="宋体"/>
    <property name="labelFontName" value="宋体"/>
    <property name="jdbcPingEnabled" value="true"></property>
    <property name="jdbcMaxActiveConnections" value="1000"></property>
    <property name="jdbcMaxIdleConnections" value="200"></property>
    <property name="jdbcMaxCheckoutTime" value="20000"></property>
    <property name="jdbcPingConnectionNotUsedFor" value="3600000"></property>
    </bean>
    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
    <property name="processEngineConfiguration" ref="processEngineConfiguration" />
    </bean>
    <!-- activiti的各种服务接口 -->
    <bean id="repositoryService" factory-bean="processEngine"
    factory-method="getRepositoryService" />
    <bean id="runtimeService" factory-bean="processEngine"
    factory-method="getRuntimeService" />
    <bean id="taskService" factory-bean="processEngine"
    factory-method="getTaskService" />
    <bean id="historyService" factory-bean="processEngine"
    factory-method="getHistoryService" />
    <bean id="managementService" factory-bean="processEngine"
    factory-method="getManagementService" />
    <bean id="IdentityService" factory-bean="processEngine"
    factory-method="getIdentityService" />
    <bean id="formService" factory-bean="processEngine"
    factory-method="getFormService" />

    </beans>
    其中核心api说明如下:

    ProcessEngineConfiguration.流程引擎配置信息类.
    属性的设置、构建流程引擎.

    ProcessEngine: 流程引擎.
    获取七个业务处理类.

     RepositoryService仓储服务:

    act_re_*、act_ge_*

    RuntimeService运行时服务
    act_ru_*

    TaskService任务服务
    act_ru_*

    FormService表单服务

    IdentityService身份服务
    act_id_*

     HistoryService历史服务
    act_hi_*

     ManagementService管理服务.
    act_id_*、act_evt_log

    3.插件安装

    idea可以安装actiBPM

     然后可以创建bpm流程文件

     

     4.activiti的代码实现

    1)部署bmp流程,使得其流程保存到数据库字段中

    RepositoryService repositoryService = processEngine.getRepositoryService();     Deployment deployment = repositoryService.createDeployment()         .addClasspathResource("onboarding.bpmn20.xml").deploy();

    2)开始流程,结束流程,查询历史流程,查询流程节点状态等都是调用核心api即可,具体可以参考activiti中接口方法,参照使用。

    类似如下:

    /**查询历史任务*/
    List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery()
    .taskAssignee(request.getData().getAssignee())
    .finished().processFinished()
    .processDefinitionNameLike(processDefinitionName)
    .orderByHistoricTaskInstanceEndTime()
    .desc()
    .listPage(request.getData().getFirstResult(), request.getData().getMaxResults())

    总而言之,activiti就是为我们封装了一套流程流转的逻辑,包括里面实现的逻辑和节点数据的保存,然后封装了sql的语法上封装了自己的语言来查询和添加数据,开始和结束流程也只是对数据的新增和修改,
    至于查看流程流转流程则只是对一系列数据的查询,大体如此了,想明白这些,也就不是什么神秘难懂的东西了。
  • 相关阅读:
    ActiveReports 报表应用教程 (9)---交互式报表之动态排序
    struts2-结果处理方式
    struts2-action的创建方式
    struts2-动态方调用
    struts2-常量配置
    struts2架构图
    maven依赖范围-Scope
    Maven在eclipse的使用入门
    Maven简介
    数组的学习与使用
  • 原文地址:https://www.cnblogs.com/xzshare/p/11987172.html
Copyright © 2011-2022 走看看