2026-06-24 f4bd1f3c89d906131495a0aca5aaf82966378510
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
package cn.iocoder.yudao.module.iot.service.alert;
 
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.iot.controller.admin.alert.vo.recrod.IotAlertRecordPageReqVO;
import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertRecordDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
import cn.iocoder.yudao.module.iot.dal.mysql.alert.IotAlertRecordMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
 
import java.util.Collection;
import java.util.List;
 
/**
 * IoT 告警记录 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class IotAlertRecordServiceImpl implements IotAlertRecordService {
 
    @Resource
    private IotAlertRecordMapper alertRecordMapper;
 
    @Override
    public IotAlertRecordDO getAlertRecord(Long id) {
        return alertRecordMapper.selectById(id);
    }
 
    @Override
    public PageResult<IotAlertRecordDO> getAlertRecordPage(IotAlertRecordPageReqVO pageReqVO) {
        return alertRecordMapper.selectPage(pageReqVO);
    }
 
    @Override
    public List<IotAlertRecordDO> getAlertRecordListBySceneRuleId(Long sceneRuleId, Long deviceId, Boolean processStatus) {
        return alertRecordMapper.selectListBySceneRuleId(sceneRuleId, deviceId, processStatus);
    }
 
    @Override
    public void processAlertRecordList(Collection<Long> ids, String processRemark) {
        if (CollUtil.isEmpty(ids)) {
            return;
        }
        // 批量更新告警记录的处理状态
        alertRecordMapper.updateList(ids, IotAlertRecordDO.builder()
                .processStatus(true).processRemark(processRemark).build());
    }
 
    @Override
    public Long createAlertRecord(IotAlertConfigDO config, Long sceneRuleId,
                                  IotDeviceMessage message, IotDeviceDO device) {
        // 构建告警记录
        IotAlertRecordDO.IotAlertRecordDOBuilder builder = IotAlertRecordDO.builder()
                .configId(config.getId()).configName(config.getName()).configLevel(config.getLevel())
                .sceneRuleId(sceneRuleId).processStatus(false);
        if (message != null) {
            builder.deviceMessage(message);
        }
        if (device != null) {
            builder.productId(device.getProductId()).deviceId(device.getId());
        }
        // 插入记录
        IotAlertRecordDO record = builder.build();
        alertRecordMapper.insert(record);
        return record.getId();
    }
 
}