1. 程式人生 > >【應用篇】Activiti外接表單簡單應用(三)

【應用篇】Activiti外接表單簡單應用(三)

Activiti的簡單應用,使用外接表單的方式將業務頁面繫結到工作流的結點上,當執行到當前結點時,打印出繫結表單的內容。

新建4form頁面,頁面內容隨便寫些內容即可:


按照下圖的方式依次繫結:


流程變數設定如圖,其他的類似:


對應生成的xml

<?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="myProcess" name="My process" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="顯示使用者詳細資訊" activiti:formKey="userinfo.form"></userTask>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
    <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="exclusivegateway1"></sequenceFlow>
    <userTask id="usertask3" name="耳機驗證" activiti:formKey="ear.form"></userTask>
    <sequenceFlow id="flow4" name="耳機驗證" sourceRef="exclusivegateway1" targetRef="usertask3">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${result=="ear"}]]></conditionExpression>
    </sequenceFlow>
    <userTask id="usertask4" name="二次登陸" activiti:formKey="secondtime.form"></userTask>
    <sequenceFlow id="flow5" name="存在登陸資訊" sourceRef="exclusivegateway1" targetRef="usertask4">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${result=="exist"}]]></conditionExpression>
    </sequenceFlow>
    <exclusiveGateway id="exclusivegateway2" name="Exclusive Gateway"></exclusiveGateway>
    <sequenceFlow id="flow6" sourceRef="usertask4" targetRef="exclusivegateway2"></sequenceFlow>
    <sequenceFlow id="flow7" name="密碼錯誤" sourceRef="exclusivegateway2" targetRef="usertask4">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${result=="no"}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow8" name="密碼正確" sourceRef="exclusivegateway2" targetRef="usertask3">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${result=="yes"}]]></conditionExpression>
    </sequenceFlow>
    <userTask id="usertask5" name="鍵盤驗證" activiti:formKey="keyboard.form"></userTask>
    <sequenceFlow id="flow9" sourceRef="usertask3" targetRef="usertask5"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow10" sourceRef="usertask5" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
    <bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="75.0" y="79.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55.0" width="105.0" x="155.0" y="69.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
        <omgdc:Bounds height="40.0" width="40.0" x="305.0" y="77.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
        <omgdc:Bounds height="55.0" width="105.0" x="415.0" y="70.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4">
        <omgdc:Bounds height="55.0" width="105.0" x="273.0" y="178.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="exclusivegateway2" id="BPMNShape_exclusivegateway2">
        <omgdc:Bounds height="40.0" width="40.0" x="447.0" y="185.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask5" id="BPMNShape_usertask5">
        <omgdc:Bounds height="55.0" width="105.0" x="600.0" y="70.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="750.0" y="80.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="110.0" y="96.0"></omgdi:waypoint>
        <omgdi:waypoint x="155.0" y="96.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="260.0" y="96.0"></omgdi:waypoint>
        <omgdi:waypoint x="305.0" y="97.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="345.0" y="97.0"></omgdi:waypoint>
        <omgdi:waypoint x="415.0" y="97.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="14.0" width="48.0" x="347.0" y="80.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="325.0" y="117.0"></omgdi:waypoint>
        <omgdi:waypoint x="325.0" y="178.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="14.0" width="72.0" x="245.0" y="151.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
        <omgdi:waypoint x="378.0" y="205.0"></omgdi:waypoint>
        <omgdi:waypoint x="447.0" y="205.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
        <omgdi:waypoint x="467.0" y="225.0"></omgdi:waypoint>
        <omgdi:waypoint x="466.0" y="309.0"></omgdi:waypoint>
        <omgdi:waypoint x="389.0" y="309.0"></omgdi:waypoint>
        <omgdi:waypoint x="325.0" y="309.0"></omgdi:waypoint>
        <omgdi:waypoint x="325.0" y="233.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="14.0" width="48.0" x="469.0" y="267.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
        <omgdi:waypoint x="467.0" y="185.0"></omgdi:waypoint>
        <omgdi:waypoint x="467.0" y="125.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="14.0" width="48.0" x="468.0" y="166.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9">
        <omgdi:waypoint x="520.0" y="97.0"></omgdi:waypoint>
        <omgdi:waypoint x="600.0" y="97.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
        <omgdi:waypoint x="705.0" y="97.0"></omgdi:waypoint>
        <omgdi:waypoint x="750.0" y="97.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

程式碼實現:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipInputStream;

import org.activiti.engine.FormService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
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 com.tgb.itoo.activiti.controller.CommonDelegate;
import com.tgb.itoo.activiti.controller.milaoshi;
import com.tgb.itoo.activiti.controller.tanghuan;

public class formprocess {

	private static String readDataFromConsole(String prompt) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = null;
		try {
			System.out.print(prompt);
			str = br.readLine();

		} catch (IOException e) {
			e.printStackTrace();
		}
		return str;
	}

	public static void main(String[] args) {

		String str = readDataFromConsole("Please input string:");
		System.out.println("The information from console: " + str);
		
		ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration
				.createStandaloneProcessEngineConfiguration();
		// 連線資料庫的配置
		processEngineConfiguration.setJdbcDriver("com.mysql.jdbc.Driver");
		processEngineConfiguration
				.setJdbcUrl("jdbc:mysql://localhost:3306/activitiexam?useUnicode=true&characterEncoding=utf8");
		processEngineConfiguration.setJdbcUsername("root");
		processEngineConfiguration.setJdbcPassword("root");
		processEngineConfiguration.setDatabaseSchemaUpdate("create");
		ProcessEngine processEngine = processEngineConfiguration
				.buildProcessEngine();

		System.out.println(processEngine);
		// 獲取流程儲存服務元件
		RepositoryService repositoryService = processEngine
				.getRepositoryService();

		// 獲取執行時服務元件
		RuntimeService runtimeService = processEngine.getRuntimeService();

		// 獲取流程任務元件
		TaskService taskService = processEngine.getTaskService();

		//獲取流程的表單元件
		FormService formService=processEngine.getFormService();
		
		// 1、部署流程檔案
		InputStream in =repositoryService.createDeployment().name("MyProcess")
		.getClass().getClassLoader().getResourceAsStream("diagrams/"+ str +".zip");
		ZipInputStream zipInputStream = new ZipInputStream(in);
		Deployment deployment = processEngine.getRepositoryService()// 與流程定義和部署物件相關的Service
				.createDeployment()// 建立一個部署物件
				.name("流程定義")// 新增部署的名稱
				.addZipInputStream(zipInputStream)// 指定zip格式的檔案完成部署
				.deploy();// 完成部署
				
		
		// 2、啟動流程--方式一
		/*ProcessInstance processInstance = runtimeService
				.startProcessInstanceByKey("myProcess");
		*/
		
		/**
		 * 2、啟動流程--方式二
		 * 此處使用這種方式,可能有問題,當所有的流程定義的key值均為myProcess時,查詢出來的資料為多條
		 * 但是真正使用時,我們是根據前臺顯示的多條中選擇其中之一,就可以直接獲取processDefinitionID故也沒有問題
		 */
		ProcessDefinitionQuery query = repositoryService
				.createProcessDefinitionQuery()
				.processDefinitionKey("myProcess").active()
				.orderByProcessDefinitionVersion().desc();
		ProcessDefinition  processDefinition = query.list().get(0);	
		Map<String, String> formProperties = new HashMap<String, String>();
		
		formProperties.put("numberOfDays", "20150601");
		//此處如果第二個引數為null值則報錯,即使不放入任何資料也要使用map格式的物件
		ProcessInstance processInstance = formService
				.submitStartFormData(processDefinition.getId(), formProperties);

		String end="1";
		while (end.equalsIgnoreCase("1")) {
			
			// 3、查詢任務
			Task task = taskService.createTaskQuery()
					.processInstanceId(processInstance.getId()).singleResult();
			;			
						
			if (task != null) {
				Object renderedTaskForm = formService.getRenderedTaskForm(task.getId());
				System.out.println("表單內容---"+renderedTaskForm.toString());
				System.out.println("任務名稱---"+task.getName());							
				
				/**
				 * 如果整個流程都是順序執行可以不暫停的,則去掉此段程式碼即可
				 * 注:現實中存在的是頁面流轉過程中是需要點選下一步操作的,可以將此暫停理解為下一步的操作
				 */
				str = readDataFromConsole("Please input next:");
				Map<String, Object> variables = new HashMap<String, Object>();
				variables.put("result", str);
				
				//方式一啟動流程的完成任務,如果下一個任務需要引數使用map傳遞,此處的變數均是給下一個任務設定的
				taskService.complete(task.getId(),variables);
				//方式二啟動流程完成任務
				//formService.submitTaskFormData(task.getId(), formProperties);
				
				//注:以上的兩種方式可以混用
			}else {
				end="0";
				System.out.println("任務已經完成");
			} 

		}

	}

}

執行結果:


總結:

以上實現了結點繫結頁面的操作,當執行到當前結點時,會打印出繫結頁面的內容,這樣頁面的執行順序就不需要我們去管理,而可以通過簡單的配置實現,以上只是一個簡單的main函式實現,下面會繼續實現一個簡單的demo


相關推薦

應用Activiti簡單應用

Activiti的簡單應用,使用外接表單的方式將業務頁面繫結到工作流的結點上,當執行到當前結點時,打印出繫結表單的內容。新建4個form頁面,頁面內容隨便寫些內容即可:按照下圖的方式依次繫結:流程變數設定如圖,其他的類似:對應生成的xml:<?xml version="

筆記最良心的計算幾何學習筆記

變量類型 其他 條件 parallel node ons put 是否 通過 世界以痛吻我, 我卻報之以歌。 開新坑... 雖然不知道這坑要填多久... 文章同步上傳到github... 有想看的可以去看看→_→ *溫馨提示: 看本文之前請務必學習或回顧數學-必修2的解析

筆記最良心的計算幾何學習筆記

紅色 online src note 不變 比較 基礎知識 cst 分類 半平面交 github傳送門 簡介 Emmmm學完旋轉卡殼感覺自己已經是個廢人了.. 修整了一個周末, 回來接著跟計算幾何勢力硬幹... (這個周末是不是有點長?) 今天就講講半平面交吧. 請自己回顧

筆記最良心的計算幾何學習筆記

完整 size cos 一道 細節問題 avi 參數 cnblogs 關系 依然放上本文的github地址... 作業QwQ 先來說一下上次留下的例題. poj這道題並沒有實數比較模式.. 所以被精度勢力幹翻. 交上去WA掉竟然是因為-0.00和0.00不相等? 根據對拍

筆記最良心的計算幾何學習筆記

不一定 source spa hub 掃描 markdown 如何 urn 神奇 動態凸包 本文的github傳送門在這裏~ ====================================================================== 不會凸

機器學習動手寫一個全連線神經網路:分類

我們來用python寫一個沒有正則化的分類神經網路。 傳統的分類方法有聚類,LR邏輯迴歸,傳統SVM,LSSVM等。其中LR和svm都是二分類器,可以將多個LR或者svm組合起來,做成多分類器。 多分類神經網路使用softmax+cross entropy組

ElasticSearch--ElasticSearch從初識到安裝和應用

sequence ria wan shard 主機 single when please lock 一、前述 ElasticSearch是一個基於Lucene的搜索服務器。它提供了一個分布式多用戶能力的全文搜索引擎,基於RESTful web接口,在企業中全文搜索時,特別常

iOS學習Macbook2k顯示器開啟hidpi的方法

一、前言:大家平時用macbook開發的時候一般都喜歡外接一個顯示器開發吧?這裡我用了一臺2k的顯示器,我們要開啟hidpi模式。你們會問到為什麼要開啟hidpi模式呢?我的2k顯示器是2560*1440分別率,如果採用預設的設定,那麼在顯示器上面的字會特別的小。如果我們開啟

提高經典演算法——有序的二分查詢

#include <stdio.h> #define SIZE 10 /* *csdn學院--2016級 *目的:讓程式碼見證成長(作為一個初學的菜鳥,如 *大家有發現錯誤,歡迎指正!) *檔名稱:Myfun150.c *作者:小臣小仁 *問題描述:經典演算法——有序表的二分查詢 *完成日期:20

入門Activiti查詢指定流程定義下待辦task

需求 某人登入系統後,需要對他待辦的任務進行處理 涉及到的表 act_ru_task 方案 根據流程定義key和任務人,依賴taskservice服務,查詢act_ru_task表待辦內容

入門Activiti查詢指定流程定義下已完成的流程例項

需求 使用者和管理員有時候需要統計,有多少個業務例項通過了稽核,這個時候需要查詢指定流程下的已完成的流程例項,用做後期的統計。 涉及到的表 act_hi_procinst:流程例項歷史表 方案 根據流程定義key,依賴historyservice服務來完成 程式碼

Python學習第2:Python之數據類型2

append 但是 iss 代碼 key 常用方法 uber ner ces 元組 #為何要有元組,存放多個值,元組不可變,更多的是用來做查詢 t=(1,[1,3],‘sss‘,(1,2)) #t=tuple((1,[1,3],‘sss‘,(1,2))) #

總結js編寫的2048小遊戲開發上:思路

2048是大家都熟悉的一款魔性小遊戲,其操作簡單,卻極其有效地殺時間。本篇將詳細講解如何構建這款小遊戲的開發思路、如何根據玩法進一步分析設計程式設計結構,適合有一定html、css、js、jquery語言基礎的讀者閱讀。 一.遊戲試玩       遊戲玩法大家都很

java webJSP中form中文亂碼的解決嘗試

       在人生中的第一個實際專案中,我遇到了一個很困擾的問題,就是在內管系統中,我做了一個測試頁面,用來測試向對方介面傳遞引數,我使用了jsp的form表單向後端傳遞引數,在本地啟動服務,進行測試都沒有問題,沒有出現中文亂碼的情況,但是提交到測試環境進行驗證時,卻出現了

前端框架Backbone.js在大型頁面應用中的應用實踐

Backbone.js是什麼? Backbone.js是一個JavaScript MVC框架,提供了良好的程式碼組織能力,可以方便地將應用程式解耦成可以複用的部分,為建立大型的單頁面應用提供框架支援,目前的版本是0.9.10(注:現在已到1.2.1版本)。通過將應用程式分解成MVC模式中不同職責的模組,

知識積累jQuery MiniUI實現聯動

需求介紹: 點選第一個datagrid裡面的節點名稱,在頁面上的第二個datagrid裡面顯示出它對應的相關資訊。用jQuery MiniUI實現表單的聯動效果: 關鍵程式碼: (1)第一個datag

Python3爬蟲當爬蟲碰到提交,有點意思

一、寫在前面   我寫爬蟲已經寫了一段時間了,對於那些使用GET請求或者POST請求的網頁,爬取的時候都還算得心應手。不過最近遇到了一個有趣的網站,雖然爬取的難度不大,不過因為表單提交的存在,所以一開始還是有點摸不著頭腦。至於最後怎麼解決的,請慢慢往下看。   二、頁面分析   這次爬取的網

SSH 基礎淺談Hibernate關系映射3

區別 ack 增加 ans 存儲結構 mil pro 映射 方向 繼上篇博客 一對多關聯映射(單向) 上面我們介紹了多對一,我們反過來看一對多不就是多對一嗎?那還用再進行不同的映射嗎?有什麽區別嗎?一對多和多對一映射原理是一致的,存儲是同樣的。也就是生成的數據庫

高斯消元CDOJ1785 曜醬的線性代數課堂

++i for cnblogs mes swa eps mem else 正在 高斯消元求行列式板子。 #include<cstdio> #include<cmath> #include<algorithm> #include

集合框架JDK1.8源碼分析之HashMap 轉載

.get 修改 object set implement .com 功能 數組元素 帶來 一、前言   在分析jdk1.8後的HashMap源碼時,發現網上好多分析都是基於之前的jdk,而Java8的HashMap對之前做了較大的優化,其中最重要的一個優化就是桶中