|
@@ -47,10 +47,6 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
private SpecimenOutboundMapper specimenOutboundMapper;
|
|
|
@Resource
|
|
|
private FileApi fileApi;
|
|
|
- public SpecimenInfoServiceImpl(SpecimenInfoMapper specimenInfoMapper, FileApi fileApi) {
|
|
|
- this.specimenInfoMapper = specimenInfoMapper;
|
|
|
- this.fileApi = fileApi;
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -58,12 +54,12 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
bizNo = "{{#specimenInfo.id}}",
|
|
|
success = MUSEUMS_SPECIMEN_CREATE_SUCCESS,
|
|
|
extra = "[{{#specimenInfo.id}}]")
|
|
|
- public String createSpecimenInfo(SpecimenInfoSaveReqVO createReqVO) {
|
|
|
+ public Long createSpecimenInfo(SpecimenInfoSaveReqVO createReqVO) {
|
|
|
// 校验标本编号是否已存在
|
|
|
- if (specimenInfoMapper.existsByNumber(createReqVO.getSpecimenNumber())) {
|
|
|
+ SpecimenInfoDO existsByNumber = specimenInfoMapper.selectBySpecimenNumber(createReqVO.getSpecimenNumber());
|
|
|
+ if (existsByNumber != null) {
|
|
|
throw exception(SPECIMEN_NUMBER_ALREADY_EXISTS_CANNOT_ADDED);
|
|
|
}
|
|
|
-
|
|
|
// 插入新标本信息
|
|
|
SpecimenInfoDO specimenInfo = BeanUtils.toBean(createReqVO, SpecimenInfoDO.class);
|
|
|
specimenInfoMapper.insert(specimenInfo);
|
|
@@ -72,7 +68,7 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
LogRecordContext.putVariable("specimenInfo", specimenInfo);
|
|
|
|
|
|
// 返回新创建的标本ID
|
|
|
- return "标本创建成功,标本ID:" + specimenInfo.getId();
|
|
|
+ return specimenInfo.getId();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -217,83 +213,7 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-// @Override
|
|
|
-// @Transactional(rollbackFor = Exception.class)
|
|
|
-// public String importSpecimenImages(MultipartFile file) throws Exception {
|
|
|
-// // 校验文件类型
|
|
|
-// if (!file.getOriginalFilename().toLowerCase().endsWith(".zip")) {
|
|
|
-// throw exception(UPLOADED_FOLDER_CANNOT_EMPTY);
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 创建临时目录存放解压后的文件
|
|
|
-// File tempDir = Files.createTempDirectory("specimen_images").toFile();
|
|
|
-//
|
|
|
-// try (ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(file.getInputStream())) {
|
|
|
-// ZipArchiveEntry entry;
|
|
|
-// Set<String> imagePathsSet = new HashSet<>(); // 使用 Set 来去重
|
|
|
-//
|
|
|
-// while ((entry = zipInputStream.getNextEntry()) != null) {
|
|
|
-// if (!entry.isDirectory()) {
|
|
|
-// File newFile = new File(tempDir, entry.getName());
|
|
|
-// try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile))) {
|
|
|
-// byte[] buffer = new byte[1024];
|
|
|
-// int len;
|
|
|
-// while ((len = zipInputStream.read(buffer)) > 0) {
|
|
|
-// bos.write(buffer, 0, len);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// String imageName = newFile.getName();
|
|
|
-// if (!isValidImageName(imageName)) {
|
|
|
-//
|
|
|
-// System.err.println("无效的图片格式: " + imageName);
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 根据图片名称查找对应的标本
|
|
|
-// SpecimenInfoDO specimenInfo = specimenInfoMapper.selectByImageNames(imageName);
|
|
|
-// if (specimenInfo != null) {
|
|
|
-// // 上传图片并获取 URL
|
|
|
-// String imagePath = fileApi.createFile(Files.readAllBytes(newFile.toPath()));
|
|
|
-//
|
|
|
-// // 确保 imagePath 有效且不为空
|
|
|
-// if (imagePath != null && !imagePath.trim().isEmpty()) {
|
|
|
-// // 添加新上传的路径
|
|
|
-// imagePathsSet.add(imagePath.trim()); // 使用 Set 来去重
|
|
|
-//
|
|
|
-// // 获取已存在的路径,并处理空值或无效的路径
|
|
|
-// String existingImagePaths = specimenInfo.getImagePath();
|
|
|
-// if (existingImagePaths != null && !existingImagePaths.trim().isEmpty()) {
|
|
|
-// // 清理已有路径中的方括号(如果有)
|
|
|
-// existingImagePaths = existingImagePaths.replaceAll("^\\[|\\]$", "").trim();
|
|
|
-// // 如果原路径是有效的且不是空数组,则拆分并添加到 Set 中
|
|
|
-// String[] existingPaths = existingImagePaths.split(",\\s*");
|
|
|
-// Collections.addAll(imagePathsSet, existingPaths); // 也用 Set 来去重
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 将 Set 中的路径重新拼接成逗号分隔的字符串
|
|
|
-// String newImagePaths = String.join(", ", imagePathsSet);
|
|
|
-//
|
|
|
-// // 更新所有标本的信息,确保只更新一次
|
|
|
-// for (File imageFile : tempDir.listFiles()) {
|
|
|
-// String imageName = imageFile.getName();
|
|
|
-// SpecimenInfoDO specimenInfo = specimenInfoMapper.selectByImageNames(imageName);
|
|
|
-// if (specimenInfo != null) {
|
|
|
-// specimenInfo.setImagePath("[" + newImagePaths + "]"); // 设置多个图片路径的字符串,外面加上方括号
|
|
|
-// updateSpecimenInfo(BeanUtils.toBean(specimenInfo, SpecimenInfoSaveReqVO.class));
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// } finally {
|
|
|
-// // 清理临时文件
|
|
|
-// FileUtils.deleteDirectory(tempDir);
|
|
|
-// }
|
|
|
-// return "标本图片导入成功";
|
|
|
-// }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public SpecimenImportRespVO importSpecimenImages(MultipartFile file) throws Exception {
|
|
@@ -401,6 +321,8 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
//按标本类别统计库存数
|
|
|
@Override
|
|
|
public Map<String, Integer> getSpecimenTypeStatistics() {
|
|
@@ -481,6 +403,14 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
yearData.putAll(entry.getValue());
|
|
|
yearlyStatisticsList.add(yearData);
|
|
|
}
|
|
|
+
|
|
|
+ // 按年份升序排序
|
|
|
+ yearlyStatisticsList.sort((map1, map2) -> {
|
|
|
+ Integer year1 = Integer.valueOf((String) map1.get("year"));
|
|
|
+ Integer year2 = Integer.valueOf((String) map2.get("year"));
|
|
|
+ return year1.compareTo(year2); // 年份升序排列
|
|
|
+ });
|
|
|
+
|
|
|
// 构建最终的返回结果
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
resultMap.put("code", 0);
|
|
@@ -490,6 +420,7 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public List<Map<String, Object>> getYearlySpecimenSourceStatistics() {
|
|
|
// 从数据库直接获取统计数据
|
|
@@ -518,12 +449,20 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
resultList.add(yearData);
|
|
|
}
|
|
|
|
|
|
+ // 按年份升序排序
|
|
|
+ resultList.sort((map1, map2) -> {
|
|
|
+ Long year1 = Long.valueOf((String) map1.get("year"));
|
|
|
+ Long year2 = Long.valueOf((String) map2.get("year"));
|
|
|
+ return year1.compareTo(year2); // 年份升序排列
|
|
|
+ });
|
|
|
+
|
|
|
return resultList;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// Helper 方法将整数源转换为字符串
|
|
|
- private String getSourceKey(Integer source) { // 使用 Integer 允许 null
|
|
|
- if (source == null) return "unknown"; // 处理 null 的情况
|
|
|
+ private String getSourceKey(Integer source) {
|
|
|
+ if (source == null) return "unknown";
|
|
|
switch (source) {
|
|
|
case 0: return "purchase";
|
|
|
case 1: return "donate";
|