From ebc94cfa52b28e954b2c182916f68caa96071b58 Mon Sep 17 00:00:00 2001
From: whyclxw <810412026@qq.com>
Date: 星期一, 23 六月 2025 15:47:58 +0800
Subject: [PATCH] 电源历史实时数据初稿

---
 src/main/java/com/whyc/service/SubTablePageInfoService.java    |   54 +++++++++++++++++++++++++++
 src/main/java/com/whyc/service/PwrdevHistorydataIdService.java |   40 ++++++++++++++++++++
 src/main/java/com/whyc/controller/RealContoller.java           |    8 +++
 3 files changed, 101 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/whyc/controller/RealContoller.java b/src/main/java/com/whyc/controller/RealContoller.java
index 860c52c..1855bb5 100644
--- a/src/main/java/com/whyc/controller/RealContoller.java
+++ b/src/main/java/com/whyc/controller/RealContoller.java
@@ -62,10 +62,16 @@
         return tdataIdService.getTinfDataWithTestRecordCount(battgroupId,testRecordCount,recordNum,granularity);
     }
 
-    @ApiOperation(value = "鍘嗗彶瀹炴椂鏌ヨ")
+    @ApiOperation(value = "鐢垫睜鍘嗗彶瀹炴椂鏌ヨ")
     @GetMapping("getBattRealDataHis")
     public Response getBattRealDataHis(@RequestParam Integer battgroupId,@RequestParam Integer granularity
             ,@RequestParam String startTime,@RequestParam String  endTime) throws ParseException, InterruptedException {
         return battRealdataIdService.getBattRealDataHis(battgroupId,granularity,startTime,endTime);
     }
+    @ApiOperation(value = "鐢垫簮鍘嗗彶瀹炴椂鏌ヨ")
+    @GetMapping("getPwrRealDataHis")
+    public Response getPwrRealDataHis(@RequestParam Integer powerId,@RequestParam Integer granularity
+            ,@RequestParam String startTime,@RequestParam String  endTime) throws ParseException, InterruptedException {
+        return pwrdevHistorydataIdService.getPwrRealDataHis(powerId,granularity,startTime,endTime);
+    }
 }
\ No newline at end of file
diff --git a/src/main/java/com/whyc/service/PwrdevHistorydataIdService.java b/src/main/java/com/whyc/service/PwrdevHistorydataIdService.java
index 7c00d39..b39b1f5 100644
--- a/src/main/java/com/whyc/service/PwrdevHistorydataIdService.java
+++ b/src/main/java/com/whyc/service/PwrdevHistorydataIdService.java
@@ -261,4 +261,44 @@
             return PwrCapperformanceEnum.PWRSTATE_4.getStateId();
         }
     }
+
+    //鐢垫簮鍘嗗彶瀹炴椂鏌ヨ
+    public Response getPwrRealDataHis(Integer powerId, Integer granularity, String startTime, String endTime) throws InterruptedException, ParseException {
+        //鑾峰彇涓や釜鏃堕棿鍒嗗壊澶氬皯寮犺〃
+        List<List<Date>> monthTimeList = DateUtil.getMonthTime(ThreadLocalUtil.parse(startTime,1),ThreadLocalUtil.parse(endTime,1));
+        List<PwrHisRealDcoutInDto> dataList = new LinkedList<>();
+        ThreadPoolExecutor pool = ThreadPoolExecutorFactory.getPoolExecutor();
+        CountDownLatch latch = new CountDownLatch(monthTimeList.size());
+        for (int i = 0; i < monthTimeList.size(); i++) {
+            int finalI = i;
+            Integer finalGranularity = granularity;
+            pool.execute(() -> {
+                int finalII = finalI;
+                Date recordDatetime=monthTimeList.get(finalII).get(0);
+                Date recordDatetime1=monthTimeList.get(finalII).get(1);
+                String table = powerId + "_" + ThreadLocalUtil.format(recordDatetime,2);
+                String tableName="db_data_history.tb_pwrdev_historydata_"+table;
+                //鍒ゆ柇琛ㄦ槸鍚﹀瓨鍦�
+                int tableNum = subTablePageInfoService.judgeTable_pwrhis(table);
+                List<PwrHisRealDcoutInDto> list = new ArrayList();
+                if (tableNum > 0) {
+                    //鑾峰彇鎸囧畾鏃堕棿娈靛唴鏈�澶ф渶灏弐ecordNum纭繚鏁版嵁鐨勫畬鏁�
+                    List recordNums= subTablePageInfoService.getPwrMaxAndMinRecordNum(tableName,recordDatetime,recordDatetime1);
+                    Integer maxRecordNum= 0;
+                    Integer minRecordNum= 0;
+                    if(recordNums.size()>0){
+                        maxRecordNum=(Integer)recordNums.get(0);
+                        minRecordNum=(Integer)recordNums.get(1);
+                    }
+                    list=subTablePageInfoService.getPwrRealDataHis(tableName, finalGranularity,recordDatetime,recordDatetime1,maxRecordNum,minRecordNum);
+                }
+                dataList.addAll(list);
+                latch.countDown();
+            });
+            sleep(200);
+        }
+        latch.await(10, TimeUnit.MINUTES);
+        List dataListSorted = dataList.stream().sorted(Comparator.comparing(PwrHisRealDcoutInDto::getRecordDatetime)).collect(Collectors.toList());
+        return new Response().setII(1,dataList.size()>0,dataListSorted,"鑾峰彇鍗婂皬鏃跺唴鐩存祦杈撳嚭缁熻");
+    }
 }
\ No newline at end of file
diff --git a/src/main/java/com/whyc/service/SubTablePageInfoService.java b/src/main/java/com/whyc/service/SubTablePageInfoService.java
index 407bf36..ff2d302 100644
--- a/src/main/java/com/whyc/service/SubTablePageInfoService.java
+++ b/src/main/java/com/whyc/service/SubTablePageInfoService.java
@@ -680,6 +680,60 @@
         });
         return list;
     }
+    //鐢垫簮鍘嗗彶瀹炴椂
+    public List<PwrHisRealDcoutInDto> getPwrRealDataHis(String tableName,Integer granularity,Date recordDatetime,Date recordDatetime1,Integer maxRecordNum,Integer minRecordNum) {
+        String sql="select  distinct * " +
+                " from "+tableName+" where record_datetime>='"+ActionUtil.sdf.format(recordDatetime)+"'" +
+                "                    and record_datetime<='"+ActionUtil.sdf.format(recordDatetime1)+
+                "' and (record_num-"+minRecordNum+")%"+granularity+"=0 or record_num="+minRecordNum+" or record_num="+maxRecordNum;
+        sql+=" order by record_datetime asc";
+        List<PwrHisRealDcoutInDto> list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
+            @Override
+            public List getResults(ResultSet rs) throws SQLException {
+                List<PwrHisRealDcoutInDto> list=new ArrayList<>();
+                while (rs.next()){
+                    PwrHisRealDcoutInDto data=new PwrHisRealDcoutInDto();
+                    data.setRecordDatetime(rs.getTimestamp("record_datetime"));
+                    data.setMOutputvol(rs.getFloat("m_outputvol"));
+                    data.setM1Outcurr(rs.getFloat("m1_outcurr"));
+                    data.setM2Outcurr(rs.getFloat("m2_outcurr"));
+                    data.setM3Outcurr(rs.getFloat("m3_outcurr"));
+                    data.setM4Outcurr(rs.getFloat("m4_outcurr"));
+                    data.setM5Outcurr(rs.getFloat("m5_outcurr"));
+                    data.setM6Outcurr(rs.getFloat("m6_outcurr"));
+                    data.setM7Outcurr(rs.getFloat("m7_outcurr"));
+                    data.setM8Outcurr(rs.getFloat("m8_outcurr"));
+                    data.setM9Outcurr(rs.getFloat("m9_outcurr"));
+                    data.setM10Outcurr(rs.getFloat("m10_outcurr"));
+                    data.setM11Outcurr(rs.getFloat("m11_outcurr"));
+                    data.setM12Outcurr(rs.getFloat("m12_outcurr"));
+                    data.setM13Outcurr(rs.getFloat("m13_outcurr"));
+                    data.setM14Outcurr(rs.getFloat("m14_outcurr"));
+                    data.setM15Outcurr(rs.getFloat("m15_outcurr"));
+                    data.setM16Outcurr(rs.getFloat("m16_outcurr"));
+                    data.setM1OutVol(rs.getFloat("m1_out_vol"));
+                    data.setM2OutVol(rs.getFloat("m2_out_vol"));
+                    data.setM3OutVol(rs.getFloat("m3_out_vol"));
+                    data.setM4OutVol(rs.getFloat("m4_out_vol"));
+                    data.setM5OutVol(rs.getFloat("m5_out_vol"));
+                    data.setM6OutVol(rs.getFloat("m6_out_vol"));
+                    data.setM7OutVol(rs.getFloat("m7_out_vol"));
+                    data.setM8OutVol(rs.getFloat("m8_out_vol"));
+                    data.setM9OutVol(rs.getFloat("m9_out_vol"));
+                    data.setM10OutVol(rs.getFloat("m10_out_vol"));
+                    data.setM11OutVol(rs.getFloat("m11_out_vol"));
+                    data.setM12OutVol(rs.getFloat("m12_out_vol"));
+                    data.setM13OutVol(rs.getFloat("m13_out_vol"));
+                    data.setM14OutVol(rs.getFloat("m14_out_vol"));
+                    data.setM15OutVol(rs.getFloat("m15_out_vol"));
+                    data.setM16OutVol(rs.getFloat("m16_out_vol"));
+                    list.add(data);
+                }
+                return list;
+            }
+        });
+        return list;
+    }
     //鍘嗗彶娴嬭瘯璁板綍鍏蜂綋鏌愪竴娆℃斁鐢垫暟鎹鎯�
     public List<BatttestdataId> getTinfDataWithTestRecordCount(String tableName, Integer testRecordCount, Integer recordNum, Integer granularity) {
         String sql="select distinct * from "+tableName+" "+

--
Gitblit v1.9.1