From bb0a043a884c820260069aef4b3bb7c1b8f3ea10 Mon Sep 17 00:00:00 2001 From: wh Date: Tue, 12 May 2026 00:38:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=9B=B4=E6=96=B0agent=20configs=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 4a84af30232bd0815bcdcf37a85f76dae54834a5) --- .../backend/service/SysConfigService.java | 59 ++++++++----------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/labelsys/backend/service/SysConfigService.java b/src/main/java/com/labelsys/backend/service/SysConfigService.java index 4a399f2..4b01af7 100644 --- a/src/main/java/com/labelsys/backend/service/SysConfigService.java +++ b/src/main/java/com/labelsys/backend/service/SysConfigService.java @@ -1,6 +1,7 @@ package com.labelsys.backend.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -311,17 +312,8 @@ public class SysConfigService { private void syncUpdateAgentConfigs(Long companyId, Long configId, SysConfig config) { try { if (ConfigType.MODEL.name().equalsIgnoreCase(config.getConfigType())) { - // 更新所有使用该模型配置的agent配置 - LambdaQueryWrapper modelWrapper = - new LambdaQueryWrapper<>(); - modelWrapper.eq(AnnotationAgentConfig::getCompanyId, companyId) - .eq(AnnotationAgentConfig::getModelConfigId, configId); - - List modelAgentConfigs = - agentConfigMapper.selectList(modelWrapper); - - // 先解密获取原始API密钥,再通过setModelApiKey加密存储 - String decryptedApiKey = null; + // 从配置值中提取模型URL、加密的API密钥和LLM类型 + String encryptedApiKey = null; String modelUrl = null; String llmType = null; try { @@ -330,42 +322,37 @@ public class SysConfigService { if (llmConfig != null) { modelUrl = llmConfig.getModelUrl(); llmType = llmConfig.getLlmType(); - // 解密API密钥,setModelApiKey会再次加密 + // 直接获取加密后的API密钥,不进行解密 if (llmConfig.getApiKey() != null) { - decryptedApiKey = SM4Util.decryptSafe(llmConfig.getApiKey()); + encryptedApiKey = llmConfig.getApiKey(); } } } catch (Exception e) { log.warn("解析模型配置值失败,configId={}, error={}", configId, e.getMessage()); } - for (AnnotationAgentConfig agentConfig : modelAgentConfigs) { - agentConfig.setModelName(config.getConfigName()); - agentConfig.setModelUrl(modelUrl); - agentConfig.setModelApiKey(decryptedApiKey); // setModelApiKey会加密存储 - agentConfig.setLlmType(llmType); - agentConfig.setCreatedAt(LocalDateTime.now()); - agentConfigMapper.updateById(agentConfig); - } + // 使用UpdateWrapper批量更新,直接存储加密后的API密钥 + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.eq("company_id", companyId) + .eq("model_config_id", configId) + .set("model_name", config.getConfigName()) + .set("model_url", modelUrl) + .set("model_api_key", encryptedApiKey) // 直接设置加密后的API密钥 + .set("llm_type", llmType) + .set("created_at", LocalDateTime.now()); - log.info("sync updated {} agent configs with modelConfigId={}", modelAgentConfigs.size(), configId); + int updatedCount = agentConfigMapper.update(null, updateWrapper); + log.info("sync updated {} agent configs with modelConfigId={}", updatedCount, configId); } else if (ConfigType.PROMPT.name().equalsIgnoreCase(config.getConfigType())) { // 更新所有使用该提示词配置的agent配置 - LambdaQueryWrapper promptWrapper = - new LambdaQueryWrapper<>(); - promptWrapper.eq(AnnotationAgentConfig::getCompanyId, companyId) - .eq(AnnotationAgentConfig::getPromptConfigId, configId); + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.eq("company_id", companyId) + .eq("prompt_config_id", configId) + .set("prompt_text", config.getConfigValue()) + .set("created_at", LocalDateTime.now()); - List promptAgentConfigs = - agentConfigMapper.selectList(promptWrapper); - - for (AnnotationAgentConfig agentConfig : promptAgentConfigs) { - agentConfig.setPromptText(config.getConfigValue()); - agentConfig.setCreatedAt(LocalDateTime.now()); - agentConfigMapper.updateById(agentConfig); - } - - log.info("sync updated {} agent configs with promptConfigId={}", promptAgentConfigs.size(), configId); + int updatedCount = agentConfigMapper.update(null, updateWrapper); + log.info("sync updated {} agent configs with promptConfigId={}", updatedCount, configId); } } catch (Exception e) { log.error("syncUpdateAgentConfigs failed, configId={}, error={}", configId, e.getMessage(), e); From 965f3cf1799b8aaff3c5045476f406a2edb712f8 Mon Sep 17 00:00:00 2001 From: wh Date: Tue, 12 May 2026 16:10:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=81=94=E8=B0=83?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/labelsys/backend/service/UserService.java | 8 +++++++- src/main/resources/mapper/AnnotationResultMapper.xml | 8 +++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/labelsys/backend/service/UserService.java b/src/main/java/com/labelsys/backend/service/UserService.java index 29ced5a..f38bda0 100644 --- a/src/main/java/com/labelsys/backend/service/UserService.java +++ b/src/main/java/com/labelsys/backend/service/UserService.java @@ -43,7 +43,13 @@ public class UserService { public List listAllUsers(LoginUser currentUser) { try { assertSystemAdmin(currentUser); - LambdaQueryWrapper wrapper = new LambdaQueryWrapper().orderByAsc(SysUser::getId); +// LambdaQueryWrapper wrapper = new LambdaQueryWrapper() +// .eq(SysUser::getPosition, UserPosition.ADMIN) // 添加岗位过滤 +// .orderByAsc(SysUser::getId); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .ne(SysUser::getId, currentUser.userId()) + .eq(SysUser::getPosition, UserPosition.ADMIN) + .orderByAsc(SysUser::getId); return sysUserMapper.selectList(wrapper); } catch (ForbiddenException e) { throw e; diff --git a/src/main/resources/mapper/AnnotationResultMapper.xml b/src/main/resources/mapper/AnnotationResultMapper.xml index b67a4a1..28abf75 100644 --- a/src/main/resources/mapper/AnnotationResultMapper.xml +++ b/src/main/resources/mapper/AnnotationResultMapper.xml @@ -8,6 +8,8 @@ + + @@ -18,8 +20,8 @@ - id, company_id, creator_id, creator_role, task_id, resource_id, qa_content_file_path, - diff_summary_file_path, requires_manual_review, is_deleted, reviewer_id, + id, company_id, creator_id, creator_role, task_id, resource_id, task_name, resource_name, + qa_content_file_path, diff_summary_file_path, requires_manual_review, is_deleted, reviewer_id, created_at, updated_at @@ -50,4 +52,4 @@ and company_id = #{companyId} and is_deleted = false - + \ No newline at end of file