whyclxw
3 天以前 ebc94cfa52b28e954b2c182916f68caa96071b58
电源历史实时数据初稿
3个文件已修改
102 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/RealContoller.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/PwrdevHistorydataIdService.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/SubTablePageInfoService.java 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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);
    }
}
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) {
                    //获取指定时间段内最大最小recordNum确保数据的完整
                    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,"获取半小时内直流输出统计");
    }
}
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+" "+