流程引擎骨架:INodeHandler接口 + NodeResult + 6个节点handler stub
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
package com.ruoyi.wcs.flow.engine;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程节点处理器接口
|
||||||
|
* 每种节点类型(start/api/plc/condition/wait/end)各实现一个
|
||||||
|
*/
|
||||||
|
public interface INodeHandler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 获取节点类型标识
|
||||||
|
*/
|
||||||
|
String getNodeType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行节点逻辑
|
||||||
|
*
|
||||||
|
* @param configJson 节点配置JSON
|
||||||
|
* @param context 流程上下文(可传递变量)
|
||||||
|
* @return 执行结果,包含 success 标志和输出数据
|
||||||
|
*/
|
||||||
|
NodeResult execute(String configJson, Map<String, Object> context);
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.ruoyi.wcs.flow.engine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点执行结果
|
||||||
|
*/
|
||||||
|
public class NodeResult
|
||||||
|
{
|
||||||
|
/** 是否成功 */
|
||||||
|
private boolean success;
|
||||||
|
|
||||||
|
/** 输出数据(JSON字符串) */
|
||||||
|
private String output;
|
||||||
|
|
||||||
|
/** 错误信息 */
|
||||||
|
private String errorMsg;
|
||||||
|
|
||||||
|
/** 下一个节点的条件分支标识(condition节点用) */
|
||||||
|
private String branchKey;
|
||||||
|
|
||||||
|
public static NodeResult ok(String output)
|
||||||
|
{
|
||||||
|
NodeResult r = new NodeResult();
|
||||||
|
r.success = true;
|
||||||
|
r.output = output;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NodeResult fail(String errorMsg)
|
||||||
|
{
|
||||||
|
NodeResult r = new NodeResult();
|
||||||
|
r.success = false;
|
||||||
|
r.errorMsg = errorMsg;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSuccess() { return success; }
|
||||||
|
public void setSuccess(boolean success) { this.success = success; }
|
||||||
|
public String getOutput() { return output; }
|
||||||
|
public void setOutput(String output) { this.output = output; }
|
||||||
|
public String getErrorMsg() { return errorMsg; }
|
||||||
|
public void setErrorMsg(String errorMsg) { this.errorMsg = errorMsg; }
|
||||||
|
public String getBranchKey() { return branchKey; }
|
||||||
|
public void setBranchKey(String branchKey) { this.branchKey = branchKey; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.ruoyi.wcs.flow.engine.handler;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import com.ruoyi.wcs.flow.engine.INodeHandler;
|
||||||
|
import com.ruoyi.wcs.flow.engine.NodeResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API调用节点处理器
|
||||||
|
* TODO: 后续对接 WcsApiConfig,通过 RestTemplate 调用外部接口
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class ApiNodeHandler implements INodeHandler
|
||||||
|
{
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ApiNodeHandler.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNodeType() { return "api"; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeResult execute(String configJson, Map<String, Object> context)
|
||||||
|
{
|
||||||
|
log.info("[FlowEngine] API调用节点执行, config={}", configJson);
|
||||||
|
// TODO: 解析 configJson 获取 apiCode,查询 WcsApiConfig,发起 HTTP 请求
|
||||||
|
return NodeResult.ok("{\"msg\":\"api call stub\"}");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.ruoyi.wcs.flow.engine.handler;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import com.ruoyi.wcs.flow.engine.INodeHandler;
|
||||||
|
import com.ruoyi.wcs.flow.engine.NodeResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 条件判断节点处理器
|
||||||
|
* TODO: 后续解析 conditionExpr 表达式,返回分支标识
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class ConditionNodeHandler implements INodeHandler
|
||||||
|
{
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ConditionNodeHandler.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNodeType() { return "condition"; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeResult execute(String configJson, Map<String, Object> context)
|
||||||
|
{
|
||||||
|
log.info("[FlowEngine] 条件判断节点执行, config={}", configJson);
|
||||||
|
// TODO: 解析条件表达式,根据 context 变量判断走哪个分支
|
||||||
|
NodeResult result = NodeResult.ok("condition evaluated");
|
||||||
|
result.setBranchKey("default");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.ruoyi.wcs.flow.engine.handler;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import com.ruoyi.wcs.flow.engine.INodeHandler;
|
||||||
|
import com.ruoyi.wcs.flow.engine.NodeResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结束节点处理器
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class EndNodeHandler implements INodeHandler
|
||||||
|
{
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(EndNodeHandler.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNodeType() { return "end"; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeResult execute(String configJson, Map<String, Object> context)
|
||||||
|
{
|
||||||
|
log.info("[FlowEngine] 结束节点执行");
|
||||||
|
return NodeResult.ok("flow ended");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.ruoyi.wcs.flow.engine.handler;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import com.ruoyi.wcs.flow.engine.INodeHandler;
|
||||||
|
import com.ruoyi.wcs.flow.engine.NodeResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PLC读写节点处理器
|
||||||
|
* TODO: 后续对接 PLC 统一读写服务
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class PlcNodeHandler implements INodeHandler
|
||||||
|
{
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(PlcNodeHandler.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNodeType() { return "plc"; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeResult execute(String configJson, Map<String, Object> context)
|
||||||
|
{
|
||||||
|
log.info("[FlowEngine] PLC读写节点执行, config={}", configJson);
|
||||||
|
// TODO: 解析 configJson 获取设备点位,读写 PLC
|
||||||
|
return NodeResult.ok("{\"msg\":\"plc rw stub\"}");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.ruoyi.wcs.flow.engine.handler;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import com.ruoyi.wcs.flow.engine.INodeHandler;
|
||||||
|
import com.ruoyi.wcs.flow.engine.NodeResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始节点处理器
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class StartNodeHandler implements INodeHandler
|
||||||
|
{
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(StartNodeHandler.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNodeType() { return "start"; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeResult execute(String configJson, Map<String, Object> context)
|
||||||
|
{
|
||||||
|
log.info("[FlowEngine] 开始节点执行");
|
||||||
|
return NodeResult.ok("flow started");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.ruoyi.wcs.flow.engine.handler;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import com.ruoyi.wcs.flow.engine.INodeHandler;
|
||||||
|
import com.ruoyi.wcs.flow.engine.NodeResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 等待节点处理器
|
||||||
|
* TODO: 后续实现轮询等待条件满足(如等待PLC信号)
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class WaitNodeHandler implements INodeHandler
|
||||||
|
{
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(WaitNodeHandler.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNodeType() { return "wait"; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeResult execute(String configJson, Map<String, Object> context)
|
||||||
|
{
|
||||||
|
log.info("[FlowEngine] 等待节点执行, config={}", configJson);
|
||||||
|
// TODO: 解析等待条件,轮询直到满足或超时
|
||||||
|
return NodeResult.ok("wait completed");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user