| | |
| | | package com.ltkj.common.utils; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | public class IdUtils { |
| | | |
| | | private static final String LIS_LAST_ID_KEY = "id:generate:lis:id"; |
| | | private static final String LIS_LAST_ID_INCR_KEY = "id:generate:lis:id:incr"; |
| | | private static final String LIS_CURRENT_DATE_KEY = "id:generate:lis:currentDate"; |
| | | |
| | | // private static final UidGenerator uidGenerator = new DefaultUidGenerator(); // 使用默认的Snowflake生成器 |
| | |
| | | return String.format(prefix+"%s%05d", yyMMdd, lastId); |
| | | } |
| | | |
| | | /** |
| | | * 生成无限递增条码号 |
| | | * @param prefix |
| | | * @return |
| | | */ |
| | | public synchronized String generateLisNextId(String prefix){ |
| | | String lastIdStr = stringRedisTemplate.opsForValue().get(LIS_LAST_ID_INCR_KEY); |
| | | int current; |
| | | if (StrUtil.isBlank(lastIdStr)) { |
| | | current = 1; |
| | | }else { |
| | | current = Integer.parseInt(lastIdStr); |
| | | } |
| | | int numberLength = String.valueOf(99999).length(); |
| | | String result = prefix + String.format("%0" + numberLength + "d", current); |
| | | current++; |
| | | stringRedisTemplate.opsForValue().set(LIS_LAST_ID_INCR_KEY,String.valueOf(current)); |
| | | return result; |
| | | } |
| | | |
| | | |
| | | //生成体检号用 |
| | | private static long lastTimestamp = -1; |