|
@@ -99,7 +99,7 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
@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);
|
|
|
}
|
|
@@ -145,225 +145,6 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
|
|
|
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 参数校验
|
|
|
-// 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)$")) {
|
|
|
-// return false; // 只要有一个格式不正确就返回 false
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 导入图片的逻辑
|
|
|
-// @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;
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 根据图片名称查找对应的标本
|
|
|
-// 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); // 追加到已有路径
|
|
|
-// }
|
|
|
-// 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);
|
|
|
-// }
|
|
|
-
|
|
|
//测试成功
|
|
|
private boolean isValidImageName(String imageNames) {
|
|
|
if (imageNames == null) return false;
|
|
@@ -442,22 +223,6 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
|
|
|
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
|