@Slf4j
@Component
public class MyCustomNode implements WorkflowNode<MyCustomContext> {
@Override
public String getNodeName() {
return this.getClass().getSimpleName();
}
@Override
public Class<MyCustomContext> getContextType() {
return MyCustomContext.class;
}
@Override
public Map<String, Object> process(MyCustomContext context, Map<String, Object> state) {
// 参数验证
BaseContext.ValidationResult validationResult = BaseContext.validateParams(
context.getParamSchemas(),
context.getParams(),
CommonParamFields.INPUT
);
if (!validationResult.isValid()) {
throw new RuntimeException("表单校验失败: " + validationResult.getFirstError());
}
// 获取参数
String input = context.getInput(state);
String customParam = context.getCustomParam(state);
Integer numberParam = context.getNumberParam(state);
// 业务逻辑处理
String result = processBusinessLogic(input, customParam, numberParam);
// 返回结果
return WorkflowState.addStringMessage(state, result, context.getId());
}
private String processBusinessLogic(String input, String customParam, Integer numberParam) {
log.info("处理输入: {}, 自定义参数: {}, 数值参数: {}", input, customParam, numberParam);
return String.format("处理结果: %s + %s + %d", input, customParam, numberParam);
}
}