Browse Source

1、冷源瞬时冷量、累计冷量计算

dev_bl_eems
3067418132@qq.com 4 weeks ago
parent
commit
f15bc6056f
  1. 155
      mh-quartz/src/main/java/com/mh/quartz/task/GetOtherSysDataJob.java

155
mh-quartz/src/main/java/com/mh/quartz/task/GetOtherSysDataJob.java

@ -62,6 +62,12 @@ public class GetOtherSysDataJob {
"PowerTotal" // 机房累计读数
};
//TODO 冷源制冷量
private final String[] coolingSourceMeters = new String[]{
"ColdRealLoadKW", // 瞬时冷量
"ColdRealLoadTONTatol" // 累计冷量
};
//TODO 主机总电表
private final String[] powerMeters = new String[]{
"ChPower", // 主机实时功率
@ -129,7 +135,7 @@ public class GetOtherSysDataJob {
List<String> cumulativeMtCodes = new ArrayList<>(); // grade=40
List<String> powerMtCodes = new ArrayList<>(); // grade=140
HashMap<String, String> mtCodeToOtherNameMap = new HashMap<>(); // mtCode到otherName的映射
for (CollectionParamsManage param : collectionParamsManages) {
if (param.getGrade() != null && param.getMtCode() != null) {
// 建立mtCode到otherName的映射关系
@ -138,10 +144,12 @@ public class GetOtherSysDataJob {
}
// 判断如果等于totalMeters、powerMeters、freezePumpMeters、coolPumpMeters、towerMeters的点位,就下一个循环
if (totalMeters[0].equals(param.getMtCode()) || totalMeters[1].equals(param.getMtCode()) ||
powerMeters[0].equals(param.getMtCode()) || powerMeters[1].equals(param.getMtCode()) ||
freezePumpMeters[0].equals(param.getMtCode()) || freezePumpMeters[1].equals(param.getMtCode()) ||
coolPumpMeters[0].equals(param.getMtCode()) || coolPumpMeters[1].equals(param.getMtCode()) ||
towerMeters[0].equals(param.getMtCode()) || towerMeters[1].equals(param.getMtCode())) {
powerMeters[0].equals(param.getMtCode()) || powerMeters[1].equals(param.getMtCode()) ||
freezePumpMeters[0].equals(param.getMtCode()) || freezePumpMeters[1].equals(param.getMtCode()) ||
coolPumpMeters[0].equals(param.getMtCode()) || coolPumpMeters[1].equals(param.getMtCode()) ||
towerMeters[0].equals(param.getMtCode()) || towerMeters[1].equals(param.getMtCode()) ||
coolingSourceMeters[0].equals(param.getMtCode()) || coolingSourceMeters[1].equals(param.getMtCode())
) {
continue;
}
@ -170,7 +178,7 @@ public class GetOtherSysDataJob {
return fetchCumulativeData(finalCumulativeMtCodes, finalMtCodeToOtherNameMap, finalRealUrl);
}, executor);
}
// 并发请求功率读数 (grade=140)
if (!powerMtCodes.isEmpty()) {
final List<String> finalPowerMtCodes = new ArrayList<>(powerMtCodes);
@ -182,46 +190,46 @@ public class GetOtherSysDataJob {
return fetchPowerData(finalPowerMtCodes, finalMtCodeToOtherNameMap, finalRealValuesUrl);
}, executor);
}
// 等待两个任务完成并合并结果
try {
List<AdvantechDatas<BigDecimal>> cumulativeDatas = null;
List<AdvantechDatas<BigDecimal>> powerDatas = null;
if (cumulativeFuture != null) {
cumulativeDatas = cumulativeFuture.get(30, TimeUnit.SECONDS);
log.info("累计读数获取完成,数据点数: {}", cumulativeDatas.size());
}
if (powerFuture != null) {
powerDatas = powerFuture.get(30, TimeUnit.SECONDS);
log.info("功率读数获取完成,数据点数: {}", powerDatas.size());
}
// 合并累计读数和功率读数后进行汇总计算
if (cumulativeDatas != null && !cumulativeDatas.isEmpty()) {
// 将功率读数添加到累计读数列表中,以便一起进行汇总计算
if (powerDatas != null && !powerDatas.isEmpty()) {
cumulativeDatas.addAll(powerDatas);
}
// 计算汇总数据并添加到cumulativeDatas(包括累计读数和瞬时功率的汇总)
try {
calculateAndAddSummaryData(cumulativeDatas, mtCodeToOtherNameMap);
} catch (Exception e) {
log.error("数据汇总计算异常,但不影响后续流程", e);
}
allAdvantechDatas.addAll(cumulativeDatas);
} else if (powerDatas != null && !powerDatas.isEmpty()) {
// 如果只有功率读数,直接添加
allAdvantechDatas.addAll(powerDatas);
}
} catch (Exception e) {
log.error("等待异步任务完成时异常", e);
}
// 封装成研华网关格式并发送到消息队列
if (!allAdvantechDatas.isEmpty()) {
AdvantechReceiver advantechReceiver = new AdvantechReceiver();
@ -235,15 +243,16 @@ public class GetOtherSysDataJob {
} else {
log.warn("没有获取到任何BSD数据");
}
} catch (Exception e) {
log.error("获取BSD数据异常", e);
}
}
/**
* 计算并添加汇总数据到cumulativeDatas
* @param cumulativeDatas 累计读数数据列表
*
* @param cumulativeDatas 累计读数数据列表
* @param mtCodeToOtherNameMap mtCode到otherName的映射关系
*/
private void calculateAndAddSummaryData(List<AdvantechDatas<BigDecimal>> cumulativeDatas, HashMap<String, String> mtCodeToOtherNameMap) {
@ -259,46 +268,129 @@ public class GetOtherSysDataJob {
CHWP_POWER("冷冻泵", "瞬时功率", "PriChWPPower", "冷冻泵总瞬时功率"),
CWP_POWER("冷却泵", "瞬时功率", "CWPPower", "冷却泵总瞬时功率"),
CT_POWER("冷却塔", "瞬时功率", "CTPower", "冷却塔总瞬时功率"),
// 冷源瞬时冷量(特殊计算:SystemRealLoadTON - HPSystemRealLoadTON)
CH_COLD_INSTANT("冷源", "瞬时冷量", "ColdRealLoadKW", "冷源总冷量计瞬时冷量", true),
ALL_COLD_INSTANT("冷源", "累计冷量", "ColdRealLoadTONTatol", "冷源总冷量计读数TON", true),
ALL_POWER(null, "瞬时功率", "Power", "机房总瞬时功率");
private final String deviceKeyword;
private final String dataKeyword;
private final String mtCode;
private final String description;
private final boolean isColdCalculation; // 标记是否为冷量计算(需要用减法)
SummaryType(String deviceKeyword, String dataKeyword, String mtCode, String description) {
this(deviceKeyword, dataKeyword, mtCode, description, false);
}
SummaryType(String deviceKeyword, String dataKeyword, String mtCode, String description, boolean isColdCalculation) {
this.deviceKeyword = deviceKeyword;
this.dataKeyword = dataKeyword;
this.mtCode = mtCode;
this.description = description;
this.isColdCalculation = isColdCalculation;
}
}
// 一次性遍历cumulativeDatas,分类累加各类型数据
Map<SummaryType, BigDecimal> summaryMap = new HashMap<>();
// 缓存原始数据,用于冷量差值计算(按tag缓存)
Map<String, BigDecimal> dataByTag = new HashMap<>();
// 初始化所有汇总类型
for (SummaryType type : SummaryType.values()) {
summaryMap.put(type, BigDecimal.ZERO);
}
for (AdvantechDatas data : cumulativeDatas) {
if (data.getTag() == null || data.getValue() == null) {
continue;
}
String tag = data.getTag();
BigDecimal value = new BigDecimal(data.getValue().toString());
// 缓存所有数据,用于冷量计算
dataByTag.put(tag, value);
// 遍历所有汇总类型进行匹配
for (SummaryType type : SummaryType.values()) {
boolean matchesDataKeyword = tag.contains(type.dataKeyword);
boolean matchesDeviceKeyword = type.deviceKeyword == null || tag.contains(type.deviceKeyword);
if (matchesDataKeyword && matchesDeviceKeyword) {
summaryMap.merge(type, value, BigDecimal::add);
// 冷量计算类型不进行累加,使用差值计算
if (!type.isColdCalculation) {
summaryMap.merge(type, value, BigDecimal::add);
}
}
}
}
// 对冷量计算类型执行差值计算
try {
// 从缓存中查找冷量相关数据
BigDecimal hpSystemRealLoadTONTatol = null; // 热泵累计冷量
BigDecimal hpSystemRealLoadTON = null; // 热泵瞬时冷量
BigDecimal systemRealLoadTON = null; // 系统瞬时冷量
BigDecimal systemRealLoadTONTatol = null; // 系统累计冷量
// 查找 hpSystemRealLoadTONTatol
for (Map.Entry<String, BigDecimal> entry : dataByTag.entrySet()) {
if (entry.getKey().contains("HPSystemRealLoadTONTatol")) {
hpSystemRealLoadTONTatol = entry.getValue();
break;
}
}
// 查找 HPSystemRealLoadTON
for (Map.Entry<String, BigDecimal> entry : dataByTag.entrySet()) {
if (entry.getKey().contains("HPSystemRealLoadTON")) {
hpSystemRealLoadTON = entry.getValue();
break;
}
}
// 查找 systemRealLoadTON
for (Map.Entry<String, BigDecimal> entry : dataByTag.entrySet()) {
if (entry.getKey().contains("SystemRealLoadTON")) {
systemRealLoadTON = entry.getValue();
break;
}
}
// 查找 SystemRealLoadTONTatol
for (Map.Entry<String, BigDecimal> entry : dataByTag.entrySet()) {
if (entry.getKey().contains("SystemRealLoadTONTatol")) {
systemRealLoadTONTatol = entry.getValue();
break;
}
}
// 计算瞬时冷量:systemRealLoadTON - HPSystemRealLoadTON
if (systemRealLoadTON != null && hpSystemRealLoadTON != null) {
BigDecimal coldRealLoadKW = systemRealLoadTON.subtract(hpSystemRealLoadTON);
summaryMap.put(SummaryType.CH_COLD_INSTANT, coldRealLoadKW);
log.info("计算瞬时冷量: {} - {} = {}", systemRealLoadTON, hpSystemRealLoadTON, coldRealLoadKW);
} else {
log.warn("瞬时冷量计算缺少必要数据,SystemRealLoadTON: {}, HPSystemRealLoadTON: {}",
systemRealLoadTON, hpSystemRealLoadTON);
}
// 计算累计冷量:SystemRealLoadTONTatol - HPSystemRealLoadTONTatol
if (systemRealLoadTONTatol != null && hpSystemRealLoadTONTatol != null) {
BigDecimal coldRealLoadTONTatol = systemRealLoadTONTatol.subtract(hpSystemRealLoadTONTatol);
summaryMap.put(SummaryType.ALL_COLD_INSTANT, coldRealLoadTONTatol);
log.info("计算累计冷量: {} - {} = {}", systemRealLoadTONTatol, hpSystemRealLoadTONTatol, coldRealLoadTONTatol);
} else {
log.warn("累计冷量计算缺少必要数据,SystemRealLoadTONTatol: {}, HPSystemRealLoadTONTatol: {}",
systemRealLoadTONTatol, hpSystemRealLoadTONTatol);
}
} catch (Exception e) {
log.error("计算冷量差值异常", e);
}
// 创建并添加汇总数据点
int successCount = 0;
for (SummaryType type : SummaryType.values()) {
@ -317,15 +409,16 @@ public class GetOtherSysDataJob {
log.error("添加{}失败", type.description, e);
}
}
log.info("数据汇总完成,成功添加{}/{}个汇总数据点", successCount, SummaryType.values().length);
}
/**
* 获取累计读数数据
* @param mtCodes 点位编码列表
*
* @param mtCodes 点位编码列表
* @param mtCodeToOtherNameMap mtCode到otherName的映射关系
* @param realUrl 请求URL
* @param realUrl 请求URL
* @return 解析后的数据列表
*/
private List<AdvantechDatas<BigDecimal>> fetchCumulativeData(List<String> mtCodes, HashMap<String, String> mtCodeToOtherNameMap, String realUrl) {
@ -383,9 +476,9 @@ public class GetOtherSysDataJob {
/**
* 获取功率读数数据
*
* @param mtCodes 点位编码列表
* @param mtCodes 点位编码列表
* @param mtCodeToOtherNameMap mtCode到otherName的映射关系
* @param realValuesUrl 请求URL
* @param realValuesUrl 请求URL
* @return 解析后的数据列表
*/
private List<AdvantechDatas<BigDecimal>> fetchPowerData(List<String> mtCodes, HashMap<String, String> mtCodeToOtherNameMap, String realValuesUrl) {

Loading…
Cancel
Save