huminmin
2026-06-29 9f1ec3d21f02d38d1a54876fface13301cc65fad
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
package com.ruoyi.safe.service.impl;
 
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.safe.pojo.SafeLineInspection;
import com.ruoyi.safe.pojo.SafeLineInspectionRecord;
import com.ruoyi.safe.mapper.SafeLineInspectionRecordMapper;
import com.ruoyi.safe.service.SafeLineInspectionRecordService;
import com.ruoyi.safe.service.SafeLineInspectionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.time.LocalDateTime;
import java.util.List;
 
/**
 * <p>
 * 安全生产--线路巡检记录 服务实现类
 * </p>
 *
 * @author 芯导软件(江苏)有限公司
 * @since 2026-06-29
 */
@Service
public class SafeLineInspectionRecordServiceImpl extends ServiceImpl<SafeLineInspectionRecordMapper, SafeLineInspectionRecord> implements SafeLineInspectionRecordService {
 
    @Autowired
    private SafeLineInspectionService safeLineInspectionService;
 
    @Override
    public List<SafeLineInspectionRecord> listByInspectionId(Integer inspectionId) {
        return this.lambdaQuery()
                .eq(SafeLineInspectionRecord::getInspectionId, inspectionId)
                .orderByDesc(SafeLineInspectionRecord::getCheckTime)
                .list();
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(SafeLineInspectionRecord entity) {
        // 保存巡检记录
        boolean result = super.save(entity);
 
        if (result && entity.getInspectionId() != null) {
            // 更新巡检任务状态为"巡检中",并设置巡检人为当前登录用户
            updateInspectionStatus(entity.getInspectionId());
        }
 
        return result;
    }
 
    /**
     * 更新巡检任务状态为"巡检中",并添加当前用户到巡检人列表
     */
    private void updateInspectionStatus(Integer inspectionId) {
        SafeLineInspection inspection = safeLineInspectionService.getById(inspectionId);
        if (inspection != null && "待巡检".equals(inspection.getStatus())) {
            Long currentUserId = SecurityUtils.getUserId();
            String currentUserIdStr = String.valueOf(currentUserId);
 
            // 添加当前用户到巡检人列表(如果不存在)
            String inspectorId = inspection.getInspectorId();
            if (inspectorId == null || inspectorId.isEmpty()) {
                inspectorId = currentUserIdStr;
            } else if (!inspectorId.contains(currentUserIdStr)) {
                inspectorId = inspectorId + "," + currentUserIdStr;
            }
 
            inspection.setStatus("巡检中");
            inspection.setInspectorId(inspectorId);
            inspection.setUpdateTime(LocalDateTime.now());
            inspection.setUpdateUser(currentUserId.intValue());
            safeLineInspectionService.updateById(inspection);
        }
    }
}