|
@@ -1,5 +1,8 @@
|
|
|
package com.yunfeiyun.agmp.iots.warn.util;
|
|
package com.yunfeiyun.agmp.iots.warn.util;
|
|
|
|
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+
|
|
|
public class WarnMessageBuilderUtil {
|
|
public class WarnMessageBuilderUtil {
|
|
|
/**
|
|
/**
|
|
|
* 构建告警信息。
|
|
* 构建告警信息。
|
|
@@ -36,16 +39,37 @@ public class WarnMessageBuilderUtil {
|
|
|
* @param name
|
|
* @param name
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public static String buildWarningOfflineMessage(String devType, String devCode, String name) {
|
|
|
|
|
- String tag = "";
|
|
|
|
|
- if (devType != null && devCode != null) {
|
|
|
|
|
- tag = String.format("%s设备(%s), 触发告警,告警原因: \n", devType, devCode);
|
|
|
|
|
|
|
+ public static String buildWarningOfflineMessage(String devType, String devCode, String name, String lastUpdateTime) {
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ try {
|
|
|
|
|
+ Date lastUpdate = sdf.parse(lastUpdateTime);
|
|
|
|
|
+ long diffInMillis = System.currentTimeMillis() - lastUpdate.getTime();
|
|
|
|
|
+
|
|
|
|
|
+ long diffMinutes = diffInMillis / (60 * 1000) % 60;
|
|
|
|
|
+ long diffHours = diffInMillis / (60 * 60 * 1000) % 24;
|
|
|
|
|
+ long diffDays = diffInMillis / (24 * 60 * 60 * 1000);
|
|
|
|
|
+
|
|
|
|
|
+ String durationStr;
|
|
|
|
|
+ if (diffDays > 0) {
|
|
|
|
|
+ durationStr = String.format("已离线%d天%d小时%d分", diffDays, diffHours, diffMinutes);
|
|
|
|
|
+ } else if (diffHours > 0) {
|
|
|
|
|
+ durationStr = String.format("已离线%d小时%d分", diffHours, diffMinutes);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ durationStr = String.format("已离线%d分钟", diffMinutes);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String content = String.format("%s设备(%s)%s;", devType, devCode, durationStr);
|
|
|
|
|
+ return content;
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ return "无法解析离线时间";
|
|
|
}
|
|
}
|
|
|
- return String.format("%s %s 离线。", tag, name);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
|
|
- String message = buildQxzWarningMessage("气象站", "87872877485", "温度", "42", "℃", "超过", "10-35℃");
|
|
|
|
|
- System.out.println(message);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// public static void main(String[] args) {
|
|
|
|
|
+// String message = buildQxzWarningMessage("气象站", "87872877485", "温度", "42", "℃", "超过", "10-35℃");
|
|
|
|
|
+// System.out.println(message);
|
|
|
|
|
+// System.out.println(buildWarningOfflineMessage("温度计", "T123", "温度监控器A", "2025-03-19 12:35:00"));
|
|
|
|
|
+// }
|
|
|
}
|
|
}
|