From a4f07b2a0ddb6c210e05afbbb491feeb466203e7 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 09 三月 2026 19:15:50 +0800
Subject: [PATCH] #V3重大更新,升级JDK17,升级SpirngBoot3.5.1

---
 src/main/java/com/zy/ai/service/LlmRoutingService.java |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/zy/ai/service/LlmRoutingService.java b/src/main/java/com/zy/ai/service/LlmRoutingService.java
index 4323d6a..673babb 100644
--- a/src/main/java/com/zy/ai/service/LlmRoutingService.java
+++ b/src/main/java/com/zy/ai/service/LlmRoutingService.java
@@ -1,6 +1,6 @@
 package com.zy.ai.service;
 
-import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.zy.ai.entity.LlmRouteConfig;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -12,6 +12,7 @@
 
 import java.time.Duration;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
@@ -29,6 +30,14 @@
 
     private volatile List<LlmRouteConfig> allRouteCache = Collections.emptyList();
     private volatile long cacheExpireAt = 0L;
+    private static final Comparator<LlmRouteConfig> ROUTE_ORDER = (a, b) -> {
+        int pa = a == null || a.getPriority() == null ? Integer.MAX_VALUE : a.getPriority();
+        int pb = b == null || b.getPriority() == null ? Integer.MAX_VALUE : b.getPriority();
+        if (pa != pb) return Integer.compare(pa, pb);
+        long ia = a == null || a.getId() == null ? Long.MAX_VALUE : a.getId();
+        long ib = b == null || b.getId() == null ? Long.MAX_VALUE : b.getId();
+        return Long.compare(ia, ib);
+    };
 
     public void evictCache() {
         cacheExpireAt = 0L;
@@ -63,9 +72,11 @@
         }
         if (result.isEmpty() && !coolingRoutes.isEmpty()) {
             // 閬垮厤鎵�鏈夎矾鐢遍兘澶勪簬鍐峰嵈鏃剁郴缁熷畬鍏ㄤ笉鍙敤锛岄檷绾у厑璁镐娇鐢ㄥ喎鍗磋矾鐢�
+            coolingRoutes.sort(ROUTE_ORDER);
             log.warn("LLM 璺敱鍧囧浜庡喎鍗达紝闄嶇骇鍚敤鍐峰嵈璺敱銆俢ooling={}, total={}", coolingRoutes.size(), total);
             return coolingRoutes;
         }
+        result.sort(ROUTE_ORDER);
         if (result.isEmpty()) {
             log.warn("鏈壘鍒板彲鐢� LLM 璺敱銆倀otal={}, disabled={}, invalid={}", total, disabled, invalid);
         }
@@ -75,7 +86,7 @@
     public void markSuccess(Long routeId) {
         if (routeId == null) return;
         try {
-            LlmRouteConfig db = llmRouteConfigService.selectById(routeId);
+            LlmRouteConfig db = llmRouteConfigService.getById(routeId);
             if (db == null) return;
             db.setSuccessCount(nvl(db.getSuccessCount()) + 1);
             db.setConsecutiveFailCount(0);
@@ -91,7 +102,7 @@
     public void markFailure(Long routeId, String errorText, boolean enterCooldown, Integer cooldownSeconds) {
         if (routeId == null) return;
         try {
-            LlmRouteConfig db = llmRouteConfigService.selectById(routeId);
+            LlmRouteConfig db = llmRouteConfigService.getById(routeId);
             if (db == null) return;
             Date now = new Date();
             db.setFailCount(nvl(db.getFailCount()) + 1);
@@ -144,10 +155,15 @@
             if (now < cacheExpireAt && allRouteCache != null) {
                 return allRouteCache;
             }
-            EntityWrapper<LlmRouteConfig> wrapper = new EntityWrapper<>();
-            wrapper.orderBy("priority", true).orderBy("id", true);
-            List<LlmRouteConfig> list = llmRouteConfigService.selectList(wrapper);
-            allRouteCache = list == null ? Collections.emptyList() : list;
+            QueryWrapper<LlmRouteConfig> wrapper = new QueryWrapper<>();
+            wrapper.orderBy(true, true, "priority").orderBy(true, true, "id");
+            List<LlmRouteConfig> list = llmRouteConfigService.list(wrapper);
+            if (list == null) {
+                allRouteCache = Collections.emptyList();
+            } else {
+                list.sort(ROUTE_ORDER);
+                allRouteCache = list;
+            }
             cacheExpireAt = System.currentTimeMillis() + CACHE_TTL_MS;
             return allRouteCache;
         }

--
Gitblit v1.9.1