|
|
|
@ -1,11 +1,15 @@
|
|
|
|
|
package com.mh.system.service.overview.impl; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.mh.common.core.domain.ColumnFilter; |
|
|
|
|
import com.mh.common.core.domain.dto.DeviceMonitorDTO; |
|
|
|
|
import com.mh.common.core.domain.dto.OverviewEnergyDTO; |
|
|
|
|
import com.mh.common.core.domain.dto.ProProfileDTO; |
|
|
|
|
import com.mh.common.core.domain.entity.ChillersEntity; |
|
|
|
|
import com.mh.common.core.domain.entity.CollectionParamsManage; |
|
|
|
|
import com.mh.common.core.domain.entity.DataMonth; |
|
|
|
|
import com.mh.common.core.domain.entity.SysDictData; |
|
|
|
|
import com.mh.common.utils.DateUtils; |
|
|
|
|
import com.mh.system.mapper.SysDictDataMapper; |
|
|
|
|
import com.mh.system.mapper.device.CollectionParamsManageMapper; |
|
|
|
|
import com.mh.system.mapper.energy.OverviewMapper; |
|
|
|
@ -13,8 +17,10 @@ import com.mh.system.service.overview.IProOverviewService;
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.time.LocalDate; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author LJF |
|
|
|
@ -38,10 +44,245 @@ public class ProOverviewServiceImpl implements IProOverviewService {
|
|
|
|
|
this.overviewMapper = overviewMapper; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<DeviceMonitorDTO> mainParams() { |
|
|
|
|
// 查询系统类型数据
|
|
|
|
|
List<SysDictData> sysTypeDataList = sysDictDataMapper.selectDictDataByType("sys_type"); |
|
|
|
|
// 遍历系统类型查询对应需要的数据
|
|
|
|
|
List<DeviceMonitorDTO> deviceMonitorDTOList = new ArrayList<>(); |
|
|
|
|
for (SysDictData sysDictData : sysTypeDataList) { |
|
|
|
|
switch (Integer.parseInt(sysDictData.getDictValue())) { |
|
|
|
|
case 0: |
|
|
|
|
// 查询冷源系统的EER
|
|
|
|
|
// 查询实时功率
|
|
|
|
|
List<CollectionParamsManage> realEleParams = queryCollectionParams("16", "0", 140); |
|
|
|
|
BigDecimal realEle = null; |
|
|
|
|
if (realEleParams != null && !realEleParams.isEmpty()) { |
|
|
|
|
realEle = realEleParams.stream() |
|
|
|
|
.map(CollectionParamsManage::getCurValue) |
|
|
|
|
.filter(Objects::nonNull) |
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
|
} |
|
|
|
|
// 查询冷源系统的产冷量
|
|
|
|
|
List<CollectionParamsManage> realColdParams = queryCollectionParams("17", "0", 140); |
|
|
|
|
BigDecimal realCold = null; |
|
|
|
|
if (realColdParams != null && !realColdParams.isEmpty()) { |
|
|
|
|
// realColdParams stream流得出cur_value总和
|
|
|
|
|
realCold = realColdParams.stream() |
|
|
|
|
.map(CollectionParamsManage::getCurValue) |
|
|
|
|
.filter(Objects::nonNull) |
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
|
} |
|
|
|
|
// 计算EER
|
|
|
|
|
BigDecimal eer = new BigDecimal("0.00"); |
|
|
|
|
if (realEle != null && realCold != null) { |
|
|
|
|
if (realCold.compareTo(BigDecimal.ZERO) == 0 || realEle.compareTo(BigDecimal.ZERO) == 0) { |
|
|
|
|
eer = new BigDecimal("0.00"); |
|
|
|
|
} else { |
|
|
|
|
eer = realCold.divide(realEle, 2, BigDecimal.ROUND_HALF_UP); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ColumnFilter eerColumn = new ColumnFilter("eer", eer.toString()); |
|
|
|
|
DeviceMonitorDTO deviceMonitorDTO = new DeviceMonitorDTO(); |
|
|
|
|
deviceMonitorDTO.setName(sysDictData.getDictLabel()); |
|
|
|
|
deviceMonitorDTO.setValues(Stream.of(eerColumn).collect(Collectors.toList())); |
|
|
|
|
deviceMonitorDTOList.add(deviceMonitorDTO); |
|
|
|
|
break; |
|
|
|
|
case 1: |
|
|
|
|
// 热泵生活热水系统
|
|
|
|
|
// 查询供回水温度
|
|
|
|
|
List<CollectionParamsManage> realInAndOutTempParams = queryCollectionParams("12", "1", 140); |
|
|
|
|
// 查询供水温度的平均值
|
|
|
|
|
BigDecimal avgOutTemp = realInAndOutTempParams.stream() |
|
|
|
|
.filter(param -> param != null |
|
|
|
|
&& param.getOtherName() != null |
|
|
|
|
&& param.getOtherName().contains("供水")) |
|
|
|
|
.map(CollectionParamsManage::getCurValue) |
|
|
|
|
.filter(Objects::nonNull) |
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add) |
|
|
|
|
.divide(new BigDecimal(realInAndOutTempParams.size()), 2, BigDecimal.ROUND_HALF_UP); |
|
|
|
|
// 查询回水温度的平均值
|
|
|
|
|
BigDecimal avgInTemp = realInAndOutTempParams.stream() |
|
|
|
|
.filter(param -> param != null |
|
|
|
|
&& param.getOtherName() != null |
|
|
|
|
&& param.getOtherName().contains("回水")) |
|
|
|
|
.map(CollectionParamsManage::getCurValue) |
|
|
|
|
.filter(Objects::nonNull) |
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add) |
|
|
|
|
.divide(new BigDecimal(realInAndOutTempParams.size()), 2, BigDecimal.ROUND_HALF_UP); |
|
|
|
|
|
|
|
|
|
ColumnFilter inTempColumn = new ColumnFilter("回水平均温度", avgInTemp.toString()); |
|
|
|
|
ColumnFilter outTempColumn = new ColumnFilter("供水平均温度", avgOutTemp.toString()); |
|
|
|
|
DeviceMonitorDTO deviceMonitorDTO2 = new DeviceMonitorDTO(); |
|
|
|
|
deviceMonitorDTO2.setName(sysDictData.getDictLabel()); |
|
|
|
|
deviceMonitorDTO2.setValues(Stream.of(inTempColumn, outTempColumn).collect(Collectors.toList())); |
|
|
|
|
deviceMonitorDTOList.add(deviceMonitorDTO2); |
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
// 空调风柜系统
|
|
|
|
|
// 查询风柜运行状态
|
|
|
|
|
List<CollectionParamsManage> windCabinetRunParams = queryCollectionParams("1", "2", 140); |
|
|
|
|
if (windCabinetRunParams != null && !windCabinetRunParams.isEmpty()) { |
|
|
|
|
// 查询风柜正在运行设备,判断cur_value=1的
|
|
|
|
|
long runCount = windCabinetRunParams.stream().filter(param -> param != null |
|
|
|
|
&& param.getCurValue() != null |
|
|
|
|
&& param.getCurValue().compareTo(BigDecimal.ONE) == 0).count(); |
|
|
|
|
long stopCount = windCabinetRunParams.size() - runCount; |
|
|
|
|
ColumnFilter runColumn = new ColumnFilter("运行", runCount + ""); |
|
|
|
|
ColumnFilter stopColumn = new ColumnFilter("停止", stopCount + ""); |
|
|
|
|
DeviceMonitorDTO deviceMonitorDTO3 = new DeviceMonitorDTO(); |
|
|
|
|
deviceMonitorDTO3.setName(sysDictData.getDictLabel()); |
|
|
|
|
deviceMonitorDTO3.setValues(Stream.of(runColumn, stopColumn).collect(Collectors.toList())); |
|
|
|
|
deviceMonitorDTOList.add(deviceMonitorDTO3); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 3: |
|
|
|
|
// 真空锅炉采暖系统
|
|
|
|
|
break; |
|
|
|
|
case 4: |
|
|
|
|
// 室内温度监测系统
|
|
|
|
|
List<CollectionParamsManage> tempParams = queryCollectionParams("12", "4", 140); |
|
|
|
|
// stream流判断时间cur_time是否是今天,如果是今天则判断在线,不是则判断离线
|
|
|
|
|
if (tempParams != null && !tempParams.isEmpty()) { |
|
|
|
|
long onlineCount = tempParams.stream() |
|
|
|
|
.filter(param -> param != null |
|
|
|
|
&& param.getCurTime() != null |
|
|
|
|
&& DateUtils.dateToString(param.getCurTime(), "yyyy-MM-dd").equals(DateUtils.dateToString(new Date(), "yyyy-MM-dd"))) |
|
|
|
|
.count(); |
|
|
|
|
long offlineCount = tempParams.size() - onlineCount; |
|
|
|
|
ColumnFilter onlineColumn = new ColumnFilter("在线", onlineCount + ""); |
|
|
|
|
ColumnFilter offlineColumn = new ColumnFilter("离线", offlineCount + ""); |
|
|
|
|
DeviceMonitorDTO deviceMonitorDTO4 = new DeviceMonitorDTO(); |
|
|
|
|
deviceMonitorDTO4.setName(sysDictData.getDictLabel()); |
|
|
|
|
deviceMonitorDTO4.setValues(Stream.of(onlineColumn, offlineColumn).collect(Collectors.toList())); |
|
|
|
|
deviceMonitorDTOList.add(deviceMonitorDTO4); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 5: |
|
|
|
|
// 园林照明控制系统
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return deviceMonitorDTOList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<OverviewEnergyDTO> energyAnalysis() { |
|
|
|
|
List<ChillersEntity> dataList = overviewMapper.energyAnalysis(null); |
|
|
|
|
return List.of(); |
|
|
|
|
// 查询系统类型数据
|
|
|
|
|
List<SysDictData> sysTypeData = sysDictDataMapper.selectDictDataByType("sys_type"); |
|
|
|
|
// 定义参数类型
|
|
|
|
|
String[] paramTypes = {"16", "17", "18", "19"}; |
|
|
|
|
// 初始化结果列表
|
|
|
|
|
List<OverviewEnergyDTO> result = new ArrayList<>(); |
|
|
|
|
// 使用Map存储不同类型的能源DTO
|
|
|
|
|
Map<String, OverviewEnergyDTO> energyMap = new HashMap<>(); |
|
|
|
|
energyMap.put("16", new OverviewEnergyDTO()); |
|
|
|
|
energyMap.put("17", new OverviewEnergyDTO()); |
|
|
|
|
energyMap.put("18", new OverviewEnergyDTO()); |
|
|
|
|
energyMap.put("19", new OverviewEnergyDTO()); |
|
|
|
|
|
|
|
|
|
for (String paramType : paramTypes) { |
|
|
|
|
List<ColumnFilter> dataList = new ArrayList<>(); |
|
|
|
|
for (SysDictData sysDictData : sysTypeData) { |
|
|
|
|
String sysType = sysDictData.getDictValue(); |
|
|
|
|
// 查询采集参数
|
|
|
|
|
List<CollectionParamsManage> collectionParamsManages = queryCollectionParams(paramType, sysType, 40); |
|
|
|
|
// 合并数据
|
|
|
|
|
if (collectionParamsManages != null && !collectionParamsManages.isEmpty()) { |
|
|
|
|
List<ColumnFilter> columnFilters = overviewMapper.energyAnalysis(collectionParamsManages); |
|
|
|
|
dataList.addAll(columnFilters); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 初始化能源数据
|
|
|
|
|
initialEnergyData(dataList, energyMap.get(paramType), getEnergyLabel(paramType), getEnergyUnit(paramType), result); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
return result.isEmpty() ? List.of() : result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<CollectionParamsManage> queryCollectionParams(String paramType, String sysType, int grade) { |
|
|
|
|
QueryWrapper<CollectionParamsManage> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.eq("param_type", paramType) |
|
|
|
|
.eq("system_type", sysType) |
|
|
|
|
.eq("grade", grade); |
|
|
|
|
|
|
|
|
|
// 先查询总表
|
|
|
|
|
queryWrapper.eq("mt_is_sum", 0); |
|
|
|
|
Long count = collectionParamsManageMapper.selectCount(queryWrapper); |
|
|
|
|
if (count > 0) { |
|
|
|
|
return collectionParamsManageMapper.selectList(queryWrapper); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 查询分表
|
|
|
|
|
queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.eq("param_type", paramType) |
|
|
|
|
.eq("system_type", sysType) |
|
|
|
|
.eq("grade", grade) |
|
|
|
|
.eq("mt_is_sum", 1); |
|
|
|
|
return collectionParamsManageMapper.selectList(queryWrapper); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String getEnergyLabel(String paramType) { |
|
|
|
|
switch (paramType) { |
|
|
|
|
case "16": |
|
|
|
|
return "总用电量"; |
|
|
|
|
case "17": |
|
|
|
|
return "总产冷量"; |
|
|
|
|
case "18": |
|
|
|
|
return "总用水量"; |
|
|
|
|
case "19": |
|
|
|
|
return "总用气量"; |
|
|
|
|
default: |
|
|
|
|
throw new IllegalArgumentException("Invalid param type: " + paramType); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String getEnergyUnit(String paramType) { |
|
|
|
|
switch (paramType) { |
|
|
|
|
case "16": |
|
|
|
|
return "kw/h"; |
|
|
|
|
case "17": |
|
|
|
|
return "kw"; |
|
|
|
|
case "18": |
|
|
|
|
return "t"; |
|
|
|
|
case "19": |
|
|
|
|
return "t"; |
|
|
|
|
default: |
|
|
|
|
throw new IllegalArgumentException("Invalid param type: " + paramType); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void initialEnergyData(List<ColumnFilter> dataList, |
|
|
|
|
OverviewEnergyDTO ele, |
|
|
|
|
String paramTypeName, |
|
|
|
|
String unitName, |
|
|
|
|
List<OverviewEnergyDTO> result) { |
|
|
|
|
if (!dataList.isEmpty()) { |
|
|
|
|
// 根据时间分组,求和取总和,再根据时间升序排序
|
|
|
|
|
// 使用LinkedHashMap保持时间顺序
|
|
|
|
|
LinkedHashMap<String, Double> eleMap = dataList.stream() |
|
|
|
|
.sorted(Comparator.comparing(ColumnFilter::getName)) // 按时间字段排序
|
|
|
|
|
.collect(Collectors.groupingBy( |
|
|
|
|
ColumnFilter::getName, |
|
|
|
|
LinkedHashMap::new, |
|
|
|
|
Collectors.summingDouble(value -> |
|
|
|
|
new BigDecimal(value.getValue()).doubleValue()) |
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
// 提取时间序列和数值序列
|
|
|
|
|
String[] timeArray = eleMap.keySet().toArray(new String[0]); |
|
|
|
|
String[] valueArray = eleMap.values().stream() |
|
|
|
|
.map(d -> String.format("%.2f", d)) // 保留两位小数
|
|
|
|
|
.toArray(String[]::new); |
|
|
|
|
|
|
|
|
|
// 设置到对象中
|
|
|
|
|
ele.setName(paramTypeName); |
|
|
|
|
ele.setUnit(unitName); |
|
|
|
|
ele.setTimeStr(timeArray); |
|
|
|
|
ele.setData(valueArray); |
|
|
|
|
result.add(ele); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -85,6 +326,10 @@ public class ProOverviewServiceImpl implements IProOverviewService {
|
|
|
|
|
yearGas); |
|
|
|
|
} else { |
|
|
|
|
// 查询分表综合
|
|
|
|
|
queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.eq("param_type", paramType); |
|
|
|
|
queryWrapper.eq("system_type", sysType); |
|
|
|
|
queryWrapper.eq("grade", 40); |
|
|
|
|
queryWrapper.eq("mt_is_sum", 1); |
|
|
|
|
// 查询分表总和
|
|
|
|
|
getTotalData(paramType, queryWrapper, |
|
|
|
|