Showing
1 changed file
with
132 additions
and
49 deletions
@@ -94,6 +94,8 @@ public class YtNoticeServiceImpl implements YtNoticeService { | @@ -94,6 +94,8 @@ public class YtNoticeServiceImpl implements YtNoticeService { | ||
94 | */ | 94 | */ |
95 | private void noticeAll(String messageCode, List<AlarmContact> alarmContactList, AlarmInfoDTO alarmInfo, Organization organization,String tenantId) { | 95 | private void noticeAll(String messageCode, List<AlarmContact> alarmContactList, AlarmInfoDTO alarmInfo, Organization organization,String tenantId) { |
96 | Optional.ofNullable(alarmContactList).ifPresent(contacts -> { | 96 | Optional.ofNullable(alarmContactList).ifPresent(contacts -> { |
97 | + | ||
98 | + /**可用的告警通知模板*/ | ||
97 | QueryWrapper<MessageTemplate> messageTemplateQueryWrapper = new QueryWrapper<MessageTemplate>(); | 99 | QueryWrapper<MessageTemplate> messageTemplateQueryWrapper = new QueryWrapper<MessageTemplate>(); |
98 | messageTemplateQueryWrapper.lambda() | 100 | messageTemplateQueryWrapper.lambda() |
99 | .eq(MessageTemplate::getTenantId, tenantId) | 101 | .eq(MessageTemplate::getTenantId, tenantId) |
@@ -106,62 +108,143 @@ public class YtNoticeServiceImpl implements YtNoticeService { | @@ -106,62 +108,143 @@ public class YtNoticeServiceImpl implements YtNoticeService { | ||
106 | templatesMap.put(item.getMessageType(), item.getId()); | 108 | templatesMap.put(item.getMessageType(), item.getId()); |
107 | } | 109 | } |
108 | }); | 110 | }); |
109 | - List<String> emailReceivers = new ArrayList<>(); | ||
110 | - contacts.stream().parallel().forEach(item -> { | ||
111 | - if (messageCode.contains(MessageTypeEnum.PHONE_MESSAGE.name()) | ||
112 | - && templatesMap.containsKey(MessageTypeEnum.PHONE_MESSAGE.name()) | ||
113 | - && !item.getPhone().isEmpty()) { | ||
114 | - | ||
115 | - | ||
116 | - SmsReqDTO info = new SmsReqDTO(); | ||
117 | - info.setId(templatesMap.get(MessageTypeEnum.PHONE_MESSAGE.name())); | ||
118 | - info.setPhoneNumbers(item.getPhone()); | ||
119 | - LinkedHashMap<String, String> params = new LinkedHashMap<>(); | ||
120 | - //name-其他;device_name-其他;level-其他;location-其他;alarm_value-其他; | ||
121 | - params.put("type", alarmInfo.getType()); | ||
122 | - params.put("device_name", alarmInfo.getDeviceName()); | ||
123 | - params.put("severity", alarmInfo.getSeverity()); | ||
124 | - params.put("organization", organization != null ? organization.getName() : ""); | ||
125 | - params.put("createtime", YtDateTimeUtils.formate(alarmInfo.getCreateTs())); | ||
126 | - info.setParams(params); | ||
127 | - smsService.sendSms(info); | ||
128 | - } | ||
129 | 111 | ||
130 | - if (messageCode.contains(MessageTypeEnum.EMAIL_MESSAGE.name()) | ||
131 | - && templatesMap.containsKey(MessageTypeEnum.EMAIL_MESSAGE.name()) | ||
132 | - && !item.getEmail().isEmpty()) { | ||
133 | - emailReceivers.add(item.getEmail()); | ||
134 | - } | ||
135 | 112 | ||
113 | + if (messageCode.contains(MessageTypeEnum.PHONE_MESSAGE.name()) | ||
114 | + && templatesMap.containsKey(MessageTypeEnum.PHONE_MESSAGE.name())) { | ||
115 | + sms4Alarm(alarmInfo,templatesMap.get(MessageTypeEnum.PHONE_MESSAGE.name()),organization,contacts); | ||
116 | + } | ||
136 | 117 | ||
137 | - if (messageCode.contains(MessageTypeEnum.DING_TALK_MESSAGE.name()) | ||
138 | - && templatesMap.containsKey(MessageTypeEnum.DING_TALK_MESSAGE.name()) | ||
139 | - && !item.getDingtalk().isEmpty()) { | 118 | + if (messageCode.contains(MessageTypeEnum.EMAIL_MESSAGE.name()) |
119 | + && templatesMap.containsKey(MessageTypeEnum.EMAIL_MESSAGE.name())) { | ||
120 | + email4Alarm(alarmInfo,templatesMap.get(MessageTypeEnum.EMAIL_MESSAGE.name()),organization,contacts); | ||
121 | + } | ||
140 | 122 | ||
141 | - } | ||
142 | 123 | ||
143 | - if (messageCode.contains(MessageTypeEnum.WECHAT_MESSAGE.name()) | ||
144 | - && templatesMap.containsKey(MessageTypeEnum.WECHAT_MESSAGE.name()) | ||
145 | - && !item.getWechat().isEmpty()) { | 124 | + if (messageCode.contains(MessageTypeEnum.DING_TALK_MESSAGE.name()) |
125 | + && templatesMap.containsKey(MessageTypeEnum.DING_TALK_MESSAGE.name())) { | ||
126 | + dingTalk4Alarm(alarmInfo,templatesMap.get(MessageTypeEnum.DING_TALK_MESSAGE.name()),organization,contacts); | ||
127 | + } | ||
146 | 128 | ||
147 | - } | ||
148 | - }); | ||
149 | - if (!emailReceivers.isEmpty()) { | ||
150 | - EmailReqDTO info = new EmailReqDTO(); | ||
151 | - info.setTo(emailReceivers.toArray(new String[emailReceivers.size()])); | ||
152 | - info.setSubject(String.format("【%s】告警通知",alarmInfo.getDeviceName())); | ||
153 | - String body =String.format("%s位于【%s】的设备【%s】触发【%s】级的【%s】,请尽快处理!" | ||
154 | - ,YtDateTimeUtils.formate(alarmInfo.getCreateTs()) | ||
155 | - , organization != null ? organization.getName() : "" | ||
156 | - ,alarmInfo.getDeviceName() | ||
157 | - ,alarmInfo.getSeverity() | ||
158 | - , alarmInfo.getType()); | ||
159 | - info.setBody(body); | ||
160 | - info.setEmailFormatEnum(EmailFormatEnum.TEXT.name()); | ||
161 | - info.setId(templatesMap.get(MessageTypeEnum.EMAIL_MESSAGE.name())); | ||
162 | - | ||
163 | - mailService.sendEmail(info); | 129 | + if (messageCode.contains(MessageTypeEnum.WECHAT_MESSAGE.name()) |
130 | + && templatesMap.containsKey(MessageTypeEnum.WECHAT_MESSAGE.name())) { | ||
131 | + weChat4Alarm(alarmInfo,templatesMap.get(MessageTypeEnum.WECHAT_MESSAGE.name()),organization,contacts); | ||
164 | } | 132 | } |
165 | }); | 133 | }); |
166 | } | 134 | } |
135 | + | ||
136 | + /** | ||
137 | + * 短信通知设备告警信息 | ||
138 | + * @param alarmInfo 告警信息 | ||
139 | + * @param templateId 告警模板主键 | ||
140 | + * @param organization 设备所属组织 | ||
141 | + * @param contacts 设备告警联系人 | ||
142 | + */ | ||
143 | + private void sms4Alarm(AlarmInfoDTO alarmInfo,String templateId, Organization organization,List<AlarmContact> contacts){ | ||
144 | + SmsReqDTO info = new SmsReqDTO(); | ||
145 | + info.setId(templateId); | ||
146 | + LinkedHashMap<String, String> params = new LinkedHashMap<>(); | ||
147 | + //name-其他;device_name-其他;level-其他;location-其他;alarm_value-其他; | ||
148 | + params.put("type", alarmInfo.getType()); | ||
149 | + params.put("device_name", alarmInfo.getDeviceName()); | ||
150 | + params.put("severity", alarmInfo.getSeverity()); | ||
151 | + params.put("organization", organization != null ? organization.getName() : ""); | ||
152 | + params.put("createtime", YtDateTimeUtils.formate(alarmInfo.getCreateTs())); | ||
153 | + info.setParams(params); | ||
154 | + contacts.stream().parallel().forEach(item -> { | ||
155 | + if (!item.getPhone().isEmpty()) { | ||
156 | + info.setPhoneNumbers(item.getPhone()); | ||
157 | + smsService.sendSms(info); | ||
158 | + } | ||
159 | + }); | ||
160 | + } | ||
161 | + | ||
162 | + /** | ||
163 | + * 邮件通知设备告警信息 | ||
164 | + * @param alarmInfo 告警信息 | ||
165 | + * @param templateId 告警模板主键 | ||
166 | + * @param organization 设备所属组织 | ||
167 | + * @param contacts 设备告警联系人 | ||
168 | + */ | ||
169 | + private void email4Alarm(AlarmInfoDTO alarmInfo,String templateId, Organization organization,List<AlarmContact> contacts){ | ||
170 | + List<String> emailReceivers = new ArrayList<>(); | ||
171 | + contacts.stream().parallel().forEach(item -> { | ||
172 | + if (!item.getEmail().isEmpty()) { | ||
173 | + emailReceivers.add(item.getEmail()); | ||
174 | + } | ||
175 | + }); | ||
176 | + if (!emailReceivers.isEmpty()) { | ||
177 | + EmailReqDTO info = new EmailReqDTO(); | ||
178 | + info.setTo(emailReceivers.toArray(new String[emailReceivers.size()])); | ||
179 | + info.setSubject(String.format("【%s】告警通知",alarmInfo.getDeviceName())); | ||
180 | + String body =String.format("%s位于【%s】的设备【%s】触发【%s】级的【%s】,请尽快处理!" | ||
181 | + ,YtDateTimeUtils.formate(alarmInfo.getCreateTs()) | ||
182 | + , organization != null ? organization.getName() : "" | ||
183 | + ,alarmInfo.getDeviceName() | ||
184 | + ,alarmInfo.getSeverity() | ||
185 | + , alarmInfo.getType()); | ||
186 | + info.setBody(body); | ||
187 | + info.setEmailFormatEnum(EmailFormatEnum.TEXT.name()); | ||
188 | + info.setId(templateId); | ||
189 | + | ||
190 | + mailService.sendEmail(info); | ||
191 | + } | ||
192 | + } | ||
193 | + | ||
194 | + /** | ||
195 | + * 钉钉通知设备告警信息 | ||
196 | + * @param alarmInfo 告警信息 | ||
197 | + * @param templateId 告警模板主键 | ||
198 | + * @param organization 设备所属组织 | ||
199 | + * @param contacts 设备告警联系人 | ||
200 | + */ | ||
201 | + private void dingTalk4Alarm(AlarmInfoDTO alarmInfo,String templateId, Organization organization,List<AlarmContact> contacts){ | ||
202 | + // TODO 推送钉钉消息 | ||
203 | + SmsReqDTO info = new SmsReqDTO(); | ||
204 | + info.setId(templateId); | ||
205 | + LinkedHashMap<String, String> params = new LinkedHashMap<>(); | ||
206 | + //name-其他;device_name-其他;level-其他;location-其他;alarm_value-其他; | ||
207 | + params.put("type", alarmInfo.getType()); | ||
208 | + params.put("device_name", alarmInfo.getDeviceName()); | ||
209 | + params.put("severity", alarmInfo.getSeverity()); | ||
210 | + params.put("organization", organization != null ? organization.getName() : ""); | ||
211 | + params.put("createtime", YtDateTimeUtils.formate(alarmInfo.getCreateTs())); | ||
212 | + info.setParams(params); | ||
213 | + contacts.stream().parallel().forEach(item -> { | ||
214 | + if (!item.getDingtalk().isEmpty()) { | ||
215 | + info.setPhoneNumbers(item.getDingtalk()); | ||
216 | + smsService.sendSms(info); | ||
217 | + } | ||
218 | + }); | ||
219 | + | ||
220 | + } | ||
221 | + | ||
222 | + /** | ||
223 | + * 微信通知设备告警信息 | ||
224 | + * @param alarmInfo 告警信息 | ||
225 | + * @param templateId 告警模板主键 | ||
226 | + * @param organization 设备所属组织 | ||
227 | + * @param contacts 设备告警联系人 | ||
228 | + */ | ||
229 | + private void weChat4Alarm(AlarmInfoDTO alarmInfo,String templateId, Organization organization,List<AlarmContact> contacts){ | ||
230 | + // TODO 推送微信通知 | ||
231 | + SmsReqDTO info = new SmsReqDTO(); | ||
232 | + info.setId(templateId); | ||
233 | + LinkedHashMap<String, String> params = new LinkedHashMap<>(); | ||
234 | + //name-其他;device_name-其他;level-其他;location-其他;alarm_value-其他; | ||
235 | + params.put("type", alarmInfo.getType()); | ||
236 | + params.put("device_name", alarmInfo.getDeviceName()); | ||
237 | + params.put("severity", alarmInfo.getSeverity()); | ||
238 | + params.put("organization", organization != null ? organization.getName() : ""); | ||
239 | + params.put("createtime", YtDateTimeUtils.formate(alarmInfo.getCreateTs())); | ||
240 | + info.setParams(params); | ||
241 | + contacts.stream().parallel().forEach(item -> { | ||
242 | + if (!item.getWechat().isEmpty()) { | ||
243 | + info.setPhoneNumbers(item.getWechat()); | ||
244 | + smsService.sendSms(info); | ||
245 | + } | ||
246 | + }); | ||
247 | + } | ||
248 | + | ||
249 | + | ||
167 | } | 250 | } |