|
@@ -17,6 +17,10 @@ import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import java.io.*;
|
|
|
import java.nio.file.Files;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.Month;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.format.DateTimeParseException;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -212,7 +216,7 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
String[] names = imageNames.split("、");
|
|
|
for (String name : names) {
|
|
|
if (!name.matches("(?i).+\\.(jpg|jpeg|png)$")) {
|
|
|
- throw exception(INVALID_IMAGE_FORMAT);
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
@@ -364,32 +368,32 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
SpecimenInfoDO existSpecimen = specimenInfoMapper.selectBySpecimenNumber(importSpecimen.getSpecimenNumber());
|
|
|
|
|
|
if (!isValidImageName(importSpecimen.getImageName())) {
|
|
|
- respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "图片名称格式不正确");
|
|
|
return;
|
|
|
}
|
|
|
- List<String> imagePathSet = new ArrayList<>();
|
|
|
- if(importSpecimen.getImageName() != null){
|
|
|
- String[] names = importSpecimen.getImageName().split("、");
|
|
|
- for (String importName : names) {
|
|
|
- File imageFile = findImageInTempDir(tempDir, importName);
|
|
|
- if (imageFile != null) {
|
|
|
- try {
|
|
|
- byte[] imageBytes = Files.readAllBytes(imageFile.toPath());
|
|
|
- String imagePath = fileApi.createFile(imageBytes);
|
|
|
- imagePathSet.add(imagePath);
|
|
|
- respVO.getCreateSpecimenImages().add(importName);
|
|
|
- // 处理上传后的路径,如存储到数据库或更新状态等
|
|
|
- } catch (IOException e) {
|
|
|
- respVO.getFailureSpecimenImages().put(importName, "图片上传失败");
|
|
|
+ List<String> imagePathSet = new ArrayList<>();
|
|
|
+ if(importSpecimen.getImageName() != null){
|
|
|
+ String[] names = importSpecimen.getImageName().split("、");
|
|
|
+ for (String importName : names) {
|
|
|
+ File imageFile = findImageInTempDir(tempDir, importName);
|
|
|
+ if (imageFile != null) {
|
|
|
+ try {
|
|
|
+ byte[] imageBytes = Files.readAllBytes(imageFile.toPath());
|
|
|
+ String imagePath = fileApi.createFile(imageBytes);
|
|
|
+ imagePathSet.add(imagePath);
|
|
|
+ respVO.getCreateSpecimenImages().add(importName);
|
|
|
+ // 处理上传后的路径,如存储到数据库或更新状态等
|
|
|
+ } catch (IOException e) {
|
|
|
+ respVO.getFailureSpecimenImages().put(importName, "图片上传失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ respVO.getFailureSpecimenImages().put(importSpecimen.getSpecimenNumber(), "图片不存在压缩包中");
|
|
|
+ }
|
|
|
+ if (existSpecimen != null && imagePathSet.isEmpty()) {
|
|
|
+ imagePathSet = BeanUtils.toBean(existSpecimen, SpecimenInfoRespVO.class).getImagePath();
|
|
|
+ }
|
|
|
}
|
|
|
- } else {
|
|
|
- respVO.getFailureSpecimenImages().put(importSpecimen.getSpecimenNumber(), "图片不存在压缩包中");
|
|
|
- }
|
|
|
- if (existSpecimen != null && imagePathSet.isEmpty()) {
|
|
|
- imagePathSet = BeanUtils.toBean(existSpecimen, SpecimenInfoRespVO.class).getImagePath();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ } respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "图片名称格式不正确");
|
|
|
+
|
|
|
|
|
|
|
|
|
// 处理文献资料字段,如果为空就赋值 <br>
|
|
@@ -416,6 +420,24 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "标本编号已存在,且不支持更新");
|
|
|
return;
|
|
|
}
|
|
|
+ LocalDateTime qidian = LocalDateTime.of(1, Month.JANUARY, 1, 0, 0);
|
|
|
+ if (importSpecimen.getAcquisitionTime() != null
|
|
|
+ && parseToLocalDateTime(importSpecimen.getAcquisitionTime()).equals(qidian)) {
|
|
|
+ respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "无效的入藏时间!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (importSpecimen.getFallTime() != null
|
|
|
+ && parseToLocalDateTime(importSpecimen.getFallTime()).equals(qidian)) {
|
|
|
+ respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "无效的降落时间!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (importSpecimen.getDiscoveryTime() != null
|
|
|
+ && parseToLocalDateTime(importSpecimen.getDiscoveryTime()).equals(qidian)) {
|
|
|
+ respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "无效的发现时间!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
// 更新逻辑
|
|
|
SpecimenInfoDO updateSpecimen = BeanUtils.toBean(importSpecimen, SpecimenInfoDO.class);
|
|
|
|
|
@@ -452,6 +474,41 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
File[] files = tempDir.listFiles((dir, name) -> name.equalsIgnoreCase(imageName));
|
|
|
return files != null && files.length > 0 ? files[0] : null;
|
|
|
}
|
|
|
+
|
|
|
+ private static LocalDateTime parseToLocalDateTime(String dateString) {
|
|
|
+ // 列出支持的日期格式
|
|
|
+ List<String> dateFormats = Arrays.asList(
|
|
|
+ "yyyy-MM-dd HH:mm:ss",
|
|
|
+ "yyyy/MM/dd HH:mm:ss",
|
|
|
+ "yyyy-MM-dd'T'HH:mm:ss", // ISO_LOCAL_DATE_TIME 格式
|
|
|
+ "yyyy/MM/dd'T'HH:mm:ss",
|
|
|
+ "yyyy-MM-dd",
|
|
|
+ "yyyy/MM/dd",
|
|
|
+ "dd-MM-yyyy HH:mm:ss",
|
|
|
+ "dd/MM/yyyy HH:mm:ss",
|
|
|
+ "dd-MM-yyyy",
|
|
|
+ "dd/MM/yyyy"
|
|
|
+ );
|
|
|
+
|
|
|
+ // 尝试每种日期格式
|
|
|
+ for (String format : dateFormats) {
|
|
|
+ try {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
|
|
+ // 使用 parse 方法将字符串解析为 LocalDateTime
|
|
|
+ if (format.contains("HH")) {
|
|
|
+ return LocalDateTime.parse(dateString, formatter);
|
|
|
+ } else {
|
|
|
+ // 如果格式不包含时间部分,则补充时间部分为00:00:00
|
|
|
+ return LocalDateTime.parse(dateString + " 00:00:00", formatter);
|
|
|
+ }
|
|
|
+ } catch (DateTimeParseException e) {
|
|
|
+ // 如果解析失败,继续尝试下一个格式
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return LocalDateTime.of(1, Month.JANUARY, 1, 0, 0);
|
|
|
+ }
|
|
|
+
|
|
|
//公共方法
|
|
|
// public List<Integer> processZipFile(ZipInputStream zipInputStream, Integer groupId) throws Exception {
|
|
|
// List<Integer> photoIds = new ArrayList<>();
|