Spring Boot 整合 Activiti 工作流引擎 極簡教程

專注的阿熊發表於2021-06-24

package com.example.actividemo;

import org.activiti.engine.HistoryService;

import org.activiti.engine.RepositoryService;

import org.activiti.engine.RuntimeService;

import org.activiti.engine.TaskService;

import org.activiti.engine.repository.DeploymentBuilder;

import org.activiti.engine.runtime.ProcessInstance;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import java.util.List;

@Service("activityService")

public class ActivityConsumerServiceImpl implements ActivityConsumerService {

     @Autowired

     private RuntimeService runtimeService;

     @Autowired

     private TaskService taskService;

     @Autowired

     private HistoryService historyService;

     @Autowired

     private RepositoryService repositoryService;

     /**

      * 註冊一個流程

      *

      * @return

      */

     @Override

     public boolean createDeployment() {

         DeploymentBuilder builder =外匯跟單gendan5.com repositoryService.createDeployment();

         builder.addClasspathResource("test01.bpmn20.xml");

         builder.deploy();

         return true;

     }

     /**

      * 查詢待辦

      *

      * @return

      */

     public List getTaskList() {

         return historyService.createHistoricActivityInstanceQuery().list();

     }

     /**

      * 根據流程 key 開啟一個流程

      *

      * @param key

      * @return

      */

     @Override

     public boolean startActivityDemo(String key) {

         ProcessInstance test01 = runtimeService.startProcessInstanceByKey(key);

         String id = test01.getId();

         System.out.println(" 流程 id=" + id);

         return true;

     }

     /**

      * 根據任務 id 提交任務

      *

      * @param taskId

      * @return

      */

     @Override

     public boolean complete(String taskId) {

         taskService.complete(taskId);

         return true;

     }

     /**

      * 根據流程 id 直接結束流程

      *

      * @param runId

      * @return

      */

     @Override

     public boolean deleteProcessInstance(String runId) {

         runtimeService.deleteProcessInstance(runId, " 結束 ");

         return true;

     }

}


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69946337/viewspace-2778197/,如需轉載,請註明出處,否則將追究法律責任。

相關文章