作者 钟来

添加告警短信和语音通知

... ... @@ -22,6 +22,16 @@ public class IotAlertUserNotice {
private String create_time; // int DEFAULT NULL COMMENT '创建时间'
@ApiModelProperty("更新时间")
private String update_time; // int DEFAULT NULL COMMENT '更新时间'
@ApiModelProperty("离线告警的通知渠道(多个英文逗号分割)")
private String online_channels; // varchar(100) DEFAULT NULL COMMENT '离线告警的通知渠道(多个英文逗号分割)'
public String getOnline_channels() {
return online_channels;
}
public void setOnline_channels(String online_channels) {
this.online_channels = online_channels;
}
public Integer getId() {
return id;
... ...
... ... @@ -463,6 +463,22 @@ public class CachAlarmConfig {
return null;
}
public static List<UserAlarmNoticeConfig> getUserOnlineAlarmNoticeConfig(Integer user_id,Integer getAlert_config_type )
{
IotAlertUserNotice iotAlertUserNotice = user_alarm_config.get(user_id+"|"+getAlert_config_type);
if(null != iotAlertUserNotice ) //*或者包含
{
if(StringUtils.isNotEmpty(iotAlertUserNotice.getOnline_channels()))
{
return channelIdsToUserAlarmNoticeConfig(iotAlertUserNotice.getOnline_channels());
}else {
return channelIdsToUserAlarmNoticeConfig(iotAlertUserNotice.getChannels());
}
}
return null;
}
private static List<UserAlarmNoticeConfig> channelIdsToUserAlarmNoticeConfig(String iot_alert_notice_channel_ids)
{
logger.info("开始渠道id转告警配置:{}",iot_alert_notice_channel_ids);
... ...
... ... @@ -13,7 +13,7 @@ public class IotAlertUserNotice {
private Integer type; // int DEFAULT NULL COMMENT '告警类型(1系统告警,2用户告警)',
private String alert_ids; // varchar(100) DEFAULT '*' COMMENT '告警id集合(关联iot_alert_log和iot_alert_user表的id,多个英文逗号分割,*表示所有)',
private Integer user_id; // int DEFAULT NULL COMMENT '用户id'
private String online_channels; //离线告警的通知渠道(多个英文逗号分割)
public static IotAlertUserNotice instantiate(List<CanalEntry.Column> columns) {
if (null == columns || columns.size() == 0) {
return null;
... ... @@ -36,10 +36,22 @@ public class IotAlertUserNotice {
case "user_id":
iotAlertUserNotice.setUser_id(Integer.parseInt(column.getValue()));
break;
case "online_channels":
iotAlertUserNotice.setOnline_channels(column.getValue());
break;
}
}
return iotAlertUserNotice;
}
public String getOnline_channels() {
return online_channels;
}
public void setOnline_channels(String online_channels) {
this.online_channels = online_channels;
}
public Integer getId() {
return id;
}
... ...
... ... @@ -25,8 +25,14 @@ public interface NoticeFactory {
boolean send(IotAlertLog iotAlertLog);
static boolean notice(IotAlertLog iotAlertLog)
{
List<UserAlarmNoticeConfig> userAlarmNoticeConfigList = null;
//获取通知配置
List<UserAlarmNoticeConfig> userAlarmNoticeConfigList = CachAlarmConfig.getUserAlarmNoticeConfig(iotAlertLog.getUser_id(),iotAlertLog.getAlert_config_type(),iotAlertLog.getAlert_id());
if(1==iotAlertLog.getAlert_id()) //如果是离线告警
{
userAlarmNoticeConfigList = CachAlarmConfig.getUserOnlineAlarmNoticeConfig(iotAlertLog.getUser_id(),iotAlertLog.getAlert_config_type());
}else{
userAlarmNoticeConfigList = CachAlarmConfig.getUserAlarmNoticeConfig(iotAlertLog.getUser_id(),iotAlertLog.getAlert_config_type(),iotAlertLog.getAlert_id());
}
if(null != userAlarmNoticeConfigList && userAlarmNoticeConfigList.size()!=0) //有配置告警通知的才发送
{
boolean rb = true;
... ... @@ -60,13 +66,14 @@ public interface NoticeFactory {
{
rb=rb&&noticeFactory.send(iotAlertLog);
}
}
return rb;
}else {
return false;
}
}
static boolean request(IotAlertLog iotAlertLog)
... ...
... ... @@ -165,6 +165,7 @@ public class UserInfoAlarmController extends BaseController {
@ApiOperation("更新告警通知渠道配置")
@ApiImplicitParams({
@ApiImplicitParam(value = "离线通知渠道(iot_alert_notice_channel表的id集合,多个英文逗号分割)",name = "online_channels"),
@ApiImplicitParam(value = "通知渠道(iot_alert_notice_channel表的id集合,多个英文逗号分割)",name = "channels"),
@ApiImplicitParam(value = "告警id集合(关联iot_alert和iot_alert_user表的id,多个英文逗号分割,*表示所有)",name = "alert_ids"),
@ApiImplicitParam(value = "主键id",name = "id"),
... ... @@ -172,18 +173,20 @@ public class UserInfoAlarmController extends BaseController {
@Log(title = "更新告警通知渠道配置", businessType = BusinessType.UPDATE)
@Transactional
@PostMapping(value = "upIotAlertUserNotice/{id}")
public AjaxResult upIotAlertUserNotice(@PathVariable Integer id,String channels, String alert_ids)
public AjaxResult upIotAlertUserNotice(@PathVariable Integer id,String channels, String alert_ids,String online_channels)
{
IotAlertUserNotice iotAlertUserNotice = new IotAlertUserNotice();
iotAlertUserNotice.setId(id);
iotAlertUserNotice.setChannels(channels);
iotAlertUserNotice.setAlert_ids(alert_ids);
iotAlertUserNotice.setOnline_channels(online_channels);
int i = publicService.updateObject(iotAlertUserNotice,"id");
return AjaxResult.success(i);
}
@ApiOperation("更新指定产品的告警通知渠道配置")
@ApiImplicitParams({
@ApiImplicitParam(value = "离线通知渠道(iot_alert_notice_channel表的id集合,多个英文逗号分割)",name = "online_channels"),
@ApiImplicitParam(value = "通知渠道(iot_alert_notice_channel表的id集合,多个英文逗号分割)",name = "channels"),
@ApiImplicitParam(value = "告警id集合(关联iot_alert和iot_alert_user表的id,多个英文逗号分割,*表示所有)",name = "alert_ids"),
@ApiImplicitParam(value = "主键id",name = "id"),
... ... @@ -192,7 +195,7 @@ public class UserInfoAlarmController extends BaseController {
@Log(title = "更新指定产品的告警通知渠道配置", businessType = BusinessType.UPDATE)
@Transactional
@PostMapping(value = "upIotAlertUserNoticeByProduct/{id}/{product_id}")
public AjaxResult upIotAlertUserNoticeByProduct(@PathVariable Integer id,@PathVariable Long product_id,String channels, String alert_ids)
public AjaxResult upIotAlertUserNoticeByProduct(@PathVariable Integer id,@PathVariable Long product_id,String channels, String alert_ids,String online_channels)
{
IotAlertUserNotice iotAlertUserNotice = publicService.getObject(IotAlertUserNotice.class,"id",id+"");
... ... @@ -219,6 +222,10 @@ public class UserInfoAlarmController extends BaseController {
}
}
if(StringUtils.isNotEmpty(online_channels))
{
uPiotAlertUserNotice.setOnline_channels(online_channels);
}
int upi = 0;
if(StringUtils.isNotEmpty(uPiotAlertUserNotice.getChannels()) || StringUtils.isNotEmpty(uPiotAlertUserNotice.getAlert_ids()))
{
... ...