| | |
| | | package com.ruoyi.safe.service.impl; |
| | | |
| | | import com.ruoyi.safe.pojo.SafeLineInspectionRecord; |
| | | import com.ruoyi.safe.mapper.SafeLineInspectionRecordMapper; |
| | | import com.ruoyi.safe.service.SafeLineInspectionRecordService; |
| | | 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 java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | @Service |
| | | public class SafeLineInspectionRecordServiceImpl extends ServiceImpl<SafeLineInspectionRecordMapper, SafeLineInspectionRecord> implements SafeLineInspectionRecordService { |
| | | |
| | | @Autowired |
| | | 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 |
| | | public boolean save(SafeLineInspectionRecord entity) { |
| | | boolean saved = super.save(entity); |
| | | syncAttachments(saved, entity); |
| | | return saved; |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateById(SafeLineInspectionRecord entity) { |
| | | boolean updated = super.updateById(entity); |
| | | syncAttachments(updated, entity); |
| | | return updated; |
| | | } |
| | | |
| | | 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); |
| | | }); |
| | | } |
| | | } |