fix: 无时间中缀不设置Redis过期时间

This commit is contained in:
LesanOuO 2025-01-27 09:25:57 +08:00
parent 362b872aa8
commit b4f93e832f
1 changed files with 7 additions and 1 deletions

View File

@ -29,6 +29,7 @@ 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");
@ -42,13 +43,18 @@ 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)) {
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);
} }