gongchunyi
4 小时以前 16d50e1fd871b2306e7beb650463bc76263e5e98
src/main/java/com/ruoyi/safe/service/impl/SafeFacilityInspectionServiceImpl.java
@@ -2,6 +2,10 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.safe.pojo.SafeFacilityInspection;
@@ -17,6 +21,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
@@ -34,6 +39,8 @@
    private SafeFacilityLedgerService safeFacilityLedgerService;
    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private FileUtil fileUtil;
    @Override
    public SafeFacilityInspection getById(Serializable id) {
@@ -57,6 +64,20 @@
        return result;
    }
    @Override
    public boolean save(SafeFacilityInspection entity) {
        boolean saved = super.save(entity);
        syncAttachments(saved, entity);
        return saved;
    }
    @Override
    public boolean updateById(SafeFacilityInspection entity) {
        boolean updated = super.updateById(entity);
        syncAttachments(updated, entity);
        return updated;
    }
    private void fillExtraInfo(List<SafeFacilityInspection> records) {
        if (records == null || records.isEmpty()) {
            return;
@@ -65,14 +86,14 @@
        // 收集所有设施ID
        List<Integer> facilityIds = records.stream()
                .map(SafeFacilityInspection::getFacilityId)
                .filter(id -> id != null)
                .filter(Objects::nonNull)
                .distinct()
                .collect(Collectors.toList());
        // 收集所有巡检人ID
        List<Long> inspectorIds = records.stream()
                .map(SafeFacilityInspection::getInspectorId)
                .filter(id -> id != null)
                .filter(Objects::nonNull)
                .map(Integer::longValue)
                .distinct()
                .collect(Collectors.toList());
@@ -81,7 +102,7 @@
        Map<Integer, SafeFacilityLedger> facilityMap = Map.of();
        if (!facilityIds.isEmpty()) {
            facilityMap = safeFacilityLedgerService.listByIds(facilityIds).stream()
                    .collect(Collectors.toMap(SafeFacilityLedger::getId, f -> f, (v1, v2) -> v1));
                    .collect(Collectors.toMap(SafeFacilityLedger::getId, f -> f, (v1, _) -> v1));
        }
        // 批量查询巡检人信息
@@ -89,7 +110,7 @@
        if (!inspectorIds.isEmpty()) {
            List<SysUser> users = sysUserMapper.selectUserByIds(inspectorIds);
            userMap = users.stream()
                    .collect(Collectors.toMap(SysUser::getUserId, SysUser::getNickName, (v1, v2) -> v1));
                    .collect(Collectors.toMap(SysUser::getUserId, SysUser::getNickName, (v1, _) -> v1));
        }
        // 填充字段
@@ -104,6 +125,25 @@
            if (record.getInspectorId() != null) {
                record.setInspectorName(userMap.getOrDefault(record.getInspectorId().longValue(), "未知用户"));
            }
            if (record.getId() != null) {
                List<StorageBlobVO> attachments = fileUtil.getStorageBlobVOsByRecordTypeAndRecordId(
                        RecordTypeEnum.SAFE_FACILITY_INSPECTION,
                        record.getId().longValue()
                );
                record.setStorageBlobVOs(attachments == null ? Collections.emptyList() : attachments);
            }
        }
    }
    private void syncAttachments(boolean success, SafeFacilityInspection entity) {
        if (!success || entity == null || entity.getId() == null || entity.getStorageBlobDTOs() == null) {
            return;
        }
        fileUtil.saveStorageAttachment(
                ApplicationTypeEnum.IMAGE,
                RecordTypeEnum.SAFE_FACILITY_INSPECTION,
                entity.getId().longValue(),
                entity.getStorageBlobDTOs()
        );
    }
}