修复学习资源名称重复 不提示直接报错问题

This commit is contained in:
limin 2025-01-07 10:11:29 +08:00
parent 451b95cc20
commit c16fc239b4
2 changed files with 19 additions and 0 deletions

View File

@ -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, "学习资源标题名称已存在");
}

View File

@ -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<LearningResourcesDO> wrapper = new LambdaQueryWrapper<LearningResourcesDO>()
.eq(LearningResourcesDO::getResourceTitle, reqVO.getResourceTitle())
.eq(LearningResourcesDO::getResourceCategory, reqVO.getResourceCategory());
if (reqVO.getId() != null){
wrapper.ne(LearningResourcesDO::getId, reqVO.getId());
}
List<LearningResourcesDO> learningResourcesDOS = learningResourcesMapper.selectList(wrapper);
if (CollectionUtils.isNotEmpty(learningResourcesDOS)){
throw exception(LEARNING_RESOURCES_NAME_NOT_EXISTS);
}
}
@Override
public LearningResourcesDO getLearningResources(Long id) {