|
@@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
|
|
import cn.iocoder.yudao.module.museums.dal.dataobject.specimenoutbound.SpecimenOutboundDO;
|
|
|
import cn.iocoder.yudao.module.museums.dal.mysql.specimenoutbound.SpecimenOutboundMapper;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import org.apache.tomcat.util.http.fileupload.FileUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
@@ -45,13 +46,12 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
@Resource
|
|
|
private FileApi fileApi;
|
|
|
|
|
|
+
|
|
|
public SpecimenInfoServiceImpl(SpecimenInfoMapper specimenInfoMapper, FileApi fileApi) {
|
|
|
this.specimenInfoMapper = specimenInfoMapper;
|
|
|
this.fileApi = fileApi;
|
|
|
}
|
|
|
|
|
|
- @Resource
|
|
|
- private SpecimenInfoDO specimenInfoDO;
|
|
|
|
|
|
@Override
|
|
|
public Integer createSpecimenInfo(SpecimenInfoSaveReqVO createReqVO) {
|
|
@@ -96,10 +96,131 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
}
|
|
|
|
|
|
//标本Excel的批量导入
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
|
+ public SpecimenImportRespVO importSpecimenList(List<SpecimenImportExcelVO> importSpecimens, boolean isUpdateSupport) {
|
|
|
+// 1.1 参数校验
|
|
|
+ if (CollUtil.isEmpty(importSpecimens)) {
|
|
|
+ throw exception(SPECIMEN_INFO_LIST_IS_EMPTY);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 遍历,逐个创建或更新
|
|
|
+ SpecimenImportRespVO respVO = SpecimenImportRespVO.builder()
|
|
|
+ .createSpecimenNumbers(new ArrayList<>())
|
|
|
+ .updateSpecimenNumbers(new ArrayList<>())
|
|
|
+ .failureSpecimenNumbers(new LinkedHashMap<>()).build();
|
|
|
+
|
|
|
+ importSpecimens.forEach(importSpecimen -> {
|
|
|
+ // 校验逻辑可以根据需要添加
|
|
|
+
|
|
|
+ // 2.1. 判断是否存在
|
|
|
+ SpecimenInfoDO existSpecimen = specimenInfoMapper.selectBySpecimenNumber(importSpecimen.getSpecimenNumber());
|
|
|
+
|
|
|
+ // 1. 校验图片名格式
|
|
|
+ if (!isValidImageName(importSpecimen.getImageName())) {
|
|
|
+ respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "图片名称格式不正确");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (existSpecimen == null) {
|
|
|
+ // 2.2.1 不存在则插入
|
|
|
+ SpecimenInfoDO newSpecimen = BeanUtils.toBean(importSpecimen, SpecimenInfoDO.class);
|
|
|
+ specimenInfoMapper.insert(newSpecimen);
|
|
|
+ respVO.getCreateSpecimenNumbers().add(importSpecimen.getSpecimenNumber());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2.2.2 如果存在,判断是否允许更新
|
|
|
+// if (!isUpdateSupport) {
|
|
|
+// respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "标本编号已存在,且不支持更新");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+
|
|
|
+ // 更新逻辑
|
|
|
+ SpecimenInfoDO updateSpecimen = BeanUtils.toBean(importSpecimen, SpecimenInfoDO.class);
|
|
|
+ updateSpecimen.setId(existSpecimen.getId()); // 设置 ID 进行更新
|
|
|
+ specimenInfoMapper.updateById(updateSpecimen);
|
|
|
+ respVO.getUpdateSpecimenNumbers().add(importSpecimen.getSpecimenNumber());
|
|
|
+ });
|
|
|
+
|
|
|
+ return respVO;
|
|
|
+ }
|
|
|
+// private boolean isValidImageName(String imageName) {
|
|
|
+// return imageName != null && imageName.matches(".*\\.(jpg|jpeg|png|gif)$"); // 检查格式
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// @Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
|
+// public String importSpecimenImages(MultipartFile file) throws Exception {
|
|
|
+// // 校验文件类型
|
|
|
+// 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())) {
|
|
|
+// ZipEntry entry;
|
|
|
+// 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);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// // 处理每个图片文件
|
|
|
+// File[] imageFiles = tempDir.listFiles();
|
|
|
+// if (imageFiles != null) {
|
|
|
+// for (File imageFile : imageFiles) {
|
|
|
+// String imageName = imageFile.getName();
|
|
|
+// if (!isValidImageName(imageName)) {
|
|
|
+// // 如果不符合格式,抛出异常或记录日志
|
|
|
+// System.err.println("无效的图片格式: " + imageName);
|
|
|
+// continue; // 或者 throw new Exception("无效的图片格式: " + imageName);
|
|
|
+// }
|
|
|
+// // 根据图片名称查找对应的标本
|
|
|
+// SpecimenInfoDO specimenInfo = specimenInfoMapper.selectByImageName(imageName);
|
|
|
+// if (specimenInfo != null) {
|
|
|
+// // 上传图片并获取URL
|
|
|
+// String imagePath = fileApi.createFile(Files.readAllBytes(imageFile.toPath()));
|
|
|
+// // 更新标本信息中的图片路径
|
|
|
+// specimenInfo.setImagePath(imagePath);
|
|
|
+// specimenInfoMapper.updateById(specimenInfo);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 清理临时文件
|
|
|
+// FileUtils.deleteDirectory(tempDir);
|
|
|
+// return "标本图片导入成功";
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// @Transactional(rollbackFor = Exception.class) // 事务管理
|
|
|
+// public void importSpecimenData(MultipartFile excelFile, MultipartFile imageFile, boolean updateSupport) throws Exception {
|
|
|
+// // 1. 导入标本
|
|
|
+// List<SpecimenImportExcelVO> list = ExcelUtils.read(excelFile, SpecimenImportExcelVO.class);
|
|
|
+// SpecimenImportRespVO importRespVO = importSpecimenList(list, updateSupport);
|
|
|
+//
|
|
|
+// // 2. 导入图片
|
|
|
+// String imageImportResult = importSpecimenImages(imageFile);
|
|
|
+//
|
|
|
+// // 可以根据需要记录导入结果
|
|
|
+// System.out.println("标本导入结果: " + importRespVO);
|
|
|
+// System.out.println("标本图片导入结果: " + imageImportResult);
|
|
|
+// }
|
|
|
+
|
|
|
+ //测试
|
|
|
// @Override
|
|
|
// @Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
|
// public SpecimenImportRespVO importSpecimenList(List<SpecimenImportExcelVO> importSpecimens, boolean isUpdateSupport) {
|
|
|
-//// 1.1 参数校验
|
|
|
+// // 1.1 参数校验
|
|
|
// if (CollUtil.isEmpty(importSpecimens)) {
|
|
|
// throw exception(SPECIMEN_INFO_LIST_IS_EMPTY);
|
|
|
// }
|
|
@@ -117,7 +238,10 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
// SpecimenInfoDO existSpecimen = specimenInfoMapper.selectBySpecimenNumber(importSpecimen.getSpecimenNumber());
|
|
|
//
|
|
|
// // 1. 校验图片名格式
|
|
|
-// if (!isValidImageName(importSpecimen.getImageName())) {
|
|
|
+// String[] imageNames = importSpecimen.getImageName().split(","); // 处理多个图片名
|
|
|
+// boolean validImageNames = Arrays.stream(imageNames).allMatch(this::isValidImageName);
|
|
|
+//
|
|
|
+// if (!validImageNames) {
|
|
|
// respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "图片名称格式不正确");
|
|
|
// return;
|
|
|
// }
|
|
@@ -125,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);
|
|
@@ -145,10 +271,21 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
//
|
|
|
// return respVO;
|
|
|
// }
|
|
|
-// private boolean isValidImageName(String imageName) {
|
|
|
-// return imageName != null && imageName.matches(".*\\.(jpg|jpeg|png|gif)$"); // 检查格式
|
|
|
+//
|
|
|
+//
|
|
|
+// // 检查多个图片名称格式
|
|
|
+// private boolean isValidImageName(String imageNames) {
|
|
|
+// if (imageNames == null) return false;
|
|
|
+// String[] names = imageNames.split(",");
|
|
|
+// for (String name : names) {
|
|
|
+// if (!name.matches(".*\\.(jpg|jpeg|png|gif)$")) {
|
|
|
+// return false; // 只要有一个格式不正确就返回 false
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return true;
|
|
|
// }
|
|
|
//
|
|
|
+// // 导入图片的逻辑
|
|
|
// @Override
|
|
|
// @Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
|
// public String importSpecimenImages(MultipartFile file) throws Exception {
|
|
@@ -174,6 +311,7 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
+//
|
|
|
// // 处理每个图片文件
|
|
|
// File[] imageFiles = tempDir.listFiles();
|
|
|
// if (imageFiles != null) {
|
|
@@ -182,15 +320,22 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
// if (!isValidImageName(imageName)) {
|
|
|
// // 如果不符合格式,抛出异常或记录日志
|
|
|
// System.err.println("无效的图片格式: " + imageName);
|
|
|
-// continue; // 或者 throw new Exception("无效的图片格式: " + 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()));
|
|
|
+//
|
|
|
// // 更新标本信息中的图片路径
|
|
|
-// specimenInfo.setImagePath(imagePath);
|
|
|
+// String currentImagePaths = specimenInfo.getImagePath();
|
|
|
+// if (currentImagePaths == null || currentImagePaths.isEmpty()) {
|
|
|
+// specimenInfo.setImagePath(imagePath); // 第一次设置
|
|
|
+// } else {
|
|
|
+// specimenInfo.setImagePath(currentImagePaths + "," + imagePath); // 追加到已有路径
|
|
|
+// }
|
|
|
// specimenInfoMapper.updateById(specimenInfo);
|
|
|
// }
|
|
|
// }
|
|
@@ -201,6 +346,9 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
// return "标本图片导入成功";
|
|
|
// }
|
|
|
//
|
|
|
+//
|
|
|
+//
|
|
|
+// // 主导入逻辑
|
|
|
// @Override
|
|
|
// @Transactional(rollbackFor = Exception.class) // 事务管理
|
|
|
// public void importSpecimenData(MultipartFile excelFile, MultipartFile imageFile, boolean updateSupport) throws Exception {
|
|
@@ -216,76 +364,17 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
// System.out.println("标本图片导入结果: " + imageImportResult);
|
|
|
// }
|
|
|
|
|
|
- //测试
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
|
- public SpecimenImportRespVO importSpecimenList(List<SpecimenImportExcelVO> importSpecimens, boolean isUpdateSupport) {
|
|
|
- // 1.1 参数校验
|
|
|
- if (CollUtil.isEmpty(importSpecimens)) {
|
|
|
- throw exception(SPECIMEN_INFO_LIST_IS_EMPTY);
|
|
|
- }
|
|
|
-
|
|
|
- // 2. 遍历,逐个创建或更新
|
|
|
- SpecimenImportRespVO respVO = SpecimenImportRespVO.builder()
|
|
|
- .createSpecimenNumbers(new ArrayList<>())
|
|
|
- .updateSpecimenNumbers(new ArrayList<>())
|
|
|
- .failureSpecimenNumbers(new LinkedHashMap<>()).build();
|
|
|
-
|
|
|
- importSpecimens.forEach(importSpecimen -> {
|
|
|
- // 校验逻辑可以根据需要添加
|
|
|
-
|
|
|
- // 2.1. 判断是否存在
|
|
|
- SpecimenInfoDO existSpecimen = specimenInfoMapper.selectBySpecimenNumber(importSpecimen.getSpecimenNumber());
|
|
|
-
|
|
|
- // 1. 校验图片名格式
|
|
|
- String[] imageNames = importSpecimen.getImageName().split(","); // 处理多个图片名
|
|
|
- boolean validImageNames = Arrays.stream(imageNames).allMatch(this::isValidImageName);
|
|
|
-
|
|
|
- if (!validImageNames) {
|
|
|
- respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "图片名称格式不正确");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- 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;
|
|
|
-// }
|
|
|
-
|
|
|
- // 更新逻辑
|
|
|
- SpecimenInfoDO updateSpecimen = BeanUtils.toBean(importSpecimen, SpecimenInfoDO.class);
|
|
|
- updateSpecimen.setId(existSpecimen.getId()); // 设置 ID 进行更新
|
|
|
- specimenInfoMapper.updateById(updateSpecimen);
|
|
|
- respVO.getUpdateSpecimenNumbers().add(importSpecimen.getSpecimenNumber());
|
|
|
- });
|
|
|
-
|
|
|
- return respVO;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 检查多个图片名称格式
|
|
|
+ //测试成功
|
|
|
private boolean isValidImageName(String imageNames) {
|
|
|
if (imageNames == null) return false;
|
|
|
String[] names = imageNames.split(",");
|
|
|
for (String name : names) {
|
|
|
- if (!name.matches(".*\\.(jpg|jpeg|png|gif)$")) {
|
|
|
+ if (!name.matches(".+\\.(jpg|jpeg|png|gif)$")) {
|
|
|
return false; // 只要有一个格式不正确就返回 false
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
- // 导入图片的逻辑
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
|
public String importSpecimenImages(MultipartFile file) throws Exception {
|
|
@@ -293,6 +382,7 @@ 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())) {
|
|
@@ -310,45 +400,48 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ // 处理每个图片文件
|
|
|
+ File[] imageFiles = tempDir.listFiles();
|
|
|
+ if (imageFiles != null) {
|
|
|
+ for (File imageFile : imageFiles) {
|
|
|
+ String imageName = imageFile.getName();
|
|
|
+ if (!isValidImageName(imageName)) {
|
|
|
+ System.err.println("无效的图片格式: " + imageName);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 根据图片名称查找对应的标本
|
|
|
+ SpecimenInfoDO specimenInfo = specimenInfoMapper.selectByImageNames(imageName);
|
|
|
+ if (specimenInfo != null) {
|
|
|
+ // 上传图片并获取URL
|
|
|
+ String imagePath = fileApi.createFile(Files.readAllBytes(imageFile.toPath()));
|
|
|
+ // 获取当前的图片路径
|
|
|
+ Set<String> imagePathsSet = new HashSet<>();
|
|
|
+ String existingImagePaths = specimenInfo.getImagePath();
|
|
|
+
|
|
|
+ // 如果 existingImagePaths 为空或仅包含空白字符,则不添加
|
|
|
+ if (existingImagePaths != null && !existingImagePaths.trim().isEmpty()) {
|
|
|
+ Collections.addAll(imagePathsSet, existingImagePaths.split(","));
|
|
|
+ }
|
|
|
|
|
|
- // 处理每个图片文件
|
|
|
- File[] imageFiles = tempDir.listFiles();
|
|
|
- if (imageFiles != null) {
|
|
|
- for (File imageFile : imageFiles) {
|
|
|
- String imageName = imageFile.getName();
|
|
|
- if (!isValidImageName(imageName)) {
|
|
|
- // 如果不符合格式,抛出异常或记录日志
|
|
|
- System.err.println("无效的图片格式: " + imageName);
|
|
|
- continue;
|
|
|
- }
|
|
|
+ // 检查 imagePath 是否有效
|
|
|
+ if (imagePath != null && !imagePath.trim().isEmpty()) {
|
|
|
+ imagePathsSet.add(imagePath);
|
|
|
+ }
|
|
|
|
|
|
- // 根据图片名称查找对应的标本
|
|
|
- List<SpecimenInfoDO> specimenInfoList = (List<SpecimenInfoDO>) specimenInfoMapper.selectByImageName(imageName);
|
|
|
- for (SpecimenInfoDO specimenInfo : specimenInfoList) {
|
|
|
- // 上传图片并获取URL
|
|
|
- String imagePath = fileApi.createFile(Files.readAllBytes(imageFile.toPath()));
|
|
|
-
|
|
|
- // 更新标本信息中的图片路径
|
|
|
- String currentImagePaths = specimenInfo.getImagePath();
|
|
|
- if (currentImagePaths == null || currentImagePaths.isEmpty()) {
|
|
|
- specimenInfo.setImagePath(imagePath); // 第一次设置
|
|
|
- } else {
|
|
|
- specimenInfo.setImagePath(currentImagePaths + "," + imagePath); // 追加到已有路径
|
|
|
+ // 转换回字符串,避免前面出现多余的逗号
|
|
|
+ String newImagePaths = String.join(",", imagePathsSet);
|
|
|
+ specimenInfo.setImagePath(newImagePaths);
|
|
|
+
|
|
|
+ updateSpecimenInfo(BeanUtils.toBean(specimenInfo, SpecimenInfoSaveReqVO.class));
|
|
|
}
|
|
|
- specimenInfoMapper.updateById(specimenInfo);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
// 清理临时文件
|
|
|
FileUtils.deleteDirectory(tempDir);
|
|
|
return "标本图片导入成功";
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- // 主导入逻辑
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class) // 事务管理
|
|
|
public void importSpecimenData(MultipartFile excelFile, MultipartFile imageFile, boolean updateSupport) throws Exception {
|
|
@@ -365,21 +458,12 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
//工作台
|
|
|
//根据入库的登记情况统计本年标本入库信息
|
|
|
-// @Override
|
|
|
-// public List<SpecimenInfoDO> getEntryStatistics(int year) {
|
|
|
-// return specimenInfoMapper.selectEntryStatisticsByYear(year);
|
|
|
-// }
|
|
|
-
|
|
|
@Override
|
|
|
public List<Map<String, Object>> getMonthlyEntryStatistics(int year) {
|
|
|
return specimenInfoMapper.selectMonthlyEntryStatisticsByYear(year);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
//按标本类别统计库存数
|
|
|
@Override
|
|
|
public List<SpecimenInfoDO> getSpecimenTypeStatistics(int specimen_type) {
|
|
@@ -392,53 +476,6 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
|
|
|
|
|
|
//根据出、回、入库登记统计标本历年增减情况
|
|
|
-// @Override
|
|
|
-// public Map<Integer, Map<String, Integer>> getYearlySpecimenStatistics() {
|
|
|
-// // 年份与标本统计信息的映射
|
|
|
-// Map<Integer, Map<String, Integer>> yearlyDataMap = new HashMap<>();
|
|
|
-//
|
|
|
-// // 获取入库记录
|
|
|
-// List<SpecimenInfoDO> inStockRecords = specimenInfoMapper.getInStockRecords();
|
|
|
-// if (inStockRecords == null) {
|
|
|
-// inStockRecords = new ArrayList<>(); // 初始化为空列表
|
|
|
-// }
|
|
|
-// for (SpecimenInfoDO record : inStockRecords) {
|
|
|
-// if (record.getCreateTime() != null) { // 检查时间字段
|
|
|
-// int year = record.getCreateTime().getYear(); // 获取年份
|
|
|
-// yearlyDataMap.putIfAbsent(year, new HashMap<>());
|
|
|
-// yearlyDataMap.get(year).put("inStockCount", yearlyDataMap.get(year).getOrDefault("inStockCount", 0) + 1);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 获取出库记录
|
|
|
-// List<SpecimenOutboundDO> outboundRecords = specimenOutboundMapper.getOutboundRecords();
|
|
|
-// if (outboundRecords == null) {
|
|
|
-// outboundRecords = new ArrayList<>(); // 初始化为空列表
|
|
|
-// }
|
|
|
-// for (SpecimenOutboundDO record : outboundRecords) {
|
|
|
-// if (record.getOutgoingTime() != null) { // 检查时间字段
|
|
|
-// int year = record.getOutgoingTime().getYear(); // 获取年份
|
|
|
-// yearlyDataMap.putIfAbsent(year, new HashMap<>());
|
|
|
-// yearlyDataMap.get(year).put("outStockCount", yearlyDataMap.get(year).getOrDefault("outStockCount", 0) + 1);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 获取回库记录
|
|
|
-// List<SpecimenOutboundDO> inboundRecords = specimenOutboundMapper.getOutboundRecords();
|
|
|
-// if (inboundRecords == null) {
|
|
|
-// inboundRecords = new ArrayList<>(); // 初始化为空列表
|
|
|
-// }
|
|
|
-// for (SpecimenOutboundDO record : inboundRecords) {
|
|
|
-// if (record.getReturnDate() != null) { // 检查时间字段
|
|
|
-// int year = record.getReturnDate().getYear(); // 获取年份
|
|
|
-// yearlyDataMap.putIfAbsent(year, new HashMap<>());
|
|
|
-// yearlyDataMap.get(year).put("returnCount", yearlyDataMap.get(year).getOrDefault("returnCount", 0) + 1);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// return yearlyDataMap;
|
|
|
-// }
|
|
|
-
|
|
|
@Override
|
|
|
public Map<String, Object> getYearlySpecimenStatistics() {
|
|
|
// 创建一个列表来存放每年的统计数据
|
|
@@ -509,33 +546,6 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-// @Override
|
|
|
-// public Map<Integer, Map<String, Integer>> getYearlySpecimenSourceStatistics() {
|
|
|
-// // 年份与标本来源统计信息的映射
|
|
|
-// Map<Integer, Map<String, Integer>> yearlySourceDataMap = new HashMap<>();
|
|
|
-//
|
|
|
-// // 获取入库记录
|
|
|
-// List<SpecimenInfoDO> inStockRecords = specimenInfoMapper.getInStockRecords();
|
|
|
-// if (inStockRecords == null) {
|
|
|
-// inStockRecords = new ArrayList<>(); // 初始化为空列表
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 统计入库记录
|
|
|
-// for (SpecimenInfoDO record : inStockRecords) {
|
|
|
-// if (record != null && record.getCreateTime() != null) { // 检查 record 和 createTime
|
|
|
-// int year = record.getCreateTime().getYear(); // 获取年份
|
|
|
-// yearlySourceDataMap.putIfAbsent(year, new HashMap<>());
|
|
|
-//
|
|
|
-// // 根据标本来源进行统计
|
|
|
-// String sourceKey = getSourceKey(record.getSource());
|
|
|
-// yearlySourceDataMap.get(year).put(sourceKey, yearlySourceDataMap.get(year).getOrDefault(sourceKey, 0) + 1);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// return yearlySourceDataMap;
|
|
|
-// }
|
|
|
-
|
|
|
@Override
|
|
|
public List<Map<String, Object>> getYearlySpecimenSourceStatistics() {
|
|
|
// 年份与标本来源统计信息的映射
|