|
@ -42,40 +42,52 @@ public class FileService extends BaseService<FileMapper, FileDto> { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 处理文件列表信息,将文件信息转换为文件响应DTO的列表。 |
|
|
|
|
|
* |
|
|
|
|
|
* @param fileDto 文件DTO,包含文件的详细信息。 |
|
|
|
|
|
* @return 返回一个文件响应DTO的列表,每个DTO包含文件名、阶段和上传日期等信息。 |
|
|
|
|
|
*/ |
|
|
public List<FileResponseDto> handleFileList(FileDto fileDto) { |
|
|
public List<FileResponseDto> handleFileList(FileDto fileDto) { |
|
|
|
|
|
|
|
|
List<FileResponseDto> list = new ArrayList<>(); |
|
|
List<FileResponseDto> list = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
// 获取fileDto对象的所有声明字段
|
|
|
Field[] fields = fileDto.getClass().getDeclaredFields(); |
|
|
Field[] fields = fileDto.getClass().getDeclaredFields(); |
|
|
|
|
|
|
|
|
|
|
|
// 遍历所有字段
|
|
|
for (Field field : fields) { |
|
|
for (Field field : fields) { |
|
|
field.setAccessible(true); |
|
|
field.setAccessible(true); // 允许访问私有字段
|
|
|
try { |
|
|
try { |
|
|
|
|
|
// 检查字段值是否为空
|
|
|
if (isEmpty((String) field.get(fileDto))) { |
|
|
if (isEmpty((String) field.get(fileDto))) { |
|
|
|
|
|
// 处理字段值,移除特定字符串并分割
|
|
|
String trim = ((String) field.get(fileDto)).replace(", []", "").replace("[]", "").trim(); |
|
|
String trim = ((String) field.get(fileDto)).replace(", []", "").replace("[]", "").trim(); |
|
|
|
|
|
|
|
|
String[] split = trim.split("\\$ "); |
|
|
String[] split = trim.split("\\$ "); |
|
|
|
|
|
|
|
|
|
|
|
// 获取字段上的Stage注解
|
|
|
Stage annotation = field.getAnnotation(Stage.class); |
|
|
Stage annotation = field.getAnnotation(Stage.class); |
|
|
FileResponseDto responseDto = new FileResponseDto(); |
|
|
FileResponseDto responseDto = new FileResponseDto(); |
|
|
for (String s : split) { |
|
|
for (String s : split) { |
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
if (s.equals("")) { |
|
|
if (s.equals("")) { |
|
|
continue; |
|
|
continue; // 跳过空字符串
|
|
|
} |
|
|
} |
|
|
|
|
|
// 将字符串反序列化为文件信息列表
|
|
|
List<FileInfo> fileInfoList = objectMapper.readValue(s, new TypeReference<List<FileInfo>>(){}); |
|
|
List<FileInfo> fileInfoList = objectMapper.readValue(s, new TypeReference<List<FileInfo>>(){}); |
|
|
for (FileInfo fileInfo : fileInfoList) { |
|
|
for (FileInfo fileInfo : fileInfoList) { |
|
|
|
|
|
// 设置文件名、阶段和上传日期
|
|
|
responseDto.setFileName(fileInfo.getName()); |
|
|
responseDto.setFileName(fileInfo.getName()); |
|
|
|
|
|
responseDto.setFileUrl(fileInfo.getUrl()); |
|
|
responseDto.setFileStage(annotation.value()); |
|
|
responseDto.setFileStage(annotation.value()); |
|
|
if (fileInfo.getFileName() == null) { |
|
|
if (fileInfo.getFileName() == null) { |
|
|
responseDto.setUploadDate(null); |
|
|
responseDto.setUploadDate(null); |
|
|
}else { |
|
|
}else { |
|
|
|
|
|
// 从文件名中提取上传日期
|
|
|
responseDto.setUploadDate(fileInfo.getFileName().substring(9, 19)); |
|
|
responseDto.setUploadDate(fileInfo.getFileName().substring(9, 19)); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
list.add(responseDto); |
|
|
list.add(responseDto); // 添加到列表中
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -94,6 +106,7 @@ public class FileService extends BaseService<FileMapper, FileDto> { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Boolean isEmpty(String name) { |
|
|
public Boolean isEmpty(String name) { |
|
|
if (name == null) { |
|
|
if (name == null) { |
|
|
return false; |
|
|
return false; |
|
|