package com.jiayue.biz.service.impl; import cn.hutool.core.date.DateTime; import cn.hutool.core.util.ObjectUtil; import cn.hutool.db.Entity; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.jiayue.biz.domain.*; import com.jiayue.biz.dto.EquipmentDto; import com.jiayue.biz.dto.ProjectEvolveDto; import com.jiayue.biz.dto.ProjectInfoDto; import com.jiayue.biz.dto.SelectLabForVal; import com.jiayue.biz.eunms.WindDirectionEnum; import com.jiayue.biz.mapper.ProphaseAnemometryDataMapper; import com.jiayue.biz.mapper.ProphaseWeatherDataMapper; import com.jiayue.biz.mapper.WindTowerDataParentTableMapper; import com.jiayue.biz.service.*; import com.jiayue.biz.util.CalculationUtil; import com.jiayue.biz.util.DateTimeUtil; import com.jiayue.common.core.redis.RedisCache; import com.jiayue.common.utils.DateUtil; import com.jiayue.common.utils.spring.SpringUtils; import com.sun.corba.se.spi.ior.ObjectKey; import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.math.RoundingMode; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; /** * 首页Service业务层处理 * * @author L.ym * @date 2022-05-11 */ @Service @AllArgsConstructor public class HomePageServiceImpl extends ServiceImpl implements HomePageService { private final WindTowerInfoService windTowerInfoService; private final EquipmentAttributeService equipmentAttributeService; private final WindTowerCalculationDataServiceImpl windTowerCalculationDataService; private final WindTowerDataParentTableService windTowerDataParentTableService; private final StatisticsSituationService iStatisticsSituationService; private final ProjectService projectService; private final ElectricStationService electricStationService; private final ProvincialEnergyStationsService provincialEnergyStationsService; private final ProjectInfoService projectInfoService; private final StationInfoService stationInfoService; private final ProjectProgressService proProjectInfoService; private final TotalityInfoService totalityInfoService; private final FanModelDataService fanModelDataService; private final ProphaseAnemometryDataMapper prophaseAnemometryDataMapper; private final ProphaseWeatherDataMapper prophaseWeatherDataMapper; private final OtherStationInfoService otherStationInfoService; private final BigDecimal threeParameterOne = new BigDecimal("1.146"); private final BigDecimal threeParameterTow = new BigDecimal("77.42"); private final BigDecimal threeParameterThree = new BigDecimal("1672"); private final BigDecimal threeParameterFour = new BigDecimal("5251"); private final Double e = 10.0; /** * 风速 风功率 柱状图 * * @param equipmentId 设备编号 * @return Map */ public Map getWsAndWpdForHeight(String equipmentId, String month) { List windTowerInfoList = windTowerInfoService.lambdaQuery().eq(WindTowerInfo::getEquipmentNo, equipmentId).list(); String[] heights = windTowerInfoList.get(0).getHeights().split(","); //风速数据 List prophaseAnemometryDataList = new ArrayList<>(); //空气密度 List weatherDataList = new ArrayList<>(); if (!month.equals("")) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); try { Date startDate = sdf.parse(month); Date endDate = DateTimeUtil.endOfMonth(startDate); prophaseAnemometryDataList = prophaseAnemometryDataMapper.selectWsAve(equipmentId, new Timestamp(startDate.getTime()), new Timestamp(endDate.getTime())); weatherDataList = prophaseWeatherDataMapper.selectAir(equipmentId, new Timestamp(startDate.getTime()), new Timestamp(endDate.getTime())); } catch (ParseException e) { e.printStackTrace(); } } else { // 最新一天数据 List lastData = prophaseWeatherDataMapper.getLastData(equipmentId); Timestamp timeEnd = (Timestamp) lastData.get(0).get("last (ts)"); DateTime startTime = DateUtil.beginOfDay(new Date(timeEnd.getTime())); prophaseAnemometryDataList = prophaseAnemometryDataMapper.selectWsAve(equipmentId, new Timestamp(startTime.getTime()), timeEnd); weatherDataList = prophaseWeatherDataMapper.selectAir(equipmentId, new Timestamp(startTime.getTime()), timeEnd); } //时间和空气密度map Map timeAndAirMap = weatherDataList.stream().collect(Collectors.toMap(ProphaseWeatherData::getTs, ProphaseWeatherData::getAirDensity)); HashMap dataMap = new HashMap<>(); ArrayList wpdList = new ArrayList<>(); ArrayList wsList = new ArrayList<>(); ArrayList heightList = new ArrayList<>(); for (String height : heights) { //根据层高获取时间和风速map Map timeAndWsMap = prophaseAnemometryDataList.stream().filter(p -> p.getLayerHeight().equals(height)).collect(Collectors.toMap(ProphaseAnemometryData::getTs, ProphaseAnemometryData::getWsAve)); if (!timeAndWsMap.isEmpty() && !timeAndAirMap.isEmpty()) { ArrayList wsSumList = new ArrayList<>(); ArrayList wpdSumList = new ArrayList<>(); //遍历空气密度 for (Map.Entry airAndTime : timeAndAirMap.entrySet()) { //过滤风速map Map map = timeAndWsMap.entrySet().stream().filter(t -> t.getKey().getTime() == airAndTime.getKey().getTime()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); if (!map.isEmpty()) { BigDecimal wpdCalculate = CalculationUtil.getWpdCalculate(BigDecimal.valueOf(map.get(airAndTime.getKey())), BigDecimal.valueOf(airAndTime.getValue())); wpdSumList.add(wpdCalculate); wsSumList.add(BigDecimal.valueOf(map.get(airAndTime.getKey()))); } } if (wsSumList.size() > 0) { BigDecimal wpdAve = BigDecimal.valueOf(wsSumList.stream().collect(Collectors.averagingDouble(BigDecimal::doubleValue))).setScale(2, RoundingMode.HALF_UP); wsList.add(wpdAve); } if (wpdSumList.size() > 0) { BigDecimal wpdAve = BigDecimal.valueOf(wpdSumList.stream().collect(Collectors.averagingDouble(BigDecimal::doubleValue))).setScale(2, RoundingMode.HALF_UP); wpdList.add(wpdAve); } heightList.add(height + "m"); } } dataMap.put("ws", wsList); dataMap.put("wpd", wpdList); dataMap.put("height", heightList); return dataMap; } /*首页地图 测风塔信息*/ public List> homePageMap() { List> list = new ArrayList<>(); try { SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date startDay = DateTimeUtil.getDayStartTime(new Date().getTime() - 1000 * 60 * 60 * 24); Date endDay = DateTimeUtil.getDayLastTime(new Date().getTime() - 1000 * 60 * 60 * 24); /*测风塔设备*/ List windTowerInfoList = windTowerInfoService.list(); List statisticsSituationList = iStatisticsSituationService.list(); /*系统昨日的时间戳*/ long date = DateTimeUtil.getDayStartTime(new Date().getTime()).getTime() - 86400000; for (WindTowerInfo windTowerInfo : windTowerInfoList) { Map map = new HashMap(); // 状态 Boolean status = true; /*判断此塔是否停机状态 若运行状态 计算是否10天内没接入数据*/ if (windTowerInfo.getStatus() == null || windTowerInfo.getStatus().equals("1")) { /*根据设备编号获取该塔的最后一条数据*/ WindTowerDataParentTable lastData = windTowerDataParentTableService.getLastData(windTowerInfo.getEquipmentNo()); /*获取该塔接入的时间*/ long startTime = DateTimeUtil.getDayStartTime(lastData.getTime().getTime()).getTime(); /*测风塔最新接入时间 - 今日系统时间 = 差值 差值代表此塔几天没有接入数据,若差值>=10 将此塔状态设置为异常*/ long differenceDays = date - startTime; if ((differenceDays / 86400000) >= 10) { status = false; } else { status = true; } } // 缺失的数据条数 BigDecimal defectCount = new BigDecimal(144); /*昨日数据条数*/ List> maps = windTowerDataParentTableService.countDataIntegrity(windTowerInfo.getEquipmentNo(), sdfTime.format(startDay), sdfTime.format(endDay)); List statisticsSituations = statisticsSituationList.stream().filter(w -> w.getEquipmentId().equals(windTowerInfo.getEquipmentNo())).collect(Collectors.toList()); String info = ""; if (!statisticsSituations.isEmpty()) { StatisticsSituation statisticsSituation = statisticsSituations.get(0); String[] split = statisticsSituation.getStartTimeAndEndTime().split(","); info = info + "数据起止时间:" + sdf.format(new Date(Long.parseLong(split[0]))) + " - " + sdf.format(new Date(Long.parseLong(split[1]))); // if (statisticsSituation.getWsAve140() != null) // info = info + ";140米风速:" + statisticsSituation.getWsAve140().setScale(2, RoundingMode.HALF_UP); // if (statisticsSituation.getWsAve120() != null) // info = info + ";120米风速:" + statisticsSituation.getWsAve120().setScale(2, RoundingMode.HALF_UP); // if (statisticsSituation.getWsAve100() != null) // info = info + ";100米风速:" + statisticsSituation.getWsAve100().setScale(2, RoundingMode.HALF_UP); // if (statisticsSituation.getWsAve80() != null) // info = info + ";80米风速:" + statisticsSituation.getWsAve80().setScale(2, RoundingMode.HALF_UP); // if (statisticsSituation.getWsAve70() != null) // info = info + ";70米风速:" + statisticsSituation.getWsAve70().setScale(2, RoundingMode.HALF_UP); // if (statisticsSituation.getWsAve50() != null) // info = info + ";50米风速:" + statisticsSituation.getWsAve50().setScale(2, RoundingMode.HALF_UP); // if (statisticsSituation.getWsAve30() != null) // info = info + ";30米风速:" + statisticsSituation.getWsAve30().setScale(2, RoundingMode.HALF_UP); // if (statisticsSituation.getWsAve10() != null) // info = info + ";10米风速:" + statisticsSituation.getWsAve10().setScale(2, RoundingMode.HALF_UP); } if (!maps.isEmpty()) { defectCount = new BigDecimal(maps.get(0).get("num").toString()).subtract(new BigDecimal(144)); } map.put("name", windTowerInfo.getName()); map.put("equipmentNo", windTowerInfo.getEquipmentNo()); map.put("lon", windTowerInfo.getLongitude()); map.put("lat", windTowerInfo.getLatitude()); map.put("defectCount", defectCount); map.put("status", status); map.put("info", info); list.add(map); } } catch (Exception e) { e.printStackTrace(); } return list; }/*首页地图 测风塔信息*/ public List> homePageAllWindMap() { List> list = new ArrayList<>(); try { /*项目信息*/ List projectList = projectService.list(); /*场站信息*/ List electricStationList = electricStationService.list(); /*测风塔设备*/ // List windTowerInfoList = windTowerInfoService.list(); List windTowerInfoList = windTowerInfoService.lambdaQuery().list(); /*项目塔信息*/ List> projectTowerList = projectTowerMap(projectList, windTowerInfoList); list.addAll(projectTowerList); /*场站塔信息*/ List> electricStationTowerList = electricStationTowerMap(electricStationList, windTowerInfoList); list.addAll(electricStationTowerList); } catch (Exception e) { e.printStackTrace(); } return list; } /*首页地图项目塔*/ public List> projectTowerMap(List projectList, List windTowerInfoList) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); List> list = new ArrayList<>(); /*统计概述*/ List statisticsSituationList = iStatisticsSituationService.list(); /*系统昨日的时间戳*/ long date = DateTimeUtil.getDayStartTime(new Date().getTime()).getTime() - 86400000; /*项目塔*/ for (Project project : projectList) { /*项目关联的塔*/ String[] strings = project.getRelationEquipment().split(","); if (strings.length > 0) { for (String equipmentNo : strings) { Map map = new HashMap(); map.put("type", "emailWind"); map.put("projectId", project.getId()); List windTowerInfos = windTowerInfoList.stream().filter(w -> w.getEquipmentNo().equals(equipmentNo)).collect(Collectors.toList()); WindTowerInfo windTowerInfo = windTowerInfos.get(0); // 状态 Boolean status = true; /*判断此塔是否停机状态 若运行状态 计算是否10天内没接入数据*/ if (windTowerInfo.getStatus() == null || windTowerInfo.getStatus().equals("1")) { /*根据设备编号获取该塔的最后一条数据*/ WindTowerDataParentTable lastData = windTowerDataParentTableService.getLastData(windTowerInfo.getEquipmentNo()); /*获取该塔接入的时间*/ long startTime = DateTimeUtil.getDayStartTime(lastData.getTime().getTime()).getTime(); /*测风塔最新接入时间 - 今日系统时间 = 差值 差值代表此塔几天没有接入数据,若差值>=10 将此塔状态设置为异常*/ long differenceDays = date - startTime; if ((differenceDays / 86400000) >= 10) { status = false; } else { status = true; } } /*获取数据的起止时间*/ List statisticsSituations = statisticsSituationList.stream().filter(w -> w.getEquipmentId().equals(windTowerInfo.getEquipmentNo())).collect(Collectors.toList()); String info = ""; if (!statisticsSituations.isEmpty()) { StatisticsSituation statisticsSituation = statisticsSituations.get(0); String[] split = statisticsSituation.getStartTimeAndEndTime().split(","); info = info + "数据起止时间:" + sdf.format(new Date(Long.parseLong(split[0]))) + " - " + sdf.format(new Date(Long.parseLong(split[1]))); } map.put("name", windTowerInfo.getName()); map.put("equipmentNo", windTowerInfo.getEquipmentNo()); map.put("lon", windTowerInfo.getLongitude()); map.put("lat", windTowerInfo.getLatitude()); map.put("status", status); map.put("info", info); list.add(map); } } } return list; } /*首页地图实时塔*/ public List> electricStationTowerMap(List electricStationList, List windTowerInfoList) { List> list = new ArrayList<>(); /*实时塔*/ for (ElectricStation electricStation : electricStationList) { /*风场站关联的塔*/ String[] strings = electricStation.getRelationEquipment().split(","); if (strings.length > 0) { for (String equipmentNo : strings) { Map map = new HashMap(); map.put("type", "realWind"); map.put("electricStationId", electricStation.getId()); List windTowerInfos = windTowerInfoList.stream().filter(w -> w.getEquipmentNo().equals(equipmentNo)).collect(Collectors.toList()); if (!windTowerInfos.isEmpty()) { WindTowerInfo windTowerInfo = windTowerInfos.get(0); // 状态 Boolean status = windTowerInfo.getStatus() == null || windTowerInfo.getStatus().equals("1") ? true : false; map.put("name", windTowerInfo.getName()); map.put("equipmentNo", windTowerInfo.getEquipmentNo()); map.put("lon", windTowerInfo.getLongitude()); map.put("lat", windTowerInfo.getLatitude()); map.put("status", status); list.add(map); } } } } return list; } /** * 首页查询最新一天的风向玫瑰图 * * @param equipmentId 设备编号 * @param height 层高 * @return List> */ @Override public HashMap homePageRose(String equipmentId, String height, String month) { List anemometryData = new ArrayList<>(); if (!month.equals("")) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); try { Date startDate = sdf.parse(month); Date endDate = DateTimeUtil.endOfMonth(startDate); anemometryData = prophaseAnemometryDataMapper.selectWdAveAndWdAveAndWsStaForHeight(equipmentId, new Timestamp(startDate.getTime()), new Timestamp(endDate.getTime()), height); } catch (ParseException e) { e.printStackTrace(); } } else { // 最新一天数据 List lastData = prophaseWeatherDataMapper.getLastData(equipmentId); Timestamp timeEnd = (Timestamp) lastData.get(0).get("last (ts)"); DateTime startTime = DateUtil.beginOfDay(new Date(timeEnd.getTime())); anemometryData = prophaseAnemometryDataMapper.selectWdAveAndWdAveAndWsStaForHeight(equipmentId, new Timestamp(startTime.getTime()), timeEnd, height); } HashMap hashMap = new HashMap<>(); BigDecimal total = BigDecimal.ZERO; Map map = new HashMap<>(); Map windPowerMap = new HashMap<>(); for (WindDirectionEnum value : WindDirectionEnum.values()) { //根据设备属性风向获取数据 List heightAndWindDirectionEnum = CalculationUtil.getForHeightAndWindDirectionEnum(anemometryData, value); BigDecimal wsAve = BigDecimal.ZERO; if (heightAndWindDirectionEnum.size() > 0) { wsAve = BigDecimal.valueOf(heightAndWindDirectionEnum.stream().map(h -> { return BigDecimal.valueOf(h.getWsAve()); }).collect(Collectors.averagingDouble(BigDecimal::doubleValue))); } hashMap.put(value.name(), heightAndWindDirectionEnum.size()); total = total.add(BigDecimal.valueOf(heightAndWindDirectionEnum.size())); if (anemometryData.size() > 0) { //风向频率 BigDecimal wdF = BigDecimal.valueOf(heightAndWindDirectionEnum.size()).divide(BigDecimal.valueOf(anemometryData.size()), 2, RoundingMode.HALF_UP); map.put(value.name(), BigDecimal.valueOf(100).multiply(wdF)); // 风能:风向频率 * 平均风速的立方 windPowerMap.put(value.name(), wsAve.multiply(wsAve).multiply(wsAve).multiply(wdF).setScale(2, RoundingMode.HALF_UP)); } else { map.put(value.name(), BigDecimal.ZERO); windPowerMap.put(value.name(), BigDecimal.ZERO); } } ArrayList> entries = new ArrayList<>(map.entrySet()); entries.sort((o1, o2) -> { return o2.getValue().compareTo(o1.getValue()); }); List> entries1 = entries.subList(0, 3); HashMap everyMap = new HashMap<>(); everyMap.put("echars", map); everyMap.put("windPowerEchars", windPowerMap); everyMap.put("proportion", entries1); return everyMap; } /** * @param equipmentId 设备编号 * @param height 层高 * @return Map */ public Map getHeightForAveWs(String equipmentId, String height) { // 最新一天数据 List> mapList = windTowerDataParentTableService.getStartTimeAndEndTimeForData(equipmentId); List wsForHeight = CalculationUtil.getWsForHeight(mapList, height); //本层高风速总和 BigDecimal aveWs = wsForHeight.stream().reduce(BigDecimal.ZERO, BigDecimal::add); HashMap hashMap = new HashMap<>(); //层高所有条数 long total = 0; for (int i = 0; i < 11; i = i + 2) { long count; int finalI = i; String iStr = ""; if (i >= 10) { count = wsForHeight.stream().filter(w -> w.compareTo(BigDecimal.valueOf(finalI)) > 0).count(); iStr = ">" + finalI + "m/s"; } else { count = wsForHeight.stream().filter(w -> w.compareTo(BigDecimal.valueOf(finalI)) > 0 && w.compareTo(BigDecimal.valueOf(finalI + 2)) < 0).count(); iStr = finalI + "~" + (finalI + 2) + "m/s"; } total += count; if (count > 0) { hashMap.put(iStr, count); } } HashMap dataMap = new HashMap<>(); if (total > 0) { dataMap.put("wsAve", aveWs.divide(BigDecimal.valueOf(total), 2, RoundingMode.HALF_UP)); } else { dataMap.put("wsAve", BigDecimal.ZERO); } dataMap.put("proportion", hashMap); return dataMap; } /** * 首页查询最新一天的平均风速 * * @param equipmentId 设备编号 * @return */ public Map homePageCharts(String equipmentId, String month) { List mapList = new ArrayList<>(); if (!month.equals("")) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); try { Date startDate = sdf.parse(month); Date endDate = DateTimeUtil.endOfMonth(startDate); mapList = prophaseAnemometryDataMapper.selectWsAve(equipmentId, new Timestamp(startDate.getTime()), new Timestamp(endDate.getTime())); } catch (ParseException e) { e.printStackTrace(); } } else { // 最新一天数据 List lastData = prophaseWeatherDataMapper.getLastData(equipmentId); Timestamp timeEnd = (Timestamp) lastData.get(0).get("last (ts)"); DateTime startTime = DateUtil.beginOfDay(new Date(timeEnd.getTime())); mapList = prophaseAnemometryDataMapper.selectWsAve(equipmentId, new Timestamp(startTime.getTime()), timeEnd); } HashMap everyMap = new HashMap(); //获取风速层高 List windTowerInfos = windTowerInfoService.getByEquipmentNo(equipmentId); String height = windTowerInfos.get(0).getHeights(); String[] heightAll = height.split(","); // 时间list ArrayList timeList = new ArrayList(); ArrayList everyData = new ArrayList<>(); for (String h : heightAll) { timeList = new ArrayList(); ArrayList hList = new ArrayList(); HashMap hMap = new HashMap(); //根据层高过滤时间和风速 TreeMap heightForTimeAndWs = new TreeMap<>(mapList.stream().filter(p -> p.getLayerHeight().equals(h)).collect(Collectors.toMap(prophaseAnemometryData -> prophaseAnemometryData != null ? prophaseAnemometryData.getTs().getTime() : null, prophaseAnemometryData1 -> prophaseAnemometryData1 != null ? prophaseAnemometryData1.getWsAve() : null))); for (Map.Entry entry : heightForTimeAndWs.entrySet()) { String time = DateUtil.format(new Date(entry.getKey()), "yyyy-MM-dd HH:mm:ss"); timeList.add(time); hList.add(entry.getValue()); } hMap.put("height", h); hMap.put("value", hList); everyData.add(hMap); } everyMap.put("chart", everyData); everyMap.put("time", timeList); return everyMap; } /** * 首页空气密度和温度 折线图 * * @param equipmentId 场站编号 * @return List */ public Map> selectTForAir(String equipmentId) { //获取最新一天的数据 List> mapList = windTowerDataParentTableService.getStartTimeAndEndTimeForData(equipmentId); ArrayList tList = new ArrayList<>(); ArrayList airList = new ArrayList<>(); ArrayList timeList = new ArrayList<>(); HashMap> hashMap1 = new HashMap<>(); for (Map map : mapList) { BigDecimal tAve = BigDecimal.ZERO; BigDecimal airDensity = BigDecimal.ZERO; String abnormal_type = ""; //过滤异常值 if (map.get("abnormal_type") != null) { abnormal_type = map.get("abnormal_type").toString(); } if (map.get("t_ave") != null && !map.get("t_ave").equals("") && (!abnormal_type.contains("t_ave"))) { tAve = CalculationUtil.getBigDecimal(map.get("t_ave")); } if (map.get("air_density") != null && !map.get("air_density").equals("") && (!abnormal_type.contains("air_density"))) { airDensity = CalculationUtil.getBigDecimal(map.get("air_density")); } tList.add(tAve); airList.add(airDensity); String time = DateUtil.format(new Date(Long.parseLong(map.get("time").toString())), "yyyy-MM-dd HH:mm:ss"); timeList.add(time); } hashMap1.put("t", tList); hashMap1.put("air", airList); hashMap1.put("time", timeList); return hashMap1; } /** * 首页空气密度、温度、压强平均值 湍流 风切变 * * @param equipmentId 场站编号 * @return Map */ public Map getAirAndPaAndT(String equipmentId, String month) { List weatherDataList = new ArrayList<>(); List anemometryDataList = new ArrayList<>(); if (!month.equals("")) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); try { Date startDate = sdf.parse(month); Date endDate = DateTimeUtil.endOfMonth(startDate); weatherDataList = prophaseWeatherDataMapper.selectTAveAndPaAveAndAir(equipmentId, new Timestamp(startDate.getTime()), new Timestamp(endDate.getTime())); anemometryDataList = prophaseAnemometryDataMapper.selectAveAndSta(equipmentId, new Timestamp(startDate.getTime()), new Timestamp(endDate.getTime())); } catch (ParseException e) { e.printStackTrace(); } } else { List lastData = prophaseWeatherDataMapper.getLastData(equipmentId); Timestamp timeEnd = (Timestamp) lastData.get(0).get("last (ts)"); DateTime startTime = DateUtil.beginOfDay(new Date(timeEnd.getTime())); // 最新一天数据 weatherDataList = prophaseWeatherDataMapper.selectTAveAndPaAveAndAir(equipmentId, new Timestamp(startTime.getTime()), timeEnd); anemometryDataList = prophaseAnemometryDataMapper.selectAveAndSta(equipmentId, new Timestamp(startTime.getTime()), timeEnd); } WindTowerInfo windTowerInfo = windTowerInfoService.getByEquipmentNo(equipmentId).get(0); String height; String[] strings = windTowerInfo.getHeights().split(","); height = CalculationUtil.getNumberFromString(strings[0]); String minHeight = CalculationUtil.getNumberFromString(strings[strings.length - 1]); //最底层 if (windTowerInfo.getDisplayHeight() != null && !windTowerInfo.getDisplayHeight().equals("")) { height = windTowerInfo.getDisplayHeight(); } HashMap dataMap = new HashMap<>(); BigDecimal tAve = BigDecimal.ZERO; BigDecimal airDensity = BigDecimal.ZERO; BigDecimal pa = BigDecimal.ZERO; // 风速集合 String finalHeight = height; List wsForHeight = anemometryDataList.stream().filter(a -> a.getLayerHeight().equals(finalHeight)).map(h -> { return BigDecimal.valueOf(h.getWsAve()); }).collect(Collectors.toList()); List minWsForHeight = anemometryDataList.stream().filter(a -> a.getLayerHeight().equals(minHeight)).map(h -> { return BigDecimal.valueOf(h.getWsAve()); }).collect(Collectors.toList()); // 风速标准差集合 List wsStaForHeight = anemometryDataList.stream().filter(a -> a.getLayerHeight().equals(minHeight)).map(h -> { return BigDecimal.valueOf(h.getWsSta()); }).collect(Collectors.toList()); BigDecimal avgWs = CalculationUtil.getAvgWind(wsForHeight); // 风速平均值 BigDecimal avgMinWs = CalculationUtil.getAvgWind(minWsForHeight); // 最小风速平均值 BigDecimal avgWsSta = CalculationUtil.getAvgWind(wsStaForHeight);// 风速标准差平均值 BigDecimal turbulence = CalculationUtil.caTurbulenceIntensity(avgWsSta, avgWs); // 湍流 BigDecimal windShear = BigDecimal.ZERO; if (avgWs.compareTo(BigDecimal.ZERO) != 0) { windShear = CalculationUtil.caWindShear(avgWs, avgMinWs, new BigDecimal(height), new BigDecimal(minHeight));// 风切变 } if(!weatherDataList.isEmpty()){ airDensity = BigDecimal.valueOf(weatherDataList.stream().map(w -> { return BigDecimal.valueOf(w.getAirDensity()); }).collect(Collectors.averagingDouble(BigDecimal::doubleValue))).setScale(2,RoundingMode.HALF_UP); tAve = BigDecimal.valueOf(weatherDataList.stream().map(w -> { return BigDecimal.valueOf(w.getTAve()); }).collect(Collectors.averagingDouble(BigDecimal::doubleValue))).setScale(2,RoundingMode.HALF_UP); pa = BigDecimal.valueOf(weatherDataList.stream().map(w -> { return BigDecimal.valueOf(w.getPaAve()); }).collect(Collectors.averagingDouble(BigDecimal::doubleValue))).setScale(2,RoundingMode.HALF_UP); } BigDecimal batterySum = BigDecimal.ZERO; for (BigDecimal ws : wsForHeight) { // 日发电量 = 风速*功率*塔个数*频率 累加至24小时 BigDecimal battery = CalculationUtil.getBattery(ws); batterySum = batterySum.add(battery); } //日发电量 batterySum = batterySum.divide(BigDecimal.valueOf(6 * 1000), 2, RoundingMode.HALF_UP); //满发小时数 BigDecimal hourMax = batterySum.divide(BigDecimal.valueOf(6.25), 2, RoundingMode.HALF_UP); dataMap.put("battery", batterySum); dataMap.put("hour", hourMax); dataMap.put("t", tAve); dataMap.put("air", airDensity); dataMap.put("pa", pa); dataMap.put("turbulence", turbulence); dataMap.put("windShear", windShear); dataMap.put("height", height); return dataMap; } /** * 根据时间范围和设备id查询数据 * * @param startTime 开始时间 * @param endTime 结束时间 * @param equipmentId 设备id * @return List> */ public List> selectDataByBetweenTimeAndEquipmetId(Date startTime, Date endTime, String equipmentId) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); String key = "homepageWindDataSelect" + sdf.format(startTime) + equipmentId; Object cacheObj = SpringUtils.getBean(RedisCache.class).getCacheObject(key); if (ObjectUtil.isNotNull(cacheObj)) { return (List>) cacheObj; } List> mapList = windTowerDataParentTableService.selectDataByBetweenTimeAndEquipmetId(startTime, endTime, equipmentId); SpringUtils.getBean(RedisCache.class).setCacheObject(key, mapList); return mapList; } //首页全省资源概述 public HashMap getResourcesOverview() { ProvincialEnergyStations provincialEnergyStations = provincialEnergyStationsService.getProvincialEnergyStations(); HashMap hashMap = new HashMap<>(); hashMap.put("resourcesOverview", provincialEnergyStations.getResourcesOverview()); return hashMap; } //获取华电以及全省资源概况 public ProvincialEnergyStations getProvincialEnergyStations() { return provincialEnergyStationsService.getProvincialEnergyStations(); } //获取项目类别以及项目概况 public HashMap getProjectSort() { HashMap dataMap = new HashMap<>(); List totalityInfos = totalityInfoService.selectTotalityInfoList(); List projectInfoList = projectInfoService.getProjectInfoList(); //根据类别分组 Map> four = projectInfoList.stream() .filter(p -> !p.getProjectBasicInfo().getProjectSort().equals("four")) .collect(Collectors.groupingBy((ProjectInfo pro) -> { return pro.getProjectBasicInfo().getProjectSort(); })); //循环数据 存放Id和项目名称 for (Map.Entry> entry : four.entrySet()) { ArrayList projectInfoDtoList = new ArrayList<>(); for (ProjectInfo projectInfo : entry.getValue()) { ProjectInfoDto projectInfoDto = new ProjectInfoDto(); projectInfoDto.setId(projectInfo.getId()); projectInfoDto.setProjectSort(projectInfo.getProjectBasicInfo().getProjectName()); projectInfoDtoList.add(projectInfoDto); } dataMap.put(entry.getKey(), projectInfoDtoList); } //项目基本信息 dataMap.put("pInfo", totalityInfos.get(0).getPInfo()); return dataMap; } //查询项目概况 public HashMap projectMapInfo(String projectId) { HashMap dataMap = new HashMap<>(); //获取项目信息 List projectInfoList = projectInfoService.getProjectInfoList(); //根据项目ID过滤指定数据 List collect = projectInfoList.stream().filter(p -> p.getId().equals(projectId)).collect(Collectors.toList()); //获取对应项目概述 if (!collect.isEmpty()) { for (ProjectInfo projectInfo : collect) { dataMap.put("projectOverview", projectInfo.getProjectBasicInfo().getProjectOverview()); dataMap.put("resourcesOverview", projectInfo.getProjectBasicInfo().getResourcesOverview()); if (projectInfo.getEquipment() != null && projectInfo.getEquipment().size() > 0) { dataMap.put("longitude", projectInfo.getEquipment().get(0).getLongitude()); dataMap.put("latitude", projectInfo.getEquipment().get(0).getLatitude()); } } } return dataMap; } //地图点位坐标 (风机、测风塔、拐点) public HashMap getPointMap() { HashMap dataMap = new HashMap<>(); //获取项目信息 List projectInfoList = projectInfoService.getProjectInfoList(); //获取场站数据 List stationInfoList = stationInfoService.selectStationInfo(); //循环所有项目于信息 //测风塔List ArrayList> towerList = new ArrayList<>(); //拐点坐标List ArrayList> coordinateList = new ArrayList<>(); //风机List ArrayList fanList = new ArrayList<>(); for (ProjectInfo projectInfo : projectInfoList) { //拐点坐标 coordinateList.add(projectInfo.getCoordinates()); if (projectInfo.getEquipment() != null && projectInfo.getEquipment().size() > 0) { //循环测风塔信息 for (Equipment equipment : projectInfo.getEquipment()) { HashMap map = new HashMap<>(); map.put("longitude", equipment.getLongitude()); map.put("latitude", equipment.getLatitude()); map.put("towerName", equipment.getName()); map.put("projectName", projectInfo.getProjectBasicInfo().getProjectNameEasy()); towerList.add(map); } } } dataMap.put("towerList", towerList); dataMap.put("coordinatesList", coordinateList); for (StationInfo stationInfo : stationInfoList) { if (stationInfo.getEquipment() != null && stationInfo.getEquipment().size() > 0) { //循环测风塔信息 ArrayList> arrayList = new ArrayList<>(); for (Equipment equipment : stationInfo.getEquipment()) { HashMap map = new HashMap<>(); map.put("longitude", equipment.getLongitude()); map.put("latitude", equipment.getLatitude()); map.put("towerName", equipment.getName()); map.put("stationName", stationInfo.getStationBasicInfo().getStationName()); arrayList.add(map); } towerList.addAll(arrayList); } fanList.addAll(stationInfo.getFanTowerList()); } dataMap.put("fan", fanList); return dataMap; } /** * 项目测风塔下拉框 * * @return List */ public List projectSelect() { List projectInfoList = projectInfoService.getProjectInfoList(); ArrayList selectList = new ArrayList<>(); if (projectInfoList.size() > 0) { //循环数据 放入项目id和项目名称 for (ProjectInfo projectInfo : projectInfoList) { SelectLabForVal selectLabForVal = new SelectLabForVal(); selectLabForVal.setLabel(projectInfo.getProjectBasicInfo().getProjectNameEasy()); selectLabForVal.setValue(projectInfo.getId()); if (projectInfo.getEquipment().size() > 0) { ArrayList equipmentDtoList = new ArrayList<>(); //循环数据 放入测风塔id和测风塔名称 for (Equipment equipment : projectInfo.getEquipment()) { EquipmentDto equipmentDto = new EquipmentDto(); equipmentDto.setLabel(equipment.getName()); equipmentDto.setValue(equipment.getId()); equipmentDtoList.add(equipmentDto); } selectLabForVal.setEquipmentDto(equipmentDtoList); } selectList.add(selectLabForVal); } } return selectList; } //查询场站信息以及场站列表 public HashMap getStationTotalityInfo() { //总体信息 List totalityInfos = totalityInfoService.selectTotalityInfoList(); //场站信息 List stationInfos = stationInfoService.selectStationInfo(); HashMap stationMap = new HashMap<>(); if (totalityInfos.size() > 0) { stationMap.put("fInfo", totalityInfos.get(0).getFInfo()); stationMap.put("gInfo", totalityInfos.get(0).getGInfo()); if (stationInfos.size() > 0) { ArrayList arrayList = new ArrayList<>(); for (StationInfo stationInfo : stationInfos) { HashMap hashMap = new HashMap<>(); hashMap.put("id", stationInfo.getId()); hashMap.put("stationName", stationInfo.getStationBasicInfo().getStationName()); //经度 hashMap.put("longitude", stationInfo.getStationBasicInfo().getLongitude()); //纬度 hashMap.put("latitude", stationInfo.getStationBasicInfo().getLatitude()); arrayList.add(hashMap); } stationMap.put("station", arrayList); } } return stationMap; } /** * 查询所有的场站坐标 */ public HashMap getStationSeat() { HashMap dataMap = new HashMap<>(); List otherStationInfoList = otherStationInfoService.selectOtherStationInfo(); List stationInfos = stationInfoService.selectStationInfo(); ArrayList> stationList = new ArrayList<>(); for (StationInfo stationInfo : stationInfos) { HashMap hashMap = new HashMap<>(); hashMap.put("id", stationInfo.getId()); hashMap.put("stationName", stationInfo.getStationBasicInfo().getStationName()); //经度 hashMap.put("longitude", stationInfo.getStationBasicInfo().getLongitude()); //纬度 hashMap.put("latitude", stationInfo.getStationBasicInfo().getLatitude()); stationList.add(hashMap); } ArrayList> otherStationList = new ArrayList<>(); for (OtherStationInfo otherStationInfo : otherStationInfoList) { HashMap hashMap = new HashMap<>(); hashMap.put("id", otherStationInfo.getId()); hashMap.put("stationName", otherStationInfo.getStationName()); //经度 hashMap.put("longitude", otherStationInfo.getLongitude()); //纬度 hashMap.put("latitude", otherStationInfo.getLatitude()); otherStationList.add(hashMap); } dataMap.put("HDStation",stationList); dataMap.put("otherStation",otherStationList); return dataMap; } /** * 查询所有的项目坐标 */ public ArrayList getProjectSeat() { ArrayList arrayList = new ArrayList<>(); //获取项目信息 List projectInfoList = projectInfoService.getProjectInfoList(); for (ProjectInfo projectInfo : projectInfoList) { if (projectInfo.getEquipment() != null && projectInfo.getEquipment().size() > 0) { Equipment equipment = projectInfo.getEquipment().get(0); HashMap map = new HashMap<>(); map.put("longitude", equipment.getLongitude()); map.put("latitude", equipment.getLatitude()); map.put("id", projectInfo.getId()); map.put("projectNameEasy", projectInfo.getProjectBasicInfo().getProjectNameEasy()); map.put("projectName", projectInfo.getProjectBasicInfo().getProjectName()); arrayList.add(map); } } return arrayList; } /** * 查询场站详细信息(风机、机型等) */ public HashMap getStationInfo(String stationId) { //场站信息 List stationInfos = stationInfoService.selectStationInfo(); List stationInfoList = stationInfos.stream().filter(s -> s.getId().equals(stationId)).collect(Collectors.toList()); List fanModelDataList = fanModelDataService.getFanModelDataList(); //过滤 List collect = fanModelDataList.stream().filter(f -> f.getStationId().equals(stationId)).collect(Collectors.toList()); HashMap dataMap = new HashMap<>(); if (stationInfoList.size() > 0) { ArrayList> arrayList = new ArrayList<>(); //根据风机类型分组 Map> modelMap = stationInfoList.get(0).getFanTowerList().stream() .collect(Collectors.groupingBy(FanTower::getFanModel)); //遍历map指定key for (Map.Entry> entry : modelMap.entrySet()) { for (FanModelData fanModelData : collect) { if (fanModelData.getModelName().equals(entry.getKey())) { HashMap map = new HashMap<>(); //风机名称 map.put("modelType", entry.getKey()); //风机数量 map.put("modelTotal", entry.getValue().size()); //满发小时数 map.put("wsAve", fanModelData.getWsAve()); //主风向 map.put("wdSum", fanModelData.getWdSum()); //发电量 map.put("generatingCapacity", fanModelData.getGeneratingCapacity()); //满发小时数 map.put("realTimeTotal", fanModelData.getRealTimeTotal()); arrayList.add(map); } } } //过滤塔信息 StationInfo stationInfo = stationInfoList.get(0); if (stationInfo.getEquipment() != null && stationInfo.getEquipment().size() > 0) { dataMap.put("longitude", stationInfo.getEquipment().get(0).getLongitude()); dataMap.put("latitude", stationInfo.getEquipment().get(0).getLatitude()); } else { dataMap.put("longitude", stationInfo.getFanTowerList().get(0).getLongitudeFan()); dataMap.put("latitude", stationInfo.getFanTowerList().get(0).getLatitudeFan()); } dataMap.put("modelT", arrayList); } return dataMap; } /** * 场站测风塔下拉框 * * @return List */ public List stationSelect() { List stationInfoList = stationInfoService.selectStationInfo(); ArrayList selectList = new ArrayList<>(); if (stationInfoList.size() > 0) { //循环数据 放入项目id和项目名称 for (StationInfo stationInfo : stationInfoList) { SelectLabForVal selectLabForVal = new SelectLabForVal(); selectLabForVal.setLabel(stationInfo.getStationBasicInfo().getStationName()); selectLabForVal.setValue(stationInfo.getId()); if (stationInfo.getEquipment().size() > 0) { ArrayList equipmentDtoList = new ArrayList<>(); //循环数据 放入测风塔id和测风塔名称 for (Equipment equipment : stationInfo.getEquipment()) { EquipmentDto equipmentDto = new EquipmentDto(); equipmentDto.setLabel(equipment.getName()); equipmentDto.setValue(equipment.getId()); equipmentDtoList.add(equipmentDto); } selectLabForVal.setEquipmentDto(equipmentDtoList); } selectList.add(selectLabForVal); } } return selectList; } //项目进展 public List getProjectEvolve(String projectId) { //查询项目进展信息 List projectProgresses = proProjectInfoService.selectProProjectInfo(); //根据项目id筛选数据 List progressList = projectProgresses.stream().filter(p -> p.getProjectId().equals(projectId)).collect(Collectors.toList()); ArrayList projectEvolveList = new ArrayList<>(); if (progressList.size() > 0) { //循环项目进展信息 一般只有一条 for (ProjectProgress progress : progressList) { if (progress.getProjectMenusOneList().size() > 0) { //循环一级菜单 for (ProjectMenusOne menusOne : progress.getProjectMenusOneList()) { ProjectEvolveDto projectEvolveDtoOne = new ProjectEvolveDto(); //一级菜单 projectEvolveDtoOne.setIndex(menusOne.getIndex()); projectEvolveDtoOne.setTaskContent(menusOne.getWorkContent()); projectEvolveDtoOne.setPlanTime(menusOne.getPlanTime()); if (menusOne.getProjectMenusTows().size() > 0 && menusOne.getProjectMenusTows().get(0).getIndex().equals("")) { if (menusOne.getProjectMenusTows().get(0).getProjectMenusThreeList().size() > 0) { projectEvolveDtoOne.setStatus(menusOne.getProjectMenusTows().get(0).getProjectMenusThreeList().get(0).getRealTime()); projectEvolveList.add(projectEvolveDtoOne); } } else { projectEvolveList.add(projectEvolveDtoOne); if (menusOne.getProjectMenusTows() != null && menusOne.getProjectMenusTows().size() > 0) { //循环二级菜单 for (ProjectMenusTow menusTow : menusOne.getProjectMenusTows()) { if (menusTow.getProjectMenusThreeList() != null && menusTow.getProjectMenusThreeList().size() > 0) { //循环三级菜单 for (ProjectMenusThree menusThree : menusTow.getProjectMenusThreeList()) { ProjectEvolveDto projectEvolveDto = new ProjectEvolveDto(); //放入二级序号 projectEvolveDto.setIndex(menusTow.getIndex()); //放入二级计划时间 projectEvolveDto.setPlanTime(menusTow.getPlanTime()); //放入二级工作内容 projectEvolveDto.setTaskContent(menusTow.getWorkContent()); //详细工作信息 三级工作内容 projectEvolveDto.setDetailedTaskContent(menusThree.getWorkContent()); //实际完成时间 三级时间 projectEvolveDto.setRealTime(menusThree.getRealTime()); //放入状态 三级备注 projectEvolveDto.setStatus(menusThree.getRemark()); projectEvolveList.add(projectEvolveDto); } } else { ProjectEvolveDto projectEvolveDto = new ProjectEvolveDto(); projectEvolveDto.setIndex(menusTow.getIndex()); projectEvolveDto.setTaskContent(menusTow.getWorkContent()); projectEvolveDto.setPlanTime(menusTow.getPlanTime()); projectEvolveList.add(projectEvolveDto); } } } } } } } } return projectEvolveList; } }