Junjie
1 天以前 a4f07b2a0ddb6c210e05afbbb491feeb466203e7
src/main/java/com/zy/ai/controller/LlmRouteConfigController.java
@@ -1,6 +1,6 @@
package com.zy.ai.controller;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.core.annotations.ManagerAuth;
import com.core.common.R;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -33,9 +33,9 @@
    @GetMapping("/list/auth")
    @ManagerAuth
    public R list() {
        EntityWrapper<LlmRouteConfig> wrapper = new EntityWrapper<>();
        wrapper.orderBy("priority", true).orderBy("id", true);
        List<LlmRouteConfig> list = llmRouteConfigService.selectList(wrapper);
        QueryWrapper<LlmRouteConfig> wrapper = new QueryWrapper<>();
        wrapper.orderBy(true, true, "priority").orderBy(true, true, "id");
        List<LlmRouteConfig> list = llmRouteConfigService.list(wrapper);
        return R.ok(list);
    }
@@ -52,9 +52,9 @@
        if (config.getId() == null) {
            llmRoutingService.fillAndNormalize(config, true);
            llmRouteConfigService.insert(config);
            llmRouteConfigService.save(config);
        } else {
            LlmRouteConfig db = llmRouteConfigService.selectById(config.getId());
            LlmRouteConfig db = llmRouteConfigService.getById(config.getId());
            if (db == null) {
                return R.error("配置不存在");
            }
@@ -87,7 +87,7 @@
        if (id == null) {
            return R.error("id不能为空");
        }
        llmRouteConfigService.deleteById(id);
        llmRouteConfigService.removeById(id);
        llmRoutingService.evictCache();
        return R.ok();
    }
@@ -98,7 +98,7 @@
        if (id == null) {
            return R.error("id不能为空");
        }
        LlmRouteConfig cfg = llmRouteConfigService.selectById(id);
        LlmRouteConfig cfg = llmRouteConfigService.getById(id);
        if (cfg == null) {
            return R.error("配置不存在");
        }
@@ -121,7 +121,7 @@
        }
        Map<String, Object> data = llmRoutingService.testRoute(config);
        if (Boolean.TRUE.equals(data.get("ok")) && config.getId() != null) {
            LlmRouteConfig db = llmRouteConfigService.selectById(config.getId());
            LlmRouteConfig db = llmRouteConfigService.getById(config.getId());
            if (db != null) {
                db.setCooldownUntil(null);
                db.setConsecutiveFailCount(0);
@@ -136,9 +136,9 @@
    @GetMapping("/export/auth")
    @ManagerAuth
    public R exportConfig() {
        EntityWrapper<LlmRouteConfig> wrapper = new EntityWrapper<>();
        wrapper.orderBy("priority", true).orderBy("id", true);
        List<LlmRouteConfig> list = llmRouteConfigService.selectList(wrapper);
        QueryWrapper<LlmRouteConfig> wrapper = new QueryWrapper<>();
        wrapper.orderBy(true, true, "priority").orderBy(true, true, "id");
        List<LlmRouteConfig> list = llmRouteConfigService.list(wrapper);
        List<Map<String, Object>> routes = new ArrayList<>();
        if (list != null) {
            for (LlmRouteConfig cfg : list) {
@@ -216,12 +216,12 @@
        }
        if (replace) {
            llmRouteConfigService.delete(new EntityWrapper<LlmRouteConfig>());
            llmRouteConfigService.remove(new QueryWrapper<LlmRouteConfig>());
        }
        HashMap<Long, LlmRouteConfig> dbById = new HashMap<>();
        if (!replace) {
            List<LlmRouteConfig> current = llmRouteConfigService.selectList(new EntityWrapper<>());
            List<LlmRouteConfig> current = llmRouteConfigService.list(new QueryWrapper<>());
            if (current != null) {
                for (LlmRouteConfig item : current) {
                    if (item != null && item.getId() != null) {
@@ -269,7 +269,7 @@
            cfg.setLastUsedTime(null);
            cfg.setLastError(null);
            llmRoutingService.fillAndNormalize(cfg, true);
            llmRouteConfigService.insert(cfg);
            llmRouteConfigService.save(cfg);
            inserted++;
        }