Pārlūkot izejas kodu

飞书账号池修复

xw 3 dienas atpakaļ
vecāks
revīzija
c217a9f600

+ 12 - 1
fs-service/src/main/java/com/fs/feishu/service/FeishuClientPool.java

@@ -97,6 +97,16 @@ public class FeishuClientPool {
         return feishuAccountMapper.countEnabledByCompanyUserId(companyUserId);
     }
 
+    /**
+     * 账号增删改后同步 Redis 轮询池,避免池中残留已删除/禁用的账号 ID。
+     */
+    public void refreshPool(Long companyUserId) {
+        if (companyUserId == null) {
+            return;
+        }
+        resetPoolIndexes(companyUserId);
+    }
+
     public synchronized void disableAccount(Long feishuAccountId, String errorMsg) {
         feishuAccountMapper.updateStatusAndErrorMsg(feishuAccountId, 0, errorMsg);
         clientCache.remove(feishuAccountId);
@@ -140,7 +150,8 @@ public class FeishuClientPool {
                     return account;
                 }
             }
-            log.warn("销售[{}]账号池索引 {} 已失效,重试", companyUserId, accountId);
+            log.warn("销售[{}]账号池索引 {} 已失效,重建账号池", companyUserId, accountId);
+            resetPoolIndexes(companyUserId, accounts);
         }
     }
 

+ 21 - 3
fs-service/src/main/java/com/fs/feishu/service/impl/FeishuAccountServiceImpl.java

@@ -57,7 +57,11 @@ public class FeishuAccountServiceImpl implements IFeishuAccountService {
         Date now = new Date();
         account.setCreateTime(now);
         account.setUpdateTime(now);
-        return feishuAccountMapper.insert(account);
+        int rows = feishuAccountMapper.insert(account);
+        if (rows > 0) {
+            clientPool.refreshPool(account.getCompanyUserId());
+        }
+        return rows;
     }
 
     @Override
@@ -80,13 +84,27 @@ public class FeishuAccountServiceImpl implements IFeishuAccountService {
 
     @Override
     public int updateFeishuAccount(FeishuAccount account) {
+        FeishuAccount existing = account.getId() != null ? feishuAccountMapper.selectById(account.getId()) : null;
         account.setUpdateTime(new Date());
-        return feishuAccountMapper.update(account);
+        int rows = feishuAccountMapper.update(account);
+        if (rows > 0 && existing != null) {
+            clientPool.refreshPool(existing.getCompanyUserId());
+            Long newCompanyUserId = account.getCompanyUserId();
+            if (newCompanyUserId != null && !newCompanyUserId.equals(existing.getCompanyUserId())) {
+                clientPool.refreshPool(newCompanyUserId);
+            }
+        }
+        return rows;
     }
 
     @Override
     public int deleteFeishuAccountById(Long id) {
-        return feishuAccountMapper.deleteById(id);
+        FeishuAccount existing = feishuAccountMapper.selectById(id);
+        int rows = feishuAccountMapper.deleteById(id);
+        if (rows > 0 && existing != null) {
+            clientPool.refreshPool(existing.getCompanyUserId());
+        }
+        return rows;
     }
 
     @Override