【代码评审】BPM:ID 编码器
This commit is contained in:
parent
3cbe59ace3
commit
129e9868fb
|
@ -1,6 +1,7 @@
|
||||||
package cn.iocoder.yudao.module.bpm.dal.redis;
|
package cn.iocoder.yudao.module.bpm.dal.redis;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
@ -29,7 +30,6 @@ public class BpmProcessIdRedisDAO {
|
||||||
public String generate(BpmModelMetaInfoVO.ProcessIdRule processIdRule) {
|
public String generate(BpmModelMetaInfoVO.ProcessIdRule processIdRule) {
|
||||||
// 生成日期前缀
|
// 生成日期前缀
|
||||||
String infix = "";
|
String infix = "";
|
||||||
boolean expireEnable = true;
|
|
||||||
switch (processIdRule.getInfix()) {
|
switch (processIdRule.getInfix()) {
|
||||||
case "DAY":
|
case "DAY":
|
||||||
infix = DateUtil.format(LocalDateTime.now(), "yyyyMMDD");
|
infix = DateUtil.format(LocalDateTime.now(), "yyyyMMDD");
|
||||||
|
@ -43,16 +43,14 @@ public class BpmProcessIdRedisDAO {
|
||||||
case "SECOND":
|
case "SECOND":
|
||||||
infix = DateUtil.format(LocalDateTime.now(), "yyyyMMDDHHmmss");
|
infix = DateUtil.format(LocalDateTime.now(), "yyyyMMDDHHmmss");
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
expireEnable = false;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成序号
|
// 生成序号
|
||||||
String noPrefix = processIdRule.getPrefix() + infix + processIdRule.getPostfix();
|
String noPrefix = processIdRule.getPrefix() + infix + processIdRule.getPostfix();
|
||||||
String key = RedisKeyConstants.BPM_PROCESS_ID + noPrefix;
|
String key = RedisKeyConstants.BPM_PROCESS_ID + noPrefix;
|
||||||
Long no = stringRedisTemplate.opsForValue().increment(key);
|
Long no = stringRedisTemplate.opsForValue().increment(key);
|
||||||
if (Boolean.TRUE.equals(expireEnable)) {
|
if (StrUtil.isEmpty(infix)) {
|
||||||
|
// 特殊:没有前缀,则不能过期,不能每次都是从 0 开始
|
||||||
stringRedisTemplate.expire(key, Duration.ofDays(1L));
|
stringRedisTemplate.expire(key, Duration.ofDays(1L));
|
||||||
}
|
}
|
||||||
return noPrefix + String.format("%0" + processIdRule.getLength() + "d", no);
|
return noPrefix + String.format("%0" + processIdRule.getLength() + "d", no);
|
||||||
|
|
Loading…
Reference in New Issue