mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-05 13:38:58 +08:00
refactor: 文件处理完善
This commit is contained in:
parent
4dd7177430
commit
e0ee4cd184
@ -29,8 +29,8 @@ public class LocalFileRepository implements FileRepository {
|
||||
private void createFileDir(FileRequest request) {
|
||||
String dir = getFileDir(request);
|
||||
File fileDir = new File(dir);
|
||||
if (!fileDir.exists()) {
|
||||
fileDir.mkdirs();
|
||||
if (!fileDir.exists() && !fileDir.mkdirs()) {
|
||||
throw new RuntimeException("Failed to create directory: " + dir);
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,8 +40,6 @@ public class LocalFileRepository implements FileRepository {
|
||||
try (OutputStream ops = new FileOutputStream(file)) {
|
||||
ops.write(bytes);
|
||||
return file.getPath();
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,8 +48,8 @@ public class LocalFileRepository implements FileRepository {
|
||||
String path = StringUtils.join(getFilePath(request));
|
||||
File file = new File(path);
|
||||
FileUtil.deleteContents(file);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
if (file.exists() && !file.delete()) {
|
||||
throw new RuntimeException("Failed to delete file: " + path);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,6 +72,7 @@ public class LocalFileRepository implements FileRepository {
|
||||
|
||||
@Override
|
||||
public void downloadFile(FileRequest request, String localPath) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,7 +3,7 @@ package io.metersphere.sdk.util;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class SubListUtil {
|
||||
public class SubListUtils {
|
||||
|
||||
/**
|
||||
* 将较长的数组截断成较短的数组进行批处理
|
@ -5,7 +5,7 @@ import io.metersphere.sdk.dto.CustomFieldDTO;
|
||||
import io.metersphere.sdk.dto.request.CustomFieldOptionRequest;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.SubListUtil;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.system.domain.CustomField;
|
||||
import io.metersphere.system.domain.CustomFieldExample;
|
||||
import io.metersphere.system.domain.CustomFieldOption;
|
||||
@ -143,7 +143,7 @@ public class OrganizationCustomFieldService extends BaseCustomFieldService {
|
||||
// 删除字段选项
|
||||
List<String> projectCustomFieldIds = extOrganizationCustomFieldMapper.getCustomFieldByRefId(orgCustomFieldId);
|
||||
// 分批删除
|
||||
SubListUtil.dealForSubList(projectCustomFieldIds, 100, baseCustomFieldOptionService::deleteByFieldIds);
|
||||
SubListUtils.dealForSubList(projectCustomFieldIds, 100, baseCustomFieldOptionService::deleteByFieldIds);
|
||||
}
|
||||
|
||||
private void checkOrganizationTemplateEnable(String orgId, String scene) {
|
||||
|
@ -5,7 +5,7 @@ import io.metersphere.sdk.dto.TemplateDTO;
|
||||
import io.metersphere.sdk.dto.request.TemplateCustomFieldRequest;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.SubListUtil;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.system.domain.OrganizationParameter;
|
||||
import io.metersphere.system.domain.Template;
|
||||
import io.metersphere.system.domain.TemplateExample;
|
||||
@ -179,7 +179,7 @@ public class OrganizationTemplateService extends BaseTemplateService {
|
||||
// 删除项目模板和字段的关联关系
|
||||
List<String> projectTemplateIds = extOrganizationTemplateMapper.getTemplateIdByRefId(orgTemplateId);
|
||||
// 分批删除
|
||||
SubListUtil.dealForSubList(projectTemplateIds, 100, baseTemplateCustomFieldService::deleteByTemplateIds);
|
||||
SubListUtils.dealForSubList(projectTemplateIds, 100, baseTemplateCustomFieldService::deleteByTemplateIds);
|
||||
}
|
||||
|
||||
private void checkOrganizationTemplateEnable(String orgId, String scene) {
|
||||
|
Loading…
Reference in New Issue
Block a user