作者 钟来

添加告警短信和语音通知

@@ -22,6 +22,16 @@ public class IotAlertUserNotice { @@ -22,6 +22,16 @@ public class IotAlertUserNotice {
22 private String create_time; // int DEFAULT NULL COMMENT '创建时间' 22 private String create_time; // int DEFAULT NULL COMMENT '创建时间'
23 @ApiModelProperty("更新时间") 23 @ApiModelProperty("更新时间")
24 private String update_time; // int DEFAULT NULL COMMENT '更新时间' 24 private String update_time; // int DEFAULT NULL COMMENT '更新时间'
  25 + @ApiModelProperty("离线告警的通知渠道(多个英文逗号分割)")
  26 + private String online_channels; // varchar(100) DEFAULT NULL COMMENT '离线告警的通知渠道(多个英文逗号分割)'
  27 +
  28 + public String getOnline_channels() {
  29 + return online_channels;
  30 + }
  31 +
  32 + public void setOnline_channels(String online_channels) {
  33 + this.online_channels = online_channels;
  34 + }
25 35
26 public Integer getId() { 36 public Integer getId() {
27 return id; 37 return id;
@@ -463,6 +463,22 @@ public class CachAlarmConfig { @@ -463,6 +463,22 @@ public class CachAlarmConfig {
463 return null; 463 return null;
464 } 464 }
465 465
  466 + public static List<UserAlarmNoticeConfig> getUserOnlineAlarmNoticeConfig(Integer user_id,Integer getAlert_config_type )
  467 + {
  468 + IotAlertUserNotice iotAlertUserNotice = user_alarm_config.get(user_id+"|"+getAlert_config_type);
  469 + if(null != iotAlertUserNotice ) //*或者包含
  470 + {
  471 + if(StringUtils.isNotEmpty(iotAlertUserNotice.getOnline_channels()))
  472 + {
  473 + return channelIdsToUserAlarmNoticeConfig(iotAlertUserNotice.getOnline_channels());
  474 + }else {
  475 + return channelIdsToUserAlarmNoticeConfig(iotAlertUserNotice.getChannels());
  476 + }
  477 +
  478 + }
  479 + return null;
  480 + }
  481 +
466 private static List<UserAlarmNoticeConfig> channelIdsToUserAlarmNoticeConfig(String iot_alert_notice_channel_ids) 482 private static List<UserAlarmNoticeConfig> channelIdsToUserAlarmNoticeConfig(String iot_alert_notice_channel_ids)
467 { 483 {
468 logger.info("开始渠道id转告警配置:{}",iot_alert_notice_channel_ids); 484 logger.info("开始渠道id转告警配置:{}",iot_alert_notice_channel_ids);
@@ -13,7 +13,7 @@ public class IotAlertUserNotice { @@ -13,7 +13,7 @@ public class IotAlertUserNotice {
13 private Integer type; // int DEFAULT NULL COMMENT '告警类型(1系统告警,2用户告警)', 13 private Integer type; // int DEFAULT NULL COMMENT '告警类型(1系统告警,2用户告警)',
14 private String alert_ids; // varchar(100) DEFAULT '*' COMMENT '告警id集合(关联iot_alert_log和iot_alert_user表的id,多个英文逗号分割,*表示所有)', 14 private String alert_ids; // varchar(100) DEFAULT '*' COMMENT '告警id集合(关联iot_alert_log和iot_alert_user表的id,多个英文逗号分割,*表示所有)',
15 private Integer user_id; // int DEFAULT NULL COMMENT '用户id' 15 private Integer user_id; // int DEFAULT NULL COMMENT '用户id'
16 - 16 + private String online_channels; //离线告警的通知渠道(多个英文逗号分割)
17 public static IotAlertUserNotice instantiate(List<CanalEntry.Column> columns) { 17 public static IotAlertUserNotice instantiate(List<CanalEntry.Column> columns) {
18 if (null == columns || columns.size() == 0) { 18 if (null == columns || columns.size() == 0) {
19 return null; 19 return null;
@@ -36,10 +36,22 @@ public class IotAlertUserNotice { @@ -36,10 +36,22 @@ public class IotAlertUserNotice {
36 case "user_id": 36 case "user_id":
37 iotAlertUserNotice.setUser_id(Integer.parseInt(column.getValue())); 37 iotAlertUserNotice.setUser_id(Integer.parseInt(column.getValue()));
38 break; 38 break;
  39 + case "online_channels":
  40 + iotAlertUserNotice.setOnline_channels(column.getValue());
  41 + break;
39 } 42 }
40 } 43 }
41 return iotAlertUserNotice; 44 return iotAlertUserNotice;
42 } 45 }
  46 +
  47 + public String getOnline_channels() {
  48 + return online_channels;
  49 + }
  50 +
  51 + public void setOnline_channels(String online_channels) {
  52 + this.online_channels = online_channels;
  53 + }
  54 +
43 public Integer getId() { 55 public Integer getId() {
44 return id; 56 return id;
45 } 57 }
@@ -25,8 +25,14 @@ public interface NoticeFactory { @@ -25,8 +25,14 @@ public interface NoticeFactory {
25 boolean send(IotAlertLog iotAlertLog); 25 boolean send(IotAlertLog iotAlertLog);
26 static boolean notice(IotAlertLog iotAlertLog) 26 static boolean notice(IotAlertLog iotAlertLog)
27 { 27 {
  28 + List<UserAlarmNoticeConfig> userAlarmNoticeConfigList = null;
28 //获取通知配置 29 //获取通知配置
29 - List<UserAlarmNoticeConfig> userAlarmNoticeConfigList = CachAlarmConfig.getUserAlarmNoticeConfig(iotAlertLog.getUser_id(),iotAlertLog.getAlert_config_type(),iotAlertLog.getAlert_id()); 30 + if(1==iotAlertLog.getAlert_id()) //如果是离线告警
  31 + {
  32 + userAlarmNoticeConfigList = CachAlarmConfig.getUserOnlineAlarmNoticeConfig(iotAlertLog.getUser_id(),iotAlertLog.getAlert_config_type());
  33 + }else{
  34 + userAlarmNoticeConfigList = CachAlarmConfig.getUserAlarmNoticeConfig(iotAlertLog.getUser_id(),iotAlertLog.getAlert_config_type(),iotAlertLog.getAlert_id());
  35 + }
30 if(null != userAlarmNoticeConfigList && userAlarmNoticeConfigList.size()!=0) //有配置告警通知的才发送 36 if(null != userAlarmNoticeConfigList && userAlarmNoticeConfigList.size()!=0) //有配置告警通知的才发送
31 { 37 {
32 boolean rb = true; 38 boolean rb = true;
@@ -60,13 +66,14 @@ public interface NoticeFactory { @@ -60,13 +66,14 @@ public interface NoticeFactory {
60 { 66 {
61 rb=rb&&noticeFactory.send(iotAlertLog); 67 rb=rb&&noticeFactory.send(iotAlertLog);
62 } 68 }
  69 +
63 } 70 }
  71 +
64 return rb; 72 return rb;
65 73
66 }else { 74 }else {
67 return false; 75 return false;
68 } 76 }
69 -  
70 } 77 }
71 78
72 static boolean request(IotAlertLog iotAlertLog) 79 static boolean request(IotAlertLog iotAlertLog)
@@ -165,6 +165,7 @@ public class UserInfoAlarmController extends BaseController { @@ -165,6 +165,7 @@ public class UserInfoAlarmController extends BaseController {
165 165
166 @ApiOperation("更新告警通知渠道配置") 166 @ApiOperation("更新告警通知渠道配置")
167 @ApiImplicitParams({ 167 @ApiImplicitParams({
  168 + @ApiImplicitParam(value = "离线通知渠道(iot_alert_notice_channel表的id集合,多个英文逗号分割)",name = "online_channels"),
168 @ApiImplicitParam(value = "通知渠道(iot_alert_notice_channel表的id集合,多个英文逗号分割)",name = "channels"), 169 @ApiImplicitParam(value = "通知渠道(iot_alert_notice_channel表的id集合,多个英文逗号分割)",name = "channels"),
169 @ApiImplicitParam(value = "告警id集合(关联iot_alert和iot_alert_user表的id,多个英文逗号分割,*表示所有)",name = "alert_ids"), 170 @ApiImplicitParam(value = "告警id集合(关联iot_alert和iot_alert_user表的id,多个英文逗号分割,*表示所有)",name = "alert_ids"),
170 @ApiImplicitParam(value = "主键id",name = "id"), 171 @ApiImplicitParam(value = "主键id",name = "id"),
@@ -172,18 +173,20 @@ public class UserInfoAlarmController extends BaseController { @@ -172,18 +173,20 @@ public class UserInfoAlarmController extends BaseController {
172 @Log(title = "更新告警通知渠道配置", businessType = BusinessType.UPDATE) 173 @Log(title = "更新告警通知渠道配置", businessType = BusinessType.UPDATE)
173 @Transactional 174 @Transactional
174 @PostMapping(value = "upIotAlertUserNotice/{id}") 175 @PostMapping(value = "upIotAlertUserNotice/{id}")
175 - public AjaxResult upIotAlertUserNotice(@PathVariable Integer id,String channels, String alert_ids) 176 + public AjaxResult upIotAlertUserNotice(@PathVariable Integer id,String channels, String alert_ids,String online_channels)
176 { 177 {
177 IotAlertUserNotice iotAlertUserNotice = new IotAlertUserNotice(); 178 IotAlertUserNotice iotAlertUserNotice = new IotAlertUserNotice();
178 iotAlertUserNotice.setId(id); 179 iotAlertUserNotice.setId(id);
179 iotAlertUserNotice.setChannels(channels); 180 iotAlertUserNotice.setChannels(channels);
180 iotAlertUserNotice.setAlert_ids(alert_ids); 181 iotAlertUserNotice.setAlert_ids(alert_ids);
  182 + iotAlertUserNotice.setOnline_channels(online_channels);
181 int i = publicService.updateObject(iotAlertUserNotice,"id"); 183 int i = publicService.updateObject(iotAlertUserNotice,"id");
182 return AjaxResult.success(i); 184 return AjaxResult.success(i);
183 } 185 }
184 186
185 @ApiOperation("更新指定产品的告警通知渠道配置") 187 @ApiOperation("更新指定产品的告警通知渠道配置")
186 @ApiImplicitParams({ 188 @ApiImplicitParams({
  189 + @ApiImplicitParam(value = "离线通知渠道(iot_alert_notice_channel表的id集合,多个英文逗号分割)",name = "online_channels"),
187 @ApiImplicitParam(value = "通知渠道(iot_alert_notice_channel表的id集合,多个英文逗号分割)",name = "channels"), 190 @ApiImplicitParam(value = "通知渠道(iot_alert_notice_channel表的id集合,多个英文逗号分割)",name = "channels"),
188 @ApiImplicitParam(value = "告警id集合(关联iot_alert和iot_alert_user表的id,多个英文逗号分割,*表示所有)",name = "alert_ids"), 191 @ApiImplicitParam(value = "告警id集合(关联iot_alert和iot_alert_user表的id,多个英文逗号分割,*表示所有)",name = "alert_ids"),
189 @ApiImplicitParam(value = "主键id",name = "id"), 192 @ApiImplicitParam(value = "主键id",name = "id"),
@@ -192,7 +195,7 @@ public class UserInfoAlarmController extends BaseController { @@ -192,7 +195,7 @@ public class UserInfoAlarmController extends BaseController {
192 @Log(title = "更新指定产品的告警通知渠道配置", businessType = BusinessType.UPDATE) 195 @Log(title = "更新指定产品的告警通知渠道配置", businessType = BusinessType.UPDATE)
193 @Transactional 196 @Transactional
194 @PostMapping(value = "upIotAlertUserNoticeByProduct/{id}/{product_id}") 197 @PostMapping(value = "upIotAlertUserNoticeByProduct/{id}/{product_id}")
195 - public AjaxResult upIotAlertUserNoticeByProduct(@PathVariable Integer id,@PathVariable Long product_id,String channels, String alert_ids) 198 + public AjaxResult upIotAlertUserNoticeByProduct(@PathVariable Integer id,@PathVariable Long product_id,String channels, String alert_ids,String online_channels)
196 { 199 {
197 IotAlertUserNotice iotAlertUserNotice = publicService.getObject(IotAlertUserNotice.class,"id",id+""); 200 IotAlertUserNotice iotAlertUserNotice = publicService.getObject(IotAlertUserNotice.class,"id",id+"");
198 201
@@ -219,6 +222,10 @@ public class UserInfoAlarmController extends BaseController { @@ -219,6 +222,10 @@ public class UserInfoAlarmController extends BaseController {
219 } 222 }
220 } 223 }
221 224
  225 + if(StringUtils.isNotEmpty(online_channels))
  226 + {
  227 + uPiotAlertUserNotice.setOnline_channels(online_channels);
  228 + }
222 int upi = 0; 229 int upi = 0;
223 if(StringUtils.isNotEmpty(uPiotAlertUserNotice.getChannels()) || StringUtils.isNotEmpty(uPiotAlertUserNotice.getAlert_ids())) 230 if(StringUtils.isNotEmpty(uPiotAlertUserNotice.getChannels()) || StringUtils.isNotEmpty(uPiotAlertUserNotice.getAlert_ids()))
224 { 231 {