| | |
| | | |
| | | 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; |
| | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private SafeFacilityLedgerService safeFacilityLedgerService; |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | @Autowired |
| | | private FileUtil fileUtil; |
| | | |
| | | @Override |
| | | public SafeFacilityInspection getById(Serializable id) { |
| | |
| | | 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; |
| | |
| | | // 收集所有设施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()); |
| | |
| | | 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)); |
| | | } |
| | | |
| | | // 批量查询巡检人信息 |
| | |
| | | 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)); |
| | | } |
| | | |
| | | // 填充字段 |
| | |
| | | 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() |
| | | ); |
| | | } |
| | | } |