|
|
@@ -13,12 +13,19 @@ import cc.iotkit.common.api.PageRequest;
|
|
|
import cc.iotkit.common.api.Paging;
|
|
|
import cc.iotkit.common.utils.JsonUtils;
|
|
|
import cc.iotkit.common.utils.StringUtils;
|
|
|
-import cc.iotkit.data.manager.IDeviceInfoData;
|
|
|
-import cc.iotkit.data.manager.IRuleInfoData;
|
|
|
+import cc.iotkit.data.manager.*;
|
|
|
+import cc.iotkit.message.model.Message;
|
|
|
+import cc.iotkit.message.service.MessageService;
|
|
|
+import cc.iotkit.model.alert.AlertConfig;
|
|
|
+import cc.iotkit.model.notify.Channel;
|
|
|
+import cc.iotkit.model.notify.ChannelConfig;
|
|
|
+import cc.iotkit.model.notify.ChannelTemplate;
|
|
|
import cc.iotkit.model.rule.FilterConfig;
|
|
|
import cc.iotkit.model.rule.RuleAction;
|
|
|
import cc.iotkit.model.rule.RuleInfo;
|
|
|
import cc.iotkit.ruleengine.action.Action;
|
|
|
+import cc.iotkit.ruleengine.action.alert.AlertAction;
|
|
|
+import cc.iotkit.ruleengine.action.alert.AlertService;
|
|
|
import cc.iotkit.ruleengine.action.device.DeviceAction;
|
|
|
import cc.iotkit.ruleengine.action.device.DeviceActionService;
|
|
|
import cc.iotkit.ruleengine.action.http.HttpAction;
|
|
|
@@ -68,6 +75,21 @@ public class RuleManager {
|
|
|
@Autowired
|
|
|
private DeviceActionService deviceActionService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IAlertConfigData alertConfigData;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IChannelTemplateData channelTemplateData;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IChannelConfigData channelConfigData;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IChannelData channelData;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MessageService messageService;
|
|
|
+
|
|
|
public RuleManager() {
|
|
|
ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
|
|
|
executorService.schedule(this::initRules, 1, TimeUnit.SECONDS);
|
|
|
@@ -196,6 +218,46 @@ public class RuleManager {
|
|
|
service.initLink(ruleId);
|
|
|
}
|
|
|
return tcpAction;
|
|
|
+ } else if (AlertAction.TYPE.equals(type)) {
|
|
|
+ List<AlertConfig> alertConfigs = alertConfigData.findAllByCondition(AlertConfig.builder()
|
|
|
+ .ruleInfoId(ruleId)
|
|
|
+ .build());
|
|
|
+
|
|
|
+ AlertAction alertAction = parse(config, AlertAction.class);
|
|
|
+ String script = alertAction.getServices().get(0).getScript();
|
|
|
+
|
|
|
+ List<AlertService> alertServices = new ArrayList<>();
|
|
|
+ for (AlertConfig alertConfig : alertConfigs) {
|
|
|
+ if (alertConfig.getEnable() != null && !alertConfig.getEnable()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ AlertService service = new AlertService();
|
|
|
+ service.setScript(script);
|
|
|
+ service.setDeviceInfoData(deviceInfoData);
|
|
|
+ service.setMessageService(messageService);
|
|
|
+
|
|
|
+ ChannelTemplate channelTemplate = channelTemplateData.findById(Long.parseLong(alertConfig.getMessageTemplateId()));
|
|
|
+ Long channelConfigId = channelTemplate.getChannelConfigId();
|
|
|
+
|
|
|
+ Message message = Message.builder()
|
|
|
+ .content(channelTemplate.getContent())
|
|
|
+ .alertConfigId(alertConfig.getId())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ if (channelConfigId != null) {
|
|
|
+ ChannelConfig channelConfig = channelConfigData.findById(channelTemplate.getChannelConfigId());
|
|
|
+ Channel channel = channelData.findById(channelConfig.getChannelId());
|
|
|
+ message.setChannel(channel.getCode());
|
|
|
+ message.setChannelId(channel.getId());
|
|
|
+ message.setChannelConfig(channelConfig.getParam());
|
|
|
+ }
|
|
|
+
|
|
|
+ service.setMessage(message);
|
|
|
+ alertServices.add(service);
|
|
|
+ }
|
|
|
+ alertAction.setServices(alertServices);
|
|
|
+ return alertAction;
|
|
|
}
|
|
|
return null;
|
|
|
}
|