/**
* 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. [转] javascript 正则表达式提取数字使用

    简述: 测试了一下js的正则表达式函数match 用来从一个字符串里挑出非0开头的数字, 放入一个array里, 之后join(',')之后输出 知识点: 1. 用match函数, 提取一个字符串当中 ...

  2. 应用安全 - 工具 - 中间件 - Apache - Apache Tika - 漏洞汇总

    CVE-2016-6809 Date2016 类型远程代码执行 影响范围Apache Tika 1.6-1.13 CVE-2018-1335 Date2018 类型命令注入 影响范围Tika-serv ...

  3. 【VS开发】win7下让程序默认以管理员身份运行

    在win7中用自己写的程序读取MBR时,突然提示无法对磁盘进行操作,而在xp下并没有这个问题:最后点右键以管理员身份运行才可以正常运行.于是想办法让程序在双击启动时默认以管理员身份运行.具体方法: 1 ...

  4. vue --》elementUI 中 el-table组件 如何实现点击列,让该列高亮显示 ?

    在elmentui官网中,只给了让当前行高亮显示的方法,但是如何让当前列高亮显示呢? <template> <div> <el-table :data="tab ...

  5. java 依据文件名判断mime类型

    依据文件名称判断mime类型 import java.util.HashMap; import java.util.Map; /** * 依据文件名获取MimeType */ public class ...

  6. POJ2387 Til the Cows Come Home (最短路 dijkstra)

    AC代码 POJ2387 Til the Cows Come Home Bessie is out in the field and wants to get back to the barn to ...

  7. pyrhon 开始 基础类型

    https://repl.it/languages/python  线上编辑器 字符串不支持  减法 除法

  8. PostGIS 爆管分析之找出上游阀门(优化版)

    说明 前面描述过利用postgis查找上游阀门的原理,以及代码,其实当初写完就发现又很大的优化空间,但一直没有时间去做. 最近遇到一个情况,处理60w+条管网数据时,效率太慢了,于是腾时间优化了一版. ...

  9. 083、Prometheus架构(2019-05-05 周日)

    参考https://www.cnblogs.com/CloudMan6/p/7692765.html   Prometheus 是一个非常优秀的监控工具,准确的说,应该是监控方案.Prometheus ...

  10. xcode中进行git代码管理

    http://www.cocoachina.com/ios/20140524/8536.html