/**
* 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. 第三方MBXPageViewController的使用和注意事项

    GitHub的地址: https://github.com/Moblox/MBXPageViewController 介绍SegmentController的使用: - (void)createSeg ...

  2. 替换RTXLogo插件说明

    一.包含Logo图标文件介绍 (一)桌面图标包含在RTX.exe (二)桌面右下角图标包含在MainFrameRes.dll (三)RTX设置图标包含在Config.dll (四)查看用户信息图标包含 ...

  3. Java编程思想—八皇后问题(数组法、堆栈法)

    Java编程思想-八皇后问题(数组法.堆栈法) 实验题目:回溯法实验(八皇后问题) 实验目的: 实验要求: 实验内容: (1)问题描述 (2)实验步骤: 数组法: 堆栈法: 算法伪代码: 实验结果: ...

  4. SpringCloud解决了哪些问题?

    1.与分布式系统相关的复杂性 – 包括网络问题,延迟开销,带宽问题,安全问题. 2.处理服务发现的能力 – 服务发现允许集群中的进程和服务找到彼此并进行通信. 3.解决冗余问题 – 冗余问题经常发生在 ...

  5. win10电脑休眠后无法唤醒的解决办法

    电脑的休眠功能,为长时间不用的电脑进行了关闭显示.硬盘停转的深度节能模式,不仅节约能源,还保护设备. 但有些时候也会出现一些问题,如休眠后无法唤醒,无法移动鼠标,敲击键盘都无效,最后只能长按电源键来强 ...

  6. 【VS开发】【图像处理】自动白平衡(AWB)算法---色温曲线

    原文地址:http://blog.csdn.net/wzwxiaozheng/article/details/38434391 白平衡算法---色温曲线 本文大体讲解了白平衡的算法流程,适用于想了解和 ...

  7. Elasticsearch-搜索并获取数据

    Elasticsearch-搜索并获取数据 在group中搜索elasticsearch curl -XGET "localhost:9200/get-together/group/_sea ...

  8. python之网络部分

    1.C/S B/S架构 C: client端 B: browse 浏览器 S: server端 C/S架构: 基于客户端与服务端之间的通信 ​ QQ, 游戏,皮皮虾, 快手,抖音. ​ 优点: 个性化 ...

  9. 工作中常用到的JS验证

    Common.js // JavaScript Document // _ooOoo_ // o8888888o // 88" . "88 // (| -_- |) // O\ = ...

  10. spring boot 是如何利用jackson进行反序列化的?

    以下面的代码为例: @RestController public class HelloController { @RequestMapping("/") public BillS ...