Commit 53c7ce2220848a5b34f9803f3377eb86ef1fa8b1
1 parent
db03c6d7
feat:【IoT 物联网】新增告警恢复场景规则执行类 IotAlertRecoverSceneRuleAction
Showing
1 changed file
with
69 additions
and
0 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/action/IotAlertRecoverSceneRuleAction.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.service.rule.scene.action; | |
| 2 | + | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 5 | +import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; | |
| 6 | +import cn.iocoder.yudao.module.iot.dal.dataobject.alert.IotAlertConfigDO; | |
| 7 | +import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; | |
| 8 | +import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; | |
| 9 | +import cn.iocoder.yudao.module.iot.service.alert.IotAlertConfigService; | |
| 10 | +import cn.iocoder.yudao.module.iot.service.alert.IotAlertRecordService; | |
| 11 | +import cn.iocoder.yudao.module.system.api.mail.MailSendApi; | |
| 12 | +import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi; | |
| 13 | +import cn.iocoder.yudao.module.system.api.sms.SmsSendApi; | |
| 14 | +import jakarta.annotation.Resource; | |
| 15 | +import org.springframework.stereotype.Component; | |
| 16 | + | |
| 17 | +import javax.annotation.Nullable; | |
| 18 | +import java.util.List; | |
| 19 | + | |
| 20 | +// TODO @puhui999、@芋艿:未测试;需要场景联动开发完 | |
| 21 | +/** | |
| 22 | + * IoT 告警触发的 {@link IotSceneRuleAction} 实现类 | |
| 23 | + * | |
| 24 | + * @author 芋道源码 | |
| 25 | + */ | |
| 26 | +@Component | |
| 27 | +public class IotAlertTriggerSceneRuleAction implements IotSceneRuleAction { | |
| 28 | + | |
| 29 | + @Resource | |
| 30 | + private IotAlertConfigService alertConfigService; | |
| 31 | + @Resource | |
| 32 | + private IotAlertRecordService alertRecordService; | |
| 33 | + | |
| 34 | + @Resource | |
| 35 | + private SmsSendApi smsSendApi; | |
| 36 | + @Resource | |
| 37 | + private MailSendApi mailSendApi; | |
| 38 | + @Resource | |
| 39 | + private NotifyMessageSendApi notifyMessageSendApi; | |
| 40 | + | |
| 41 | + @Override | |
| 42 | + public void execute(@Nullable IotDeviceMessage message, | |
| 43 | + IotRuleSceneDO rule, IotRuleSceneDO.ActionConfig actionConfig) throws Exception { | |
| 44 | + List<IotAlertConfigDO> alertConfigs = alertConfigService.getAlertConfigListBySceneRuleIdAndStatus( | |
| 45 | + rule.getId(), CommonStatusEnum.ENABLE.getStatus()); | |
| 46 | + if (CollUtil.isEmpty(alertConfigs)) { | |
| 47 | + return; | |
| 48 | + } | |
| 49 | + alertConfigs.forEach(alertConfig -> { | |
| 50 | + // 记录告警记录 | |
| 51 | + alertRecordService.createAlertRecord(alertConfig, message); | |
| 52 | + // 发送告警消息 | |
| 53 | + sendAlertMessage(alertConfig, message); | |
| 54 | + }); | |
| 55 | + } | |
| 56 | + | |
| 57 | + private void sendAlertMessage(IotAlertConfigDO config, IotDeviceMessage deviceMessage) { | |
| 58 | + // TODO @芋艿:等场景联动开发完,再实现 | |
| 59 | + // TODO @芋艿:短信 | |
| 60 | + // TODO @芋艿:邮箱 | |
| 61 | + // TODO @芋艿:站内信 | |
| 62 | + } | |
| 63 | + | |
| 64 | + @Override | |
| 65 | + public IotRuleSceneActionTypeEnum getType() { | |
| 66 | + return IotRuleSceneActionTypeEnum.ALERT_TRIGGER; | |
| 67 | + } | |
| 68 | + | |
| 69 | +} | ... | ... |