refactor: 文件处理完善
This commit is contained in:
parent
4dd7177430
commit
e0ee4cd184
|
@ -29,8 +29,8 @@ public class LocalFileRepository implements FileRepository {
|
||||||
private void createFileDir(FileRequest request) {
|
private void createFileDir(FileRequest request) {
|
||||||
String dir = getFileDir(request);
|
String dir = getFileDir(request);
|
||||||
File fileDir = new File(dir);
|
File fileDir = new File(dir);
|
||||||
if (!fileDir.exists()) {
|
if (!fileDir.exists() && !fileDir.mkdirs()) {
|
||||||
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)) {
|
try (OutputStream ops = new FileOutputStream(file)) {
|
||||||
ops.write(bytes);
|
ops.write(bytes);
|
||||||
return file.getPath();
|
return file.getPath();
|
||||||
} catch (Exception e) {
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +48,8 @@ public class LocalFileRepository implements FileRepository {
|
||||||
String path = StringUtils.join(getFilePath(request));
|
String path = StringUtils.join(getFilePath(request));
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
FileUtil.deleteContents(file);
|
FileUtil.deleteContents(file);
|
||||||
if (file.exists()) {
|
if (file.exists() && !file.delete()) {
|
||||||
file.delete();
|
throw new RuntimeException("Failed to delete file: " + path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +72,7 @@ public class LocalFileRepository implements FileRepository {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadFile(FileRequest request, String localPath) {
|
public void downloadFile(FileRequest request, String localPath) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,7 +3,7 @@ package io.metersphere.sdk.util;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
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.dto.request.CustomFieldOptionRequest;
|
||||||
import io.metersphere.sdk.exception.MSException;
|
import io.metersphere.sdk.exception.MSException;
|
||||||
import io.metersphere.sdk.util.BeanUtils;
|
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.CustomField;
|
||||||
import io.metersphere.system.domain.CustomFieldExample;
|
import io.metersphere.system.domain.CustomFieldExample;
|
||||||
import io.metersphere.system.domain.CustomFieldOption;
|
import io.metersphere.system.domain.CustomFieldOption;
|
||||||
|
@ -143,7 +143,7 @@ public class OrganizationCustomFieldService extends BaseCustomFieldService {
|
||||||
// 删除字段选项
|
// 删除字段选项
|
||||||
List<String> projectCustomFieldIds = extOrganizationCustomFieldMapper.getCustomFieldByRefId(orgCustomFieldId);
|
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) {
|
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.dto.request.TemplateCustomFieldRequest;
|
||||||
import io.metersphere.sdk.exception.MSException;
|
import io.metersphere.sdk.exception.MSException;
|
||||||
import io.metersphere.sdk.util.BeanUtils;
|
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.OrganizationParameter;
|
||||||
import io.metersphere.system.domain.Template;
|
import io.metersphere.system.domain.Template;
|
||||||
import io.metersphere.system.domain.TemplateExample;
|
import io.metersphere.system.domain.TemplateExample;
|
||||||
|
@ -179,7 +179,7 @@ public class OrganizationTemplateService extends BaseTemplateService {
|
||||||
// 删除项目模板和字段的关联关系
|
// 删除项目模板和字段的关联关系
|
||||||
List<String> projectTemplateIds = extOrganizationTemplateMapper.getTemplateIdByRefId(orgTemplateId);
|
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) {
|
private void checkOrganizationTemplateEnable(String orgId, String scene) {
|
||||||
|
|
Loading…
Reference in New Issue