Просмотр исходного кода

江津influxdb数据采集bug修复

1037015548@qq.com 2 месяцев назад
Родитель
Сommit
6b79d34720

+ 6 - 4
dc3-gateway/src/main/java/io/github/pnoker/gateway/bizmgr/KprJiangjinWaterBizfun.java

@@ -303,13 +303,15 @@ public class KprJiangjinWaterBizfun {
             //TODO
             LocalDateTime todayMidnight = LocalDateTime.now().toLocalDate().atTime(1, 0);
 
-            // 循环从 startDateTime 开始,每 6 小时一次,直到今天 0 点
+            // 循环从 startDateTime 开始,每 3 小时一次,直到今天 0 点
             LocalDateTime currentDateTime = startDateTime;//每次循环查询的起始时间
             while(currentDateTime.isBefore(todayMidnight)) {
                 String startStr = currentDateTime.format(formatter);
-                String endStr = currentDateTime.plusHours(6).format(formatter);
+                String endStr = currentDateTime.plusHours(3).format(formatter);
                 String extend = " QCQUISITION_TIME >= TO_DATE('" + startStr + "', 'YYYY-MM-DD HH24:MI:SS') " +
-                        " AND QCQUISITION_TIME <= TO_DATE('" + endStr + "', 'YYYY-MM-DD HH24:MI:SS') ";
+                        " AND QCQUISITION_TIME <= TO_DATE('" + endStr + "', 'YYYY-MM-DD HH24:MI:SS')";
+//                String extend = " QCQUISITION_TIME >= TO_DATE('" + startStr + "', 'YYYY-MM-DD HH24:MI:SS') " +
+//                        " AND QCQUISITION_TIME <= TO_DATE('" + endStr + "', 'YYYY-MM-DD HH24:MI:SS') and TAG_CODE = 'OPC.JJZLS.CENTER_MODBUS_SS_LJLL2'";
                 int count = DBMgrProxy.getInstance().applyJiangjinDbApi().getTabWaterHistoryCount(extend);
                 if(count>0){
                     int pageNum = count % 5000 == 0 ? count / 5000 : (count / 5000) + 1;//总页数
@@ -356,7 +358,7 @@ public class KprJiangjinWaterBizfun {
                     }
                     System.out.println(startStr+"到"+endStr+"数据整理完成:"+count);
                 }
-                currentDateTime = currentDateTime.plusHours(6); // 增加 6 小时
+                currentDateTime = currentDateTime.plusHours(3); // 增加 3 小时
             }
         }catch(Exception ex){
             ex.printStackTrace();

+ 225 - 223
dc3-gateway/src/main/java/io/github/pnoker/gateway/comtool/ScheduleTaskMgr.java

@@ -219,191 +219,46 @@ public class ScheduleTaskMgr {
 
     //TODO 江津相关
 
-//    @Resource(name = "infulxJiangjinDbUtil")
-//    private InfulxJiangjinDbUtil infulxJiangjinDbUtil;
-//
-//    //TODO 启动后5秒初始化所有配置参数
-//    @PostConstruct
-//    public void initJiangjinApplication(){
-//        new Timer().schedule(new TimerTask() {
-//            @Override
-//            public void run() {
-//                try {
-//                    infulxJiangjinDbUtil.initInfluxDataBase();
-//                    KprJiangjinWaterBizfun.infulxJiangjinDbUtil = infulxJiangjinDbUtil;
-//                }catch(Exception ex){
-//                    log.error("江津启动时初始化配置参数失败:"+ex.getLocalizedMessage());
-//                }
-//            }
-//        },5000);
-//    }
-//
-//    @PostConstruct
-//    public void initJiangjinHisData(){
-//        new Timer().schedule(new TimerTask() {
-//            @Override
-//            public void run() {
-//                try {
-//                    KprJiangjinWaterBizfun.InitRealDb();
-////                    KprJiangjinWaterBizfun.InitDeviceFrequency();
-//                }catch(Exception ex){
-//
-//                }
-//            }
-//        },7000,60000);
-//        //TODO 启动时同步当前月一号到当前时间的所有历史数据
-//        new Timer().schedule(new TimerTask() {
-//            @Override
-//            public void run() {
-//                try {
-//                    KprJiangjinWaterBizfun.initHistoryDb(LocalDate.now().withDayOfMonth(1).atStartOfDay());
-//                }catch(Exception ex){
-//
-//                }
-//            }
-//        },8000);
-//    }
-//
-//    //TODO 每分钟的第五秒执行
-//    @Scheduled(cron = "5 * * * * ?")
-//    public void executeTask() {
-//        KprJiangjinWaterBizfun.InitRealDb();
-//    }
-//
-//    //TODO 每天凌晨1点执行前一天的
-//    @Scheduled(cron = "0 0 1 * * ?")
-//    public void executeHistoryTask() {
-//        //TODO 执行前一天的数据到当前
-//        KprJiangjinWaterBizfun.initHistoryDb(LocalDate.now().minusDays(1).atStartOfDay());
-//    }
-//
-//    //TODO 江津水量预测相关
-//    //每天每个整点的5分
-//    @Scheduled(cron = "0 5 * * * *")
-//    public void executeRecord() {
-//        String formattedDateTime = LocalDate.now().minusDays(1)
-//                .atStartOfDay()
-//                .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
-//        KprJiangjinAimWaterBizFun.initTapWaterData(formattedDateTime);
-//    }
-//    //每天每个整点的5分
-//    @Scheduled(cron = "0 10 * * * *")
-//    public void executeRecordAll() {
-//        String formattedDateTime = LocalDate.now().minusDays(1)
-//                .atStartOfDay()
-//                .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
-//        KprJiangjinAimWaterBizFun.initWaterCollecationReacordAll(formattedDateTime);
-//    }
-//    //TODO 每天每小时的21分执行预测当前月日小时数据
-//    @Scheduled(cron = "0 21 * * * *")
-//    public void executeTbMHourWaterNow() {
-//        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
-////        KprJiangjinAimWaterBizFun.insertYuceHourAddData(time);
-//        KprJiangjinAimWaterBizFun.insertYuceHourDataScheduled(time);
-//    }
-//    //TODO 启动时执行一次
-//    @PostConstruct
-//    public void initExecuteRecordAndAll(){
-//        String formattedDateTime = LocalDate.now().minusDays(1)
-//                .atStartOfDay()
-//                .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
-//        Timer timer = new Timer();
-//        // 创建定时器任务
-//        TimerTask timerTask = new TimerTask() {
-//            @Override
-//            public void run() {
-//                KprJiangjinAimWaterBizFun.initTapWaterData(formattedDateTime);
-//            }
-//        };
-//        timer.schedule(timerTask, 10000); // 10秒后执行一次
-//        Timer timer1 = new Timer();
-//        // 创建定时器任务
-//        TimerTask timerTask1 = new TimerTask() {
-//            @Override
-//            public void run() {
-//                KprJiangjinAimWaterBizFun.initWaterCollecationReacordAll(formattedDateTime);
-//            }
-//        };
-//        timer1.schedule(timerTask1, 10000); // 10秒后执行一次
-//    }
-//
-//    @PostConstruct
-//    public void initOneTapWater(){
-//        Timer timer = new Timer();
-//        // 创建定时器任务
-//        TimerTask timerTask = new TimerTask() {
-//            @Override
-//            public void run() {
-//                KprJiangjinAimWaterBizFun.initTapWaterData("2023-11-01 00:00:00");
-//            }
-//        };
-//        timer.schedule(timerTask, 10000); // 10秒后执行一次
-//    }
-//
-//    @PostConstruct
-//    public void initWaterRecordAll(){
-//        Timer timer = new Timer();
-//        TimerTask timerTask1 = new TimerTask() {
-//            @Override
-//            public void run() {
-//                KprJiangjinAimWaterBizFun.initWaterCollecationReacordAll("2023-11-01 00:00:00");
-//            }
-//        };
-//        timer.schedule(timerTask1,11000);//11秒后执行一次
-//    }
-//    @PostConstruct
-//    public void initWaterHour(){
-//        Timer timer = new Timer();
-//        TimerTask timerTask1 = new TimerTask() {
-//            @Override
-//            public void run() {
-//                String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
-//                KprJiangjinAimWaterBizFun.insertYuceHourDataScheduled(time);
-//            }
-//        };
-//        timer.schedule(timerTask1,9000);//9秒后执行一次
-//    }
-
-
-    /**
-     * TODO 自来水相关
-     */
-    @Resource(name = "infulxZilaishuiDbUtil")
-    private InfulxZilaishuiDbUtil infulxZilaishuiDbUtil;
+    @Resource(name = "infulxJiangjinDbUtil")
+    private InfulxJiangjinDbUtil infulxJiangjinDbUtil;
 
     //TODO 启动后5秒初始化所有配置参数
     @PostConstruct
-    public void initZilaishuiApplication(){
+    public void initJiangjinApplication(){
         new Timer().schedule(new TimerTask() {
             @Override
             public void run() {
                 try {
-                    infulxZilaishuiDbUtil.initInfluxDataBase();
-                    KprZilaishuiWaterBizFun.infulxZilaishuiDbUtil= infulxZilaishuiDbUtil;
+                    infulxJiangjinDbUtil.initInfluxDataBase();
+                    KprJiangjinWaterBizfun.infulxJiangjinDbUtil = infulxJiangjinDbUtil;
                 }catch(Exception ex){
-                    log.error("自来水启动时初始化配置参数失败:"+ex.getLocalizedMessage());
+                    log.error("江津启动时初始化配置参数失败:"+ex.getLocalizedMessage());
                 }
             }
         },5000);
     }
 
     @PostConstruct
-    public void initZilaishuiHisData(){
-        //TODO 启动时同步当前月一号到当前时间的所有历史数据
+    public void initJiangjinHisData(){
         new Timer().schedule(new TimerTask() {
             @Override
             public void run() {
                 try {
-                    KprZilaishuiWaterBizFun.initHistoryDb(LocalDate.now().withDayOfMonth(1).atStartOfDay());
+                    KprJiangjinWaterBizfun.InitRealDb();
+//                    KprJiangjinWaterBizfun.InitDeviceFrequency();
                 }catch(Exception ex){
 
                 }
             }
-        },7000);
+        },7000,60000);
+        //TODO 启动时同步当前月一号到当前时间的所有历史数据
         new Timer().schedule(new TimerTask() {
             @Override
             public void run() {
                 try {
+                    KprJiangjinWaterBizfun.initHistoryDb(LocalDate.now().withDayOfMonth(1).atStartOfDay());
+//                    KprJiangjinWaterBizfun.initHistoryDb(LocalDateTime.now().withDayOfMonth(10).withHour(12)
+//                    .withMinute(0).withSecond(0));
                 }catch(Exception ex){
 
                 }
@@ -411,96 +266,243 @@ public class ScheduleTaskMgr {
         },8000);
     }
 
-    //TODO 每小时的第 0, 5, 10, 15, ..., 55 分钟执行一次
-    @Scheduled(cron = "0 0/5 * * * ?")
-    public void executeZilaishuiTask() {
-        KprZilaishuiWaterBizFun.initHistoryDb(LocalDateTime.now()
-                .withMinute(0)
-                .withSecond(0)
-                .withNano(0));
+    //TODO 每分钟的第五秒执行
+    @Scheduled(cron = "5 * * * * ?")
+    public void executeTask() {
+        KprJiangjinWaterBizfun.InitRealDb();
     }
 
     //TODO 每天凌晨1点执行前一天的
     @Scheduled(cron = "0 0 1 * * ?")
-    public void executeZilaishuiHistoryTask() {
+    public void executeHistoryTask() {
         //TODO 执行前一天的数据到当前
-        KprZilaishuiWaterBizFun.initHistoryDb(LocalDate.now()
-                .minusDays(1)
-                .atStartOfDay());
+        KprJiangjinWaterBizfun.initHistoryDb(LocalDate.now().minusDays(1).atStartOfDay());
+    }
+
+    //TODO 江津水量预测相关
+    //每天每个整点的5分
+    @Scheduled(cron = "0 5 * * * *")
+    public void executeRecord() {
+        String formattedDateTime = LocalDate.now().minusDays(1)
+                .atStartOfDay()
+                .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        KprJiangjinAimWaterBizFun.initTapWaterData(formattedDateTime);
+    }
+    //每天每个整点的5分
+    @Scheduled(cron = "0 10 * * * *")
+    public void executeRecordAll() {
+        String formattedDateTime = LocalDate.now().minusDays(1)
+                .atStartOfDay()
+                .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        KprJiangjinAimWaterBizFun.initWaterCollecationReacordAll(formattedDateTime);
+    }
+    //TODO 每天每小时的21分执行预测当前月日小时数据
+    @Scheduled(cron = "0 21 * * * *")
+    public void executeTbMHourWaterNow() {
+        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
+//        KprJiangjinAimWaterBizFun.insertYuceHourAddData(time);
+        KprJiangjinAimWaterBizFun.insertYuceHourDataScheduled(time);
     }
-    //TODO 市自来水水位预测相关
+    //TODO 启动时执行一次
     @PostConstruct
-    public void initWaterCollecationReacordAll(){
-        new Timer().schedule(new TimerTask() {
+    public void initExecuteRecordAndAll(){
+        String formattedDateTime = LocalDate.now().minusDays(1)
+                .atStartOfDay()
+                .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        Timer timer = new Timer();
+        // 创建定时器任务
+        TimerTask timerTask = new TimerTask() {
             @Override
             public void run() {
-                LocalDateTime firstDayOfLastMonth = LocalDateTime.now()
-                        .minusMonths(1)
-                        .with(TemporalAdjusters.firstDayOfMonth())
-                        .withHour(0)
-                        .withMinute(0)
-                        .withSecond(0)
-                        .withNano(0);//上个月0点
-
-                String formattedDate = firstDayOfLastMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
-                KprZilaishuiLevelBizFun.initWaterLevelReacordAll(formattedDate);
+                KprJiangjinAimWaterBizFun.initTapWaterData(formattedDateTime);
             }
-        },5000);
-    }
-    //TODO 每小时的10分执行原始小时液位数据计算
-    @Scheduled(cron = "0 10 * * * *")
-    public void initHourWaterCollecationReacordAll(){
-        new Timer().schedule(new TimerTask() {
+        };
+        timer.schedule(timerTask, 10000); // 10秒后执行一次
+        Timer timer1 = new Timer();
+        // 创建定时器任务
+        TimerTask timerTask1 = new TimerTask() {
             @Override
             public void run() {
-                String formattedDate = LocalDate.now().atStartOfDay().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
-                KprZilaishuiLevelBizFun.initWaterLevelReacordAll(formattedDate);
+                KprJiangjinAimWaterBizFun.initWaterCollecationReacordAll(formattedDateTime);
             }
-        },5000);
+        };
+        timer1.schedule(timerTask1, 10000); // 10秒后执行一次
     }
-    //TODO 每小时的10分执行原始小时液位数据计算
-    @Scheduled(cron = "0 15 * * * *")
-    public void initYuceLevel(){
-        new Timer().schedule(new TimerTask() {
+
+    @PostConstruct
+    public void initOneTapWater(){
+        Timer timer = new Timer();
+        // 创建定时器任务
+        TimerTask timerTask = new TimerTask() {
             @Override
             public void run() {
-                KprZilaishuiLevelBizFun.insertDailyData();
-                KprZilaishuiLevelBizFun.insertForecastData();
+                KprJiangjinAimWaterBizFun.initTapWaterData("2023-11-01 00:00:00");
             }
-        },5000);
+        };
+        timer.schedule(timerTask, 10000); // 10秒后执行一次
     }
 
-    //TODO 市自来水泵数据采集
     @PostConstruct
-    public void initPumpRecordAll(){
-        new Timer().schedule(new TimerTask() {
+    public void initWaterRecordAll(){
+        Timer timer = new Timer();
+        TimerTask timerTask1 = new TimerTask() {
             @Override
             public void run() {
-                //当前时间到去年对应月份1号0点开始
-                LocalDateTime firstDayOfLastMonth = LocalDateTime.now()
-                        .minusYears(1)
-                        .with(TemporalAdjusters.firstDayOfMonth())
-                        .withHour(0)
-                        .withMinute(0)
-                        .withSecond(0)
-                        .withNano(0);//上个月0点
-                String formattedDate = firstDayOfLastMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
-                KprZilaishuiPumpBizFun.initWaterPumpReacordAll(formattedDate);
+                KprJiangjinAimWaterBizFun.initWaterCollecationReacordAll("2023-11-01 00:00:00");
             }
-        },5000);
+        };
+        timer.schedule(timerTask1,11000);//11秒后执行一次
     }
-
-    //TODO 每小时的10分执行原始小时泵数据计算
-    @Scheduled(cron = "0 10 * * * *")
-    public void checkPumpRecordAll(){
-        new Timer().schedule(new TimerTask() {
+    @PostConstruct
+    public void initWaterHour(){
+        Timer timer = new Timer();
+        TimerTask timerTask1 = new TimerTask() {
             @Override
             public void run() {
-                //当前时间到今天的0点开始
-                LocalDateTime firstDayOfLastMonth = LocalDate.now().atStartOfDay();//上个月0点
-                String formattedDate = firstDayOfLastMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
-                KprZilaishuiPumpBizFun.initWaterPumpReacordAll(formattedDate);
+                String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
+                KprJiangjinAimWaterBizFun.insertYuceHourDataScheduled(time);
             }
-        },5000);
+        };
+        timer.schedule(timerTask1,9000);//9秒后执行一次
     }
+
+
+    /**
+     * TODO 自来水相关
+     */
+//    @Resource(name = "infulxZilaishuiDbUtil")
+//    private InfulxZilaishuiDbUtil infulxZilaishuiDbUtil;
+//
+//    //TODO 启动后5秒初始化所有配置参数
+//    @PostConstruct
+//    public void initZilaishuiApplication(){
+//        new Timer().schedule(new TimerTask() {
+//            @Override
+//            public void run() {
+//                try {
+//                    infulxZilaishuiDbUtil.initInfluxDataBase();
+//                    KprZilaishuiWaterBizFun.infulxZilaishuiDbUtil= infulxZilaishuiDbUtil;
+//                }catch(Exception ex){
+//                    log.error("自来水启动时初始化配置参数失败:"+ex.getLocalizedMessage());
+//                }
+//            }
+//        },5000);
+//    }
+//
+//    @PostConstruct
+//    public void initZilaishuiHisData(){
+//        //TODO 启动时同步当前月一号到当前时间的所有历史数据
+//        new Timer().schedule(new TimerTask() {
+//            @Override
+//            public void run() {
+//                try {
+//                    KprZilaishuiWaterBizFun.initHistoryDb(LocalDate.now().withDayOfMonth(1).atStartOfDay());
+//                }catch(Exception ex){
+//
+//                }
+//            }
+//        },7000);
+//        new Timer().schedule(new TimerTask() {
+//            @Override
+//            public void run() {
+//                try {
+//                }catch(Exception ex){
+//
+//                }
+//            }
+//        },8000);
+//    }
+//
+//    //TODO 每小时的第 0, 5, 10, 15, ..., 55 分钟执行一次
+//    @Scheduled(cron = "0 0/5 * * * ?")
+//    public void executeZilaishuiTask() {
+//        KprZilaishuiWaterBizFun.initHistoryDb(LocalDateTime.now()
+//                .withMinute(0)
+//                .withSecond(0)
+//                .withNano(0));
+//    }
+//
+//    //TODO 每天凌晨1点执行前一天的
+//    @Scheduled(cron = "0 0 1 * * ?")
+//    public void executeZilaishuiHistoryTask() {
+//        //TODO 执行前一天的数据到当前
+//        KprZilaishuiWaterBizFun.initHistoryDb(LocalDate.now()
+//                .minusDays(1)
+//                .atStartOfDay());
+//    }
+//    //TODO 市自来水水位预测相关
+//    @PostConstruct
+//    public void initWaterCollecationReacordAll(){
+//        new Timer().schedule(new TimerTask() {
+//            @Override
+//            public void run() {
+//                LocalDateTime firstDayOfLastMonth = LocalDateTime.now()
+//                        .minusMonths(1)
+//                        .with(TemporalAdjusters.firstDayOfMonth())
+//                        .withHour(0)
+//                        .withMinute(0)
+//                        .withSecond(0)
+//                        .withNano(0);//上个月0点
+//
+//                String formattedDate = firstDayOfLastMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+//                KprZilaishuiLevelBizFun.initWaterLevelReacordAll(formattedDate);
+//            }
+//        },5000);
+//    }
+//    //TODO 每小时的10分执行原始小时液位数据计算
+//    @Scheduled(cron = "0 10 * * * *")
+//    public void initHourWaterCollecationReacordAll(){
+//        new Timer().schedule(new TimerTask() {
+//            @Override
+//            public void run() {
+//                String formattedDate = LocalDate.now().atStartOfDay().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+//                KprZilaishuiLevelBizFun.initWaterLevelReacordAll(formattedDate);
+//            }
+//        },5000);
+//    }
+//    //TODO 每小时的10分执行原始小时液位数据计算
+//    @Scheduled(cron = "0 15 * * * *")
+//    public void initYuceLevel(){
+//        new Timer().schedule(new TimerTask() {
+//            @Override
+//            public void run() {
+//                KprZilaishuiLevelBizFun.insertDailyData();
+//                KprZilaishuiLevelBizFun.insertForecastData();
+//            }
+//        },5000);
+//    }
+//
+//    //TODO 市自来水泵数据采集
+//    @PostConstruct
+//    public void initPumpRecordAll(){
+//        new Timer().schedule(new TimerTask() {
+//            @Override
+//            public void run() {
+//                //当前时间到去年对应月份1号0点开始
+//                LocalDateTime firstDayOfLastMonth = LocalDateTime.now()
+//                        .minusYears(1)
+//                        .with(TemporalAdjusters.firstDayOfMonth())
+//                        .withHour(0)
+//                        .withMinute(0)
+//                        .withSecond(0)
+//                        .withNano(0);//上个月0点
+//                String formattedDate = firstDayOfLastMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+//                KprZilaishuiPumpBizFun.initWaterPumpReacordAll(formattedDate);
+//            }
+//        },5000);
+//    }
+//
+//    //TODO 每小时的10分执行原始小时泵数据计算
+//    @Scheduled(cron = "0 10 * * * *")
+//    public void checkPumpRecordAll(){
+//        new Timer().schedule(new TimerTask() {
+//            @Override
+//            public void run() {
+//                //当前时间到今天的0点开始
+//                LocalDateTime firstDayOfLastMonth = LocalDate.now().atStartOfDay();//上个月0点
+//                String formattedDate = firstDayOfLastMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+//                KprZilaishuiPumpBizFun.initWaterPumpReacordAll(formattedDate);
+//            }
+//        },5000);
+//    }
 }

+ 239 - 0
dc3-gateway/src/main/java/io/github/pnoker/gateway/utils/ExcelTestUtil.java

@@ -0,0 +1,239 @@
+package io.github.pnoker.gateway.utils;
+
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.util.IOUtils;
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.*;
+
+/**
+ * @ClassName ExcelTestUtil
+ * @Description: TODO 最多用35万-五十万数据 批次操作
+ * @Author LX
+ * @Date 2025/3/27
+ * @Version V1.0
+ **/
+public class ExcelTestUtil {
+    public static void main(String[] args) {
+        String filePath = "E:\\工作文件夹\\汤阴\\工作区\\压力计-农村c.xlsx"; // Excel文件路径
+
+        // 定义devId和deviceName的映射关系
+        Map<String, String> devIdToDeviceName = new HashMap<>();
+        devIdToDeviceName.put("372012406122817", "赵家窑供水站压力计");
+        devIdToDeviceName.put("372012406122891", "娄湾供水站压力计");
+        devIdToDeviceName.put("372012406122850", "西冢上供水站压力计");
+        devIdToDeviceName.put("372012406122837", "小庄供水站压力计");
+        devIdToDeviceName.put("372012406122740", "小屯供水站压力计");
+        devIdToDeviceName.put("372012406122710", "西水磨湾供水站压力计");
+        devIdToDeviceName.put("372012406122792", "小贺屯供水站压力计");
+        devIdToDeviceName.put("372012406122844", "小河供水站压力计");
+        devIdToDeviceName.put("372012406122855", "小光供水站压力计");
+        devIdToDeviceName.put("372012406122834", "孙庄供水站压力计");
+        devIdToDeviceName.put("372012406122769", "司马供水站压力计");
+        devIdToDeviceName.put("372012406122884", "前小滩供水站(靠右侧)压力计");
+        devIdToDeviceName.put("372012406123052", "人民路幼儿园工厂压力计");
+        devIdToDeviceName.put("372012406123046", "人民路幼儿园供水站压力计");
+        devIdToDeviceName.put("372012406122791", "七涧村供水站压力计");
+        devIdToDeviceName.put("372012406122754", "南阳供水站压力计");
+        devIdToDeviceName.put("372012406122832", "焦孔供水站压力计");
+        devIdToDeviceName.put("372012406122827", "韩庄供水站压力计");
+        devIdToDeviceName.put("372012406122841", "候庄供水站压力计");
+        devIdToDeviceName.put("372012406122714", "后攸昙供水站压力计");
+        devIdToDeviceName.put("372012406122746", "岗阳南供水站压力计");
+        devIdToDeviceName.put("372012406122729", "岗阳北供水站压力计");
+        devIdToDeviceName.put("372012406122790", "驸马营供水站压力计");
+        devIdToDeviceName.put("372012406122744", "伏道四街供水站压力计");
+        devIdToDeviceName.put("372012406122877", "伏道一街供水站压力计");
+        devIdToDeviceName.put("372012406122808", "董庄供水站压力计");
+        devIdToDeviceName.put("372012406122803", "大性中街供水站压力计");
+        devIdToDeviceName.put("372012406122762", "大性南街供水站压力计");
+        devIdToDeviceName.put("372012406122776", "大性北供水站压力计");
+        devIdToDeviceName.put("372012406122723", "东官庄供水站压力计");
+        devIdToDeviceName.put("372012406123089", "北里于供水站压力计");
+        devIdToDeviceName.put("372012406122913", "白营县政府供水站压力计");
+        devIdToDeviceName.put("372012406122909", "白营养老院供水站压力计");
+        devIdToDeviceName.put("372012406122840", "部落供水站压力计");
+        devIdToDeviceName.put("372012406122821", "庵上供水站压力计");
+        devIdToDeviceName.put("372012406122758", "东师庄供水站压力计");
+        devIdToDeviceName.put("372012406122726", "东水磨湾供水站压力计");
+        devIdToDeviceName.put("372012403252412", "白营一支线压力计");
+        devIdToDeviceName.put("372012403251531", "白营二支线压力计");
+        devIdToDeviceName.put("372012403251634", "二水厂主管线-2 水厂右侧压力计");
+        devIdToDeviceName.put("372012403251516", "二水厂主管线-1 水厂左侧压力计");
+        devIdToDeviceName.put("372012403251579", "南申庄供水站压力计");
+        devIdToDeviceName.put("372012403251547", "辉泉供水站压力计");
+        devIdToDeviceName.put("372012403251539", "辉鹏供水站压力计");
+        devIdToDeviceName.put("372012403251627", "管线支线压力计");
+        devIdToDeviceName.put("372012403251611", "飞机场支线压力计");
+        devIdToDeviceName.put("372012403251595", "伏道二街第二支线压力计");
+        devIdToDeviceName.put("372012403251509", "伏道支线一支压力计");
+        devIdToDeviceName.put("372012403251523", "北城王供水站压力计");
+        devIdToDeviceName.put("372012403251603", "飞机场供水站压力计");
+
+
+        // 增加内存限制
+        IOUtils.setByteArrayMaxOverride(400_000_000);
+
+        try (FileInputStream fis = new FileInputStream(filePath)) {
+            // 读取原始文件
+            Workbook inputWorkbook = new XSSFWorkbook(fis);
+            Sheet inputSheet = inputWorkbook.getSheetAt(0);
+            int totalRows = inputSheet.getLastRowNum() + 1;
+
+            // 线程池配置
+            int threadCount = Math.max(1, Runtime.getRuntime().availableProcessors() / 2); // 根据 CPU 核心数调整线程数
+            ExecutorService executor = Executors.newFixedThreadPool(threadCount);
+
+            // 用于存储需要修改的行数据和对应的deviceName
+            ConcurrentHashMap<Integer, String> rowDataMap = new ConcurrentHashMap<>();
+
+            // 分块处理Sheet
+            int chunkSize = 1000; // 每次处理的行数
+            for (int startRow = 1; startRow < totalRows; startRow += chunkSize) {
+                int endRow = Math.min(startRow + chunkSize, totalRows); // 确保不超出最大索引
+                int copyStartRow = startRow;
+                executor.submit(() -> processChunk(inputSheet, devIdToDeviceName, copyStartRow, endRow, rowDataMap));
+            }
+
+            // 关闭线程池并等待所有任务完成
+            executor.shutdown();
+            executor.awaitTermination(1, TimeUnit.HOURS);
+
+            // 创建新的 SXSSFWorkbook
+            try (SXSSFWorkbook workbook = new SXSSFWorkbook(1000)) { // 设置缓存 1000 行
+                Sheet outputSheet = workbook.createSheet("Sheet1");
+
+                // 手动管理 FileOutputStream
+                try (FileOutputStream fos = new FileOutputStream(filePath)) {
+                    // 分批写入数据
+                    for (int startRow = 0; startRow < totalRows; startRow += 100000) {
+                        int endRow = Math.min(startRow + 100000, totalRows);
+                        writeBatch(inputSheet, outputSheet, startRow, endRow, rowDataMap, 8); // 假设设备名插入到第5列(索引为4)
+                    }
+                    // 刷新数据到文件
+                    System.out.println("正在执行写入....");
+                    workbook.write(fos);
+                    fos.flush(); // 刷新流,确保数据写入文件
+                }
+
+                // 清理临时文件
+                workbook.dispose();
+            }
+
+            System.out.println("操作完成!");
+
+        } catch (IOException | InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+
+    // 处理单块数据
+    private static void processChunk(Sheet sheet, Map<String, String> devIdToDeviceName, int startRow, int endRow, ConcurrentHashMap<Integer, String> rowDataMap) {
+        for (int rowIndex = startRow; rowIndex < endRow; rowIndex++) {
+            Row row = sheet.getRow(rowIndex);
+            if (row == null) continue;
+
+            // 获取dev_id列的值(第4列,索引为3)
+            Cell devIdCell = row.getCell(3); // 第4列
+            if (devIdCell != null) {
+                String devId = getCellValueAsString(devIdCell);
+                System.out.println("处理行: " + rowIndex + ", devId: " + devId + ", 设备名: " + devIdToDeviceName.get(devId));
+                // 如果dev_id在映射集合中,则记录需要修改的行数据
+                if (devIdToDeviceName.containsKey(devId)) {
+                    rowDataMap.put(rowIndex, devIdToDeviceName.get(devId));
+                }
+            }
+        }
+    }
+
+    // 将单元格值转换为字符串
+    private static String getCellValueAsString(Cell cell) {
+        switch (cell.getCellType()) {
+            case STRING:
+                return cell.getStringCellValue();
+            case NUMERIC:
+                return String.valueOf((long) cell.getNumericCellValue()); // 假设dev_id是整数
+            default:
+                return "";
+        }
+    }
+
+    /**
+     * 将设备名插入到指定列
+     *
+     * @param inputSheet   输入表格
+     * @param outputSheet  输出表格
+     * @param startRow     起始行
+     * @param endRow       结束行
+     * @param rowDataMap   存储行数据和设备名的映射
+     * @param targetColumn 目标列(列索引从 0 开始)
+     */
+    private static void writeBatch(Sheet inputSheet, Sheet outputSheet, int startRow, int endRow,
+                                   ConcurrentHashMap<Integer, String> rowDataMap, int targetColumn) {
+        for (int rowIndex = startRow; rowIndex < endRow; rowIndex++) {
+            Row inputRow = inputSheet.getRow(rowIndex);
+            if (inputRow == null) {
+                continue; // 如果行为空,跳过
+            }
+
+            // 获取设备名
+            String deviceName = rowDataMap.get(rowIndex);
+            if (deviceName == null) {
+                continue; // 如果设备名不存在,跳过
+            }
+
+            // 检查行是否已经存在
+            Row outputRow = outputSheet.getRow(rowIndex);
+            if (outputRow == null) {
+                outputRow = outputSheet.createRow(rowIndex); // 如果行不存在,则创建
+            }
+
+            // 复制输入行数据到输出行
+            for (int colIndex = 0; colIndex < inputRow.getLastCellNum(); colIndex++) {
+                Cell inputCell = inputRow.getCell(colIndex);
+                if (inputCell != null) {
+                    Cell outputCell = outputRow.createCell(colIndex);
+                    switch (inputCell.getCellType()) {
+                        case STRING:
+                            outputCell.setCellValue(inputCell.getStringCellValue());
+                            break;
+                        case NUMERIC:
+                            if (DateUtil.isCellDateFormatted(inputCell)) {
+                                // 如果是日期类型,获取日期值
+                                outputCell.setCellValue(inputCell.getDateCellValue());
+                            } else {
+                                // 如果是数值类型,获取数值
+                                outputCell.setCellValue(inputCell.getNumericCellValue());
+                            }
+                            break;
+                        case BOOLEAN:
+                            outputCell.setCellValue(inputCell.getBooleanCellValue());
+                            break;
+                        case FORMULA:
+                            outputCell.setCellFormula(inputCell.getCellFormula());
+                            break;
+                        case BLANK:
+                            outputCell.setBlank();
+                            break;
+                        default:
+                            outputCell.setCellValue(""); // 其他类型设置为空字符串
+                            break;
+                    }
+                }
+            }
+
+            // 在指定列插入设备名
+            Cell targetCell = outputRow.createCell(targetColumn);
+            targetCell.setCellValue(deviceName);
+        }
+    }
+
+
+
+}

+ 15 - 2
dc3-gateway/src/main/resources/application.yml

@@ -16,7 +16,7 @@
 
 server:
   #服务器配置
-  port: 8000
+  port: 8003
   undertow:
     threads:
       io: 2
@@ -151,9 +151,22 @@ spring:
             driver-class-name: oracle.jdbc.driver.OracleDriver
       childpg:
         driver-class-name: org.postgis.DriverWrapper
-        jdbc-url: jdbc:postgresql_postGIS://10.101.3.104:5432/water_volume_prediction_jiangjin?useSSL=false&useAffectedRows=false&allowMultiQueries=true
+#        jdbc-url: jdbc:postgresql_postGIS://10.101.3.104:5432/water_volume_prediction_jiangjin2?useSSL=false&useAffectedRows=false&allowMultiQueries=true
+        jdbc-url: jdbc:postgresql_postGIS://140.246.183.164:5432/water_volume_prediction_jiangjin?useSSL=false&useAffectedRows=false&allowMultiQueries=true
         username: postgres
         password: kpr.23417.postgres
+      child2pg:
+        driver-class-name: org.postgis.DriverWrapper
+        jdbc-url: jdbc:postgresql_postGIS://10.101.5.50:5432/water_level_prediction?useSSL=false&useAffectedRows=false&allowMultiQueries=true
+        username: postgres
+        password: ygt.23417.postgres
+      child3pg:
+        driver-class-name: org.postgis.DriverWrapper
+        jdbc-url: jdbc:postgresql_postGIS://10.101.5.50:5432/water_volume_prediction?useSSL=false&useAffectedRows=false&allowMultiQueries=true
+#        jdbc-url: jdbc:postgresql_postGIS://140.246.183.164:5432/water_volume_prediction?useSSL=false&useAffectedRows=false&allowMultiQueries=true
+        username: postgres
+        password: ygt.23417.postgres
+#        password: kpr.23417.postgres
   jpa:
     show-sql: false