package com.jiayue.biz.service.impl; import cn.hutool.core.date.DateTime; import cn.hutool.db.Entity; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.jiayue.biz.domain.*; import com.jiayue.biz.eunms.WindDirectionEnum; import com.jiayue.biz.mapper.WindTowerDataParentTableMapper; import com.jiayue.biz.service.*; import com.jiayue.biz.util.CalculationUtil; import com.jiayue.biz.util.DateMomentUtil; import com.jiayue.biz.util.DateTimeUtil; import com.jiayue.common.utils.DateUtil; import flanagan.analysis.ProbabilityPlot; import lombok.AllArgsConstructor; import org.apache.commons.lang3.time.DateUtils; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.math.RoundingMode; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; import static com.jiayue.biz.eunms.TimeDimension.month; /** * 首页Service业务层处理 * * @author L.ym * @date 2022-05-11 */ @Service @AllArgsConstructor public class PdfServiceImpl extends ServiceImpl implements PdfService { private final WindTowerInfoServiceImpl windTowerInfoService; private final WindTowerCalculationDataServiceImpl windTowerCalculationDataService; private final EquipmentAttributeService equipmentAttributeService; private final RealTimeDisplayService realTimeDisplayService; private final WindDirectionStatisticsDataServiceImpl windDirectionStatisticsDataService; private final ProphaseAnemometryDataService prophaseAnemometryDataService; private final ProphaseWeatherDataService prophaseWeatherDataService; @Override public Map generatePDF(String equipmentId, String height, Date startDay, Date endDay) { //如果结束时间大于现在时间 if (DateUtil.date().getTime() < endDay.getTime()) { //将结束时间设置为昨天结束时间 endDay = DateUtil.endOfDay(DateUtil.yesterday()); } Map map = new HashMap<>(); SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); long realityCount = 0;//数据实际条数 // 一年的计算数据 startDay = DateUtil.beginOfMonth(startDay); endDay = DateUtil.endOfMonth(endDay); List windTowerCalculationDatas = windTowerCalculationDataService.getByBetweenTimeAndEquipmentId(startDay, endDay, equipmentId); // 一年的风向统计数据 List windDirectionStatisticsDataList = windDirectionStatisticsDataService.getByBetweenTimeAndEquipmentId(startDay, endDay, equipmentId); //所有类型数据 List equipmentAttributeList = equipmentAttributeService.list(); //所有测风塔信息 List windTowerInfoList = windTowerInfoService.list(); List windTowerInfos = windTowerInfoList.stream().filter(w -> w.getEquipmentNo().equals(equipmentId)).collect(Collectors.toList()); // List windTowerInfos = windTowerInfoService.getByEquipmentNo(equipmentId); //计算完整性 List entities = prophaseWeatherDataService.selectCount(equipmentId); for (Entity entity : entities) { //过滤非时间区间的数据累加;只要时间范围内的 if(((Timestamp)entity.get("_wstart")).compareTo(startDay) > -1 && ((Timestamp)entity.get("_wstart")).compareTo(endDay) <=0){ // td engine 取出的时间需要截取字段 realityCount += (long) entity.get("count(*)"); } } //测风塔信息概要 Map windTowerInfo = getWindTowerInfo(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos, height, realityCount, startDay, endDay); map.put("windTowerInfo", windTowerInfo); //测风塔统计概要概要 Map statisticsData = statisticsWindTowerStatusData(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos, realityCount, startDay, endDay); map.put("statisticsData", statisticsData); //风速和风功率密度时间曲线图 (时间序列) Map wsAndWpd = getWsAndWpd(windTowerCalculationDatas, equipmentAttributeList, height, startDay, endDay); map.put("wsAndWpd", wsAndWpd); //风速和风速标准差时间曲线图 Map wsAndWsStaData = wsAndWsSta(windTowerCalculationDatas, equipmentAttributeList, height, startDay, endDay); map.put("wsAndWsStaData", wsAndWsStaData); //风速和风速密度日变化 Map windPowerDensityAndAverageWindSpeed = getWindPowerDensityAndAverageWindSpeed(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos, height); map.put("windPowerDensityAndAverageWindSpeed", windPowerDensityAndAverageWindSpeed); //风速和风速密度各月日变化 List> MonthWsAndWpd = getMonthWsAndWpd(windTowerCalculationDatas, equipmentAttributeList, height, startDay, endDay); map.put("MonthWsAndWpd", MonthWsAndWpd); //风速和风速密度年变化曲线 Map yearWsAndWpd = getYearWsAndWpd(windTowerCalculationDatas, equipmentAttributeList, height, startDay, endDay); map.put("yearWsAndWpd", yearWsAndWpd); //风速和风速密度各月日变化表格 Map monthWpdTable = getMonthWpdTable(windTowerCalculationDatas, equipmentAttributeList, windTowerInfos, startDay, endDay); map.put("monthWpdTable", monthWpdTable); //pdf威布尔 Map weibull = pdfWeibull(equipmentAttributeList, equipmentId, windTowerCalculationDatas, height); map.put("weibull", weibull); //一年玫瑰图 Map roseChart = roseCharts(windDirectionStatisticsDataList, equipmentAttributeList, height); map.put("roseChart", roseChart); //各月玫瑰图 Map monthRoseCharts = getMonthRoseCharts(windDirectionStatisticsDataList, equipmentAttributeList, height); map.put("monthRoseCharts", monthRoseCharts); //空气密度 Map airDensity = getAirDensity(windTowerCalculationDatas, equipmentAttributeList, startDay, endDay); map.put("airDensity", airDensity); //获取风切变指数(风向玫瑰图) List> windShearRose = getWindShearRose(windDirectionStatisticsDataList, equipmentAttributeList, height); map.put("windShearRose", windShearRose); //风切变日/年变化 Map windShear = getWindShear(windTowerCalculationDatas, equipmentAttributeList, height); map.put("windShear", windShear); //湍流曲线 List> turIntensityCharts = getTurIntensityCharts(windTowerCalculationDatas, equipmentAttributeList, height); map.put("turIntensityCharts", turIntensityCharts); //湍流日/年变化 Map turIntensity = getTurIntensity(windTowerCalculationDatas, equipmentAttributeList, height); map.put("turIntensity", turIntensity); //获取湍流(风向玫瑰图) Map turIntensityRose = getTurIntensityRose(windDirectionStatisticsDataList, equipmentAttributeList, windTowerInfos.get(0), height); map.put("turIntensityRose", turIntensityRose); return map; } /** * 测风塔信息概要 * * @param windTowerCalculationDataList 统计数据 * @param equipmentAttributeList 属性数据 * @param windTowerInfos 测风塔信息 * @param height 层高 * @param realityCount 数据条数 * @return */ public Map getWindTowerInfo(List windTowerCalculationDataList, List equipmentAttributeList, List windTowerInfos, String height, long realityCount, Date startDay, Date endDay) { Map map = new HashMap<>(); try { map.put("windInfo", windTowerInfos.get(0)); /*数据记录信息*/ Map dataMap = new HashMap<>(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //如果查询月份等于当前时间月份就拿数据库最后一天数据的时间作为结束时间 if (endDay.getMonth() == new Date().getMonth()) { List lastData = prophaseWeatherDataService.getLastData(windTowerInfos.get(0).getEquipmentNo()); Timestamp timestamp = new Timestamp(new Date().getTime()); if (lastData != null && lastData.size() > 0) { timestamp = (Timestamp) lastData.get(0).get("last (ts)"); } endDay = new Date(timestamp.getTime()); } Date dayLastTime = DateTimeUtil.getDayLastTime(endDay.getTime()); long count = (dayLastTime.getTime() + 1000 - startDay.getTime()) / (86400000); long totalCount = count * 144;//时间范围内的总条数 long deletionCount;//缺失条数 BigDecimal totalRate = BigDecimal.valueOf(0.0);//完整率 BigDecimal deletionRate = BigDecimal.valueOf(0.0);//缺失率 BigDecimal aveWs = new BigDecimal(0);//平均风速 //取出heigth层高的平均风速属性 List equipmentAttributeList1 = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "awsMonth")).collect(Collectors.toList()); //取出这个层高所有的数据 List windTowerCalculationDataList1 = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(equipmentAttributeList1.get(0).getId())).collect(Collectors.toList()); deletionCount = totalCount - realityCount; if (!windTowerCalculationDataList1.isEmpty()) { //做平均值 aveWs = windTowerCalculationDataList1.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(windTowerCalculationDataList1.size()), 2, RoundingMode.HALF_UP); } else { deletionCount = totalCount; } if (realityCount != 0L) { totalRate = new BigDecimal(realityCount).divide(new BigDecimal(totalCount), 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); } if (deletionCount != 0L) { deletionRate = new BigDecimal(deletionCount).divide(new BigDecimal(totalCount), 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); } dataMap.put("realityCount", realityCount); dataMap.put("totalCount", totalCount); dataMap.put("integrityRate", totalRate); dataMap.put("deletionRate", deletionRate); dataMap.put("ws", aveWs); dataMap.put("time", sdf.format(startDay) + " - " + sdf.format(endDay)); map.put("dataInfo", dataMap); } catch (Exception e) { e.printStackTrace(); } return map; } /** * 测风塔统计概要概要 * * @param windTowerCalculationDatas 统计数据 * @param equipmentAttributeList 属性数据 * @param windTowerInfos 测风塔信息 * @param realityCount 数据条数 * @return */ public Map statisticsWindTowerStatusData(List windTowerCalculationDatas, List equipmentAttributeList, List windTowerInfos, long realityCount, Date startDay, Date endDay) { Map map = new HashMap<>(); try { List> dataList = new ArrayList<>(); //如果查询月份等于当前时间月份就拿数据库最后一天数据的时间作为结束时间 if (endDay.getMonth() == new Date().getMonth()) { List lastData = prophaseWeatherDataService.getLastData(windTowerInfos.get(0).getEquipmentNo()); Timestamp timestamp = new Timestamp(new Date().getTime()); if (lastData != null && lastData.size() > 0) { timestamp = (Timestamp) lastData.get(0).get("last (ts)"); } endDay = new Date(timestamp.getTime()); } Date dayLastTime = DateTimeUtil.getDayLastTime(endDay.getTime()); long count = (dayLastTime.getTime() + 1000 - startDay.getTime()) / (86400000); long totalCount = count * 144;//时间范围内的总条数 // 根据设备属性表中的属性作用查询所有月平均湍流 List turbulenceMonths = equipmentAttributeList.stream().filter(e -> "turbulenceMonth".equals(e.getAttributeFunction())).collect(Collectors.toList()); List wpdMonths = equipmentAttributeList.stream().filter(e -> "WindPowerDensity".equals(e.getAttributeFunction())).collect(Collectors.toList()); String heights = windTowerInfos.get(0).getHeights(); if (heights == null || heights.equals("")) { heights = "10,30,50,60,70,80,90,100,110,120,140,150"; } String[] heightStrs = heights.split(","); for (String height : heightStrs) { Map dataMap = new HashMap<>(); long deletionCount;//缺失条数 BigDecimal integrityRate = BigDecimal.valueOf(0.0);//完整率 BigDecimal aveWs = new BigDecimal(0);//平均风速 BigDecimal maxWs = new BigDecimal(0);//最大风速 BigDecimal aveTur = new BigDecimal(0);//平均湍流 BigDecimal aveWpd = new BigDecimal(0);//平均风功率密度 //取出heigth层高的平均风速属性 List equipmentAttributeList1 = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "awsMonth")).collect(Collectors.toList()); //取height层高的最大风速 List equipmentAttributeListMaxws = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "maxwsMonth")).collect(Collectors.toList()); //取出这个层高所有的数据 List windTowerCalculationDataList1 = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(equipmentAttributeList1.get(0).getId())).collect(Collectors.toList()); //最大值 List windTowerCalculationDataMaxList = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(equipmentAttributeListMaxws.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getValue).reversed()).collect(Collectors.toList()); if (!windTowerCalculationDataList1.isEmpty()) { deletionCount = totalCount - realityCount; if (!windTowerCalculationDataList1.isEmpty()) { aveWs = windTowerCalculationDataList1.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(windTowerCalculationDataList1.size()), 2, RoundingMode.HALF_UP); } if (!windTowerCalculationDataMaxList.isEmpty()) { maxWs = windTowerCalculationDataMaxList.get(0).getValue(); } } else { deletionCount = totalCount; } if (realityCount != 0L) { integrityRate = new BigDecimal(realityCount).divide(new BigDecimal(totalCount), 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); } if (!turbulenceMonths.isEmpty()) { /*平均湍流*/ String turbulenceMonth = height + "turbulenceMonth"; // 过滤属性集合找对应的属性id List turbulenceMonthAtt = turbulenceMonths.stream().filter(w -> w.getFieldName().equals(turbulenceMonth)).collect(Collectors.toList()); String turEbId = turbulenceMonthAtt.get(0).getId(); // 过滤一周数据 List turbulenceMonthList = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(turEbId)).collect(Collectors.toList()); if (!turbulenceMonthList.isEmpty()) { aveTur = turbulenceMonthList.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(turbulenceMonthList.size()), 2, RoundingMode.HALF_UP); } } if (!wpdMonths.isEmpty()) { /*平均风功率密度*/ String wpdMonth = height + "wpdMonth"; // 过滤属性集合找对应的属性id List wpdMonthAtt = wpdMonths.stream().filter(w -> w.getFieldName().equals(wpdMonth)).collect(Collectors.toList()); String wpdEbId = wpdMonthAtt.get(0).getId(); // 过滤一周数据 List wpdMonthList = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(wpdEbId)).collect(Collectors.toList()); if (!wpdMonthList.isEmpty()) { aveWpd = wpdMonthList.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(wpdMonthList.size()), 2, RoundingMode.HALF_UP); } } dataMap.put("height", height); dataMap.put("deletionCount", deletionCount); // dataMap.put("freezeCount", 0);//结冰数据 // dataMap.put("abnormalCount", 0);//异常数据 // dataMap.put("lowDataQualityCount", 0);//质量低数据 dataMap.put("integrityRate", integrityRate); // dataMap.put("efficiency", integrityRate);//有效率 dataMap.put("ws", aveWs); dataMap.put("maxWs", maxWs); dataMap.put("tur", aveTur); dataMap.put("power", aveWpd); dataList.add(dataMap); } /*环境数据*/ //从数据库属性表里查出环境数据的属性 List paMax = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("paMAX")).collect(Collectors.toList()); List paMin = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("paMIN")).collect(Collectors.toList()); List paAve = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("paAVE")).collect(Collectors.toList()); List rhMax = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("rhMAX")).collect(Collectors.toList()); List rhMin = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("rhMIN")).collect(Collectors.toList()); List rhAve = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("rhAVE")).collect(Collectors.toList()); List tMax = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("tMAX")).collect(Collectors.toList()); List tMin = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("tMIN")).collect(Collectors.toList()); List tAve = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("tAVE")).collect(Collectors.toList()); List airDensityAve = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals("airDensityMonth")).collect(Collectors.toList()); //通过属性过滤数据 List paMaxData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(paMax.get(0).getId())).collect(Collectors.toList()); List paMinData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(paMin.get(0).getId())).collect(Collectors.toList()); List paAveData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(paAve.get(0).getId())).collect(Collectors.toList()); List rhMaxData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(rhMax.get(0).getId())).collect(Collectors.toList()); List rhMinData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(rhMin.get(0).getId())).collect(Collectors.toList()); List rhAveData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(rhAve.get(0).getId())).collect(Collectors.toList()); List tMaxData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(tMax.get(0).getId())).collect(Collectors.toList()); List tMinData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(tMin.get(0).getId())).collect(Collectors.toList()); List tAveData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(tAve.get(0).getId())).collect(Collectors.toList()); List airDensityAveData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(airDensityAve.get(0).getId())).collect(Collectors.toList()); //做平均值 BigDecimal paMaxDataMax = paMaxData.stream().map(WindTowerCalculationData::getValue).max((x1, x2) -> x1.compareTo(x2)).get(); BigDecimal paMinDataMin = paMinData.stream().map(WindTowerCalculationData::getValue).min((x1, x2) -> x1.compareTo(x2)).get(); BigDecimal paAveDataAge = paAveData.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(paAveData.size()), 2, RoundingMode.HALF_UP); BigDecimal rhMaxDataMax = rhMaxData.stream().map(WindTowerCalculationData::getValue).max((x1, x2) -> x1.compareTo(x2)).get(); BigDecimal rhMinDataMin = rhMinData.stream().map(WindTowerCalculationData::getValue).min((x1, x2) -> x1.compareTo(x2)).get(); BigDecimal rhAveDataAge = rhAveData.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(rhAveData.size()), 2, RoundingMode.HALF_UP); BigDecimal tMaxDataMax = tMaxData.stream().map(WindTowerCalculationData::getValue).max((x1, x2) -> x1.compareTo(x2)).get(); BigDecimal tMinDataMin = tMinData.stream().map(WindTowerCalculationData::getValue).min((x1, x2) -> x1.compareTo(x2)).get(); BigDecimal tAveDataAge = tAveData.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(tAveData.size()), 2, RoundingMode.HALF_UP); BigDecimal airDensityAveDataAge = airDensityAveData.stream().map(WindTowerCalculationData::getValue).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(airDensityAveData.size()), 2, RoundingMode.HALF_UP); //放到list里 List> environmentData = new ArrayList<>(); Map paMap = new HashMap<>(); paMap.put("parameter", "气压(hpa)"); paMap.put("min", paMinDataMin); paMap.put("max", paMaxDataMax); paMap.put("ave", paAveDataAge); Map rhMap = new HashMap<>(); rhMap.put("parameter", "湿度(RH)"); rhMap.put("min", rhMinDataMin.compareTo(new BigDecimal(0)) == 0 ? "--" : rhMinDataMin); rhMap.put("max", rhMaxDataMax.compareTo(new BigDecimal(0)) == 0 ? "--" : rhMaxDataMax); rhMap.put("ave", rhAveDataAge.compareTo(new BigDecimal(0)) == 0 ? "--" : rhAveDataAge); Map tMap = new HashMap<>(); tMap.put("parameter", "气温(°C)"); tMap.put("min", tMinDataMin); tMap.put("max", tMaxDataMax); tMap.put("ave", tAveDataAge); Map airDensityMap = new HashMap<>(); airDensityMap.put("parameter", "空气密度(kg/m³)"); airDensityMap.put("min", airDensityAveDataAge.multiply(BigDecimal.valueOf(0.8))); airDensityMap.put("max", airDensityAveDataAge.multiply(BigDecimal.valueOf(1.2))); airDensityMap.put("ave", airDensityAveDataAge); environmentData.add(paMap); environmentData.add(rhMap); environmentData.add(tMap); environmentData.add(airDensityMap); map.put("dataList", dataList); map.put("environment", environmentData); } catch (Exception e) { e.printStackTrace(); } return map; } /** * 测风塔数据时间范围 * * @return */ public List> getDataTime() { List windTowerInfoList = windTowerInfoService.list(); ArrayList> timeList = new ArrayList<>(); for (WindTowerInfo windTowerInfo : windTowerInfoList) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); HashMap hashMap = new HashMap<>(); Map startAndEnd = prophaseWeatherDataService.getDataTimeStartAndEnd(windTowerInfo.getEquipmentNo()); hashMap.put("time", sdf.format(new Date(startAndEnd.get("startTime"))) + " - " + sdf.format(new Date(startAndEnd.get("endTime")))); hashMap.put("eqId", windTowerInfo.getEquipmentNo()); timeList.add(hashMap); } return timeList; } /** * 测风塔数据时间范围 * * @return */ public List> getDataTimeForEveryTower() { List windTowerInfoList = windTowerInfoService.list(); List collect = windTowerInfoList.stream().sorted(Comparator.comparing(WindTowerInfo::getEquipmentNo)).collect(Collectors.toList()); ArrayList> timeList = new ArrayList<>(); for (WindTowerInfo windTowerInfo : collect) { HashMap hashMap = new HashMap<>(); Map startAndEnd = prophaseWeatherDataService.getDataTimeStartAndEnd(windTowerInfo.getEquipmentNo()); //获取去年数据截止的时间 Date yearDay = DateTimeUtil.getYearDay(startAndEnd.get("endTime")); Date startTime; if (startAndEnd.get("startTime") < yearDay.getTime()) { startTime = DateUtil.offsetMonth(yearDay, 1); } else { startTime = new Date(startAndEnd.get("startTime")); } hashMap.put("startTime", startTime); hashMap.put("endTime", new Date(startAndEnd.get("endTime"))); hashMap.put("eqId", windTowerInfo.getEquipmentNo()); timeList.add(hashMap); } return timeList; } /** * 风速和风功率密度时间曲线图 * * @param * @return map */ public Map getWsAndWpd(List windTowerCalculationDataList, List equipmentAttributeList, String height, Date startDay, Date endDay) { Map map = new HashMap<>(); try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 根据设备属性表中的属性作用查询 List wsDayAttList = equipmentAttributeList.stream().filter(e -> "wsDay".equals(e.getAttributeFunction())).collect(Collectors.toList()); List wpdMonthAttList = equipmentAttributeList.stream().filter(e -> "WindPowerDensity".equals(e.getAttributeFunction())).collect(Collectors.toList()); // 一年的计算数据 String wsFieldName = height + "awsDay"; String wpdFieldName = height + "wpdDay"; // 过滤属性集合找对应的属性id List wsDayAtt = wsDayAttList.stream().filter(w -> w.getFieldName().equals(wsFieldName)).collect(Collectors.toList()); String wsEbId = wsDayAtt.get(0).getId(); List wpdMonthAtt = wpdMonthAttList.stream().filter(w -> w.getFieldName().equals(wpdFieldName)).collect(Collectors.toList()); String wpdEbId = wpdMonthAtt.get(0).getId(); // 过滤一周数据 List> wsDataList = new ArrayList<>(); List> wpdDataList = new ArrayList<>(); for (Long l = startDay.getTime(); l <= endDay.getTime(); l += 86400000L) { Date finalL = DateTimeUtil.getDayStartTime(l); List wsList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(wsEbId) && w.getTime().equals(finalL)).collect(Collectors.toList()); List list = new ArrayList<>(); if (!wsList.isEmpty()) { list.add(sdf.format(wsList.get(0).getTime())); list.add(wsList.get(0).getValue()); wsDataList.add(list); } else { list.add(sdf.format(new Date(l))); list.add(new BigDecimal(0)); wsDataList.add(list); } List wpdList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(wpdEbId) && w.getTime().equals(finalL)).collect(Collectors.toList()); List listWpd = new ArrayList<>(); if (!wpdList.isEmpty()) { listWpd.add(sdf.format(wpdList.get(0).getTime())); listWpd.add(wpdList.get(0).getValue()); wpdDataList.add(listWpd); } else { listWpd.add(sdf.format(new Date(l))); listWpd.add(new BigDecimal(0)); wpdDataList.add(listWpd); } } map.put("ws", wsDataList); map.put("wpd", wpdDataList); } catch (Exception e) { e.printStackTrace(); } return map; } /** * 风速和风速标准差时间曲线图 * * @param windTowerCalculationDataList 统计数据 * @param equipmentAttributeList 属性数据 * @param height 层高 * @return */ public Map wsAndWsSta(List windTowerCalculationDataList, List equipmentAttributeList, String height, Date startDay, Date endDay) { // long yesterday = new Date().getTime() - 1000 * 60 * 60 * 24;//昨天 // Date startTime = DateTimeUtil.getDayStartTime(DateTimeUtil.getYearDay(yesterday).getTime()); // Date endTime = DateTimeUtil.getDayLastTime(yesterday); // List dateTime = DateTimeUtil.getIntervalTimeByMonth(DateTimeUtil.beginOfMonth(startTime), DateTimeUtil.beginOfMonth(endTime)); Map map = new HashMap<>(); try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 根据设备属性表中的属性作用查询 String wsFieldName = height + "awsDay"; // 过滤属性集合找对应的属性id List wsDayAtt = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals(wsFieldName)).collect(Collectors.toList()); String wsEbId = wsDayAtt.get(0).getId(); //取出heigth层高的平均风速标差属性 String staEbId = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "staDay")).collect(Collectors.toList()).get(0).getId(); List> wsDataList = new ArrayList<>(); List> wsStaDataList = new ArrayList<>(); for (Long l = startDay.getTime(); l <= endDay.getTime(); l += 86400000L) { Date finalL = DateTimeUtil.getDayStartTime(l); List wsList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(wsEbId) && w.getTime().equals(finalL)).collect(Collectors.toList()); List list = new ArrayList<>(); if (!wsList.isEmpty()) { list.add(sdf.format(wsList.get(0).getTime())); list.add(wsList.get(0).getValue()); wsDataList.add(list); } else { list.add(sdf.format(new Date(l))); list.add(new BigDecimal(0)); wsDataList.add(list); } //计算风速标准差 List wsStaList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(staEbId) && w.getTime().equals(finalL)).collect(Collectors.toList()); //取出这个层高所有的数据 list = new ArrayList<>(); if (!wsStaList.isEmpty()) { list.add(sdf.format(wsStaList.get(0).getTime())); list.add(wsStaList.get(0).getValue()); wsStaDataList.add(list); } else { list.add(sdf.format(new Date(l))); list.add(BigDecimal.ZERO); wsStaDataList.add(list); } } map.put("ws", wsDataList); map.put("wsSta", wsStaDataList); } catch (Exception e) { e.printStackTrace(); } return map; } /** * 风速和风速密度日变化 * * @param height * @return map */ public Map getWindPowerDensityAndAverageWindSpeed(List windTowerCalculationDataList, List equipmentAttributeList, List windTowerInfos, String height) { Map map = new HashMap<>(); try { String wpdFieldName = height + "wpd"; String awsFieldName = height + "aws"; List wpdFieldNameList = equipmentAttributeList.stream().filter(e -> wpdFieldName.equals(e.getFieldName())).collect(Collectors.toList()); List awsFieldNameList = equipmentAttributeList.stream().filter(e -> awsFieldName.equals(e.getFieldName())).collect(Collectors.toList()); if (!wpdFieldNameList.isEmpty() && !awsFieldNameList.isEmpty()) { String wpdEbId = wpdFieldNameList.get(0).getId(); String awsEbId = awsFieldNameList.get(0).getId(); //平均风速集合 List awsList; //风功率密度集合 List wpdList; awsList = windTowerCalculationDataList.stream().filter(w -> awsEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); wpdList = windTowerCalculationDataList.stream().filter(w -> wpdEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); if (!awsList.isEmpty()) { map.put("AverageWindSpeed", CalculationUtil.getData24(awsList)); } if (!wpdList.isEmpty()) { map.put("WindPowerDensity", CalculationUtil.getData24(wpdList)); } } map.put("table", getWpdTable(windTowerCalculationDataList, equipmentAttributeList, windTowerInfos)); } catch (Exception e) { e.printStackTrace(); } return map; } /** * 风速和风速密度日变化表格 * * @return map */ public Map getWpdTable(List windTowerCalculationDataList, List equipmentAttributeList, List windTowerInfos) { Map map = new HashMap<>(); List> list = new ArrayList<>(); try { String height; height = windTowerInfos.get(0).getHeights(); if (height == null || height.equals("")) { height = "10,30,50,60,70,80,90,100,110,120,140,150"; } String[] heightAll = height.split(","); List tableHeader = new ArrayList<>(); tableHeader.add("时间"); for (String str : heightAll) { List wsDataList = new ArrayList<>(); List wpdDataList = new ArrayList<>(); tableHeader.add(str + "m风速(m/s)"); tableHeader.add(str + "m风功率密度(w/㎡)"); String wpdFieldName = str + "wpd"; String awsFieldName = str + "aws"; List wpdFieldNameList = equipmentAttributeList.stream().filter(e -> wpdFieldName.equals(e.getFieldName())).collect(Collectors.toList()); List awsFieldNameList = equipmentAttributeList.stream().filter(e -> awsFieldName.equals(e.getFieldName())).collect(Collectors.toList()); //选择时间段的平均风速 BigDecimal avgWs = new BigDecimal(0); //选择时间段的风功率密度 BigDecimal avgWpd = new BigDecimal(0); if (!wpdFieldNameList.isEmpty() && !awsFieldNameList.isEmpty()) { String wpdEbId = wpdFieldNameList.get(0).getId(); String awsEbId = awsFieldNameList.get(0).getId(); //平均风速集合 List awsList; //风功率密度集合 List wpdList; awsList = windTowerCalculationDataList.stream().filter(w -> awsEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); wpdList = windTowerCalculationDataList.stream().filter(w -> wpdEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); if (!awsList.isEmpty()) { BigDecimal wsSum = new BigDecimal(0); for (WindTowerCalculationData data : awsList) { wsSum = wsSum.add(data.getValue()); } //如何总和不为0 if (wsSum.compareTo(new BigDecimal(0)) != 0) { avgWs = wsSum.divide(new BigDecimal(awsList.size()), 2, RoundingMode.HALF_UP); } wsDataList = getData24(awsList); wsDataList.add(avgWs); } if (!wpdList.isEmpty()) { BigDecimal wpdSum = new BigDecimal(0); for (WindTowerCalculationData data : wpdList) { wpdSum = wpdSum.add(data.getValue()); } //如何总和不为0 if (wpdSum.compareTo(new BigDecimal(0)) != 0) { avgWpd = wpdSum.divide(new BigDecimal(wpdList.size()), 2, RoundingMode.HALF_UP); } wpdDataList = getData24(wpdList); wpdDataList.add(avgWpd); } } list.add(wsDataList); list.add(wpdDataList); } map.put("tableHeader", tableHeader); map.put("data", list); } catch (Exception e) { e.printStackTrace(); } return map; } /** * 风速和风速密度各月日变化 * * @param height * @return map */ public List> getMonthWsAndWpd(List windTowerCalculationDataList, List equipmentAttributeList, String height, Date startDay, Date endDay) { List> list = new ArrayList<>(); try { SimpleDateFormat sdf = new SimpleDateFormat("M"); String wpdFieldName = height + "wpd"; String awsFieldName = height + "aws"; List wpdFieldNameList = equipmentAttributeList.stream().filter(e -> wpdFieldName.equals(e.getFieldName())).collect(Collectors.toList()); List awsFieldNameList = equipmentAttributeList.stream().filter(e -> awsFieldName.equals(e.getFieldName())).collect(Collectors.toList()); List nullList = new ArrayList<>(); if (!wpdFieldNameList.isEmpty() && !awsFieldNameList.isEmpty()) { String wpdEbId = wpdFieldNameList.get(0).getId(); String awsEbId = awsFieldNameList.get(0).getId(); List awsAllList = windTowerCalculationDataList.stream().filter(w -> awsEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); List wpdAllList = windTowerCalculationDataList.stream().filter(w -> wpdEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); List intervalTimeByMonth = DateTimeUtil.getIntervalTimeByMonth(startDay, endDay); for (int i = 1; i <= 12; i++) { //平均风速集合 List awsList = new ArrayList<>(); //风功率密度集合 List wpdList = new ArrayList<>(); Map dataMap = new HashMap<>(); for (Long l : intervalTimeByMonth) { //判断月份是否相等 if (String.valueOf(i).equals(sdf.format(new Date(l)))) { Date monthStartTime = DateTimeUtil.beginOfMonth(new Date(l)); Date monthendTime = DateTimeUtil.endOfMonth(new Date(l)); awsList = awsAllList.stream().filter(w -> w.getTime().compareTo(monthStartTime) >= 0 && w.getTime().compareTo(monthendTime) < 0).collect(Collectors.toList()); wpdList = wpdAllList.stream().filter(w -> w.getTime().compareTo(monthStartTime) >= 0 && w.getTime().compareTo(monthendTime) < 0).collect(Collectors.toList()); } } if (!awsList.isEmpty()) { dataMap.put("ws", CalculationUtil.getData24(awsList)); } else { dataMap.put("ws", nullList); } if (!wpdList.isEmpty()) { dataMap.put("wpd", CalculationUtil.getData24(wpdList)); } else { dataMap.put("wpd", nullList); } dataMap.put("time", i + "月"); list.add(dataMap); } } } catch (Exception e) { e.printStackTrace(); } return list; } /** * 风速和风速密度年变化曲线 * * @return map */ public Map getYearWsAndWpd(List windTowerCalculationDataList, List equipmentAttributeList, String height, Date startDay, Date endDay) { Map map = new HashMap<>(); try { // Long yesterday = new Date().getTime() - 1000 * 60 * 60 * 24;//昨天 // Date startTime = DateTimeUtil.getDayStartTime(DateTimeUtil.getYearDay(yesterday).getTime());//报告的开始时间 一年前的昨天的00:00:00 // Date endTime = DateTimeUtil.getDayLastTime(yesterday);//报告的结束时间 昨天的23:59:59 /*设备属性信息*/ String wpdFieldName = height + "wpdMonth"; //wpdMonth awsDay String awsFieldName = height + "awsMonth"; List wpdFieldNameList = equipmentAttributeList.stream().filter(e -> wpdFieldName.equals(e.getFieldName())).collect(Collectors.toList()); List awsFieldNameList = equipmentAttributeList.stream().filter(e -> awsFieldName.equals(e.getFieldName())).collect(Collectors.toList()); List wsDataList = new ArrayList<>(); List wpdDataList = new ArrayList<>(); List timeList = new ArrayList<>(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); if (!wpdFieldNameList.isEmpty() && !awsFieldNameList.isEmpty()) { String wpdEbId = wpdFieldNameList.get(0).getId(); String awsEbId = awsFieldNameList.get(0).getId(); //平均风速集合 List awsAllList = new ArrayList<>(); //风功率密度集合 List wpdAllList = new ArrayList<>(); awsAllList = windTowerCalculationDataList.stream().filter(w -> awsEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); wpdAllList = windTowerCalculationDataList.stream().filter(w -> wpdEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); List timeByMonth = DateTimeUtil.getIntervalTimeByMonth(startDay, endDay); for (Long aLong : timeByMonth) { BigDecimal avgWs = new BigDecimal(0); BigDecimal avgWpd = new BigDecimal(0); //过滤平均风速集合 List awsList = new ArrayList<>(); //过滤风功率密度集合 List wpdList = new ArrayList<>(); // awsList = awsAllList.stream().filter(w -> w.getTime().compareTo(monthStartTime) >= 0 && w.getTime().compareTo(monthendTime) < 0 && w.getValue() != null && w.getValue().compareTo(new BigDecimal(-99)) != 0).collect(Collectors.toList()); awsList = awsAllList.stream().filter(w -> w.getTime().equals(new Date(aLong)) && w.getValue() != null && w.getValue().compareTo(new BigDecimal(-99)) != 0).collect(Collectors.toList()); wpdList = wpdAllList.stream().filter(w -> w.getTime().equals(new Date(aLong)) && w.getValue() != null && w.getValue().compareTo(new BigDecimal(-99)) != 0).collect(Collectors.toList()); if (!awsList.isEmpty()) { List valueList = awsList.stream().map(WindTowerCalculationData::getValue).collect(Collectors.toList()); avgWs = valueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(valueList.size()), 2, RoundingMode.HALF_UP); } wsDataList.add(avgWs); if (!wpdList.isEmpty()) { List valueList = wpdList.stream().map(WindTowerCalculationData::getValue).collect(Collectors.toList()); avgWpd = valueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(valueList.size()), 2, RoundingMode.HALF_UP); } wpdDataList.add(avgWpd); timeList.add(sdf.format(aLong)); } } map.put("wsList", wsDataList); map.put("wpdList", wpdDataList); map.put("time", timeList); } catch (Exception e) { e.printStackTrace(); } return map; } /** * 风速和风速密度各月日变化表格 * * @return map */ public Map getMonthWpdTable(List windTowerCalculationDataList, List equipmentAttributeList, List windTowerInfos, Date startDay, Date endDay) { Map map = new HashMap<>(); List> list = new ArrayList<>(); List timeList = new ArrayList<>(); try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); List timeByMonth = DateTimeUtil.getIntervalTimeByMonth(startDay, endDay); for (Long aLong : timeByMonth) { Date monthStartTime = DateTimeUtil.getDayStartTime(aLong); timeList.add(sdf.format(monthStartTime)); } timeList.add("平均"); //获取风速层高 String height; height = windTowerInfos.get(0).getHeights(); if (height == null || height.equals("")) { height = "10,30,50,60,70,80,90,100,110,120,140,150"; } String[] heightAll = height.split(","); List tableHeader = new ArrayList<>(); tableHeader.add("月份"); for (String str : heightAll) { List wsDataList = new ArrayList<>(); List wpdDataList = new ArrayList<>(); tableHeader.add(str + "m风速(m/s)"); tableHeader.add(str + "m风功率密度(w/㎡)"); String wpdFieldName = str + "wpdMonth"; //wpdMonth awsDay String awsFieldName = str + "awsMonth"; List wpdFieldNameList = equipmentAttributeList.stream().filter(e -> wpdFieldName.equals(e.getFieldName())).collect(Collectors.toList()); List awsFieldNameList = equipmentAttributeList.stream().filter(e -> awsFieldName.equals(e.getFieldName())).collect(Collectors.toList()); BigDecimal sumAveWs = new BigDecimal(0); BigDecimal sumAveWpd = new BigDecimal(0); if (!wpdFieldNameList.isEmpty() && !awsFieldNameList.isEmpty()) { String wpdEbId = wpdFieldNameList.get(0).getId(); String awsEbId = awsFieldNameList.get(0).getId(); //平均风速集合 List awsAllList; //风功率密度集合 List wpdAllList; awsAllList = windTowerCalculationDataList.stream().filter(w -> awsEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); wpdAllList = windTowerCalculationDataList.stream().filter(w -> wpdEbId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); for (Long aLong : timeByMonth) { BigDecimal avgWs = new BigDecimal(0); BigDecimal avgWpd = new BigDecimal(0); //过滤平均风速集合 List awsList; //过滤风功率密度集合 List wpdList; awsList = awsAllList.stream().filter(w -> w.getTime().equals(new Date(aLong))).collect(Collectors.toList()); wpdList = wpdAllList.stream().filter(w -> w.getTime().equals(new Date(aLong))).collect(Collectors.toList()); if (!awsList.isEmpty()) { List valueList = awsList.stream().map(WindTowerCalculationData::getValue).collect(Collectors.toList()); avgWs = valueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(valueList.size()), 2, RoundingMode.HALF_UP); } wsDataList.add(avgWs); if (!wpdList.isEmpty()) { List valueList = wpdList.stream().map(WindTowerCalculationData::getValue).collect(Collectors.toList()); avgWpd = valueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(valueList.size()), 2, RoundingMode.HALF_UP); } wpdDataList.add(avgWpd); } int wsListCount = wsDataList.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList()).size(); int wpdListCount = wpdDataList.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList()).size(); if (wsListCount != 0) { sumAveWs = wsDataList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(wsListCount), 2, RoundingMode.HALF_UP); } if (wpdListCount != 0) { sumAveWpd = wpdDataList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(wpdListCount), 2, RoundingMode.HALF_UP); } wsDataList.add(sumAveWs); wpdDataList.add(sumAveWpd); } list.add(wsDataList); list.add(wpdDataList); } map.put("tableHeader", tableHeader); map.put("data", list); map.put("month", timeList); } catch (Exception e) { e.printStackTrace(); } return map; } /** * pdf威布尔 * * @param height 层高 * @return weibull */ public Map pdfWeibull(List equipmentAttributeList, String equipmentId, List windTowerCalculationDataList, String height) { Map map = new HashMap<>(); List wsList = new ArrayList<>(); try { double e = 2.71828183; // 风速集合 String ebId = equipmentAttributeList.stream().filter(w -> w.getFieldName().equals(height + "aws")).collect(Collectors.toList()).get(0).getId(); List calculationDataList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(ebId)).collect(Collectors.toList()); for (WindTowerCalculationData w : calculationDataList) { wsList.add(w.getValue()); } TreeMap> wsMap = new TreeMap<>(); if (!wsList.isEmpty()) { ArrayList arrayWsList = new ArrayList<>(wsList); //把风速集合传入,计算A、K ProbabilityPlot probabilityPlot = new ProbabilityPlot(arrayWsList); probabilityPlot.suppressDisplay(); double K = probabilityPlot.weibullTwoParGamma(); double A = probabilityPlot.weibullTwoParSigma(); map.put("K", BigDecimal.valueOf(K).setScale(2, RoundingMode.HALF_UP).doubleValue()); map.put("A", BigDecimal.valueOf(A).setScale(2, RoundingMode.HALF_UP).doubleValue()); BigDecimal wsAve = wsList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(wsList.size()), 2, RoundingMode.HALF_UP); map.put("wsAve", wsAve); /*根据风速过滤出风速区间集合*/ for (BigDecimal ws : wsList) { // 风速区间 BigDecimal speedLevel = BigDecimal.valueOf(Math.ceil(ws.subtract(BigDecimal.valueOf(0.5)).doubleValue())); if (wsMap.containsKey(speedLevel)) { wsMap.get(speedLevel).add(ws); } else { wsMap.put(speedLevel, new ArrayList<>()); wsMap.get(speedLevel.setScale(1, RoundingMode.HALF_UP)).add(ws); } } /*风速频率*/ List> wsFreList = new ArrayList<>(); /*威布尔*/ List> weibullList = new ArrayList<>(); wsMap.forEach((key, val) -> { List list = new ArrayList<>(); List tempList = new ArrayList<>(); BigDecimal wsFrequency = new BigDecimal(val.size()).divide(new BigDecimal(wsList.size()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); list.add(key.setScale(0, RoundingMode.HALF_UP)); list.add(wsFrequency); wsFreList.add(list); /*区间威布尔累加求和求平均值*/ BigDecimal aveWs = val.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(val.size()), 2, RoundingMode.HALF_UP); BigDecimal weibull = CalculationUtil.getBigDecimal(e, aveWs.doubleValue(), K, A); tempList.add(key.setScale(0, RoundingMode.HALF_UP)); tempList.add(weibull); weibullList.add(tempList); }); map.put("wsFrequency", wsFreList); map.put("weibull", weibullList); } } catch (Exception e) { e.printStackTrace(); } return map; } /** * 一年玫瑰图 * * @param height 层高 * @return * @throws Exception */ public Map roseCharts(List windDirectionStatisticsData, List equipmentAttributeList, String height) { Map map = new HashMap<>(); try { // 若层高包含A按照去掉A的层高计算 if (height.contains("A")) { height = height.substring(0, height.length() - 1); } map.put("wd", getwd(windDirectionStatisticsData, equipmentAttributeList, height)); map.put("power", getPower(windDirectionStatisticsData, equipmentAttributeList, height)); } catch (Exception e) { e.printStackTrace(); } return map; } /** * 各月玫瑰图 * * @param height 层高 * @return * @throws Exception */ public Map getMonthRoseCharts(List windDirectionStatisticsData, List equipmentAttributeList, String height) { Map map = new HashMap<>(); List> wdList = new ArrayList<>(); List> powerList = new ArrayList<>(); SimpleDateFormat monthSdf = new SimpleDateFormat("M"); try { // 若层高包含A按照去掉A的层高计算 if (height.contains("A")) { height = height.substring(0, height.length() - 1); } for (int i = 1; i <= 12; i++) { Map wdMap = new HashMap<>(); Map powerMap = new HashMap<>(); // Date monthStartTime = DateTimeUtil.getDayStartTime(DateTimeUtil.mouthOneDay(i).getTime()); // Date monthendTime = DateTimeUtil.getDayLastTime(DateTimeUtil.mouthLastDay(i).getTime()); //过滤时间区间集合 List filterList = new ArrayList<>(); // filterList = windDirectionStatisticsData.stream().filter(w -> w.getTime().compareTo(monthStartTime) >= 0 && w.getTime().compareTo(monthendTime) < 0).collect(Collectors.toList()); int finalI = i; filterList = windDirectionStatisticsData.stream().filter(w -> monthSdf.format(w.getTime()).equals(String.valueOf(finalI))).collect(Collectors.toList()); wdMap.put("time", i + "月"); powerMap.put("time", i + "月"); //如果月份数据为空就放null if (!filterList.isEmpty()) { List> getwd = getwd(filterList, equipmentAttributeList, height); wdMap.put("data", getwd); powerMap.put("data", getPower(filterList, equipmentAttributeList, height)); } else { wdMap.put("data", null); powerMap.put("data", null); } wdList.add(wdMap); powerList.add(powerMap); } map.put("wd", wdList); map.put("power", powerList); } catch (Exception e) { e.printStackTrace(); } return map; } /*风向玫瑰图数据*/ public List> getwd(List windDirectionStatisticsData, List equipmentAttributeList, String height) { List> list = new ArrayList<>(); String wdFieldName = height + "monthWdRose"; // 过滤获取ebId List wdEquipmentAttribute = equipmentAttributeList.stream().filter(e -> wdFieldName.equals(e.getFieldName())).collect(Collectors.toList()); // 获取风向统计数据 List wdList = windDirectionStatisticsData.stream().filter(e -> e.getEbId().equals(wdEquipmentAttribute.get(0).getId())).collect(Collectors.toList()); /*玫瑰图风向枚举*/ for (WindDirectionEnum value : WindDirectionEnum.values()) { Map wdMap = new HashMap<>(); // 根据风向过滤统计表 List filterWdList = wdList.stream().filter(e -> e.getDirection().equals(value.name())).collect(Collectors.toList()); // 提取过滤的value值 List filterwdValueList = filterWdList.stream().map(WindDirectionStatisticsData::getValue).filter(w -> w != null).collect(Collectors.toList()); // 累加保留两位小数 BigDecimal sumWd = null; if (!filterwdValueList.isEmpty()) { sumWd = filterwdValueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP); } wdMap.put(value.name(), sumWd); list.add(wdMap); } return list; } /*风能玫瑰图数据*/ public List> getPower(List windDirectionStatisticsData, List equipmentAttributeList, String height) { List> list = new ArrayList<>(); String powerFieldName = height + "monthPowerRose"; // 过滤获取ebId List powerEquipmentAttribute = equipmentAttributeList.stream().filter(e -> powerFieldName.equals(e.getFieldName())).collect(Collectors.toList()); // 获取风向统计数据 List powerList = windDirectionStatisticsData.stream().filter(e -> e.getEbId().equals(powerEquipmentAttribute.get(0).getId())).collect(Collectors.toList()); /*玫瑰图风向枚举*/ for (WindDirectionEnum value : WindDirectionEnum.values()) { Map powerMap = new HashMap<>(); // 根据风向过滤统计表 List filterPowerList = powerList.stream().filter(e -> e.getDirection().equals(value.name())).collect(Collectors.toList()); // 提取过滤的value值 List filterPowerValueList = filterPowerList.stream().map(WindDirectionStatisticsData::getValue).filter(w -> w != null).collect(Collectors.toList()); // 累加保留两位小数 BigDecimal sumPower = null; if (!filterPowerValueList.isEmpty()) { sumPower = filterPowerValueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP); } powerMap.put(value.name(), sumPower); list.add(powerMap); } return list; } /** * 空气密度 * * @return * @throws Exception */ public Map getAirDensity(List windTowerCalculationDatas, List equipmentAttributeList, Date startDay, Date endDay) { Map map = new HashMap<>(); List timeList = new ArrayList<>(); List monthTimeList = new ArrayList<>(); List tList = new ArrayList<>(); List paList = new ArrayList<>(); try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); List tAVE = equipmentAttributeList.stream().filter(e -> "tDay".equals(e.getFieldName())).collect(Collectors.toList()); List paAVE = equipmentAttributeList.stream().filter(e -> "paDay".equals(e.getFieldName())).collect(Collectors.toList()); List airDensityMonth = equipmentAttributeList.stream().filter(e -> "airDensityMonth".equals(e.getFieldName())).collect(Collectors.toList()); List airDensityDayForYear = equipmentAttributeList.stream().filter(e -> "airDensityDayForYear".equals(e.getFieldName())).collect(Collectors.toList()); List tAVEData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(tAVE.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); List paAVEData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(paAVE.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); List airDensityMonthData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(airDensityMonth.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); List airDensityDayForYearData = windTowerCalculationDatas.stream().filter(w -> w.getEbId().equals(airDensityDayForYear.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); /*温度气压曲线*/ //补点做法 for (Long l = startDay.getTime(); l <= endDay.getTime(); l += 86400000L) { Date finalL = DateUtil.beginOfDay(new Date(l)); String dates = sdf1.format(finalL); List collect = tAVEData.stream().filter(t -> sdf1.format(t.getTime()).equals(dates)).collect(Collectors.toList()); if (!collect.isEmpty()) { tList.add(collect.get(0).getValue()); } else { tList.add(null); } List collect1 = paAVEData.stream().filter(p -> sdf1.format(p.getTime()).equals(dates)).collect(Collectors.toList()); if (!collect1.isEmpty()) { paList.add(collect1.get(0).getValue()); } else { paList.add(null); } timeList.add(sdf.format(finalL)); } map.put("time", timeList); map.put("t", tList); map.put("pa", paList); // //月平均温度 // for (WindTowerCalculationData w : tAVEData) { // timeList.add(sdf.format(w.getTime())); // tList.add(w.getValue()); // } // //月平均气压 // for (WindTowerCalculationData w : paAVEData) { // paList.add(w.getValue()); // } // map.put("time", timeList); // map.put("t", tList); // map.put("pa", paList); /*空气密度日变化*/ List airDensityList = new ArrayList<>(); if (!airDensityDayForYearData.isEmpty()) { airDensityList = CalculationUtil.getData24(airDensityDayForYearData); } List airDensityCollect = airDensityList.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList()); BigDecimal ave24AirDensity = BigDecimal.ZERO; if (!airDensityCollect.isEmpty()) { ave24AirDensity = airDensityCollect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(24), 3, RoundingMode.HALF_UP); } map.put("dayAirDensity", airDensityList); map.put("aveDayAirDensity", ave24AirDensity); /*空气年变化*/ List monthList = new ArrayList<>(); SimpleDateFormat sdfMonth = new SimpleDateFormat("M"); for (int i = 1; i <= 12; i++) { // Date monthStartTime = DateTimeUtil.getDayStartTime(DateTimeUtil.mouthOneDay(i).getTime()); //过滤时间区间集合 List filterList = new ArrayList<>(); BigDecimal value = new BigDecimal(0); int finalI = i; filterList = airDensityMonthData.stream().filter(w -> sdfMonth.format(w.getTime()).equals(String.valueOf(finalI))).collect(Collectors.toList()); if (!filterList.isEmpty()) { value = filterList.get(0).getValue(); } monthList.add(value); monthTimeList.add(i + "月"); } // for (WindTowerCalculationData w : airDensityMonthData) { // monthTimeList.add(sdf.format(w.getTime())); // monthList.add(w.getValue()); // } List collect = monthList.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList()); BigDecimal yearAveAirDensity = new BigDecimal(0); if (!collect.isEmpty()) { yearAveAirDensity = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 3, RoundingMode.HALF_UP); } map.put("monthTime", monthTimeList); map.put("yearAirDensity", monthList); map.put("yearAveAirDensity", yearAveAirDensity); } catch (Exception e) { e.printStackTrace(); } return map; } /** * 获取风切变指数(风向玫瑰图) * * @param height */ public List> getWindShearRose(List windDirectionStatisticsData, List equipmentAttributeList, String height) { List> list = new ArrayList<>(); try { // 若层高包含A按照去掉A的层高计算 if (height.contains("A")) { height = height.substring(0, height.length() - 1); } String shearFieldName = height + "monthShearRose"; // 过滤获取ebId List shearEquipmentAttribute = equipmentAttributeList.stream().filter(e -> shearFieldName.equals(e.getFieldName())).collect(Collectors.toList()); // 获取风向统计数据 List shearList = windDirectionStatisticsData.stream().filter(e -> e.getEbId().equals(shearEquipmentAttribute.get(0).getId())).collect(Collectors.toList()); for (WindDirectionEnum value : WindDirectionEnum.values()) { Map map = new HashMap<>(); // 根据风向过滤统计表 List filterShearList = shearList.stream().filter(e -> e.getDirection().equals(value.name())).collect(Collectors.toList()); // 提取过滤的value值 List filterShearValueList = filterShearList.stream().map(WindDirectionStatisticsData::getValue).filter(w -> w != null).collect(Collectors.toList()); // 累加保留两位小数 BigDecimal sumShear = null; if (!filterShearValueList.isEmpty()) { sumShear = filterShearValueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP); } map.put(value.name(), sumShear); list.add(map); } } catch (Exception e) { e.printStackTrace(); } return list; } /** * 风切变日/年变化 * * @return * @throws Exception */ public Map getWindShear(List windTowerCalculationDataLists, List equipmentAttributeList, String height) { Map map = new HashMap<>(); try { List dayResults = new ArrayList<>();//日变化 List yearResults = new ArrayList<>();//年变化 List monthTimeList = new ArrayList<>(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH"); SimpleDateFormat sdf = new SimpleDateFormat("M"); String shearFieldName = "windShear"; List shearFieldNameList = equipmentAttributeList.stream().filter(e -> shearFieldName.equals(e.getFieldName())).collect(Collectors.toList()); if (!shearFieldNameList.isEmpty()) { String ebId = shearFieldNameList.get(0).getId(); //属性id //查询风切变 月平均数据 根据时间,层高,设备id 并根据时间升序排列 List windTowerCalculationDataList = windTowerCalculationDataLists.stream().filter(w -> ebId.equals(w.getEbId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); if (!windTowerCalculationDataList.isEmpty()) { /*日变化*/ long startTime1 = DateMomentUtil.getDayStartTime(DateUtils.addDays(new Date(), -1).getTime()); long endTime1 = startTime1 + 86399000L; for (long time = startTime1; time <= endTime1; time += 3600000L) { Long finalTime = time; String format = simpleDateFormat.format(finalTime); List collect = windTowerCalculationDataList.stream().filter(s -> simpleDateFormat.format(s.getTime()) .equals(format) && s.getValue() != null && s.getValue().compareTo(new BigDecimal(-99)) != 0) .map(WindTowerCalculationData::getValue).collect(Collectors.toList()); BigDecimal ave = new BigDecimal(0); if (!collect.isEmpty()) { ave = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 3, RoundingMode.HALF_UP); } dayResults.add(ave); } BigDecimal dayAve = new BigDecimal(0); if (!dayResults.isEmpty()) { dayAve = dayResults.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(24), 3, RoundingMode.HALF_UP); } map.put("dayShear", dayResults); map.put("aveDayShear", dayAve); /*年变化*/ for (int i = 1; i <= 12; i++) { //过滤时间区间集合 List filterList = new ArrayList<>(); BigDecimal yearShear = new BigDecimal(0); int finalI = i; filterList = windTowerCalculationDataList.stream().filter(w -> sdf.format(w.getTime()).equals(String.valueOf(finalI))).collect(Collectors.toList()); if (!filterList.isEmpty()) { List collect = filterList.stream().map(WindTowerCalculationData::getValue).collect(Collectors.toList()); yearShear = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 3, RoundingMode.HALF_UP); } yearResults.add(yearShear); monthTimeList.add(i + "月"); } BigDecimal aveYearShear = new BigDecimal(0); List collect = yearResults.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList()); if (!collect.isEmpty()) { aveYearShear = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 3, RoundingMode.HALF_UP); } map.put("monthTime", monthTimeList); map.put("yearShear", yearResults); map.put("aveYearShear", aveYearShear); } } } catch (Exception e) { e.printStackTrace(); } return map; } /** * 湍流曲线 * * @param height 层高 * @return * @throws Exception */ public List> getTurIntensityCharts(List windTowerCalculationDataList, List equipmentAttributeList, String height) { List> list = new ArrayList<>(); try { BigDecimal ws;//风速值 BigDecimal sta;//风速标准差 BigDecimal turInsity = new BigDecimal(0);//湍流值 String wsFieldName = height + "awsDay"; List wsDayAttList = equipmentAttributeList.stream().filter(e -> "wsDay".equals(e.getAttributeFunction())).collect(Collectors.toList()); // 过滤属性集合找对应的属性id List wsDayAtt = wsDayAttList.stream().filter(w -> w.getFieldName().equals(wsFieldName)).collect(Collectors.toList()); String wsEbId = wsDayAtt.get(0).getId(); //height层高的平均风速 List wsList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(wsEbId)).collect(Collectors.toList()); //取出heigth层高的平均风速标差属性 List equipmentAttributeList1 = equipmentAttributeList.stream().filter(e -> e.getFieldName().equals(height + "staDay")).collect(Collectors.toList()); //取出这个层高所有的数据 List staList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(equipmentAttributeList1.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); /*风速段-----方差数组*/ Map> turbulenceMap = new HashMap<>(); BigDecimal speedLevel; for (int i = 0; i < wsList.size(); i++) { try { ws = wsList.get(i).getValue(); if (i >= staList.size()) { break; } else { sta = staList.get(i).getValue(); } turInsity = sta.divide(ws, 2, RoundingMode.HALF_UP); //风速段 speedLevel = BigDecimal.valueOf(Math.ceil(ws.subtract(BigDecimal.valueOf(0.5)).doubleValue())); if (turbulenceMap.containsKey((speedLevel))) { turbulenceMap.get(speedLevel).add(turInsity); } else { turbulenceMap.put(speedLevel, new ArrayList<>()); turbulenceMap.get(speedLevel.setScale(1, RoundingMode.HALF_UP)).add(turInsity); } } catch (IndexOutOfBoundsException e) { log.error("PDF 湍流曲线计算异常:" + e); } } //利用treeMap排序 HashMap> turbulenceTreeMap = new HashMap<>(turbulenceMap); turbulenceTreeMap.forEach((key, val) -> { List tempList = new ArrayList<>(); BigDecimal turbulence = val.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(val.size()), 3, RoundingMode.HALF_UP); tempList.add(key.setScale(0, RoundingMode.HALF_UP)); tempList.add(turbulence); list.add(tempList); }); } catch (Exception e) { e.printStackTrace(); } return list; } /** * 湍流日/年变化 * * @return * @throws Exception */ public Map getTurIntensity(List windTowerCalculationDataList, List equipmentAttributeList, String height) { Map map = new HashMap<>(); try { List dayResults = new ArrayList<>();//日变化 List yearResults = new ArrayList<>();//年变化 List monthTimeList = new ArrayList<>(); SimpleDateFormat sdf = new SimpleDateFormat("M"); String wsFieldName = height + "turbulenceMonth"; String turFieldName = height + "turDayForMonth"; //height层高月平均湍流属性 List turbulenceMonth = equipmentAttributeList.stream().filter(e -> wsFieldName.equals(e.getFieldName())).collect(Collectors.toList()); //height层高 月逐时湍流属性 List turbulenceHourForMonth = equipmentAttributeList.stream().filter(e -> turFieldName.equals(e.getFieldName())).collect(Collectors.toList()); //height层高的月平均湍流集合 List turbulenceList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(turbulenceMonth.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); //height层高的月逐时湍流集合 List turbulenceHourForMonthList = windTowerCalculationDataList.stream().filter(w -> w.getEbId().equals(turbulenceHourForMonth.get(0).getId())).sorted(Comparator.comparing(WindTowerCalculationData::getTime)).collect(Collectors.toList()); /*日变化*/ if (!turbulenceHourForMonthList.isEmpty()) { dayResults = CalculationUtil.getData24(turbulenceHourForMonthList); } BigDecimal aveDayTurInsity = new BigDecimal(0); aveDayTurInsity = dayResults.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(24), 2, RoundingMode.HALF_UP); map.put("dayTurInsity", dayResults); map.put("aveDayTurInsity", aveDayTurInsity); /*年变化*/ // for (WindTowerCalculationData w : turbulenceList) { // yearResults.add(w.getValue()); // monthTimeList.add(sdf.format(w.getTime())); // } for (int i = 1; i <= 12; i++) { // Date monthStartTime = DateTimeUtil.getDayStartTime(DateTimeUtil.mouthOneDay(i).getTime()); //过滤时间区间集合 List filterList = new ArrayList<>(); BigDecimal value = new BigDecimal(0); int finalI = i; filterList = turbulenceList.stream().filter(w -> sdf.format(w.getTime()).equals(String.valueOf(finalI))).collect(Collectors.toList()); if (!filterList.isEmpty()) { value = filterList.get(0).getValue(); } yearResults.add(value); monthTimeList.add(i + "月"); } BigDecimal aveYearTurInsity = new BigDecimal(0); //过滤为0的数据 List collect = yearResults.stream().filter(w -> w.compareTo(new BigDecimal(0)) != 0).collect(Collectors.toList()); if (collect.size() > 0) { aveYearTurInsity = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 2, RoundingMode.HALF_UP); } map.put("yearTurInsity", yearResults); map.put("aveYearTurInsity", aveYearTurInsity); map.put("monthTime", monthTimeList); } catch (Exception e) { e.printStackTrace(); } return map; } /** * 获取湍流(风向玫瑰图) * * @param height */ public Map getTurIntensityRose(List windDirectionStatisticsData, List equipmentAttributeList, WindTowerInfo windTowerInfo, String height) { Map map = new HashMap<>(); try { // 若层高包含A按照去掉A的层高计算 if (height.contains("A")) { height = height.substring(0, height.length() - 1); } List> list = new ArrayList<>(); String turFieldName = height + "monthTurRose"; // 过滤获取ebId List turEquipmentAttribute = equipmentAttributeList.stream().filter(e -> turFieldName.equals(e.getFieldName())).collect(Collectors.toList()); // 获取风向统计数据 List turList = windDirectionStatisticsData.stream().filter(e -> e.getEbId().equals(turEquipmentAttribute.get(0).getId())).collect(Collectors.toList()); for (WindDirectionEnum value : WindDirectionEnum.values()) { Map roseMap = new HashMap<>(); // 根据风向过滤统计表 List filterTurList = turList.stream().filter(e -> e.getDirection().equals(value.name())).collect(Collectors.toList()); // 提取过滤的value值 List filterTurValueList = filterTurList.stream().map(WindDirectionStatisticsData::getValue).filter(w -> w != null).collect(Collectors.toList()); // 累加保留两位小数 BigDecimal sumtur = null; if (!filterTurValueList.isEmpty()) { sumtur = filterTurValueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP); } roseMap.put(value.name(), sumtur); list.add(roseMap); } List> aveTurbulenceIntensity; aveTurbulenceIntensity = getAveTurbulenceIntensity(windDirectionStatisticsData, equipmentAttributeList, windTowerInfo); map.put("turIntensity", list); map.put("aveTurIntensity", aveTurbulenceIntensity); } catch (Exception e) { e.printStackTrace(); } return map; } /** * 获取所有层高的平均湍流(风向玫瑰图) */ public List> getAveTurbulenceIntensity(List windDirectionStatisticsData, List equipmentAttributeList, WindTowerInfo windTowerInfo) { String heights; heights = windTowerInfo.getWdHeights(); if (heights == null || heights.equals("")) { heights = "10,30,50,60,70,80,90,100,110,120,140,150"; } String[] heightAll = heights.split(","); BigDecimal zero = new BigDecimal(0); List> list = new ArrayList<>(); for (WindDirectionEnum value : WindDirectionEnum.values()) { Map map = new HashMap<>(); List dataList = new ArrayList<>(); // 累加保留两位小数 BigDecimal sumtur = zero; BigDecimal sumCount = zero; BigDecimal aveTur = zero; for (String height : heightAll) { String turFieldName = height + "monthTurRose"; // 过滤获取ebId List turEquipmentAttribute = equipmentAttributeList.stream().filter(e -> turFieldName.equals(e.getFieldName())).collect(Collectors.toList()); // 获取风向统计数据 List turList = windDirectionStatisticsData.stream().filter(e -> e.getEbId().equals(turEquipmentAttribute.get(0).getId()) && e.getDirection().equals(value.name())).collect(Collectors.toList()); // 提取过滤的value值 List filterTurValueList = turList.stream().map(WindDirectionStatisticsData::getValue).filter(w -> w != null).collect(Collectors.toList()); if (!filterTurValueList.isEmpty()) { sumtur = sumtur.add(filterTurValueList.stream().reduce(BigDecimal.ZERO, BigDecimal::add)); sumCount = sumCount.add(BigDecimal.valueOf(filterTurValueList.size())); } } if (sumCount.compareTo(zero) != 0 && sumtur.compareTo(zero) != 0) { aveTur = sumtur.divide(sumCount, 2, RoundingMode.HALF_UP); } map.put(value.name(), aveTur); list.add(map); } return list; } /** * 封装逐小时数据集合 * * @param awsList 数据 * @return */ public List getData24(List awsList) { long hour = 3600000L; Date systemDate = new Date(); List results = new ArrayList<>(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH"); //获取昨日开始和结束时间 long startTime = DateMomentUtil.getDayStartTime(DateUtils.addDays(systemDate, -1).getTime()); long endTime = startTime + 86399000; for (long time = startTime; time <= endTime; time += hour) { Long finalTime = time; String format = simpleDateFormat.format(finalTime); List collect = awsList.stream().filter(s -> simpleDateFormat.format(s.getTime()) .equals(format) && s.getValue().compareTo(new BigDecimal(-99)) != 0) .map(WindTowerCalculationData::getValue).collect(Collectors.toList()); BigDecimal avg = collect.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(collect.size()), 2, RoundingMode.HALF_UP); results.add(avg); } return results; } }