Browse Source

日志记录

hyy 4 months ago
parent
commit
0dc4a127ff

+ 1 - 1
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/controller/admin/specimeninfo/SpecimenInfoController.java

@@ -191,7 +191,7 @@ public class SpecimenInfoController {
                 throw exception(INVALID_IMAGE_FORMAT);
             }
         }
-        System.gc();
+//        System.gc();
         return success(importResult);
     }
 

+ 0 - 10
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/controller/admin/specimeninfo/vo/SpecimenImportRespVO.java

@@ -26,14 +26,4 @@ public class SpecimenImportRespVO {
 
     @Schema(description = "成功导入的标本id", requiredMode = Schema.RequiredMode.REQUIRED)
     private List<Long> createdSpecimenIds; // 新增字段
-
-//    @Schema(description = "创建成功的图片名称数组", requiredMode = Schema.RequiredMode.REQUIRED)
-//    private List<String> createSpecimenImages;
-//
-//    @Schema(description = "更新成功的图片名称数组", requiredMode = Schema.RequiredMode.REQUIRED)
-//    private List<String> updateSpecimenImages;
-//
-//    @Schema(description = "导入失败的图片集合,key 为图片名称,value 为失败原因", requiredMode = Schema.RequiredMode.REQUIRED)
-//    private Map<String, String> failureSpecimenImages;
-
 }

+ 6 - 113
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/service/specimeninfo/SpecimenInfoServiceImpl.java

@@ -6,11 +6,13 @@ 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 cn.iocoder.yudao.module.museums.enums.social.LogRecordConstants;
+import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
 import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.mzt.logapi.context.LogRecordContext;
+import com.mzt.logapi.service.impl.DiffParseFunction;
 import com.mzt.logapi.starter.annotation.LogRecord;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
@@ -83,15 +85,6 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
         return "标本创建成功,标本ID:" + specimenInfo.getId();
     }
 
-//    @Override
-//    public void updateSpecimenInfo(SpecimenInfoSaveReqVO updateReqVO) {
-//        // 校验存在
-//        validateSpecimenInfoExists(updateReqVO.getId());
-//        // 更新
-//        SpecimenInfoDO updateObj = BeanUtils.toBean(updateReqVO, SpecimenInfoDO.class);
-//        specimenInfoMapper.updateById(updateObj);
-//    }
-
 //    @Override
 //    @LogRecord(type = MUSEUMS_SPECIMEN_TYPE, subType = MUSEUMS_SPECIMEN_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}",
 //            success = MUSEUMS_SPECIMEN_UPDATE_SUCCESS , extra = "{{#updateReqVO.id}}")
@@ -113,9 +106,11 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
         if(specimenInfo != null){
             SpecimenInfoDO updateObj = BeanUtils.toBean(updateReqVO, SpecimenInfoDO.class);
             specimenInfoMapper.updateById(updateObj);
-            LogRecordContext.putVariable("update-specimen", updateObj);
+            // 3. 记录操作日志上下文
+             LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(specimenInfo, SpecimenInfoSaveReqVO.class));
         }
     }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     @LogRecord(type = MUSEUMS_SPECIMEN_TYPE, subType = MUSEUMS_SPECIMEN_DELETE_SUB_TYPE, bizNo = "{{#id}}",
@@ -242,108 +237,6 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
         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();
-//        // 创建一个临时文件用于存储上传的 ZIP 文件
-//        File tempZipFile = File.createTempFile("uploaded_", ".zip");
-//        // 将 MultipartFile 的内容复制到临时文件
-//        file.transferTo(tempZipFile);
-////        try (ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(tempZipFile.toPath()))) {
-////            ZipEntry entry;
-////            while ((entry = zipInputStream.getNextEntry()) != null) {
-////                if (!entry.isDirectory()) {
-////                    File newFile = new File(tempDir, entry.getName());
-////                    // 确保目录存在
-////                    newFile.getParentFile().mkdirs();
-////                    // 进行解压
-////                    try (BufferedOutputStream bos = new BufferedOutputStream(Files.newOutputStream(newFile.toPath()))) {
-////                        byte[] buffer = new byte[1024];
-////                        int len;
-////                        while ((len = zipInputStream.read(buffer)) > 0) {
-////                            bos.write(buffer, 0, len);
-////                        }
-////                    }
-////                }
-////                zipInputStream.closeEntry();
-////            }
-//        try (ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(Files.newInputStream(tempZipFile.toPath()))) {
-//            ZipArchiveEntry entry;
-//            while ((entry = zipInputStream.getNextEntry()) != null) {
-//                if (!entry.isDirectory()) {
-//                    // 获取解压后的文件名,Commons Compress 会自动处理编码
-//                    String entryName = entry.getName();
-//                    File newFile = new File(tempDir, entryName);
-//                    newFile.getParentFile().mkdirs();  // 确保目录存在
-//                    try (BufferedOutputStream bos = new BufferedOutputStream(Files.newOutputStream(newFile.toPath()))) {
-//                        byte[] buffer = new byte[1024];
-//                        int len;
-//                        while ((len = zipInputStream.read(buffer)) > 0) {
-//                            bos.write(buffer, 0, len);
-//                        }
-//                    }
-//                }
-//                zipInputStream.close();
-//            }
-//            // 处理每个图片文件
-//            File[] imageFiles = tempDir.listFiles();
-//            if (imageFiles != null) {
-//                Set<String> imagePathsSet = new HashSet<>();  // 使用 Set 防止重复
-//                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()));
-//
-//                        // 确保 imagePath 有效且不为空
-//                        if (imagePath != null && !imagePath.trim().isEmpty()) {
-//                            // 添加新上传的路径
-//                            imagePathsSet.add(imagePath.trim());
-//
-//                            // 添加已存在的路径
-//                            String existingImagePaths = specimenInfo.getImagePath();
-//                            if (existingImagePaths != null && !existingImagePaths.trim().isEmpty()&& !existingImagePaths.equals("[]")) {
-//                                String[] existingPaths = existingImagePaths.split(",\\s*");
-//                                Collections.addAll(imagePathsSet, existingPaths);
-//                            }
-//                        }
-//                    }
-//                }
-//
-//                // 生成最终的逗号分隔的字符串
-//                String newImagePaths = String.join(", ", imagePathsSet);
-//                // 更新所有标本的信息,确保只更新一次
-//                for (File imageFile : imageFiles) {
-//                    String imageName = imageFile.getName();
-//                    SpecimenInfoDO specimenInfo = specimenInfoMapper.selectByImageNames(imageName);
-//                    if (specimenInfo != null) {
-//                        specimenInfo.setImagePath(newImagePaths);
-//                        updateSpecimenInfo(BeanUtils.toBean(specimenInfo, SpecimenInfoSaveReqVO.class));
-//                    }
-//                }
-//            }
-//            zipInputStream.close();
-//            System.gc();
-//        } finally {
-//            // 清理临时文件
-//            FileUtils.deleteDirectory(tempDir);
-//        }
-//        return "标本图片导入成功";
-//    }
-
     @Override
     @Transactional(rollbackFor = Exception.class)
     public String importSpecimenImages(MultipartFile file) throws Exception {
@@ -392,7 +285,7 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
 
                             // 获取已存在的路径,并处理空值或无效的路径
                             String existingImagePaths = specimenInfo.getImagePath();
-                            if (existingImagePaths != null && !existingImagePaths.trim().isEmpty() && !existingImagePaths.equals("[]")) {
+                            if (existingImagePaths != null && !existingImagePaths.trim().isEmpty()) {
                                 // 清理已有路径中的方括号(如果有)
                                 existingImagePaths = existingImagePaths.replaceAll("^\\[|\\]$", "").trim();
                                 // 如果原路径是有效的且不是空数组,则拆分并添加到 Set 中