feat:【IoT 物联网】新增告警恢复场景规则执行类 IotAlertRecoverSceneRuleAction
This commit is contained in:
@@ -0,0 +1,69 @@
|
|||||||
|
package cn.iocoder.yudao.module.iot.service.rule.scene.action;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||||
|
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.rule.IotRuleSceneDO;
|
||||||
|
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.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 org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
// TODO @puhui999、@芋艿:未测试;需要场景联动开发完
|
||||||
|
/**
|
||||||
|
* IoT 告警触发的 {@link IotSceneRuleAction} 实现类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class IotAlertTriggerSceneRuleAction implements IotSceneRuleAction {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IotAlertConfigService alertConfigService;
|
||||||
|
@Resource
|
||||||
|
private IotAlertRecordService alertRecordService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SmsSendApi smsSendApi;
|
||||||
|
@Resource
|
||||||
|
private MailSendApi mailSendApi;
|
||||||
|
@Resource
|
||||||
|
private NotifyMessageSendApi notifyMessageSendApi;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(@Nullable IotDeviceMessage message,
|
||||||
|
IotRuleSceneDO rule, IotRuleSceneDO.ActionConfig actionConfig) throws Exception {
|
||||||
|
List<IotAlertConfigDO> alertConfigs = alertConfigService.getAlertConfigListBySceneRuleIdAndStatus(
|
||||||
|
rule.getId(), CommonStatusEnum.ENABLE.getStatus());
|
||||||
|
if (CollUtil.isEmpty(alertConfigs)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
alertConfigs.forEach(alertConfig -> {
|
||||||
|
// 记录告警记录
|
||||||
|
alertRecordService.createAlertRecord(alertConfig, message);
|
||||||
|
// 发送告警消息
|
||||||
|
sendAlertMessage(alertConfig, message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendAlertMessage(IotAlertConfigDO config, IotDeviceMessage deviceMessage) {
|
||||||
|
// TODO @芋艿:等场景联动开发完,再实现
|
||||||
|
// TODO @芋艿:短信
|
||||||
|
// TODO @芋艿:邮箱
|
||||||
|
// TODO @芋艿:站内信
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IotRuleSceneActionTypeEnum getType() {
|
||||||
|
return IotRuleSceneActionTypeEnum.ALERT_TRIGGER;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user