From c16fc239b4687f79e27d37955237b07afd0224a1 Mon Sep 17 00:00:00 2001 From: limin Date: Tue, 7 Jan 2025 10:11:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AD=A6=E4=B9=A0=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E5=90=8D=E7=A7=B0=E9=87=8D=E5=A4=8D=20=E4=B8=8D?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E7=9B=B4=E6=8E=A5=E6=8A=A5=E9=94=99=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/llm/enums/ErrorCodeConstants.java | 1 + .../LearningResourcesServiceImpl.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/yudao-module-llm/yudao-module-llm-api/src/main/java/cn/iocoder/yudao/module/llm/enums/ErrorCodeConstants.java b/yudao-module-llm/yudao-module-llm-api/src/main/java/cn/iocoder/yudao/module/llm/enums/ErrorCodeConstants.java index bf816359b..5f0c2d393 100644 --- a/yudao-module-llm/yudao-module-llm-api/src/main/java/cn/iocoder/yudao/module/llm/enums/ErrorCodeConstants.java +++ b/yudao-module-llm/yudao-module-llm-api/src/main/java/cn/iocoder/yudao/module/llm/enums/ErrorCodeConstants.java @@ -93,6 +93,7 @@ public interface ErrorCodeConstants { ErrorCode PROMPT_TEMPLATES_TAGS_BACKUP_NOT_EXISTS = new ErrorCode(10037, "模板信息不存在"); ErrorCode DATA_PROCESS_TASK_NAME_NOT_EXISTS = new ErrorCode(10038, "数据处理任务名称已存在"); ErrorCode FINE_TUNING_TASK_NAME_NOT_EXISTS = new ErrorCode(10039, "模型调优任务名称已存在"); + ErrorCode LEARNING_RESOURCES_NAME_NOT_EXISTS = new ErrorCode(10040, "学习资源标题名称已存在"); } diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/learningresources/LearningResourcesServiceImpl.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/learningresources/LearningResourcesServiceImpl.java index d4dc60b8a..5647e964f 100644 --- a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/learningresources/LearningResourcesServiceImpl.java +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/learningresources/LearningResourcesServiceImpl.java @@ -2,6 +2,9 @@ package cn.iocoder.yudao.module.llm.service.learningresources; import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.URLUtil; +import cn.iocoder.yudao.module.llm.dal.dataobject.dataset.DatasetDO; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -37,6 +40,7 @@ public class LearningResourcesServiceImpl implements LearningResourcesService { @Override public Long createLearningResources(LearningResourcesSaveReqVO createReqVO) { + validateLearningResourcesNameExists(createReqVO); // 插入 LearningResourcesDO learningResources = BeanUtils.toBean(createReqVO, LearningResourcesDO.class); learningResourcesMapper.insert(learningResources); @@ -48,6 +52,7 @@ public class LearningResourcesServiceImpl implements LearningResourcesService { public void updateLearningResources(LearningResourcesSaveReqVO updateReqVO) { // 校验存在 validateLearningResourcesExists(updateReqVO.getId()); + validateLearningResourcesNameExists(updateReqVO); // 更新 LearningResourcesDO updateObj = BeanUtils.toBean(updateReqVO, LearningResourcesDO.class); learningResourcesMapper.updateById(updateObj); @@ -66,6 +71,19 @@ public class LearningResourcesServiceImpl implements LearningResourcesService { throw exception(LEARNING_RESOURCES_NOT_EXISTS); } } + private void validateLearningResourcesNameExists(LearningResourcesSaveReqVO reqVO) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .eq(LearningResourcesDO::getResourceTitle, reqVO.getResourceTitle()) + .eq(LearningResourcesDO::getResourceCategory, reqVO.getResourceCategory()); + + if (reqVO.getId() != null){ + wrapper.ne(LearningResourcesDO::getId, reqVO.getId()); + } + List learningResourcesDOS = learningResourcesMapper.selectList(wrapper); + if (CollectionUtils.isNotEmpty(learningResourcesDOS)){ + throw exception(LEARNING_RESOURCES_NAME_NOT_EXISTS); + } + } @Override public LearningResourcesDO getLearningResources(Long id) {