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) {