add: 新增 ruoyi-common-liteflow 规则引擎模块

This commit is contained in:
疯狂的狮子Li
2026-07-02 14:37:53 +08:00
parent 6876bd355f
commit 53f857714d
11 changed files with 218 additions and 0 deletions
+8
View File
@@ -63,6 +63,7 @@
<sms4j.version>3.3.5</sms4j.version>
<!-- 工作流配置 -->
<warm-flow.version>1.8.8</warm-flow.version>
<liteflow.version>2.16.0</liteflow.version>
<!-- mqtt客户端 -->
<mica-mqtt.version>2.6.6</mica-mqtt.version>
@@ -358,6 +359,13 @@
<version>${warm-flow.version}</version>
</dependency>
<!-- LiteFlow 规则编排引擎 -->
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-spring-boot-starter</artifactId>
<version>${liteflow.version}</version>
</dependency>
<!-- mqtt客户端 -->
<dependency>
<groupId>org.dromara.mica-mqtt</groupId>
+1
View File
@@ -37,6 +37,7 @@
<module>ruoyi-common-json</module>
<module>ruoyi-common-encrypt</module>
<module>ruoyi-common-push</module>
<module>ruoyi-common-liteflow</module>
<module>ruoyi-common-mqtt</module>
<module>ruoyi-common-ai</module>
<module>ruoyi-common-mcp</module>
+7
View File
@@ -159,6 +159,13 @@
<version>${revision}</version>
</dependency>
<!-- liteflow模块 -->
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-liteflow</artifactId>
<version>${revision}</version>
</dependency>
<!-- mqtt模块 -->
<dependency>
<groupId>org.dromara</groupId>
@@ -0,0 +1,31 @@
<?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>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ruoyi-common-liteflow</artifactId>
<description>
ruoyi-common-liteflow LiteFlow规则编排模块
</description>
<dependencies>
<!-- 核心模块 -->
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-core</artifactId>
</dependency>
<!-- LiteFlow 规则编排 -->
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-spring-boot-starter</artifactId>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,19 @@
package org.dromara.common.liteflow.component;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeBooleanComponent;
/**
* LiteFlow 恒为 false 的条件节点。
*
* @author Lion Li
*/
@LiteflowComponent("alwaysFalse")
public class AlwaysFalseComponent extends NodeBooleanComponent {
@Override
public boolean processBoolean() {
return false;
}
}
@@ -0,0 +1,19 @@
package org.dromara.common.liteflow.component;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeBooleanComponent;
/**
* LiteFlow 恒为 true 的条件节点。
*
* @author Lion Li
*/
@LiteflowComponent("alwaysTrue")
public class AlwaysTrueComponent extends NodeBooleanComponent {
@Override
public boolean processBoolean() {
return true;
}
}
@@ -0,0 +1,22 @@
package org.dromara.common.liteflow.component;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.dromara.common.core.exception.ServiceException;
/**
* LiteFlow 上下文必填校验节点。
*
* @author Lion Li
*/
@LiteflowComponent("contextRequired")
public class ContextRequiredComponent extends NodeComponent {
@Override
public void process() {
if (getRequestData() == null) {
throw new ServiceException("LiteFlow 上下文不能为空");
}
}
}
@@ -0,0 +1,40 @@
package org.dromara.common.liteflow.component;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.liteflow.core.FailMessageProvider;
/**
* LiteFlow 失败节点,用于显式表达链路分支不可继续执行。
*
* @author Lion Li
*/
@LiteflowComponent("fail")
public class FailComponent extends NodeComponent {
private static final String DEFAULT_MESSAGE = "LiteFlow 链路执行失败";
@Override
public void process() {
throw new ServiceException(getFailMessage());
}
/**
* 优先从上下文读取业务失败提示,未提供时使用默认提示。
*
* @return 失败提示
*/
private String getFailMessage() {
Object requestData = getRequestData();
if (requestData instanceof FailMessageProvider provider) {
String message = provider.getFailMessage();
if (StringUtils.isNotBlank(message)) {
return message;
}
}
return DEFAULT_MESSAGE;
}
}
@@ -0,0 +1,19 @@
package org.dromara.common.liteflow.component;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
/**
* LiteFlow 空节点,用于显式表达无需处理的分支。
*
* @author Lion Li
*/
@LiteflowComponent("noop")
public class NoopComponent extends NodeComponent {
@Override
public void process() {
// no-op
}
}
@@ -0,0 +1,17 @@
package org.dromara.common.liteflow.core;
/**
* LiteFlow 失败提示提供者。
*
* @author Lion Li
*/
public interface FailMessageProvider {
/**
* 获取公共失败节点抛出的业务提示。
*
* @return 失败提示
*/
String getFailMessage();
}
@@ -0,0 +1,35 @@
package org.dromara.common.liteflow.utils;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.SpringUtils;
/**
* LiteFlow 执行工具。
*
* @author Lion Li
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class LiteFlowUtils {
/**
* 执行 LiteFlow 链路,并按业务异常语义透传失败原因。
*
* @param chainId 链路标识
* @param context 链路上下文
*/
public static void execute(String chainId, Object context) {
LiteflowResponse response = SpringUtils.getBean(FlowExecutor.class).execute2Resp(chainId, context);
if (!response.isSuccess()) {
Exception cause = response.getCause();
if (cause instanceof RuntimeException runtimeException) {
throw runtimeException;
}
throw new ServiceException(cause != null ? cause.getMessage() : response.getMessage());
}
}
}