From 449a7759beeb8df5459b3c124777f493eb2a4d2d Mon Sep 17 00:00:00 2001 From: zhangdaiscott Date: Mon, 25 Jan 2021 18:31:46 +0800 Subject: [PATCH] =?UTF-8?q?JeecgBoot=202.4.2=20=E7=A7=AF=E6=9C=A8=E6=8A=A5?= =?UTF-8?q?=E8=A1=A8=E7=89=88=E6=9C=AC=E5=8F=91=E5=B8=83=EF=BC=8C=E5=9F=BA?= =?UTF-8?q?=E4=BA=8ESpringBoot=E7=9A=84=E4=BD=8E=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/system/rule/OrderNumberRule.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/rule/OrderNumberRule.java diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/rule/OrderNumberRule.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/rule/OrderNumberRule.java new file mode 100644 index 00000000..24b2f1b5 --- /dev/null +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/rule/OrderNumberRule.java @@ -0,0 +1,36 @@ +package org.jeecg.modules.system.rule; + +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.math.RandomUtils; +import org.jeecg.common.handler.IFillRuleHandler; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * 填值规则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; + } + +} -- GitLab