Commit 129e9868fb104ca2d771920562e3a91ea3dfdc8d
1 parent
3cbe59ac
【代码评审】BPM:ID 编码器
Showing
1 changed file
with
3 additions
and
5 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/redis/BpmProcessIdRedisDAO.java
| 1 | package cn.iocoder.yudao.module.bpm.dal.redis; | 1 | package cn.iocoder.yudao.module.bpm.dal.redis; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.date.DateUtil; | 3 | import cn.hutool.core.date.DateUtil; |
| 4 | +import cn.hutool.core.util.StrUtil; | ||
| 4 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO; | 5 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO; |
| 5 | import jakarta.annotation.Resource; | 6 | import jakarta.annotation.Resource; |
| 6 | import org.springframework.data.redis.core.StringRedisTemplate; | 7 | import org.springframework.data.redis.core.StringRedisTemplate; |
| @@ -29,7 +30,6 @@ public class BpmProcessIdRedisDAO { | @@ -29,7 +30,6 @@ public class BpmProcessIdRedisDAO { | ||
| 29 | public String generate(BpmModelMetaInfoVO.ProcessIdRule processIdRule) { | 30 | public String generate(BpmModelMetaInfoVO.ProcessIdRule processIdRule) { |
| 30 | // 生成日期前缀 | 31 | // 生成日期前缀 |
| 31 | String infix = ""; | 32 | String infix = ""; |
| 32 | - boolean expireEnable = true; | ||
| 33 | switch (processIdRule.getInfix()) { | 33 | switch (processIdRule.getInfix()) { |
| 34 | case "DAY": | 34 | case "DAY": |
| 35 | infix = DateUtil.format(LocalDateTime.now(), "yyyyMMDD"); | 35 | infix = DateUtil.format(LocalDateTime.now(), "yyyyMMDD"); |
| @@ -43,16 +43,14 @@ public class BpmProcessIdRedisDAO { | @@ -43,16 +43,14 @@ public class BpmProcessIdRedisDAO { | ||
| 43 | case "SECOND": | 43 | case "SECOND": |
| 44 | infix = DateUtil.format(LocalDateTime.now(), "yyyyMMDDHHmmss"); | 44 | infix = DateUtil.format(LocalDateTime.now(), "yyyyMMDDHHmmss"); |
| 45 | break; | 45 | break; |
| 46 | - default: | ||
| 47 | - expireEnable = false; | ||
| 48 | - break; | ||
| 49 | } | 46 | } |
| 50 | 47 | ||
| 51 | // 生成序号 | 48 | // 生成序号 |
| 52 | String noPrefix = processIdRule.getPrefix() + infix + processIdRule.getPostfix(); | 49 | String noPrefix = processIdRule.getPrefix() + infix + processIdRule.getPostfix(); |
| 53 | String key = RedisKeyConstants.BPM_PROCESS_ID + noPrefix; | 50 | String key = RedisKeyConstants.BPM_PROCESS_ID + noPrefix; |
| 54 | Long no = stringRedisTemplate.opsForValue().increment(key); | 51 | Long no = stringRedisTemplate.opsForValue().increment(key); |
| 55 | - if (Boolean.TRUE.equals(expireEnable)) { | 52 | + if (StrUtil.isEmpty(infix)) { |
| 53 | + // 特殊:没有前缀,则不能过期,不能每次都是从 0 开始 | ||
| 56 | stringRedisTemplate.expire(key, Duration.ofDays(1L)); | 54 | stringRedisTemplate.expire(key, Duration.ofDays(1L)); |
| 57 | } | 55 | } |
| 58 | return noPrefix + String.format("%0" + processIdRule.getLength() + "d", no); | 56 | return noPrefix + String.format("%0" + processIdRule.getLength() + "d", no); |