fix(llm): 优化模型评估维度删除逻辑
- 新增自动评估维度正在使用中不可删除的错误码 - 在删除模型评估维度时增加使用中的维度检查- 优化本地文件客户端的上传方法,使用切片上传
This commit is contained in:
parent
4d40eac3af
commit
e2f6967e48
@ -4,6 +4,8 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.AbstractFileClient;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
/**
|
||||
* 本地文件客户端
|
||||
@ -24,15 +26,40 @@ public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String upload(byte[] content, String path, String type) {
|
||||
// 执行写入
|
||||
String filePath = getFilePath(path);
|
||||
FileUtil.writeBytes(content, filePath);
|
||||
// 拼接返回路径
|
||||
return super.formatFileUrl(config.getDomain(), path);
|
||||
// @Override
|
||||
// public String upload(byte[] content, String path, String type) {
|
||||
// // 执行写入
|
||||
// String filePath = getFilePath(path);
|
||||
// FileUtil.writeBytes(content, filePath);
|
||||
// // 拼接返回路径
|
||||
// return super.formatFileUrl(config.getDomain(), path);
|
||||
// }
|
||||
@Override
|
||||
public String upload(byte[] content, String path, String type) {
|
||||
String filePath = getFilePath(path);
|
||||
|
||||
int partSize = 5 * 1024 * 1024; // 每片 5MB
|
||||
int totalParts = (int) Math.ceil((double) content.length / partSize);
|
||||
|
||||
// 确保目录存在
|
||||
FileUtil.mkdir(new File(filePath).getParentFile());
|
||||
|
||||
try (RandomAccessFile raf = new RandomAccessFile(filePath, "rw")) {
|
||||
for (int partNumber = 0; partNumber < totalParts; partNumber++) {
|
||||
int start = partNumber * partSize;
|
||||
int end = Math.min(start + partSize, content.length);
|
||||
raf.seek(start);
|
||||
raf.write(content, start, end - start);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("切片上传失败: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
// 拼接返回路径
|
||||
return super.formatFileUrl(config.getDomain(), path);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void delete(String path) {
|
||||
String filePath = getFilePath(path);
|
||||
|
||||
@ -30,6 +30,7 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode MODEL_ASSESS_TASK_STOPLIST_NOT_EXISTS = new ErrorCode(10013, "自动评估维度不存在");
|
||||
|
||||
ErrorCode MODEL_ASSESS_STOPLIST_NOT_EXISTS = new ErrorCode(10014, "自动评估维度不存在");
|
||||
ErrorCode THE_AUTO_EVALUATE_DIMENSION_IS_IN_USE = new ErrorCode(10014_1, "自动评估维度正在使用中不可删除");
|
||||
|
||||
ErrorCode LEARNING_RESOURCES_NOT_EXISTS = new ErrorCode(10015, "学习资源不存在");
|
||||
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package cn.iocoder.yudao.module.llm.service.modelassessstoplist;
|
||||
|
||||
import cn.iocoder.yudao.module.llm.dal.dataobject.modelassesstaskauto.ModelAssessTaskStoplistDO;
|
||||
import cn.iocoder.yudao.module.llm.dal.mysql.modelassesstaskauto.ModelAssessTaskStoplistMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
@ -30,6 +33,9 @@ public class ModelAssessStoplistServiceImpl implements ModelAssessStoplistServic
|
||||
@Resource
|
||||
private ModelAssessStoplistMapper modelAssessStoplistMapper;
|
||||
|
||||
@Resource
|
||||
private ModelAssessTaskStoplistMapper modelingTaskStoplistMapper;
|
||||
|
||||
@Override
|
||||
public Long createModelAssessStoplist(ModelAssessStoplistSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
@ -52,6 +58,11 @@ public class ModelAssessStoplistServiceImpl implements ModelAssessStoplistServic
|
||||
public void deleteModelAssessStoplist(Long id) {
|
||||
// 校验存在
|
||||
validateModelAssessStoplistExists(id);
|
||||
LambdaQueryWrapper<ModelAssessTaskStoplistDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(ModelAssessTaskStoplistDO::getStoplistId, id);
|
||||
if (modelingTaskStoplistMapper.selectCount(queryWrapper) > 0){
|
||||
throw exception(THE_AUTO_EVALUATE_DIMENSION_IS_IN_USE);
|
||||
}
|
||||
// 删除
|
||||
LambdaUpdateWrapper<ModelAssessStoplistDO> wrapper = new LambdaUpdateWrapper<>();
|
||||
wrapper.eq(ModelAssessStoplistDO::getId, id)
|
||||
@ -82,4 +93,4 @@ public class ModelAssessStoplistServiceImpl implements ModelAssessStoplistServic
|
||||
return modelAssessStoplistMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,6 +137,10 @@ public class ModelAssessTaskAutoServiceImpl implements ModelAssessTaskAutoServic
|
||||
public void deleteModelAssessTaskAuto (Long id) {
|
||||
// 校验存在
|
||||
validateModelAssessTaskAutoExists(id);
|
||||
// 删除子表
|
||||
LambdaQueryWrapper<ModelAssessTaskStoplistDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(ModelAssessTaskStoplistDO::getTaskId, id);
|
||||
modelingTaskStoplistMapper.delete(queryWrapper);
|
||||
LambdaUpdateWrapper<ModelAssessTaskAutoDO> wrapper = new LambdaUpdateWrapper<>();
|
||||
// 删除
|
||||
wrapper.eq(ModelAssessTaskAutoDO::getId, id)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user