feat:【IoT 物联网】新增告警恢复场景规则执行类 IotAlertRecoverSceneRuleAction

This commit is contained in:
YunaiV 2025-06-28 19:39:29 +08:00
parent 97260b8efe
commit a3f58be571

View File

@ -1,69 +1,49 @@
package cn.iocoder.yudao.module.iot.service.rule.scene.action; package cn.iocoder.yudao.module.iot.service.rule.scene.action;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; 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.rule.IotRuleSceneDO; import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO;
import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum;
import cn.iocoder.yudao.module.iot.service.alert.IotAlertConfigService;
import cn.iocoder.yudao.module.iot.service.alert.IotAlertRecordService; import cn.iocoder.yudao.module.iot.service.alert.IotAlertRecordService;
import cn.iocoder.yudao.module.system.api.mail.MailSendApi;
import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
import cn.iocoder.yudao.module.system.api.sms.SmsSendApi;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
// TODO @puhui999@芋艿未测试需要场景联动开发完 // TODO @puhui999@芋艿未测试需要场景联动开发完
/** /**
* IoT 告警触发 {@link IotSceneRuleAction} 实现类 * IoT 告警恢复 {@link IotSceneRuleAction} 实现类
* *
* @author 芋道源码 * @author 芋道源码
*/ */
@Component @Component
public class IotAlertTriggerSceneRuleAction implements IotSceneRuleAction { public class IotAlertRecoverSceneRuleAction implements IotSceneRuleAction {
private static final String PROCESS_REMARK = "告警自动回复,基于【{}】场景联动规则";
@Resource
private IotAlertConfigService alertConfigService;
@Resource @Resource
private IotAlertRecordService alertRecordService; private IotAlertRecordService alertRecordService;
@Resource
private SmsSendApi smsSendApi;
@Resource
private MailSendApi mailSendApi;
@Resource
private NotifyMessageSendApi notifyMessageSendApi;
@Override @Override
public void execute(@Nullable IotDeviceMessage message, public void execute(IotDeviceMessage message,
IotRuleSceneDO rule, IotRuleSceneDO.ActionConfig actionConfig) throws Exception { IotRuleSceneDO rule, IotRuleSceneDO.ActionConfig actionConfig) throws Exception {
List<IotAlertConfigDO> alertConfigs = alertConfigService.getAlertConfigListBySceneRuleIdAndStatus( Long deviceId = message != null ? message.getDeviceId() : null;
rule.getId(), CommonStatusEnum.ENABLE.getStatus()); List<IotAlertRecordDO> alertRecords = alertRecordService.getAlertRecordListBySceneRuleId(
if (CollUtil.isEmpty(alertConfigs)) { rule.getId(), deviceId, false);
if (CollUtil.isEmpty(alertRecords)) {
return; return;
} }
alertConfigs.forEach(alertConfig -> { alertRecordService.processAlertRecordList(convertList(alertRecords, IotAlertRecordDO::getId),
// 记录告警记录 StrUtil.format(PROCESS_REMARK, rule.getName()));
alertRecordService.createAlertRecord(alertConfig, message);
// 发送告警消息
sendAlertMessage(alertConfig, message);
});
}
private void sendAlertMessage(IotAlertConfigDO config, IotDeviceMessage deviceMessage) {
// TODO @芋艿等场景联动开发完再实现
// TODO @芋艿短信
// TODO @芋艿邮箱
// TODO @芋艿站内信
} }
@Override @Override
public IotRuleSceneActionTypeEnum getType() { public IotRuleSceneActionTypeEnum getType() {
return IotRuleSceneActionTypeEnum.ALERT_TRIGGER; return IotRuleSceneActionTypeEnum.ALERT_RECOVER;
} }
} }