package cn.iocoder.yudao.module.bpm.dal.redis; import cn.iocoder.yudao.framework.common.util.number.BizNoUtils; import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO; import jakarta.annotation.Resource; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Repository; /** * BPM 流程 Id 编码的 Redis DAO * * @author Lesan */ @Repository public class BpmProcessIdRedisDAO { @Resource private StringRedisTemplate stringRedisTemplate; /** * 生成 16 位纯数字业务编码(全系统唯一)。 * *
为兼容既有调用方,保留 {@code processIdRule} 入参,但不再参与编码拼接。 * * @param processIdRule 流程 Id 规则(已不再参与编码拼接) * @return 16 位纯数字编码 */ public String generate(BpmModelMetaInfoVO.ProcessIdRule processIdRule) { // 全系统共用同一自增序列,保证编码「16 位纯数字」且全系统唯一 // 随机生成 16 位纯数字编码,并用 Redis 集合查重,保证全系统唯一(不使用自增/顺序) for (int i = 0; i < BizNoUtils.MAX_RETRY; i++) { String code = BizNoUtils.randomCode(); Long added = stringRedisTemplate.opsForSet().add(BizNoUtils.USED_SET_KEY, code); if (added != null && added > 0) { return code; } } throw new IllegalStateException("生成唯一业务编码失败,请重试"); } }