Browse Source

向钉钉推送报警消息时增加时间

lingpeng.li 3 months ago
parent
commit
d5b6220f36

+ 26 - 10
jeecg-module-gather/src/main/java/org/jeecg/modules/fpgJob/LeanModelStatistics.java

@@ -50,6 +50,7 @@ public class LeanModelStatistics {
 
     private static final String WEBHOOK_URL = "https://oapi.dingtalk.com/robot/send?access_token=11065895a52e659bc789a84ae9a81483e2eb9f02c4611ceacb9865f4e51fa2df";
 
+
     @Autowired
     IFpgLeanModelService fpgLeanModelService;
 
@@ -152,10 +153,12 @@ public class LeanModelStatistics {
                             String errorMessage = String.format("【告警】峰平谷MongoDB 统计数据处理异常!\n" +
                                             "**模型代码**: %s\n" +
                                             "**统计ID**: %s\n" +
-                                            "**错误信息**: %s\n",
+                                            "**错误信息**: %s\n" +
+                                            "**时间**: %s",
                                     fpgLeanModeInfo.getLeanModelCode(),
                                     fpgStatiscsModelMongoInfo.get_id(),
-                                    e.getMessage());
+                                    e.getMessage(),
+                                    getFormattedTime());
                             sendDingMessage(errorMessage);
                         }
                     });
@@ -164,9 +167,11 @@ public class LeanModelStatistics {
                     log.error("查询 MongoDB 统计数据异常,模型代码: {}, 错误: {}", fpgLeanModeInfo.getLeanModelCode(), e.getMessage(), e);
                     String errorMessage = String.format("【告警】峰平谷MongoDB 查询统计数据异常!\n" +
                                     "**模型代码**: %s\n" +
-                                    "**错误信息**: %s\n",
+                                    "**错误信息**: %s\n" +
+                                    "**时间**: %s",
                             fpgLeanModeInfo.getLeanModelCode(),
-                            e.getMessage());
+                            e.getMessage(),
+                            getFormattedTime());
                     sendDingMessage(errorMessage);
                 }
             });
@@ -174,8 +179,10 @@ public class LeanModelStatistics {
         } catch (Exception e) {
             log.error("变更占比任务异常,错误: {}", e.getMessage(), e);
             String errorMessage = String.format("【告警】峰平谷变更占比任务异常!\n" +
-                            "**错误信息**: %s\n",
-                    e.getMessage());
+                            "**错误信息**: %s\n" +
+                            "**时间**: %s",
+                    e.getMessage(),
+                    getFormattedTime());
             sendDingMessage(errorMessage);
         }
     }
@@ -430,8 +437,10 @@ public class LeanModelStatistics {
                 } catch (Exception e) {
                     log.error(e.getMessage());
                     String errorMessage = String.format("【告警】峰平谷设备启停统计数据异常!\n" +
-                                    "**错误信息**: %s\n",
-                            e.getMessage());
+                                    "**错误信息**: %s\n" +
+                                    "**时间**: %s",
+                            e.getMessage(),
+                            getFormattedTime());
 
                     sendDingMessage(errorMessage);
 
@@ -850,8 +859,10 @@ public class LeanModelStatistics {
                     log.error(e.getMessage());
 
                     String errorMessage = String.format("【告警】峰平谷精益模型统计数据异常!\n" +
-                                    "**错误信息**: %s\n",
-                            e.getMessage());
+                                    "**错误信息**: %s\n" +
+                                    "**时间**: %s",
+                            e.getMessage(),
+                            getFormattedTime());
 
                     sendDingMessage(errorMessage);
 
@@ -917,4 +928,9 @@ public class LeanModelStatistics {
         log.info("钉钉消息发送结果:{}", response);
     }
 
+
+    public static String getFormattedTime() {
+        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
+    }
+
 }

+ 8 - 1
jeecg-module-gather/src/main/java/org/jeecg/modules/utils/PostgreSQLUtil.java

@@ -8,6 +8,8 @@ import lombok.extern.slf4j.Slf4j;
 
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -52,7 +54,8 @@ public class PostgreSQLUtil {
             // 发送钉钉告警
             String errorMessage = "【告警】:峰平谷PostgreSQL数据库 连接失败!\n" +
                     "【数据库 IP】:" + dbHost + "\n" +
-                    "【端口】:" + dbPort;
+                    "【端口】:" + dbPort + "\n" +
+                    "【时间】:" + getFormattedTime();
             sendDingMessage(errorMessage);
 
             // 这里抛出 RuntimeException,避免返回 null
@@ -102,4 +105,8 @@ public class PostgreSQLUtil {
     private PostgreSQLUtil() {
         // 私有构造函数,防止实例化
     }
+
+    public static String getFormattedTime() {
+        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
+    }
 }

+ 23 - 16
jeecg-module-gather/src/main/java/org/jeecg/modules/utils/ProductPostgreSQLUtil.java

@@ -8,6 +8,8 @@ import lombok.extern.slf4j.Slf4j;
 
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -21,21 +23,21 @@ public class ProductPostgreSQLUtil {
 
     static {
         try {
-        HikariConfig config = new HikariConfig();
-        config.setJdbcUrl("jdbc:postgresql://192.168.19.59:5432/epower?useUnicode=true&ssl=false");
-        config.setUsername("postgres");
-        config.setPassword("1qaz2wsx..");
-        config.setDriverClassName("org.postgresql.Driver");
-        config.setMaximumPoolSize(10); // 最大连接数
-        config.setMinimumIdle(5);      // 最小空闲连接数
-        config.setIdleTimeout(30000);  // 空闲连接超时时间(毫秒)
-        config.setConnectionTimeout(30000); // 连接超时时间(毫秒)
-        config.setMaxLifetime(1800000); // 连接最大生命周期(毫秒)
-
-        // 提取 IP 和端口
-        extractDbInfo(config.getJdbcUrl());
-
-        dataSource = new HikariDataSource(config);
+            HikariConfig config = new HikariConfig();
+            config.setJdbcUrl("jdbc:postgresql://192.168.19.59:5432/epower?useUnicode=true&ssl=false");
+            config.setUsername("postgres");
+            config.setPassword("1qaz2wsx..");
+            config.setDriverClassName("org.postgresql.Driver");
+            config.setMaximumPoolSize(10); // 最大连接数
+            config.setMinimumIdle(5);      // 最小空闲连接数
+            config.setIdleTimeout(30000);  // 空闲连接超时时间(毫秒)
+            config.setConnectionTimeout(30000); // 连接超时时间(毫秒)
+            config.setMaxLifetime(1800000); // 连接最大生命周期(毫秒)
+
+            // 提取 IP 和端口
+            extractDbInfo(config.getJdbcUrl());
+
+            dataSource = new HikariDataSource(config);
         } catch (Exception e) {
             // 这里不能抛出异常,否则类加载失败
             System.err.println("峰平谷PostgreSQL 数据库初始化失败: " + e.getMessage());
@@ -52,7 +54,8 @@ public class ProductPostgreSQLUtil {
             // 发送钉钉告警
             String errorMessage = "【告警】:峰平谷PostgreSQL数据库 连接失败!\n" +
                     "【数据库 IP】:" + dbHost + "\n" +
-                    "【端口】:" + dbPort;
+                    "【端口】:" + dbPort + "\n" +
+                    "【时间】:" + getFormattedTime();
             sendDingMessage(errorMessage);
 
             // 这里抛出 RuntimeException,避免返回 null
@@ -101,4 +104,8 @@ public class ProductPostgreSQLUtil {
     private ProductPostgreSQLUtil() {
         // 私有构造函数,防止实例化
     }
+
+    public static String getFormattedTime() {
+        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
+    }
 }