gongchunyi
6 小时以前 16d50e1fd871b2306e7beb650463bc76263e5e98
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.ruoyi.safe.service.impl;
 
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;
 
/**
 * <p>
 * 安全生产--线路巡检记录 服务实现类
 * </p>
 *
 * @author 芯导软件(江苏)有限公司
 * @since 2026-06-29
 */
@Service
public class SafeLineInspectionRecordServiceImpl extends ServiceImpl<SafeLineInspectionRecordMapper, SafeLineInspectionRecord> implements SafeLineInspectionRecordService {
 
    @Autowired
    private FileUtil fileUtil;
 
    @Override
    public List<SafeLineInspectionRecord> listByInspectionId(Integer inspectionId) {
        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);
        });
    }
}