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/SafeLineInspectionHazardServiceImpl.java |   66 +++++++++++++++++++++++++++++++--
 1 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/ruoyi/safe/service/impl/SafeLineInspectionHazardServiceImpl.java b/src/main/java/com/ruoyi/safe/service/impl/SafeLineInspectionHazardServiceImpl.java
index 733043d..4b53b5c 100644
--- a/src/main/java/com/ruoyi/safe/service/impl/SafeLineInspectionHazardServiceImpl.java
+++ b/src/main/java/com/ruoyi/safe/service/impl/SafeLineInspectionHazardServiceImpl.java
@@ -2,13 +2,19 @@
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.ruoyi.safe.pojo.SafeLineInspectionHazard;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.project.system.domain.SysUser;
+import com.ruoyi.project.system.mapper.SysUserMapper;
 import com.ruoyi.safe.mapper.SafeLineInspectionHazardMapper;
+import com.ruoyi.safe.pojo.SafeLineInspectionHazard;
 import com.ruoyi.safe.service.SafeLineInspectionHazardService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
+import java.time.LocalDateTime;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -21,21 +27,73 @@
 @Service
 public class SafeLineInspectionHazardServiceImpl extends ServiceImpl<SafeLineInspectionHazardMapper, SafeLineInspectionHazard> implements SafeLineInspectionHazardService {
 
+    @Autowired
+    private SysUserMapper sysUserMapper;
+
     @Override
     public IPage<SafeLineInspectionHazard> pageSafeLineInspectionHazard(Page page, SafeLineInspectionHazard safeLineInspectionHazard) {
-        return this.lambdaQuery()
+        IPage<SafeLineInspectionHazard> result = this.lambdaQuery()
                 .eq(safeLineInspectionHazard.getInspectionId() != null, SafeLineInspectionHazard::getInspectionId, safeLineInspectionHazard.getInspectionId())
                 .like(safeLineInspectionHazard.getHazardCode() != null, SafeLineInspectionHazard::getHazardCode, safeLineInspectionHazard.getHazardCode())
                 .eq(safeLineInspectionHazard.getStatus() != null, SafeLineInspectionHazard::getStatus, safeLineInspectionHazard.getStatus())
                 .orderByDesc(SafeLineInspectionHazard::getCreateTime)
                 .page(page);
+        fillRectifyUserName(result.getRecords());
+        return result;
     }
 
     @Override
     public List<SafeLineInspectionHazard> listByInspectionId(Integer inspectionId) {
-        return this.lambdaQuery()
+        List<SafeLineInspectionHazard> records = this.lambdaQuery()
                 .eq(SafeLineInspectionHazard::getInspectionId, inspectionId)
                 .orderByDesc(SafeLineInspectionHazard::getCreateTime)
                 .list();
+        fillRectifyUserName(records);
+        return records;
+    }
+
+    @Override
+    public boolean save(SafeLineInspectionHazard entity) {
+        if (entity.getHazardCode() == null || entity.getHazardCode().isEmpty()) {
+            entity.setHazardCode(generateHazardCode());
+        }
+        return super.save(entity);
+    }
+
+    @Override
+    public boolean updateById(SafeLineInspectionHazard entity) {
+        if ("宸叉暣鏀�".equals(entity.getStatus())) {
+            Long currentUserId = SecurityUtils.getUserId();
+            entity.setRectifyUserId(currentUserId.intValue());
+            entity.setRectifyTime(LocalDateTime.now());
+        }
+        return super.updateById(entity);
+    }
+
+    private String generateHazardCode() {
+        long count = this.count() + 1;
+        return "YH" + String.format("%05d", count);
+    }
+
+    private void fillRectifyUserName(List<SafeLineInspectionHazard> records) {
+        if (records == null || records.isEmpty()) {
+            return;
+        }
+        List<Long> userIds = records.stream()
+                .map(SafeLineInspectionHazard::getRectifyUserId)
+                .filter(Objects::nonNull)
+                .map(Integer::longValue)
+                .distinct()
+                .collect(Collectors.toList());
+        if (userIds.isEmpty()) {
+            return;
+        }
+        Map<Long, String> userMap = sysUserMapper.selectUserByIds(userIds).stream()
+                .collect(Collectors.toMap(SysUser::getUserId, SysUser::getNickName, (v1, v2) -> v1));
+        records.forEach(record -> {
+            if (record.getRectifyUserId() != null) {
+                record.setRectifyUserName(userMap.getOrDefault(record.getRectifyUserId().longValue(), "鏈煡鐢ㄦ埛"));
+            }
+        });
     }
 }

--
Gitblit v1.9.3