From 64de92ae028b582b7fbe8d3c84eb568edf0d400f Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期四, 30 七月 2026 13:49:37 +0800
Subject: [PATCH] feat: 安全设施巡检调整
---
src/main/java/com/ruoyi/safe/service/impl/SafeLineInspectionHazardServiceImpl.java | 222 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 214 insertions(+), 8 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..a2d03e7 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,30 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.ruoyi.safe.pojo.SafeLineInspectionHazard;
-import com.ruoyi.safe.mapper.SafeLineInspectionHazardMapper;
-import com.ruoyi.safe.service.SafeLineInspectionHazardService;
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.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.project.system.domain.SysUser;
+import com.ruoyi.project.system.mapper.SysUserMapper;
+import com.ruoyi.safe.mapper.SafeLineInspectionHazardMapper;
+import com.ruoyi.safe.mapper.SafeLineInspectionMapper;
+import com.ruoyi.safe.pojo.SafeHidden;
+import com.ruoyi.safe.pojo.SafeLineInspection;
+import com.ruoyi.safe.pojo.SafeLineInspectionHazard;
+import com.ruoyi.safe.service.SafeHiddenService;
+import com.ruoyi.safe.service.SafeLineInspectionHazardService;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import java.util.List;
+import java.io.Serializable;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.*;
+import java.util.stream.Collectors;
/**
* <p>
@@ -21,21 +38,210 @@
@Service
public class SafeLineInspectionHazardServiceImpl extends ServiceImpl<SafeLineInspectionHazardMapper, SafeLineInspectionHazard> implements SafeLineInspectionHazardService {
+ @Autowired
+ private SysUserMapper sysUserMapper;
+ @Autowired
+ private SafeHiddenService safeHiddenService;
+ @Autowired
+ private SafeLineInspectionMapper safeLineInspectionMapper;
+ @Autowired
+ private FileUtil fileUtil;
+
@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())
+ .like(StringUtils.isNotBlank(safeLineInspectionHazard.getHazardCode()), SafeLineInspectionHazard::getHazardCode, safeLineInspectionHazard.getHazardCode())
+ .like(StringUtils.isNotBlank(safeLineInspectionHazard.getHazardDesc()), SafeLineInspectionHazard::getHazardDesc, safeLineInspectionHazard.getHazardDesc())
+ .eq(StringUtils.isNotBlank(safeLineInspectionHazard.getStatus()), SafeLineInspectionHazard::getStatus, safeLineInspectionHazard.getStatus())
.orderByDesc(SafeLineInspectionHazard::getCreateTime)
.page(page);
+ fillRectifyUserName(result.getRecords());
+ fillInspectionInfo(result.getRecords());
+ fillRectifyAttachments(result.getRecords());
+ return result;
+ }
+
+ @Override
+ public SafeLineInspectionHazard getById(Serializable id) {
+ SafeLineInspectionHazard record = super.getById(id);
+ if (record != null) {
+ fillRectifyUserName(Collections.singletonList(record));
+ fillInspectionInfo(Collections.singletonList(record));
+ fillRectifyAttachments(Collections.singletonList(record));
+ }
+ return record;
}
@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);
+ fillInspectionInfo(records);
+ fillRectifyAttachments(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) {
+ SafeLineInspectionHazard oldRecord = entity.getId() == null ? null : this.getById(entity.getId());
+ if (oldRecord == null) {
+ throw new IllegalArgumentException("鏁存敼璁板綍涓嶅瓨鍦�");
+ }
+ Integer safeHiddenId = entity.getSafeHiddenId() != null
+ ? entity.getSafeHiddenId()
+ : oldRecord.getSafeHiddenId();
+ if ("宸叉暣鏀�".equals(entity.getStatus())) {
+ validateRectify(entity, oldRecord);
+ entity.setRectifyUserId(oldRecord.getRectifyUserId());
+ entity.setRectifyTime(LocalDateTime.now());
+ }
+ boolean updated = super.updateById(entity);
+ if (updated && "宸叉暣鏀�".equals(entity.getStatus())) {
+ syncRectifyAttachments(entity);
+ }
+ if (updated && "宸叉暣鏀�".equals(entity.getStatus()) && safeHiddenId != null) {
+ SafeHidden hidden = new SafeHidden();
+ hidden.setId(safeHiddenId);
+ hidden.setRectifyMeasures(entity.getRectifyDesc());
+ hidden.setRectifyActualTime(LocalDate.now());
+ safeHiddenService.updateById(hidden);
+ }
+ if (updated && "宸叉暣鏀�".equals(entity.getStatus())) {
+ Integer inspectionId = entity.getInspectionId() != null
+ ? entity.getInspectionId()
+ : oldRecord.getInspectionId();
+ completeInspectionIfAllRectified(inspectionId);
+ }
+ return updated;
+ }
+
+ private void validateRectify(SafeLineInspectionHazard entity, SafeLineInspectionHazard oldRecord) {
+ if ("宸叉暣鏀�".equals(oldRecord.getStatus())) {
+ throw new IllegalArgumentException("璇ラ殣鎮e凡鏁存敼锛岃鍕块噸澶嶆搷浣�");
+ }
+ Long currentUserId = SecurityUtils.getUserId();
+ if (oldRecord.getRectifyUserId() == null || currentUserId == null
+ || !oldRecord.getRectifyUserId().equals(currentUserId.intValue())) {
+ throw new IllegalArgumentException("鍙湁鏁存敼璐d换浜哄彲浠ヨ繘琛屾暣鏀�");
+ }
+ if (StringUtils.isBlank(entity.getRectifyDesc())) {
+ throw new IllegalArgumentException("璇疯緭鍏ユ暣鏀硅鏄�");
+ }
+ if (entity.getStorageBlobDTOs() == null || entity.getStorageBlobDTOs().isEmpty()) {
+ throw new IllegalArgumentException("璇蜂笂浼犳暣鏀瑰悗鐓х墖");
+ }
+ }
+
+ private void syncRectifyAttachments(SafeLineInspectionHazard entity) {
+ if (entity.getId() == null || entity.getStorageBlobDTOs() == null) {
+ return;
+ }
+ fileUtil.saveStorageAttachment(
+ ApplicationTypeEnum.IMAGE,
+ RecordTypeEnum.SAFE_LINE_INSPECTION_HAZARD,
+ entity.getId().longValue(),
+ entity.getStorageBlobDTOs()
+ );
+ }
+
+ 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(), "鏈煡鐢ㄦ埛"));
+ }
+ });
+ }
+
+ private void fillInspectionInfo(List<SafeLineInspectionHazard> records) {
+ if (records == null || records.isEmpty()) {
+ return;
+ }
+ List<Integer> inspectionIds = records.stream()
+ .map(SafeLineInspectionHazard::getInspectionId)
+ .filter(Objects::nonNull)
+ .distinct()
+ .collect(Collectors.toList());
+ if (inspectionIds.isEmpty()) {
+ return;
+ }
+ Map<Integer, SafeLineInspection> inspectionMap = safeLineInspectionMapper.selectBatchIds(inspectionIds).stream()
+ .collect(Collectors.toMap(SafeLineInspection::getId, item -> item, (v1, v2) -> v1));
+ records.forEach(record -> {
+ SafeLineInspection inspection = inspectionMap.get(record.getInspectionId());
+ if (inspection != null) {
+ record.setInspectionCode(inspection.getInspectionCode());
+ record.setInspectionName(inspection.getInspectionName());
+ record.setLineName(inspection.getLineName());
+ }
+ });
+ }
+
+ private void fillRectifyAttachments(List<SafeLineInspectionHazard> records) {
+ if (records == null || records.isEmpty()) {
+ return;
+ }
+ records.forEach(record -> {
+ if (record.getId() == null) {
+ return;
+ }
+ List<StorageBlobVO> attachments = fileUtil.getStorageBlobVOsByRecordTypeAndRecordId(
+ RecordTypeEnum.SAFE_LINE_INSPECTION_HAZARD,
+ record.getId().longValue()
+ );
+ record.setStorageBlobVOs(attachments == null ? Collections.emptyList() : attachments);
+ });
+ }
+
+ private void completeInspectionIfAllRectified(Integer inspectionId) {
+ if (inspectionId == null) {
+ return;
+ }
+ long unrectifiedCount = this.lambdaQuery()
+ .eq(SafeLineInspectionHazard::getInspectionId, inspectionId)
+ .ne(SafeLineInspectionHazard::getStatus, "宸叉暣鏀�")
+ .count();
+ if (unrectifiedCount > 0) {
+ return;
+ }
+ SafeLineInspection inspection = safeLineInspectionMapper.selectById(inspectionId);
+ if (inspection == null || "宸插畬鎴�".equals(inspection.getStatus())) {
+ return;
+ }
+ Long currentUserId = SecurityUtils.getUserId();
+ inspection.setStatus("宸插畬鎴�");
+ inspection.setUpdateTime(LocalDateTime.now());
+ inspection.setUpdateUser(currentUserId == null ? null : currentUserId.intValue());
+ safeLineInspectionMapper.updateById(inspection);
}
}
--
Gitblit v1.9.3