From 16d50e1fd871b2306e7beb650463bc76263e5e98 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期二, 28 七月 2026 10:03:30 +0800
Subject: [PATCH] fix: 异常图片上传、bug修改

---
 src/main/java/com/ruoyi/safe/service/impl/SafeLineInspectionRecordServiceImpl.java |   87 +++++++++++++++++++++++--------------------
 1 files changed, 46 insertions(+), 41 deletions(-)

diff --git a/src/main/java/com/ruoyi/safe/service/impl/SafeLineInspectionRecordServiceImpl.java b/src/main/java/com/ruoyi/safe/service/impl/SafeLineInspectionRecordServiceImpl.java
index 5032ec7..bca99c5 100644
--- a/src/main/java/com/ruoyi/safe/service/impl/SafeLineInspectionRecordServiceImpl.java
+++ b/src/main/java/com/ruoyi/safe/service/impl/SafeLineInspectionRecordServiceImpl.java
@@ -1,17 +1,17 @@
 package com.ruoyi.safe.service.impl;
 
-import com.ruoyi.common.utils.SecurityUtils;
-import com.ruoyi.safe.pojo.SafeLineInspection;
-import com.ruoyi.safe.pojo.SafeLineInspectionRecord;
-import com.ruoyi.safe.mapper.SafeLineInspectionRecordMapper;
-import com.ruoyi.safe.service.SafeLineInspectionRecordService;
-import com.ruoyi.safe.service.SafeLineInspectionService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.basic.dto.StorageBlobVO;
+import com.ruoyi.basic.enums.ApplicationTypeEnum;
+import com.ruoyi.basic.enums.RecordTypeEnum;
+import com.ruoyi.basic.utils.FileUtil;
+import com.ruoyi.safe.mapper.SafeLineInspectionRecordMapper;
+import com.ruoyi.safe.pojo.SafeLineInspectionRecord;
+import com.ruoyi.safe.service.SafeLineInspectionRecordService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 
-import java.time.LocalDateTime;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -26,52 +26,57 @@
 public class SafeLineInspectionRecordServiceImpl extends ServiceImpl<SafeLineInspectionRecordMapper, SafeLineInspectionRecord> implements SafeLineInspectionRecordService {
 
     @Autowired
-    private SafeLineInspectionService safeLineInspectionService;
+    private FileUtil fileUtil;
 
     @Override
     public List<SafeLineInspectionRecord> listByInspectionId(Integer inspectionId) {
-        return this.lambdaQuery()
+        List<SafeLineInspectionRecord> records = this.lambdaQuery()
                 .eq(SafeLineInspectionRecord::getInspectionId, inspectionId)
                 .orderByDesc(SafeLineInspectionRecord::getCheckTime)
                 .list();
+        fillAttachments(records);
+        return records;
     }
 
     @Override
-    @Transactional(rollbackFor = Exception.class)
     public boolean save(SafeLineInspectionRecord entity) {
-        // 淇濆瓨宸℃璁板綍
-        boolean result = super.save(entity);
-
-        if (result && entity.getInspectionId() != null) {
-            // 鏇存柊宸℃浠诲姟鐘舵�佷负"宸℃涓�"锛屽苟璁剧疆宸℃浜轰负褰撳墠鐧诲綍鐢ㄦ埛
-            updateInspectionStatus(entity.getInspectionId());
-        }
-
-        return result;
+        boolean saved = super.save(entity);
+        syncAttachments(saved, entity);
+        return saved;
     }
 
-    /**
-     * 鏇存柊宸℃浠诲姟鐘舵�佷负"宸℃涓�"锛屽苟娣诲姞褰撳墠鐢ㄦ埛鍒板贰妫�浜哄垪琛�
-     */
-    private void updateInspectionStatus(Integer inspectionId) {
-        SafeLineInspection inspection = safeLineInspectionService.getById(inspectionId);
-        if (inspection != null && "寰呭贰妫�".equals(inspection.getStatus())) {
-            Long currentUserId = SecurityUtils.getUserId();
-            String currentUserIdStr = String.valueOf(currentUserId);
+    @Override
+    public boolean updateById(SafeLineInspectionRecord entity) {
+        boolean updated = super.updateById(entity);
+        syncAttachments(updated, entity);
+        return updated;
+    }
 
-            // 娣诲姞褰撳墠鐢ㄦ埛鍒板贰妫�浜哄垪琛紙濡傛灉涓嶅瓨鍦級
-            String inspectorId = inspection.getInspectorId();
-            if (inspectorId == null || inspectorId.isEmpty()) {
-                inspectorId = currentUserIdStr;
-            } else if (!inspectorId.contains(currentUserIdStr)) {
-                inspectorId = inspectorId + "," + currentUserIdStr;
-            }
-
-            inspection.setStatus("宸℃涓�");
-            inspection.setInspectorId(inspectorId);
-            inspection.setUpdateTime(LocalDateTime.now());
-            inspection.setUpdateUser(currentUserId.intValue());
-            safeLineInspectionService.updateById(inspection);
+    private void syncAttachments(boolean success, SafeLineInspectionRecord entity) {
+        if (!success || entity == null || entity.getId() == null || entity.getStorageBlobDTOs() == null) {
+            return;
         }
+        fileUtil.saveStorageAttachment(
+                ApplicationTypeEnum.IMAGE,
+                RecordTypeEnum.SAFE_LINE_INSPECTION_RECORD,
+                entity.getId().longValue(),
+                entity.getStorageBlobDTOs()
+        );
+    }
+
+    private void fillAttachments(List<SafeLineInspectionRecord> records) {
+        if (records == null || records.isEmpty()) {
+            return;
+        }
+        records.forEach(record -> {
+            if (record.getId() == null) {
+                return;
+            }
+            List<StorageBlobVO> attachments = fileUtil.getStorageBlobVOsByRecordTypeAndRecordId(
+                    RecordTypeEnum.SAFE_LINE_INSPECTION_RECORD,
+                    record.getId().longValue()
+            );
+            record.setStorageBlobVOs(attachments == null ? Collections.emptyList() : attachments);
+        });
     }
 }

--
Gitblit v1.9.3