标签:activiti 流程 使用 activiti7 ACT org log4j out
目录
一、Activiti环境
1、idea安装插件
* Bpmn图形其实是通过xml表示业务流程(.bpmn文件使用文本编辑器打开)
* File | Settings | Plugins
- 搜索actiBPM(Activiti BPMN visualizer)
2、数据库支持
* 阿里云PolarDB
- 集群白名单
~ 新增ip白名单分组(www.ip138.com)
~ 选择安全组
- 账号管理
~ 创建账号
- 基本信息
~ 链接地址(主地址申请公网)
~ 登录数据库
* 创建数据库(名字任意)
- CREATE DATABASE activiti DEFAULT CHARACTER SET utf8;
3、创建maven工程
<properties>
<slf4j.version>1.6.6</slf4j.version>
<log4j.version>1.2.12</log4j.version>
<activiti.version>7.0.0.Beta1</activiti.version>
</properties>
<dependencies>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>${activiti.version}</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>${activiti.version}</version>
</dependency>
<!-- bpmn 模型处理 -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-bpmn-model</artifactId>
<version>${activiti.version}</version>
</dependency>
<!-- bpmn 转换 -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-bpmn-converter</artifactId>
<version>${activiti.version}</version>
</dependency>
<!-- bpmn json数据转换 -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-json-converter</artifactId>
<version>${activiti.version}</version>
</dependency>
<!-- bpmn 布局 -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-bpmn-layout</artifactId>
<version>${activiti.version}</version>
</dependency>
<!-- activiti 云支持 -->
<dependency>
<groupId>org.activiti.cloud</groupId>
<artifactId>activiti-cloud-services-api</artifactId>
<version>${activiti.version}</version>
</dependency>
<!-- mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.40</version>
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>
<!-- 链接池 -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!-- log start -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
- src/main/resources/log4j.properties
# Set root category priority to INFO and its only appender to CONSOLE.
#log4j.rootCategory=INFO, CONSOLE debug info warn error fatal
log4j.rootCategory=debug, CONSOLE, LOGFILE
# Set the enterprise logger category to FATAL and its only appender to CONSOLE.
log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-6r[%15.15t] %-5p %30.30c %x - %m\n
# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=f:\act\activiti.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d{ISO8601} %-6r[%15.15t] %-5p %30.30c %x - %m\n
- src/main/resources/activiti.cfg.xml
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/contex
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 默认id对应的值 为processEngineConfiguration -->
<!-- processEngine Activiti的流程引擎 -->
<bean id="processEngineConfiguration"
class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="jdbcDriver" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql:///activiti"/>
<property name="jdbcUsername" value="root"/>
<property name="jdbcPassword" value="123456"/>
<!-- activiti数据库表处理策略 -->
<property name="databaseSchemaUpdate" value="true"/>
</bean>
</beans>
- src/test/java/com/linjincheng/test/TestCreate.java
package com.itheima.activiti01.test;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.junit.Test;
public class TestDemo {
/**
* 生成 activiti的数据库表
*/
@Test
public void testCreateDbTable() {
//使用classpath下的activiti.cfg.xml中的配置创建processEngine
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
System.out.println(processEngine);
}
}
表分类 |
表名 |
解释 |
一般数据 |
|
|
|
[ACT_GE_BYTEARRAY] |
通用的流程定义和流程资源 |
|
[ACT_GE_PROPERTY] |
系统相关属性 |
流程历史记录 |
|
|
|
[ACT_HI_ACTINST] |
历史的流程实例 |
|
[ACT_HI_ATTACHMENT] |
历史的流程附件 |
|
[ACT_HI_COMMENT] |
历史的说明性信息 |
|
[ACT_HI_DETAIL] |
历史的流程运行中的细节信息 |
|
[ACT_HI_IDENTITYLINK] |
历史的流程运行过程中用户关系 |
|
[ACT_HI_PROCINST] |
历史的流程实例 |
|
[ACT_HI_TASKINST] |
历史的任务实例 |
|
[ACT_HI_VARINST] |
历史的流程运行中的变量信息 |
流程定义表 |
|
|
|
[ACT_RE_DEPLOYMENT] |
部署单元信息 |
|
[ACT_RE_MODEL] |
模型信息 |
|
[ACT_RE_PROCDEF] |
已部署的流程定义 |
运行实例表 |
|
|
|
[ACT_RU_EVENT_SUBSCR] |
运行时事件 |
|
[ACT_RU_EXECUTION] |
运行时流程执行实例 |
|
[ACT_RU_IDENTITYLINK] |
运行时用户关系信息,存储任务节点与参与者的相关信息 |
|
[ACT_RU_JOB] |
运行时作业 |
|
[ACT_RU_TASK] |
运行时任务 |
|
[ACT_RU_VARIABLE] |
运行时变量表 |
service名称 |
service作用 |
RepositoryService |
activiti的资源管理类 |
RuntimeService |
activiti的流程运行管理类 |
TaskService |
activiti的任务管理类 |
HistoryService |
activiti的历史管理类 |
ManagerService |
activiti的引擎管理类 |
4、activiti入门
* 事件Event
- 开始事件
- 中间事件
- 结束事件
* 活动Activity
- 用户任务
- 服务任务
- 子流程
* 网关GateWay
- 排他网关(x)
- 并行网关(+)
- 包容网关(+)
- 综合网关
- 事件网关(+)
* 流向Flow
- 顺序流
- 消息流
- 关联
- 数据关联
* 右击目录 -> new -> New Activiti 6.x BPMN 2.0 file
* 右击xml编辑面板 -> View BPMN (Activiti) Diagram
* 右击画板
- Connection:连接
- Event:事件
- Task:任务
- Gateway:网关
- Container:容器
- Boundary event:边界事件
- Intermediate event:中间事件
5、流程定义部署
- src/test/java/com/linjincheng/test/ActivitiDemo.java
package com.linjincheng.test;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.junit.Test;
public class ActivitiDemo {
@Test
public void testDeployment() {
// 改动四张表:act_re_deployment、act_re_procdef、act_ge_bytearray、act_ge_property
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
Deployment deploy = repositoryService
.createDeployment()
.name("出差申请流程")
.addClasspathResource("bpmn/evection.bpmn20.xml")
.addClasspathResource("bpmn/evection.png")
.deploy();
System.out.println("流程部署id=" + deploy.getId());
System.out.println("流程部署名字=" + deploy.getName());
}
}
6、启动流程-任务查询-完成任务
- src/test/java/com/linjincheng/test/ActivitiDemo.java
package com.linjincheng.test;
import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
import java.util.List;
public class ActivitiDemo {
@Test
public void testStartProcess() {
// 启动流程
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstance instance = runtimeService.startProcessInstanceByKey("evection");
System.out.println("流程定义ID:" + instance.getProcessDefinitionId());
System.out.println("流程实例ID:" + instance.getId());
System.out.println("当前活动的ID:" + instance.getActivityId());
}
@Test
public void testFindPersonalTaskList() {
// 任务查询
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
List<Task> taskList = taskService.createTaskQuery().processDefinitionKey("evection").taskAssignee("zhangsan").list();
for (Task task : taskList) {
System.out.println("流程实例id=" + task.getProcessInstanceId());
System.out.println("任务Id=" + task.getId());
System.out.println("任务负责人=" + task.getAssignee());
System.out.println("任务名称=" + task.getName());
}
}
@Test
public void completTask() {
// 完成任务
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
// taskService.complete("7505");
// Task task = taskService.createTaskQuery().processDefinitionKey("evection").taskAssignee("jerry").singleResult();
// Task task = taskService.createTaskQuery().processDefinitionKey("evection").taskAssignee("jack").singleResult();
Task task = taskService.createTaskQuery().processDefinitionKey("evection").taskAssignee("rose").singleResult();
System.out.println("流程实例id=" + task.getProcessInstanceId());
System.out.println("任务Id=" + task.getId());
System.out.println("任务负责人=" + task.getAssignee());
System.out.println("任务名称=" + task.getName());
taskService.complete(task.getId());
}
}
标签:activiti,
流程,
使用,
activiti7,
ACT,
org,
log4j,
out
From: https://www.cnblogs.com/linding/p/17917684.html