修复标签管理报错

This commit is contained in:
limin 2025-01-13 15:32:56 +08:00
parent f608cfd0b8
commit 1ab7de806d
2 changed files with 18 additions and 1 deletions

View File

@ -105,5 +105,6 @@ public interface ErrorCodeConstants {
ErrorCode MODEL_SERVIC_ENAME_NOT_EXISTS = new ErrorCode(10043, "模型名称已存在");
ErrorCode OPTIMIZE_PROMPT_NOT_EXISTS = new ErrorCode(10044, "优化后信息不存在");
ErrorCode LABEL_NAME_EXISTS = new ErrorCode(10045, "标签名称重复");
}

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.llm.service.label;
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.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -19,7 +21,7 @@ import cn.iocoder.yudao.module.llm.dal.mysql.label.LabelMapper;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.llm.enums.ErrorCodeConstants.LABEL_NOT_EXISTS;
import static cn.iocoder.yudao.module.llm.enums.ErrorCodeConstants.*;
/**
* 标签管理 Service 实现类
@ -35,6 +37,7 @@ public class LabelServiceImpl implements LabelService {
@Override
public Long createLabel(LabelSaveReqVO createReqVO) {
validateLabelNameExists(createReqVO);
// 插入
LabelDO label = BeanUtils.toBean(createReqVO, LabelDO.class);
labelMapper.insert(label);
@ -46,6 +49,7 @@ public class LabelServiceImpl implements LabelService {
public void updateLabel(LabelSaveReqVO updateReqVO) {
// 校验存在
validateLabelExists(updateReqVO.getId());
validateLabelNameExists(updateReqVO);
// 更新
LabelDO updateObj = BeanUtils.toBean(updateReqVO, LabelDO.class);
labelMapper.updateById(updateObj);
@ -64,6 +68,18 @@ public class LabelServiceImpl implements LabelService {
throw exception(LABEL_NOT_EXISTS);
}
}
private void validateLabelNameExists(LabelSaveReqVO updateReqVO) {
LambdaQueryWrapper<LabelDO> wrapper = new LambdaQueryWrapper<LabelDO>()
.eq(LabelDO::getLabelName, updateReqVO.getLabelName());
if (updateReqVO.getId() != null){
wrapper.ne(LabelDO::getId, updateReqVO.getId());
}
List<LabelDO> labelDOS = labelMapper.selectList(wrapper);
if (CollectionUtils.isNotEmpty(labelDOS)){
throw exception(LABEL_NAME_EXISTS);
}
}
@Override
public LabelDO getLabel(Long id) {