| | |
| | | private BattRealdataIdService battRealdataIdService; |
| | | |
| | | @ApiOperation(value = "交流单元") |
| | | @PostMapping("getPwrHisAcData") |
| | | public Response getPwrHisAcData(@RequestBody SticRealDataAc stic) throws ParseException, InterruptedException { |
| | | return pwrdevHistorydataIdService.getPwrHisAcData(stic); |
| | | @PostMapping("getSticRealAcData") |
| | | public Response getSticRealAcData(@RequestBody SticRealDataAc stic) throws ParseException, InterruptedException { |
| | | return pwrdevHistorydataIdService.getSticRealAcData(stic); |
| | | } |
| | | |
| | | @ApiOperation(value = "核容设备") |
| | | @PostMapping("getSticRealHrData") |
| | | public Response getSticRealHrData(@RequestBody SticRealDataAc stic) throws ParseException, InterruptedException { |
| | | return battRealdataIdService.getSticRealHrData(stic); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | @Data |
| | | public class SticRealDataAc { |
| | | private Integer battgroupId; |
| | | private Integer powerId; |
| | | private Map<String,List<String>> propertyInfo; |
| | | } |
| | |
| | | package com.whyc.service; |
| | | |
| | | import com.whyc.dto.Real.*; |
| | | import com.whyc.dto.RealDataStatic.ResRealDataAc; |
| | | import com.whyc.dto.RealDataStatic.SticRealDataAc; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.factory.ThreadPoolExecutorFactory; |
| | | import com.whyc.mapper.CommonMapper; |
| | |
| | | List dataListSorted = dataList.stream().sorted(Comparator.comparing(RealDateDTO::getRecordTime)).collect(Collectors.toList()); |
| | | return new Response().setIII(1, dataListSorted!=null,dataListSorted,map,"历史实时查询"); |
| | | } |
| | | //实时数据统计曲线--核容设备 |
| | | public Response getSticRealHrData(SticRealDataAc stic) throws ParseException, InterruptedException { |
| | | //获取前笔数*时间间隔 |
| | | PowerheartParam heartParam=heartService.getHeartParamByPowerId(stic.getPowerId()); |
| | | Integer interverCount=100*5;//默认值 |
| | | Integer granularity=5;//默认值 |
| | | if(heartParam!=null){ |
| | | interverCount=heartParam.getAcinInterverCfg()*heartParam.getAcinCountCfg(); |
| | | granularity=heartParam.getAcinInterverCfg(); |
| | | } |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | String dateTime = now.format(formatter); |
| | | Date endTime=ActionUtil.sdf.parse(dateTime); |
| | | // 计算笔数*时间间隔的时间点 |
| | | LocalDateTime halfHourAgo = now.minusMinutes(interverCount); |
| | | // 格式化输出 |
| | | String halfHourAgoTime=halfHourAgo.format(formatter); |
| | | Date startTime=ActionUtil.sdf.parse(halfHourAgoTime); |
| | | //获取两个时间分割多少张表 |
| | | List<List<Date>> monthTimeList = DateUtil.getMonthTime(startTime,endTime); |
| | | List<ResRealDataAc> 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; |
| | | BattRealdataId realdata = new BattRealdataId(); |
| | | realdata.setRecordTime(monthTimeList.get(finalII).get(0)); |
| | | realdata.setRecordTime1(monthTimeList.get(finalII).get(1)); |
| | | String table = stic.getBattgroupId() + "_" + ThreadLocalUtil.format(realdata.getRecordTime(),2); |
| | | String tableName="db_data_history.tb_batt_realdata_"+table; |
| | | realdata.setTableName(table);//表名时间格式部分 |
| | | //判断表是否存在 |
| | | int tableNum = subTablePageInfoService.judgeTable_realdata(table); |
| | | List<ResRealDataAc> list = new ArrayList(); |
| | | if (tableNum > 0) { |
| | | //获取指定时间段内最大最小recordNum确保数据的完整 |
| | | List recordNums= subTablePageInfoService.getBattMaxAndMinRecordNum(tableName,realdata.getRecordTime(),realdata.getRecordTime1()); |
| | | Integer maxRecordNum= 0; |
| | | Integer minRecordNum= 0; |
| | | if(recordNums.size()>0){ |
| | | maxRecordNum=(Integer)recordNums.get(0); |
| | | minRecordNum=(Integer)recordNums.get(1); |
| | | } |
| | | list = subTablePageInfoService.getSticRealHrData(realdata, finalGranularity,maxRecordNum,minRecordNum,stic.getPropertyInfo()); |
| | | } |
| | | dataList.addAll(list); |
| | | latch.countDown(); |
| | | }); |
| | | sleep(200); |
| | | } |
| | | latch.await(10, TimeUnit.MINUTES); |
| | | List dataListSorted = dataList.stream().sorted(Comparator.comparing(ResRealDataAc::getRecordDatetime)).collect(Collectors.toList()); |
| | | return new Response().setII(1,dataList.size()>0,dataListSorted,"实时数据统计曲线--核容设备"); |
| | | } |
| | | } |
| | |
| | | return new Response().setII(1,dataList.size()>0,dataListSorted,"获取半小时内直流输出统计"); |
| | | } |
| | | //实时数据数据曲线统计-交流单元 |
| | | public Response getPwrHisAcData(SticRealDataAc stic) throws ParseException, InterruptedException { |
| | | public Response getSticRealAcData(SticRealDataAc stic) throws ParseException, InterruptedException { |
| | | //获取前笔数*时间间隔 |
| | | PowerheartParam heartParam=heartService.getHeartParamByPowerId(stic.getPowerId()); |
| | | Integer interverCount=100*5;//默认值 |
| | |
| | | maxRecordNum=(Integer)recordNums.get(0); |
| | | minRecordNum=(Integer)recordNums.get(1); |
| | | } |
| | | list=subTablePageInfoService.getPwrHisAcData(tableName, finalGranularity,recordDatetime,recordDatetime1,maxRecordNum,minRecordNum,stic.getPropertyInfo()); |
| | | list=subTablePageInfoService.getSticRealAcData(tableName, finalGranularity,recordDatetime,recordDatetime1,maxRecordNum,minRecordNum,stic.getPropertyInfo()); |
| | | } |
| | | dataList.addAll(list); |
| | | latch.countDown(); |
| | |
| | | return list; |
| | | } |
| | | //实时数据数据曲线统计-交流单元 |
| | | public List<ResRealDataAc> getPwrHisAcData(String tableName, Integer granularity, Date recordDatetime, Date recordDatetime1 |
| | | public List<ResRealDataAc> getSticRealAcData(String tableName, Integer granularity, Date recordDatetime, Date recordDatetime1 |
| | | , Integer maxRecordNum, Integer minRecordNum, Map<String, List<String>> propertyInfo) { |
| | | String propertyStr = propertyInfo.values().stream() |
| | | .flatMap(List::stream) |
| | |
| | | } |
| | | //电池数据历史实时处理 |
| | | public List<RealDateDTO> getBattRealDataHis(BattRealdataId realdata, int granularity,Integer maxRecordNum,Integer minRecordNum) { |
| | | String sql=" select record_time, group_vol, online_vol,group_curr,load_curr, mon_vol, mon_tmp, mon_res, mon_num,record_num " + |
| | | String sql=" select distinct record_time, group_vol, online_vol,group_curr,load_curr, mon_vol, mon_tmp, mon_res, mon_num,record_num " + |
| | | " from db_data_history.tb_batt_realdata_"+realdata.getTableName()+" " + |
| | | " where record_time >= '"+ThreadLocalUtil.format(realdata.getRecordTime(),1)+"' " + |
| | | " and record_time <= '"+ThreadLocalUtil.format(realdata.getRecordTime1(),1)+"' "+ |
| | |
| | | }); |
| | | return list; |
| | | } |
| | | |
| | | //实时数据统计曲线--核容设备 |
| | | public List<ResRealDataAc> getSticRealHrData(BattRealdataId realdata, Integer granularity, Integer maxRecordNum, Integer minRecordNum, Map<String, List<String>> propertyInfo) { |
| | | String propertyStr = propertyInfo.values().stream() |
| | | .flatMap(List::stream) |
| | | .collect(Collectors.joining(",")); |
| | | String sql=" select distinct record_time, "+propertyStr+" "+ |
| | | " from db_data_history.tb_batt_realdata_"+realdata.getTableName()+" " + |
| | | " where record_time >= '"+ThreadLocalUtil.format(realdata.getRecordTime(),1)+"' " + |
| | | " and record_time <= '"+ThreadLocalUtil.format(realdata.getRecordTime1(),1)+"' "+ |
| | | " and (record_num-"+minRecordNum+")%"+granularity+"=0 or record_num="+maxRecordNum+" or record_num="+minRecordNum ; |
| | | List<ResRealDataAc> list = sqlExecuteService.executeQuery_call(sql, new CallBack() { |
| | | @Override |
| | | public List getResults(ResultSet rs) throws SQLException { |
| | | List<ResRealDataAc> list=new ArrayList<>(); |
| | | while (rs.next()){ |
| | | ResRealDataAc data=new ResRealDataAc(); |
| | | data.setRecordDatetime(rs.getTimestamp("record_time")); |
| | | Map<String,Map<String,Float>>dataMap=new HashMap<>(); |
| | | for (Map.Entry<String, List<String>> entry : propertyInfo.entrySet()) { |
| | | String key = entry.getKey(); |
| | | List<String> valueList = entry.getValue(); |
| | | Map<String,Float> propertyMap=new HashMap<>(); |
| | | for (String value : valueList) { |
| | | Float propertyValue = rs.getFloat(value); |
| | | propertyMap.put(value,propertyValue); |
| | | } |
| | | dataMap.put(key,propertyMap); |
| | | } |
| | | data.setPropertyInfo(dataMap); |
| | | list.add(data); |
| | | } |
| | | return list; |
| | | } |
| | | }); |
| | | return list; |
| | | } |
| | | //系统概览获取前N笔核容设备信息 |
| | | public List<RealDateDTO> getBattDevData100(String tableName, Integer granularity, Date recordDatetime, Date recordDatetime1,Integer maxRecordNum,Integer minRecordNum) { |
| | | String sql=" select record_time, group_vol, online_vol,group_curr, load_curr,record_num " + |
| | |
| | | }); |
| | | return list; |
| | | } |
| | | |
| | | } |