Commit c1ea85fe01048e4abf3b420172e8302a10daa201
1 parent
7fbc47e7
JeecgBoot 2.4.2 积木报表版本发布,基于SpringBoot的低代码平台
Showing
1 changed file
with
36 additions
and
0 deletions
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/rule/OrderNumberRule.java
0 → 100644
1 | +package org.jeecg.modules.system.rule; | |
2 | + | |
3 | +import com.alibaba.fastjson.JSONObject; | |
4 | +import org.apache.commons.lang.StringUtils; | |
5 | +import org.apache.commons.lang.math.RandomUtils; | |
6 | +import org.jeecg.common.handler.IFillRuleHandler; | |
7 | + | |
8 | +import java.text.SimpleDateFormat; | |
9 | +import java.util.Date; | |
10 | + | |
11 | +/** | |
12 | + * 填值规则Demo:生成订单号 | |
13 | + * 【测试示例】 | |
14 | + */ | |
15 | +public class OrderNumberRule implements IFillRuleHandler { | |
16 | + | |
17 | + @Override | |
18 | + public Object execute(JSONObject params, JSONObject formData) { | |
19 | + String prefix = "CN"; | |
20 | + //订单前缀默认为CN 如果规则参数不为空,则取自定义前缀 | |
21 | + if (params != null) { | |
22 | + Object obj = params.get("prefix"); | |
23 | + if (obj != null) prefix = obj.toString(); | |
24 | + } | |
25 | + SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); | |
26 | + int random = RandomUtils.nextInt(90) + 10; | |
27 | + String value = prefix + format.format(new Date()) + random; | |
28 | + // 根据formData的值的不同,生成不同的订单号 | |
29 | + String name = formData.getString("name"); | |
30 | + if (!StringUtils.isEmpty(name)) { | |
31 | + value += name; | |
32 | + } | |
33 | + return value; | |
34 | + } | |
35 | + | |
36 | +} | |
... | ... |