| | |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.Random; |
| | | |
| | | /** |
| | | * @Company: 西安路泰科技有限公司 |
| | |
| | | |
| | | private static final String LIS_LAST_ID_KEY = "id:generate:lis:id"; |
| | | private static final String LIS_CURRENT_DATE_KEY = "id:generate:lis:currentDate"; |
| | | |
| | | // private static final UidGenerator uidGenerator = new DefaultUidGenerator(); // 使用默认的Snowflake生成器 |
| | | |
| | | @Autowired |
| | | private StringRedisTemplate stringRedisTemplate; |
| | |
| | | return String.format(prefix+"%s%05d", yyMMdd, lastId); |
| | | } |
| | | |
| | | |
| | | //生成体检号用 |
| | | private static long lastTimestamp = -1; |
| | | private static final Random random = new Random(); |
| | | |
| | | public static synchronized String getTjNumber() { |
| | | long timestamp = System.currentTimeMillis(); // 获取当前时间戳(毫秒) |
| | | |
| | | // 如果时间戳和上次生成的时间戳相同,生成一个新的随机数 |
| | | if (timestamp == lastTimestamp) { |
| | | return String.format("%09d", (timestamp % 1000000000) + random.nextInt(900) + 100); |
| | | } else { |
| | | lastTimestamp = timestamp; // 更新最后生成时间戳 |
| | | return String.format("%09d", (timestamp % 1000000000) + random.nextInt(900) + 100); |
| | | } |
| | | } |
| | | |
| | | |
| | | // 使用分布式ID生成器(如Snowflake) |
| | | public static String generateExamNumber() { |
| | | // long id = uidGenerator.getUID(); // 获取生成的唯一ID |
| | | // return String.format("%09d", Math.abs(id) % 1000000000); // 格式化为9位 |
| | | return null; |
| | | } |
| | | |
| | | } |