系统编码规则如何使用 - xinwu-yang/cube-java GitHub Wiki

功能介绍

自动生成规则编码,比如: 订单号的生成,前缀+年月日时分秒,时间戳等

使用步骤

实现接口 IFillRuleHandler

/**
 * 填值规则Demo:生成订单号
 * 【测试示例】
 */
public class OrderNumberRule implements IFillRuleHandler {

    @Override
    public Object execute(JSONObject params, JSONObject formData) {
        String prefix = "CN";
        //订单前缀默认为CN 如果规则参数不为空,则取自定义前缀
        if (params != null) {
            Object obj = params.get("prefix");
            if (obj != null) prefix = obj.toString();
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        int random = RandomUtils.nextInt(90) + 10;
        String value = prefix + format.format(new Date()) + random;
        // 根据formData的值的不同,生成不同的订单号
        String name = formData.getString("name");
        if (!StringUtils.isEmpty(name)) {
            value += name;
        }
        return value;
    }

}

在【在线开发】-》【系统编码规则】中添加

通过接口执行规则生成

通过 ruleCode 执行自定义填值规则

维护人:杨欣武

URL

描述:通过 ruleCode 执行自定义填值规则

ContentType:application/json

Path参数
名称 必填 描述 示例值
ruleCode 要执行的填值规则编码 74486
请求头
名称 必填 描述 示例值
X-Access-Token 鉴权Token 6242b39f-22bf-4312-9ad8-009004279362
请求参数
Body Parameter
名称 类型 必填 最大长度 描述 示例值
containerNode boolean - No comments found. true
valueNode boolean - No comments found. true
missingNode boolean - No comments found. true
object boolean - No comments found. true
array boolean - No comments found. true
请求示例
{
    "containerNode": true,
    "valueNode": true,
    "missingNode": true,
    "object": true,
    "array": true
}
响应参数
名称 类型 必填 最大长度 描述 示例值
success boolean - No comments found. true
message string - No comments found. success
code int32 - No comments found. 701
result object - No comments found.
timestamp int64 - No comments found. 1657603695567
响应示例
{
    "success": true,
    "message": "success",
    "code": 701,
    "result": {},
    "timestamp": 1657603695567
}