Commit 129e9868fb104ca2d771920562e3a91ea3dfdc8d

Authored by YunaiV
1 parent 3cbe59ac

【代码评审】BPM:ID 编码器

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