|
@@ -238,7 +238,10 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
SpecimenInfoDO existSpecimen = specimenInfoMapper.selectBySpecimenNumber(importSpecimen.getSpecimenNumber());
|
|
|
|
|
|
// 1. 校验图片名格式
|
|
|
- if (!areValidImageNames(importSpecimen.getImageName())) {
|
|
|
+ String[] imageNames = importSpecimen.getImageName().split(","); // 处理多个图片名
|
|
|
+ boolean validImageNames = Arrays.stream(imageNames).allMatch(this::isValidImageName);
|
|
|
+
|
|
|
+ if (!validImageNames) {
|
|
|
respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "图片名称格式不正确");
|
|
|
return;
|
|
|
}
|
|
@@ -246,16 +249,18 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
if (existSpecimen == null) {
|
|
|
// 2.2.1 不存在则插入
|
|
|
SpecimenInfoDO newSpecimen = BeanUtils.toBean(importSpecimen, SpecimenInfoDO.class);
|
|
|
+ newSpecimen.setImagePath(""); // 初始化为空
|
|
|
specimenInfoMapper.insert(newSpecimen);
|
|
|
respVO.getCreateSpecimenNumbers().add(importSpecimen.getSpecimenNumber());
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 2.2.2 如果存在,判断是否允许更新
|
|
|
- if (!isUpdateSupport) {
|
|
|
- respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "标本编号已存在,且不支持更新");
|
|
|
- return;
|
|
|
- }
|
|
|
+ // 如果需要支持更新,取消注释以下代码
|
|
|
+// if (!isUpdateSupport) {
|
|
|
+// respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "标本编号已存在,且不支持更新");
|
|
|
+// return;
|
|
|
+// }
|
|
|
|
|
|
// 更新逻辑
|
|
|
SpecimenInfoDO updateSpecimen = BeanUtils.toBean(importSpecimen, SpecimenInfoDO.class);
|
|
@@ -267,8 +272,9 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
return respVO;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// 检查多个图片名称格式
|
|
|
- private boolean areValidImageNames(String imageNames) {
|
|
|
+ private boolean isValidImageName(String imageNames) {
|
|
|
if (imageNames == null) return false;
|
|
|
String[] names = imageNames.split(",");
|
|
|
for (String name : names) {
|
|
@@ -287,7 +293,6 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
if (!file.getOriginalFilename().endsWith(".zip")) {
|
|
|
throw exception(UPLOADED_FOLDER_CANNOT_EMPTY);
|
|
|
}
|
|
|
-
|
|
|
// 创建临时目录存放解压后的文件
|
|
|
File tempDir = Files.createTempDirectory("specimen_images").toFile();
|
|
|
try (ZipInputStream zipInputStream = new ZipInputStream(file.getInputStream())) {
|
|
@@ -312,25 +317,25 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
if (imageFiles != null) {
|
|
|
for (File imageFile : imageFiles) {
|
|
|
String imageName = imageFile.getName();
|
|
|
-// if (!isValidImageName(imageName)) {
|
|
|
-// System.err.println("无效的图片格式: " + imageName);
|
|
|
-// continue; // 跳过无效图片
|
|
|
-// }
|
|
|
+ if (!isValidImageName(imageName)) {
|
|
|
+ // 如果不符合格式,抛出异常或记录日志
|
|
|
+ System.err.println("无效的图片格式: " + imageName);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
// 根据图片名称查找对应的标本
|
|
|
- SpecimenInfoDO specimenInfo = specimenInfoMapper.selectByImageName(imageName);
|
|
|
- if (specimenInfo != null) {
|
|
|
+ List<SpecimenInfoDO> specimenInfoList = (List<SpecimenInfoDO>) specimenInfoMapper.selectByImageName(imageName);
|
|
|
+ for (SpecimenInfoDO specimenInfo : specimenInfoList) {
|
|
|
// 上传图片并获取URL
|
|
|
String imagePath = fileApi.createFile(Files.readAllBytes(imageFile.toPath()));
|
|
|
|
|
|
- // 更新标本信息中的图片路径,允许多个路径
|
|
|
- String existingImagePaths = specimenInfo.getImagePath();
|
|
|
- if (existingImagePaths == null || existingImagePaths.isEmpty()) {
|
|
|
- specimenInfo.setImagePath(imagePath);
|
|
|
+ // 更新标本信息中的图片路径
|
|
|
+ String currentImagePaths = specimenInfo.getImagePath();
|
|
|
+ if (currentImagePaths == null || currentImagePaths.isEmpty()) {
|
|
|
+ specimenInfo.setImagePath(imagePath); // 第一次设置
|
|
|
} else {
|
|
|
- specimenInfo.setImagePath(existingImagePaths + "," + imagePath);
|
|
|
+ specimenInfo.setImagePath(currentImagePaths + "," + imagePath); // 追加到已有路径
|
|
|
}
|
|
|
-
|
|
|
specimenInfoMapper.updateById(specimenInfo);
|
|
|
}
|
|
|
}
|
|
@@ -341,6 +346,8 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
return "标本图片导入成功";
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
// 主导入逻辑
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class) // 事务管理
|
|
@@ -361,11 +368,18 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
|
|
|
//工作台
|
|
|
//根据入库的登记情况统计本年标本入库信息
|
|
|
+// @Override
|
|
|
+// public List<SpecimenInfoDO> getEntryStatistics(int year) {
|
|
|
+// return specimenInfoMapper.selectEntryStatisticsByYear(year);
|
|
|
+// }
|
|
|
+
|
|
|
@Override
|
|
|
- public List<SpecimenInfoDO> getEntryStatistics(int year) {
|
|
|
- return specimenInfoMapper.selectEntryStatisticsByYear(year);
|
|
|
+ public List<Map<String, Object>> getMonthlyEntryStatistics(int year) {
|
|
|
+ return specimenInfoMapper.selectMonthlyEntryStatisticsByYear(year);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
//按标本类别统计库存数
|
|
|
@Override
|
|
|
public List<SpecimenInfoDO> getSpecimenTypeStatistics(int specimen_type) {
|
|
@@ -583,6 +597,4 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
return specimenInfoMapper.getSpecimenRecords(id);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
}
|