import org.activiti.engine.*;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricActivityInstanceQuery;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.zip.ZipInputStream;
/**
* 工作流引擎创建 、流程部署、查询流程定义、任务查看、个人任务完成、删除部署、删除流程定义、下载资源、查看历史信息
* @param
* @author 张延分
* @date 2020-01-05
* @return
**/
public class TestActivitiDemo {
/*创建数据表结构*/
@Test
public void testCreateDb(){
// 工作流引擎(ProcessEngine)相当于一个门面接口,通过ProcessEngineConfiguration创建,通过ProcessEngine创建各个Service
//1、默认创建方式,配置文件名只能为activiti.cfg.xml
// ProcessEngine processEngine= ProcessEngines.getDefaultProcessEngine();
//2、使用自定义方式 获取工作流引擎;配置文件名可自定义名称
ProcessEngineConfiguration pec=ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
// 创建一个流程引擎对象,在创建流程引擎对象时会自动建表
ProcessEngine processEngine=pec.buildProcessEngine();
System.out.println(processEngine);
System.out.println("数据表创建完毕");
}
/**
* 1-部署流程定义(第一种方式)
* 下面三个表会保存流程的定义信息
* act_re_deployment : 部署信息
* act_re_procdef : 流程定义的相关信息
* act_ge_bytearray : 流程定义的bpmn文件及png文件
*/
@Test
public void testDeployed(){
//1、默认创建方式,配置文件名只能为activiti.cfg.xml
ProcessEngine processEngine= ProcessEngines.getDefaultProcessEngine();
//2、读取RepositoryService
RepositoryService repositoryService = processEngine.getRepositoryService();
//3、使用service进行流程部署,定义一个流程名字,把bpmn和png部署到数据库汇总
Deployment deployment = repositoryService.createDeployment() // 创建一个部署对象
.name("请假申请流程")// 添加部署的名称
.addClasspathResource("bpmn/evection.bpmn")
.addClasspathResource("bpmn/evection.png")
.deploy();// 完成部署
//4、输出部署
System.out.println("流程部署Id:"+deployment.getId());
System.out.println("流程部署key:"+deployment.getKey());
System.out.println("流程部署名称:"+deployment.getName());
System.out.println("流程部署版本号:"+deployment.getVersion());
System.out.println("流程部署时间:"+deployment.getDeploymentTime());
// 流程部署Id:1
// 流程部署key:null
// 流程部署名称:请假申请流程
// 流程部署版本号:1
// 流程部署时间:Fri Sep 17 10:35:43 CST 2021
}
/**
* 1- 部署流程定义(第二种方式)
* 新建文件夹,把 .bpmn 文件和 .png 文件放入文件夹,再把改文件夹压缩成zip包
*/
public void testDeployedByZip() {
//1、获取ProcessEngine 流程引擎对象
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//2、获取 RepositoryService 实例
RepositoryService repositoryService = processEngine.getRepositoryService();
//3、读取资源文件并创建 zip 流
InputStream inputStream = TestActivitiDemo.class
.getClassLoader()
.getResourceAsStream("bpmn/evetion.zip");
//用inputstream 构建 ZipInputStream
ZipInputStream zipInputStream = new ZipInputStream(inputStream);
//4、部署
Deployment deployment = repositoryService.createDeployment()
.addZipInputStream(zipInputStream)
.name("请假申请流程")
.deploy();
//5、查看结果
System.out.println("流程部署Id:"+deployment.getId());
System.out.println("流程部署key:"+deployment.getKey());
System.out.println("流程部署名称:"+deployment.getName());
System.out.println("流程部署版本号:"+deployment.getVersion());
System.out.println("流程部署时间:"+deployment.getDeploymentTime());
}
/**
* 2-启动流程
*
* 启动流程后,在如下的表中会增加会更新数据
* act_ru_task -- (只有节点为UserTask该表才会有数据):正在执行的任务表
* act_ru_execution -- 正在执行的执行对象表
* act_ru_identitylink -- 参与者信息
* act_hi_procinst -- 流程实例历史表
* act_hi_taskinst -- (只有节点为UserTask该表才会有数据):任务历史表
* act_hi_actinst -- 所有活动的历史表
* act_hi_identitylink -- 参与者信息
*/
@Test
public void testStartProcessInstance(){
//流程定义的key.,key对应evection.bpmn文件中id的属性值,使用key值启动,默认是按照最新版本的流程定义启动
String processDefinitionKey = "myEvection";
//1、获取ProcessEngine 流程引擎对象
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//2、获取RuntimeService
RuntimeService runtimeService = processEngine.getRuntimeService();//与正在执行的流程实例和执行对象相关的Service
//3、根据流程定义的id启动流程
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey);//使用流程定义的key启动流程实例
//4、查看结果
System.out.println("流程部署ID:"+processInstance.getDeploymentId());
System.out.println("流程定义ID:"+processInstance.getProcessDefinitionId());
System.out.println("流程实例ID:"+processInstance.getId());
System.out.println("流程定义的key:"+processInstance.getProcessDefinitionKey());
System.out.println("当前活动(运行中流程)ID:"+processInstance.getActivityId());
System.out.println("StartUserId:"+processInstance.getStartUserId());
// 流程部署ID:null
// 流程定义ID:myEvection:1:4
// 流程实例ID:2501
// 流程定义的key:myEvection
// 当前活动(运行中流程)ID:null
// StartUserId:null
}
/**
* 3-查询个人待执行任务
*/
@Test
public void testFindTaskList() {
//1、获取流程引擎 ProcessEngine 对象
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//2、获取 TaskService 对象
TaskService taskService = processEngine.getTaskService();//与正在执行的任务管理相关的Service
//3、根据 key 和 当前实例任务负责人 进行查询
List<Task> taskList = taskService.createTaskQuery() //创建任务查询对象
.processDefinitionKey("myEvection")//流程key
/**查询条件(where部分)*/
.taskAssignee("zhangsan")//查询的负责人
// .taskCandidateUser(candidateUser)//组任务的办理人查询
// .processDefinitionId(processDefinitionId)//使用流程定义ID查询
// .p
没有合适的资源?快使用搜索试试~ 我知道了~
spingboot整合activity7实践代码
共132个文件
xml:113个
java:10个
bpmn:4个
需积分: 3 0 下载量 183 浏览量
2024-07-26
15:34:18
上传
评论
收藏 78KB RAR 举报
温馨提示
学习activity7的一些代码案例
资源推荐
资源详情
资源评论
收起资源包目录
spingboot整合activity7实践代码 (132个子文件)
evection-golbal.bpmn 6KB
evection-listener.bpmn 6KB
evection-uel.bpmn 5KB
evection.bpmn 5KB
.gitignore 230B
activiti7-study.iml 12KB
TestActivitiDemo.java 21KB
TestActivitiBusinessDemo.java 6KB
TestVariables2.java 6KB
TestVariables3.java 5KB
TestVariables1.java 5KB
TestVariables.java 4KB
TestAssigneeUel.java 4KB
TestListener.java 2KB
MyTastListener.java 719B
EvectionEntity.java 630B
evection.png 6KB
log4j.properties 1KB
qaplug_profiles.xml 41KB
workspace.xml 14KB
pom.xml 8KB
activiti.cfg.xml 3KB
Project_Default.xml 1KB
Maven__org_springframework_boot_spring_boot_actuator_autoconfigure_2_1_12_RELEASE.xml 804B
misc.xml 776B
Maven__org_activiti_core_common_activiti_spring_security_policies_7_1_0_M6.xml 755B
Maven__org_springframework_boot_spring_boot_starter_logging_2_1_12_RELEASE.xml 755B
Maven__org_activiti_core_common_activiti_spring_resource_finder_7_1_0_M6.xml 741B
Maven__org_springframework_security_spring_security_core_5_1_7_RELEASE.xml 715B
Maven__org_activiti_activiti_spring_process_extensions_7_1_0_M6.xml 714B
Maven__org_activiti_core_common_activiti_spring_application_7_1_0_M6.xml 713B
Maven__org_activiti_activiti_api_process_runtime_impl_7_1_0_M6.xml 707B
Maven__org_springframework_boot_spring_boot_actuator_2_1_12_RELEASE.xml 706B
Maven__org_activiti_cloud_rb_activiti_cloud_services_api_7_1_0_M6.xml 701B
Maven__org_activiti_activiti_api_runtime_shared_impl_7_1_0_M6.xml 700B
Maven__org_activiti_core_common_activiti_spring_connector_7_1_0_M6.xml 699B
Maven__org_springframework_boot_spring_boot_starter_2_1_12_RELEASE.xml 699B
Maven__com_fasterxml_jackson_datatype_jackson_datatype_jsr310_2_9_10.xml 695B
Maven__org_activiti_activiti_spring_resource_loader_7_1_0_M6.xml 693B
Maven__org_activiti_activiti_api_process_model_impl_7_1_0_M6.xml 693B
Maven__org_activiti_core_common_activiti_spring_identity_7_1_0_M6.xml 692B
Maven__org_activiti_core_common_activiti_spring_security_7_1_0_M6.xml 692B
Maven__org_activiti_core_common_activiti_connector_model_7_1_0_M6.xml 692B
Maven__org_activiti_api_activiti_api_process_runtime_7_1_0_M6.xml 688B
Maven__org_activiti_activiti_api_model_shared_impl_7_1_0_M6.xml 686B
Maven__org_activiti_activiti_api_task_runtime_impl_7_1_0_M6.xml 686B
Maven__org_activiti_core_common_activiti_spring_project_7_1_0_M6.xml 685B
Maven__org_activiti_api_activiti_api_runtime_shared_7_1_0_M6.xml 681B
Maven__org_activiti_core_common_activiti_project_model_7_1_0_M6.xml 678B
Maven__org_springframework_boot_spring_boot_autoconfigure_2_5_3.xml 678B
Maven__org_activiti_api_activiti_api_process_model_7_1_0_M6.xml 674B
Maven__org_activiti_activiti_api_task_model_impl_7_1_0_M6.xml 672B
Maven__org_activiti_activiti_spring_boot_starter_7_1_0_M6.xml 672B
Maven__org_springframework_boot_spring_boot_starter_jdbc_2_5_3.xml 671B
Maven__org_activiti_api_activiti_api_task_runtime_7_1_0_M6.xml 667B
Maven__org_activiti_api_activiti_api_model_shared_7_1_0_M6.xml 667B
Maven__org_activiti_activiti_process_validation_7_1_0_M6.xml 665B
Maven__org_activiti_activiti_spring_app_process_7_1_0_M6.xml 665B
Maven__org_springframework_spring_expression_5_1_13_RELEASE.xml 665B
Maven__org_activiti_core_common_activiti_common_util_7_1_0_M6.xml 664B
Maven__org_activiti_api_activiti_api_task_model_7_1_0_M6.xml 653B
Maven__com_fasterxml_jackson_core_jackson_annotations_2_9_10.xml 651B
Maven__org_springframework_spring_context_5_1_13_RELEASE.xml 644B
Maven__com_fasterxml_jackson_core_jackson_databind_2_9_10_2.xml 644B
Maven__com_baomidou_mybatis_plus_boot_starter_3_4_3_3.xml 644B
Maven__org_springframework_boot_spring_boot_2_1_12_RELEASE.xml 643B
compiler.xml 642B
Maven__org_activiti_activiti_json_converter_7_1_0_M6.xml 637B
Maven__org_activiti_activiti_bpmn_converter_7_1_0_M6.xml 637B
Maven__org_springframework_spring_beans_5_1_13_RELEASE.xml 630B
Maven__com_baomidou_mybatis_plus_annotation_3_4_3_3.xml 630B
Maven__org_springframework_spring_jdbc_5_1_13_RELEASE.xml 623B
Maven__org_springframework_spring_core_5_1_13_RELEASE.xml 623B
Maven__com_baomidou_mybatis_plus_extension_3_4_3_3.xml 623B
Maven__org_springframework_spring_aop_5_1_13_RELEASE.xml 616B
Maven__commons_collections_commons_collections_3_2_1.xml 616B
Maven__org_springframework_spring_jcl_5_1_13_RELEASE.xml 616B
Maven__org_activiti_activiti_bpmn_layout_7_1_0_M6.xml 616B
Maven__org_springframework_spring_orm_5_1_13_RELEASE.xml 616B
Maven__com_fasterxml_uuid_java_uuid_generator_3_1_4.xml 612B
Maven__javax_annotation_javax_annotation_api_1_3_2.xml 611B
Maven__org_springframework_spring_tx_5_1_13_RELEASE.xml 609B
Maven__org_activiti_activiti_bpmn_model_7_1_0_M6.xml 609B
Maven__org_apache_logging_log4j_log4j_to_slf4j_2_11_2.xml 608B
Maven__com_fasterxml_jackson_core_jackson_core_2_9_10.xml 602B
Maven__commons_beanutils_commons_beanutils_1_8_0.xml 594B
Maven__com_baomidou_mybatis_plus_core_3_4_3_3.xml 588B
Maven__org_activiti_activiti_engine_7_1_0_M6.xml 581B
Maven__org_activiti_activiti_spring_7_1_0_M6.xml 581B
Maven__com_google_protobuf_protobuf_java_3_11_4.xml 581B
Maven__org_apache_commons_commons_lang3_3_12_0.xml 577B
Maven__mysql_mysql_connector_java_8_0_26.xml 574B
Maven__org_apache_logging_log4j_log4j_api_2_11_2.xml 573B
Maven__commons_logging_commons_logging_1_1_1.xml 572B
Maven__ch_qos_logback_logback_classic_1_2_3.xml 568B
Maven__com_github_vlsi_mxgraph_jgraphx_3_9_8_1.xml 562B
Maven__org_apache_commons_commons_email_1_5.xml 556B
Maven__com_baomidou_mybatis_plus_3_4_3_3.xml 553B
Maven__org_mybatis_mybatis_spring_2_0_6.xml 549B
Maven__org_slf4j_jcl_over_slf4j_1_7_30.xml 548B
共 132 条
- 1
- 2
资源评论
风雨无阻1203
- 粉丝: 584
- 资源: 39
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功