From 2ba86da39808ff8388531cc1f608d69822bee41c Mon Sep 17 00:00:00 2001
From: zjh <1084500556@qq.com>
Date: 星期四, 31 七月 2025 18:46:55 +0800
Subject: [PATCH] zjh20250731

---
 ltkj-hosp/src/main/java/com/ltkj/hosp/idutil/IdUtils.java |   54 +++++++++++++-----------------------------------------
 1 files changed, 13 insertions(+), 41 deletions(-)

diff --git a/ltkj-hosp/src/main/java/com/ltkj/hosp/idutil/IdUtils.java b/ltkj-hosp/src/main/java/com/ltkj/hosp/idutil/IdUtils.java
index ae2e541..c00f91e 100644
--- a/ltkj-hosp/src/main/java/com/ltkj/hosp/idutil/IdUtils.java
+++ b/ltkj-hosp/src/main/java/com/ltkj/hosp/idutil/IdUtils.java
@@ -1,6 +1,7 @@
 package com.ltkj.hosp.idutil;
 
 import cn.hutool.core.util.StrUtil;
+import com.ltkj.db.DataSourceContextHolder;
 import com.ltkj.hosp.mapper.OrderNumberMapper;
 import lombok.extern.slf4j.Slf4j;
 import org.redisson.api.RLock;
@@ -24,10 +25,9 @@
 @Slf4j
 public class IdUtils {
 
-    private static final String LIS_LAST_ID_KEY = "id:generate:lis:id";
-    private static final String TJH_LAST_ID_KEY = "id:generate:tjhs:tjh";
-    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  String LIS_LAST_ID_KEY = "id:generate:lis:id";
+    private static  String TJH_LAST_ID_KEY = "id:generate:tjhs:tjh";
+    private static  String LIS_CURRENT_DATE_KEY = "id:generate:lis:currentDate";
 
     @Autowired
     private StringRedisTemplate stringRedisTemplate;
@@ -36,27 +36,14 @@
     @Autowired
     private RedissonClient redissonClient;
 
-    public synchronized String yuangenerateLisID(String prefix) {
-        String currentDate = new SimpleDateFormat("yyyyMMdd").format(new Date());
-        String storedDate = stringRedisTemplate.opsForValue().get(LIS_CURRENT_DATE_KEY);
-        String lastIdStr = stringRedisTemplate.opsForValue().get(LIS_LAST_ID_KEY);
-        int lastId;
-        if (storedDate == null || !storedDate.equals(currentDate)) {
-            lastId = 1;
-            stringRedisTemplate.opsForValue().set(LIS_LAST_ID_KEY, String.valueOf(lastId));
-            stringRedisTemplate.opsForValue().set(LIS_CURRENT_DATE_KEY, currentDate);
-        } else {
-            lastId = Integer.parseInt(lastIdStr) + 1;
-            stringRedisTemplate.opsForValue().set(LIS_LAST_ID_KEY, String.valueOf(lastId));
-        }
-        String yyMMdd = currentDate.substring(2);
-        return String.format(prefix+"%s%05d", yyMMdd, lastId);
-    }
-
     //redis鍒嗗竷寮忛攣鍜孧ySQL鍏敤
     public String generateLisID(String prefix) {
         String lockKey = "lock:tmh:tj_tmh_lock";
         RLock lock = redissonClient.getLock(lockKey);
+        String string = DataSourceContextHolder.getDataSourceKey();
+
+        LIS_LAST_ID_KEY = "id:generate:lis:id:"+string;
+        LIS_CURRENT_DATE_KEY = "id:generate:lis:currentDate:"+string;
 
         try {
             if (lock.tryLock(3, 5, TimeUnit.SECONDS)) {
@@ -93,26 +80,6 @@
         }
     }
 
-
-    /**
-     * 鐢熸垚鏃犻檺閫掑鏉$爜鍙�
-     * @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;
-    }
 
 
     //鐢熸垚浣撴鍙风敤
@@ -198,6 +165,11 @@
         String lockKey = "lock:tjh:tj_number_lock";
         RLock lock = redissonClient.getLock(lockKey);
 
+        String string = DataSourceContextHolder.getDataSourceKey();
+
+        LIS_CURRENT_DATE_KEY = "id:generate:lis:currentDate:"+string;
+        TJH_LAST_ID_KEY = "id:generate:tjhs:tjh:"+string;
+
         try {
             if (lock.tryLock(5, 10, TimeUnit.SECONDS)) {
                 String currentDate = new SimpleDateFormat("yyyyMMdd").format(new Date());

--
Gitblit v1.8.0