Explorar o código

1.江津版本切换 , 数据采集优化
2.数据源配置优化 删除多余配置 优化配置流程
3.优化江津采集日志相关代码
4.自来水和江津采集增加重试机制

1037015548@qq.com hai 4 días
pai
achega
004e9709f5

+ 57 - 25
dc3-gateway/src/main/java/io/github/pnoker/gateway/dbdao/zilaishuiSource/ZilaishuiRealListDao.java

@@ -37,41 +37,73 @@ public class ZilaishuiRealListDao {
     @Qualifier("child3Datasource")
     private DataSource child3DataSource;
 
-    //TODO orcale相关
+    // Oracle相关
     public Integer getTabWaterHistoryCount(String extend){
-        try {
-            String sql = "select count(1)  from cqda.V_SHIZILAISHUI_HISTORY2 WHERE 1=1 ";
-            if(!StringUtils.isEmpty(extend)){
-                sql += extend;
+        int maxRetries = 10;      // 最大重试次数
+        int retryDelay = 2000;   // 每次重试等待时间(毫秒)
+
+        for (int attempt = 1; attempt <= maxRetries; attempt++) {
+            try {
+                String sql = "select count(1) from cqda.V_SHIZILAISHUI_HISTORY2 WHERE 1=1 ";
+                if(!StringUtils.isEmpty(extend)){
+                    sql += extend;
+                }
+                int count = twoTemplate.queryForObject(sql, Integer.class);
+                return count;
+            } catch(Exception ex) {
+                System.err.println("查询历史水量总数失败,第" + attempt + "次尝试:" + ex.getMessage());
+                if (attempt == maxRetries) {
+                    return null;
+                }
+                try {
+                    Thread.sleep(retryDelay);
+                } catch (InterruptedException ie) {
+                    Thread.currentThread().interrupt();
+                    return null;
+                }
             }
-            int count = twoTemplate.queryForObject(sql, Integer.class);
-            return count;
-        }catch(Exception ex){
-            return null;
         }
+        return null;
     }
-    //TODO 分页获取历史水量数据
-    public List<Map<String,Object>> getPageZILAISHUI_HISTORY2(int limit,int offset,String extend){
-        try {
-            String sql = "select " +
-                    " a.TAG_CODE,a.NAME,a.VAL,TO_CHAR(a.QCQUISITION_TIME,'yyyy-mm-dd hh24:mi:ss') AS QCQUISITION_TIME," +
-                    " TO_CHAR(a.UPDATE_TIME,'yyyy-mm-dd hh24:mi:ss') AS UPDATE_TIME " +
-                    " from ( select t.*,rownum AS rownumber from cqda.V_SHIZILAISHUI_HISTORY2  t where rownum <= "+limit+") a " +
-                    " where rownumber > "+offset;
-            if (!StringUtils.isEmpty(extend)) {
-                sql = "select " +
+
+    // 分页获取历史水量数据
+    public List<Map<String,Object>> getPageZILAISHUI_HISTORY2(int limit, int offset, String extend){
+        int maxRetries = 10;      // 最大重试次数
+        int retryDelay = 2000;   // 每次重试等待时间(毫秒)
+
+        for (int attempt = 1; attempt <= maxRetries; attempt++) {
+            try {
+                String sql = "select " +
                         " a.TAG_CODE,a.NAME,a.VAL,TO_CHAR(a.QCQUISITION_TIME,'yyyy-mm-dd hh24:mi:ss') AS QCQUISITION_TIME," +
                         " TO_CHAR(a.UPDATE_TIME,'yyyy-mm-dd hh24:mi:ss') AS UPDATE_TIME " +
-                        " from ( select t.*,rownum AS rownumber from cqda.V_SHIZILAISHUI_HISTORY2  t where rownum <= "+limit+" "+extend+") a " +
-                        " where rownumber >"+offset;
+                        " from ( select t.*,rownum AS rownumber from cqda.V_SHIZILAISHUI_HISTORY2  t where rownum <= "+limit+") a " +
+                        " where rownumber > "+offset;
+                if (!StringUtils.isEmpty(extend)) {
+                    sql = "select " +
+                            " a.TAG_CODE,a.NAME,a.VAL,TO_CHAR(a.QCQUISITION_TIME,'yyyy-mm-dd hh24:mi:ss') AS QCQUISITION_TIME," +
+                            " TO_CHAR(a.UPDATE_TIME,'yyyy-mm-dd hh24:mi:ss') AS UPDATE_TIME " +
+                            " from ( select t.*,rownum AS rownumber from cqda.V_SHIZILAISHUI_HISTORY2  t where rownum <= "+limit+" "+extend+") a " +
+                            " where rownumber >"+offset;
+                }
+                List<Map<String, Object>> tableData = twoTemplate.queryForList(sql);
+                return tableData;
+            } catch(Exception ex) {
+                System.err.println("分页查询历史水量数据失败,第" + attempt + "次尝试:" + ex.getMessage());
+                if (attempt == maxRetries) {
+                    return null;
+                }
+                try {
+                    Thread.sleep(retryDelay);
+                } catch (InterruptedException ie) {
+                    Thread.currentThread().interrupt();
+                    return null;
+                }
             }
-            List<Map<String, Object>> tableData = twoTemplate.queryForList(sql);
-            return tableData;
-        }catch(Exception ex){
-            return null;
         }
+        return null;
     }
 
+
     //TODO pgsql 相关
     //TODO 查询设备关系表信息·不分页
     public List<Map<String,Object>> getWaterLevelCollectionConfigList(String extend){