/**
* Copyright (C), 2015-2018, XXX有限公司
* FileName: DemoMain
* Author: happy
* Date: 2018/6/23 16:33
* Description:
* History:
* <author> <time> <version> <desc>
* 作者姓名 修改时间 版本号 描述
*/
package com.imooc.activiti.helloworld; import com.google.common.collect.Maps;
import org.activiti.engine.*;
import org.activiti.engine.form.FormProperty;
import org.activiti.engine.form.TaskFormData;
import org.activiti.engine.impl.form.DateFormType;
import org.activiti.engine.impl.form.StringFormType;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Scanner; /**
* 〈一句话功能简述〉<br>
* 〈〉
*
* @author happy
* @create 2018/6/23
* @since 1.0.0
*/
public class DemoMain { public static final Logger log = LoggerFactory.getLogger(DemoMain.class); public static void main(String[] args) { log.info("启动我们的程序"); //创建流程引擎
ProcessEngine processEngine = getProcessEngine(); //部署流程定义文件
ProcessDefinition processDefinition = getProcessDefinition(processEngine); //启动运行流程
final ProcessInstance[] processInstance = {getProcessInstance(processEngine, processDefinition)}; //处理流程任务
Scanner scanner = new Scanner(System.in); while (processInstance[0] != null && !processInstance[0].isEnded()) { TaskService taskService = processEngine.getTaskService();
List<Task> taskList = taskService.createTaskQuery().list();
log.info("待处理任务数量 [{}]", taskList.size());
taskList.stream().forEach(task -> {
log.info("待处理任务 [{}]", task.getName());
FormService formService = processEngine.getFormService();
TaskFormData taskFormData = formService.getTaskFormData(task.getId());
List<FormProperty> formProperties = taskFormData.getFormProperties();
Map<String, Object> variables = Maps.newHashMap();
formProperties.stream().forEach(property -> {
String line = null;
if (StringFormType.class.isInstance(property.getType())) {
log.info("请输入 {} ?", property.getName());
line = scanner.nextLine();
variables.put(property.getId(), line);
} else if (DateFormType.class.isInstance(property.getType())) {
log.info("请输入 {} ? 格式 (yyyy-MM-dd)", property.getName());
line = scanner.nextLine();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
try {
date = dateFormat.parse(line);
} catch (ParseException e) {
e.printStackTrace();
}
variables.put(property.getId(), date);
} else {
log.info("类型暂不支持 {}", property.getType());
}
log.info("您输入的内容是 [{}]", line);
});
taskService.complete(task.getId(), variables);
//Variable used in lambda expression should be final or effectively final
//(解决参考 https://www.jianshu.com/p/d957dd5560e8)
processInstance[0] = processEngine.getRuntimeService().createProcessInstanceQuery().
processInstanceId(processInstance[0].getId()).singleResult();
}); } log.info("结束我们的程序"); } private static ProcessInstance getProcessInstance(ProcessEngine processEngine, ProcessDefinition processDefinition) {
RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
log.info("启动流程 {}", processInstance.getProcessDefinitionKey());
return processInstance;
} private static ProcessDefinition getProcessDefinition(ProcessEngine processEngine) {
RepositoryService repositoryService = processEngine.getRepositoryService();
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
deploymentBuilder.addClasspathResource("second_approve.bpmn20.xml");
Deployment deployment = deploymentBuilder.deploy();
String deploymentId = deployment.getId();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.deploymentId(deploymentId)
.singleResult(); log.info("流程定义文件 {},id {}", processDefinition.getName(), processDefinition.getId());
return processDefinition;
} private static ProcessEngine getProcessEngine() {
ProcessEngineConfiguration cfg = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();
ProcessEngine processEngine = cfg.buildProcessEngine();
String name = processEngine.getName();
String version = ProcessEngine.VERSION; log.info("流程引擎的名称 {},版本号 {}", name, version);
return processEngine;
} }

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="second_approve" name="二级审批流程" isExecutable="true">
<startEvent id="startEvent" name="开始"></startEvent>
<userTask id="submitForm" name="填写审批信息">
<extensionElements>
<activiti:formProperty id="message" name="申请信息" type="string" required="true"></activiti:formProperty>
<activiti:formProperty id="name" name="申请人姓名" type="string" required="true"></activiti:formProperty>
<activiti:formProperty id="submitTime" name="提交时间" type="date" datePattern="yyyy-MM-dd" required="true"></activiti:formProperty>
<activiti:formProperty id="submitType" name="确认申请" type="string" required="true"></activiti:formProperty>
</extensionElements>
</userTask>
<sequenceFlow id="flow1" sourceRef="startEvent" targetRef="submitForm"></sequenceFlow>
<exclusiveGateway id="decideSubmit" name="提交or取消"></exclusiveGateway>
<sequenceFlow id="flow2" sourceRef="submitForm" targetRef="decideSubmit"></sequenceFlow>
<endEvent id="endEventCancle" name="结束"></endEvent>
<sequenceFlow id="flow3" sourceRef="decideSubmit" targetRef="endEventCancle">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${submitType=="N" || submitType=="n"}]]></conditionExpression>
</sequenceFlow>
<userTask id="tlApprove" name="主管审批">
<extensionElements>
<activiti:formProperty id="tlApprove" name="主管审批结果" type="string" required="true"></activiti:formProperty>
<activiti:formProperty id="tlMessage" name="主管备注" type="string" required="true"></activiti:formProperty>
</extensionElements>
</userTask>
<sequenceFlow id="flow4" sourceRef="decideSubmit" targetRef="tlApprove">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${submitType=="Y" || submitType=="y"}]]></conditionExpression>
</sequenceFlow>
<exclusiveGateway id="decideTlApprove" name="主管审批校验"></exclusiveGateway>
<sequenceFlow id="flow5" sourceRef="tlApprove" targetRef="decideTlApprove"></sequenceFlow>
<userTask id="hr_approve" name="人事审批">
<extensionElements>
<activiti:formProperty id="hrApprove" name="人事审批结果" type="string" required="true"></activiti:formProperty>
<activiti:formProperty id="hrMessage" name="人事审批备注" type="string" required="true"></activiti:formProperty>
</extensionElements>
</userTask>
<sequenceFlow id="flow6" sourceRef="decideTlApprove" targetRef="hr_approve">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${tlApprove=="Y" || tlApprove=="y"}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow10" sourceRef="decideTlApprove" targetRef="submitForm">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${tlApprove=="N" || tlApprove=="n"}]]></conditionExpression>
</sequenceFlow>
<exclusiveGateway id="decideHrApprove" name="人事审批校验"></exclusiveGateway>
<sequenceFlow id="flow11" sourceRef="hr_approve" targetRef="decideHrApprove"></sequenceFlow>
<endEvent id="endEvent" name="结束"></endEvent>
<sequenceFlow id="flow12" sourceRef="decideHrApprove" targetRef="endEvent">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${hrApprove=="Y" ||hrApprove=="y"}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow13" sourceRef="decideHrApprove" targetRef="submitForm">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${hrApprove=="N" ||hrApprove=="n"}]]></conditionExpression>
</sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_second_approve">
<bpmndi:BPMNPlane bpmnElement="second_approve" id="BPMNPlane_second_approve">
<bpmndi:BPMNShape bpmnElement="startEvent" id="BPMNShape_startEvent">
<omgdc:Bounds height="35.0" width="35.0" x="50.0" y="130.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="submitForm" id="BPMNShape_submitForm">
<omgdc:Bounds height="55.0" width="105.0" x="130.0" y="120.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="decideSubmit" id="BPMNShape_decideSubmit">
<omgdc:Bounds height="40.0" width="40.0" x="280.0" y="128.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endEventCancle" id="BPMNShape_endEventCancle">
<omgdc:Bounds height="35.0" width="35.0" x="400.0" y="230.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="tlApprove" id="BPMNShape_tlApprove">
<omgdc:Bounds height="55.0" width="105.0" x="365.0" y="121.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="decideTlApprove" id="BPMNShape_decideTlApprove">
<omgdc:Bounds height="40.0" width="40.0" x="515.0" y="129.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="hr_approve" id="BPMNShape_hr_approve">
<omgdc:Bounds height="55.0" width="105.0" x="601.0" y="123.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="decideHrApprove" id="BPMNShape_decideHrApprove">
<omgdc:Bounds height="40.0" width="40.0" x="751.0" y="131.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endEvent" id="BPMNShape_endEvent">
<omgdc:Bounds height="35.0" width="35.0" x="836.0" y="134.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="85.0" y="147.0"></omgdi:waypoint>
<omgdi:waypoint x="130.0" y="147.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="235.0" y="147.0"></omgdi:waypoint>
<omgdi:waypoint x="280.0" y="148.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="300.0" y="168.0"></omgdi:waypoint>
<omgdi:waypoint x="299.0" y="247.0"></omgdi:waypoint>
<omgdi:waypoint x="400.0" y="247.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="320.0" y="148.0"></omgdi:waypoint>
<omgdi:waypoint x="365.0" y="148.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="470.0" y="148.0"></omgdi:waypoint>
<omgdi:waypoint x="515.0" y="149.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
<omgdi:waypoint x="555.0" y="149.0"></omgdi:waypoint>
<omgdi:waypoint x="601.0" y="150.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
<omgdi:waypoint x="535.0" y="169.0"></omgdi:waypoint>
<omgdi:waypoint x="535.0" y="296.0"></omgdi:waypoint>
<omgdi:waypoint x="182.0" y="296.0"></omgdi:waypoint>
<omgdi:waypoint x="182.0" y="175.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11">
<omgdi:waypoint x="706.0" y="150.0"></omgdi:waypoint>
<omgdi:waypoint x="751.0" y="151.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow12" id="BPMNEdge_flow12">
<omgdi:waypoint x="791.0" y="151.0"></omgdi:waypoint>
<omgdi:waypoint x="836.0" y="151.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow13" id="BPMNEdge_flow13">
<omgdi:waypoint x="771.0" y="131.0"></omgdi:waypoint>
<omgdi:waypoint x="770.0" y="50.0"></omgdi:waypoint>
<omgdi:waypoint x="182.0" y="50.0"></omgdi:waypoint>
<omgdi:waypoint x="182.0" y="120.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>

工作流学习之入门demo的更多相关文章

  1. 【Activiti工作流引擎】官方快速入门demo

    Activiti官方快速入门demo 地址: https://www.activiti.org/quick-start 0. 版本 activiti 5.22.0 JDK 1.8 1. 介绍 这个快速 ...

  2. 工作流Activity框架入门(一)

    Activity工作流入门 1. 工作流概念 工作流(Workflow),就是"业务过程的部分或整体在计算机应用环境下的自动化",它主要解决的是"使在多个参与者之间按照某 ...

  3. 【SSH系列】初识spring+入门demo

    学习过了hibernate,也就是冬天,经过一个冬天的冬眠,当春风吹绿大地,万物复苏,我们迎来了spring,在前面的一系列博文中,小编介绍hibernate的相关知识,接下来的博文中,小编将继续介绍 ...

  4. LESS学习笔记 —— 入门

    今天在网上完成了LESS的基础学习,下面是我的学习笔记.总共有三个文件:index.html.main.less.mian.css,其中 mian.css 是 main.less 经过Koala编译之 ...

  5. Activiti工作流学习之流程图应用详解

    Activiti工作流学习之流程图应用详解 1.目的  了解Activiti工作流是怎样应用流程图的. 2.环境准备2.1.相关软件及版本    jdk版本:Jdk1.7及以上 IDE:eclipse ...

  6. SpringBoot 入门 Demo

    SpringBoot   入门 Demo Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从 ...

  7. Python学习--01入门

    Python学习--01入门 Python是一种解释型.面向对象.动态数据类型的高级程序设计语言.和PHP一样,它是后端开发语言. 如果有C语言.PHP语言.JAVA语言等其中一种语言的基础,学习Py ...

  8. [IT学习]sql 入门及实例

    sql 是一种数据库查询语言,可以让你很快的查询到数据.其实一般情况下,你也可以采用excel来查询数据库数据. 但是人们通常认为sql会更加灵活和方便一些. sql学习的入门网站: http://w ...

  9. PHP学习笔记 - 入门篇(5)

    PHP学习笔记 - 入门篇(5) 语言结构语句 顺序结构 eg: <?php $shoesPrice = 49; //鞋子单价 $shoesNum = 1; //鞋子数量 $shoesMoney ...

随机推荐

  1. 慕课网_文件传输基础——Java IO流

    第1章 文件的编码 1-1 文件的编码 (15:07) 第2章 File 类的使用 2-1 File 类常用 API 介绍 (10:50) import java.io.File; import ja ...

  2. delphi 导出excel

    Var FExcel:OleVariant; //excel应用程序 FWorkBook :OleVariant; //工作表 Temsheet:OleVariant; //工作薄 FPicture: ...

  3. etcd节点扩容至两个节点

    本篇已经安装了单个etcd,然后进行扩容etcd节点至2个,安装单节点请参照:https://www.cnblogs.com/effortsing/p/10295261.html 实验架构 test1 ...

  4. kubernetes集群node加入不了master错误处理

    #如果node加入不了master或者加入成功但是,在master中显示不出来.排查错误:1. 运行,kubelet, 查看日志,一般是kubelet的运行和docker启动方式不匹配.调整:vim  ...

  5. c语言Ι博客作业04

    这个作业属于哪个课程 c语言程序设计II 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/CST2019-3/homework/9771 我在这个课程的目 ...

  6. A Dangerous Maze (期望值)

    https://vjudge.net/problem/LightOJ-1027?tdsourcetag=s_pctim_aiomsg [被满为姐姐碾压 降智打击题]

  7. OLT设置vlan透传及ONU端口划vlan

    CZ-PX-ShangShi-FTTH-OLT-A#show runn System current configuration:!Software Version ISCOM5800E-SMCB_1 ...

  8. 原生CURD

    <?phpheader("content-type:text/html;charset=utf8");$link=mysqli_connect("127.0.0.1 ...

  9. 07、poly-A内参和杂交内参(arrayanalysis的问题)

    为了验证杂交的质量,Affymetrix公司加入了两类嵌入探针组: 一.poly-A内参:包括lys.phe.thr.dap 对应的探针组名称为:AFFX-r2-Bs-lys-3_at.AFFX-r2 ...

  10. 对Elastic集群内部配置TLS加密通信及身份验证

    1.介绍 官方宣布从6.8和7.1开始,免费提供多项安全功能.其中包括tls加密通信,基于角色访问控制等功能. 可以使用企业CA证书来完成这一步骤,但是一般情况下,我们可以通过elasticsearc ...