Activiti7开发(二)-流程定义
1.部署流程模型为流程定义
@PostMapping(value = "/addDeploymentByString")
public AjaxResult addDeploymentByString(@RequestParam("stringBPMN") String stringBPMN) {
processDefinitionService.addDeploymentByString(stringBPMN);
return AjaxResult.success();
}
public void addDeploymentByString(String stringBPMN) {
repositoryService.createDeployment()
.addString("CreateWithBPMNJS.bpmn", stringBPMN)
.deploy();
}
说明:stringBPMN该字符串其实就是一个xml,但与Modeler生成的内容不同;此处没有创建模型,直接进行部署。如果后期需求变更,可以基于该模型进行修改后再次部署,区别在于版本号+1,同时最新创建的流程实例是根据最新版本的流程定义创建的。
2.挂起/激活流程定义
@PostMapping("/suspendOrActiveApply")
@ResponseBody
public AjaxResult suspendOrActiveApply(@RequestBody ProcessDefinitionDTO processDefinition) {
processDefinitionService.suspendOrActiveApply(processDefinition.getId(), processDefinition.getSuspendState());
return AjaxResult.success();
}
public void suspendOrActiveApply(String id, Integer suspendState) {
if (1==suspendState) {
// 当流程定义被挂起时,已经发起的该流程定义的流程实例不受影响(如果选择级联挂起则流程实例也会被挂起)。
// 当流程定义被挂起时,无法发起新的该流程定义的流程实例。
// 直观变化:act_re_procdef 的 SUSPENSION_STATE_ 为 2
repositoryService.suspendProcessDefinitionById(id);
} else if (2==suspendState) {
repositoryService.activateProcessDefinitionById(id);
}
}
3.删除流程定义
@DeleteMapping(value = "/remove/{deploymentId}")
public AjaxResult delDefinition(@PathVariable("deploymentId") String deploymentId) {
return toAjax(processDefinitionService.deleteProcessDefinitionById(deploymentId));
}
public int deleteProcessDefinitionById(String id) {
repositoryService.deleteDeployment(id, false);
return 1;
}
4.查询流程定义
@GetMapping(value = "/list")
public TableDataInfo list(ProcessDefinitionDTO processDefinition) {
PageDomain pageDomain = TableSupport.buildPageRequest();
return getDataTable(processDefinitionService.selectProcessDefinitionList(processDefinition, pageDomain));
}
public Page<ProcessDefinitionDTO> selectProcessDefinitionList(ProcessDefinitionDTO processDefinition, PageDomain pageDomain) {
Page<ProcessDefinitionDTO> list = new Page<>();
ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionId().orderByProcessDefinitionVersion().desc();
if (StringUtils.isNotBlank(processDefinition.getName())) {
processDefinitionQuery.processDefinitionNameLike("%" + processDefinition.getName() + "%");
}
if (StringUtils.isNotBlank(processDefinition.getKey())) {
processDefinitionQuery.processDefinitionKeyLike("%" + processDefinition.getKey() + "%");
}
List<ProcessDefinition> processDefinitions = processDefinitionQuery.listPage((pageDomain.getPageNum() - 1) * pageDomain.getPageSize(), pageDomain.getPageSize());
long count = processDefinitionQuery.count();
list.setTotal(count);
if (count!=0) {
//把流程id拿到(去重)
Set<String> ids = processDefinitions.parallelStream().map(pdl -> pdl.getDeploymentId()).collect(Collectors.toSet());
//id deployTime
List<ActReDeploymentVO> actReDeploymentVOS = actReDeploymentMapper.selectActReDeploymentByIds(ids);
// id name key version deploymentId resourceName
List<ProcessDefinitionDTO> processDefinitionDTOS = processDefinitions.stream()
.map(pd -> new ProcessDefinitionDTO((ProcessDefinitionEntityImpl) pd, actReDeploymentVOS.parallelStream().filter(ard -> pd.getDeploymentId().equals(ard.getId())).findAny().orElse(new ActReDeploymentVO())))
.collect(Collectors.toList());
list.addAll(processDefinitionDTOS);
}
return list;
}
5.上传并部署流程定义
public AjaxResult uploadStreamAndDeployment(@RequestParam("file") MultipartFile file) throws IOException {
processDefinitionService.uploadStreamAndDeployment(file);
return AjaxResult.success();
}
public void uploadStreamAndDeployment(MultipartFile file) throws IOException {
// 获取上传的文件名
String fileName = file.getOriginalFilename();
// 得到输入流(字节流)对象
InputStream fileInputStream = file.getInputStream();
// 文件的扩展名
String extension = FilenameUtils.getExtension(fileName);
if (extension.equals("zip")) {
ZipInputStream zip = new ZipInputStream(fileInputStream);
repositoryService.createDeployment()//初始化流程
.addZipInputStream(zip)
.deploy();
} else {
repositoryService.createDeployment()//初始化流程
.addInputStream(fileName, fileInputStream)
.deploy();
}
}
6.查看流程模型
public void getProcessDefineXML(HttpServletResponse response,@RequestParam("deploymentId") String deploymentId,@RequestParam("resourceName") String resourceName) throws IOException {
processDefinitionService.getProcessDefineXML(response, deploymentId, resourceName);
}
public void getProcessDefineXML(HttpServletResponse response, String deploymentId, String resourceName) throws IOException {
InputStream inputStream = repositoryService.getResourceAsStream(deploymentId, resourceName);
int count = inputStream.available();
byte[] bytes = new byte[count];
response.setContentType("text/xml");
OutputStream outputStream = response.getOutputStream();
while (inputStream.read(bytes) != -1) {
outputStream.write(bytes);
}
inputStream.close();
}
返回是xml
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:activiti="http://activiti.org/bpmn" id="sample-diagram" targetNamespace="http://activiti.org/bpmn" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
<bpmn2:process id="material_apply" name="物料申请1.2" isExecutable="true" activiti:versionTag="1.2.0">
<bpmn2:startEvent id="StartEvent_1" name="Start" activiti:initiator="applyUserId">
<bpmn2:outgoing>Flow_0w19svd</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:endEvent id="Event_15f0qdt" name="End">
<bpmn2:incoming>Flow_1mzijq0</bpmn2:incoming>
<bpmn2:incoming>Flow_0eqii1k</bpmn2:incoming>
</bpmn2:endEvent>
<bpmn2:userTask id="saleSupportVerify" name="销售支持部审批" activiti:formKey="saleSupportVerify" activiti:candidateUsers="${sale_support_member}">
<bpmn2:extensionElements>
<activiti:formProperty id="FormProperty_27mbu4f--__!!radio--__!!审批意见--__!!i--__!!同意--__--不同意" type="string" label="单选按钮" />
<activiti:formProperty id="FormProperty_2am58qs--__!!textarea--__!!批注--__!!f__!!null" type="string" />
</bpmn2:extensionElements>
<bpmn2:incoming>Flow_0w19svd</bpmn2:incoming>
<bpmn2:outgoing>Flow_156vjgs</bpmn2:outgoing>
</bpmn2:userTask>
<bpmn2:exclusiveGateway id="Gateway_1wob96l" name="网关3">
<bpmn2:incoming>Flow_156vjgs</bpmn2:incoming>
<bpmn2:outgoing>Flow_1mzijq0</bpmn2:outgoing>
<bpmn2:outgoing>Flow_0eqii1k</bpmn2:outgoing>
</bpmn2:exclusiveGateway>
<bpmn2:sequenceFlow id="Flow_156vjgs" sourceRef="saleSupportVerify" targetRef="Gateway_1wob96l" />
<bpmn2:sequenceFlow id="Flow_1mzijq0" name="同意" sourceRef="Gateway_1wob96l" targetRef="Event_15f0qdt">
<bpmn2:extensionElements>
<activiti:executionListener class="com.chosenmed.workflow.oa.listener.MaterialListener" event="take">
<activiti:field name="state">
<activiti:string>3</activiti:string>
</activiti:field>
</activiti:executionListener>
</bpmn2:extensionElements>
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${FormProperty_27mbu4f==0}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="Flow_0w19svd" sourceRef="StartEvent_1" targetRef="saleSupportVerify" />
<bpmn2:sequenceFlow id="Flow_0eqii1k" name="驳回" sourceRef="Gateway_1wob96l" targetRef="Event_15f0qdt">
<bpmn2:extensionElements>
<activiti:executionListener class="com.chosenmed.workflow.oa.listener.MaterialListener" event="take">
<activiti:field name="state">
<activiti:string>2</activiti:string>
</activiti:field>
</activiti:executionListener>
</bpmn2:extensionElements>
</bpmn2:sequenceFlow>
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="material_apply">
<bpmndi:BPMNEdge id="Flow_0eqii1k_di" bpmnElement="Flow_0eqii1k">
<di:waypoint x="820" y="105" />
<di:waypoint x="820" y="292" />
<bpmndi:BPMNLabel>
<dc:Bounds x="825" y="196" width="21" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0w19svd_di" bpmnElement="Flow_0w19svd">
<di:waypoint x="208" y="80" />
<di:waypoint x="530" y="80" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1mzijq0_di" bpmnElement="Flow_1mzijq0">
<di:waypoint x="845" y="80" />
<di:waypoint x="1090" y="80" />
<di:waypoint x="1090" y="310" />
<di:waypoint x="838" y="310" />
<bpmndi:BPMNLabel>
<dc:Bounds x="1094" y="193" width="23" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_156vjgs_di" bpmnElement="Flow_156vjgs">
<di:waypoint x="630" y="80" />
<di:waypoint x="795" y="80" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="172" y="62" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="181" y="105" width="25" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_15f0qdt_di" bpmnElement="Event_15f0qdt">
<dc:Bounds x="802" y="292" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="811" y="335" width="20" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0i9t2gt_di" bpmnElement="saleSupportVerify">
<dc:Bounds x="530" y="40" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_1wob96l_di" bpmnElement="Gateway_1wob96l" isMarkerVisible="true">
<dc:Bounds x="795" y="55" width="50" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="805" y="31" width="29" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>
Activiti7开发(二)-流程定义的更多相关文章
- Slickflow.NET 开源工作流引擎高级开发(二) -- 流程快速测试增值服务工具介绍
前言:流程是由若干个任务节点组成,流转过程就是从一个节点转移到下一个节点,通常需要不断切换用户身份来完成流程的测试,这样使得测试效率比较低下,本文从实战出发,介绍常见的两种快速测试方法,用于提升流程测 ...
- Activiti 学习(二)—— Activiti 流程定义和部署
概述 在这一节,我们将创建一个 Activit 工作流,并启动这个流程,主要包含以下几个步骤: 定义流程,按照 BPMN 的规范,使用流程定义工具,用流程符号把整个流程描述出来 部署流程,把画好的流程 ...
- Activiti7流程定义
一.什么是流程定义 流程定义是线下bpmn2.0标椎去描述业务流程,通常使用activiti-explorer(web控制台)或 activiti-eclipse-designer 插件对业务流程进行 ...
- Gemini.Workflow 双子工作流入门教程二:定义流程:流程节点介绍
简介: Gemini.Workflow 双子工作流,是一套功能强大,使用简单的工作流,简称双子流,目前配套集成在Aries框架中. 下面介绍本篇教程:流程定义:流程节点属性. 流程节点: 左侧是节点工 ...
- activiti7查询流程定义的相关信息
package com.zcc.activiti02; import org.activiti.engine.ProcessEngine;import org.activiti.engine.Proc ...
- activiti7删除流程定义的相关信息
package com.zcc.activiti02; import org.activiti.engine.ProcessEngine;import org.activiti.engine.Proc ...
- Activiti7 绑定业务主键以及流程定义 流程实例的挂起和激活
绑定业务主键businessKey /** * 绑定业务主键 */ @Test public void bindingBusinessKey() { // 获取RuntimeService Runti ...
- Activiti工作流学习(一)部署对象和流程定义
一.前言 前一段时间在工作中,使用了流程审批,对api的调用非常不熟悉,都是调用别人写好的接口在界面上进行显示,基本了解了流程审批的主要步骤,现对流程审批进行学习,主要是调用api进行CRUD操作,感 ...
- (五)Activiti之获取流程定义图片和流程定义删除
一.获取流程定义图片 /** * 通过流程部署ID获取流程图图片 */ @Test public void getImageById()throws Exception{ InputStream in ...
- 【流程】Flowable流程定义总结
背景 近几年,互联网企业从消费互联网向产业互联网转型.在消费互联网时期,企业面对的时C端消费者,而产业互联网面对的是B端用户. 产业互联网涉及方方面面,企业信息化的建设就是B端用户的业务之一,在企业就 ...
随机推荐
- pytorch学习笔记(5)--神经网络
(一)神经网络的骨架 nn.Module import torch from torch import nn class Tudui(nn.Module): def __init__(self): s ...
- flask-基础篇01
一.介绍 flask只有一个内核,其WSGI工具箱采用Werkzeug(路由模块),模板引擎使用Jinja2.其他几乎所有功能都要用第三方扩展来实现. 二.常用扩展包 扩展列表:http://flas ...
- 记录aop失效问题
例子:转账demo 使用技术:基于注解的方式实现,aop也是通过注解实现(Spring) 出现问题:aop已经写好,但是没有生效 原因:1.切入点是否正确(不是本问题) 2.基于注解方式实现,没有配置 ...
- spring的作用
Spring能有效地组织你的中间层对象,无论你是否选择使用了EJB.如果你仅仅使用了Struts或其他的包含了J2EE特有API的framework,你会发现Spring关注了遗留下的问题.Sprin ...
- python机器学习——PCA降维算法
背景与原理: PCA(主成分分析)是将一个数据的特征数量减少的同时尽可能保留最多信息的方法.所谓降维,就是在说对于一个$n$维数据集,其可以看做一个$n$维空间中的点集(或者向量集),而我们要把这个向 ...
- bzoj 3309
奇怪的莫比乌斯反演... 题意:定义$f(n)$表示将$n$质因数分解后质因子的最高幂次,求$\sum_{i=1}^{a}\sum_{j=1}^{b}f(gcd(i,j))$ 首先肯定是反演嘛... ...
- JS实现异步的方法:回调函数callback、事件监听、setTimeout、Promise、生成器Generators/yield、async/awt
所有异步任务都是在同步任务执行结束之后,从任务队列中依次取出执行. 回调函数是异步操作最基本的方法,比如AJAX回调,回调函数的优点是简单.容易理解和实现,缺点是不利于代码的阅读和维护,各个部分之间高 ...
- Selenium+Python上传文件方法大全
转自:https://www.jianshu.com/p/fba37cc5d5e2
- Day09-参数+递归
参数+递归 一.命令行传参 有时候你希望运行一个程序时候再传递给它消息.这要靠传递命令行参数给main()函数实现 public class CommandLine{ public static vo ...
- 【pyqtgraph】pyqtgraph可移动竖线LineSegmentROI的拖拽事件相关
情景 Python+PyQt+pyqtgraph读取数据绘图,并在图像上添加了LineSegmentROI带handle的竖线(hanlde是为了RectROI的拖动),现要实现竖线可以直接拖动,并在 ...