1. 程式人生 > >flowable子流程實現

flowable子流程實現

flowable子流程
即在主流程之外去執行一個小的流程
注子流程可以套子流程

以下的我實現的流程圖:


以下是我的BPMN2.0的XML:

  <process id="XMSubProcessUS" name="TestsubProcessUS" isExecutable="true">
    <documentation>子流程</documentation>
    <startEvent id="Start" name="開始"></startEvent>
    <userTask id="usertask1" name="usertask1"></userTask>
    <sequenceFlow id="start-usertask1" sourceRef="Start" targetRef="usertask1"></sequenceFlow>
    <userTask id="usertask2" name="usertask2"></userTask>
    <endEvent id="end" name="結束"></endEvent>
    <sequenceFlow id="usertask2-end" sourceRef="usertask2" targetRef="end"></sequenceFlow>
    <subProcess id="subprocess" name="subprocess">
      <startEvent id="substart"></startEvent>
      <serviceTask id="subservicetask1" name="subservicetask1" flowable:class="cn.buba.flowable.submain.SubServiceTask1"></serviceTask>
      <userTask id="subusertask1" name="subusertask1"></userTask>
      <endEvent id="subend"></endEvent>
      <sequenceFlow id="subusertask1-subend" sourceRef="subusertask1" targetRef="subend"></sequenceFlow>
      <sequenceFlow id="substart-subservicetask1" sourceRef="substart" targetRef="subservicetask1"></sequenceFlow>
      <sequenceFlow id="subservicetask1-subusertask1" sourceRef="subservicetask1" targetRef="subusertask1"></sequenceFlow>
    </subProcess>
    <sequenceFlow id="sid-81152AB3-A7B7-4FBB-B83A-A7AA726A448D" sourceRef="usertask1" targetRef="subprocess"></sequenceFlow>
    <sequenceFlow id="sid-8CB3093A-815F-4433-9890-0163398C3D17" sourceRef="subprocess" targetRef="usertask2"></sequenceFlow>
  </process>


以下是我Java API 的程式設計程式碼:

		//主體流程的開始
		//建立資料庫連結資訊 連結 庫、使用者名稱、密碼  請自己編輯
		ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
		.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/******?characterEncoding=UTF-8")
		.setJdbcUsername("****")
		.setJdbcPassword("****")
		.setJdbcDriver("com.mysql.jdbc.Driver")
		.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE);
		// 通過資料庫連結資訊         建立Flowable流程引擎 Create Flowable process engine
		ProcessEngine processEngine = cfg.buildProcessEngine();
		// 獲取Flowable服務 Get Flowable repositoryService
		RepositoryService repositoryService = processEngine.getRepositoryService();
		// 獲取Flowable服務 Get Flowable runtimeService
		RuntimeService runtimeService = processEngine.getRuntimeService();
		// 獲取taskService物件 Get the first task
		TaskService taskService = processEngine.getTaskService();
		
		Deployment deploy = repositoryService.createDeployment().addClasspathResource("processes/US_ServiceTask/TestsubProcessUS.bpmn20.xml").deploy();
		ProcessInstance process = runtimeService.startProcessInstanceByKey("XMSubProcessUS");
		Task task = taskService.createTaskQuery().processInstanceId(process.getId()).singleResult();
		System.out.println("1 task is="+task);
		if (task!=null) {
			System.out.println("提交 task is="+task.getName());
			taskService.complete(task.getId());
		}
		task = taskService.createTaskQuery().processInstanceId(process.getId()).singleResult();
		System.out.println("2 taks is="+task);
		if (task!=null) {
			System.out.println("提交 task is="+task.getName());
			taskService.complete(task.getId());
		}
		
		task = taskService.createTaskQuery().processInstanceId(process.getId()).singleResult();
		System.out.println("3 task is="+task);
		if (task!=null) {
			System.out.println("提交 task is="+task.getName());
			taskService.complete(task.getId());
		}
		task = taskService.createTaskQuery().processInstanceId(process.getId()).singleResult();
		System.out.println("task is="+task);
		//關閉
		processEngine.close();
		System.exit(0);

以上是成功demo

以上如有問題可評論  我看到立馬回答

請不要所以轉載 !!!