作者 钟来

添加告警短信和语音通知

正在显示 25 个修改的文件 包含 944 行增加36 行删除
  1 +package com.zhonglai.luhui.device.dto;
  2 +
  3 +public class AliyunSmsNoticeDto {
  4 + private String accessKeyId;
  5 + private String accessKeySecret;
  6 + private String region;
  7 + private String signName;
  8 + private String templateCode;
  9 + private Integer intervalTime;
  10 + private String subjectName;
  11 +
  12 + public String getSubjectName() {
  13 + return subjectName;
  14 + }
  15 +
  16 + public void setSubjectName(String subjectName) {
  17 + this.subjectName = subjectName;
  18 + }
  19 +
  20 + public Integer getIntervalTime() {
  21 + return intervalTime;
  22 + }
  23 +
  24 + public void setIntervalTime(Integer intervalTime) {
  25 + this.intervalTime = intervalTime;
  26 + }
  27 + public String getSignName() {
  28 + return signName;
  29 + }
  30 +
  31 + public void setSignName(String signName) {
  32 + this.signName = signName;
  33 + }
  34 +
  35 + public String getTemplateCode() {
  36 + return templateCode;
  37 + }
  38 +
  39 + public void setTemplateCode(String templateCode) {
  40 + this.templateCode = templateCode;
  41 + }
  42 +
  43 + public String getAccessKeyId() {
  44 + return accessKeyId;
  45 + }
  46 +
  47 + public void setAccessKeyId(String accessKeyId) {
  48 + this.accessKeyId = accessKeyId;
  49 + }
  50 +
  51 + public String getAccessKeySecret() {
  52 + return accessKeySecret;
  53 + }
  54 +
  55 + public void setAccessKeySecret(String accessKeySecret) {
  56 + this.accessKeySecret = accessKeySecret;
  57 + }
  58 +
  59 + public String getRegion() {
  60 + return region;
  61 + }
  62 +
  63 + public void setRegion(String region) {
  64 + this.region = region;
  65 + }
  66 +}
  1 +package com.zhonglai.luhui.device.dto;
  2 +
  3 +public class AliyunTTSNoticeDto {
  4 + private String accessKeyId;
  5 + private String accessKeySecret;
  6 + private String region;
  7 + private String ttsCode;
  8 + private Integer intervalTime;
  9 + private String subjectName;
  10 +
  11 + private String calledNumber;
  12 + private Integer volume; //音量
  13 + private Integer playTimes; //播放次数
  14 +
  15 + private Integer speed; //语速
  16 +
  17 + public Integer getVolume() {
  18 + return volume;
  19 + }
  20 +
  21 + public void setVolume(Integer volume) {
  22 + this.volume = volume;
  23 + }
  24 +
  25 + public Integer getPlayTimes() {
  26 + return playTimes;
  27 + }
  28 +
  29 + public void setPlayTimes(Integer playTimes) {
  30 + this.playTimes = playTimes;
  31 + }
  32 +
  33 + public Integer getSpeed() {
  34 + return speed;
  35 + }
  36 +
  37 + public void setSpeed(Integer speed) {
  38 + this.speed = speed;
  39 + }
  40 +
  41 + public String getCalledNumber() {
  42 + return calledNumber;
  43 + }
  44 +
  45 + public void setCalledNumber(String calledNumber) {
  46 + this.calledNumber = calledNumber;
  47 + }
  48 +
  49 + public String getSubjectName() {
  50 + return subjectName;
  51 + }
  52 +
  53 + public void setSubjectName(String subjectName) {
  54 + this.subjectName = subjectName;
  55 + }
  56 +
  57 + public Integer getIntervalTime() {
  58 + return intervalTime;
  59 + }
  60 +
  61 + public void setIntervalTime(Integer intervalTime) {
  62 + this.intervalTime = intervalTime;
  63 + }
  64 +
  65 + public String getTtsCode() {
  66 + return ttsCode;
  67 + }
  68 +
  69 + public void setTtsCode(String ttsCode) {
  70 + this.ttsCode = ttsCode;
  71 + }
  72 +
  73 + public String getAccessKeyId() {
  74 + return accessKeyId;
  75 + }
  76 +
  77 + public void setAccessKeyId(String accessKeyId) {
  78 + this.accessKeyId = accessKeyId;
  79 + }
  80 +
  81 + public String getAccessKeySecret() {
  82 + return accessKeySecret;
  83 + }
  84 +
  85 + public void setAccessKeySecret(String accessKeySecret) {
  86 + this.accessKeySecret = accessKeySecret;
  87 + }
  88 +
  89 + public String getRegion() {
  90 + return region;
  91 + }
  92 +
  93 + public void setRegion(String region) {
  94 + this.region = region;
  95 + }
  96 +}
  1 +package com.zhonglai.luhui.device.dto;
  2 +
  3 +public class UserAlertPhone {
  4 + private Integer id; // int NOT NULL AUTO_INCREMENT COMMENT '主键',
  5 + private Integer user_id; // int NOT NULL COMMENT '用户id',
  6 + private String phone; // varchar(50) NOT NULL COMMENT '手机号',
  7 + private String create_time; // datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  8 +
  9 + public Integer getId() {
  10 + return id;
  11 + }
  12 +
  13 + public void setId(Integer id) {
  14 + this.id = id;
  15 + }
  16 +
  17 + public Integer getUser_id() {
  18 + return user_id;
  19 + }
  20 +
  21 + public void setUser_id(Integer user_id) {
  22 + this.user_id = user_id;
  23 + }
  24 +
  25 + public String getPhone() {
  26 + return phone;
  27 + }
  28 +
  29 + public void setPhone(String phone) {
  30 + this.phone = phone;
  31 + }
  32 +
  33 + public String getCreate_time() {
  34 + return create_time;
  35 + }
  36 +
  37 + public void setCreate_time(String create_time) {
  38 + this.create_time = create_time;
  39 + }
  40 +}
@@ -11,6 +11,16 @@ public class WeiXinGongZhongHaoNoticeDto { @@ -11,6 +11,16 @@ public class WeiXinGongZhongHaoNoticeDto {
11 private String gzhsecret; 11 private String gzhsecret;
12 private String templateId; 12 private String templateId;
13 private String redirectUrl; 13 private String redirectUrl;
  14 + private Integer intervalTime;
  15 +
  16 + public Integer getIntervalTime() {
  17 + return intervalTime;
  18 + }
  19 +
  20 + public void setIntervalTime(Integer intervalTime) {
  21 + this.intervalTime = intervalTime;
  22 + }
  23 +
14 24
15 public String getGzhsecret() { 25 public String getGzhsecret() {
16 return gzhsecret; 26 return gzhsecret;
@@ -9,7 +9,15 @@ public class WeiXinXiaoChengXuNoticeDto { @@ -9,7 +9,15 @@ public class WeiXinXiaoChengXuNoticeDto {
9 private String xcxsecret; 9 private String xcxsecret;
10 private String templateId; 10 private String templateId;
11 private String redirectUrl; 11 private String redirectUrl;
  12 + private Integer intervalTime;
12 13
  14 + public Integer getIntervalTime() {
  15 + return intervalTime;
  16 + }
  17 +
  18 + public void setIntervalTime(Integer intervalTime) {
  19 + this.intervalTime = intervalTime;
  20 + }
13 21
14 public Integer getXcxConfigId() { 22 public Integer getXcxConfigId() {
15 return xcxConfigId; 23 return xcxConfigId;
@@ -13,7 +13,10 @@ import com.zhonglai.luhui.dao.service.PublicService; @@ -13,7 +13,10 @@ import com.zhonglai.luhui.dao.service.PublicService;
13 import com.zhonglai.luhui.device.domain.IotAlertLog; 13 import com.zhonglai.luhui.device.domain.IotAlertLog;
14 import com.zhonglai.luhui.device.domain.IotAlertNoticeChannel; 14 import com.zhonglai.luhui.device.domain.IotAlertNoticeChannel;
15 import com.zhonglai.luhui.device.domain.IotPermission; 15 import com.zhonglai.luhui.device.domain.IotPermission;
  16 +import com.zhonglai.luhui.device.dto.AliyunSmsNoticeDto;
  17 +import com.zhonglai.luhui.device.dto.AliyunTTSNoticeDto;
16 import com.zhonglai.luhui.device.dto.WeiXinGongZhongHaoNoticeDto; 18 import com.zhonglai.luhui.device.dto.WeiXinGongZhongHaoNoticeDto;
  19 +import com.zhonglai.luhui.device.dto.WeiXinXiaoChengXuNoticeDto;
17 import io.swagger.annotations.Api; 20 import io.swagger.annotations.Api;
18 import io.swagger.annotations.ApiOperation; 21 import io.swagger.annotations.ApiOperation;
19 import org.springframework.beans.factory.annotation.Autowired; 22 import org.springframework.beans.factory.annotation.Autowired;
@@ -65,6 +68,27 @@ public class IotAlertNoticeChannelController extends BaseController { @@ -65,6 +68,27 @@ public class IotAlertNoticeChannelController extends BaseController {
65 return AjaxResult.error("渠道配置填写错误"); 68 return AjaxResult.error("渠道配置填写错误");
66 } 69 }
67 break; 70 break;
  71 + case 2:
  72 + WeiXinXiaoChengXuNoticeDto weiXinXiaoChengXuNoticeDto = JSONObject.parseObject(iotAlertNoticeChannel.getConfig(), WeiXinXiaoChengXuNoticeDto.class);
  73 + if(BeanUtil.isNotEmpty(weiXinXiaoChengXuNoticeDto))
  74 + {
  75 + return AjaxResult.error("渠道配置填写错误");
  76 + }
  77 + break;
  78 + case 4:
  79 + AliyunSmsNoticeDto aliyunSmsNoticeDto = JSONObject.parseObject(iotAlertNoticeChannel.getConfig(), AliyunSmsNoticeDto.class);
  80 + if(BeanUtil.isNotEmpty(aliyunSmsNoticeDto))
  81 + {
  82 + return AjaxResult.error("渠道配置填写错误");
  83 + }
  84 + break;
  85 + case 5:
  86 + AliyunTTSNoticeDto aliyunTTSNoticeDto = JSONObject.parseObject(iotAlertNoticeChannel.getConfig(), AliyunTTSNoticeDto.class);
  87 + if(BeanUtil.isNotEmpty(aliyunTTSNoticeDto))
  88 + {
  89 + return AjaxResult.error("渠道配置填写错误");
  90 + }
  91 + break;
68 } 92 }
69 return toAjax(publicService.insert(iotAlertNoticeChannel)); 93 return toAjax(publicService.insert(iotAlertNoticeChannel));
70 } 94 }
@@ -41,6 +41,19 @@ @@ -41,6 +41,19 @@
41 <groupId>com.zhonglai</groupId> 41 <groupId>com.zhonglai</groupId>
42 <artifactId>weixin-api</artifactId> 42 <artifactId>weixin-api</artifactId>
43 </dependency> 43 </dependency>
  44 +
  45 + <dependency>
  46 + <groupId>com.aliyun</groupId>
  47 + <artifactId>alibabacloud-dysmsapi20170525</artifactId>
  48 + </dependency>
  49 + <dependency>
  50 + <groupId>org.apache.httpcomponents.client5</groupId>
  51 + <artifactId>httpclient5</artifactId>
  52 + </dependency>
  53 + <dependency>
  54 + <groupId>com.aliyun</groupId>
  55 + <artifactId>alibabacloud-dyvmsapi20170525</artifactId>
  56 + </dependency>
44 </dependencies> 57 </dependencies>
45 58
46 <build> 59 <build>
@@ -46,13 +46,14 @@ public abstract class UpAlarmFactory<T> { @@ -46,13 +46,14 @@ public abstract class UpAlarmFactory<T> {
46 return new IotTerminalAlarm(IotTerminal.instantiate(beforecolumns),IotTerminal.instantiate(aftercolumns)); 46 return new IotTerminalAlarm(IotTerminal.instantiate(beforecolumns),IotTerminal.instantiate(aftercolumns));
47 case "mqtt_broker.iot_alert": 47 case "mqtt_broker.iot_alert":
48 return new IotAlertAlarm(IotAlert.instantiate(beforecolumns),IotAlert.instantiate(aftercolumns)); 48 return new IotAlertAlarm(IotAlert.instantiate(beforecolumns),IotAlert.instantiate(aftercolumns));
49 -  
50 case "mqtt_broker.iot_alert_notice_channel": 49 case "mqtt_broker.iot_alert_notice_channel":
51 return new IotAlertNoticeChannelUpCach(IotAlertNoticeChannel.instantiate(beforecolumns),IotAlertNoticeChannel.instantiate(aftercolumns)); 50 return new IotAlertNoticeChannelUpCach(IotAlertNoticeChannel.instantiate(beforecolumns),IotAlertNoticeChannel.instantiate(aftercolumns));
52 case "mqtt_broker.iot_alert_user_notice": 51 case "mqtt_broker.iot_alert_user_notice":
53 return new IotAlertUserNoticeUpCack(IotAlertUserNotice.instantiate(beforecolumns),IotAlertUserNotice.instantiate(aftercolumns)); 52 return new IotAlertUserNoticeUpCack(IotAlertUserNotice.instantiate(beforecolumns),IotAlertUserNotice.instantiate(aftercolumns));
54 case "mqtt_broker.user_openid": 53 case "mqtt_broker.user_openid":
55 return new UserOpenidUpCach(UserOpenid.instantiate(beforecolumns),UserOpenid.instantiate(aftercolumns)); 54 return new UserOpenidUpCach(UserOpenid.instantiate(beforecolumns),UserOpenid.instantiate(aftercolumns));
  55 + case "mqtt_broker.user_alert_phone":
  56 + return new UserAlertPhoneUpCach(UserAlertPhone.instantiate(beforecolumns),UserAlertPhone.instantiate(aftercolumns));
56 } 57 }
57 return null; 58 return null;
58 } 59 }
  1 +package com.zhonglai.luhui.alarm.clas;
  2 +
  3 +import com.zhonglai.luhui.alarm.config.CachAlarmConfig;
  4 +import com.zhonglai.luhui.alarm.dto.UserAlertPhone;
  5 +import com.zhonglai.luhui.alarm.dto.UserOpenid;
  6 +
  7 +import java.io.Serializable;
  8 +import java.util.Set;
  9 +
  10 +/**
  11 + * 用户告警手机号
  12 + */
  13 +public class UserAlertPhoneUpCach extends UpAlarmFactory<UserAlertPhone> implements Serializable {
  14 + public UserAlertPhoneUpCach(UserAlertPhone beforeupAlarmDb, UserAlertPhone afterupAlarmDb) {
  15 + super(beforeupAlarmDb, afterupAlarmDb);
  16 + }
  17 +
  18 + @Override
  19 + void deleteGenerateAlarm() {
  20 + Set<String> set = CachAlarmConfig.user_phone.get(beforeupAlarmDb.getUser_id());
  21 + if(null != set)
  22 + {
  23 + set.remove(beforeupAlarmDb.getPhone());
  24 + if(set.size()==0)
  25 + {
  26 + CachAlarmConfig.user_phone.remove(beforeupAlarmDb.getUser_id());
  27 + }
  28 + }
  29 +
  30 + }
  31 +
  32 + @Override
  33 + void insertGenerateAlarm() {
  34 + CachAlarmConfig.addUserPhone(afterupAlarmDb);
  35 + }
  36 +
  37 + @Override
  38 + void updateGenerateAlarm() {
  39 + deleteGenerateAlarm();
  40 + insertGenerateAlarm();
  41 + }
  42 +
  43 + @Override
  44 + Object getNowValue(Object model_name, Integer type) {
  45 + return null;
  46 + }
  47 +}
@@ -44,6 +44,10 @@ public class CachAlarmConfig { @@ -44,6 +44,10 @@ public class CachAlarmConfig {
44 /** 用户设备关系 */ 44 /** 用户设备关系 */
45 public static Map<String, Integer> dervice_user = new HashMap<>(); 45 public static Map<String, Integer> dervice_user = new HashMap<>();
46 46
  47 + /** 用户手机号关系 */
  48 + public static Map<Integer, Set<String>> user_phone = new HashMap<>();
  49 +
  50 +
47 public static void loadConfig() 51 public static void loadConfig()
48 { 52 {
49 //加载属性告警配置 53 //加载属性告警配置
@@ -69,6 +73,9 @@ public class CachAlarmConfig { @@ -69,6 +73,9 @@ public class CachAlarmConfig {
69 73
70 //加载设备用户 74 //加载设备用户
71 loadDeviceUser(); 75 loadDeviceUser();
  76 +
  77 + //加载用户手机号
  78 + loadUserPhone();
72 } 79 }
73 80
74 /** 81 /**
@@ -225,6 +232,29 @@ public class CachAlarmConfig { @@ -225,6 +232,29 @@ public class CachAlarmConfig {
225 } 232 }
226 } 233 }
227 234
  235 + private static void loadUserPhone()
  236 + {
  237 + List<UserAlertPhone> list = DbOperateUtil.getUserPhoneList();
  238 + if(null != list && list.size() != 0)
  239 + {
  240 + for (UserAlertPhone userAlertPhone:list)
  241 + {
  242 + addUserPhone(userAlertPhone);
  243 + }
  244 + }
  245 + }
  246 +
  247 + public static void addUserPhone(UserAlertPhone userAlertPhone)
  248 + {
  249 + Set<String> phoneset = user_phone.get(userAlertPhone.getUser_id());
  250 + if(null == phoneset)
  251 + {
  252 + phoneset = new HashSet<>();
  253 + user_phone.put(userAlertPhone.getUser_id(),phoneset);
  254 + }
  255 + phoneset.add(userAlertPhone.getPhone());
  256 + }
  257 +
228 public static void addDeviceUser(String derviceInfoid,Integer userInfoId) 258 public static void addDeviceUser(String derviceInfoid,Integer userInfoId)
229 { 259 {
230 dervice_user.put(derviceInfoid,userInfoId); 260 dervice_user.put(derviceInfoid,userInfoId);
@@ -466,4 +496,14 @@ public class CachAlarmConfig { @@ -466,4 +496,14 @@ public class CachAlarmConfig {
466 } 496 }
467 return null; 497 return null;
468 } 498 }
  499 +
  500 +
  501 + public static Set<String> getUserPhone(Integer user_id)
  502 + {
  503 + if(user_phone.containsKey(user_id) && null != user_phone.get(user_id))
  504 + {
  505 + return user_phone.get(user_id);
  506 + }
  507 + return null;
  508 + }
469 } 509 }
@@ -82,4 +82,9 @@ public class DbOperateUtil { @@ -82,4 +82,9 @@ public class DbOperateUtil {
82 { 82 {
83 return baseDao.findBysql("SELECT user_info_id,id FROM `iot_terminal` WHERE user_info_id IS NOT NULL",IotTerminal.class); 83 return baseDao.findBysql("SELECT user_info_id,id FROM `iot_terminal` WHERE user_info_id IS NOT NULL",IotTerminal.class);
84 } 84 }
  85 + public static List<UserAlertPhone> getUserPhoneList()
  86 + {
  87 + return baseDao.findBysql("SELECT user_id,phone FROM `user_alert_phone` WHERE user_info_id IS NOT NULL",UserAlertPhone.class);
  88 + }
  89 +
85 } 90 }
  1 +package com.zhonglai.luhui.alarm.dto;
  2 +
  3 +import com.alibaba.otter.canal.protocol.CanalEntry;
  4 +
  5 +import java.util.List;
  6 +
  7 +/**
  8 + * 用户告警手机号
  9 + */
  10 +public class UserAlertPhone {
  11 + private Integer id; // int NOT NULL AUTO_INCREMENT COMMENT '主键',
  12 + private Integer user_id; // int NOT NULL COMMENT '用户id',
  13 + private String phone; // varchar(50) NOT NULL COMMENT '手机号',
  14 + private String create_time; // datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  15 +
  16 + public static UserAlertPhone instantiate(List<CanalEntry.Column> columns) {
  17 + if (null == columns || columns.size() ==0)
  18 + {
  19 + return null;
  20 + }
  21 + UserAlertPhone userAlertPhone = new UserAlertPhone();
  22 + for (CanalEntry.Column column : columns)
  23 + {
  24 + switch (column.getName())
  25 + {
  26 + case "user_id":
  27 + userAlertPhone.setUser_id(Integer.parseInt(column.getValue()));
  28 + break;
  29 + case "phone":
  30 + userAlertPhone.setPhone(column.getValue());
  31 + break;
  32 +
  33 + }
  34 + }
  35 + if(null == userAlertPhone.getPhone() || null == userAlertPhone.getUser_id())
  36 + {
  37 + return null;
  38 + }
  39 + return userAlertPhone;
  40 + }
  41 +
  42 + public Integer getId() {
  43 + return id;
  44 + }
  45 +
  46 + public void setId(Integer id) {
  47 + this.id = id;
  48 + }
  49 +
  50 + public Integer getUser_id() {
  51 + return user_id;
  52 + }
  53 +
  54 + public void setUser_id(Integer user_id) {
  55 + this.user_id = user_id;
  56 + }
  57 +
  58 + public String getPhone() {
  59 + return phone;
  60 + }
  61 +
  62 + public void setPhone(String phone) {
  63 + this.phone = phone;
  64 + }
  65 +
  66 + public String getCreate_time() {
  67 + return create_time;
  68 + }
  69 +
  70 + public void setCreate_time(String create_time) {
  71 + this.create_time = create_time;
  72 + }
  73 +}
@@ -4,9 +4,13 @@ import com.alibaba.fastjson.JSONObject; @@ -4,9 +4,13 @@ import com.alibaba.fastjson.JSONObject;
4 import com.zhonglai.luhui.alarm.config.CachAlarmConfig; 4 import com.zhonglai.luhui.alarm.config.CachAlarmConfig;
5 import com.zhonglai.luhui.alarm.dto.IotAlertLog; 5 import com.zhonglai.luhui.alarm.dto.IotAlertLog;
6 import com.zhonglai.luhui.alarm.dto.UserAlarmNoticeConfig; 6 import com.zhonglai.luhui.alarm.dto.UserAlarmNoticeConfig;
  7 +import com.zhonglai.luhui.alarm.notice.dto.AliyunSmsNoticeDto;
  8 +import com.zhonglai.luhui.alarm.notice.dto.AliyunTTSNoticeDto;
7 import com.zhonglai.luhui.alarm.notice.dto.WeiXinGongZhongHaoNoticeDto; 9 import com.zhonglai.luhui.alarm.notice.dto.WeiXinGongZhongHaoNoticeDto;
8 import com.zhonglai.luhui.alarm.notice.dto.WeiXinXiaoChengXuNoticeDto; 10 import com.zhonglai.luhui.alarm.notice.dto.WeiXinXiaoChengXuNoticeDto;
9 import com.zhonglai.luhui.alarm.notice.dto.wxUniformSend.WeiXinMessage; 11 import com.zhonglai.luhui.alarm.notice.dto.wxUniformSend.WeiXinMessage;
  12 +import com.zhonglai.luhui.alarm.notice.impl.AliyunSmsNoticeImpl;
  13 +import com.zhonglai.luhui.alarm.notice.impl.AliyunTTSNoticeImpl;
10 import com.zhonglai.luhui.alarm.notice.impl.WeiXinGongZhongHaoNoticeImpl; 14 import com.zhonglai.luhui.alarm.notice.impl.WeiXinGongZhongHaoNoticeImpl;
11 import com.zhonglai.luhui.alarm.notice.impl.WeiXinXiaoChengXuNoticeImpl; 15 import com.zhonglai.luhui.alarm.notice.impl.WeiXinXiaoChengXuNoticeImpl;
12 import com.zhonglai.luhui.alarm.service.SendAlarmService; 16 import com.zhonglai.luhui.alarm.service.SendAlarmService;
@@ -17,6 +21,7 @@ import weixin.popular.api.MessageAPI; @@ -17,6 +21,7 @@ import weixin.popular.api.MessageAPI;
17 import java.util.List; 21 import java.util.List;
18 22
19 public interface NoticeFactory { 23 public interface NoticeFactory {
  24 + static final Logger logger = LoggerFactory.getLogger(NoticeFactory.class);
20 boolean send(IotAlertLog iotAlertLog); 25 boolean send(IotAlertLog iotAlertLog);
21 static boolean notice(IotAlertLog iotAlertLog) 26 static boolean notice(IotAlertLog iotAlertLog)
22 { 27 {
@@ -40,10 +45,15 @@ public interface NoticeFactory { @@ -40,10 +45,15 @@ public interface NoticeFactory {
40 noticeFactory = new WeiXinXiaoChengXuNoticeImpl(iotAlertLog.getUser_id(),weiXinXiaoChengXuNoticeDto); 45 noticeFactory = new WeiXinXiaoChengXuNoticeImpl(iotAlertLog.getUser_id(),weiXinXiaoChengXuNoticeDto);
41 break; 46 break;
42 case 3: 47 case 3:
  48 +
43 break; 49 break;
44 case 4: 50 case 4:
  51 + AliyunSmsNoticeDto aliyunSmsNoticeDto = JSONObject.parseObject(userAlarmNoticeConfig.getFromConfig(),AliyunSmsNoticeDto.class);
  52 + noticeFactory = new AliyunSmsNoticeImpl(iotAlertLog.getUser_id(),aliyunSmsNoticeDto);
45 break; 53 break;
46 case 5: 54 case 5:
  55 + AliyunTTSNoticeDto aliyunTTSNoticeDto = JSONObject.parseObject(userAlarmNoticeConfig.getFromConfig(), AliyunTTSNoticeDto.class);
  56 + noticeFactory = new AliyunTTSNoticeImpl(iotAlertLog.getUser_id(),aliyunTTSNoticeDto);
47 break; 57 break;
48 } 58 }
49 if(null != noticeFactory) 59 if(null != noticeFactory)
  1 +package com.zhonglai.luhui.alarm.notice.dto;
  2 +
  3 +public class AliyunSmsNoticeDto {
  4 + private String accessKeyId;
  5 + private String accessKeySecret;
  6 + private String region; //服务器地区
  7 + private String signName; //签名名称
  8 + private String templateCode; //模板
  9 + private Integer intervalTime; //间隔时间
  10 + private String subjectName; //主题名称
  11 +
  12 + public String getSubjectName() {
  13 + return subjectName;
  14 + }
  15 +
  16 + public void setSubjectName(String subjectName) {
  17 + this.subjectName = subjectName;
  18 + }
  19 +
  20 + public Integer getIntervalTime() {
  21 + return intervalTime;
  22 + }
  23 +
  24 + public void setIntervalTime(Integer intervalTime) {
  25 + this.intervalTime = intervalTime;
  26 + }
  27 + public String getSignName() {
  28 + return signName;
  29 + }
  30 +
  31 + public void setSignName(String signName) {
  32 + this.signName = signName;
  33 + }
  34 +
  35 + public String getTemplateCode() {
  36 + return templateCode;
  37 + }
  38 +
  39 + public void setTemplateCode(String templateCode) {
  40 + this.templateCode = templateCode;
  41 + }
  42 +
  43 + public String getAccessKeyId() {
  44 + return accessKeyId;
  45 + }
  46 +
  47 + public void setAccessKeyId(String accessKeyId) {
  48 + this.accessKeyId = accessKeyId;
  49 + }
  50 +
  51 + public String getAccessKeySecret() {
  52 + return accessKeySecret;
  53 + }
  54 +
  55 + public void setAccessKeySecret(String accessKeySecret) {
  56 + this.accessKeySecret = accessKeySecret;
  57 + }
  58 +
  59 + public String getRegion() {
  60 + return region;
  61 + }
  62 +
  63 + public void setRegion(String region) {
  64 + this.region = region;
  65 + }
  66 +}
  1 +package com.zhonglai.luhui.alarm.notice.dto;
  2 +
  3 +public class AliyunTTSNoticeDto {
  4 + private String accessKeyId;
  5 + private String accessKeySecret;
  6 + private String region;
  7 + private String ttsCode;
  8 + private Integer intervalTime;
  9 + private String subjectName;
  10 +
  11 + private String calledNumber; //来电显示手机号
  12 + private Integer volume; //音量
  13 + private Integer playTimes; //播放次数
  14 +
  15 + private Integer speed; //语速
  16 +
  17 + public Integer getVolume() {
  18 + return volume;
  19 + }
  20 +
  21 + public void setVolume(Integer volume) {
  22 + this.volume = volume;
  23 + }
  24 +
  25 + public Integer getPlayTimes() {
  26 + return playTimes;
  27 + }
  28 +
  29 + public void setPlayTimes(Integer playTimes) {
  30 + this.playTimes = playTimes;
  31 + }
  32 +
  33 + public Integer getSpeed() {
  34 + return speed;
  35 + }
  36 +
  37 + public void setSpeed(Integer speed) {
  38 + this.speed = speed;
  39 + }
  40 +
  41 + public String getCalledNumber() {
  42 + return calledNumber;
  43 + }
  44 +
  45 + public void setCalledNumber(String calledNumber) {
  46 + this.calledNumber = calledNumber;
  47 + }
  48 +
  49 + public String getSubjectName() {
  50 + return subjectName;
  51 + }
  52 +
  53 + public void setSubjectName(String subjectName) {
  54 + this.subjectName = subjectName;
  55 + }
  56 +
  57 + public Integer getIntervalTime() {
  58 + return intervalTime;
  59 + }
  60 +
  61 + public void setIntervalTime(Integer intervalTime) {
  62 + this.intervalTime = intervalTime;
  63 + }
  64 +
  65 + public String getTtsCode() {
  66 + return ttsCode;
  67 + }
  68 +
  69 + public void setTtsCode(String ttsCode) {
  70 + this.ttsCode = ttsCode;
  71 + }
  72 +
  73 + public String getAccessKeyId() {
  74 + return accessKeyId;
  75 + }
  76 +
  77 + public void setAccessKeyId(String accessKeyId) {
  78 + this.accessKeyId = accessKeyId;
  79 + }
  80 +
  81 + public String getAccessKeySecret() {
  82 + return accessKeySecret;
  83 + }
  84 +
  85 + public void setAccessKeySecret(String accessKeySecret) {
  86 + this.accessKeySecret = accessKeySecret;
  87 + }
  88 +
  89 + public String getRegion() {
  90 + return region;
  91 + }
  92 +
  93 + public void setRegion(String region) {
  94 + this.region = region;
  95 + }
  96 +}
@@ -11,7 +11,15 @@ public class WeiXinGongZhongHaoNoticeDto { @@ -11,7 +11,15 @@ public class WeiXinGongZhongHaoNoticeDto {
11 private String gzhsecret; 11 private String gzhsecret;
12 private String templateId; 12 private String templateId;
13 private String redirectUrl; 13 private String redirectUrl;
  14 + private Integer intervalTime;
14 15
  16 + public Integer getIntervalTime() {
  17 + return intervalTime;
  18 + }
  19 +
  20 + public void setIntervalTime(Integer intervalTime) {
  21 + this.intervalTime = intervalTime;
  22 + }
15 public String getGzhsecret() { 23 public String getGzhsecret() {
16 return gzhsecret; 24 return gzhsecret;
17 } 25 }
@@ -10,7 +10,15 @@ public class WeiXinXiaoChengXuNoticeDto { @@ -10,7 +10,15 @@ public class WeiXinXiaoChengXuNoticeDto {
10 private String templateId; 10 private String templateId;
11 private String redirectUrl; 11 private String redirectUrl;
12 12
  13 + private Integer intervalTime;
13 14
  15 + public Integer getIntervalTime() {
  16 + return intervalTime;
  17 + }
  18 +
  19 + public void setIntervalTime(Integer intervalTime) {
  20 + this.intervalTime = intervalTime;
  21 + }
14 public Integer getXcxConfigId() { 22 public Integer getXcxConfigId() {
15 return xcxConfigId; 23 return xcxConfigId;
16 } 24 }
  1 +package com.zhonglai.luhui.alarm.notice.impl;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.aliyun.auth.credentials.Credential;
  5 +import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
  6 +import com.aliyun.sdk.service.dysmsapi20170525.AsyncClient;
  7 +import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsRequest;
  8 +import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsResponse;
  9 +import com.google.gson.Gson;
  10 +import com.google.gson.JsonObject;
  11 +import com.zhonglai.luhui.alarm.config.CachAlarmConfig;
  12 +import com.zhonglai.luhui.alarm.dto.IotAlertLog;
  13 +import com.zhonglai.luhui.alarm.notice.NoticeFactory;
  14 +import com.zhonglai.luhui.alarm.notice.dto.AliyunSmsNoticeDto;
  15 +import darabonba.core.client.ClientOverrideConfiguration;
  16 +
  17 +import java.text.SimpleDateFormat;
  18 +import java.util.*;
  19 +import java.util.concurrent.CompletableFuture;
  20 +import java.util.concurrent.ExecutionException;
  21 +
  22 +/**
  23 + * 阿里云短信通知告警
  24 + */
  25 +public class AliyunSmsNoticeImpl implements NoticeFactory {
  26 + private static Map<String,Integer> phoneLastNoticeTimeMap = new HashMap<>();
  27 + private Set<String> phones;
  28 + private AliyunSmsNoticeDto aliyunSmsNoticeDto;
  29 +
  30 + public AliyunSmsNoticeImpl(Integer userId, AliyunSmsNoticeDto aliyunSmsNoticeDto)
  31 + {
  32 + this.aliyunSmsNoticeDto = aliyunSmsNoticeDto;
  33 + phones = CachAlarmConfig.getUserPhone(userId);
  34 + }
  35 + @Override
  36 + public boolean send(IotAlertLog iotAlertLog) {
  37 + if(null != phones && phones.size() != 0 )
  38 + {
  39 + int nowtime = new Long(System.currentTimeMillis()/1000).intValue();
  40 +
  41 + List<String> dphones = new ArrayList<>();
  42 + for (String phone:phones)
  43 + {
  44 + if(phoneLastNoticeTimeMap.containsKey(phone) && nowtime - phoneLastNoticeTimeMap.get(phone) < aliyunSmsNoticeDto.getIntervalTime())
  45 + {
  46 + dphones.add(phone);
  47 + }else {
  48 + phoneLastNoticeTimeMap.put(phone,nowtime);
  49 + }
  50 + }
  51 + for (String phone:dphones)
  52 + {
  53 + phones.remove(phone);
  54 + }
  55 + AsyncClient client = createSendClient(aliyunSmsNoticeDto.getAccessKeyId(),aliyunSmsNoticeDto.getAccessKeySecret(),aliyunSmsNoticeDto.getRegion());
  56 +
  57 + try {
  58 + send(client,iotAlertLog);
  59 + } catch (Exception e) {
  60 + logger.info("发送短信告警异常",e);
  61 + }finally {
  62 + client.close();
  63 + }
  64 +
  65 + }
  66 + return false;
  67 + }
  68 +
  69 + private AsyncClient createSendClient(String accessKeyId,String accessKeySecret,String region)
  70 + {
  71 + StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
  72 + .accessKeyId(accessKeyId)
  73 + .accessKeySecret(accessKeySecret)
  74 + .build());
  75 +
  76 + // Configure the Client
  77 + AsyncClient client = AsyncClient.builder()
  78 + .region(region) // Region ID
  79 + .credentialsProvider(provider)
  80 + .overrideConfiguration(
  81 + ClientOverrideConfiguration.create()
  82 + .setEndpointOverride("dysmsapi.aliyuncs.com")
  83 + )
  84 + .build();
  85 + return client;
  86 + }
  87 +
  88 + private SendSmsResponse send(AsyncClient client,IotAlertLog iotAlertLog) throws ExecutionException, InterruptedException {
  89 + JSONObject jsonObject = new JSONObject();
  90 + jsonObject.put("userName",aliyunSmsNoticeDto.getSubjectName()+"用户");
  91 + jsonObject.put("deviceName",iotAlertLog.getDevice_name());
  92 + jsonObject.put("alarmTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(iotAlertLog.getCreate_time())));
  93 + jsonObject.put("alarmName",iotAlertLog.getAlert_name());
  94 + SendSmsRequest sendSmsRequest = SendSmsRequest.builder()
  95 + .phoneNumbers(String.join(",", phones))
  96 + .signName(aliyunSmsNoticeDto.getSignName())
  97 + .templateCode(aliyunSmsNoticeDto.getTemplateCode())
  98 + .templateParam(jsonObject.toJSONString())
  99 + .build();
  100 + CompletableFuture<SendSmsResponse> response = client.sendSms(sendSmsRequest);
  101 + SendSmsResponse resp = response.get();
  102 + return resp;
  103 + }
  104 +}
  1 +package com.zhonglai.luhui.alarm.notice.impl;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.aliyun.auth.credentials.Credential;
  5 +import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
  6 +import com.aliyun.sdk.service.dyvmsapi20170525.AsyncClient;
  7 +import com.aliyun.sdk.service.dyvmsapi20170525.models.SingleCallByTtsRequest;
  8 +import com.aliyun.sdk.service.dyvmsapi20170525.models.SingleCallByTtsResponse;
  9 +import com.zhonglai.luhui.alarm.config.CachAlarmConfig;
  10 +import com.zhonglai.luhui.alarm.dto.IotAlertLog;
  11 +import com.zhonglai.luhui.alarm.notice.NoticeFactory;
  12 +import com.zhonglai.luhui.alarm.notice.dto.AliyunSmsNoticeDto;
  13 +import com.zhonglai.luhui.alarm.notice.dto.AliyunTTSNoticeDto;
  14 +import darabonba.core.client.ClientOverrideConfiguration;
  15 +
  16 +import java.text.SimpleDateFormat;
  17 +import java.util.*;
  18 +import java.util.concurrent.CompletableFuture;
  19 +import java.util.concurrent.ExecutionException;
  20 +
  21 +/**
  22 + * 阿里云语音通知
  23 + */
  24 +public class AliyunTTSNoticeImpl implements NoticeFactory {
  25 + private static Map<String,Integer> phoneLastNoticeTimeMap = new HashMap<>();
  26 + private Set<String> phones;
  27 + private AliyunTTSNoticeDto aliyunTTSNoticeDto;
  28 + public AliyunTTSNoticeImpl(Integer userId, AliyunTTSNoticeDto aliyunTTSNoticeDto)
  29 + {
  30 + this.aliyunTTSNoticeDto = aliyunTTSNoticeDto;
  31 + phones = CachAlarmConfig.getUserPhone(userId);
  32 + }
  33 + @Override
  34 + public boolean send(IotAlertLog iotAlertLog) {
  35 + if(null != phones && phones.size() != 0 )
  36 + {
  37 + int nowtime = new Long(System.currentTimeMillis()/1000).intValue();
  38 + List<String> dphones = new ArrayList<>();
  39 + for (String phone:phones)
  40 + {
  41 + if(phoneLastNoticeTimeMap.containsKey(phone) && nowtime - phoneLastNoticeTimeMap.get(phone) < aliyunTTSNoticeDto.getIntervalTime())
  42 + {
  43 + dphones.add(phone);
  44 + }else {
  45 + phoneLastNoticeTimeMap.put(phone,nowtime);
  46 + }
  47 + }
  48 + for (String phone:dphones)
  49 + {
  50 + phones.remove(phone);
  51 + }
  52 + AsyncClient client = createSendClient();
  53 + try {
  54 + send(client,iotAlertLog);
  55 + } catch (Exception e) {
  56 + logger.info("发送短信告警异常",e);
  57 + }finally {
  58 + client.close();
  59 + }
  60 +
  61 + }
  62 + return false;
  63 + }
  64 +
  65 + private AsyncClient createSendClient()
  66 + {
  67 + StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
  68 + .accessKeyId(aliyunTTSNoticeDto.getAccessKeyId())
  69 + .accessKeySecret(aliyunTTSNoticeDto.getAccessKeySecret())
  70 + .build());
  71 +
  72 + AsyncClient client = AsyncClient.builder()
  73 + .region(aliyunTTSNoticeDto.getRegion()) // Region ID
  74 + .credentialsProvider(provider)
  75 + .overrideConfiguration(
  76 + ClientOverrideConfiguration.create()
  77 + .setEndpointOverride("dyvmsapi.aliyuncs.com")
  78 + )
  79 + .build();
  80 + return client;
  81 + }
  82 +
  83 + private void send(AsyncClient client,IotAlertLog iotAlertLog) throws ExecutionException, InterruptedException {
  84 + JSONObject jsonObject = new JSONObject();
  85 + jsonObject.put("userName",aliyunTTSNoticeDto.getSubjectName()+"用户");
  86 + jsonObject.put("deviceName",iotAlertLog.getDevice_name());
  87 + jsonObject.put("alarmTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(iotAlertLog.getCreate_time())));
  88 + jsonObject.put("alarmName",iotAlertLog.getAlert_name());
  89 +
  90 + for (String phone:phones)
  91 + {
  92 + SingleCallByTtsRequest singleCallByTtsRequest = SingleCallByTtsRequest.builder()
  93 + .ttsCode(aliyunTTSNoticeDto.getTtsCode())
  94 + .ttsParam(jsonObject.toJSONString())
  95 + .playTimes(aliyunTTSNoticeDto.getPlayTimes())
  96 + .volume(aliyunTTSNoticeDto.getVolume())
  97 + .speed(aliyunTTSNoticeDto.getSpeed())
  98 + .calledNumber(phone)
  99 + .calledShowNumber(aliyunTTSNoticeDto.getCalledNumber())
  100 + .build();
  101 + CompletableFuture<SingleCallByTtsResponse> response = client.singleCallByTts(singleCallByTtsRequest);
  102 + SingleCallByTtsResponse resp = response.get();
  103 + System.out.println(JSONObject.toJSONString(resp));
  104 + }
  105 +
  106 + }
  107 +
  108 + public static void main(String[] args) throws ExecutionException, InterruptedException {
  109 + AliyunTTSNoticeDto aliyunTTSNoticeDto = new AliyunTTSNoticeDto();
  110 + aliyunTTSNoticeDto.setAccessKeyId("LTAI4GCBdtG2yynzneLiGFdH");
  111 + aliyunTTSNoticeDto.setAccessKeySecret("UQSSRgQYBSQPDFFETq4inFWsF8LO5Z");
  112 + aliyunTTSNoticeDto.setCalledNumber("02566825265");
  113 + aliyunTTSNoticeDto.setRegion("cn-shanghai");
  114 + aliyunTTSNoticeDto.setIntervalTime(60);
  115 + aliyunTTSNoticeDto.setTtsCode("TTS_93335008");
  116 + aliyunTTSNoticeDto.setSubjectName("鱼儿乐");
  117 + AliyunTTSNoticeImpl aliyunTTSNoticeImpl = new AliyunTTSNoticeImpl(1,aliyunTTSNoticeDto);
  118 + AsyncClient client = aliyunTTSNoticeImpl.createSendClient();
  119 + aliyunTTSNoticeImpl.send(client,null);
  120 + }
  121 +}
@@ -11,6 +11,7 @@ import weixin.popular.api.MessageAPI; @@ -11,6 +11,7 @@ import weixin.popular.api.MessageAPI;
11 import weixin.popular.bean.message.templatemessage.Miniprogram; 11 import weixin.popular.bean.message.templatemessage.Miniprogram;
12 import weixin.popular.bean.message.templatemessage.TemplateMessage; 12 import weixin.popular.bean.message.templatemessage.TemplateMessage;
13 import weixin.popular.bean.message.templatemessage.TemplateMessageItem; 13 import weixin.popular.bean.message.templatemessage.TemplateMessageItem;
  14 +import weixin.popular.bean.message.templatemessage.TemplateMessageResult;
14 15
15 import java.text.SimpleDateFormat; 16 import java.text.SimpleDateFormat;
16 import java.util.*; 17 import java.util.*;
@@ -19,6 +20,7 @@ import java.util.*; @@ -19,6 +20,7 @@ import java.util.*;
19 * 微信公众号 20 * 微信公众号
20 */ 21 */
21 public class WeiXinGongZhongHaoNoticeImpl implements NoticeFactory { 22 public class WeiXinGongZhongHaoNoticeImpl implements NoticeFactory {
  23 + private static Map<String,Integer> wxsendtimeMap = new HashMap<>();
22 24
23 private Set<String> toOpenIds; 25 private Set<String> toOpenIds;
24 26
@@ -54,15 +56,24 @@ public class WeiXinGongZhongHaoNoticeImpl implements NoticeFactory { @@ -54,15 +56,24 @@ public class WeiXinGongZhongHaoNoticeImpl implements NoticeFactory {
54 miniprogram.setAppid(weiXinGongZhongHaoNoticeDto.getXcxappid()); 56 miniprogram.setAppid(weiXinGongZhongHaoNoticeDto.getXcxappid());
55 miniprogram.setPagepath(weiXinGongZhongHaoNoticeDto.getRedirectUrl()); 57 miniprogram.setPagepath(weiXinGongZhongHaoNoticeDto.getRedirectUrl());
56 58
  59 + int nowtime = new Long(System.currentTimeMillis()/1000).intValue();
57 for(String o:os) 60 for(String o:os)
58 { 61 {
  62 + if(wxsendtimeMap.containsKey(o) && nowtime - wxsendtimeMap.get(o) < weiXinGongZhongHaoNoticeDto.getIntervalTime())
  63 + {
  64 + continue;
  65 + }
59 JSONObject templateMessage = new JSONObject(); 66 JSONObject templateMessage = new JSONObject();
60 templateMessage.put("touser",o); 67 templateMessage.put("touser",o);
61 templateMessage.put("template_id",weiXinGongZhongHaoNoticeDto.getTemplateId()); 68 templateMessage.put("template_id",weiXinGongZhongHaoNoticeDto.getTemplateId());
62 templateMessage.put("data",data); 69 templateMessage.put("data",data);
63 templateMessage.put("miniprogram",miniprogram); 70 templateMessage.put("miniprogram",miniprogram);
64 71
65 - WeiXinMessage.messageTemplateSend(weiXinGongZhongHaoNoticeDto.getGzhappid(),weiXinGongZhongHaoNoticeDto.getGzhsecret(),templateMessage); 72 + TemplateMessageResult templateMessageResult = WeiXinMessage.messageTemplateSend(weiXinGongZhongHaoNoticeDto.getGzhappid(),weiXinGongZhongHaoNoticeDto.getGzhsecret(),templateMessage);
  73 + if("0".equals(templateMessageResult.getErrcode()))
  74 + {
  75 + wxsendtimeMap.put(o,nowtime);
  76 + }
66 } 77 }
67 return true; 78 return true;
68 } 79 }
@@ -10,13 +10,13 @@ import weixin.popular.api.MessageAPI; @@ -10,13 +10,13 @@ import weixin.popular.api.MessageAPI;
10 import weixin.popular.bean.message.subscribe.WxXcxSubscribeMessage; 10 import weixin.popular.bean.message.subscribe.WxXcxSubscribeMessage;
11 import weixin.popular.bean.message.templatemessage.Miniprogram; 11 import weixin.popular.bean.message.templatemessage.Miniprogram;
12 import weixin.popular.bean.message.templatemessage.TemplateMessageItem; 12 import weixin.popular.bean.message.templatemessage.TemplateMessageItem;
  13 +import weixin.popular.bean.message.templatemessage.TemplateMessageResult;
13 14
14 import java.text.SimpleDateFormat; 15 import java.text.SimpleDateFormat;
15 -import java.util.Date;  
16 -import java.util.LinkedHashMap;  
17 -import java.util.Set; 16 +import java.util.*;
18 17
19 public class WeiXinXiaoChengXuNoticeImpl implements NoticeFactory { 18 public class WeiXinXiaoChengXuNoticeImpl implements NoticeFactory {
  19 + private static Map<String,Integer> wxsendtimeMap = new HashMap<>();
20 private Set<String> toOpenIds; 20 private Set<String> toOpenIds;
21 21
22 private WeiXinXiaoChengXuNoticeDto weiXinXiaoChengXuNoticeDto; 22 private WeiXinXiaoChengXuNoticeDto weiXinXiaoChengXuNoticeDto;
@@ -55,10 +55,19 @@ public class WeiXinXiaoChengXuNoticeImpl implements NoticeFactory { @@ -55,10 +55,19 @@ public class WeiXinXiaoChengXuNoticeImpl implements NoticeFactory {
55 data.put("thing8",new TemplateMessageItem(iotAlertLog.getAlert_name())); 55 data.put("thing8",new TemplateMessageItem(iotAlertLog.getAlert_name()));
56 wxXcxSubscribeMessage.setData(data); 56 wxXcxSubscribeMessage.setData(data);
57 57
  58 + int nowtime = new Long(System.currentTimeMillis()/1000).intValue();
58 for(String o:os) 59 for(String o:os)
59 { 60 {
  61 + if(wxsendtimeMap.containsKey(o) && nowtime - wxsendtimeMap.get(o) < weiXinXiaoChengXuNoticeDto.getIntervalTime())
  62 + {
  63 + continue;
  64 + }
60 wxXcxSubscribeMessage.setTouser(o); 65 wxXcxSubscribeMessage.setTouser(o);
61 - MessageAPI.messageSubscribeSend(WeiXinMessage.getWechatServerToken(weiXinXiaoChengXuNoticeDto.getXcxappid(),weiXinXiaoChengXuNoticeDto.getXcxsecret()),wxXcxSubscribeMessage); 66 + TemplateMessageResult templateMessageResult = MessageAPI.messageSubscribeSend(WeiXinMessage.getWechatServerToken(weiXinXiaoChengXuNoticeDto.getXcxappid(),weiXinXiaoChengXuNoticeDto.getXcxsecret()),wxXcxSubscribeMessage);
  67 + if("0".equals(templateMessageResult.getErrcode()))
  68 + {
  69 + wxsendtimeMap.put(o,nowtime);
  70 + }
62 } 71 }
63 return true; 72 return true;
64 } 73 }
@@ -63,7 +63,7 @@ public class TriggerAlarmService { @@ -63,7 +63,7 @@ public class TriggerAlarmService {
63 // 连接到Canal服务器 63 // 连接到Canal服务器
64 connector.connect(); 64 connector.connect();
65 // 订阅指定的表(这里以database.table为例) 65 // 订阅指定的表(这里以database.table为例)
66 - connector.subscribe("mqtt_broker\\.(iot_device|iot_terminal|iot_alert|iot_alert_notice_channel|iot_alert_user_notice|user_openid)"); 66 + connector.subscribe("mqtt_broker\\.(iot_device|iot_terminal|iot_alert|iot_alert_notice_channel|iot_alert_user_notice|user_openid|user_alert_phone)");
67 } 67 }
68 68
69 private static void handle() throws InterruptedException { 69 private static void handle() throws InterruptedException {
@@ -82,7 +82,7 @@ public class TriggerAlarmService { @@ -82,7 +82,7 @@ public class TriggerAlarmService {
82 processEntries(message.getEntries()); 82 processEntries(message.getEntries());
83 }catch (Exception e) 83 }catch (Exception e)
84 { 84 {
85 - logger.info("数据处理异常"+message.toString(),e); 85 + logger.info("数据处理异常",e);
86 } 86 }
87 },0, TimeUnit.SECONDS); 87 },0, TimeUnit.SECONDS);
88 } 88 }
@@ -12,6 +12,7 @@ import com.zhonglai.luhui.dao.service.PublicService; @@ -12,6 +12,7 @@ import com.zhonglai.luhui.dao.service.PublicService;
12 import com.zhonglai.luhui.device.domain.IotAlert; 12 import com.zhonglai.luhui.device.domain.IotAlert;
13 import com.zhonglai.luhui.device.domain.IotAlertNoticeChannel; 13 import com.zhonglai.luhui.device.domain.IotAlertNoticeChannel;
14 import com.zhonglai.luhui.device.domain.IotAlertUserNotice; 14 import com.zhonglai.luhui.device.domain.IotAlertUserNotice;
  15 +import com.zhonglai.luhui.device.dto.UserAlertPhone;
15 import com.zhonglai.luhui.device.dto.WeiXinGongZhongHaoNoticeDto; 16 import com.zhonglai.luhui.device.dto.WeiXinGongZhongHaoNoticeDto;
16 import com.zhonglai.luhui.device.dto.WeiXinXiaoChengXuNoticeDto; 17 import com.zhonglai.luhui.device.dto.WeiXinXiaoChengXuNoticeDto;
17 import com.zhonglai.luhui.security.utils.SecurityUtils; 18 import com.zhonglai.luhui.security.utils.SecurityUtils;
@@ -120,7 +121,7 @@ public class UserInfoAlarmController extends BaseController { @@ -120,7 +121,7 @@ public class UserInfoAlarmController extends BaseController {
120 { 121 {
121 map.put("iotAlertList",publicService.getObjectListBySQL("select * from `iot_alert` where product_id="+product_id)); 122 map.put("iotAlertList",publicService.getObjectListBySQL("select * from `iot_alert` where product_id="+product_id));
122 }else { 123 }else {
123 - map.put("iotAlertList",publicService.getObjectListBySQL("select * from `iot_alert` where product_id="+product_id+"alert_id in("+map.get("alert_ids")+")")); 124 + map.put("iotAlertList",publicService.getObjectListBySQL("select * from `iot_alert` where product_id="+product_id+" and alert_id in("+map.get("alert_ids")+")"));
124 } 125 }
125 break; 126 break;
126 case 2: 127 case 2:
@@ -128,7 +129,7 @@ public class UserInfoAlarmController extends BaseController { @@ -128,7 +129,7 @@ public class UserInfoAlarmController extends BaseController {
128 { 129 {
129 map.put("iotAlertList",publicService.getObjectListBySQL("select * from `iot_alert_user` where product_id="+product_id)); 130 map.put("iotAlertList",publicService.getObjectListBySQL("select * from `iot_alert_user` where product_id="+product_id));
130 }else { 131 }else {
131 - map.put("iotAlertList",publicService.getObjectListBySQL("select * from `iot_alert_user` where product_id="+product_id+"alert_id in("+map.get("alert_ids")+")")); 132 + map.put("iotAlertList",publicService.getObjectListBySQL("select * from `iot_alert_user` where product_id="+product_id+" and alert_id in("+map.get("alert_ids")+")"));
132 } 133 }
133 break; 134 break;
134 } 135 }
@@ -209,17 +210,12 @@ public class UserInfoAlarmController extends BaseController { @@ -209,17 +210,12 @@ public class UserInfoAlarmController extends BaseController {
209 uPiotAlertUserNotice.setAlert_ids(alert_ids); 210 uPiotAlertUserNotice.setAlert_ids(alert_ids);
210 }else { 211 }else {
211 List<Map<String,Object>> aidsList = publicService.getObjectListBySQL("SELECT GROUP_CONCAT(alert_id) aids FROM `iot_alert` WHERE product_id<>"+product_id+" AND alert_id IN("+iotAlertUserNotice.getAlert_ids()+")"); 212 List<Map<String,Object>> aidsList = publicService.getObjectListBySQL("SELECT GROUP_CONCAT(alert_id) aids FROM `iot_alert` WHERE product_id<>"+product_id+" AND alert_id IN("+iotAlertUserNotice.getAlert_ids()+")");
212 - if(null != aidsList && aidsList.size() != 0) 213 + if(null != aidsList && aidsList.size() != 0 && null != aidsList.get(0) && null != aidsList.get(0).get("aids"))
213 { 214 {
214 - Object aids = aidsList.get(0).get("aids");  
215 - if(null != aids && !aids.equals(""))  
216 - {  
217 - uPiotAlertUserNotice.setAlert_ids(aids+","+alert_ids); 215 + uPiotAlertUserNotice.setAlert_ids(aidsList.get(0).get("aids")+","+alert_ids);
218 }else { 216 }else {
219 uPiotAlertUserNotice.setAlert_ids(alert_ids); 217 uPiotAlertUserNotice.setAlert_ids(alert_ids);
220 } 218 }
221 -  
222 - }  
223 } 219 }
224 } 220 }
225 221
@@ -231,6 +227,66 @@ public class UserInfoAlarmController extends BaseController { @@ -231,6 +227,66 @@ public class UserInfoAlarmController extends BaseController {
231 return AjaxResult.success(upi); 227 return AjaxResult.success(upi);
232 } 228 }
233 229
  230 + @ApiOperation("获取告警通知的手机号")
  231 + @GetMapping(value = "getUserAlertPhoneList")
  232 + public AjaxResult getUserAlertPhoneList()
  233 + {
  234 + Integer user_id = SecurityUtils.getUserId().intValue();
  235 + List<Map<String,Object>> list = publicService.getObjectListBySQL("select * from user_alert_phone where user_id="+user_id);
  236 + return AjaxResult.success(list);
  237 + }
  238 +
  239 + @ApiOperation("删除告警通知的手机号")
  240 + @ApiImplicitParam(value = "被删除的手机号",name = "phone")
  241 + @PostMapping(value = "delUserAlertPhone")
  242 + public AjaxResult delUserAlertPhone(String phone)
  243 + {
  244 + Integer user_id = SecurityUtils.getUserId().intValue();
  245 + return AjaxResult.success(publicService.updateBySql("DELETE FROM `user_alert_phone` WHERE phone='"+phone+"' AND user_id="+user_id));
  246 + }
  247 +
  248 + @ApiOperation("添加告警通知手机号")
  249 + @ApiImplicitParam(value = "手机号",name = "phone")
  250 + @PostMapping(value = "addUserAlertPhone")
  251 + public AjaxResult addUserAlertPhone(String phone)
  252 + {
  253 +
  254 + Integer user_id = SecurityUtils.getUserId().intValue();
  255 + UserAlertPhone userAlertPhone = new UserAlertPhone();
  256 + userAlertPhone.setPhone(phone);
  257 + userAlertPhone.setUser_id(user_id);
  258 + Long lg = publicService.getObjectListTotle(userAlertPhone,null);
  259 + if (lg>0)
  260 + {
  261 + return AjaxResult.error("该手机号已经添加过了");
  262 + }
  263 + return AjaxResult.success( publicService.insert(userAlertPhone));
  264 + }
  265 +
  266 + @ApiOperation("开通指定通知服务")
  267 + @ApiImplicitParams({
  268 + @ApiImplicitParam(value = "渠道id(管理员提供)",name = "channel_id"),
  269 + @ApiImplicitParam(value = "告警类型(1系统告警,2用户告警)",name = "type"),
  270 + })
  271 + @Log(title = "开通指定通知服务", businessType = BusinessType.INSERT)
  272 + @Transactional
  273 + @PostMapping(value = "openNoticeService/{channel_id}/{type}")
  274 + public AjaxResult openNoticeService(@PathVariable Integer channel_id,@PathVariable Integer type)
  275 + {
  276 + //检查渠道是否存在
  277 + IotAlertNoticeChannel iotAlertNoticeChannel = publicService.getObject(IotAlertNoticeChannel.class,"id",channel_id+"");
  278 + if(null == iotAlertNoticeChannel)
  279 + {
  280 + return AjaxResult.error("通知渠道不存在");
  281 + }
  282 + if(iotAlertNoticeChannel.getType()!=1)
  283 + {
  284 + return AjaxResult.error("该渠道不是公众号通知渠道");
  285 + }
  286 + Integer user_id = SecurityUtils.getUserId().intValue();
  287 + return upIotAlertUserNotice(user_id,channel_id,type);
  288 + }
  289 +
234 private void upOpenid(Integer user_id,String openid,Integer xcxConfigid) 290 private void upOpenid(Integer user_id,String openid,Integer xcxConfigid)
235 { 291 {
236 //更新用户openid表 292 //更新用户openid表
@@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
32 <mybatis-spring-boot.version>2.2.2</mybatis-spring-boot.version> 32 <mybatis-spring-boot.version>2.2.2</mybatis-spring-boot.version>
33 <pagehelper.boot.version>1.4.3</pagehelper.boot.version> 33 <pagehelper.boot.version>1.4.3</pagehelper.boot.version>
34 <fastjson.version>1.2.80</fastjson.version> 34 <fastjson.version>1.2.80</fastjson.version>
  35 + <fastjson2.version>2.0.25</fastjson2.version>
35 <oshi.version>6.2.1</oshi.version> 36 <oshi.version>6.2.1</oshi.version>
36 <commons.io.version>2.11.0</commons.io.version> 37 <commons.io.version>2.11.0</commons.io.version>
37 <commons.fileupload.version>1.4</commons.fileupload.version> 38 <commons.fileupload.version>1.4</commons.fileupload.version>
@@ -148,7 +149,7 @@ @@ -148,7 +149,7 @@
148 <dependency> 149 <dependency>
149 <groupId>com.alibaba.fastjson2</groupId> 150 <groupId>com.alibaba.fastjson2</groupId>
150 <artifactId>fastjson2</artifactId> 151 <artifactId>fastjson2</artifactId>
151 - <version>${fastjson.version}</version> 152 + <version>${fastjson2.version}</version>
152 </dependency> 153 </dependency>
153 154
154 <!-- Token生成与解析--> 155 <!-- Token生成与解析-->
@@ -191,7 +192,7 @@ @@ -191,7 +192,7 @@
191 192
192 <!-- 代码生成--> 193 <!-- 代码生成-->
193 <dependency> 194 <dependency>
194 - <groupId>com.ruoyi</groupId> 195 + <groupId>com.zhonglai.luhui</groupId>
195 <artifactId>ruoyi-generator</artifactId> 196 <artifactId>ruoyi-generator</artifactId>
196 <version>${ruoyi.version}</version> 197 <version>${ruoyi.version}</version>
197 </dependency> 198 </dependency>
@@ -217,13 +218,6 @@ @@ -217,13 +218,6 @@
217 <version>${ruoyi.version}</version> 218 <version>${ruoyi.version}</version>
218 </dependency> 219 </dependency>
219 220
220 - <!-- 系统模块-->  
221 - <dependency>  
222 - <groupId>com.zhonglai.luhui</groupId>  
223 - <artifactId>jhlt-domin</artifactId>  
224 - <version>${ruoyi.version}</version>  
225 - </dependency>  
226 -  
227 <!-- 代码生成模块--> 221 <!-- 代码生成模块-->
228 <dependency> 222 <dependency>
229 <groupId>com.zhonglai.luhui</groupId> 223 <groupId>com.zhonglai.luhui</groupId>
@@ -245,13 +239,6 @@ @@ -245,13 +239,6 @@
245 <version>${ruoyi.version}</version> 239 <version>${ruoyi.version}</version>
246 </dependency> 240 </dependency>
247 241
248 - <!-- poi -->  
249 - <dependency>  
250 - <groupId>com.zhonglai.luhui</groupId>  
251 - <artifactId>lh-common-poi</artifactId>  
252 - <version>${ruoyi.version}</version>  
253 - </dependency>  
254 -  
255 <!-- 公用dao趁层 --> 242 <!-- 公用dao趁层 -->
256 <dependency> 243 <dependency>
257 <groupId>com.zhonglai.luhui</groupId> 244 <groupId>com.zhonglai.luhui</groupId>
@@ -580,7 +567,11 @@ @@ -580,7 +567,11 @@
580 <artifactId>alibabacloud-dysmsapi20170525</artifactId> 567 <artifactId>alibabacloud-dysmsapi20170525</artifactId>
581 <version>2.0.24</version> 568 <version>2.0.24</version>
582 </dependency> 569 </dependency>
583 - 570 + <dependency>
  571 + <groupId>com.aliyun</groupId>
  572 + <artifactId>alibabacloud-dyvmsapi20170525</artifactId>
  573 + <version>2.0.3</version>
  574 + </dependency>
584 <dependency> 575 <dependency>
585 <groupId>com.alibaba.otter</groupId> 576 <groupId>com.alibaba.otter</groupId>
586 <artifactId>canal.client</artifactId> 577 <artifactId>canal.client</artifactId>
@@ -595,7 +586,13 @@ @@ -595,7 +586,13 @@
595 <dependency> 586 <dependency>
596 <groupId>com.zhonglai</groupId> 587 <groupId>com.zhonglai</groupId>
597 <artifactId>weixin-api</artifactId> 588 <artifactId>weixin-api</artifactId>
598 - <version>1.3.2</version> 589 + <version>1.3.3</version>
  590 + </dependency>
  591 +
  592 + <dependency>
  593 + <groupId>org.apache.httpcomponents.client5</groupId>
  594 + <artifactId>httpclient5</artifactId>
  595 + <version>5.1.3</version>
599 </dependency> 596 </dependency>
600 </dependencies> 597 </dependencies>
601 598
@@ -83,7 +83,6 @@ @@ -83,7 +83,6 @@
83 <dependency> 83 <dependency>
84 <groupId>org.apache.httpcomponents.client5</groupId> 84 <groupId>org.apache.httpcomponents.client5</groupId>
85 <artifactId>httpclient5</artifactId> 85 <artifactId>httpclient5</artifactId>
86 - <version>5.1.3</version>  
87 </dependency> 86 </dependency>
88 87
89 </dependencies> 88 </dependencies>