From 53c7ce2220848a5b34f9803f3377eb86ef1fa8b1 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 28 Jun 2025 19:37:00 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E3=80=90IoT=20=E7=89=A9=E8=81=94?= =?UTF-8?q?=E7=BD=91=E3=80=91=E6=96=B0=E5=A2=9E=E5=91=8A=E8=AD=A6=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E5=9C=BA=E6=99=AF=E8=A7=84=E5=88=99=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E7=B1=BB=20IotAlertRecoverSceneRuleAction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IotAlertRecoverSceneRuleAction.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/action/IotAlertRecoverSceneRuleAction.java diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/action/IotAlertRecoverSceneRuleAction.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/action/IotAlertRecoverSceneRuleAction.java new file mode 100644 index 0000000000..f4bb853244 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/action/IotAlertRecoverSceneRuleAction.java @@ -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 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; + } + +}