初始化提交
This commit is contained in:
22
cooperop-base-workflow/pom.xml
Normal file
22
cooperop-base-workflow/pom.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>cooperop-demo-base</artifactId>
|
||||
<groupId>business.chaoran</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>cooperop-base-workflow</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.snakerflow-starter</groupId>
|
||||
<artifactId>snakerflow-spring-boot-starter</artifactId>
|
||||
<version>1.0.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,37 @@
|
||||
package business.cooperop.base.workflow.snakerflow;
|
||||
|
||||
/*
|
||||
**********************************************
|
||||
* DATE PERSON REASON
|
||||
* 2020-11-25 FXY Created
|
||||
**********************************************
|
||||
*/
|
||||
|
||||
|
||||
import org.snaker.engine.SnakerEngine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SnakerEngineBaseService {
|
||||
/**
|
||||
* 初始化状态机流程
|
||||
*
|
||||
* @return 流程主键
|
||||
* @param relativePath
|
||||
*/
|
||||
String initFlows(String relativePath);
|
||||
|
||||
/**
|
||||
* 获得执行引擎
|
||||
*
|
||||
* @return SnakerEngine
|
||||
*/
|
||||
SnakerEngine getEngine();
|
||||
|
||||
/**
|
||||
* 获得所有流程的名字
|
||||
*
|
||||
* @return List<String>
|
||||
*/
|
||||
List<String> getAllProcessNames();
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
package business.cooperop.base.workflow.snakerflow;
|
||||
|
||||
/*
|
||||
**********************************************
|
||||
* DATE PERSON REASON
|
||||
* 2020-11-25 FXY Created
|
||||
**********************************************
|
||||
*/
|
||||
|
||||
|
||||
import org.snaker.engine.entity.Order;
|
||||
import org.snaker.engine.entity.Process;
|
||||
import org.snaker.engine.entity.Task;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface SnakerEngineService extends SnakerEngineBaseService {
|
||||
|
||||
/**
|
||||
* 获得所有有效流程
|
||||
*
|
||||
* @return List<Process>
|
||||
*/
|
||||
List<Process> getAllProcess();
|
||||
|
||||
/**
|
||||
* 通过orderId 获得流程
|
||||
*
|
||||
* @param orderId 流程实例Id
|
||||
* @return List<Process>
|
||||
*/
|
||||
List<Process> getProcessByOrderId(String orderId);
|
||||
|
||||
/**
|
||||
* 通过processId发起一个流程实例
|
||||
*
|
||||
* @param processId 流程ID
|
||||
* @param operator 操作人
|
||||
* @param args 自定义参数
|
||||
* @return Order流程实例
|
||||
*/
|
||||
Order startInstanceById(String processId, String operator, Map<String, Object> args);
|
||||
|
||||
/**
|
||||
* 通过process name发起一个流程实例
|
||||
*
|
||||
* @param name 流程 name
|
||||
* @param operator 操作人
|
||||
* @param args 自定义参数
|
||||
* @return Order流程实例
|
||||
*/
|
||||
Order startInstanceByName(String name, Integer version, String operator, Map<String, Object> args);
|
||||
|
||||
/**
|
||||
* 执行流程实例
|
||||
*
|
||||
* @param name 流程 name
|
||||
* @param version 版本
|
||||
* @param operator 操作人
|
||||
* @param args 自定义参数
|
||||
* @return Order流程实例
|
||||
*/
|
||||
Order startAndExecute(String name, Integer version, String operator, Map<String, Object> args);
|
||||
|
||||
/**
|
||||
* 执行流程实例
|
||||
*
|
||||
* @param processId 流程Id
|
||||
* @param operator 操作人
|
||||
* @param args 自定义参数
|
||||
* @return Order流程实例
|
||||
*/
|
||||
Order startAndExecute(String processId, String operator, Map<String, Object> args);
|
||||
|
||||
/**
|
||||
* 通过taskId执行
|
||||
*
|
||||
* @param taskId 任务Id
|
||||
* @param operator 操作人
|
||||
* @param args 自定义参数
|
||||
* @return List<Task>
|
||||
*/
|
||||
List<Task> execute(String taskId, String operator, Map<String, Object> args);
|
||||
|
||||
/**
|
||||
* 流程跳转
|
||||
*
|
||||
* @param taskId 任务Id
|
||||
* @param operator 操作人
|
||||
* @param args 自定义参数
|
||||
* @param nodeName 跳转到的节点名称
|
||||
* @return List<Task>
|
||||
*/
|
||||
List<Task> executeAndJump(String taskId, String operator, Map<String, Object> args, String nodeName);
|
||||
|
||||
/**
|
||||
* 通过orderId获取对应的流程task
|
||||
*
|
||||
* @param orderId 流程实例Id
|
||||
* @return List<Task>
|
||||
*/
|
||||
List<Task> getTasks(String orderId);
|
||||
}
|
||||
@ -0,0 +1,212 @@
|
||||
/* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package business.cooperop.base.workflow.snakerflow;
|
||||
|
||||
import org.snaker.engine.SnakerEngine;
|
||||
import org.snaker.engine.access.QueryFilter;
|
||||
import org.snaker.engine.entity.Order;
|
||||
import org.snaker.engine.entity.Process;
|
||||
import org.snaker.engine.entity.Task;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* SnakerEngineFacets封装snakerflow基本操作,可以直接使用
|
||||
*
|
||||
* @author zhaoguoqing
|
||||
* @since 0.1
|
||||
*/
|
||||
@Component
|
||||
public class SnakerEngineServiceImpl implements SnakerEngineService {
|
||||
@Autowired
|
||||
private SnakerEngine engine;
|
||||
|
||||
/**
|
||||
* 初始化状态机流程
|
||||
*
|
||||
* @return 流程主键
|
||||
* @param relativePath 相对路径
|
||||
*/
|
||||
@Override
|
||||
public String initFlows(String relativePath) {
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
InputStream stream = classLoader.getResourceAsStream(relativePath);
|
||||
String deploy = engine.process().deploy(stream);
|
||||
return deploy;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得所有有效流程
|
||||
*
|
||||
* @return List<Process>
|
||||
*/
|
||||
@Override
|
||||
public List<Process> getAllProcess() {
|
||||
QueryFilter filter = new QueryFilter();
|
||||
return engine.process().getProcesss(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过orderId 获得流程
|
||||
*
|
||||
* @param orderId 流程实例Id
|
||||
* @return List<Process>
|
||||
*/
|
||||
@Override
|
||||
public List<Process> getProcessByOrderId(String orderId) {
|
||||
QueryFilter filter = new QueryFilter();
|
||||
filter.setOrderId(orderId);
|
||||
return engine.process().getProcesss(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得执行引擎
|
||||
*
|
||||
* @return SnakerEngine
|
||||
*/
|
||||
@Override
|
||||
public SnakerEngine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得所有流程的名字
|
||||
*
|
||||
* @return List<String>
|
||||
*/
|
||||
@Override
|
||||
public List<String> getAllProcessNames() {
|
||||
List<Process> list = engine.process().getProcesss(new QueryFilter());
|
||||
List<String> names = new ArrayList<>();
|
||||
for (Process entity : list) {
|
||||
if (names.contains(entity.getName())) {
|
||||
continue;
|
||||
} else {
|
||||
names.add(entity.getName());
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过processId发起一个流程实例
|
||||
*
|
||||
* @param processId 流程ID
|
||||
* @param operator 操作人
|
||||
* @param args 自定义参数
|
||||
* @return Order流程实例
|
||||
*/
|
||||
@Override
|
||||
public Order startInstanceById(String processId, String operator, Map<String, Object> args) {
|
||||
return engine.startInstanceById(processId, operator, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过process name发起一个流程实例
|
||||
*
|
||||
* @param name 流程 name
|
||||
* @param operator 操作人
|
||||
* @param args 自定义参数
|
||||
* @return Order流程实例
|
||||
*/
|
||||
@Override
|
||||
public Order startInstanceByName(String name, Integer version, String operator, Map<String, Object> args) {
|
||||
return engine.startInstanceByName(name, version, operator, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行流程实例
|
||||
*
|
||||
* @param name 流程 name
|
||||
* @param version 版本
|
||||
* @param operator 操作人
|
||||
* @param args 自定义参数
|
||||
* @return Order流程实例
|
||||
*/
|
||||
@Override
|
||||
public Order startAndExecute(String name, Integer version, String operator, Map<String, Object> args) {
|
||||
Order order = engine.startInstanceByName(name, version, operator, args);
|
||||
List<Task> tasks = engine.query().getActiveTasks(new QueryFilter().setOrderId(order.getId()));
|
||||
List<Task> newTasks = new ArrayList<Task>();
|
||||
if (tasks != null && tasks.size() > 0) {
|
||||
Task task = tasks.get(0);
|
||||
newTasks.addAll(engine.executeTask(task.getId(), operator, args));
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行流程实例
|
||||
*
|
||||
* @param processId 流程Id
|
||||
* @param operator 操作人
|
||||
* @param args 自定义参数
|
||||
* @return Order流程实例
|
||||
*/
|
||||
@Override
|
||||
public Order startAndExecute(String processId, String operator, Map<String, Object> args) {
|
||||
Order order = engine.startInstanceById(processId, operator, args);
|
||||
List<Task> tasks = engine.query().getActiveTasks(new QueryFilter().setOrderId(order.getId()));
|
||||
List<Task> newTasks = new ArrayList<Task>();
|
||||
if (tasks != null && tasks.size() > 0) {
|
||||
Task task = tasks.get(0);
|
||||
newTasks.addAll(engine.executeTask(task.getId(), operator, args));
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过taskId执行
|
||||
*
|
||||
* @param taskId 任务Id
|
||||
* @param operator 操作人
|
||||
* @param args 自定义参数
|
||||
* @return List<Task>
|
||||
*/
|
||||
@Override
|
||||
public List<Task> execute(String taskId, String operator, Map<String, Object> args) {
|
||||
return engine.executeTask(taskId, operator, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* 流程跳转
|
||||
*
|
||||
* @param taskId 任务Id
|
||||
* @param operator 操作人
|
||||
* @param args 自定义参数
|
||||
* @param nodeName 跳转到的节点名称
|
||||
* @return List<Task>
|
||||
*/
|
||||
@Override
|
||||
public List<Task> executeAndJump(String taskId, String operator, Map<String, Object> args, String nodeName) {
|
||||
return engine.executeAndJumpTask(taskId, operator, args, nodeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过orderId获取对应的流程task
|
||||
*
|
||||
* @param orderId 流程实例Id
|
||||
* @return List<Task>
|
||||
*/
|
||||
@Override
|
||||
public List<Task> getTasks(String orderId) {
|
||||
return engine.query().getActiveTasks(new QueryFilter().setOrderId(orderId));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
package business.cooperop.base.workflow.snakerflow.config;
|
||||
|
||||
/*
|
||||
**********************************************
|
||||
* DATE PERSON REASON
|
||||
* 2020-11-25 FXY Created
|
||||
**********************************************
|
||||
*/
|
||||
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.snaker.engine.DBAccess;
|
||||
import org.snaker.engine.access.mybatis.MybatisAccess;
|
||||
import org.snaker.engine.cache.CacheManager;
|
||||
import org.snaker.engine.cache.memory.MemoryCacheManager;
|
||||
import org.snaker.engine.core.*;
|
||||
import org.snaker.engine.impl.LogInterceptor;
|
||||
import org.snaker.engine.spring.SpelExpression;
|
||||
import org.snaker.engine.spring.SpringSnakerEngine;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class BeanConfig {
|
||||
|
||||
@Bean("engine")
|
||||
public SpringSnakerEngine springSnakerEngine(ProcessService processService, OrderService orderService,
|
||||
TaskService taskService, QueryService queryService, ManagerService managerService) {
|
||||
|
||||
SpringSnakerEngine springSnakerEngine = new SpringSnakerEngine();
|
||||
springSnakerEngine.setProcessService(processService);
|
||||
springSnakerEngine.setOrderService(orderService);
|
||||
springSnakerEngine.setTaskService(taskService);
|
||||
springSnakerEngine.setQueryService(queryService);
|
||||
springSnakerEngine.setManagerService(managerService);
|
||||
return springSnakerEngine;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ProcessService processService(DBAccess dbAccess, CacheManager cacheManager) {
|
||||
ProcessService processService=new ProcessService();
|
||||
processService.setCacheManager(cacheManager);
|
||||
processService.setAccess(dbAccess);
|
||||
return processService;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public OrderService orderService(DBAccess dbAccess) {
|
||||
OrderService orderService = new OrderService();
|
||||
orderService.setAccess(dbAccess);
|
||||
return orderService;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskService taskService(DBAccess dbAccess) {
|
||||
TaskService taskService = new TaskService();
|
||||
taskService.setAccess(dbAccess);
|
||||
return taskService;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public QueryService queryService(DBAccess dbAccess) {
|
||||
QueryService queryService = new QueryService();
|
||||
queryService.setAccess(dbAccess);
|
||||
return queryService;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ManagerService managerService(DBAccess dbAccess) {
|
||||
ManagerService managerService = new ManagerService();
|
||||
managerService.setAccess(dbAccess);
|
||||
return managerService;
|
||||
}
|
||||
|
||||
@Bean("snakerCacheManager")
|
||||
public MemoryCacheManager memoryCacheManager(){
|
||||
return new MemoryCacheManager();
|
||||
}
|
||||
|
||||
@Bean("logInterceptor")
|
||||
public LogInterceptor logInterceptor(){
|
||||
return new LogInterceptor();
|
||||
}
|
||||
|
||||
@Bean("spelExpression")
|
||||
public SpelExpression spelExpression(){
|
||||
return new SpelExpression();
|
||||
}
|
||||
|
||||
@Bean("dbAccess")
|
||||
public MybatisAccess mybatisAccess(SqlSessionFactory sqlSessionFactory){
|
||||
MybatisAccess mybatisAccess=new MybatisAccess();
|
||||
mybatisAccess.setSqlSessionFactory(sqlSessionFactory);
|
||||
return mybatisAccess;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user