Java接口说明

package fx.custom.apl.example.validate_function;

import com.fxiaoke.functions.FunctionContext;
import com.fxiaoke.functions.Fx;
import com.fxiaoke.functions.client.DebugHelper;
import com.fxiaoke.functions.model.ValidateResult;
import com.fxiaoke.functions.template.IValidateAction;
import fx.custom.apl.example.flow.FlowValidateExample;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 校验函数使用样例
 * 校验函数返回值字段含义介绍
 */
public class ValidateExample implements IValidateAction {
    /**
     * 校验函数的运行方法
     */
    @Override
    public ValidateResult validate(FunctionContext context, Map<String, Object> args) {
        Map data = context.getData();
        String type = String.valueOf(data.get("filed_afgsd__c"));
        if (Objects.equals("sign", type)) {
            ValidateResult valid = ValidateResult.builder()
                    .success(true)
                    .build();
            return valid;
        }

        ValidateResult valid = ValidateResult.builder()
                .success(false)                    //校验是否通过
                .errorMessage("类型错误")       //success为false时的错误信息(阻塞后续操作)
                .nonBlockMessage("xxx为空")        //success为false时的错误信息(不阻塞后续操作)和errorMessage两者选填一个就行
                .data("5ecf2029903bc400019dd8cb") //非必填, 用来做阶段跳转校验的,放可以跳转的阶段ID
                .build();
        return valid;
    }


    public static void main(String[] args) throws IOException {
        //调试器
        DebugHelper helper = new DebugHelper();
        helper.init();
        Map<String, Object> param = new HashMap<>();
        //构造当前执行类
        //模拟调试的上下文,例如开发时想模拟一个客户对象的上下文,以方便开发
        FunctionContext context = helper.context("AccountObj", "63100e7915d6a300017121cc");
        ValidateResult validate = new FlowValidateExample().validate(context, param);
        Fx.log.info(validate);
    }
}


2024-10-22
1 0