Compare commits
50 Commits
2d3222e03d
...
2025-11
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
770fb09223 | ||
|
|
eb334cc7c7 | ||
|
|
404d11526a | ||
| 7bac805988 | |||
|
|
e4e04fc5db | ||
| f588a0ffc8 | |||
| f8ffe767dc | |||
|
|
68cbad2fdb | ||
|
|
9b9d75e463 | ||
|
|
62c3c09a6b | ||
|
|
b523a24e5b | ||
|
|
075dfc19d6 | ||
|
|
279c5c7642 | ||
|
|
ff1351b107 | ||
|
|
2dd67f9e3a | ||
|
|
b0ef851479 | ||
|
|
be899a262b | ||
| 4339a37268 | |||
|
|
9659aa257a | ||
| 9d32ca05df | |||
|
|
d48cf09119 | ||
|
|
c38b07ec07 | ||
|
|
87f05c6278 | ||
| e9ac024f73 | |||
| b7e3bb9796 | |||
| 4bebf28b76 | |||
|
|
20ec9bc0b4 | ||
| 5e93eb3691 | |||
| b63fab9085 | |||
|
|
aba66aaf4a | ||
|
|
1c7c514691 | ||
| 04fe9bdbbd | |||
|
|
b41347c596 | ||
|
|
4f75deac43 | ||
| 2c68646fc9 | |||
| 02599eeb81 | |||
| 0cec471ce2 | |||
|
|
102bab7430 | ||
| 28378dcfa1 | |||
| 1692799f0b | |||
| 90471c368d | |||
| 08ec8591f1 | |||
| d038dfe655 | |||
| c1bf8d79ce | |||
| 74420e7107 | |||
|
|
6815e1df4b | ||
|
|
c1dca815e7 | ||
|
|
5c3baf4e57 | ||
|
|
28f7e038ce | ||
| fe1195b7b5 |
6
pom.xml
6
pom.xml
@@ -41,9 +41,9 @@
|
||||
<properties>
|
||||
<!--中间件目标地址-->
|
||||
<!-- <middle.server.url>10.95.53.49</middle.server.url>-->
|
||||
<middle.server.url>192.168.1.22</middle.server.url>
|
||||
<middle.server.url>192.168.1.103</middle.server.url>
|
||||
<!--微服务模块发布地址-->
|
||||
<service.server.url>192.168.1.127</service.server.url>
|
||||
<service.server.url>127.0.0.1</service.server.url>
|
||||
<!--docker仓库地址-->
|
||||
<docker.server.url>192.168.1.22</docker.server.url>
|
||||
<!--nacos的ip:port-->
|
||||
@@ -55,7 +55,7 @@
|
||||
<!--服务器发布内容为空-->
|
||||
<!-- <nacos.namespace></nacos.namespace>-->
|
||||
<!-- <nacos.namespace>30c701c4-2a94-49d9-82e1-76aa9456573f</nacos.namespace>-->
|
||||
<nacos.namespace>78588706-e06f-4580-b612-b26d72493fcb</nacos.namespace>
|
||||
<nacos.namespace>6fd2d036-f390-46ee-9c9d-d5a5c00e3314</nacos.namespace>
|
||||
<!-- <nacos.namespace>910d0d69-2254-481b-b9f7-7ecf9cb881b0</nacos.namespace>-->
|
||||
<!-- sentinel:port-->
|
||||
<sentinel.url>${middle.server.url}:8080</sentinel.url>
|
||||
|
||||
@@ -264,7 +264,7 @@ public class AnalyWave {
|
||||
break;
|
||||
case 1:// 总点数 //这里的strTemp是一个偏移量
|
||||
OneRate.nSampleNum = (long) (Float.parseFloat(strTempArray[j]) - nOffset);
|
||||
nOffset = OneRate.nSampleNum;
|
||||
nOffset += OneRate.nSampleNum;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,9 @@ public interface QvvrCauseDLL extends Library {
|
||||
|
||||
// 创建临时文件
|
||||
String tempDir = System.getProperty("java.io.tmpdir");
|
||||
File tempLibFile = new File(tempDir, "qvvr_" + System.currentTimeMillis() + "_" + libFileName);
|
||||
File tempLibFile = new File(tempDir, libFileName);
|
||||
|
||||
//File tempLibFile = new File(tempDir, "qvvr_" + System.currentTimeMillis() + "_" + libFileName);
|
||||
|
||||
// 提取库文件到临时目录
|
||||
try (FileOutputStream out = new FileOutputStream(tempLibFile)) {
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package com.njcn.advance.event.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.njcn.advance.event.cause.core.VoltageSagAnalyzer;
|
||||
import com.njcn.advance.event.cause.jna.QvvrCauseDLL;
|
||||
import com.njcn.advance.event.cause.model.AnalysisResult;
|
||||
import com.njcn.advance.event.cause.model.DataFeature;
|
||||
import com.njcn.advance.event.cause.model.QvvrDataStruct;
|
||||
import com.njcn.advance.event.type.jna.*;
|
||||
import com.njcn.advance.pojo.dto.EventAnalysisDTO;
|
||||
import com.njcn.advance.event.service.IEventAdvanceService;
|
||||
import com.njcn.advance.event.type.jna.QvvrDLL;
|
||||
import com.njcn.common.config.GeneralInfo;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.event.file.component.WaveFileComponent;
|
||||
@@ -89,8 +86,55 @@ public class EventAdvanceServiceImpl implements IEventAdvanceService {
|
||||
}
|
||||
}
|
||||
List<List<Float>> listWaveData = waveDataDTO.getListWaveData();
|
||||
// 暂降类型
|
||||
// 创建数据结构
|
||||
QvvrDLL.QvvrDataStruct typeDataStruct = new QvvrDLL.QvvrDataStruct();
|
||||
System.out.println("初始化qvvrdll成功-----------");
|
||||
typeDataStruct.smp_rate = waveDataDTO.getComtradeCfgDTO().getFinalSampleRate();
|
||||
System.out.println("采样率-----------" + typeDataStruct.smp_rate);
|
||||
typeDataStruct.smp_len = listWaveData.size();
|
||||
System.out.println("波形长度-----------" + listWaveData.size());
|
||||
|
||||
// 获取ABC三相的瞬时数据
|
||||
for (int i = 0; i < listWaveData.size(); i++) {
|
||||
typeDataStruct.smp_va[i] = listWaveData.get(i).get(1);
|
||||
typeDataStruct.smp_vb[i] = listWaveData.get(i).get(2);
|
||||
typeDataStruct.smp_vc[i] = listWaveData.get(i).get(3);
|
||||
}
|
||||
|
||||
|
||||
// 执行算法分析 - 直接调用C DLL
|
||||
try {
|
||||
QvvrDLL.INSTANCE.qvvr_fun(typeDataStruct);
|
||||
System.out.println("调用qvvrdll成功-----------");
|
||||
|
||||
if (typeDataStruct.evt_num > 0) {
|
||||
// 全局比较找出最小三相电压特征值
|
||||
float globalMinVoltage = Float.MAX_VALUE;
|
||||
int globalFaultType = 10;
|
||||
for (int i = 0; i < typeDataStruct.evt_num; i++) {
|
||||
QvvrDLL.EventBuffer evt = typeDataStruct.evt_buf[i];
|
||||
for (int j = 0; j < evt.u_min_num; j++) {
|
||||
float u3min = evt.u3_min[j];
|
||||
if (u3min < globalMinVoltage) {
|
||||
globalMinVoltage = u3min;
|
||||
globalFaultType = evt.qvvr_cata_type[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
eventAnalysis.setType(globalFaultType);
|
||||
} else {
|
||||
eventAnalysis.setType(DataFeature.TYPE10);
|
||||
}
|
||||
System.out.println("结束qvvrdll方法调用-----------");
|
||||
} catch (Exception e) {
|
||||
eventAnalysis.setType(DataFeature.TYPE10);
|
||||
eventAnalysis.setTypeFlag(0);
|
||||
}
|
||||
|
||||
|
||||
// 暂降原因JNA的方式
|
||||
com.njcn.advance.event.cause.jna.QvvrCauseDLL.QvvrDataStruct causeDataStruct = new com.njcn.advance.event.cause.jna.QvvrCauseDLL.QvvrDataStruct();
|
||||
QvvrCauseDLL.QvvrDataStruct causeDataStruct = new QvvrCauseDLL.QvvrDataStruct();
|
||||
causeDataStruct.smp_rate = waveDataDTO.getComtradeCfgDTO().getFinalSampleRate();
|
||||
causeDataStruct.smp_len = listWaveData.size();
|
||||
// 获取ABC三相的瞬时数据
|
||||
@@ -112,45 +156,6 @@ public class EventAdvanceServiceImpl implements IEventAdvanceService {
|
||||
}
|
||||
System.out.println("暂降原因分析完毕===============");
|
||||
System.out.println("cause:" + eventAnalysis);
|
||||
|
||||
// 暂降类型
|
||||
// 创建数据结构
|
||||
// com.njcn.advance.event.type.jna.QvvrDLL.QvvrDataStruct typeDataStruct = new com.njcn.advance.event.type.jna.QvvrDLL.QvvrDataStruct();
|
||||
// typeDataStruct.smp_rate = waveDataDTO.getComtradeCfgDTO().getFinalSampleRate();
|
||||
// typeDataStruct.smp_len = listWaveData.size();
|
||||
// // 获取ABC三相的瞬时数据
|
||||
// for (int i = 0; i < listWaveData.size(); i++) {
|
||||
// typeDataStruct.smp_va[i] = listWaveData.get(i).get(1);
|
||||
// typeDataStruct.smp_vb[i] = listWaveData.get(i).get(2);
|
||||
// typeDataStruct.smp_vc[i] = listWaveData.get(i).get(3);
|
||||
// }
|
||||
// // 执行算法分析 - 直接调用C DLL
|
||||
// try {
|
||||
// QvvrDLL.INSTANCE.qvvr_fun(typeDataStruct);
|
||||
// if (typeDataStruct.evt_num > 0) {
|
||||
// // 全局比较找出最小三相电压特征值
|
||||
// float globalMinVoltage = Float.MAX_VALUE;
|
||||
// int globalFaultType = 10;
|
||||
// for (int i = 0; i < typeDataStruct.evt_num; i++) {
|
||||
// QvvrDLL.EventBuffer evt = typeDataStruct.evt_buf[i];
|
||||
// for (int j = 0; j < evt.u_min_num; j++) {
|
||||
// float u3min = evt.u3_min[j];
|
||||
// if (u3min < globalMinVoltage) {
|
||||
// globalMinVoltage = u3min;
|
||||
// globalFaultType = evt.qvvr_cata_type[j];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// eventAnalysis.setType(globalFaultType);
|
||||
// } else {
|
||||
// eventAnalysis.setType(DataFeature.TYPE10);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// eventAnalysis.setType(DataFeature.TYPE10);
|
||||
// eventAnalysis.setTypeFlag(0);
|
||||
// }
|
||||
return eventAnalysis;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public interface QvvrDLL extends Library {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从jar中提取库文件到临时目录
|
||||
*/
|
||||
@@ -62,11 +62,13 @@ public interface QvvrDLL extends Library {
|
||||
if (libStream == null) {
|
||||
throw new FileNotFoundException("在jar中找不到库文件: " + resourcePath);
|
||||
}
|
||||
|
||||
|
||||
// 创建临时文件
|
||||
String tempDir = System.getProperty("java.io.tmpdir");
|
||||
File tempLibFile = new File(tempDir, "qvvr_" + System.currentTimeMillis() + "_" + libFileName);
|
||||
|
||||
File tempLibFile = new File(tempDir, libFileName);
|
||||
|
||||
// File tempLibFile = new File(tempDir, "qvvr_" + System.currentTimeMillis() + "_" + libFileName);
|
||||
|
||||
// 提取库文件到临时目录
|
||||
try (FileOutputStream out = new FileOutputStream(tempLibFile)) {
|
||||
byte[] buffer = new byte[8192];
|
||||
@@ -77,45 +79,47 @@ public interface QvvrDLL extends Library {
|
||||
} finally {
|
||||
libStream.close();
|
||||
}
|
||||
|
||||
|
||||
// 设置为可执行
|
||||
tempLibFile.setExecutable(true);
|
||||
tempLibFile.setReadable(true);
|
||||
|
||||
|
||||
// JVM退出时删除临时文件
|
||||
tempLibFile.deleteOnExit();
|
||||
|
||||
|
||||
System.out.println("已提取库文件到: " + tempLibFile.getAbsolutePath());
|
||||
return tempLibFile;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 直接调用C DLL的qvvr_fun函数
|
||||
* void __stdcall qvvr_fun(void *data)
|
||||
*/
|
||||
void qvvr_fun(QvvrDataStruct data);
|
||||
|
||||
|
||||
void ping();
|
||||
|
||||
/**
|
||||
* 对应C语言的qvvr_data_struct结构体
|
||||
*/
|
||||
public static class QvvrDataStruct extends Structure {
|
||||
|
||||
|
||||
// 输入数据
|
||||
public float[] smp_va = new float[128 * 50 * 120]; // A相电压
|
||||
public float[] smp_vb = new float[128 * 50 * 120]; // B相电压
|
||||
public float[] smp_vb = new float[128 * 50 * 120]; // B相电压
|
||||
public float[] smp_vc = new float[128 * 50 * 120]; // C相电压
|
||||
public int smp_rate; // 采样频率
|
||||
public int smp_len; // 数据长度
|
||||
|
||||
|
||||
// 输出结果
|
||||
public int evt_num; // 事件数量
|
||||
public EventBuffer[] evt_buf = new EventBuffer[32]; // 事件缓冲区
|
||||
|
||||
|
||||
@Override
|
||||
protected List<String> getFieldOrder() {
|
||||
return Arrays.asList("smp_va", "smp_vb", "smp_vc", "smp_rate", "smp_len", "evt_num", "evt_buf");
|
||||
}
|
||||
|
||||
|
||||
public QvvrDataStruct() {
|
||||
super();
|
||||
// 初始化事件缓冲区
|
||||
@@ -124,49 +128,49 @@ public interface QvvrDLL extends Library {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 事件缓冲区结构
|
||||
*/
|
||||
public static class EventBuffer extends Structure {
|
||||
public int[] qvvr_cata_cause = new int[256];
|
||||
public int[] qvvr_phasetype = new int[256];
|
||||
public int[] qvvr_phasetype = new int[256];
|
||||
public int[] qvvr_cata_type = new int[256];
|
||||
|
||||
|
||||
public float hold_time_rms;
|
||||
public float hold_time_dq;
|
||||
|
||||
|
||||
public float POW_a;
|
||||
public float POW_b;
|
||||
public float POW_c;
|
||||
|
||||
|
||||
public float Voltagechange_Va;
|
||||
public float Voltagechange_Vb;
|
||||
public float Voltagechange_Vc;
|
||||
|
||||
|
||||
public int SEG_T_num;
|
||||
public int[] SEG_T0_idx = new int[256];
|
||||
public int[] SEG_T_idx = new int[256];
|
||||
|
||||
|
||||
public int SEG_RMS_T_num;
|
||||
public int[] SEG_RMS_T_idx = new int[256];
|
||||
|
||||
|
||||
public int u_min_num;
|
||||
public float[] ua_min = new float[256];
|
||||
public float[] ub_min = new float[256];
|
||||
public float[] ub_min = new float[256];
|
||||
public float[] uc_min = new float[256];
|
||||
public float[] u3_min = new float[256];
|
||||
public int[] order_min_idx = new int[256];
|
||||
|
||||
|
||||
public float[] angle_diff_ap = new float[256];
|
||||
public float[] angle_diff_bp = new float[256];
|
||||
public float[] angle_diff_cp = new float[256];
|
||||
public float[] angle_diff_an = new float[256];
|
||||
public float[] angle_diff_bn = new float[256];
|
||||
public float[] angle_diff_cn = new float[256];
|
||||
|
||||
|
||||
public float[] bph_max_value = new float[256];
|
||||
|
||||
|
||||
@Override
|
||||
protected List<String> getFieldOrder() {
|
||||
return Arrays.asList(
|
||||
|
||||
@@ -0,0 +1,381 @@
|
||||
package com.njcn.advance.responsibility.analysis;
|
||||
|
||||
import com.njcn.advance.responsibility.constant.HarmonicConstants;
|
||||
import com.njcn.advance.responsibility.utils.MathUtils;
|
||||
import org.apache.commons.math3.linear.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 典则相关分析类
|
||||
* 实现典则相关系数的计算
|
||||
*
|
||||
* @author hongawen
|
||||
* @version 1.0
|
||||
*/
|
||||
public class CanonicalCorrelationAnalysis {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CanonicalCorrelationAnalysis.class);
|
||||
|
||||
/**
|
||||
* 计算典则相关系数
|
||||
* 对应C代码中的TransCancor函数
|
||||
*
|
||||
* @param powerData 功率数据矩阵 [时间][节点]
|
||||
* @param harmonicData 谐波数据向量
|
||||
* @param windowSize 窗口大小
|
||||
* @param nodeCount 节点数量
|
||||
* @return 典则相关系数
|
||||
*/
|
||||
public static float computeCanonicalCorrelation(float[][] powerData, float[] harmonicData,
|
||||
int windowSize, int nodeCount) {
|
||||
logger.info("===== 开始典型相关分析 =====");
|
||||
logger.info("输入参数: windowSize={}, nodeCount={}", windowSize, nodeCount);
|
||||
|
||||
try {
|
||||
// 提取窗口数据
|
||||
double[][] x = new double[windowSize][nodeCount];
|
||||
double[] y = new double[windowSize];
|
||||
|
||||
// ===== 数据质量统计(只统计,不影响计算) =====
|
||||
int nanCountPower = 0, infiniteCountPower = 0, zeroCountPower = 0;
|
||||
int nanCountHarmonic = 0, infiniteCountHarmonic = 0, zeroCountHarmonic = 0;
|
||||
double powerSum = 0, harmonicSum = 0;
|
||||
double powerMin = Double.MAX_VALUE, powerMax = -Double.MAX_VALUE;
|
||||
double harmonicMin = Double.MAX_VALUE, harmonicMax = -Double.MAX_VALUE;
|
||||
|
||||
for (int i = 0; i < windowSize; i++) {
|
||||
for (int j = 0; j < nodeCount; j++) {
|
||||
float val = powerData[i][j];
|
||||
x[i][j] = val;
|
||||
|
||||
// 仅统计,不改变原逻辑
|
||||
if (Float.isNaN(val)) {
|
||||
nanCountPower++;
|
||||
} else if (Float.isInfinite(val)) {
|
||||
infiniteCountPower++;
|
||||
} else if (val == 0.0f) {
|
||||
zeroCountPower++;
|
||||
} else {
|
||||
powerSum += val;
|
||||
powerMin = Math.min(powerMin, val);
|
||||
powerMax = Math.max(powerMax, val);
|
||||
}
|
||||
}
|
||||
|
||||
float harmonicVal = harmonicData[i];
|
||||
y[i] = harmonicVal;
|
||||
|
||||
// 仅统计,不改变原逻辑
|
||||
if (Float.isNaN(harmonicVal)) {
|
||||
nanCountHarmonic++;
|
||||
} else if (Float.isInfinite(harmonicVal)) {
|
||||
infiniteCountHarmonic++;
|
||||
} else if (harmonicVal == 0.0f) {
|
||||
zeroCountHarmonic++;
|
||||
} else {
|
||||
harmonicSum += harmonicVal;
|
||||
harmonicMin = Math.min(harmonicMin, harmonicVal);
|
||||
harmonicMax = Math.max(harmonicMax, harmonicVal);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 数据质量报告(只记录日志) =====
|
||||
int totalPowerCount = windowSize * nodeCount;
|
||||
int totalHarmonicCount = windowSize;
|
||||
|
||||
logger.info("功率数据质量分析:");
|
||||
logger.info(" 总数据点: {}", totalPowerCount);
|
||||
logger.info(" NaN数量: {} ({:.2f}%)", nanCountPower, nanCountPower * 100.0 / totalPowerCount);
|
||||
logger.info(" 无穷大数量: {} ({:.2f}%)", infiniteCountPower, infiniteCountPower * 100.0 / totalPowerCount);
|
||||
logger.info(" 零值数量: {} ({:.2f}%)", zeroCountPower, zeroCountPower * 100.0 / totalPowerCount);
|
||||
logger.info(" 有效数据范围: [{}, {}]", powerMin == Double.MAX_VALUE ? "N/A" : powerMin,
|
||||
powerMax == -Double.MAX_VALUE ? "N/A" : powerMax);
|
||||
|
||||
logger.info("谐波数据质量分析:");
|
||||
logger.info(" 总数据点: {}", totalHarmonicCount);
|
||||
logger.info(" NaN数量: {} ({:.2f}%)", nanCountHarmonic, nanCountHarmonic * 100.0 / totalHarmonicCount);
|
||||
logger.info(" 无穷大数量: {} ({:.2f}%)", infiniteCountHarmonic, infiniteCountHarmonic * 100.0 / totalHarmonicCount);
|
||||
logger.info(" 零值数量: {} ({:.2f}%)", zeroCountHarmonic, zeroCountHarmonic * 100.0 / totalHarmonicCount);
|
||||
logger.info(" 有效数据范围: [{}, {}]", harmonicMin == Double.MAX_VALUE ? "N/A" : harmonicMin,
|
||||
harmonicMax == -Double.MAX_VALUE ? "N/A" : harmonicMax);
|
||||
|
||||
// 只记录警告,不停止计算
|
||||
if (nanCountPower > 0 || infiniteCountPower > 0) {
|
||||
logger.warn("功率数据包含异常值!NaN: {}, Infinite: {}", nanCountPower, infiniteCountPower);
|
||||
}
|
||||
if (nanCountHarmonic > 0 || infiniteCountHarmonic > 0) {
|
||||
logger.warn("谐波数据包含异常值!NaN: {}, Infinite: {}", nanCountHarmonic, infiniteCountHarmonic);
|
||||
}
|
||||
|
||||
// 计算协方差矩阵 SXX
|
||||
logger.info("===== 开始协方差计算 =====");
|
||||
double[][] sxxMatrix = MathUtils.covarianceMatrix(x, windowSize, nodeCount);
|
||||
|
||||
// ===== SXX矩阵诊断(只记录日志)=====
|
||||
double sxxTrace = 0;
|
||||
double sxxFrobeniusNorm = 0;
|
||||
boolean sxxHasNaN = false, sxxHasInfinite = false;
|
||||
|
||||
for (int i = 0; i < nodeCount; i++) {
|
||||
sxxTrace += sxxMatrix[i][i];
|
||||
for (int j = 0; j < nodeCount; j++) {
|
||||
double val = sxxMatrix[i][j];
|
||||
if (Double.isNaN(val)) {
|
||||
sxxHasNaN = true;
|
||||
}
|
||||
if (Double.isInfinite(val)) {
|
||||
sxxHasInfinite = true;
|
||||
}
|
||||
sxxFrobeniusNorm += val * val;
|
||||
}
|
||||
}
|
||||
sxxFrobeniusNorm = Math.sqrt(sxxFrobeniusNorm);
|
||||
|
||||
logger.info("SXX矩阵诊断:");
|
||||
logger.info(" 维度: {}x{}", nodeCount, nodeCount);
|
||||
logger.info(" 迹(trace): {}", sxxTrace);
|
||||
logger.info(" Frobenius范数: {}", sxxFrobeniusNorm);
|
||||
logger.info(" 包含NaN: {}", sxxHasNaN);
|
||||
logger.info(" 包含无穷大: {}", sxxHasInfinite);
|
||||
logger.info(" 对角线元素: {}", java.util.Arrays.toString(
|
||||
java.util.stream.IntStream.range(0, nodeCount)
|
||||
.mapToDouble(i -> sxxMatrix[i][i])
|
||||
.toArray()));
|
||||
|
||||
// 计算协方差 SYY
|
||||
double syyMatrix = MathUtils.covariance(y, y, windowSize);
|
||||
logger.info("SYY协方差: {}", syyMatrix);
|
||||
|
||||
if (Math.abs(syyMatrix) < HarmonicConstants.MIN_COVARIANCE) {
|
||||
logger.warn("SYY过小 ({}), 调整为最小值: {}", syyMatrix, HarmonicConstants.MIN_COVARIANCE);
|
||||
syyMatrix = HarmonicConstants.MIN_COVARIANCE;
|
||||
}
|
||||
|
||||
// 计算协方差向量 SXY
|
||||
double[] sxyVector = MathUtils.covarianceVector(x, y, windowSize, nodeCount);
|
||||
|
||||
// ===== SXY向量诊断(只记录日志)=====
|
||||
double sxyNorm = 0;
|
||||
boolean sxyHasNaN = false, sxyHasInfinite = false;
|
||||
for (double val : sxyVector) {
|
||||
if (Double.isNaN(val)) {
|
||||
sxyHasNaN = true;
|
||||
}
|
||||
if (Double.isInfinite(val)) {
|
||||
sxyHasInfinite = true;
|
||||
}
|
||||
sxyNorm += val * val;
|
||||
}
|
||||
sxyNorm = Math.sqrt(sxyNorm);
|
||||
|
||||
logger.info("SXY向量诊断:");
|
||||
logger.info(" 长度: {}", sxyVector.length);
|
||||
logger.info(" L2范数: {}", sxyNorm);
|
||||
logger.info(" 包含NaN: {}", sxyHasNaN);
|
||||
logger.info(" 包含无穷大: {}", sxyHasInfinite);
|
||||
logger.info(" 向量值: {}", java.util.Arrays.toString(sxyVector));
|
||||
|
||||
// 使用Apache Commons Math进行矩阵运算
|
||||
logger.info("===== 开始矩阵分解 =====");
|
||||
RealMatrix sxx = new Array2DRowRealMatrix(sxxMatrix);
|
||||
RealVector sxy = new ArrayRealVector(sxyVector);
|
||||
|
||||
// 计算 SXX^(-1)
|
||||
logger.info("准备计算SXX逆矩阵...");
|
||||
DecompositionSolver solver = new LUDecomposition(sxx).getSolver();
|
||||
RealMatrix invSxx;
|
||||
|
||||
// 检查矩阵奇异性
|
||||
double sxxDet = new LUDecomposition(sxx).getDeterminant();
|
||||
logger.info("SXX矩阵行列式: {}", sxxDet);
|
||||
|
||||
if (Math.abs(sxxDet) < 1e-15) {
|
||||
logger.warn("SXX矩阵几乎奇异 (det={})", sxxDet);
|
||||
}
|
||||
|
||||
if (!solver.isNonSingular()) {
|
||||
// 如果矩阵奇异,使用伪逆
|
||||
logger.warn("SXX matrix is singular, using pseudo-inverse");
|
||||
try {
|
||||
SingularValueDecomposition svd = new SingularValueDecomposition(sxx);
|
||||
invSxx = svd.getSolver().getInverse();
|
||||
} catch (Exception svdException) {
|
||||
logger.error("SVD pseudo-inverse failed, using regularized inverse", svdException);
|
||||
// 添加正则化项
|
||||
RealMatrix identity = MatrixUtils.createRealIdentityMatrix(sxx.getRowDimension());
|
||||
RealMatrix regularized = sxx.add(identity.scalarMultiply(1e-10));
|
||||
invSxx = new LUDecomposition(regularized).getSolver().getInverse();
|
||||
}
|
||||
} else {
|
||||
invSxx = solver.getInverse();
|
||||
}
|
||||
|
||||
// 计算 U = SXX^(-1) * SXY * (1/SYY) * SXY'
|
||||
RealVector temp = invSxx.operate(sxy);
|
||||
double scale = 1.0 / syyMatrix;
|
||||
RealMatrix uMatrix = temp.outerProduct(sxy).scalarMultiply(scale);
|
||||
|
||||
// 计算特征值 - 添加数值稳定性处理
|
||||
double maxEigenvalue = 0.0;
|
||||
|
||||
try {
|
||||
// 首先检查矩阵是否有效
|
||||
double[][] uMatrixData = uMatrix.getData();
|
||||
boolean hasNaN = false;
|
||||
boolean hasInfinite = false;
|
||||
|
||||
for (int i = 0; i < uMatrixData.length; i++) {
|
||||
for (int j = 0; j < uMatrixData[i].length; j++) {
|
||||
if (Double.isNaN(uMatrixData[i][j])) {
|
||||
hasNaN = true;
|
||||
}
|
||||
if (Double.isInfinite(uMatrixData[i][j])) {
|
||||
hasInfinite = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasNaN || hasInfinite) {
|
||||
logger.warn("U matrix contains NaN or Infinite values, returning 0");
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
// 检查矩阵条件数
|
||||
SingularValueDecomposition svdCheck = new SingularValueDecomposition(uMatrix);
|
||||
double conditionNumber = svdCheck.getConditionNumber();
|
||||
|
||||
if (conditionNumber > 1e12) {
|
||||
logger.warn("U matrix is ill-conditioned (condition number: {}), using SVD approach", conditionNumber);
|
||||
|
||||
// 使用SVD方法获取最大奇异值的平方作为最大特征值
|
||||
double[] singularValues = svdCheck.getSingularValues();
|
||||
if (singularValues.length > 0) {
|
||||
maxEigenvalue = singularValues[0] * singularValues[0];
|
||||
}
|
||||
} else {
|
||||
// 正常的特征值分解
|
||||
EigenDecomposition eigenDecomposition = new EigenDecomposition(uMatrix);
|
||||
double[] eigenvalues = eigenDecomposition.getRealEigenvalues();
|
||||
|
||||
// 找最大特征值
|
||||
for (double eigenvalue : eigenvalues) {
|
||||
maxEigenvalue = Math.max(maxEigenvalue, Math.abs(eigenvalue));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception eigenException) {
|
||||
logger.warn("EigenDecomposition failed, trying alternative approach: {}", eigenException.getMessage());
|
||||
|
||||
// 备用方案:使用SVD方法
|
||||
try {
|
||||
SingularValueDecomposition svd = new SingularValueDecomposition(uMatrix);
|
||||
double[] singularValues = svd.getSingularValues();
|
||||
if (singularValues.length > 0) {
|
||||
maxEigenvalue = singularValues[0] * singularValues[0];
|
||||
}
|
||||
} catch (Exception svdException) {
|
||||
logger.error("Both EigenDecomposition and SVD failed, returning 0", svdException);
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
// 典则相关系数是最大特征值的平方根
|
||||
double canonicalCorr = Math.sqrt(Math.abs(maxEigenvalue));
|
||||
|
||||
// 限制在[0,1]范围内
|
||||
if (canonicalCorr > 1.0) {
|
||||
canonicalCorr = 1.0;
|
||||
}
|
||||
|
||||
logger.info("===== 典型相关分析计算完成 =====");
|
||||
logger.info("最大特征值: {}", maxEigenvalue);
|
||||
logger.info("典型相关系数: {}", canonicalCorr);
|
||||
logger.info("是否被截断到1.0: {}", canonicalCorr >= 1.0);
|
||||
|
||||
return (float) canonicalCorr;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error computing canonical correlation", e);
|
||||
logger.error("异常详情: {}", e.getMessage());
|
||||
logger.error("异常类型: {}", e.getClass().getSimpleName());
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 滑动窗口计算典则相关系数序列
|
||||
* 对应C代码中的SlideCanCor函数
|
||||
*
|
||||
* @param powerData 功率数据矩阵 [时间][节点]
|
||||
* @param harmonicData 谐波数据向量
|
||||
* @param windowSize 窗口大小
|
||||
* @param nodeCount 节点数量
|
||||
* @param dataLength 数据总长度
|
||||
* @return 典则相关系数序列
|
||||
*/
|
||||
public static float[] slidingCanonicalCorrelation(float[][] powerData, float[] harmonicData,
|
||||
int windowSize, int nodeCount, int dataLength) {
|
||||
int slideLength = dataLength - windowSize;
|
||||
if (slideLength <= 0) {
|
||||
throw new IllegalArgumentException("Data length must be greater than window size");
|
||||
}
|
||||
|
||||
float[] slideCanCor = new float[slideLength];
|
||||
|
||||
logger.info("Starting sliding canonical correlation analysis, slide length: {}", slideLength);
|
||||
|
||||
for (int i = 0; i < slideLength; i++) {
|
||||
// 提取窗口数据
|
||||
float[][] windowPower = new float[windowSize][nodeCount];
|
||||
float[] windowHarmonic = new float[windowSize];
|
||||
|
||||
for (int j = 0; j < windowSize; j++) {
|
||||
System.arraycopy(powerData[i + j], 0, windowPower[j], 0, nodeCount);
|
||||
windowHarmonic[j] = harmonicData[i + j];
|
||||
}
|
||||
|
||||
// 计算当前窗口的典则相关系数
|
||||
slideCanCor[i] = computeCanonicalCorrelation(windowPower, windowHarmonic,
|
||||
windowSize, nodeCount);
|
||||
|
||||
if (i % 10 == 0) {
|
||||
logger.debug("Processed window {}/{}", i, slideLength);
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Sliding canonical correlation analysis completed");
|
||||
|
||||
return slideCanCor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算包含/不包含背景的动态相关系数
|
||||
* 对应C代码中的SlideCor函数
|
||||
*
|
||||
* @param powerData 功率数据(单个节点)
|
||||
* @param harmonicData 谐波数据
|
||||
* @param slideCanCor 滑动典则相关系数
|
||||
* @param windowSize 窗口大小
|
||||
* @return 动态相关系数序列
|
||||
*/
|
||||
public static float[] slidingCorrelation(float[] powerData, float[] harmonicData,
|
||||
float[] slideCanCor, int windowSize) {
|
||||
int slideLength = slideCanCor.length;
|
||||
float[] slideCor = new float[slideLength];
|
||||
|
||||
for (int i = 0; i < slideLength; i++) {
|
||||
float[] tempPower = new float[windowSize];
|
||||
float[] tempHarmonic = new float[windowSize];
|
||||
|
||||
for (int j = 0; j < windowSize; j++) {
|
||||
tempPower[j] = powerData[i + j];
|
||||
tempHarmonic[j] = harmonicData[i + j] * slideCanCor[i];
|
||||
}
|
||||
|
||||
slideCor[i] = MathUtils.pearsonCorrelation(tempHarmonic, tempPower, windowSize);
|
||||
}
|
||||
|
||||
return slideCor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,424 @@
|
||||
package com.njcn.advance.responsibility.calculator;
|
||||
|
||||
import com.njcn.advance.responsibility.analysis.CanonicalCorrelationAnalysis;
|
||||
import com.njcn.advance.responsibility.constant.CalculationMode;
|
||||
import com.njcn.advance.responsibility.constant.CalculationStatus;
|
||||
import com.njcn.advance.responsibility.constant.HarmonicConstants;
|
||||
import com.njcn.advance.responsibility.model.HarmonicData;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 谐波责任计算主引擎
|
||||
* 严格对应C代码中的harm_res系列函数
|
||||
*
|
||||
* @author hongawen
|
||||
* @version 2.0 - 修复版本,严格对照C代码实现
|
||||
*/
|
||||
public class HarmonicCalculationEngine {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(HarmonicCalculationEngine.class);
|
||||
|
||||
// 对应C代码中的全局变量
|
||||
private int P; // 节点数 p_node
|
||||
private int TL; // 功率数据长度 p_num
|
||||
private int LL; // 谐波数据长度 harm_num
|
||||
private int JIANGE; // 数据间隔比例
|
||||
private int width; // 窗口大小
|
||||
private float XIANE; // 谐波门槛
|
||||
|
||||
/**
|
||||
* 主计算入口
|
||||
* 对应C代码中的harm_res函数
|
||||
*
|
||||
* @param data 谐波数据对象
|
||||
* @return 计算是否成功
|
||||
*/
|
||||
public boolean calculate(HarmonicData data) {
|
||||
logger.info("Starting harmonic calculation, mode: {}", data.getCalculationMode());
|
||||
|
||||
try {
|
||||
if (data.getCalculationMode() == CalculationMode.FULL_CALCULATION) {
|
||||
return fullCalculation(data);
|
||||
} else {
|
||||
return partialCalculation(data);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Calculation failed with exception: " + e.getMessage(), e);
|
||||
e.printStackTrace();
|
||||
data.setCalculationStatus(CalculationStatus.FAILED);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 完整计算模式
|
||||
* 严格对应C代码中的harm_res_all函数
|
||||
*
|
||||
* @param data 谐波数据对象
|
||||
* @return 计算是否成功
|
||||
*/
|
||||
private boolean fullCalculation(HarmonicData data) {
|
||||
logger.info("Executing full calculation mode");
|
||||
|
||||
// 1. 数据初始化 - 对应 data_init_all()
|
||||
if (!initializeFullCalculationData(data)) {
|
||||
logger.error("Data initialization failed");
|
||||
data.setCalculationStatus(CalculationStatus.FAILED);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. 创建工作数组 - 对应C代码行536-540
|
||||
float[][] a = new float[TL][P]; // 功率数据副本
|
||||
float[] b = new float[LL]; // 谐波数据副本
|
||||
float[] u = new float[TL]; // 对齐后的谐波数据
|
||||
|
||||
// 3. 复制数据 - 对应C代码行542-552
|
||||
for (int i = 0; i < TL; i++) {
|
||||
for (int j = 0; j < P; j++) {
|
||||
a[i][j] = data.getPowerData()[i][j];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < LL; i++) {
|
||||
b[i] = data.getHarmonicData()[i];
|
||||
}
|
||||
|
||||
// 4. 数据对齐处理 - 严格对应C代码行554-562
|
||||
// 注意:C代码是原地修改数组b
|
||||
for (int i = 0; i < LL; i += JIANGE) {
|
||||
float tempt = 0.0f;
|
||||
for (int j = 0; j < JIANGE; j++) {
|
||||
tempt += b[i + j];
|
||||
}
|
||||
b[i] = tempt / JIANGE; // 覆盖原位置
|
||||
}
|
||||
|
||||
// 5. 构建Udata - 严格对应C代码行570-580
|
||||
// 注意:使用 i*JIANGE 索引
|
||||
for (int i = 0; i < TL; i++) {
|
||||
u[i] = b[i * JIANGE]; // 关键:使用 i*JIANGE 索引
|
||||
}
|
||||
|
||||
int slcorlength = TL - width;
|
||||
|
||||
// 6. 计算滑动典则相关系数 - 对应C代码行584
|
||||
logger.info("Computing sliding canonical correlation");
|
||||
float[] cancorrelation = CanonicalCorrelationAnalysis.slidingCanonicalCorrelation(
|
||||
a, u, width, P, TL
|
||||
);
|
||||
|
||||
// 7. 保存典则相关系数 - 对应C代码行592-601
|
||||
float[] Core = new float[slcorlength];
|
||||
float[] BjCore = new float[slcorlength];
|
||||
for (int i = 0; i < slcorlength; i++) {
|
||||
Core[i] = cancorrelation[i];
|
||||
BjCore[i] = 1 - cancorrelation[i];
|
||||
}
|
||||
data.setCanonicalCorrelation(Core);
|
||||
data.setBackgroundCanonicalCorr(BjCore);
|
||||
|
||||
// 8. 计算动态相关系数矩阵 - 对应C代码行605-635
|
||||
logger.info("Computing correlation matrix");
|
||||
float[][] simCor = new float[slcorlength][P];
|
||||
|
||||
// 对应C代码行618-632:对每个节点计算动态相关系数
|
||||
for (int i = 0; i < P; i++) {
|
||||
// 提取第i个节点的功率数据
|
||||
float[] xe = new float[TL];
|
||||
for (int m = 0; m < TL; m++) {
|
||||
xe[m] = a[m][i]; // 对应 Pdata.block(0, i, TL, 1)
|
||||
}
|
||||
|
||||
// 计算该节点的滑动相关系数
|
||||
float[] slidecor = CanonicalCorrelationAnalysis.slidingCorrelation(
|
||||
xe, u, cancorrelation, width
|
||||
);
|
||||
|
||||
// 存储结果
|
||||
for (int j = 0; j < slcorlength; j++) {
|
||||
simCor[j][i] = slidecor[j];
|
||||
}
|
||||
}
|
||||
data.setCorrelationData(simCor);
|
||||
|
||||
// 9. 计算EK值 - 对应C代码行642-654
|
||||
logger.info("Computing EK values");
|
||||
float[][] EKdata = ResponsibilityCalculator.computeEK(
|
||||
simCor, a, width, P, TL
|
||||
);
|
||||
|
||||
// 10. 计算FK值 - 对应C代码行660-673
|
||||
logger.info("Computing FK values");
|
||||
float[][] FKdata = ResponsibilityCalculator.computeFK(
|
||||
EKdata, width, P, TL
|
||||
);
|
||||
data.setFkData(FKdata);
|
||||
|
||||
// 11. 计算HK值 - 对应C代码行678-691
|
||||
logger.info("Computing HK values");
|
||||
float[][] HKdata = ResponsibilityCalculator.computeHK(
|
||||
BjCore, EKdata, width, P, TL
|
||||
);
|
||||
data.setHkData(HKdata);
|
||||
|
||||
// 12. 设置结果数量 - 对应C代码行693
|
||||
data.setResponsibilityDataCount(slcorlength);
|
||||
|
||||
// 13. 统计超限时段的责任 - 对应C代码行696-724
|
||||
logger.info("Computing responsibility sums");
|
||||
|
||||
// 重要修正:C代码的SumHK函数中,虽然Udata长度是TL,但是循环只遍历前slg(=TL-width)个元素
|
||||
// 所以我们需要传入完整的u数组(长度TL),让sumResponsibility内部处理
|
||||
// 对应C代码:VectorXd Udata(TL); 以及 SumHK函数调用
|
||||
|
||||
// 统计HK责任(包含背景)- 对应C代码行698-710
|
||||
// 注意:传入完整的u数组(TL长度),而不是截取的数组
|
||||
float[] sumHK = ResponsibilityCalculator.sumResponsibility(
|
||||
HKdata, u, XIANE, width, P + 1, TL
|
||||
);
|
||||
data.setSumHKData(sumHK);
|
||||
|
||||
// 统计FK责任(不包含背景)- 对应C代码行712-724
|
||||
// 同样传入完整的u数组和TL参数
|
||||
float[] sumFK = ResponsibilityCalculator.sumResponsibility(
|
||||
FKdata, u, XIANE, width, P, TL
|
||||
);
|
||||
data.setSumFKData(sumFK);
|
||||
|
||||
// 14. 标记计算成功 - 对应C代码行739
|
||||
data.setCalculationStatus(CalculationStatus.CALCULATED);
|
||||
logger.info("Full calculation completed successfully");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化完整计算数据
|
||||
* 对应C代码中的data_init_all函数
|
||||
*/
|
||||
private boolean initializeFullCalculationData(HarmonicData data) {
|
||||
// 设置全局变量 - 对应C代码行478-483
|
||||
P = data.getPowerNodeCount();
|
||||
TL = data.getPowerCount();
|
||||
LL = data.getHarmonicCount();
|
||||
// 对应C代码第481行:JIANGE = pq_buf.harm_num/pq_buf.p_num;
|
||||
// 重要修正:JIANGE应该是 谐波数量/功率点数,不是谐波数量/节点数
|
||||
JIANGE = LL / TL; // 这个是正确的:harm_num / p_num (其中p_num是功率点数)
|
||||
width = data.getWindowSize();
|
||||
XIANE = data.getHarmonicThreshold();
|
||||
|
||||
// 验证数据 - 对应C代码行485-504
|
||||
if (JIANGE * TL != LL || JIANGE < 1) {
|
||||
logger.error("Data length mismatch: JIANGE({}) * TL({}) != LL({})",
|
||||
JIANGE, TL, LL);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (width < HarmonicConstants.MIN_WIN_LEN || width > HarmonicConstants.MAX_WIN_LEN) {
|
||||
logger.error("Invalid window size: {}", width);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TL < 2 * width) {
|
||||
logger.error("Power data length {} is too short for window size {}", TL, width);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (P > HarmonicConstants.MAX_P_NODE || TL > HarmonicConstants.MAX_P_NUM ||
|
||||
LL > HarmonicConstants.MAX_HARM_NUM) {
|
||||
logger.error("Data size exceeds limits");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 部分重算模式
|
||||
* 对应C代码中的harm_res_part函数
|
||||
*
|
||||
* @param data 谐波数据对象
|
||||
* @return 计算是否成功
|
||||
*/
|
||||
private boolean partialCalculation(HarmonicData data) {
|
||||
logger.info("Executing partial calculation mode");
|
||||
|
||||
// 1. 数据初始化 - 对应 data_init_part()
|
||||
if (!initializePartialCalculationData(data)) {
|
||||
logger.error("Data initialization failed for partial calculation");
|
||||
data.setCalculationStatus(CalculationStatus.FAILED);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. 准备Udata - 对应C代码行816-818
|
||||
// C代码:VectorXd Udata(TL); 并从pq_buf.harm_data复制TL个元素
|
||||
int res_num = data.getResponsibilityDataCount();
|
||||
|
||||
// 验证责任数据行数
|
||||
if (res_num != TL - width) {
|
||||
logger.warn("责任数据行数({})与期望值(TL-width={})不匹配", res_num, TL - width);
|
||||
res_num = TL - width; // 使用正确的值
|
||||
}
|
||||
|
||||
// 重要修正:与C代码保持一致,Udata长度应该是TL,而不是res_num
|
||||
// C代码:VectorXd Udata(TL);
|
||||
float[] Udata = new float[TL];
|
||||
|
||||
// 从harm_data复制TL个元素到Udata
|
||||
// C代码:for (int j = 0; j < TL; j++) Udata[j] = pq_buf.harm_data[j];
|
||||
if (data.getHarmonicData().length < TL) {
|
||||
logger.warn("谐波数据长度({})小于TL({}), 将补零",
|
||||
data.getHarmonicData().length, TL);
|
||||
System.arraycopy(data.getHarmonicData(), 0, Udata, 0, data.getHarmonicData().length);
|
||||
// 剩余部分自动补零
|
||||
} else {
|
||||
System.arraycopy(data.getHarmonicData(), 0, Udata, 0, TL);
|
||||
}
|
||||
|
||||
logger.debug("准备Udata完成: 长度={} (对应C代码TL), 责任数据行数={}", Udata.length, res_num);
|
||||
|
||||
// 3. 统计HK责任 - 对应C代码行806-830
|
||||
logger.info("Recalculating HK responsibility sums");
|
||||
|
||||
// 对应C代码第808-814行:创建新的HKdata矩阵,只包含RES_NUM行
|
||||
// C代码:MatrixXd HKdata(RES_NUM, (P + 1));
|
||||
|
||||
// 添加数据验证
|
||||
if (data.getHkData() == null || data.getHkData().length == 0) {
|
||||
logger.error("HK数据为空或长度为0");
|
||||
data.setCalculationStatus(CalculationStatus.FAILED);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 重要:C代码创建了新的RES_NUM行的HKdata,从原始数据复制前RES_NUM行
|
||||
// 对应C代码第808-814行
|
||||
float[][] HKdataForCalc = new float[res_num][P + 1];
|
||||
int copyRows = Math.min(res_num, data.getHkData().length);
|
||||
|
||||
logger.debug("创建用于计算的HK数据矩阵: {}x{}, 从原始数据复制{}行",
|
||||
res_num, P + 1, copyRows);
|
||||
|
||||
for (int i = 0; i < copyRows; i++) {
|
||||
for (int j = 0; j < P + 1; j++) {
|
||||
if (j < data.getHkData()[i].length) {
|
||||
HKdataForCalc[i][j] = data.getHkData()[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
logger.debug("调用HK sumResponsibility参数: HKdata[{}x{}], Udata[{}], TL={}, width={}",
|
||||
HKdataForCalc.length, HKdataForCalc.length > 0 ? HKdataForCalc[0].length : 0,
|
||||
Udata.length, TL, width);
|
||||
|
||||
try {
|
||||
// 对应C代码第819行:arrHKsum = SumHK(HKdata, Udata, wdith, colK, TL);
|
||||
float[] sumHK = ResponsibilityCalculator.sumResponsibility(
|
||||
HKdataForCalc, // 使用新创建的RES_NUM行的HK数据
|
||||
Udata, // 长度为TL的数组
|
||||
XIANE,
|
||||
width,
|
||||
P + 1,
|
||||
TL // 传入TL参数
|
||||
);
|
||||
data.setSumHKData(sumHK);
|
||||
logger.debug("HK责任计算完成,结果长度: {}", sumHK != null ? sumHK.length : "null");
|
||||
} catch (Exception e) {
|
||||
logger.error("HK责任计算失败: " + e.getMessage(), e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// 4. 统计FK责任 - 对应C代码行839-851
|
||||
logger.info("Recalculating FK responsibility sums");
|
||||
|
||||
// 对应C代码:虽然没有显式创建新的FKdata,但逻辑相同
|
||||
|
||||
// 添加数据验证
|
||||
if (data.getFkData() == null || data.getFkData().length == 0) {
|
||||
logger.error("FK数据为空或长度为0");
|
||||
data.setCalculationStatus(CalculationStatus.FAILED);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 创建用于计算的FK数据矩阵(RES_NUM行)
|
||||
float[][] FKdataForCalc = new float[res_num][P];
|
||||
int copyRowsFK = Math.min(res_num, data.getFkData().length);
|
||||
|
||||
logger.debug("创建用于计算的FK数据矩阵: {}x{}, 从原始数据复制{}行",
|
||||
res_num, P, copyRowsFK);
|
||||
|
||||
for (int i = 0; i < copyRowsFK; i++) {
|
||||
for (int j = 0; j < P; j++) {
|
||||
if (j < data.getFkData()[i].length) {
|
||||
FKdataForCalc[i][j] = data.getFkData()[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
logger.debug("调用FK sumResponsibility参数: FKdata[{}x{}], Udata[{}], TL={}, width={}",
|
||||
FKdataForCalc.length, FKdataForCalc.length > 0 ? FKdataForCalc[0].length : 0,
|
||||
Udata.length, TL, width);
|
||||
|
||||
try {
|
||||
// 对应C代码第840行:arrHKsum = SumHK(FKdata, Udata, wdith, colK, TL);
|
||||
float[] sumFK = ResponsibilityCalculator.sumResponsibility(
|
||||
FKdataForCalc, // 使用新创建的RES_NUM行的FK数据
|
||||
Udata, // 使用相同的Udata(长度TL)
|
||||
XIANE,
|
||||
width,
|
||||
P,
|
||||
TL // 传入TL参数
|
||||
);
|
||||
data.setSumFKData(sumFK);
|
||||
logger.debug("FK责任计算完成,结果长度: {}", sumFK != null ? sumFK.length : "null");
|
||||
} catch (Exception e) {
|
||||
logger.error("FK责任计算失败: " + e.getMessage(), e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// 5. 标记计算成功 - 对应C代码行858
|
||||
data.setCalculationStatus(CalculationStatus.CALCULATED);
|
||||
logger.info("Partial calculation completed successfully");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化部分计算数据
|
||||
* 对应C代码中的data_init_part函数
|
||||
*/
|
||||
private boolean initializePartialCalculationData(HarmonicData data) {
|
||||
// 设置变量 - 对应C代码行762-766
|
||||
int RES_NUM = data.getResponsibilityDataCount();
|
||||
P = data.getPowerNodeCount();
|
||||
TL = data.getWindowSize() + RES_NUM;
|
||||
width = data.getWindowSize();
|
||||
XIANE = data.getHarmonicThreshold();
|
||||
|
||||
// 验证数据 - 对应C代码行756-778
|
||||
if ((RES_NUM + width) != data.getHarmonicCount()) {
|
||||
logger.error("Data length mismatch: res_num({}) + win({}) != harm_num({})",
|
||||
RES_NUM, width, data.getHarmonicCount());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (width < HarmonicConstants.MIN_WIN_LEN || width > HarmonicConstants.MAX_WIN_LEN) {
|
||||
logger.error("Invalid window size: {}", width);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (P > HarmonicConstants.MAX_P_NODE || TL > HarmonicConstants.MAX_P_NUM) {
|
||||
logger.error("Data size exceeds limits");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 验证FK和HK数据存在
|
||||
if (data.getFkData() == null || data.getHkData() == null) {
|
||||
logger.error("FK or HK data is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
package com.njcn.advance.responsibility.calculator;
|
||||
|
||||
import com.njcn.advance.responsibility.analysis.CanonicalCorrelationAnalysis;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 责任指标计算类
|
||||
* 计算谐波责任的各项指标
|
||||
* 严格对应C代码实现
|
||||
*
|
||||
* @author hongawen
|
||||
* @version 2.0 - 修复版本,严格对照C代码实现
|
||||
*/
|
||||
public class ResponsibilityCalculator {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ResponsibilityCalculator.class);
|
||||
|
||||
/**
|
||||
* 计算EK值(动态责任指标)
|
||||
* 严格对应C代码中的DyEKCom函数(行300-357)
|
||||
*
|
||||
* @param correlationData 动态相关系数矩阵 [时间][节点]
|
||||
* @param powerData 功率数据矩阵 [时间][节点]
|
||||
* @param windowSize 窗口大小
|
||||
* @param nodeCount 节点数量
|
||||
* @param dataLength 数据长度
|
||||
* @return EK值矩阵
|
||||
*/
|
||||
public static float[][] computeEK(float[][] correlationData, float[][] powerData,
|
||||
int windowSize, int nodeCount, int dataLength) {
|
||||
int slideLength = dataLength - windowSize;
|
||||
float[][] ekData = new float[slideLength][nodeCount];
|
||||
float[][] akData = new float[slideLength][nodeCount];
|
||||
|
||||
logger.info("Computing EK values, slide length: {}", slideLength);
|
||||
|
||||
// 计算AK值 - 对应C代码行307-319
|
||||
for (int i = 0; i < slideLength; i++) {
|
||||
float sumPower = 0;
|
||||
|
||||
// 计算功率总和 - 对应C代码行309-313
|
||||
for (int j = 0; j < nodeCount; j++) {
|
||||
sumPower += powerData[i][j]; // 注意:这里用的是powerData[i][j]
|
||||
}
|
||||
|
||||
// 计算AK值 - 对应C代码行314-318
|
||||
for (int j = 0; j < nodeCount; j++) {
|
||||
if (sumPower > 0) {
|
||||
akData[i][j] = correlationData[i][j] * (powerData[i][j] / sumPower);
|
||||
} else {
|
||||
akData[i][j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 归一化处理得到EK值 - 对应C代码行320-342
|
||||
for (int i = 0; i < slideLength; i++) {
|
||||
// 重要:C代码初始化为0,而不是Float.MIN_VALUE/MAX_VALUE
|
||||
// 对应C代码行322-323
|
||||
float maxValue = 0;
|
||||
float minValue = 0;
|
||||
|
||||
// 找最大最小值 - 对应C代码行322-334
|
||||
for (int j = 0; j < nodeCount; j++) {
|
||||
if (akData[i][j] > maxValue) {
|
||||
maxValue = akData[i][j];
|
||||
}
|
||||
if (akData[i][j] < minValue) {
|
||||
minValue = akData[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
float range = maxValue - minValue;
|
||||
|
||||
// 归一化 - 对应C代码行338-341
|
||||
for (int j = 0; j < nodeCount; j++) {
|
||||
if (Math.abs(range) > 1e-10) {
|
||||
ekData[i][j] = (akData[i][j] - minValue) / range;
|
||||
} else {
|
||||
ekData[i][j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("EK computation completed");
|
||||
|
||||
return ekData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算FK值(不包含背景的责任指标)
|
||||
* 严格对应C代码中的DyFKCom函数(行358-389)
|
||||
*
|
||||
* @param ekData EK值矩阵
|
||||
* @param windowSize 窗口大小
|
||||
* @param nodeCount 节点数量
|
||||
* @param dataLength 数据长度
|
||||
* @return FK值矩阵
|
||||
*/
|
||||
public static float[][] computeFK(float[][] ekData, int windowSize,
|
||||
int nodeCount, int dataLength) {
|
||||
int slideLength = dataLength - windowSize;
|
||||
float[][] fkData = new float[slideLength][nodeCount];
|
||||
|
||||
logger.info("Computing FK values");
|
||||
|
||||
// 对应C代码行364-376
|
||||
for (int i = 0; i < slideLength; i++) {
|
||||
float sumEK = 0;
|
||||
|
||||
// 计算EK总和 - 对应C代码行366-370
|
||||
for (int j = 0; j < nodeCount; j++) {
|
||||
sumEK += ekData[i][j];
|
||||
}
|
||||
|
||||
// 计算FK值(归一化)- 对应C代码行372-375
|
||||
for (int j = 0; j < nodeCount; j++) {
|
||||
if (sumEK > 0) {
|
||||
fkData[i][j] = ekData[i][j] / sumEK;
|
||||
} else {
|
||||
fkData[i][j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("FK computation completed");
|
||||
|
||||
return fkData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算HK值(包含背景的责任指标)
|
||||
* 严格对应C代码中的DyHKCom函数(行390-429)
|
||||
*
|
||||
* @param backgroundCanCor 背景典则相关系数(1-典则相关系数)
|
||||
* @param ekData EK值矩阵
|
||||
* @param windowSize 窗口大小
|
||||
* @param nodeCount 节点数量
|
||||
* @param dataLength 数据长度
|
||||
* @return HK值矩阵
|
||||
*/
|
||||
public static float[][] computeHK(float[] backgroundCanCor, float[][] ekData,
|
||||
int windowSize, int nodeCount, int dataLength) {
|
||||
int slideLength = dataLength - windowSize;
|
||||
float[][] hkData = new float[slideLength][nodeCount + 1];
|
||||
float[][] newEK = new float[slideLength][nodeCount + 1];
|
||||
|
||||
logger.info("Computing HK values");
|
||||
|
||||
// 构建包含背景的EK矩阵 - 对应C代码行396-403
|
||||
for (int i = 0; i < slideLength; i++) {
|
||||
// 复制原有EK值
|
||||
for (int j = 0; j < nodeCount; j++) {
|
||||
newEK[i][j] = ekData[i][j];
|
||||
}
|
||||
// 添加背景值
|
||||
newEK[i][nodeCount] = backgroundCanCor[i];
|
||||
}
|
||||
|
||||
// 计算HK值 - 对应C代码行405-416
|
||||
for (int i = 0; i < slideLength; i++) {
|
||||
float sumEK = 0;
|
||||
|
||||
// 计算总和 - 对应C代码行407-411
|
||||
for (int j = 0; j < nodeCount + 1; j++) {
|
||||
sumEK += newEK[i][j];
|
||||
}
|
||||
|
||||
// 归一化得到HK值 - 对应C代码行412-415
|
||||
for (int j = 0; j < nodeCount + 1; j++) {
|
||||
if (sumEK > 0) {
|
||||
hkData[i][j] = newEK[i][j] / sumEK;
|
||||
} else {
|
||||
hkData[i][j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("HK computation completed");
|
||||
|
||||
return hkData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算超限时段的责任总和
|
||||
* 严格对应C代码中的SumHK函数(行431-461)
|
||||
*
|
||||
* @param responsibilityData 责任数据矩阵(FK或HK)[时间][节点]
|
||||
* @param harmonicData 谐波数据(Udata) - 长度为TL
|
||||
* @param threshold 谐波门槛(XIANE)
|
||||
* @param windowSize 窗口大小
|
||||
* @param columnCount 列数(节点数或节点数+1)
|
||||
* @param tl_num 对应C代码的TL参数(总数据点数)
|
||||
* @return 各节点的责任总和百分比
|
||||
*/
|
||||
public static float[] sumResponsibility(float[][] responsibilityData, float[] harmonicData,
|
||||
float threshold, int windowSize, int columnCount, int tl_num) {
|
||||
// 对应C代码:int slg = tl_num - width;
|
||||
int slideLength = tl_num - windowSize; // 使用传入的tl_num计算,而不是从responsibilityData.length推断
|
||||
float[] sumData = new float[columnCount]; // 对应C代码中的 arrHKsum
|
||||
double[] HKSum = new double[columnCount]; // 对应C代码中的 VectorXd HKSum - 使用double精度
|
||||
int exceedCount = 0; // 对应C代码中的 coutt
|
||||
|
||||
// ===== 添加详细调试日志 =====
|
||||
logger.info("======= 开始 sumResponsibility 计算 =======");
|
||||
logger.info("输入参数:");
|
||||
logger.info(" threshold(阈值): {}", threshold);
|
||||
logger.info(" windowSize(窗口大小): {}", windowSize);
|
||||
logger.info(" columnCount(列数): {}", columnCount);
|
||||
logger.info(" tl_num(总数据长度): {}", tl_num);
|
||||
logger.info(" slideLength(滑动长度): {}", slideLength);
|
||||
logger.info(" responsibilityData维度: {}x{}",
|
||||
responsibilityData != null ? responsibilityData.length : "null",
|
||||
responsibilityData != null && responsibilityData.length > 0 ? responsibilityData[0].length : "null");
|
||||
logger.info(" harmonicData长度: {}", harmonicData != null ? harmonicData.length : "null");
|
||||
|
||||
// 数据验证
|
||||
if (harmonicData == null) {
|
||||
logger.error("错误: harmonicData为null!");
|
||||
throw new NullPointerException("harmonicData不能为null");
|
||||
}
|
||||
|
||||
if (responsibilityData == null) {
|
||||
logger.error("错误: responsibilityData为null!");
|
||||
throw new NullPointerException("responsibilityData不能为null");
|
||||
}
|
||||
|
||||
|
||||
// 关键验证:检查数组长度是否充足
|
||||
// C代码中Udata长度是TL,循环遍历slg=TL-width个元素
|
||||
logger.info("数据验证: slideLength={}, harmonicData.length={}, responsibilityData.length={}",
|
||||
slideLength, harmonicData.length, responsibilityData.length);
|
||||
|
||||
if (harmonicData.length < slideLength) {
|
||||
logger.error("!!!谐波数据长度不足!!!");
|
||||
logger.error("需要访问harmonicData[0]到harmonicData[{}], 但数组长度只有{}",
|
||||
slideLength - 1, harmonicData.length);
|
||||
throw new IllegalArgumentException(
|
||||
String.format("谐波数据长度不足: 需要%d, 实际%d", slideLength, harmonicData.length));
|
||||
}
|
||||
|
||||
if (responsibilityData.length < slideLength) {
|
||||
logger.error("!!!责任数据行数不足!!!");
|
||||
logger.error("需要访问responsibilityData[0]到responsibilityData[{}], 但数组长度只有{}",
|
||||
slideLength - 1, responsibilityData.length);
|
||||
throw new IllegalArgumentException(
|
||||
String.format("责任数据行数不足: 需要%d, 实际%d", slideLength, responsibilityData.length));
|
||||
}
|
||||
|
||||
// ===== 添加数据分布统计 =====
|
||||
logger.info("谐波数据分析:");
|
||||
float harmonicMin = Float.MAX_VALUE, harmonicMax = Float.MIN_VALUE;
|
||||
double harmonicSum = 0;
|
||||
int preliminaryExceedCount = 0;
|
||||
for (int i = 0; i < Math.min(slideLength, harmonicData.length); i++) {
|
||||
float val = harmonicData[i];
|
||||
harmonicMin = Math.min(harmonicMin, val);
|
||||
harmonicMax = Math.max(harmonicMax, val);
|
||||
harmonicSum += val;
|
||||
if (val > threshold) {
|
||||
preliminaryExceedCount++;
|
||||
}
|
||||
}
|
||||
double harmonicAvg = harmonicSum / Math.min(slideLength, harmonicData.length);
|
||||
logger.info(" 谐波数据范围: [{}, {}]", harmonicMin, harmonicMax);
|
||||
logger.info(" 谐波数据平均值: {}", harmonicAvg);
|
||||
logger.info(" 设定阈值: {}", threshold);
|
||||
logger.info(" 初步统计超限个数: {}/{} ({:.2f}%)",
|
||||
preliminaryExceedCount, Math.min(slideLength, harmonicData.length),
|
||||
preliminaryExceedCount * 100.0 / Math.min(slideLength, harmonicData.length));
|
||||
|
||||
// ===== 责任数据分析 =====
|
||||
logger.info("责任数据分析(检查前5行的归一化情况):");
|
||||
for (int i = 0; i < Math.min(5, responsibilityData.length); i++) {
|
||||
float rowSum = 0;
|
||||
for (int j = 0; j < responsibilityData[i].length; j++) {
|
||||
rowSum += responsibilityData[i][j];
|
||||
}
|
||||
logger.info(" 第{}行和: {} (期望值: 1.0, 偏差: {})", i, rowSum, Math.abs(rowSum - 1.0f));
|
||||
}
|
||||
|
||||
// 统计超限时段的责任 - 对应C代码行437-449
|
||||
// 重要:C代码中有一个设计缺陷:coutt在每个j循环中被重置,
|
||||
// 但最后计算百分比时使用的是最后一次j循环的coutt值
|
||||
// 为了严格保持一致,我们也要复现这个逻辑
|
||||
logger.info("===== 开始循环计算每列的累加值 =====");
|
||||
int[] exceedCountPerColumn = new int[columnCount]; // 记录每列的超限次数,用于调试
|
||||
|
||||
for (int j = 0; j < columnCount; j++) {
|
||||
HKSum[j] = 0;
|
||||
exceedCount = 0; // 对应C代码行440: coutt = 0;
|
||||
logger.info("开始计算第{}列 (共{}列)", j, columnCount);
|
||||
|
||||
double columnSum = 0; // 用于调试
|
||||
int columnExceedCount = 0; // 用于调试
|
||||
|
||||
for (int i = 0; i < slideLength; i++) {
|
||||
// 添加越界检查
|
||||
if (i >= harmonicData.length) {
|
||||
logger.error("!!!数组越界!!! 尝试访问harmonicData[{}], 但数组长度只有{}",
|
||||
i, harmonicData.length);
|
||||
logger.error("发生在: j={}, i={}", j, i);
|
||||
throw new ArrayIndexOutOfBoundsException(
|
||||
String.format("访问harmonicData[%d]越界, 数组长度=%d", i, harmonicData.length));
|
||||
}
|
||||
|
||||
// 对应C代码行443-447
|
||||
if (harmonicData[i] > threshold) {
|
||||
double currentResponsibility = responsibilityData[i][j];
|
||||
HKSum[j] += currentResponsibility; // 对应C代码行445
|
||||
exceedCount++; // 对应C代码行446
|
||||
columnSum += currentResponsibility;
|
||||
columnExceedCount++;
|
||||
|
||||
// 只打印前几个超限情况的详细信息
|
||||
if (columnExceedCount <= 3) {
|
||||
logger.info(" 时刻i={}: 谐波值={} > 阈值={}, 责任值={}, 累加到{}",
|
||||
i, harmonicData[i], threshold, currentResponsibility, HKSum[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exceedCountPerColumn[j] = columnExceedCount;
|
||||
logger.info("第{}列计算完成: 累加值={}, 超限次数={}", j, HKSum[j], columnExceedCount);
|
||||
}
|
||||
// 注意:这里exceedCount保留的是最后一列(j=columnCount-1)的超限次数
|
||||
// 这与C代码的行为一致
|
||||
|
||||
logger.info("===== 循环计算完成 =====");
|
||||
logger.info("最终exceedCount={} (来自最后一列的计算)", exceedCount);
|
||||
logger.info("各列超限次数对比: {}", java.util.Arrays.toString(exceedCountPerColumn));
|
||||
logger.info("各列累加值: {}", java.util.Arrays.toString(HKSum));
|
||||
|
||||
// 计算平均责任百分比 - 对应C代码行453-459
|
||||
logger.info("===== 开始计算最终百分比 =====");
|
||||
for (int i = 0; i < columnCount; i++) {
|
||||
sumData[i] = 0; // 对应C代码行454
|
||||
}
|
||||
|
||||
double totalPercentage = 0; // 用于统计总和
|
||||
for (int i = 0; i < columnCount; i++) {
|
||||
if (exceedCount > 0) {
|
||||
// 对应C代码行458: arrHKsum[i] = 100 * (HKSum(i)/coutt);
|
||||
// 使用double进行计算,然后转换为float
|
||||
double percentage = 100.0 * (HKSum[i] / (double)exceedCount);
|
||||
sumData[i] = (float)percentage;
|
||||
totalPercentage += percentage;
|
||||
|
||||
logger.info("节点{}: 累加值={}, 除以超限次数={}, 百分比={}%",
|
||||
i, HKSum[i], exceedCount, percentage);
|
||||
} else {
|
||||
logger.warn("节点{}: 超限次数为0,百分比设为0", i);
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("===== 计算结果汇总 =====");
|
||||
logger.info("使用的超限次数(分母): {}", exceedCount);
|
||||
logger.info("各节点百分比: {}", java.util.Arrays.toString(sumData));
|
||||
logger.info("百分比总和: {}% (期望100%)", totalPercentage);
|
||||
logger.info("偏差: {}%", Math.abs(totalPercentage - 100.0));
|
||||
|
||||
if (Math.abs(totalPercentage - 100.0) > 1.0) {
|
||||
logger.warn("!!!注意!!! 百分比总和偏离100%超过1%,可能存在问题");
|
||||
}
|
||||
|
||||
logger.info("======= sumResponsibility 计算完成 =======");
|
||||
return sumData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算超限时段的责任总和(兼容版本)
|
||||
* 为了向后兼容,保留不带tl_num参数的版本
|
||||
*
|
||||
* @param responsibilityData 责任数据矩阵(FK或HK)[时间][节点]
|
||||
* @param harmonicData 谐波数据(Udata)
|
||||
* @param threshold 谐波门槛(XIANE)
|
||||
* @param windowSize 窗口大小
|
||||
* @param columnCount 列数(节点数或节点数+1)
|
||||
* @return 各节点的责任总和百分比
|
||||
*/
|
||||
public static float[] sumResponsibility(float[][] responsibilityData, float[] harmonicData,
|
||||
float threshold, int windowSize, int columnCount) {
|
||||
// 如果没有提供tl_num,从数据推断
|
||||
int tl_num = responsibilityData.length + windowSize;
|
||||
return sumResponsibility(responsibilityData, harmonicData, threshold, windowSize, columnCount, tl_num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算所有节点的动态相关系数矩阵
|
||||
* 这个函数在主引擎中已经内联实现,这里保留作为辅助方法
|
||||
*
|
||||
* @param powerData 功率数据矩阵
|
||||
* @param harmonicData 谐波数据
|
||||
* @param canonicalCorr 典则相关系数序列
|
||||
* @param windowSize 窗口大小
|
||||
* @param nodeCount 节点数量
|
||||
* @return 动态相关系数矩阵
|
||||
*/
|
||||
public static float[][] computeCorrelationMatrix(float[][] powerData, float[] harmonicData,
|
||||
float[] canonicalCorr, int windowSize,
|
||||
int nodeCount) {
|
||||
int slideLength = canonicalCorr.length;
|
||||
float[][] correlationMatrix = new float[slideLength][nodeCount];
|
||||
|
||||
logger.info("Computing correlation matrix for all nodes");
|
||||
|
||||
for (int nodeIdx = 0; nodeIdx < nodeCount; nodeIdx++) {
|
||||
// 提取单个节点的功率数据
|
||||
float[] nodePower = new float[powerData.length];
|
||||
for (int i = 0; i < powerData.length; i++) {
|
||||
nodePower[i] = powerData[i][nodeIdx];
|
||||
}
|
||||
|
||||
// 计算该节点的动态相关系数
|
||||
float[] nodeCorr = CanonicalCorrelationAnalysis
|
||||
.slidingCorrelation(nodePower, harmonicData, canonicalCorr, windowSize);
|
||||
|
||||
// 存储结果
|
||||
for (int i = 0; i < slideLength; i++) {
|
||||
correlationMatrix[i][nodeIdx] = nodeCorr[i];
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Correlation matrix computation completed");
|
||||
|
||||
return correlationMatrix;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.njcn.advance.responsibility.constant;
|
||||
|
||||
/**
|
||||
* 计算模式枚举
|
||||
*
|
||||
* @author hongawen
|
||||
* @version 1.0
|
||||
*/
|
||||
public enum CalculationMode {
|
||||
/**
|
||||
* 完整计算模式
|
||||
* 使用电压和功率数据计算相关系数和责任
|
||||
*/
|
||||
FULL_CALCULATION(0, "完整计算模式"),
|
||||
|
||||
/**
|
||||
* 部分重算模式
|
||||
* 使用已有的动态相关系数计算责任
|
||||
*/
|
||||
PARTIAL_RECALCULATION(1, "部分重算模式");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
CalculationMode(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static CalculationMode fromCode(int code) {
|
||||
for (CalculationMode mode : values()) {
|
||||
if (mode.code == code) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid calculation mode code: " + code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.njcn.advance.responsibility.constant;
|
||||
|
||||
/**
|
||||
* 计算状态枚举
|
||||
*
|
||||
* @author hongawen
|
||||
* @version 1.0
|
||||
*/
|
||||
public enum CalculationStatus {
|
||||
/**
|
||||
* 未计算
|
||||
*/
|
||||
NOT_CALCULATED(0, "未计算"),
|
||||
|
||||
/**
|
||||
* 计算完成
|
||||
*/
|
||||
CALCULATED(1, "计算完成"),
|
||||
|
||||
/**
|
||||
* 计算失败
|
||||
*/
|
||||
FAILED(-1, "计算失败");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
CalculationStatus(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static CalculationStatus fromCode(int code) {
|
||||
for (CalculationStatus status : values()) {
|
||||
if (status.code == code) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return NOT_CALCULATED;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.njcn.advance.responsibility.constant;
|
||||
|
||||
/**
|
||||
* 谐波责任量化系统常量定义
|
||||
*
|
||||
* @author hongawen
|
||||
* @version 1.0
|
||||
*/
|
||||
public final class HarmonicConstants {
|
||||
|
||||
private HarmonicConstants() {
|
||||
// 防止实例化
|
||||
}
|
||||
|
||||
/**
|
||||
* 最大谐波数据个数 (1440*100)
|
||||
* 按一分钟间隔,100天处理
|
||||
*/
|
||||
public static final int MAX_HARM_NUM = 144000;
|
||||
|
||||
/**
|
||||
* 最大功率数据个数 (96*100)
|
||||
* 按15分钟间隔,100天处理
|
||||
*/
|
||||
public static final int MAX_P_NUM = 9600;
|
||||
|
||||
/**
|
||||
* 最大功率节点个数
|
||||
* 按200个限制
|
||||
*/
|
||||
public static final int MAX_P_NODE = 200;
|
||||
|
||||
/**
|
||||
* 最大数据窗长度 (96*10)
|
||||
* 按15分钟算10天
|
||||
*/
|
||||
public static final int MAX_WIN_LEN = 960;
|
||||
|
||||
/**
|
||||
* 最小数据窗长度
|
||||
* 按15分钟算一小时
|
||||
*/
|
||||
public static final int MIN_WIN_LEN = 4;
|
||||
|
||||
/**
|
||||
* 默认数据窗大小
|
||||
* 一天的数据量(15分钟间隔)
|
||||
*/
|
||||
public static final int DEFAULT_WINDOW_SIZE = 96;
|
||||
|
||||
/**
|
||||
* 数值计算精度阈值
|
||||
*/
|
||||
public static final double EPSILON = 1e-10;
|
||||
|
||||
/**
|
||||
* 协方差计算最小值(避免除零)
|
||||
*/
|
||||
public static final double MIN_COVARIANCE = 1e-5;
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
package com.njcn.advance.responsibility.model;
|
||||
|
||||
import com.njcn.advance.responsibility.constant.CalculationMode;
|
||||
import com.njcn.advance.responsibility.constant.CalculationStatus;
|
||||
import com.njcn.advance.responsibility.constant.HarmonicConstants;
|
||||
|
||||
/**
|
||||
* 谐波数据结构类
|
||||
* 对应C语言中的harm_data_struct结构体
|
||||
*
|
||||
* @author hongawen
|
||||
* @version 1.0
|
||||
*/
|
||||
public class HarmonicData {
|
||||
|
||||
// 输入参数
|
||||
private CalculationMode calculationMode; // 计算标志
|
||||
private int harmonicCount; // 谐波数据个数
|
||||
private int powerCount; // 功率数据个数
|
||||
private int powerNodeCount; // 功率负荷节点数
|
||||
private int windowSize; // 数据窗大小
|
||||
private int responsibilityDataCount; // 代入的责任数据个数
|
||||
private float harmonicThreshold; // 谐波电压门槛
|
||||
|
||||
// 数据数组
|
||||
private float[] harmonicData; // 谐波数据序列
|
||||
private float[][] powerData; // 功率数据序列
|
||||
|
||||
// 输入输出数据
|
||||
private float[][] correlationData; // 动态相关系数数据序列
|
||||
private float[][] fkData; // 不包含背景动态谐波责任数据序列
|
||||
private float[][] hkData; // 包含背景动态谐波责任数据序列
|
||||
private float[] canonicalCorrelation; // 典则相关系数
|
||||
private float[] backgroundCanonicalCorr; // 包含背景典则相关系数
|
||||
|
||||
// 输出结果
|
||||
private CalculationStatus calculationStatus; // 计算状态
|
||||
private float[] sumFKData; // 不包含背景谐波责任
|
||||
private float[] sumHKData; // 包含背景谐波责任
|
||||
|
||||
/**
|
||||
* 默认构造函数
|
||||
*/
|
||||
public HarmonicData() {
|
||||
this.calculationMode = CalculationMode.FULL_CALCULATION;
|
||||
this.calculationStatus = CalculationStatus.NOT_CALCULATED;
|
||||
this.windowSize = HarmonicConstants.DEFAULT_WINDOW_SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder模式构造器
|
||||
*/
|
||||
public static class Builder {
|
||||
private HarmonicData data = new HarmonicData();
|
||||
|
||||
public Builder calculationMode(CalculationMode mode) {
|
||||
data.calculationMode = mode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder harmonicCount(int count) {
|
||||
data.harmonicCount = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder powerCount(int count) {
|
||||
data.powerCount = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder powerNodeCount(int count) {
|
||||
data.powerNodeCount = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder windowSize(int size) {
|
||||
data.windowSize = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder harmonicThreshold(float threshold) {
|
||||
data.harmonicThreshold = threshold;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder harmonicData(float[] data) {
|
||||
this.data.harmonicData = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder powerData(float[][] data) {
|
||||
this.data.powerData = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HarmonicData build() {
|
||||
// 验证数据
|
||||
validateData();
|
||||
// 初始化数组
|
||||
initializeArrays();
|
||||
return data;
|
||||
}
|
||||
|
||||
private void validateData() {
|
||||
if (data.harmonicCount <= 0 || data.harmonicCount > HarmonicConstants.MAX_HARM_NUM) {
|
||||
throw new IllegalArgumentException("Invalid harmonic count: " + data.harmonicCount);
|
||||
}
|
||||
if (data.powerCount <= 0 || data.powerCount > HarmonicConstants.MAX_P_NUM) {
|
||||
throw new IllegalArgumentException("Invalid power count: " + data.powerCount);
|
||||
}
|
||||
if (data.powerNodeCount <= 0 || data.powerNodeCount > HarmonicConstants.MAX_P_NODE) {
|
||||
throw new IllegalArgumentException("Invalid power node count: " + data.powerNodeCount);
|
||||
}
|
||||
if (data.windowSize < HarmonicConstants.MIN_WIN_LEN ||
|
||||
data.windowSize > HarmonicConstants.MAX_WIN_LEN) {
|
||||
throw new IllegalArgumentException("Invalid window size: " + data.windowSize);
|
||||
}
|
||||
|
||||
// 验证数据对齐
|
||||
if (data.calculationMode == CalculationMode.FULL_CALCULATION) {
|
||||
int ratio = data.harmonicCount / data.powerCount;
|
||||
if (ratio * data.powerCount != data.harmonicCount || ratio < 1) {
|
||||
throw new IllegalArgumentException("Harmonic data count must be integer multiple of power data count");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeArrays() {
|
||||
if (data.harmonicData == null) {
|
||||
data.harmonicData = new float[data.harmonicCount];
|
||||
}
|
||||
if (data.powerData == null) {
|
||||
data.powerData = new float[data.powerCount][data.powerNodeCount];
|
||||
}
|
||||
|
||||
int resultCount = data.powerCount - data.windowSize;
|
||||
if (resultCount > 0) {
|
||||
data.correlationData = new float[resultCount][data.powerNodeCount];
|
||||
data.fkData = new float[resultCount][data.powerNodeCount];
|
||||
data.hkData = new float[resultCount][data.powerNodeCount + 1];
|
||||
data.canonicalCorrelation = new float[resultCount];
|
||||
data.backgroundCanonicalCorr = new float[resultCount];
|
||||
}
|
||||
|
||||
data.sumFKData = new float[data.powerNodeCount];
|
||||
data.sumHKData = new float[data.powerNodeCount + 1];
|
||||
}
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public CalculationMode getCalculationMode() {
|
||||
return calculationMode;
|
||||
}
|
||||
|
||||
public void setCalculationMode(CalculationMode calculationMode) {
|
||||
this.calculationMode = calculationMode;
|
||||
}
|
||||
|
||||
public int getHarmonicCount() {
|
||||
return harmonicCount;
|
||||
}
|
||||
|
||||
public void setHarmonicCount(int harmonicCount) {
|
||||
this.harmonicCount = harmonicCount;
|
||||
}
|
||||
|
||||
public int getPowerCount() {
|
||||
return powerCount;
|
||||
}
|
||||
|
||||
public void setPowerCount(int powerCount) {
|
||||
this.powerCount = powerCount;
|
||||
}
|
||||
|
||||
public int getPowerNodeCount() {
|
||||
return powerNodeCount;
|
||||
}
|
||||
|
||||
public void setPowerNodeCount(int powerNodeCount) {
|
||||
this.powerNodeCount = powerNodeCount;
|
||||
}
|
||||
|
||||
public int getWindowSize() {
|
||||
return windowSize;
|
||||
}
|
||||
|
||||
public void setWindowSize(int windowSize) {
|
||||
this.windowSize = windowSize;
|
||||
}
|
||||
|
||||
public int getResponsibilityDataCount() {
|
||||
return responsibilityDataCount;
|
||||
}
|
||||
|
||||
public void setResponsibilityDataCount(int responsibilityDataCount) {
|
||||
this.responsibilityDataCount = responsibilityDataCount;
|
||||
}
|
||||
|
||||
public float getHarmonicThreshold() {
|
||||
return harmonicThreshold;
|
||||
}
|
||||
|
||||
public void setHarmonicThreshold(float harmonicThreshold) {
|
||||
this.harmonicThreshold = harmonicThreshold;
|
||||
}
|
||||
|
||||
public float[] getHarmonicData() {
|
||||
return harmonicData;
|
||||
}
|
||||
|
||||
public void setHarmonicData(float[] harmonicData) {
|
||||
this.harmonicData = harmonicData;
|
||||
}
|
||||
|
||||
public float[][] getPowerData() {
|
||||
return powerData;
|
||||
}
|
||||
|
||||
public void setPowerData(float[][] powerData) {
|
||||
this.powerData = powerData;
|
||||
}
|
||||
|
||||
public float[][] getCorrelationData() {
|
||||
return correlationData;
|
||||
}
|
||||
|
||||
public void setCorrelationData(float[][] correlationData) {
|
||||
this.correlationData = correlationData;
|
||||
}
|
||||
|
||||
public float[][] getFkData() {
|
||||
return fkData;
|
||||
}
|
||||
|
||||
public void setFkData(float[][] fkData) {
|
||||
this.fkData = fkData;
|
||||
}
|
||||
|
||||
public float[][] getHkData() {
|
||||
return hkData;
|
||||
}
|
||||
|
||||
public void setHkData(float[][] hkData) {
|
||||
this.hkData = hkData;
|
||||
}
|
||||
|
||||
public float[] getCanonicalCorrelation() {
|
||||
return canonicalCorrelation;
|
||||
}
|
||||
|
||||
public void setCanonicalCorrelation(float[] canonicalCorrelation) {
|
||||
this.canonicalCorrelation = canonicalCorrelation;
|
||||
}
|
||||
|
||||
public float[] getBackgroundCanonicalCorr() {
|
||||
return backgroundCanonicalCorr;
|
||||
}
|
||||
|
||||
public void setBackgroundCanonicalCorr(float[] backgroundCanonicalCorr) {
|
||||
this.backgroundCanonicalCorr = backgroundCanonicalCorr;
|
||||
}
|
||||
|
||||
public CalculationStatus getCalculationStatus() {
|
||||
return calculationStatus;
|
||||
}
|
||||
|
||||
public void setCalculationStatus(CalculationStatus calculationStatus) {
|
||||
this.calculationStatus = calculationStatus;
|
||||
}
|
||||
|
||||
public float[] getSumFKData() {
|
||||
return sumFKData;
|
||||
}
|
||||
|
||||
public void setSumFKData(float[] sumFKData) {
|
||||
this.sumFKData = sumFKData;
|
||||
}
|
||||
|
||||
public float[] getSumHKData() {
|
||||
return sumHKData;
|
||||
}
|
||||
|
||||
public void setSumHKData(float[] sumHKData) {
|
||||
this.sumHKData = sumHKData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.njcn.advance.responsibility.service;
|
||||
|
||||
import com.njcn.advance.responsibility.model.HarmonicData;
|
||||
|
||||
/**
|
||||
* 谐波责任计算服务接口
|
||||
*
|
||||
* @author hongawen
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface IHarmonicResponsibilityService {
|
||||
|
||||
/**
|
||||
* 执行谐波责任计算
|
||||
*
|
||||
* @param data 输入的谐波数据
|
||||
* @return 计算是否成功
|
||||
*/
|
||||
boolean calculate(HarmonicData data);
|
||||
|
||||
/**
|
||||
* 执行完整计算
|
||||
*
|
||||
* @param harmonicData 谐波数据数组
|
||||
* @param powerData 功率数据矩阵
|
||||
* @param harmonicCount 谐波数据个数
|
||||
* @param powerCount 功率数据个数
|
||||
* @param nodeCount 节点数量
|
||||
* @param windowSize 窗口大小
|
||||
* @param threshold 谐波门槛
|
||||
* @return 计算结果
|
||||
*/
|
||||
HarmonicData fullCalculation(float[] harmonicData, float[][] powerData,
|
||||
int harmonicCount, int powerCount, int nodeCount,
|
||||
int windowSize, float threshold);
|
||||
|
||||
/**
|
||||
* 执行部分重算
|
||||
*
|
||||
* @param harmonicData 谐波数据数组
|
||||
* @param fkData FK数据矩阵
|
||||
* @param hkData HK数据矩阵
|
||||
* @param harmonicCount 谐波数据个数
|
||||
* @param nodeCount 节点数量
|
||||
* @param windowSize 窗口大小
|
||||
* @param responsibilityCount 责任数据个数
|
||||
* @param threshold 谐波门槛
|
||||
* @return 计算结果
|
||||
*/
|
||||
HarmonicData partialCalculation(float[] harmonicData, float[][] fkData, float[][] hkData,
|
||||
int harmonicCount, int nodeCount, int windowSize,
|
||||
int responsibilityCount, float threshold);
|
||||
|
||||
/**
|
||||
* 验证输入数据的有效性
|
||||
*
|
||||
* @param data 待验证的数据
|
||||
* @return 验证结果消息,null表示验证通过
|
||||
*/
|
||||
String validateData(HarmonicData data);
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package com.njcn.advance.responsibility.service.impl;
|
||||
|
||||
import com.njcn.advance.responsibility.calculator.HarmonicCalculationEngine;
|
||||
import com.njcn.advance.responsibility.constant.CalculationMode;
|
||||
import com.njcn.advance.responsibility.constant.HarmonicConstants;
|
||||
import com.njcn.advance.responsibility.model.HarmonicData;
|
||||
import com.njcn.advance.responsibility.service.IHarmonicResponsibilityService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 谐波责任计算服务实现类
|
||||
*
|
||||
* @author hongawen
|
||||
* @version 1.0
|
||||
*/
|
||||
@Service
|
||||
public class HarmonicResponsibilityServiceImpl implements IHarmonicResponsibilityService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(HarmonicResponsibilityServiceImpl.class);
|
||||
|
||||
private final HarmonicCalculationEngine engine;
|
||||
|
||||
public HarmonicResponsibilityServiceImpl() {
|
||||
this.engine = new HarmonicCalculationEngine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean calculate(HarmonicData data) {
|
||||
if (data == null) {
|
||||
logger.error("Input data is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
String validationError = validateData(data);
|
||||
if (validationError != null) {
|
||||
logger.error("Data validation failed: {}", validationError);
|
||||
return false;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
boolean result = engine.calculate(data);
|
||||
long endTime = System.currentTimeMillis();
|
||||
|
||||
logger.info("Calculation completed in {} ms, result: {}", (endTime - startTime), result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HarmonicData fullCalculation(float[] harmonicData, float[][] powerData,
|
||||
int harmonicCount, int powerCount, int nodeCount,
|
||||
int windowSize, float threshold) {
|
||||
logger.info("Starting full calculation with harmonicCount={}, powerCount={}, nodeCount={}, windowSize={}",
|
||||
harmonicCount, powerCount, nodeCount, windowSize);
|
||||
|
||||
HarmonicData data = new HarmonicData.Builder()
|
||||
.calculationMode(CalculationMode.FULL_CALCULATION)
|
||||
.harmonicCount(harmonicCount)
|
||||
.powerCount(powerCount)
|
||||
.powerNodeCount(nodeCount)
|
||||
.windowSize(windowSize)
|
||||
.harmonicThreshold(threshold)
|
||||
.harmonicData(harmonicData)
|
||||
.powerData(powerData)
|
||||
.build();
|
||||
|
||||
calculate(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HarmonicData partialCalculation(float[] harmonicData, float[][] fkData, float[][] hkData,
|
||||
int harmonicCount, int nodeCount, int windowSize,
|
||||
int responsibilityCount, float threshold) {
|
||||
logger.info("Starting partial calculation with harmonicCount={}, nodeCount={}, windowSize={}, responsibilityCount={}",
|
||||
harmonicCount, nodeCount, windowSize, responsibilityCount);
|
||||
|
||||
HarmonicData data = new HarmonicData();
|
||||
data.setCalculationMode(CalculationMode.PARTIAL_RECALCULATION);
|
||||
data.setHarmonicCount(harmonicCount);
|
||||
data.setPowerNodeCount(nodeCount);
|
||||
data.setWindowSize(windowSize);
|
||||
data.setResponsibilityDataCount(responsibilityCount);
|
||||
data.setHarmonicThreshold(threshold);
|
||||
data.setHarmonicData(harmonicData);
|
||||
data.setFkData(fkData);
|
||||
data.setHkData(hkData);
|
||||
|
||||
// 初始化输出数组
|
||||
data.setSumFKData(new float[nodeCount]);
|
||||
data.setSumHKData(new float[nodeCount + 1]);
|
||||
|
||||
calculate(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String validateData(HarmonicData data) {
|
||||
if (data == null) {
|
||||
return "Data object is null";
|
||||
}
|
||||
|
||||
// 验证基本参数
|
||||
if (data.getHarmonicCount() <= 0 || data.getHarmonicCount() > HarmonicConstants.MAX_HARM_NUM) {
|
||||
return String.format("Invalid harmonic count: %d (should be 1-%d)",
|
||||
data.getHarmonicCount(), HarmonicConstants.MAX_HARM_NUM);
|
||||
}
|
||||
|
||||
if (data.getCalculationMode() == CalculationMode.FULL_CALCULATION) {
|
||||
// 完整计算模式验证
|
||||
if (data.getPowerCount() <= 0 || data.getPowerCount() > HarmonicConstants.MAX_P_NUM) {
|
||||
return String.format("Invalid power count: %d (should be 1-%d)",
|
||||
data.getPowerCount(), HarmonicConstants.MAX_P_NUM);
|
||||
}
|
||||
|
||||
if (data.getPowerNodeCount() <= 0 || data.getPowerNodeCount() > HarmonicConstants.MAX_P_NODE) {
|
||||
return String.format("Invalid power node count: %d (should be 1-%d)",
|
||||
data.getPowerNodeCount(), HarmonicConstants.MAX_P_NODE);
|
||||
}
|
||||
|
||||
// 验证数据对齐
|
||||
int ratio = data.getHarmonicCount() / data.getPowerCount();
|
||||
if (ratio * data.getPowerCount() != data.getHarmonicCount()) {
|
||||
return String.format("Harmonic count %d is not aligned with power count %d",
|
||||
data.getHarmonicCount(), data.getPowerCount());
|
||||
}
|
||||
|
||||
// 验证数据数组
|
||||
if (data.getHarmonicData() == null || data.getHarmonicData().length < data.getHarmonicCount()) {
|
||||
return "Harmonic data array is null or insufficient";
|
||||
}
|
||||
|
||||
if (data.getPowerData() == null || data.getPowerData().length < data.getPowerCount()) {
|
||||
return "Power data array is null or insufficient";
|
||||
}
|
||||
|
||||
} else if (data.getCalculationMode() == CalculationMode.PARTIAL_RECALCULATION) {
|
||||
// 部分计算模式验证
|
||||
if (data.getResponsibilityDataCount() + data.getWindowSize() != data.getHarmonicCount()) {
|
||||
return String.format("Data length mismatch: resNum(%d) + winSize(%d) != harmCount(%d)",
|
||||
data.getResponsibilityDataCount(), data.getWindowSize(), data.getHarmonicCount());
|
||||
}
|
||||
|
||||
if (data.getFkData() == null || data.getHkData() == null) {
|
||||
return "FK or HK data is null for partial calculation";
|
||||
}
|
||||
}
|
||||
|
||||
// 验证窗口大小
|
||||
if (data.getWindowSize() < HarmonicConstants.MIN_WIN_LEN ||
|
||||
data.getWindowSize() > HarmonicConstants.MAX_WIN_LEN) {
|
||||
return String.format("Invalid window size: %d (should be %d-%d)",
|
||||
data.getWindowSize(), HarmonicConstants.MIN_WIN_LEN, HarmonicConstants.MAX_WIN_LEN);
|
||||
}
|
||||
|
||||
return null; // 验证通过
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,314 @@
|
||||
package com.njcn.advance.responsibility.utils;
|
||||
|
||||
import com.njcn.advance.responsibility.constant.HarmonicConstants;
|
||||
import org.apache.commons.math3.linear.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 数学工具类
|
||||
* 提供基础数学计算功能
|
||||
*
|
||||
* @author hongawen
|
||||
* @version 1.0
|
||||
*/
|
||||
public class MathUtils {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MathUtils.class);
|
||||
|
||||
/**
|
||||
* 计算协方差
|
||||
*
|
||||
* @param x 数据序列1
|
||||
* @param y 数据序列2
|
||||
* @param width 数据窗宽度
|
||||
* @return 协方差值
|
||||
*/
|
||||
public static double covariance(double[] x, double[] y, int width) {
|
||||
if (x == null || y == null || width <= 0) {
|
||||
throw new IllegalArgumentException("Invalid input parameters for covariance calculation");
|
||||
}
|
||||
|
||||
if (x.length < width || y.length < width) {
|
||||
throw new IllegalArgumentException("Data length is less than window width");
|
||||
}
|
||||
|
||||
double meanX = 0.0;
|
||||
double meanY = 0.0;
|
||||
|
||||
// 计算均值
|
||||
for (int i = 0; i < width; i++) {
|
||||
meanX += x[i];
|
||||
meanY += y[i];
|
||||
}
|
||||
meanX /= width;
|
||||
meanY /= width;
|
||||
|
||||
// 计算协方差
|
||||
double cov = 0.0;
|
||||
for (int i = 0; i < width; i++) {
|
||||
cov += (x[i] - meanX) * (y[i] - meanY);
|
||||
}
|
||||
|
||||
return cov / (width - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算协方差(float版本)
|
||||
*/
|
||||
public static float covariance(float[] x, float[] y, int width) {
|
||||
double[] dx = new double[x.length];
|
||||
double[] dy = new double[y.length];
|
||||
for (int i = 0; i < x.length; i++) dx[i] = x[i];
|
||||
for (int i = 0; i < y.length; i++) dy[i] = y[i];
|
||||
return (float) covariance(dx, dy, width);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算Pearson相关系数
|
||||
*
|
||||
* @param x 数据序列1
|
||||
* @param y 数据序列2
|
||||
* @param count 数据长度
|
||||
* @return Pearson相关系数
|
||||
*/
|
||||
public static double pearsonCorrelation(double[] x, double[] y, int count) {
|
||||
if (x == null || y == null || count <= 0) {
|
||||
throw new IllegalArgumentException("Invalid input parameters for Pearson correlation");
|
||||
}
|
||||
|
||||
double meanX = 0.0;
|
||||
double meanY = 0.0;
|
||||
|
||||
// 计算均值
|
||||
for (int i = 0; i < count; i++) {
|
||||
meanX += x[i];
|
||||
meanY += y[i];
|
||||
}
|
||||
meanX /= count;
|
||||
meanY /= count;
|
||||
|
||||
// 计算相关系数的各个部分
|
||||
double numerator = 0.0;
|
||||
double denomX = 0.0;
|
||||
double denomY = 0.0;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
double dx = x[i] - meanX;
|
||||
double dy = y[i] - meanY;
|
||||
numerator += dx * dy;
|
||||
denomX += dx * dx;
|
||||
denomY += dy * dy;
|
||||
}
|
||||
|
||||
double denominator = Math.sqrt(denomX * denomY);
|
||||
|
||||
if (Math.abs(denominator) < HarmonicConstants.EPSILON) {
|
||||
logger.warn("Denominator is too small in Pearson correlation calculation");
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return numerator / denominator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算Pearson相关系数(float版本)
|
||||
*/
|
||||
public static float pearsonCorrelation(float[] x, float[] y, int count) {
|
||||
double[] dx = new double[count];
|
||||
double[] dy = new double[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
dx[i] = x[i];
|
||||
dy[i] = y[i];
|
||||
}
|
||||
return (float) pearsonCorrelation(dx, dy, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算协方差矩阵(SXX)
|
||||
*
|
||||
* @param data 数据矩阵 [时间][节点]
|
||||
* @param width 窗口宽度
|
||||
* @param nodeCount 节点数
|
||||
* @return 协方差矩阵
|
||||
*/
|
||||
public static double[][] covarianceMatrix(double[][] data, int width, int nodeCount) {
|
||||
double[][] covMatrix = new double[nodeCount][nodeCount];
|
||||
|
||||
for (int i = 0; i < nodeCount; i++) {
|
||||
for (int j = 0; j < nodeCount; j++) {
|
||||
double[] col1 = new double[width];
|
||||
double[] col2 = new double[width];
|
||||
|
||||
for (int k = 0; k < width; k++) {
|
||||
col1[k] = data[k][i];
|
||||
col2[k] = data[k][j];
|
||||
}
|
||||
|
||||
covMatrix[i][j] = covariance(col1, col2, width);
|
||||
}
|
||||
}
|
||||
|
||||
return covMatrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算协方差矩阵(float版本)
|
||||
*/
|
||||
public static float[][] covarianceMatrix(float[][] data, int width, int nodeCount) {
|
||||
float[][] covMatrix = new float[nodeCount][nodeCount];
|
||||
|
||||
for (int i = 0; i < nodeCount; i++) {
|
||||
for (int j = 0; j < nodeCount; j++) {
|
||||
float[] col1 = new float[width];
|
||||
float[] col2 = new float[width];
|
||||
|
||||
for (int k = 0; k < width; k++) {
|
||||
col1[k] = data[k][i];
|
||||
col2[k] = data[k][j];
|
||||
}
|
||||
|
||||
covMatrix[i][j] = covariance(col1, col2, width);
|
||||
}
|
||||
}
|
||||
|
||||
return covMatrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算协方差向量(SXY)
|
||||
*
|
||||
* @param data 数据矩阵 [时间][节点]
|
||||
* @param y 目标向量
|
||||
* @param width 窗口宽度
|
||||
* @param nodeCount 节点数
|
||||
* @return 协方差向量
|
||||
*/
|
||||
public static double[] covarianceVector(double[][] data, double[] y, int width, int nodeCount) {
|
||||
double[] covVector = new double[nodeCount];
|
||||
|
||||
for (int i = 0; i < nodeCount; i++) {
|
||||
double[] col = new double[width];
|
||||
for (int k = 0; k < width; k++) {
|
||||
col[k] = data[k][i];
|
||||
}
|
||||
covVector[i] = covariance(col, y, width);
|
||||
}
|
||||
|
||||
return covVector;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算协方差向量(float版本)
|
||||
*/
|
||||
public static float[] covarianceVector(float[][] data, float[] y, int width, int nodeCount) {
|
||||
float[] covVector = new float[nodeCount];
|
||||
|
||||
for (int i = 0; i < nodeCount; i++) {
|
||||
float[] col = new float[width];
|
||||
for (int k = 0; k < width; k++) {
|
||||
col[k] = data[k][i];
|
||||
}
|
||||
covVector[i] = covariance(col, y, width);
|
||||
}
|
||||
|
||||
return covVector;
|
||||
}
|
||||
|
||||
/**
|
||||
* 矩阵求逆
|
||||
* 使用Apache Commons Math库
|
||||
*
|
||||
* @param matrix 输入矩阵
|
||||
* @return 逆矩阵
|
||||
*/
|
||||
public static double[][] matrixInverse(double[][] matrix) {
|
||||
RealMatrix realMatrix = new Array2DRowRealMatrix(matrix);
|
||||
|
||||
try {
|
||||
// 使用LU分解求逆
|
||||
DecompositionSolver solver = new LUDecomposition(realMatrix).getSolver();
|
||||
RealMatrix inverseMatrix = solver.getInverse();
|
||||
return inverseMatrix.getData();
|
||||
} catch (SingularMatrixException e) {
|
||||
logger.error("Matrix is singular, cannot compute inverse", e);
|
||||
throw new RuntimeException("Matrix inversion failed: singular matrix");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算矩阵的特征值
|
||||
*
|
||||
* @param matrix 输入矩阵
|
||||
* @return 特征值数组
|
||||
*/
|
||||
public static double[] eigenvalues(double[][] matrix) {
|
||||
RealMatrix realMatrix = new Array2DRowRealMatrix(matrix);
|
||||
EigenDecomposition eigenDecomposition = new EigenDecomposition(realMatrix);
|
||||
return eigenDecomposition.getRealEigenvalues();
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化处理
|
||||
* 将数据归一化到[0,1]区间
|
||||
*
|
||||
* @param data 输入数据
|
||||
* @return 归一化后的数据
|
||||
*/
|
||||
public static double[] normalize(double[] data) {
|
||||
if (data == null || data.length == 0) {
|
||||
return data;
|
||||
}
|
||||
|
||||
double min = Double.MAX_VALUE;
|
||||
double max = Double.MIN_VALUE;
|
||||
|
||||
// 找最大最小值
|
||||
for (double value : data) {
|
||||
min = Math.min(min, value);
|
||||
max = Math.max(max, value);
|
||||
}
|
||||
|
||||
double range = max - min;
|
||||
if (Math.abs(range) < HarmonicConstants.EPSILON) {
|
||||
return new double[data.length]; // 返回全0数组
|
||||
}
|
||||
|
||||
double[] normalized = new double[data.length];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
normalized[i] = (data[i] - min) / range;
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据对齐处理
|
||||
* 将不同采样间隔的数据对齐到相同的时间间隔
|
||||
*
|
||||
* @param data 原始数据
|
||||
* @param originalInterval 原始采样间隔
|
||||
* @param targetInterval 目标采样间隔
|
||||
* @return 对齐后的数据
|
||||
*/
|
||||
public static float[] alignData(float[] data, int originalInterval, int targetInterval) {
|
||||
if (targetInterval % originalInterval != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Target interval must be multiple of original interval");
|
||||
}
|
||||
|
||||
int ratio = targetInterval / originalInterval;
|
||||
int newLength = data.length / ratio;
|
||||
float[] alignedData = new float[newLength];
|
||||
|
||||
for (int i = 0; i < newLength; i++) {
|
||||
float sum = 0;
|
||||
for (int j = 0; j < ratio; j++) {
|
||||
sum += data[i * ratio + j];
|
||||
}
|
||||
alignedData[i] = sum / ratio;
|
||||
}
|
||||
|
||||
return alignedData;
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,7 @@ public class GovernSchemeCalcServiceImpl implements IGovernSchemeCalcService {
|
||||
throw new BusinessException(AdvanceResponseEnum.INCOMING_LINE_DATA_MISS);
|
||||
}
|
||||
sgGovernSchemeHistoryAllVO.setInComingLineName(sgIncomingLine.getName());
|
||||
sgGovernSchemeHistoryAllVO.getQuick().setIncomingLineId(sgIncomingLine.getName());
|
||||
//时间内的电网接入水平(暂降次数)
|
||||
String startTime = sgGovernSchemeHistoryParam.getStartTime();
|
||||
String endTime = sgGovernSchemeHistoryParam.getEndTime();
|
||||
|
||||
@@ -854,6 +854,21 @@ public class EventRelevantAnalysisServiceImpl extends ServiceImpl<RmpEventAdvanc
|
||||
/*************************************************************************************
|
||||
* 获取变压器信息并生成矩阵
|
||||
*************************************************************************************/
|
||||
public Map<String, Map<String, Integer>> getNodeBefore(){
|
||||
Map<String, EntityMtrans> entityMtranMap = new HashMap<>(32);
|
||||
|
||||
HandleEvent handleEvent = new HandleEvent();
|
||||
List<EntityLogic> list = relevantLogMapper.getLogic();
|
||||
Map<String, Map<String, Integer>> setNodeSort = new HashMap<>();
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
Map<String, List<String>> map = getLogicInfo(list);
|
||||
setNodeSort = nodeSort(map);
|
||||
}
|
||||
|
||||
return setNodeSort;
|
||||
}
|
||||
|
||||
|
||||
public Map<String, EntityMtrans> getNodeInfo( ) {
|
||||
Map<String, EntityMtrans> entityMtranMap = new HashMap<>(32);
|
||||
|
||||
|
||||
@@ -21,8 +21,12 @@ import java.util.List;
|
||||
*/
|
||||
public interface IRespDataService extends IService<RespData> {
|
||||
|
||||
ResponsibilityResult getDynamicDataOld(ResponsibilityCalculateParam responsibilityCalculateParam);
|
||||
|
||||
ResponsibilityResult getDynamicData(ResponsibilityCalculateParam responsibilityCalculateParam);
|
||||
|
||||
ResponsibilityResult getResponsibilityDataOld(ResponsibilitySecondCalParam responsibilitySecondCalParam);
|
||||
|
||||
ResponsibilityResult getResponsibilityData(ResponsibilitySecondCalParam responsibilitySecondCalParam);
|
||||
|
||||
Page<RespDataDTO> responsibilityList(BaseParam queryParam);
|
||||
|
||||
@@ -27,6 +27,9 @@ import com.njcn.advance.pojo.param.ResponsibilityCalculateParam;
|
||||
import com.njcn.advance.pojo.param.ResponsibilitySecondCalParam;
|
||||
import com.njcn.advance.pojo.po.responsibility.RespData;
|
||||
import com.njcn.advance.pojo.po.responsibility.RespDataResult;
|
||||
import com.njcn.advance.responsibility.constant.CalculationStatus;
|
||||
import com.njcn.advance.responsibility.model.HarmonicData;
|
||||
import com.njcn.advance.responsibility.service.IHarmonicResponsibilityService;
|
||||
import com.njcn.advance.service.responsibility.IRespDataResultService;
|
||||
import com.njcn.advance.service.responsibility.IRespDataService;
|
||||
import com.njcn.advance.service.responsibility.IRespUserDataService;
|
||||
@@ -91,6 +94,8 @@ public class RespDataServiceImpl extends ServiceImpl<RespDataMapper, RespData> i
|
||||
|
||||
private final CommTerminalGeneralClient commTerminalGeneralClient;
|
||||
|
||||
private final IHarmonicResponsibilityService harmonicResponsibilityService;
|
||||
|
||||
public final static int SORT_10 = 10;
|
||||
public final static int INTERVAL_TIME_1 = 1;
|
||||
public final static int INTERVAL_TIME_3 = 3;
|
||||
@@ -161,7 +166,8 @@ public class RespDataServiceImpl extends ServiceImpl<RespDataMapper, RespData> i
|
||||
|
||||
|
||||
@Override
|
||||
public ResponsibilityResult getDynamicData(ResponsibilityCalculateParam responsibilityCalculateParam) {
|
||||
@Deprecated
|
||||
public ResponsibilityResult getDynamicDataOld(ResponsibilityCalculateParam responsibilityCalculateParam) {
|
||||
ResponsibilityResult result = new ResponsibilityResult();
|
||||
//调用c++依赖需要待初始化的参数
|
||||
int pNode, pNum, win, harmNum;
|
||||
@@ -419,7 +425,268 @@ public class RespDataServiceImpl extends ServiceImpl<RespDataMapper, RespData> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponsibilityResult getResponsibilityData(ResponsibilitySecondCalParam responsibilitySecondCalParam) {
|
||||
public ResponsibilityResult getDynamicData(ResponsibilityCalculateParam responsibilityCalculateParam) {
|
||||
ResponsibilityResult result = new ResponsibilityResult();
|
||||
//调用c++依赖需要待初始化的参数
|
||||
int pNode, pNum, win, harmNum;
|
||||
float harmMk;
|
||||
List<UserDataExcel> userDataExcels = respUserDataService.getUserDataExcelList(responsibilityCalculateParam.getUserDataId());
|
||||
//开始处理,根据接口参数需求,需要节点数(用户数,用户名+监测点号为一个用户),时间范围内功率数据
|
||||
DealDataResult dealDataResult = RespUserDataServiceImpl.getStanderData(userDataExcels, 1);
|
||||
List<String> dateStr = PubUtils.getTimes(DateUtil.parse(responsibilityCalculateParam.getSearchBeginTime(), DatePattern.NORM_DATE_PATTERN), DateUtil.parse(responsibilityCalculateParam.getSearchEndTime(), DatePattern.NORM_DATE_PATTERN));
|
||||
Map<String/*户号@监测点号@户名*/, Map<String/*yyyy-MM-dd天日期*/, List<UserDataExcel>>> finalData = getFinalUserData(dealDataResult, dateStr);
|
||||
//至此,finalData便是我们最终获得的用于计算责任数据,第一个参数节点数值pNode获取到
|
||||
//第一个参数pNode
|
||||
pNode = finalData.size();
|
||||
if (pNode < 1) {
|
||||
//没有合理的用采数据直接返回
|
||||
throw new BusinessException(AdvanceResponseEnum.USER_DATA_P_NODE_PARAMETER_ERROR);
|
||||
}
|
||||
//第二个参数pNum,根据起始时间和截止时间以及监测点测量间隔计算数量
|
||||
RespCommon pNumAndInterval = getPNumAndInterval(finalData, responsibilityCalculateParam.getLineId(), dateStr);
|
||||
pNum = pNumAndInterval.getPNum();
|
||||
int userIntervalTime = pNumAndInterval.getUserIntervalTime();
|
||||
int lineInterval = pNumAndInterval.getLineInterval();
|
||||
//第三个参数win,根据起始时间和截止时间的间隔
|
||||
if (dateStr.size() > 1) {
|
||||
if (userIntervalTime == INTERVAL_TIME_15) {
|
||||
win = WINDOW_96;
|
||||
} else {
|
||||
win = WINDOW_48;
|
||||
}
|
||||
} else {
|
||||
win = WINDOW_4;
|
||||
}
|
||||
//第四个参数harmMk,默认为0f
|
||||
harmMk = 0f;
|
||||
//第五个参数harmNum,与功率数据保持一致
|
||||
harmNum = pNum;
|
||||
//至此基础数据组装完毕,开始组装功率数据和谐波数据
|
||||
//先做谐波数据,理论上到这步的时候,谐波数据是满足完整性并已经补充完整性到100%,此处需要将谐波数据与功率数据长度匹配上
|
||||
RespHarmData respHarmData = getRespHarmData(responsibilityCalculateParam, lineInterval);
|
||||
//harmData填充完毕后,开始组装功率数据
|
||||
//首先获取当前时间内的各个用户的数据
|
||||
Map<String/*用户名*/, List<UserDataExcel>> originalPData = new HashMap<>(16);
|
||||
List<String> names = new ArrayList<>();
|
||||
Set<String> userNamesFinal = finalData.keySet();
|
||||
for (String userName : userNamesFinal) {
|
||||
List<UserDataExcel> tempData = new ArrayList<>();
|
||||
//根据日期将日期数据全部获取出来z
|
||||
Map<String, List<UserDataExcel>> tempResult = finalData.get(userName);
|
||||
for (String date : dateStr) {
|
||||
tempData.addAll(tempResult.get(date));
|
||||
}
|
||||
//按日期排序
|
||||
Collections.sort(tempData);
|
||||
originalPData.put(userName, tempData);
|
||||
names.add(userName);
|
||||
}
|
||||
//然后开始组装数据
|
||||
float[][] pData = new float[QvvrDataEntity.MAX_P_NUM][QvvrDataEntity.MAX_P_NODE];
|
||||
for (int i = 0; i < names.size(); i++) {
|
||||
//当前某用户测量节点的所有数据
|
||||
List<UserDataExcel> userDataExcelBodies1 = originalPData.get(names.get(i));
|
||||
for (int k = 0; k < userDataExcelBodies1.size(); k++) {
|
||||
float[] pDataStruct = pData[k];
|
||||
if (pDataStruct == null) {
|
||||
pDataStruct = new float[QvvrDataEntity.MAX_P_NODE];
|
||||
}
|
||||
float[] p = pDataStruct;
|
||||
p[i] = userDataExcelBodies1.get(k).getWork().floatValue();
|
||||
pData[k] = pDataStruct;
|
||||
}
|
||||
}
|
||||
//至此功率数据也组装完毕,调用友谊提供的接口
|
||||
// QvvrDataEntity qvvrDataEntity = new QvvrDataEntity();
|
||||
// qvvrDataEntity.calFlag = 0;
|
||||
// qvvrDataEntity.pNode = pNode;
|
||||
// qvvrDataEntity.pNum = pNum;
|
||||
// qvvrDataEntity.win = win;
|
||||
// qvvrDataEntity.harmNum = harmNum;
|
||||
// qvvrDataEntity.harmMk = harmMk;
|
||||
// qvvrDataEntity.pData = pData;
|
||||
// qvvrDataEntity.harmData = respHarmData.getHarmData();
|
||||
// ResponsibilityAlgorithm responsibilityAlgorithm = new ResponsibilityAlgorithm();
|
||||
// qvvrDataEntity = responsibilityAlgorithm.getResponsibilityResult(qvvrDataEntity);
|
||||
|
||||
HarmonicData harmonicData = harmonicResponsibilityService.fullCalculation(respHarmData.getHarmData(), pData, harmNum, pNum, pNode, win, harmMk);
|
||||
//至此接口调用结束,开始组装动态责任数据和用户责任量化结果
|
||||
//首先判断cal_ok的标识位是否为1,为0表示程序没有计算出结果
|
||||
if (harmonicData.getCalculationStatus() == CalculationStatus.FAILED) {
|
||||
throw new BusinessException(AdvanceResponseEnum.RESPONSIBILITY_PARAMETER_ERROR);
|
||||
}
|
||||
//没问题后,先玩动态责任数据
|
||||
CustomerData[] customerDatas = new CustomerData[harmonicData.getPowerNodeCount()];
|
||||
float[][] fKdata/*无背景的动态责任数据*/ = harmonicData.getFkData();
|
||||
//第一个时间节点是起始时间+win窗口得到的时间
|
||||
Date sTime = DateUtil.parse(dateStr.get(0).concat(" 00:00:00"), DatePattern.NORM_DATETIME_PATTERN);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(sTime);
|
||||
calendar.add(Calendar.MINUTE, (win - 1) * userIntervalTime);
|
||||
List<Long> timeDatas = new ArrayList<>();
|
||||
for (int i = 0; i < harmonicData.getPowerCount() - harmonicData.getWindowSize(); i++) {
|
||||
calendar.add(Calendar.MINUTE, userIntervalTime);
|
||||
//一个时间点所有的用户数据
|
||||
float[] fKdatum = fKdata[i];
|
||||
for (int k = 0; k < harmonicData.getPowerNodeCount(); k++) {
|
||||
CustomerData customerData = customerDatas[k];
|
||||
if (null == customerData) {
|
||||
customerData = new CustomerData();
|
||||
customerData.setCustomerName(names.get(k));
|
||||
}
|
||||
List<Float> valueDatas = customerData.getValueDatas();
|
||||
Float valueTemp = fKdatum[k];
|
||||
if (valueTemp.isNaN()) {
|
||||
valueTemp = 0.0f;
|
||||
}
|
||||
valueDatas.add(valueTemp);
|
||||
customerData.setValueDatas(valueDatas);
|
||||
customerDatas[k] = customerData;
|
||||
}
|
||||
timeDatas.add(calendar.getTimeInMillis());
|
||||
}
|
||||
//OK拿到所有测量点的数据了,现在就是看如何将相同户号的动态数据进行算术和求值,之前的用户name为:户号@测量点号@用户名
|
||||
Map<String/*用户名(户号)*/, List<CustomerData>> customerDataTemp = new HashMap<>(16);
|
||||
for (CustomerData data : customerDatas) {
|
||||
String customerName = data.getCustomerName();
|
||||
String[] customerInfo = customerName.split("@");
|
||||
String name = customerInfo[2] + "(" + customerInfo[0] + ")";
|
||||
List<CustomerData> customerData = customerDataTemp.get(name);
|
||||
CustomerData temp = data;
|
||||
temp.setCustomerName(name);
|
||||
if (CollectionUtils.isEmpty(customerData)) {
|
||||
customerData = new ArrayList<>();
|
||||
}
|
||||
customerData.add(temp);
|
||||
customerDataTemp.put(name, customerData);
|
||||
}
|
||||
//动态数据组装完成后,开始组装责任数据
|
||||
List<CustomerResponsibility> customerResponsibilities = getCustomerResponsibilityData(names, harmonicData.getSumFKData(), harmonicData.getPowerNodeCount());
|
||||
//根据前十的用户数据,获取这些用户的动态责任数据
|
||||
List<CustomerData> customerData = new ArrayList<>();
|
||||
for (CustomerResponsibility customerResponsibility : customerResponsibilities) {
|
||||
String cusName = customerResponsibility.getCustomerName();
|
||||
List<CustomerData> customerData1 = customerDataTemp.get(cusName);
|
||||
if (CollectionUtils.isEmpty(customerData1)) {
|
||||
continue;
|
||||
}
|
||||
if (customerData1.size() == 1) {
|
||||
//表示用户唯一的
|
||||
customerData.add(customerData1.get(0));
|
||||
} else {
|
||||
// 表示用户可能包含多个监测点号,需要进行数据累加
|
||||
CustomerData customerDataT = new CustomerData();
|
||||
customerDataT.setCustomerName(cusName);
|
||||
//进行数值累加
|
||||
List<Float> valueDatas = new ArrayList<>();
|
||||
for (int i = 0; i < customerData1.get(0).getValueDatas().size(); i++) {
|
||||
float original = 0.0f;
|
||||
for (CustomerData data : customerData1) {
|
||||
original = original + data.getValueDatas().get(i);
|
||||
}
|
||||
valueDatas.add(original);
|
||||
}
|
||||
customerDataT.setValueDatas(valueDatas);
|
||||
customerData.add(customerDataT);
|
||||
}
|
||||
}
|
||||
result.setDatas(customerData);
|
||||
result.setTimeDatas(timeDatas);
|
||||
result.setResponsibilities(customerResponsibilities);
|
||||
//此次的操作进行入库操作responsibilityData表数据
|
||||
//根据监测点名称+谐波框选的时间来查询,是否做过责任量化
|
||||
String timeWin = responsibilityCalculateParam.getSearchBeginTime().replaceAll(StrPool.DASHED, "").concat(StrPool.DASHED).concat(responsibilityCalculateParam.getSearchEndTime().replaceAll(StrPool.DASHED, ""));
|
||||
String type = responsibilityCalculateParam.getType() == 0 ? "谐波电流" : "谐波电压";
|
||||
//为了避免有监测点名称重复的,最终还是选择使用监测点索引来判断唯一性
|
||||
LambdaQueryWrapper<RespData> respDataLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
respDataLambdaQueryWrapper.eq(RespData::getLineId, responsibilityCalculateParam.getLineId())
|
||||
.eq(RespData::getUserDataId, responsibilityCalculateParam.getUserDataId())
|
||||
.eq(RespData::getTimeWindow, timeWin)
|
||||
.eq(RespData::getDataType, type)
|
||||
.eq(RespData::getState, DataStateEnum.ENABLE.getCode());
|
||||
List<RespData> responsibilityDataTemp = this.baseMapper.selectList(respDataLambdaQueryWrapper);
|
||||
RespData responsibilityData;
|
||||
if (CollectionUtils.isEmpty(responsibilityDataTemp)) {
|
||||
responsibilityData = new RespData();
|
||||
//库中没有记录则可以新建数据进行插入
|
||||
responsibilityData.setLineId(responsibilityCalculateParam.getLineId());
|
||||
responsibilityData.setUserDataId(responsibilityCalculateParam.getUserDataId());
|
||||
responsibilityData.setDataType(type);
|
||||
responsibilityData.setDataTimes(responsibilityCalculateParam.getTime().toString());
|
||||
responsibilityData.setTimeWindow(timeWin);
|
||||
responsibilityData.setState(DataStateEnum.ENABLE.getCode());
|
||||
//进行插入操作
|
||||
this.baseMapper.insert(responsibilityData);
|
||||
} else {
|
||||
//库中存在记录只需要判断次数进行数据更新
|
||||
responsibilityData = responsibilityDataTemp.get(0);
|
||||
String times = responsibilityData.getDataTimes();
|
||||
List<String> timesList = Stream.of(times.split(StrPool.COMMA)).collect(Collectors.toList());
|
||||
Integer time = responsibilityCalculateParam.getTime();
|
||||
if (!timesList.contains(time.toString())) {
|
||||
timesList.add(time.toString());
|
||||
timesList = timesList.stream().sorted().collect(Collectors.toList());
|
||||
responsibilityData.setDataTimes(String.join(StrPool.COMMA, timesList));
|
||||
}
|
||||
//执行更新操作
|
||||
this.baseMapper.updateById(responsibilityData);
|
||||
}
|
||||
//入库完毕之后,需要将必要数据进行序列化存储,方便后期的重复利用
|
||||
/*
|
||||
* 需要序列化三种数据结构 1 cal_flag置为1时需要的一些列参数的CacheQvvrData 2 cal_flag为0时的,动态结果。3 用户责任量化结果
|
||||
* 其中1/2都只需要一个文件即可
|
||||
* 3因为用户限值的变化调整,可能存在很多个文件,具体根据用户的选择而定
|
||||
*
|
||||
* 路径的结构为,temPath+userData+excelName+type+timeWin+lineIndex+time+文件名
|
||||
* 用户责任量化结果,需要再细化到限值
|
||||
*/
|
||||
//首先判断有没有存储记录,没有则存储,有就略过 指定测点、时间窗口、谐波类型、谐波次数判断唯一性
|
||||
LambdaQueryWrapper<RespDataResult> respDataResultLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
respDataResultLambdaQueryWrapper.eq(RespDataResult::getResDataId, responsibilityData.getId())
|
||||
.eq(RespDataResult::getTime, responsibilityCalculateParam.getTime())
|
||||
.eq(RespDataResult::getStartTime, DateUtil.parse(responsibilityCalculateParam.getSearchBeginTime() + " 00:00:00", DatePattern.NORM_DATETIME_PATTERN))
|
||||
.eq(RespDataResult::getEndTime, DateUtil.parse(responsibilityCalculateParam.getSearchEndTime() + " 23:59:59", DatePattern.NORM_DATETIME_PATTERN))
|
||||
.eq(RespDataResult::getLimitValue, respHarmData.getOverLimit());
|
||||
RespDataResult respDataResult = respDataResultService.getOne(respDataResultLambdaQueryWrapper);
|
||||
if (Objects.isNull(respDataResult)) {
|
||||
respDataResult = new RespDataResult();
|
||||
respDataResult.setResDataId(responsibilityData.getId());
|
||||
respDataResult.setTime(responsibilityCalculateParam.getTime());
|
||||
respDataResult.setStartTime(DateUtil.parse(responsibilityCalculateParam.getSearchBeginTime() + " 00:00:00", DatePattern.NORM_DATETIME_PATTERN));
|
||||
respDataResult.setEndTime(DateUtil.parse(responsibilityCalculateParam.getSearchEndTime() + " 23:59:59", DatePattern.NORM_DATETIME_PATTERN));
|
||||
respDataResult.setLimitValue(respHarmData.getOverLimit());
|
||||
//时间横轴数据 timeDatas
|
||||
JSONArray timeDataJson = JSONArray.parseArray(JSON.toJSONString(timeDatas));
|
||||
InputStream timeDataStream = IoUtil.toUtf8Stream(timeDataJson.toString());
|
||||
String timeDataPath = fileStorageUtil.uploadStream(timeDataStream, OssPath.RESPONSIBILITY_USER_RESULT_DATA, FileUtil.generateFileName("json"));
|
||||
respDataResult.setTimeData(timeDataPath);
|
||||
//用户每时刻对应的责任数据
|
||||
JSONArray customerDataJson = JSONArray.parseArray(JSON.toJSONString(customerData));
|
||||
InputStream customerStream = IoUtil.toUtf8Stream(customerDataJson.toString());
|
||||
String customerPath = fileStorageUtil.uploadStream(customerStream, OssPath.RESPONSIBILITY_USER_RESULT_DATA, FileUtil.generateFileName("json"));
|
||||
respDataResult.setUserDetailData(customerPath);
|
||||
//调用qvvr生成的中间数据
|
||||
CacheQvvrData cacheQvvrData = new CacheQvvrData(harmonicData.getPowerNodeCount(), harmonicData.getHarmonicCount(), harmonicData.getHarmonicData(), harmonicData.getFkData(), harmonicData.getHkData(), names, userIntervalTime, harmonicData.getWindowSize(), userIntervalTime, respHarmData.getHarmTime());
|
||||
String cacheJson = PubUtils.obj2json(cacheQvvrData);
|
||||
InputStream cacheQvvrDataStream = IoUtil.toUtf8Stream(cacheJson);
|
||||
String cacheQvvrDataPath = fileStorageUtil.uploadStream(cacheQvvrDataStream, OssPath.RESPONSIBILITY_USER_RESULT_DATA, FileUtil.generateFileName("json"));
|
||||
respDataResult.setQvvrData(cacheQvvrDataPath);
|
||||
//用户前10数据存储
|
||||
JSONArray customerResJson = JSONArray.parseArray(JSON.toJSONString(customerResponsibilities));
|
||||
InputStream customerResStream = IoUtil.toUtf8Stream(customerResJson.toString());
|
||||
String customerResPath = fileStorageUtil.uploadStream(customerResStream, OssPath.RESPONSIBILITY_USER_RESULT_DATA, FileUtil.generateFileName("json"));
|
||||
respDataResult.setUserResponsibility(customerResPath);
|
||||
respDataResultService.save(respDataResult);
|
||||
}
|
||||
//防止过程中创建了大量的对象,主动调用下GC处理
|
||||
System.gc();
|
||||
result.setResponsibilityDataIndex(responsibilityData.getId());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public ResponsibilityResult getResponsibilityDataOld(ResponsibilitySecondCalParam responsibilitySecondCalParam) {
|
||||
ResponsibilityResult result = new ResponsibilityResult();
|
||||
//根据时间天数,获取理论上多少次用采数据
|
||||
RespData responsibilityData = this.baseMapper.selectById(responsibilitySecondCalParam.getResDataId());
|
||||
@@ -664,6 +931,258 @@ public class RespDataServiceImpl extends ServiceImpl<RespDataMapper, RespData> i
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponsibilityResult getResponsibilityData(ResponsibilitySecondCalParam responsibilitySecondCalParam) {
|
||||
ResponsibilityResult result = new ResponsibilityResult();
|
||||
//根据时间天数,获取理论上多少次用采数据
|
||||
RespData responsibilityData = this.baseMapper.selectById(responsibilitySecondCalParam.getResDataId());
|
||||
if (Objects.isNull(responsibilityData)) {
|
||||
throw new BusinessException(AdvanceResponseEnum.RESP_DATA_NOT_FOUND);
|
||||
}
|
||||
Overlimit overlimit = lineFeignClient.getOverLimitData(responsibilityData.getLineId()).getData();
|
||||
//获取总数据
|
||||
LambdaQueryWrapper<RespDataResult> respDataResultLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
respDataResultLambdaQueryWrapper.eq(RespDataResult::getResDataId, responsibilityData.getId())
|
||||
.eq(RespDataResult::getTime, responsibilitySecondCalParam.getTime());
|
||||
if (responsibilitySecondCalParam.getType() == 0) {
|
||||
respDataResultLambdaQueryWrapper.eq(RespDataResult::getLimitValue, PubUtils.getValueByMethod(overlimit, "getIharm", responsibilitySecondCalParam.getTime()));
|
||||
} else {
|
||||
respDataResultLambdaQueryWrapper.eq(RespDataResult::getLimitValue, PubUtils.getValueByMethod(overlimit, "getUharm", responsibilitySecondCalParam.getTime()));
|
||||
}
|
||||
RespDataResult respDataResultTemp = respDataResultService.getOne(respDataResultLambdaQueryWrapper);
|
||||
if (Objects.isNull(respDataResultTemp)) {
|
||||
throw new BusinessException(AdvanceResponseEnum.RESP_DATA_NOT_FOUND);
|
||||
}
|
||||
CacheQvvrData cacheQvvrData;
|
||||
try {
|
||||
InputStream fileStream = fileStorageUtil.getFileStream(respDataResultTemp.getQvvrData());
|
||||
String qvvrDataStr = IoUtil.readUtf8(fileStream);
|
||||
cacheQvvrData = PubUtils.json2obj(qvvrDataStr, CacheQvvrData.class);
|
||||
|
||||
} catch (Exception exception) {
|
||||
throw new BusinessException(AdvanceResponseEnum.RESP_RESULT_DATA_NOT_FOUND);
|
||||
}
|
||||
//获取成功后,延长该缓存的生命周期为初始生命时长
|
||||
int win = cacheQvvrData.getWin();
|
||||
//不管窗口为4或者96,都需要考虑最小公倍数
|
||||
//最小公倍数根据监测点测量间隔来获取,可以考虑也由第一步操作缓存起来
|
||||
int minMultiple = cacheQvvrData.getMinMultiple();
|
||||
//谐波横轴所有的时间
|
||||
List<Long> times = cacheQvvrData.getTimes();
|
||||
//首先根据窗口判断限值时间范围是否满足最小窗口
|
||||
Long limitSL = DateUtil.parse(responsibilitySecondCalParam.getLimitStartTime(), DatePattern.NORM_DATETIME_PATTERN).getTime();
|
||||
Long limitEL = DateUtil.parse(responsibilitySecondCalParam.getLimitEndTime(), DatePattern.NORM_DATETIME_PATTERN).getTime();
|
||||
List<Integer> temp = getTimes(times, limitSL, limitEL);
|
||||
//在动态责任数据中,时间的起始索引位置和截止索引位置
|
||||
Integer timeStartIndex = temp.get(0);
|
||||
Integer timeEndIndex = temp.get(1);
|
||||
//间隔中的时间长度
|
||||
int minus = timeEndIndex - timeStartIndex + 1;
|
||||
//组装参数
|
||||
QvvrDataEntity qvvrDataEntity = new QvvrDataEntity();
|
||||
qvvrDataEntity.calFlag = 1;
|
||||
qvvrDataEntity.pNode = cacheQvvrData.getPNode();
|
||||
qvvrDataEntity.harmMk = responsibilitySecondCalParam.getLimitValue();
|
||||
qvvrDataEntity.win = win;
|
||||
int resNum;
|
||||
float[][] FKdata = new float[9600][QvvrDataEntity.MAX_P_NODE];
|
||||
float[][] HKdata = new float[9600][QvvrDataEntity.MAX_P_NODE + 1];
|
||||
float[] harmData = new float[1440 * 100];
|
||||
float[][] fKdataOriginal = cacheQvvrData.getFKData();
|
||||
float[][] hKdataOriginal = cacheQvvrData.getHKData();
|
||||
float[] harmDataOriginal = cacheQvvrData.getHarmData();
|
||||
//如果起始索引与截止索引的差值等于时间轴的长度,则说明用户没有选择限值时间,直接带入全部的原始数据,参与计算即可
|
||||
if (minus == times.size()) {
|
||||
qvvrDataEntity.harmNum = cacheQvvrData.getHarmNum();
|
||||
qvvrDataEntity.resNum = cacheQvvrData.getHarmNum() - cacheQvvrData.getWin();
|
||||
qvvrDataEntity.setFKData(cacheQvvrData.getFKData());
|
||||
qvvrDataEntity.setHKData(cacheQvvrData.getHKData());
|
||||
qvvrDataEntity.harmData = cacheQvvrData.getHarmData();
|
||||
} else {
|
||||
if (win == WINDOW_4) {
|
||||
//当窗口为4时,两个时间限制范围在最小公倍数为15时,最起码有5个有效时间点,在最小公倍数为30时,最起码有3个有效时间点
|
||||
if (minMultiple == INTERVAL_TIME_15) {
|
||||
if (minus < MINUS_5) {
|
||||
throw new BusinessException(AdvanceResponseEnum.WIN_TIME_ERROR);
|
||||
}
|
||||
resNum = minus - MINUS_4;
|
||||
|
||||
} else if (minMultiple == INTERVAL_TIME_30) {
|
||||
if (minus < MINUS_3) {
|
||||
throw new BusinessException(AdvanceResponseEnum.WIN_TIME_ERROR);
|
||||
}
|
||||
resNum = minus - MINUS_2;
|
||||
} else {
|
||||
throw new BusinessException(AdvanceResponseEnum.CALCULATE_INTERVAL_ERROR);
|
||||
}
|
||||
} else if (win == WINDOW_96) {
|
||||
//当窗口为96时,两个时间限值范围在最小公倍数为15时,最起码有97个有效时间点,在最小公倍数为30时,最起码有49个有效时间点
|
||||
if (minMultiple == INTERVAL_TIME_15) {
|
||||
if (minus <= WINDOW_96) {
|
||||
throw new BusinessException(AdvanceResponseEnum.WIN_TIME_ERROR);
|
||||
}
|
||||
resNum = minus - WINDOW_96;
|
||||
} else if (minMultiple == INTERVAL_TIME_30) {
|
||||
if (minus <= WINDOW_48) {
|
||||
throw new BusinessException(AdvanceResponseEnum.WIN_TIME_ERROR);
|
||||
}
|
||||
resNum = minus - WINDOW_48;
|
||||
} else {
|
||||
throw new BusinessException(AdvanceResponseEnum.CALCULATE_INTERVAL_ERROR);
|
||||
}
|
||||
} else {
|
||||
throw new BusinessException(AdvanceResponseEnum.CALCULATE_INTERVAL_ERROR);
|
||||
}
|
||||
qvvrDataEntity.resNum = resNum;
|
||||
qvvrDataEntity.harmNum = minus;
|
||||
//因为限值时间实际是含头含尾的,所以harmNum需要索引差值+1
|
||||
for (int i = timeStartIndex; i <= timeEndIndex; i++) {
|
||||
harmData[i - timeStartIndex] = harmDataOriginal[i];
|
||||
}
|
||||
qvvrDataEntity.harmData = harmData;
|
||||
//FKData与HKData的值则等于resNum
|
||||
for (int i = timeStartIndex; i < timeStartIndex + resNum; i++) {
|
||||
FKdata[i - timeStartIndex] = fKdataOriginal[i];
|
||||
HKdata[i - timeStartIndex] = hKdataOriginal[i];
|
||||
}
|
||||
|
||||
qvvrDataEntity.setFKData(FKdata);
|
||||
qvvrDataEntity.setHKData(HKdata);
|
||||
}
|
||||
// ResponsibilityAlgorithm responsibilityAlgorithm = new ResponsibilityAlgorithm();
|
||||
// qvvrDataEntity = responsibilityAlgorithm.getResponsibilityResult(qvvrDataEntity);
|
||||
//
|
||||
// if (qvvrDataEntity.calOk == 0) {
|
||||
// throw new BusinessException(AdvanceResponseEnum.RESPONSIBILITY_PARAMETER_ERROR);
|
||||
// }
|
||||
HarmonicData harmonicData = harmonicResponsibilityService.partialCalculation(
|
||||
qvvrDataEntity.getHarmData(), qvvrDataEntity.getFKData(), qvvrDataEntity.getHKData(), qvvrDataEntity.getHarmNum(), qvvrDataEntity.getPNode(), qvvrDataEntity.getWin(), qvvrDataEntity.getResNum(), qvvrDataEntity.getHarmMk());
|
||||
if (harmonicData.getCalculationStatus() == CalculationStatus.FAILED) {
|
||||
throw new BusinessException(AdvanceResponseEnum.RESPONSIBILITY_PARAMETER_ERROR);
|
||||
}
|
||||
|
||||
//没问题后,先玩动态责任数据
|
||||
List<String> names = cacheQvvrData.getNames();
|
||||
CustomerData[] customerDatas = new CustomerData[harmonicData.getPowerNodeCount()];
|
||||
float[][] fKdata/*无背景的动态责任数据*/ = harmonicData.getFkData();
|
||||
//第一个时间节点是起始时间+win窗口得到的时间
|
||||
Date sTime = new Date();
|
||||
sTime.setTime(times.get(timeStartIndex));
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(sTime);
|
||||
calendar.add(Calendar.MINUTE, (win - 1) * minMultiple);
|
||||
List<Long> timeDatas = new ArrayList<>();
|
||||
for (int i = 0; i < harmonicData.getHarmonicCount() - harmonicData.getWindowSize(); i++) {
|
||||
calendar.add(Calendar.MINUTE, minMultiple);
|
||||
//一个时间点所有的用户数据
|
||||
float[] fKdatum = fKdata[i];
|
||||
for (int k = 0; k < harmonicData.getPowerNodeCount(); k++) {
|
||||
CustomerData customerData = customerDatas[k];
|
||||
if (null == customerData) {
|
||||
customerData = new CustomerData();
|
||||
customerData.setCustomerName(names.get(k));
|
||||
}
|
||||
List<Float> valueDatas = customerData.getValueDatas();
|
||||
Float valueTemp = fKdatum[k];
|
||||
if (valueTemp.isNaN()) {
|
||||
valueTemp = 0.0f;
|
||||
}
|
||||
valueDatas.add(valueTemp);
|
||||
customerData.setValueDatas(valueDatas);
|
||||
customerDatas[k] = customerData;
|
||||
}
|
||||
timeDatas.add(calendar.getTimeInMillis());
|
||||
}
|
||||
//OK拿到所有测量点的数据了,现在就是看如何将相同户号的动态数据进行算术和求值,之前的用户name为:户号@测量点号@用户名
|
||||
Map<String/*用户名(户号)*/, List<CustomerData>> customerDataTemp = new HashMap<>(32);
|
||||
for (CustomerData data : customerDatas) {
|
||||
String customerName = data.getCustomerName();
|
||||
String[] customerInfo = customerName.split("@");
|
||||
String name = customerInfo[2] + "(" + customerInfo[0] + ")";
|
||||
List<CustomerData> customerData = customerDataTemp.get(name);
|
||||
CustomerData customerTemp = data;
|
||||
customerTemp.setCustomerName(name);
|
||||
if (CollectionUtils.isEmpty(customerData)) {
|
||||
customerData = new ArrayList<>();
|
||||
}
|
||||
customerData.add(customerTemp);
|
||||
customerDataTemp.put(name, customerData);
|
||||
}
|
||||
//调用程序接口后,首先组装责任量化结果
|
||||
float[] sumFKdata = harmonicData.getSumFKData();
|
||||
List<CustomerResponsibility> customerResponsibilities = getCustomerResponsibilityData(names, sumFKdata, harmonicData.getPowerNodeCount());
|
||||
//根据前十的用户数据,获取这些用户的动态责任数据
|
||||
List<CustomerData> customerData = new ArrayList<>();
|
||||
|
||||
for (CustomerResponsibility customerResponsibility : customerResponsibilities) {
|
||||
String cusName = customerResponsibility.getCustomerName();
|
||||
List<CustomerData> customerData1 = customerDataTemp.get(cusName);
|
||||
if (CollectionUtils.isEmpty(customerData1)) {
|
||||
continue;
|
||||
}
|
||||
if (customerData1.size() == 1) {
|
||||
//表示用户唯一的
|
||||
customerData.add(customerData1.get(0));
|
||||
} else {
|
||||
// 表示用户可能包含多个监测点号,需要进行数据累加
|
||||
CustomerData customerDataT = new CustomerData();
|
||||
customerDataT.setCustomerName(cusName);
|
||||
//进行数值累加
|
||||
List<Float> valueDatas = new ArrayList<>();
|
||||
for (int i = 0; i < customerData1.get(0).getValueDatas().size(); i++) {
|
||||
float original = 0.0f;
|
||||
for (CustomerData data : customerData1) {
|
||||
original = original + data.getValueDatas().get(i);
|
||||
}
|
||||
valueDatas.add(original);
|
||||
}
|
||||
customerDataT.setValueDatas(valueDatas);
|
||||
customerData.add(customerDataT);
|
||||
}
|
||||
}
|
||||
//接着组装动态数据结果
|
||||
result.setResponsibilities(customerResponsibilities);
|
||||
result.setDatas(customerData);
|
||||
result.setTimeDatas(timeDatas);
|
||||
|
||||
//首先判断有没有存储记录,没有则存储,有就略过 指定测点、时间窗口、谐波类型、谐波次数判断唯一性
|
||||
LambdaQueryWrapper<RespDataResult> respDataResultLambdaQueryWrapper1 = new LambdaQueryWrapper<>();
|
||||
respDataResultLambdaQueryWrapper1.eq(RespDataResult::getResDataId, responsibilityData.getId())
|
||||
.eq(RespDataResult::getTime, responsibilitySecondCalParam.getTime())
|
||||
.eq(RespDataResult::getStartTime, DateUtil.parse(responsibilitySecondCalParam.getLimitStartTime(), DatePattern.NORM_DATETIME_PATTERN))
|
||||
.eq(RespDataResult::getEndTime, DateUtil.parse(responsibilitySecondCalParam.getLimitEndTime(), DatePattern.NORM_DATETIME_PATTERN))
|
||||
.eq(RespDataResult::getLimitValue, responsibilitySecondCalParam.getLimitValue());
|
||||
RespDataResult respDataResult = respDataResultService.getOne(respDataResultLambdaQueryWrapper1);
|
||||
if (Objects.isNull(respDataResult)) {
|
||||
respDataResult = new RespDataResult();
|
||||
respDataResult.setResDataId(responsibilityData.getId());
|
||||
respDataResult.setTime(responsibilitySecondCalParam.getTime());
|
||||
respDataResult.setStartTime(DateUtil.parse(responsibilitySecondCalParam.getLimitStartTime(), DatePattern.NORM_DATETIME_PATTERN));
|
||||
respDataResult.setEndTime(DateUtil.parse(responsibilitySecondCalParam.getLimitEndTime(), DatePattern.NORM_DATETIME_PATTERN));
|
||||
respDataResult.setLimitValue(responsibilitySecondCalParam.getLimitValue());
|
||||
//时间横轴数据 timeDatas
|
||||
JSONArray timeDataJson = JSONArray.parseArray(JSON.toJSONString(timeDatas));
|
||||
InputStream timeDataStream = IoUtil.toUtf8Stream(timeDataJson.toString());
|
||||
String timeDataPath = fileStorageUtil.uploadStream(timeDataStream, OssPath.RESPONSIBILITY_USER_RESULT_DATA, FileUtil.generateFileName("json"));
|
||||
respDataResult.setTimeData(timeDataPath);
|
||||
//用户每时刻对应的责任数据
|
||||
JSONArray customerDataJson = JSONArray.parseArray(JSON.toJSONString(customerData));
|
||||
InputStream customerStream = IoUtil.toUtf8Stream(customerDataJson.toString());
|
||||
String customerPath = fileStorageUtil.uploadStream(customerStream, OssPath.RESPONSIBILITY_USER_RESULT_DATA, FileUtil.generateFileName("json"));
|
||||
respDataResult.setUserDetailData(customerPath);
|
||||
//用户前10数据存储
|
||||
JSONArray customerResJson = JSONArray.parseArray(JSON.toJSONString(customerResponsibilities));
|
||||
InputStream customerResStream = IoUtil.toUtf8Stream(customerResJson.toString());
|
||||
String customerResPath = fileStorageUtil.uploadStream(customerResStream, OssPath.RESPONSIBILITY_USER_RESULT_DATA, FileUtil.generateFileName("json"));
|
||||
respDataResult.setUserResponsibility(customerResPath);
|
||||
respDataResultService.save(respDataResult);
|
||||
}
|
||||
//防止过程中创建了大量的对象,主动调用下GC处理
|
||||
System.gc();
|
||||
result.setResponsibilityDataIndex(responsibilityData.getId());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 监测点测量间隔获取最后用于计算的功率数据
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -57,6 +57,11 @@
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<!--vastbase驱动用postgresql-->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
<!--达梦驱动-->
|
||||
<dependency>
|
||||
<groupId>com.dameng</groupId>
|
||||
|
||||
@@ -432,7 +432,7 @@ public class WaveFileComponent {
|
||||
rateDTO.setNOneSample(result);
|
||||
// 总点数 //这里的strTemp是一个偏移量
|
||||
rateDTO.setNSampleNum((Integer.parseInt(strTempArray[1]) - nOffset));
|
||||
nOffset = rateDTO.getNSampleNum();
|
||||
nOffset += rateDTO.getNSampleNum();
|
||||
lstRate.add(rateDTO);
|
||||
}
|
||||
comtradeCfgDTO.setLstRate(lstRate);
|
||||
@@ -497,7 +497,7 @@ public class WaveFileComponent {
|
||||
int nDigSize = (comtradeCfgDTO.getNDigitalNum() % 16) > 0 ? (comtradeCfgDTO.getNDigitalNum() / 16 + 1) * 2 : comtradeCfgDTO.getNDigitalNum() / 16 * 2;
|
||||
int nBlockSize = 2 * Integer.SIZE / 8 + comtradeCfgDTO.getNAnalogNum() * 2 + nDigSize;
|
||||
// 总长度除以每个块的大小
|
||||
int nBlockNum = datArray.length / nBlockSize;
|
||||
int nBlockNum = (int)Math.floor(datArray.length / nBlockSize);
|
||||
|
||||
// 获取采样率
|
||||
int finalSampleRate = getFinalWaveSample(comtradeCfgDTO.getLstRate(), iType);
|
||||
@@ -612,6 +612,9 @@ public class WaveFileComponent {
|
||||
}
|
||||
float fCoef = comtradeCfgDTO.getLstAnalogDTO().get(j).getFCoefficent();
|
||||
|
||||
if((i * nBlockSize + 2 * 4 + j * 2) == 2437568){
|
||||
System.out.println(55);
|
||||
}
|
||||
fValue = BitConverter.byte2ToUnsignedShort(datArray, i * nBlockSize + 2 * 4 + j * 2) * fCoef;
|
||||
//WW 2019-11-14
|
||||
/*************************
|
||||
@@ -767,6 +770,7 @@ public class WaveFileComponent {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new BusinessException(WaveFileResponseEnum.DAT_DATA_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,52 @@ public interface BusinessTopic {
|
||||
|
||||
String NJCN_APP_FILE_STREAM_TOPIC = "njcnAppFileStreamTopic";
|
||||
|
||||
/**
|
||||
* 云前置主题
|
||||
*/
|
||||
String CLD_ASK_REAL_DATA_TOPIC = "ask_real_data_Topic";
|
||||
|
||||
String CLD_HANDLE_REAL_DATA_TOPIC = "Real_Time_Data_Topic";
|
||||
|
||||
/**
|
||||
* 云前置心跳主题
|
||||
*/
|
||||
String HEART_BEAT_TOPIC = "Heart_Beat_Topic";
|
||||
|
||||
/**
|
||||
* 云前置状态反转主题
|
||||
*/
|
||||
String DEVICE_RUN_FLAG_TOPIC = "Device_Run_Flag_Topic";
|
||||
|
||||
/**
|
||||
* 云前置日志主题
|
||||
*/
|
||||
String LOG_TOPIC = "log_Topic";
|
||||
|
||||
/**
|
||||
* 台账更新下发
|
||||
*/
|
||||
String CONTROL_TOPIC = "control_Topic";
|
||||
|
||||
/**
|
||||
* 台账更新前置端响应
|
||||
*/
|
||||
String REPLY_TOPIC = "Reply_Topic";
|
||||
|
||||
/**
|
||||
* 前置进程控制
|
||||
*/
|
||||
String PROCESS_TOPIC = "process_Topic";
|
||||
|
||||
/**
|
||||
* 补召下发命令
|
||||
*/
|
||||
String ASK_RECALL_TOPIC = "ask_recall_Topic";
|
||||
|
||||
/**
|
||||
* 补召应答命令
|
||||
*/
|
||||
String REPLY_RECALL_TOPIC = "reply_recall_Topic";
|
||||
|
||||
/********************************数据中心*********************************/
|
||||
|
||||
@@ -79,5 +124,4 @@ public interface BusinessTopic {
|
||||
String STREAM_TAG = "streamInfo";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -28,14 +28,14 @@ public class AppFileMessage extends BaseMessage {
|
||||
|
||||
private Integer code;
|
||||
|
||||
private AppFileMessage.Msg msg;
|
||||
private Msg msg;
|
||||
|
||||
@Data
|
||||
public static class Msg{
|
||||
|
||||
private String type;
|
||||
|
||||
private AppFileMessage.FileInfo fileInfo;
|
||||
private FileInfo fileInfo;
|
||||
|
||||
private String data;
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.njcn.mq.message;
|
||||
|
||||
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class BZEventMessage extends BaseMessage {
|
||||
|
||||
//补召事件
|
||||
@Data
|
||||
public static class Event{
|
||||
|
||||
@ApiModelProperty("请求的guid")
|
||||
private String guid;
|
||||
|
||||
@ApiModelProperty("终端id")
|
||||
private String terminalId;
|
||||
|
||||
@ApiModelProperty("监测点id")
|
||||
private List<String> monitorIdList;
|
||||
|
||||
@ApiModelProperty("数据类型 0 稳态 1 暂态事件 2 暂态波形")
|
||||
private Integer dataType;
|
||||
|
||||
@ApiModelProperty("时间范围")
|
||||
private List<String> timeInterval;
|
||||
|
||||
}
|
||||
|
||||
//补召波形
|
||||
@Data
|
||||
public static class File{
|
||||
|
||||
@ApiModelProperty("请求的guid")
|
||||
private String guid;
|
||||
|
||||
@ApiModelProperty("终端id")
|
||||
private String terminalId;
|
||||
|
||||
@ApiModelProperty("监测点id")
|
||||
private String monitorId;
|
||||
|
||||
@ApiModelProperty("数据类型 0 稳态 1 暂态事件 2 暂态波形")
|
||||
private Integer dataType;
|
||||
|
||||
@ApiModelProperty("缺失波形时标集合")
|
||||
private List<String> timeList;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.njcn.mq.message;
|
||||
|
||||
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2025/9/29 15:06
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class BzMessage extends BaseMessage {
|
||||
|
||||
@ApiModelProperty("唯一标识")
|
||||
private String guid;
|
||||
|
||||
@ApiModelProperty("补召类型")
|
||||
private String dataType;
|
||||
|
||||
@ApiModelProperty("响应码")
|
||||
private Integer code;
|
||||
|
||||
@ApiModelProperty("结果")
|
||||
private String result;
|
||||
|
||||
@ApiModelProperty("设备id")
|
||||
private String terminalId;
|
||||
|
||||
@ApiModelProperty("监测点id")
|
||||
private String monitorId;
|
||||
|
||||
@ApiModelProperty("补召起始时间")
|
||||
private String recallStartDate;
|
||||
|
||||
@ApiModelProperty("补召结束时间")
|
||||
private String recallEndDate;
|
||||
|
||||
@ApiModelProperty("前置服务器id")
|
||||
private String nodeId;
|
||||
|
||||
@ApiModelProperty("前置进程")
|
||||
private String processNo;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.njcn.mq.message;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 类的介绍:日志信息
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2025/9/18 15:06
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CldControlMessage {
|
||||
|
||||
@ApiModelProperty("请求的guid")
|
||||
private String guid;
|
||||
|
||||
@ApiModelProperty("功能代号")
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty("前置服务器id")
|
||||
private String nodeId;
|
||||
|
||||
@ApiModelProperty("指定处理的进程号")
|
||||
private Integer processNo;
|
||||
|
||||
@ApiModelProperty("delete用于杀死进程")
|
||||
private String fun;
|
||||
|
||||
@ApiModelProperty("进程数")
|
||||
private Integer processNum;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.njcn.mq.message;
|
||||
|
||||
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/8/11 15:06
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CldDeviceRunFlagMessage extends BaseMessage {
|
||||
|
||||
@ApiModelProperty("设备id")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty("前置类型")
|
||||
private String date;
|
||||
|
||||
@ApiModelProperty("状态 0:中断 1:连接")
|
||||
private String status;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.njcn.mq.message;
|
||||
|
||||
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/8/11 15:06
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CldHeartBeatMessage extends BaseMessage {
|
||||
|
||||
@ApiModelProperty("前置类型")
|
||||
private String frontType;
|
||||
|
||||
@ApiModelProperty("前置id")
|
||||
private String nodeId;
|
||||
|
||||
@ApiModelProperty("进程id")
|
||||
private Integer processNo;
|
||||
|
||||
@ApiModelProperty("状态")
|
||||
private String status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.njcn.mq.message;
|
||||
|
||||
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 类的介绍:日志信息
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2025/9/18 15:06
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CldLogMessage extends BaseMessage {
|
||||
|
||||
@ApiModelProperty("前置id")
|
||||
private String nodeId;
|
||||
|
||||
@ApiModelProperty("进程id")
|
||||
private String processNo;
|
||||
|
||||
@ApiModelProperty("监测点id、装置id")
|
||||
private String businessId;
|
||||
|
||||
@ApiModelProperty("级别(process进程、terminal装置、measurepoint监测点)")
|
||||
private String level;
|
||||
|
||||
@ApiModelProperty("日志等级")
|
||||
private String grade;
|
||||
|
||||
@ApiModelProperty("告警码")
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty("告警时间")
|
||||
private String time;
|
||||
|
||||
@ApiModelProperty("日志信息")
|
||||
private String log;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.njcn.mq.message;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* cld设备更新台账实体
|
||||
* @author xy
|
||||
*/
|
||||
@Data
|
||||
public class CldUpdateLedgerMessage implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("消息唯一标识")
|
||||
private String guid;
|
||||
|
||||
@ApiModelProperty("add_terminal/delete_terminal/ledger_modify")
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty("进程号")
|
||||
private Integer processNo;
|
||||
|
||||
@ApiModelProperty("数据")
|
||||
private List<CldDeviceDto> data;
|
||||
|
||||
@Data
|
||||
public static class CldDeviceDto implements Serializable {
|
||||
|
||||
@ApiModelProperty("最大进程数")
|
||||
private Integer maxProcessNum;
|
||||
|
||||
@ApiModelProperty("进程号")
|
||||
private Integer node;
|
||||
|
||||
@ApiModelProperty("设备id")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty("设备MAC")
|
||||
private String ip;
|
||||
|
||||
@ApiModelProperty("设备型号")
|
||||
private String devType;
|
||||
|
||||
@ApiModelProperty("设备名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("监测点信息集合")
|
||||
private List<CldMonitorDto> monitorData;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class CldMonitorDto implements Serializable {
|
||||
|
||||
@ApiModelProperty("监测点id")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty("监测点名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("监测点线路号")
|
||||
private String lineNo;
|
||||
|
||||
@ApiModelProperty("电压等级")
|
||||
private String voltageLevel;
|
||||
|
||||
@ApiModelProperty("status")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty("接线方式")
|
||||
private String ptType;
|
||||
|
||||
@ApiModelProperty("设备id")
|
||||
private String deviceId;
|
||||
|
||||
@ApiModelProperty("pt一次变比")
|
||||
private Double pt1;
|
||||
|
||||
@ApiModelProperty("pt二次变比")
|
||||
private Double pt2;
|
||||
|
||||
@ApiModelProperty("ct一次变比")
|
||||
private Double ct1;
|
||||
|
||||
@ApiModelProperty("ct二次变比")
|
||||
private Double ct2;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.njcn.mq.message;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/8/11 15:06
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class RealDataMessage {
|
||||
|
||||
@ApiModelProperty("终端序号")
|
||||
private String devSeries;
|
||||
|
||||
@ApiModelProperty("监测点序号")
|
||||
private Integer line;
|
||||
|
||||
@ApiModelProperty("实时数据开启/关闭")
|
||||
private Boolean realData;
|
||||
|
||||
@ApiModelProperty("Soe开启/关闭")
|
||||
private Boolean soeData;
|
||||
|
||||
@ApiModelProperty("限制")
|
||||
private Integer limit;
|
||||
|
||||
@ApiModelProperty("限制")
|
||||
private Integer count;
|
||||
|
||||
@ApiModelProperty("idx")
|
||||
private Integer idx;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.njcn.mq.message;
|
||||
|
||||
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2025/9/29 15:06
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UpdateLedgerMessage extends BaseMessage {
|
||||
|
||||
@ApiModelProperty("唯一标识")
|
||||
private String guid;
|
||||
|
||||
@ApiModelProperty("数据")
|
||||
private List<HandleData> data;
|
||||
|
||||
@Data
|
||||
public static class HandleData implements Serializable {
|
||||
|
||||
@ApiModelProperty("设备id")
|
||||
private String deviceId;
|
||||
|
||||
@ApiModelProperty("响应码")
|
||||
private Integer code;
|
||||
|
||||
@ApiModelProperty("结果描述")
|
||||
private String result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.njcn.mq.template;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||
import com.njcn.middle.rocket.template.RocketMQEnhanceTemplate;
|
||||
import com.njcn.mq.constant.BusinessResource;
|
||||
import com.njcn.mq.constant.BusinessTopic;
|
||||
import org.apache.rocketmq.client.producer.SendResult;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 类的介绍:补召事件
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
*/
|
||||
@Component
|
||||
public class BZEventMessageTemplate extends RocketMQEnhanceTemplate {
|
||||
|
||||
public BZEventMessageTemplate(RocketMQTemplate template) {
|
||||
super(template);
|
||||
}
|
||||
|
||||
public SendResult sendMember(Object message, String tag) {
|
||||
BaseMessage baseMessage = new BaseMessage();
|
||||
baseMessage.setSource(BusinessResource.WEB_RESOURCE);
|
||||
baseMessage.setMessageBody(new Gson().toJson(message));
|
||||
return send(BusinessTopic.ASK_RECALL_TOPIC,tag,baseMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.njcn.mq.template;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||
import com.njcn.middle.rocket.template.RocketMQEnhanceTemplate;
|
||||
import com.njcn.mq.constant.BusinessResource;
|
||||
import com.njcn.mq.constant.BusinessTopic;
|
||||
import com.njcn.mq.message.CldControlMessage;
|
||||
import org.apache.rocketmq.client.producer.SendResult;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 类的介绍:实时数据模板
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/8/11 15:28
|
||||
*/
|
||||
@Component
|
||||
public class CldControlMessageTemplate extends RocketMQEnhanceTemplate {
|
||||
|
||||
public CldControlMessageTemplate(RocketMQTemplate template) {
|
||||
super(template);
|
||||
}
|
||||
|
||||
public SendResult sendMember(CldControlMessage message, String tag) {
|
||||
BaseMessage baseMessage = new BaseMessage();
|
||||
baseMessage.setSource(BusinessResource.WEB_RESOURCE);
|
||||
baseMessage.setMessageBody(new Gson().toJson(message));
|
||||
return send(BusinessTopic.PROCESS_TOPIC,tag,baseMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.njcn.mq.template;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||
import com.njcn.middle.rocket.template.RocketMQEnhanceTemplate;
|
||||
import com.njcn.mq.constant.BusinessResource;
|
||||
import com.njcn.mq.constant.BusinessTopic;
|
||||
import com.njcn.mq.message.CldUpdateLedgerMessage;
|
||||
import org.apache.rocketmq.client.producer.SendResult;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 类的介绍:实时数据模板
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/8/11 15:28
|
||||
*/
|
||||
@Component
|
||||
public class CldUpdateLedgerMessageTemplate extends RocketMQEnhanceTemplate {
|
||||
|
||||
public CldUpdateLedgerMessageTemplate(RocketMQTemplate template) {
|
||||
super(template);
|
||||
}
|
||||
|
||||
public SendResult sendMember(CldUpdateLedgerMessage cldUpdateLedgerMessage, String tag) {
|
||||
BaseMessage baseMessage = new BaseMessage();
|
||||
baseMessage.setSource(BusinessResource.WEB_RESOURCE);
|
||||
baseMessage.setMessageBody(new Gson().toJson(cldUpdateLedgerMessage));
|
||||
return send(BusinessTopic.CONTROL_TOPIC,tag,baseMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.njcn.mq.template;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||
import com.njcn.middle.rocket.template.RocketMQEnhanceTemplate;
|
||||
import com.njcn.mq.constant.BusinessResource;
|
||||
import com.njcn.mq.constant.BusinessTopic;
|
||||
import com.njcn.mq.message.RealDataMessage;
|
||||
import org.apache.rocketmq.client.producer.SendResult;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 类的介绍:实时数据模板
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/8/11 15:28
|
||||
*/
|
||||
@Component
|
||||
public class RealDataMessageTemplate extends RocketMQEnhanceTemplate {
|
||||
|
||||
public RealDataMessageTemplate(RocketMQTemplate template) {
|
||||
super(template);
|
||||
}
|
||||
|
||||
public SendResult sendMember(RealDataMessage realDataMessage,String tag) {
|
||||
BaseMessage baseMessage = new BaseMessage();
|
||||
baseMessage.setSource(BusinessResource.WEB_RESOURCE);
|
||||
baseMessage.setMessageBody(new Gson().toJson(realDataMessage));
|
||||
return send(BusinessTopic.CLD_ASK_REAL_DATA_TOPIC,tag,baseMessage);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.njcn.oss.utils;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.njcn.common.config.GeneralInfo;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.huawei.obs.util.OBSUtil;
|
||||
@@ -88,16 +89,23 @@ public class FileStorageUtil {
|
||||
}
|
||||
}else {
|
||||
try {
|
||||
// 确保目录存在
|
||||
Path uploadPath = Paths.get(generalInfo.getLocalStorePath());
|
||||
// 构建完整目录:基准目录 + dir子目录
|
||||
Path basePath = Paths.get(generalInfo.getLocalStorePath());
|
||||
Path uploadPath = basePath.resolve(dir); // 将dir作为子目录添加
|
||||
|
||||
// 确保完整目录存在(包括dir子目录)
|
||||
if (!Files.exists(uploadPath)) {
|
||||
Files.createDirectories(uploadPath);
|
||||
}
|
||||
|
||||
// 生成本地文件名(可以添加时间戳或UUID防止重名)
|
||||
// 生成本地文件名(处理扩展名,防止异常)
|
||||
String originalFilename = multipartFile.getOriginalFilename();
|
||||
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
String newFilename = UUID.randomUUID().toString() + fileExtension;
|
||||
String fileExtension = "";
|
||||
int extIndex = originalFilename.lastIndexOf(".");
|
||||
if (extIndex > 0 && extIndex < originalFilename.length() - 1) {
|
||||
fileExtension = originalFilename.substring(extIndex);
|
||||
}
|
||||
String newFilename = IdUtil.simpleUUID().toUpperCase() + fileExtension;
|
||||
|
||||
// 构建完整路径
|
||||
Path filePathPath = uploadPath.resolve(newFilename);
|
||||
@@ -105,7 +113,7 @@ public class FileStorageUtil {
|
||||
// 保存文件
|
||||
multipartFile.transferTo(filePathPath.toFile());
|
||||
|
||||
// 返回相对路径或完整路径,根据需求调整
|
||||
// 返回相对路径或完整路径
|
||||
filePath = dir + File.separator + newFilename;
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException("本地文件上传失败: " + e.getMessage());
|
||||
@@ -271,7 +279,6 @@ public class FileStorageUtil {
|
||||
}else {
|
||||
// 本地存储处理
|
||||
Path path = Paths.get(generalInfo.getLocalStorePath()+File.separator+filePath);
|
||||
System.out.println("下载文件路径:"+generalInfo.getLocalStorePath()+File.separator+filePath);
|
||||
inputStream = Files.newInputStream(path);
|
||||
|
||||
// 设置下载文件名(从路径中提取)
|
||||
@@ -324,8 +331,15 @@ public class FileStorageUtil {
|
||||
public void deleteFile(String fileName) {
|
||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||
obsUtil.delete(fileName);
|
||||
} else {
|
||||
} else if(generalInfo.getBusinessFileStorage() == GeneralConstant.MINIO_OSS){
|
||||
minIoUtils.removeObject(minIossProperties.getBucket(), fileName);
|
||||
} else if(generalInfo.getBusinessFileStorage() == GeneralConstant.LOCAL_DISK){
|
||||
Path path = Paths.get(generalInfo.getLocalStorePath()+File.separator+fileName);
|
||||
try {
|
||||
Files.delete(path);
|
||||
} catch (IOException e) {
|
||||
log.info("删除本地文件{}失败失败原因{}", path,e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,12 @@ public enum RedisKeyEnum {
|
||||
/***
|
||||
* 存放用户的角色关系
|
||||
*/
|
||||
USER_ROLE_TYPE_KEY("USER_ROLE_TYPE_KEY", -1L);
|
||||
USER_ROLE_TYPE_KEY("USER_ROLE_TYPE_KEY", -1L),
|
||||
|
||||
/**
|
||||
* 云前置心跳
|
||||
*/
|
||||
CLD_HEART_BEAT_KEY("CLD_HEART_BEAT:", 180L);
|
||||
|
||||
|
||||
private final String key;
|
||||
|
||||
@@ -81,7 +81,9 @@ public class Knife4jSwaggerConfig {
|
||||
"com.njcn.supervision.controller",
|
||||
"com.njcn.algorithm",
|
||||
"com.njcn.dataProcess",
|
||||
"com.njcn.migration"
|
||||
"com.njcn.migration",
|
||||
"com.njcn.harmonic.rstatlimitrate.controller",
|
||||
"com.njcn.device.device.controller"
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
List<GrantType> grantTypes = new ArrayList<>();
|
||||
|
||||
@@ -32,6 +32,7 @@ public enum DeviceResponseEnum {
|
||||
|
||||
DEVICE_SAME_NAME("A0290","设备名称已存在"),
|
||||
DEVICE_REPETITION("A0291","设备名称重复"),
|
||||
MODEL_NAME_REPEAT("A00350","名称不可重复"),
|
||||
DEVICE_IP_REPETITION("A0292","设备ip端口号重复"),
|
||||
DEVICE_SAME_IP("A0293","当前设备ip端口号已存在"),
|
||||
DEVICE_EMPTY("A0294","设备为空"),
|
||||
|
||||
@@ -74,7 +74,10 @@ public class PollutionLineInfoDTO {
|
||||
* 电压等级
|
||||
*/
|
||||
private String lineVoltage;
|
||||
|
||||
/**
|
||||
* 变电站电压等级
|
||||
*/
|
||||
private String subVoltage;
|
||||
/**
|
||||
* 装置id
|
||||
*/
|
||||
@@ -85,4 +88,13 @@ public class PollutionLineInfoDTO {
|
||||
*/
|
||||
private String monitorId;
|
||||
|
||||
/**
|
||||
* 监测点统计间隔(解决MySQL关键字问题)
|
||||
*/
|
||||
private Integer timeInterval;
|
||||
|
||||
/**
|
||||
* 监测点名称
|
||||
*/
|
||||
private String lineName;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<modules>
|
||||
<module>pq-device-api</module>
|
||||
<module>pq-device-boot</module>
|
||||
<module>pq-device-com</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -3,9 +3,9 @@ package com.njcn.device.pq.api.fallback;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.device.biz.utils.DeviceEnumUtil;
|
||||
import com.njcn.device.pq.api.AlarmClient;
|
||||
import com.njcn.device.pq.pojo.vo.AlarmStrategyVO;
|
||||
import com.njcn.device.biz.utils.DeviceEnumUtil;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -14,11 +14,12 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 告警管理熔断降级
|
||||
*
|
||||
* @author yzh
|
||||
* @date 2022/9/19
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@Component("deviceAlarmClientFallbackFactory")
|
||||
public class AlarmClientFallbackFactory implements FallbackFactory<AlarmClient> {
|
||||
@Override
|
||||
public AlarmClient create(Throwable throwable) {
|
||||
|
||||
@@ -55,7 +55,11 @@ public interface Param {
|
||||
//长时间闪变值
|
||||
String pst = "DataFlicker-pst";
|
||||
|
||||
//电压暂降
|
||||
String Voltage_Dip = "r_mp_event_detail-Voltage_Dip";
|
||||
//电压暂升
|
||||
String Voltage_Rise = "r_mp_event_detail-Voltage_Rise";
|
||||
|
||||
String pf = "DataHarmPowerP-pf";
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.njcn.device.pq.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* pqs
|
||||
*
|
||||
* @author cdf
|
||||
* @date 2022/1/4
|
||||
*/
|
||||
@Getter
|
||||
public enum JbPowerFlagEnum {
|
||||
|
||||
/**
|
||||
* 系统拓扑各层级描述
|
||||
*/
|
||||
GRID_SIDE(0, "电网侧"),
|
||||
NO_GRID_SIDE(1, "非电网侧"),
|
||||
SEND_NETWORK(2, "上送国网"),
|
||||
NOT_NETWORK(3, "非上送国网"),
|
||||
unknown(4, "未知"),
|
||||
;
|
||||
|
||||
private final Integer code;
|
||||
private final String message;
|
||||
|
||||
JbPowerFlagEnum(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public static JbPowerFlagEnum getPowerFlagEnumByCode(Integer code) {
|
||||
return Arrays.stream(JbPowerFlagEnum.values())
|
||||
.filter(x -> x.getCode().equals(code))
|
||||
.findAny()
|
||||
.orElse(unknown);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -124,11 +124,11 @@ public class LineParam {
|
||||
private String objId;
|
||||
|
||||
@ApiModelProperty(name = "bigObjType",value = "对象大类")
|
||||
@NotBlank(message = "对象大类不可为空")
|
||||
// @NotBlank(message = "对象大类不可为空")
|
||||
private String bigObjType;
|
||||
|
||||
@ApiModelProperty(name = "smallObjType",value = "对象小类")
|
||||
@NotBlank(message = "对象小类不可为空")
|
||||
// @NotBlank(message = "对象小类不可为空")
|
||||
private String smallObjType;
|
||||
|
||||
/**
|
||||
|
||||
@@ -137,6 +137,16 @@ public class PqDataVerifyBak {
|
||||
*/
|
||||
private Integer pst;
|
||||
|
||||
/**
|
||||
* 电压暂降(0:正常 1:异常)
|
||||
*/
|
||||
private Integer dip;
|
||||
|
||||
/**
|
||||
* 电压暂升(0:正常 1:异常)
|
||||
*/
|
||||
private Integer rise;
|
||||
|
||||
/**
|
||||
* 判断所有指标 0:无异常 1:有异常
|
||||
*/
|
||||
|
||||
@@ -27,6 +27,9 @@ public class DevDetail {
|
||||
@ApiModelProperty("供电公司")
|
||||
private String gdName;
|
||||
|
||||
@ApiModelProperty("所属部门")
|
||||
private String deptName;
|
||||
|
||||
@ApiModelProperty("变电站名称")
|
||||
private String bdzName;
|
||||
|
||||
@@ -37,9 +40,15 @@ public class DevDetail {
|
||||
@ApiModelProperty("终端等级")
|
||||
private String lineGrade;
|
||||
|
||||
@ApiModelProperty("终端厂商")
|
||||
private String manufacturer;
|
||||
|
||||
@ApiModelProperty("通讯状态(0:中断;1:正常)")
|
||||
private Integer comFlag;
|
||||
|
||||
@ApiModelProperty("运行状态(0:运行;1:检修;2:停运;3:调试;4:退运)")
|
||||
private Integer runFlag;
|
||||
|
||||
@ApiModelProperty("定检时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDate nextTimeCheck;
|
||||
|
||||
@@ -11,6 +11,15 @@ import lombok.Data;
|
||||
@Data
|
||||
public class DevDetailVO {
|
||||
|
||||
@ApiModelProperty("地市")
|
||||
private String cit;
|
||||
|
||||
@ApiModelProperty("供电公司")
|
||||
private String company;
|
||||
|
||||
@ApiModelProperty("终端厂家")
|
||||
private String manufacturer;
|
||||
|
||||
@ApiModelProperty(name = "lineId",value = "监测点索引")
|
||||
private String lineId;
|
||||
|
||||
@@ -32,4 +41,6 @@ public class DevDetailVO {
|
||||
@ApiModelProperty(name = "subName",value = "对象id(新能源用户)")
|
||||
private String ObjId;
|
||||
|
||||
@ApiModelProperty("终端运行状态(0:运行;1:检修;2:停运;3:调试;4:退运)")
|
||||
private Integer runFlag;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ import java.util.List;
|
||||
@Data
|
||||
public class DeviceRunEvaluateVO {
|
||||
|
||||
@ApiModelProperty("终端id")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty("名称")
|
||||
private String name;
|
||||
|
||||
@@ -26,6 +29,18 @@ public class DeviceRunEvaluateVO {
|
||||
@ApiModelProperty("评价")
|
||||
private BigDecimal evaluate;
|
||||
|
||||
@ApiModelProperty("地市")
|
||||
private String cit;
|
||||
|
||||
@ApiModelProperty("供电公司")
|
||||
private String company;
|
||||
|
||||
@ApiModelProperty("终端厂家")
|
||||
private String manufacturer;
|
||||
|
||||
@ApiModelProperty("终端运行状态(0:运行;1:检修;2:停运;3:调试;4:退运)")
|
||||
private String runFlag;
|
||||
|
||||
@ApiModelProperty("完整率")
|
||||
private BigDecimal integrityRate;
|
||||
|
||||
@@ -40,4 +55,29 @@ public class DeviceRunEvaluateVO {
|
||||
@ApiModelProperty("终端id集合")
|
||||
private List<String> devIds;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
|
||||
@ApiModelProperty("名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("评价")
|
||||
private BigDecimal score;
|
||||
|
||||
@ApiModelProperty("终端数量")
|
||||
private Integer count;
|
||||
|
||||
@ApiModelProperty("在线率")
|
||||
private BigDecimal online;
|
||||
|
||||
@ApiModelProperty("数据完整性")
|
||||
private BigDecimal integrity;
|
||||
|
||||
@ApiModelProperty("异常率")
|
||||
private BigDecimal qualified;
|
||||
|
||||
@ApiModelProperty("终端信息")
|
||||
List<DeviceRunEvaluateVO> list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ import java.time.LocalDateTime;
|
||||
@Data
|
||||
public class LineDetailVO implements Serializable {
|
||||
|
||||
@ApiModelProperty("部门名称")
|
||||
private String deptName;
|
||||
|
||||
@ApiModelProperty("供电公司名称")
|
||||
private String gdName;
|
||||
|
||||
@@ -92,6 +95,16 @@ public class LineDetailVO implements Serializable {
|
||||
|
||||
@ApiModelProperty("已用流量占比")
|
||||
private Float flowProportion;
|
||||
|
||||
@ApiModelProperty("电网标志 0-电网侧;1-非电网侧")
|
||||
private Integer powerFlag;
|
||||
|
||||
@ApiModelProperty(name = "监测点运行状态")
|
||||
private String lineRunType;
|
||||
|
||||
@ApiModelProperty(name = "终端厂家")
|
||||
private String manufacturer;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.njcn.device.pq.pojo.vo;
|
||||
|
||||
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.njcn.device.pq.pojo.vo.common;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description
|
||||
* @date 2025/11/26 11:00
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class DeviceOnlineRate {
|
||||
|
||||
@ApiModelProperty("总终端数量")
|
||||
private Integer totalNum;
|
||||
|
||||
@ApiModelProperty("低于90终端数据")
|
||||
private Integer belowNum;
|
||||
|
||||
@ApiModelProperty("总终端在线率")
|
||||
private String totalOnlineRate;
|
||||
|
||||
@ApiModelProperty("统计信息")
|
||||
List<CitDetail> citDetailList;
|
||||
|
||||
@Data
|
||||
public static class CitDetail {
|
||||
|
||||
@ApiModelProperty("地市")
|
||||
private String citName;
|
||||
|
||||
@ApiModelProperty("总终端数量")
|
||||
private Integer citTotalNum;
|
||||
|
||||
@ApiModelProperty("低于90终端数据")
|
||||
private Integer citBelowNum;
|
||||
|
||||
@ApiModelProperty("总终端在线率")
|
||||
private String citTotalOnlineRate;
|
||||
|
||||
@ApiModelProperty("统计信息")
|
||||
List<?> detailList;
|
||||
}
|
||||
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
|
||||
@ApiModelProperty("地市")
|
||||
private String cit;
|
||||
|
||||
@ApiModelProperty("供电公司")
|
||||
private String company;
|
||||
|
||||
@ApiModelProperty("变电站")
|
||||
private String subStation;
|
||||
|
||||
@ApiModelProperty("终端ID")
|
||||
private String deviceId;
|
||||
|
||||
@ApiModelProperty("终端名称")
|
||||
private String deviceName;
|
||||
|
||||
@ApiModelProperty("终端厂家")
|
||||
private String manufacturer;
|
||||
|
||||
@ApiModelProperty("终端IP")
|
||||
private String ip;
|
||||
|
||||
@ApiModelProperty("终端运行状态(0:运行;1:检修;2:停运;3:调试;4:退运)")
|
||||
private String runFlag;
|
||||
|
||||
@ApiModelProperty("终端通讯状态(0:中断;1:正常)")
|
||||
private String comFlag;
|
||||
|
||||
@ApiModelProperty("最新数据时间")
|
||||
private LocalDateTime timeID;
|
||||
|
||||
@ApiModelProperty("在线率")
|
||||
private String onlineRate;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class LineDetail {
|
||||
|
||||
@ApiModelProperty("地市")
|
||||
private String cit;
|
||||
|
||||
@ApiModelProperty("供电公司")
|
||||
private String company;
|
||||
|
||||
@ApiModelProperty("变电站")
|
||||
private String subStation;
|
||||
|
||||
@ApiModelProperty("终端ID")
|
||||
private String deviceId;
|
||||
|
||||
@ApiModelProperty("终端名称")
|
||||
private String deviceName;
|
||||
|
||||
@ApiModelProperty("终端厂家")
|
||||
private String manufacturer;
|
||||
|
||||
@ApiModelProperty("终端IP")
|
||||
private String ip;
|
||||
|
||||
@ApiModelProperty("监测点id")
|
||||
private String lineId;
|
||||
|
||||
@ApiModelProperty("监测点名称")
|
||||
private String lineName;
|
||||
|
||||
@ApiModelProperty("监测点运行状态")
|
||||
private String runFlag;
|
||||
|
||||
@ApiModelProperty("最新数据时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime latestTime;
|
||||
|
||||
@ApiModelProperty("数据完整性")
|
||||
private Double integrity;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,6 +50,8 @@ public class DetailAbnormalVO {
|
||||
private String avg;
|
||||
//CP95
|
||||
private String cp95;
|
||||
//幅值
|
||||
private String featureAmplitude;
|
||||
|
||||
}
|
||||
|
||||
@@ -73,6 +75,7 @@ public class DetailAbnormalVO {
|
||||
//最大
|
||||
private String val;
|
||||
|
||||
|
||||
//限值
|
||||
private float overLimitValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,14 +9,29 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
public class JsonBaseVO {
|
||||
|
||||
/**
|
||||
* 超标时间
|
||||
*/
|
||||
private String time;
|
||||
|
||||
/**
|
||||
* 异常值
|
||||
*/
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* 相别
|
||||
*/
|
||||
private String phasic;
|
||||
|
||||
/**
|
||||
* 数据类型(最大值:max、最小值:min、平均值:avg、95值:cp95)
|
||||
*/
|
||||
private String valueType;
|
||||
|
||||
/**
|
||||
* 限值
|
||||
*/
|
||||
private float overLimitValue;
|
||||
|
||||
}
|
||||
|
||||
@@ -20,10 +20,9 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>pq-device-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<artifactId>pq-device-com</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>system-api</artifactId>
|
||||
@@ -39,26 +38,10 @@
|
||||
<artifactId>common-web</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-oss</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn.platform</groupId>
|
||||
<artifactId>message-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>supervision-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn.platform</groupId>
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.device.biz.pojo.dto.LineDTO;
|
||||
import com.njcn.device.biz.pojo.dto.LineALLInfoDTO;
|
||||
import com.njcn.device.biz.pojo.dto.PollutionLineInfoDTO;
|
||||
import com.njcn.device.pq.service.LineService;
|
||||
import com.njcn.device.line.service.LineService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
@@ -11,14 +11,12 @@ import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.device.biz.pojo.dto.*;
|
||||
import com.njcn.device.biz.pojo.param.DeptGetLineParam;
|
||||
import com.njcn.device.biz.pojo.param.SubstationParam;
|
||||
import com.njcn.device.biz.pojo.po.Overlimit;
|
||||
import com.njcn.device.biz.pojo.po.PqsDeviceUnit;
|
||||
import com.njcn.device.pq.mapper.LineDetailMapper;
|
||||
import com.njcn.device.pq.mapper.LineMapper;
|
||||
import com.njcn.device.line.mapper.LineMapper;
|
||||
import com.njcn.device.line.service.LineService;
|
||||
import com.njcn.device.line.mapper.LineDetailMapper;
|
||||
import com.njcn.device.pq.service.CommTerminalService;
|
||||
import com.njcn.device.pq.service.IOverLimitService;
|
||||
import com.njcn.device.pq.service.IPqsDeviceUnitService;
|
||||
import com.njcn.device.pq.service.LineService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
@@ -57,9 +55,6 @@ public class CommTerminalController extends BaseController {
|
||||
|
||||
private final IPqsDeviceUnitService iPqsDeviceUnitService;
|
||||
|
||||
private final IOverLimitService iOverLimitService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 通过部门获取所有子集部门所拥有的监测点基本信息
|
||||
@@ -241,34 +236,6 @@ public class CommTerminalController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getOverLimitData")
|
||||
@ApiOperation("根据监测点id获取越限数值")
|
||||
@ApiImplicitParam(name = "id", value = "监测点id", required = true)
|
||||
public HttpResult<Overlimit> getOverLimitData(@RequestParam("id") String id) {
|
||||
String methodDescribe = getMethodDescribe("getOverLimitData");
|
||||
Overlimit result = lineService.getOverLimitData(id);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getAllLineOverLimit")
|
||||
@ApiOperation("获取投运在线的监测点的限值")
|
||||
public HttpResult<List<Overlimit>> getAllLineOverLimit() {
|
||||
String methodDescribe = getMethodDescribe("getAllLineOverLimit");
|
||||
List<Overlimit> result = lineService.getAllLineOverLimit("harmonic-boot", null);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getOverLimitDataByIds")
|
||||
@ApiOperation("根据监测点id集合获取越限数值")
|
||||
@ApiImplicitParam(name = "ids", value = "监测点id集合", required = true)
|
||||
public HttpResult<List<Overlimit>> getOverLimitDataByIds(@RequestBody List<String> ids) {
|
||||
String methodDescribe = getMethodDescribe("getOverLimitDataByIds");
|
||||
List<Overlimit> result = iOverLimitService.listByIds(ids);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@PostMapping("/getLineBySubstationRelation")
|
||||
@ApiOperation("获取变电站和监测点的关系")
|
||||
|
||||
@@ -7,10 +7,10 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.device.pq.mapper.DeptLineMapper;
|
||||
import com.njcn.device.line.mapper.DeptLineMapper;
|
||||
import com.njcn.device.line.service.DeptLineService;
|
||||
import com.njcn.device.pq.pojo.po.DeptLine;
|
||||
import com.njcn.device.pq.pojo.vo.LineDeviceStateVO;
|
||||
import com.njcn.device.pq.service.DeptLineService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.pojo.param.DeptLineParam;
|
||||
import io.swagger.annotations.Api;
|
||||
|
||||
@@ -76,4 +76,14 @@ public class DeviceRunEvaluateController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@PostMapping("/getRunEvaluateInfo")
|
||||
@ApiOperation("终端评价列表(冀北)")
|
||||
public HttpResult<List<DeviceRunEvaluateVO.Detail>> getRunEvaluateInfo(@RequestBody DeviceInfoParam.BusinessParam businessParam) {
|
||||
String methodDescribe = getMethodDescribe("getRunEvaluateInfo");
|
||||
List<DeviceRunEvaluateVO.Detail> runEvaluate = deviceRunEvaluateService.getRunEvaluate(businessParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, runEvaluate, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.device.common.service.GeneralDeviceService;
|
||||
import com.njcn.device.common.service.TerminalBaseService;
|
||||
import com.njcn.device.pq.mapper.RStatOnlinerateDMapper;
|
||||
import com.njcn.device.pq.pojo.bo.BaseLineInfo;
|
||||
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
|
||||
@@ -13,8 +15,6 @@ import com.njcn.device.pq.pojo.param.DeviceInfoParam;
|
||||
import com.njcn.device.pq.pojo.param.OnlineRateParam;
|
||||
import com.njcn.device.pq.pojo.po.TopMsgPO;
|
||||
import com.njcn.device.pq.pojo.vo.*;
|
||||
import com.njcn.device.pq.service.TerminalBaseService;
|
||||
import com.njcn.device.pq.service.impl.GeneralDeviceService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.njcn.device.pq.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
@@ -17,6 +16,7 @@ import com.njcn.device.pq.pojo.param.LineDataQualityParam;
|
||||
import com.njcn.device.pq.pojo.param.LineIntegrityDataParam;
|
||||
import com.njcn.device.pq.pojo.po.RStatIntegrityD;
|
||||
import com.njcn.device.pq.pojo.vo.LineIntegrityDataVO;
|
||||
import com.njcn.device.pq.pojo.vo.common.DeviceOnlineRate;
|
||||
import com.njcn.device.pq.service.IRStatIntegrityDService;
|
||||
import com.njcn.device.pq.service.LineIntegrityDataService;
|
||||
import com.njcn.harmonic.pojo.vo.IntegrityIconVO;
|
||||
@@ -148,4 +148,14 @@ public class LineIntegrityDataController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,flag,methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/data")
|
||||
@ApiOperation("监测点数据完整性(冀北)")
|
||||
@ApiImplicitParam(name = "param", value = "参数实体", required = true)
|
||||
public HttpResult<DeviceOnlineRate> getData(@RequestBody DeviceInfoParam.BusinessParam param) {
|
||||
String methodDescribe = getMethodDescribe("getData");
|
||||
DeviceOnlineRate rate = irStatIntegrityDService.getData(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, rate, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,20 +7,18 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.device.line.service.LineService;
|
||||
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
|
||||
import com.njcn.device.pq.pojo.param.PqsParam;
|
||||
import com.njcn.device.pq.pojo.po.TopMsgPO;
|
||||
import com.njcn.device.pq.pojo.vo.*;
|
||||
import com.njcn.device.pq.service.LineService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
package com.njcn.device.pq.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.device.biz.pojo.po.Overlimit;
|
||||
import com.njcn.device.pq.pojo.param.AlarmStrategyParam;
|
||||
import com.njcn.device.pq.pojo.vo.AlarmStrategyVO;
|
||||
import com.njcn.device.pq.service.AlarmStrategyService;
|
||||
import com.njcn.device.pq.service.IOverLimitService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 监测点限值
|
||||
* @author cdf
|
||||
* @date 2023/6/7
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/overLimit")
|
||||
@Api(tags = "监测点限值")
|
||||
@RequiredArgsConstructor
|
||||
public class OverLimitController extends BaseController {
|
||||
|
||||
private final IOverLimitService iOverLimitService;
|
||||
|
||||
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getOverLimitByLineIds")
|
||||
@ApiOperation("监测点集合获取限值")
|
||||
@ApiImplicitParam(name = "lineIds", value = "监测点ids", required = true)
|
||||
@ApiIgnore
|
||||
public HttpResult<List<Overlimit>> getOverLimitByLineIds(@RequestBody List<String> lineIds){
|
||||
String methodDescribe = getMethodDescribe("getOverLimitByLineIds");
|
||||
List<Overlimit> overLimitList= iOverLimitService.list(new LambdaQueryWrapper<Overlimit>().in(Overlimit::getId,lineIds));
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, overLimitList, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getLimitMapsByLineIds")
|
||||
@ApiOperation("监测点集合获取限值")
|
||||
@ApiImplicitParam(name = "lineIds", value = "监测点ids", required = true)
|
||||
@ApiIgnore
|
||||
public HttpResult<List<Map<String, Object>>> getLimitMapsByLineIds(@RequestBody List<String> lineIds){
|
||||
String methodDescribe = getMethodDescribe("getLimitMapsByLineIds");
|
||||
List<Map<String, Object>> overLimitList= iOverLimitService.listMaps(new LambdaQueryWrapper<Overlimit>().in(Overlimit::getId,lineIds));
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, overLimitList, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,9 @@ import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.device.biz.enums.DeviceResponseEnum;
|
||||
import com.njcn.device.common.service.GeneralDeviceService;
|
||||
import com.njcn.device.common.service.TerminalBaseService;
|
||||
import com.njcn.device.line.service.LineService;
|
||||
import com.njcn.device.pq.pojo.bo.DeviceType;
|
||||
import com.njcn.device.pq.pojo.bo.excel.TerminalBaseExcel;
|
||||
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
|
||||
@@ -20,10 +23,6 @@ import com.njcn.device.pq.pojo.dto.PushResultDTO;
|
||||
import com.njcn.device.pq.pojo.param.*;
|
||||
import com.njcn.device.pq.pojo.po.Line;
|
||||
import com.njcn.device.pq.pojo.vo.*;
|
||||
import com.njcn.device.pq.service.LineService;
|
||||
import com.njcn.device.pq.service.TerminalBaseService;
|
||||
import com.njcn.device.pq.service.impl.GeneralDeviceService;
|
||||
import com.njcn.message.constant.DeviceRebootType;
|
||||
import com.njcn.poi.util.PoiUtil;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
@@ -54,7 +54,7 @@ public class TerminalTreeController extends BaseController {
|
||||
String methodDescribe = getMethodDescribe("getTerminalTree");
|
||||
List<TerminalTree> tree;
|
||||
if(isJb){
|
||||
tree= terminalTreeService.getJbTerminalTree();
|
||||
tree= terminalTreeService.getJbNewTerminalTree();
|
||||
}else{
|
||||
tree= terminalTreeService.getTerminalTree();
|
||||
}
|
||||
|
||||
@@ -4,21 +4,13 @@ import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import com.njcn.dataProcess.api.PqsCommunicateFeignClient;
|
||||
import com.njcn.dataProcess.pojo.dto.PqsCommunicateDto;
|
||||
import com.njcn.device.pq.constant.Param;
|
||||
import com.njcn.device.pq.mapper.LineMapper;
|
||||
import com.njcn.device.pq.mapper.NodeMapper;
|
||||
import com.njcn.device.pq.mapper.PqsTerminalLogsMapper;
|
||||
import com.njcn.device.pq.pojo.dto.DeviceInfo;
|
||||
import com.njcn.device.pq.pojo.dto.NodeProcessDeviceTree;
|
||||
import com.njcn.device.device.service.DeviceProcessService;
|
||||
import com.njcn.device.device.service.IDeviceService;
|
||||
import com.njcn.device.node.mapper.NodeMapper;
|
||||
import com.njcn.device.pq.pojo.po.Device;
|
||||
import com.njcn.device.pq.pojo.po.DeviceProcess;
|
||||
import com.njcn.device.pq.pojo.po.Node;
|
||||
import com.njcn.device.pq.pojo.po.PqsTerminalLogs;
|
||||
import com.njcn.device.pq.service.DeviceProcessService;
|
||||
import com.njcn.device.pq.service.IDeviceService;
|
||||
import com.njcn.message.constant.DeviceRebootType;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
@@ -26,12 +18,9 @@ import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.njcn.device.pq.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.device.pq.pojo.po.Device;
|
||||
import com.njcn.device.pq.pojo.po.DeviceProcess;
|
||||
import com.njcn.device.pq.pojo.vo.DevDetail;
|
||||
import com.njcn.device.pq.pojo.vo.LineInfluxDbOnlineVO;
|
||||
import com.njcn.device.pq.pojo.vo.RunManageVO;
|
||||
import com.njcn.device.pq.pojo.vo.RunTimeVO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author cdf
|
||||
* @since 2022-01-04
|
||||
*/
|
||||
public interface DeviceProcessMapper extends BaseMapper<DeviceProcess> {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.njcn.device.pq.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.device.biz.pojo.po.Overlimit;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author cdf
|
||||
* @since 2022-01-04
|
||||
*/
|
||||
public interface OverlimitMapper extends BaseMapper<Overlimit> {
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.device.pq.mapper.OverlimitMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -34,4 +34,13 @@ public interface DeviceRunEvaluateService {
|
||||
|
||||
|
||||
TerminalEvaluateAreaVO.lastWeekTrendVO lastWeekTrend(DeviceInfoParam.BusinessParam businessParam);
|
||||
|
||||
/**
|
||||
* @Description: 获取终端列表
|
||||
* @param param
|
||||
* @return: java.util.List<com.njcn.device.pq.pojo.vo.DeviceRunEvaluateVO.Detail>
|
||||
* @Author: wr
|
||||
* @Date: 2025/11/27 10:24
|
||||
*/
|
||||
List<DeviceRunEvaluateVO.Detail> getRunEvaluate(DeviceInfoParam.BusinessParam param);
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.njcn.device.pq.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.device.biz.pojo.po.Overlimit;
|
||||
import com.njcn.device.pq.pojo.po.RStatIntegrityD;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 越限表实体
|
||||
* </p>
|
||||
*
|
||||
* @author hongawen
|
||||
* @since 2023-03-28
|
||||
*/
|
||||
public interface IOverLimitService extends IService<Overlimit> {
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -5,9 +5,11 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.github.jeffreyning.mybatisplus.service.IMppService;
|
||||
import com.njcn.device.pq.pojo.dto.LineDataQualityDTO;
|
||||
import com.njcn.device.pq.pojo.dto.MonitorIntegrityDTO;
|
||||
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
|
||||
import com.njcn.device.pq.pojo.param.LineBaseQueryParam;
|
||||
import com.njcn.device.pq.pojo.param.LineDataQualityParam;
|
||||
import com.njcn.device.pq.pojo.po.RStatIntegrityD;
|
||||
import com.njcn.device.pq.pojo.vo.common.DeviceOnlineRate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -33,4 +35,6 @@ public interface IRStatIntegrityDService extends IMppService<RStatIntegrityD> {
|
||||
List<LineDataQualityDTO> getLineDataQuality(LineDataQualityParam lineDataQualityParam);
|
||||
|
||||
Boolean saveOrUpdateData(List<MonitorIntegrityDTO> monitorIntegrityDTOList);
|
||||
|
||||
DeviceOnlineRate getData(DeviceInfoParam.BusinessParam param);
|
||||
}
|
||||
|
||||
@@ -49,4 +49,7 @@ public interface TerminalTreeService {
|
||||
* @return
|
||||
*/
|
||||
List<TerminalTree> getJbTerminalTree();
|
||||
|
||||
|
||||
List<TerminalTree> getJbNewTerminalTree();
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ import com.njcn.common.utils.EnumUtils;
|
||||
import com.njcn.device.biz.pojo.dto.*;
|
||||
import com.njcn.device.biz.pojo.param.DeptGetLineParam;
|
||||
import com.njcn.device.biz.pojo.param.SubstationParam;
|
||||
import com.njcn.device.line.mapper.LineMapper;
|
||||
import com.njcn.device.line.service.DeptLineService;
|
||||
import com.njcn.device.pq.enums.RunFlagEnum;
|
||||
import com.njcn.device.pq.mapper.LineMapper;
|
||||
import com.njcn.device.pq.pojo.param.dataClean.MonitorBaseParam;
|
||||
import com.njcn.device.pq.service.CommTerminalService;
|
||||
import com.njcn.device.pq.service.DeptLineService;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.user.api.DeptFeignClient;
|
||||
import com.njcn.user.pojo.dto.DeptDTO;
|
||||
|
||||
@@ -3,8 +3,7 @@ package com.njcn.device.pq.service.impl;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.*;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.device.pq.mapper.OnlineRateMapper;
|
||||
import com.njcn.device.pq.mapper.RStatIntegrityDMapper;
|
||||
import com.njcn.device.line.service.LineService;
|
||||
import com.njcn.device.pq.mapper.RStatOnlinerateDMapper;
|
||||
import com.njcn.device.pq.pojo.param.OnlineRateParam;
|
||||
import com.njcn.device.pq.pojo.param.PulicTimeParam;
|
||||
@@ -12,23 +11,17 @@ import com.njcn.device.pq.pojo.param.PulicTimeStatisParam;
|
||||
import com.njcn.device.pq.pojo.po.RStatOnlinerateD;
|
||||
import com.njcn.device.pq.pojo.vo.*;
|
||||
import com.njcn.device.pq.service.CommunicateService;
|
||||
import com.njcn.device.pq.service.LineService;
|
||||
import com.njcn.device.pq.utils.PublicDateUtil;
|
||||
import com.njcn.device.rstatintegrity.mapper.RStatIntegrityDMapper;
|
||||
import com.njcn.web.enums.DateFlagEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,13 +4,9 @@ package com.njcn.device.pq.service.impl;
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.*;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.C;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.dataProcess.api.DataLimitRateDetailFeignClient;
|
||||
@@ -21,31 +17,23 @@ import com.njcn.dataProcess.enums.DataCleanEnum;
|
||||
import com.njcn.dataProcess.param.DataCleanParam;
|
||||
import com.njcn.dataProcess.param.LineCountEvaluateParam;
|
||||
import com.njcn.dataProcess.pojo.dto.DataLimitRateDetailDto;
|
||||
import com.njcn.dataProcess.pojo.dto.DataLimitRateDto;
|
||||
import com.njcn.dataProcess.pojo.dto.DataLimitTargetDto;
|
||||
import com.njcn.dataProcess.pojo.dto.PqReasonableRangeDto;
|
||||
import com.njcn.device.biz.enums.DeviceResponseEnum;
|
||||
import com.njcn.device.biz.pojo.dto.LineDevGetDTO;
|
||||
import com.njcn.device.pq.constant.Param;
|
||||
import com.njcn.device.line.mapper.LineMapper;
|
||||
import com.njcn.device.pq.mapper.DataVerifyMapper;
|
||||
import com.njcn.device.pq.mapper.LineDetailMapper;
|
||||
import com.njcn.device.pq.mapper.LineMapper;
|
||||
import com.njcn.device.pq.mapper.PqDataVerifyBakMapper;
|
||||
import com.njcn.device.pq.pojo.param.dataClean.MonitorBaseParam;
|
||||
import com.njcn.device.pq.pojo.po.DataVerify;
|
||||
|
||||
import com.njcn.device.pq.pojo.po.Line;
|
||||
import com.njcn.device.pq.pojo.po.LineDetail;
|
||||
import com.njcn.device.pq.pojo.vo.AreaLineInfoVO;
|
||||
import com.njcn.device.pq.pojo.vo.LineDetailDataVO;
|
||||
import com.njcn.device.pq.pojo.vo.dataClean.*;
|
||||
import com.njcn.device.pq.service.CommTerminalService;
|
||||
import com.njcn.device.pq.service.IDataVerifyService;
|
||||
import com.njcn.device.pq.service.LineService;
|
||||
import com.njcn.harmonic.pojo.vo.RStatLimitTargetVO;
|
||||
import com.njcn.supervision.api.UserLedgerFeignClient;
|
||||
import com.njcn.supervision.pojo.vo.user.NewUserReportVO;
|
||||
import com.njcn.supervision.pojo.vo.user.UserLedgerVO;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
@@ -58,16 +46,12 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.DateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -525,6 +509,7 @@ public class DataVerifyServiceImpl extends ServiceImpl<DataVerifyMapper, DataVer
|
||||
vo.setVal(valArr[i]);
|
||||
vo.setPhaseType(phasic);
|
||||
vo.setTargetName(StrUtil.isNotBlank(count) ? count + "次" + targetName : targetName);
|
||||
vo.setOverLimitValue(it.getOverLimitValue());
|
||||
result.add(vo);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -6,33 +6,41 @@ import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.njcn.device.pq.mapper.RStatIntegrityDMapper;
|
||||
import com.njcn.device.common.mapper.onlinerate.OnLineRateMapper;
|
||||
import com.njcn.device.common.service.GeneralDeviceService;
|
||||
import com.njcn.device.line.mapper.LineMapper;
|
||||
import com.njcn.device.line.service.DeptLineService;
|
||||
import com.njcn.device.line.service.LineService;
|
||||
import com.njcn.device.pq.mapper.RStatOnlinerateDMapper;
|
||||
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
|
||||
import com.njcn.device.pq.pojo.param.DevRunEvaluateParam;
|
||||
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
|
||||
import com.njcn.device.pq.pojo.param.OnlineRateParam;
|
||||
import com.njcn.device.pq.pojo.po.Line;
|
||||
import com.njcn.device.pq.pojo.po.RStatIntegrityD;
|
||||
import com.njcn.device.pq.pojo.po.RStatOnlinerateD;
|
||||
import com.njcn.device.pq.pojo.vo.DevDetailVO;
|
||||
import com.njcn.device.pq.pojo.vo.DeviceRunEvaluateVO;
|
||||
import com.njcn.device.pq.pojo.vo.*;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.njcn.device.pq.enums.LineBaseEnum;
|
||||
import com.njcn.device.pq.enums.PowerFlagEnum;
|
||||
import com.njcn.device.pq.enums.RunFlagEnum;
|
||||
import com.njcn.device.pq.mapper.LineMapper;
|
||||
import com.njcn.device.pq.pojo.dto.MonitorInfoDTO;
|
||||
import com.njcn.device.pq.pojo.vo.TerminalEvaluateAreaVO;
|
||||
import com.njcn.device.pq.service.DeptLineService;
|
||||
import com.njcn.device.pq.service.DeviceRunEvaluateService;
|
||||
import com.njcn.device.rstatintegrity.mapper.RStatIntegrityDMapper;
|
||||
import com.njcn.harmonic.api.RStatLimitRateDClient;
|
||||
import com.njcn.harmonic.pojo.param.RStatLimitQueryParam;
|
||||
import com.njcn.harmonic.pojo.po.day.RStatLimitRateDPO;
|
||||
import com.njcn.supervision.api.UserLedgerFeignClient;
|
||||
import com.njcn.supervision.pojo.vo.user.NewUserReportVO;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.enums.DicDataTypeEnum;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import com.njcn.user.api.DeptFeignClient;
|
||||
import com.njcn.user.pojo.po.Dept;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -61,7 +69,10 @@ public class DeviceRunEvaluateServiceImpl implements DeviceRunEvaluateService {
|
||||
private final LineMapper lineMapper;
|
||||
private final UserLedgerFeignClient userLedgerFeignClient;
|
||||
private final DeptLineService deptLineService;
|
||||
|
||||
private final GeneralDeviceService deviceService;
|
||||
private final OnLineRateMapper onLineRateMapper;
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
private final DeptFeignClient deptFeignClient;
|
||||
/**
|
||||
* 数据完整性:50%
|
||||
*/
|
||||
@@ -95,7 +106,7 @@ public class DeviceRunEvaluateServiceImpl implements DeviceRunEvaluateService {
|
||||
DeviceRunEvaluateVO.Info evaluateVO;
|
||||
for (GeneralDeviceDTO deptDeviceInfo : deptDeviceInfos) {
|
||||
List<String> lineIndexes = deptDeviceInfo.getLineIndexes();
|
||||
List<String> devIndexes = deptDeviceInfo.getLineIndexes();
|
||||
List<String> devIndexes = deptDeviceInfo.getDeviceIndexes();
|
||||
if (CollUtil.isNotEmpty(lineIndexes)) {
|
||||
evaluateVO = new DeviceRunEvaluateVO.Info();
|
||||
evaluateVO.setName(deptDeviceInfo.getName());
|
||||
@@ -106,7 +117,7 @@ public class DeviceRunEvaluateServiceImpl implements DeviceRunEvaluateService {
|
||||
|
||||
}
|
||||
|
||||
return info.stream().sorted(Comparator.comparing(DeviceRunEvaluateVO.Info::getEvaluate,Comparator.reverseOrder())).collect(Collectors.toList());
|
||||
return info.stream().sorted(Comparator.comparing(DeviceRunEvaluateVO.Info::getEvaluate, Comparator.reverseOrder())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void setEvaluate(List<String> devIds, List<String> lineIds, List<RStatIntegrityD> onIntegrityList, DeviceRunEvaluateVO evaluateVO, List<RStatOnlinerateD> onlineRateList, List<RStatLimitRateDPO> limitRateList) {
|
||||
@@ -115,7 +126,7 @@ public class DeviceRunEvaluateServiceImpl implements DeviceRunEvaluateService {
|
||||
if (CollUtil.isNotEmpty(integrityDS)) {
|
||||
double realTime = integrityDS.stream().mapToDouble(RStatIntegrityD::getRealTime).sum();
|
||||
double dueTime = integrityDS.stream().mapToDouble(RStatIntegrityD::getDueTime).sum();
|
||||
evaluateVO.setIntegrityRate(NumberUtil.round(Math.min(realTime * 100 / dueTime,100), 2));
|
||||
evaluateVO.setIntegrityRate(NumberUtil.round(Math.min(realTime * 100 / dueTime, 100), 2));
|
||||
} else {
|
||||
evaluateVO.setIntegrityRate(new BigDecimal(0));
|
||||
}
|
||||
@@ -124,7 +135,7 @@ public class DeviceRunEvaluateServiceImpl implements DeviceRunEvaluateService {
|
||||
if (CollUtil.isNotEmpty(onlineRateDS)) {
|
||||
double onlineTime = onlineRateDS.stream().mapToDouble(RStatOnlinerateD::getOnlineMin).sum();
|
||||
double offlineTime = onlineRateDS.stream().mapToDouble(RStatOnlinerateD::getOfflineMin).sum();
|
||||
evaluateVO.setOnLineRate(NumberUtil.round(Math.min(onlineTime * 100.0 / (onlineTime + offlineTime),100), 2));
|
||||
evaluateVO.setOnLineRate(NumberUtil.round(Math.min(onlineTime * 100.0 / (onlineTime + offlineTime), 100), 2));
|
||||
} else {
|
||||
evaluateVO.setOnLineRate(new BigDecimal(0));
|
||||
}
|
||||
@@ -142,7 +153,7 @@ public class DeviceRunEvaluateServiceImpl implements DeviceRunEvaluateService {
|
||||
if (allTime == 0) {
|
||||
evaluateVO.setPassRate(new BigDecimal(0));
|
||||
} else {
|
||||
evaluateVO.setPassRate(NumberUtil.round(Math.min((1 - (overTime * 1.0 / allTime)) * 100,100), 2));
|
||||
evaluateVO.setPassRate(NumberUtil.round(Math.min((1 - (overTime * 1.0 / allTime)) * 100, 100), 2));
|
||||
}
|
||||
} else {
|
||||
evaluateVO.setPassRate(new BigDecimal(0));
|
||||
@@ -212,7 +223,7 @@ public class DeviceRunEvaluateServiceImpl implements DeviceRunEvaluateService {
|
||||
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceService.getDeviceInfo(businessParam, Stream.of(RunFlagEnum.RUNNING.getStatus()).collect(Collectors.toList()), Stream.of(PowerFlagEnum.REAL_DEVICE.getCode()).collect(Collectors.toList()));
|
||||
if (CollectionUtil.isNotEmpty(generalDeviceDTOList)) {
|
||||
if (generalDeviceDTOList.size() == 1 && generalDeviceDTOList.get(0).getIndex().equals(businessParam.getDeptIndex())) {
|
||||
if(CollUtil.isNotEmpty(generalDeviceDTOList.get(0).getLineIndexes())) {
|
||||
if (CollUtil.isNotEmpty(generalDeviceDTOList.get(0).getLineIndexes())) {
|
||||
//已经最底层,展示电站和用户场站
|
||||
List<MonitorInfoDTO> lineDetailList = lineMapper.getLineListByIds(generalDeviceDTOList.get(0).getLineIndexes());
|
||||
List<String> ids = lineDetailList.stream().map(MonitorInfoDTO::getId).distinct().collect(Collectors.toList());
|
||||
@@ -245,7 +256,7 @@ public class DeviceRunEvaluateServiceImpl implements DeviceRunEvaluateService {
|
||||
}
|
||||
} else {
|
||||
for (GeneralDeviceDTO generalDeviceDTO : generalDeviceDTOList) {
|
||||
if(CollUtil.isEmpty(generalDeviceDTO.getDeviceIndexes())){
|
||||
if (CollUtil.isEmpty(generalDeviceDTO.getDeviceIndexes())) {
|
||||
continue;
|
||||
}
|
||||
List<RStatIntegrityD> rStatIntegrityDList = new ArrayList<>();
|
||||
@@ -333,6 +344,139 @@ public class DeviceRunEvaluateServiceImpl implements DeviceRunEvaluateService {
|
||||
return lastWeekTrendVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceRunEvaluateVO.Detail> getRunEvaluate(DeviceInfoParam.BusinessParam param) {
|
||||
List<DictData> manufacturerList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.DEV_MANUFACTURER.getCode()).getData();
|
||||
Map<String, String> manufacturerMap = manufacturerList.stream().collect(Collectors.toMap(DictData::getId, DictData::getName));
|
||||
List<Dept> deptList = deptFeignClient.getAllDept().getData();
|
||||
Map<String, String> deptMap = deptList.stream().collect(Collectors.toMap(Dept::getId, Dept::getName));
|
||||
|
||||
List<DeviceRunEvaluateVO.Detail> info = new ArrayList<>();
|
||||
//获取终端台账类信息
|
||||
List<GeneralDeviceDTO> deviceInfo = deviceService.getDeviceInfo(param, ObjectUtil.isNull(param.getLineRunFlag()) ? null : Arrays.asList(param.getLineRunFlag()), Arrays.asList(1));
|
||||
if (CollUtil.isNotEmpty(deviceInfo)) {
|
||||
List<String> deviceIds = deviceInfo.stream()
|
||||
.flatMap(x -> x.getDeviceIndexes().stream()).collect(Collectors.toList())
|
||||
.stream()
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
List<String> lineIds = deviceInfo.stream()
|
||||
.flatMap(x -> x.getLineIndexes().stream()).collect(Collectors.toList())
|
||||
.stream()
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
//获取所有监测点信息信息
|
||||
List<DevDetailVO> lineDeviceByDevIds = lineMapper.getLineDeviceByDevIds(param.getPowerFlag(), lineIds, deviceIds);
|
||||
RStatLimitQueryParam rStatLimitQueryParam = new RStatLimitQueryParam();
|
||||
rStatLimitQueryParam.setIds(lineIds);
|
||||
rStatLimitQueryParam.setDate(param.getSearchBeginTime());
|
||||
rStatLimitQueryParam.setEndDate(param.getSearchEndTime());
|
||||
OnlineRateParam onlineRateParam = new OnlineRateParam();
|
||||
onlineRateParam.setIds(deviceIds);
|
||||
onlineRateParam.setStartTime(param.getSearchBeginTime());
|
||||
onlineRateParam.setEndTime(param.getSearchEndTime());
|
||||
DeviceRunEvaluateVO.Detail detail;
|
||||
//完整率
|
||||
List<RStatIntegrityVO> integrityList = integrityDMapper.getLineIntegrityRateInfo(lineIds, param.getSearchBeginTime(), param.getSearchEndTime());
|
||||
//超标率
|
||||
List<RStatLimitRateDPO> limitRatePOList = rStatLimitRateDClient.monitorIdsGetLimitInfo(rStatLimitQueryParam).getData();
|
||||
//获取所有终端在线率
|
||||
List<RStatOnlinerateVO> onlineRateByDev = onLineRateMapper.getOnlineRateByDevIds(onlineRateParam);
|
||||
|
||||
for (GeneralDeviceDTO dto : deviceInfo) {
|
||||
detail = new DeviceRunEvaluateVO.Detail();
|
||||
detail.setName(dto.getName());
|
||||
detail.setCount(dto.getDeviceIndexes().size());
|
||||
detail.setOnline(onLineRate(onlineRateByDev, dto.getDeviceIndexes()));
|
||||
detail.setIntegrity(integrity(integrityList, dto.getLineIndexes()));
|
||||
detail.setQualified(limitRate(limitRatePOList, dto.getLineIndexes()));
|
||||
detail.setScore(ONINTEGRITY.multiply(detail.getIntegrity())
|
||||
.add(ONLINERATE.multiply(detail.getOnline())
|
||||
.add(LIMITRATE.multiply(detail.getQualified()))).stripTrailingZeros());
|
||||
Map<String, List<DevDetailVO>> dev = lineDeviceByDevIds
|
||||
.stream()
|
||||
.filter(x -> dto.getDeviceIndexes().contains(x.getDevId()))
|
||||
.collect(Collectors.groupingBy(DevDetailVO::getDevId));
|
||||
List<DeviceRunEvaluateVO> deviceDetail = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(dev)) {
|
||||
dev.forEach((key, value) -> {
|
||||
List<String> ids = value.stream().map(DevDetailVO::getLineId).distinct().collect(Collectors.toList());
|
||||
DeviceRunEvaluateVO evaluateVO = new DeviceRunEvaluateVO();
|
||||
evaluateVO.setId(value.get(0).getDevId());
|
||||
evaluateVO.setName(value.get(0).getDevName());
|
||||
evaluateVO.setSubName(value.get(0).getSubName());
|
||||
evaluateVO.setIp(value.get(0).getIp());
|
||||
//部门
|
||||
if (deptMap.containsKey(value.get(0).getCit())) {
|
||||
evaluateVO.setCit(deptMap.get(value.get(0).getCit()));
|
||||
}
|
||||
//终端厂商
|
||||
if (manufacturerMap.containsKey(value.get(0).getManufacturer())) {
|
||||
evaluateVO.setManufacturer(manufacturerMap.get(value.get(0).getManufacturer()));
|
||||
}
|
||||
evaluateVO.setOnLineRate(onLineRate(onlineRateByDev, Arrays.asList(key)));
|
||||
evaluateVO.setIntegrityRate(integrity(integrityList, ids));
|
||||
evaluateVO.setPassRate(limitRate(limitRatePOList, ids));
|
||||
evaluateVO.setEvaluate(ONINTEGRITY.multiply(evaluateVO.getIntegrityRate())
|
||||
.add(ONLINERATE.multiply(evaluateVO.getOnLineRate())
|
||||
.add(LIMITRATE.multiply(evaluateVO.getPassRate()))).stripTrailingZeros());
|
||||
deviceDetail.add(evaluateVO);
|
||||
});
|
||||
}
|
||||
detail.setList(deviceDetail);
|
||||
info.add(detail);
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
private BigDecimal integrity(List<RStatIntegrityVO> integrityList, List<String> lineIds) {
|
||||
//监测完整率
|
||||
List<RStatIntegrityVO> integrityDS = integrityList.stream().filter(x -> lineIds.contains(x.getLineIndex())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(integrityDS)) {
|
||||
double realTime = integrityDS.stream().mapToDouble(RStatIntegrityVO::getRealTime).sum();
|
||||
double dueTime = integrityDS.stream().mapToDouble(RStatIntegrityVO::getDueTime).sum();
|
||||
return NumberUtil.round(Math.min(realTime * 100 / dueTime, 100), 2);
|
||||
} else {
|
||||
return new BigDecimal(0);
|
||||
}
|
||||
}
|
||||
|
||||
private BigDecimal onLineRate(List<RStatOnlinerateVO> onlineRateByDev, List<String> devIds) {
|
||||
//终端在线率
|
||||
List<RStatOnlinerateVO> onlineRateDS = onlineRateByDev.stream().filter(x -> devIds.contains(x.getDevIndex())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(onlineRateDS)) {
|
||||
double onlineTime = onlineRateDS.stream().mapToDouble(RStatOnlinerateVO::getOnlineMin).sum();
|
||||
double offlineTime = onlineRateDS.stream().mapToDouble(RStatOnlinerateVO::getOfflineMin).sum();
|
||||
return NumberUtil.round(Math.min(onlineTime * 100.0 / (onlineTime + offlineTime), 100), 2);
|
||||
} else {
|
||||
return new BigDecimal(0);
|
||||
}
|
||||
}
|
||||
|
||||
private BigDecimal limitRate(List<RStatLimitRateDPO> limitRatePOList, List<String> lineIds) {
|
||||
//超标信息
|
||||
List<RStatLimitRateDPO> limitRateDPOS = limitRatePOList.stream().filter(x -> lineIds.contains(x.getLineId())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(limitRateDPOS)) {
|
||||
double overTime = limitRateDPOS.stream().mapToDouble(x -> (x.getUaberranceOvertime() +
|
||||
x.getUharm2Overtime() + x.getUharm3Overtime() + x.getUharm4Overtime() + x.getUharm5Overtime() +
|
||||
x.getUharm6Overtime() + x.getUharm7Overtime() + x.getUharm8Overtime() + x.getUharm9Overtime() +
|
||||
x.getUharm10Overtime() + x.getUharm11Overtime() + x.getUharm12Overtime() + x.getUharm13Overtime() + x.getUharm14Overtime() +
|
||||
x.getUharm15Overtime() + x.getUharm16Overtime() + x.getUharm17Overtime() + x.getUharm18Overtime() + x.getUharm19Overtime() +
|
||||
x.getUharm20Overtime() + x.getUharm21Overtime() + x.getUharm22Overtime() + x.getUharm23Overtime() + x.getUharm24Overtime() +
|
||||
x.getUharm25Overtime())).sum();
|
||||
double allTime = limitRateDPOS.stream().mapToDouble(x -> x.getAllTime() * 25.0).sum();
|
||||
if (allTime == 0) {
|
||||
return new BigDecimal(0);
|
||||
} else {
|
||||
return NumberUtil.round(Math.min((1 - (overTime * 1.0 / allTime)) * 100, 100), 2);
|
||||
}
|
||||
} else {
|
||||
return new BigDecimal(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Map<String, NewUserReportVO> getUserLedgerByObjIds(List<String> objIds) {
|
||||
List<NewUserReportVO> userReportVOList = userLedgerFeignClient.getUserReportByIds(objIds).getData();
|
||||
return userReportVOList.stream().collect(Collectors.toMap(NewUserReportVO::getId, Function.identity()));
|
||||
|
||||
@@ -5,7 +5,6 @@ import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -14,8 +13,11 @@ import com.njcn.common.pojo.param.StatisticsBizBaseParam;
|
||||
import com.njcn.device.biz.pojo.dto.DeptGetChildrenMoreDTO;
|
||||
import com.njcn.device.biz.pojo.dto.LineDevGetDTO;
|
||||
import com.njcn.device.biz.pojo.param.DeptGetLineParam;
|
||||
import com.njcn.device.pq.mapper.LineDetailMapper;
|
||||
import com.njcn.device.pq.mapper.RStatIntegrityDMapper;
|
||||
import com.njcn.device.common.service.GeneralDeviceService;
|
||||
import com.njcn.device.device.service.IDeviceService;
|
||||
import com.njcn.device.line.mapper.LineDetailMapper;
|
||||
import com.njcn.device.line.service.DeptLineService;
|
||||
import com.njcn.device.line.service.LineService;
|
||||
import com.njcn.device.pq.mapper.RStatOnlinerateDMapper;
|
||||
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
|
||||
import com.njcn.device.pq.pojo.param.GridDiagramParam;
|
||||
@@ -25,12 +27,12 @@ import com.njcn.device.pq.pojo.po.*;
|
||||
import com.njcn.device.pq.pojo.vo.GridDiagramProVO;
|
||||
import com.njcn.device.pq.pojo.vo.GridDiagramVO;
|
||||
import com.njcn.device.pq.service.*;
|
||||
import com.njcn.device.rstatintegrity.mapper.RStatIntegrityDMapper;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.enums.DicDataTypeEnum;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import com.njcn.user.api.DeptFeignClient;
|
||||
import com.njcn.user.pojo.dto.DeptDTO;
|
||||
import com.njcn.user.pojo.po.Dept;
|
||||
|
||||
import java.time.ZoneId;
|
||||
@@ -39,7 +41,6 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.njcn.web.utils.WebUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -243,7 +244,6 @@ public class GridDiagramServiceImpl implements GridDiagramService {
|
||||
public GridDiagramVO getGridDiagramDev(GridDiagramParam param) {
|
||||
//获取电压等级
|
||||
List<DictData> dictDataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.DEV_VOLTAGE_STAND.getCode()).getData();
|
||||
|
||||
List<DictData> v = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.PANORAMIC_VOLTAGE.getCode()).getData();
|
||||
List<String> voltageIds;
|
||||
//获取电压等级550 220 110 35
|
||||
@@ -263,7 +263,6 @@ public class GridDiagramServiceImpl implements GridDiagramService {
|
||||
List<Dept> data = deptFeignClient.getDirectSonSelf(param.getOrgId()).getData();
|
||||
DeptGetLineParam deptGetLineParam = new DeptGetLineParam();
|
||||
deptGetLineParam.setDeptId(param.getOrgId());
|
||||
deptGetLineParam.setLineRunFlag(0);
|
||||
List<DeptGetChildrenMoreDTO> deptGetChildrenMoreDTOS = commTerminalService.deptGetLine(deptGetLineParam);
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.njcn.device.pq.service.impl;
|
||||
|
||||
import com.njcn.common.pojo.dto.SimpleDTO;
|
||||
import com.njcn.device.common.service.GeneralDeviceService;
|
||||
import com.njcn.device.pq.mapper.LargeScreenMapper;
|
||||
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
|
||||
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
|
||||
|
||||
@@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.config.GeneralInfo;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.device.common.service.GeneralDeviceService;
|
||||
import com.njcn.device.pq.api.AlarmClient;
|
||||
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
|
||||
import com.njcn.device.biz.enums.DeviceResponseEnum;
|
||||
@@ -15,7 +16,6 @@ import com.njcn.device.pq.enums.LineBaseEnum;
|
||||
import com.njcn.device.pq.enums.PowerFlagEnum;
|
||||
import com.njcn.device.pq.enums.RunFlagEnum;
|
||||
import com.njcn.device.pq.mapper.LineIntegrityDataMapper;
|
||||
import com.njcn.device.pq.mapper.RStatIntegrityDMapper;
|
||||
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
|
||||
import com.njcn.device.pq.pojo.dto.PublicDTO;
|
||||
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
|
||||
@@ -27,6 +27,7 @@ import com.njcn.device.pq.pojo.vo.LineIntegrityDataVO;
|
||||
import com.njcn.device.pq.pojo.vo.RStatIntegrityVO;
|
||||
import com.njcn.device.pq.service.LineIntegrityDataService;
|
||||
import com.njcn.device.pq.utils.DataStatisticsUtil;
|
||||
import com.njcn.device.rstatintegrity.mapper.RStatIntegrityDMapper;
|
||||
import com.njcn.harmonic.pojo.vo.IntegrityIconVO;
|
||||
import com.njcn.supervision.api.UserLedgerFeignClient;
|
||||
import com.njcn.supervision.pojo.param.user.UserReportParam;
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.device.biz.enums.DeviceResponseEnum;
|
||||
import com.njcn.device.pq.mapper.LineDetailMapper;
|
||||
import com.njcn.device.line.mapper.LineDetailMapper;
|
||||
import com.njcn.device.pq.mapper.LineMarkMapper;
|
||||
import com.njcn.device.pq.pojo.bo.excel.LineMark;
|
||||
import com.njcn.device.pq.pojo.param.TerminalMainQueryParam;
|
||||
|
||||
@@ -7,30 +7,20 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.njcn.db.constant.DbConstant;
|
||||
import com.njcn.device.line.mapper.LineMapper;
|
||||
import com.njcn.device.pq.mapper.EventPushLogsMapper;
|
||||
import com.njcn.device.pq.mapper.LineMapper;
|
||||
import com.njcn.device.pq.mapper.LogManageMapper;
|
||||
import com.njcn.device.pq.pojo.constant.DeviceValidMessage;
|
||||
import com.njcn.device.pq.pojo.param.DeviceLogParam;
|
||||
import com.njcn.device.pq.pojo.param.EventLogParam;
|
||||
import com.njcn.device.pq.pojo.po.EventPushLogs;
|
||||
import com.njcn.device.pq.pojo.vo.AreaLineInfoVO;
|
||||
import com.njcn.device.pq.pojo.vo.DeviceLogVO;
|
||||
import com.njcn.device.pq.pojo.vo.EventLogVO;
|
||||
import com.njcn.device.pq.service.LogManageService;
|
||||
import com.njcn.event.api.EventDetailFeignClient;
|
||||
import com.njcn.event.pojo.po.EventDetail;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.influxdb.dto.QueryResult;
|
||||
import org.influxdb.impl.InfluxDBResultMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -7,8 +7,8 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.device.biz.enums.DeviceResponseEnum;
|
||||
import com.njcn.device.line.mapper.LineDetailMapper;
|
||||
import com.njcn.device.pq.enums.PvDeviceResponseEnum;
|
||||
import com.njcn.device.pq.mapper.LineDetailMapper;
|
||||
import com.njcn.device.pq.mapper.NewStationMapper;
|
||||
import com.njcn.device.pq.pojo.param.NewStationQueryParam;
|
||||
import com.njcn.device.pq.pojo.po.NewStation;
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.njcn.device.pq.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.device.biz.pojo.po.Overlimit;
|
||||
import com.njcn.device.pq.mapper.OverlimitMapper;
|
||||
import com.njcn.device.pq.service.IOverLimitService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* pqs
|
||||
*
|
||||
* @author cdf
|
||||
* @date 2023/6/7
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class OverLimitServiceImpl extends ServiceImpl<OverlimitMapper, Overlimit> implements IOverLimitService {
|
||||
|
||||
}
|
||||
@@ -17,15 +17,11 @@ import com.njcn.dataProcess.api.PqReasonableRangeFeignClient;
|
||||
import com.njcn.dataProcess.enums.DataCleanEnum;
|
||||
import com.njcn.dataProcess.param.DataCleanParam;
|
||||
import com.njcn.dataProcess.pojo.dto.PqReasonableRangeDto;
|
||||
import com.njcn.device.biz.enums.DeviceResponseEnum;
|
||||
import com.njcn.device.biz.enums.LineFlagEnum;
|
||||
import com.njcn.device.biz.pojo.dto.LineDevGetDTO;
|
||||
import com.njcn.device.line.mapper.LineMapper;
|
||||
import com.njcn.device.pq.constant.Param;
|
||||
import com.njcn.device.pq.enums.LineBaseEnum;
|
||||
import com.njcn.device.pq.mapper.LineMapper;
|
||||
import com.njcn.device.pq.mapper.PqDataVerifyBakMapper;
|
||||
import com.njcn.device.pq.pojo.param.dataClean.MonitorBaseParam;
|
||||
import com.njcn.device.pq.pojo.po.DataVerify;
|
||||
import com.njcn.device.pq.pojo.po.PqDataVerifyBak;
|
||||
import com.njcn.device.pq.pojo.vo.AreaLineInfoVO;
|
||||
import com.njcn.device.pq.pojo.vo.LineDetailDataVO;
|
||||
@@ -35,8 +31,6 @@ import com.njcn.device.pq.pojo.vo.dataClean.VerifyMonitorVO;
|
||||
import com.njcn.device.pq.pojo.vo.dataClean.VerifyTargetVO;
|
||||
import com.njcn.device.pq.service.CommTerminalService;
|
||||
import com.njcn.device.pq.service.IPqDataVerifyBakService;
|
||||
import com.njcn.harmonic.enums.HarmonicResponseEnum;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.supervision.api.UserLedgerFeignClient;
|
||||
import com.njcn.supervision.pojo.vo.user.NewUserReportVO;
|
||||
@@ -45,13 +39,10 @@ import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
@@ -484,7 +475,7 @@ public class PqDataVerifyBakServiceImpl extends ServiceImpl<PqDataVerifyBakMappe
|
||||
vo.setTargetKey(targetKey);
|
||||
vo.setPhaseType(phaseKey);
|
||||
|
||||
if ((pqReasonableRangeDto.getInfluxdbTableName() + SEPARATOR + pqReasonableRangeDto.getIndexCode()).equals(targetKey)) {
|
||||
if ((DataCleanEnum.DataI.getCode() + SEPARATOR + DataCleanEnum.RmsI.getCode() ).equals(targetKey)) {
|
||||
vo.setRangeDesc(pqReasonableRangeDto.getMinValue() + unit + " ~ " + pqReasonableRangeDto.getMaxValue() + "*CT1" + unit);
|
||||
} else {
|
||||
vo.setRangeDesc(pqReasonableRangeDto.getMinValue() + unit + " ~ " + pqReasonableRangeDto.getMaxValue() + unit);
|
||||
@@ -502,6 +493,8 @@ public class PqDataVerifyBakServiceImpl extends ServiceImpl<PqDataVerifyBakMappe
|
||||
break;
|
||||
case "CP95":
|
||||
vo.setCp95(ites.getVal());
|
||||
case "Feature_Amplitude":
|
||||
vo.setFeatureAmplitude(ites.getVal());
|
||||
break;
|
||||
}
|
||||
});
|
||||
@@ -527,7 +520,7 @@ public class PqDataVerifyBakServiceImpl extends ServiceImpl<PqDataVerifyBakMappe
|
||||
queryWrapper.select("line_id as lineId,sum(freq) as freq,sum(freq_Dev) as freqDev,sum(v_Rms) as vRms,sum(v_Pos) as vPos,sum(v_Neg) as vNeg," +
|
||||
"sum(v_Zero) as vZero,sum(v_Unbalance) as vUnbalance,sum(rms_Lvr) as rmsLvr,sum(vu_Dev) as vuDev,sum(vl_Dev) as vlDev," +
|
||||
"sum(v_Thd) as vThd,sum(v) as v,sum(i_Rms) as iRms,sum(plt) as plt,sum(v_Inharm) as vInharm,sum(v_Harm) as vHarm,sum(pf) as pf," +
|
||||
"sum(v_Phasic) as vPhasic,sum(v1_Phasic) as v1Phasic,sum(fluc) as fluc,sum(pst) as pst,sum(state) as state")
|
||||
"sum(v_Phasic) as vPhasic,sum(v1_Phasic) as v1Phasic,sum(fluc) as fluc,sum(pst) as pst,sum(dip) as dip,sum(rise) as rise,sum(state) as state")
|
||||
.lambda().between(PqDataVerifyBak::getTimeId, DateUtil.beginOfDay(DateUtil.parse(monitorBaseParam.getSearchBeginTime())), DateUtil.endOfDay(DateUtil.parse(monitorBaseParam.getSearchEndTime())))
|
||||
.in(PqDataVerifyBak::getLineId, monitorIds)
|
||||
.eq(PqDataVerifyBak::getState, 1)
|
||||
@@ -661,6 +654,14 @@ public class PqDataVerifyBakServiceImpl extends ServiceImpl<PqDataVerifyBakMappe
|
||||
ids = dataVerifyList.stream().filter(it -> it.getPf() > 0).map(PqDataVerifyBak::getLineId).collect(Collectors.toSet());
|
||||
assembleEntity(ids, dto, result);
|
||||
break;
|
||||
case Param.Voltage_Dip:
|
||||
ids = dataVerifyList.stream().filter(it -> it.getDip() > 0).map(PqDataVerifyBak::getLineId).collect(Collectors.toSet());
|
||||
assembleEntity(ids, dto, result);
|
||||
break;
|
||||
case Param.Voltage_Rise:
|
||||
ids = dataVerifyList.stream().filter(it -> it.getRise() > 0).map(PqDataVerifyBak::getLineId).collect(Collectors.toSet());
|
||||
assembleEntity(ids, dto, result);
|
||||
break;
|
||||
default:
|
||||
log.error("未匹配到异常数据指标");
|
||||
break;
|
||||
|
||||
@@ -9,18 +9,17 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.bpm.utils.CollectionUtils;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.device.device.service.IDeviceService;
|
||||
import com.njcn.device.device.service.PqDevTypeService;
|
||||
import com.njcn.device.line.mapper.LineMapper;
|
||||
import com.njcn.device.pms.enums.PmsDeviceResponseEnum;
|
||||
import com.njcn.device.pq.constant.Param;
|
||||
import com.njcn.device.pq.mapper.LineMapper;
|
||||
import com.njcn.device.pq.mapper.PqsTerminalLogsMapper;
|
||||
import com.njcn.device.pq.pojo.dto.PqIcdPathDTO;
|
||||
import com.njcn.device.pq.pojo.param.PqIcdPathParam;
|
||||
import com.njcn.device.pq.pojo.po.*;
|
||||
import com.njcn.device.pq.service.IDeviceService;
|
||||
import com.njcn.device.pq.service.PqDevTypeService;
|
||||
import com.njcn.device.terminal.mapper.PqsTerminalLogsMapper;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.enums.DicDataTypeEnum;
|
||||
@@ -59,7 +58,7 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
|
||||
private final IDeviceService deviceService;
|
||||
private final PqsTerminalLogsMapper pqsTerminalLogsMapper;
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
private final LineMapper lineMapper;
|
||||
private final LineMapper lineMapper;
|
||||
|
||||
@Override
|
||||
public List<PqIcdPathDTO> icdPathList(List<String> devType) {
|
||||
@@ -152,9 +151,9 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
|
||||
icdPath.setPath(param.getFilePath());
|
||||
//查询绑定的icd的设备型号
|
||||
List<PqDevType> pqDevTypeList = devTypeService.lambdaQuery().eq(PqDevType::getIcdId, param.getId()).eq(PqDevType::getState, 1).list();
|
||||
if(!CollectionUtil.isEmpty(pqDevTypeList)) {
|
||||
if (!CollectionUtil.isEmpty(pqDevTypeList)) {
|
||||
List<String> collect = pqDevTypeList.stream().map(PqDevType::getId).collect(Collectors.toList());
|
||||
List<Device> list = deviceService.lambdaQuery().in(Device::getDevType,collect).eq(Device::getRunFlag, 0).list();
|
||||
List<Device> list = deviceService.lambdaQuery().in(Device::getDevType, collect).eq(Device::getRunFlag, 0).list();
|
||||
list.forEach(temp -> {
|
||||
//记录日志
|
||||
DictData dataDic = dicDataFeignClient.getDicDataByCodeAndType(DicDataEnum.DEV_PARAMETER.getCode(), DicDataTypeEnum.DEV_OPS.getCode()).getData();
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.njcn.device.pq.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.device.line.mapper.LineMapper;
|
||||
import com.njcn.device.pq.enums.LineBaseEnum;
|
||||
import com.njcn.device.pq.mapper.LineMapper;
|
||||
import com.njcn.device.pq.mapper.PqsDeviceUnitMapper;
|
||||
import com.njcn.device.pq.pojo.po.Line;
|
||||
import com.njcn.device.biz.pojo.po.PqsDeviceUnit;
|
||||
|
||||
@@ -11,7 +11,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.device.pq.mapper.LineMapper;
|
||||
import com.njcn.device.line.mapper.LineMapper;
|
||||
import com.njcn.device.pq.mapper.PqsLineWeightMapper;
|
||||
import com.njcn.device.pq.pojo.param.TerminalMainQueryParam;
|
||||
import com.njcn.device.pq.pojo.po.PqsLineWeight;
|
||||
@@ -19,7 +19,7 @@ import com.njcn.device.pq.pojo.vo.PqsLineWeightVo;
|
||||
import com.njcn.device.pq.pojo.vo.TerminalTree;
|
||||
import com.njcn.device.pq.service.IPqsLineWeightService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.device.pq.utils.ExcelStyleUtil;
|
||||
import com.njcn.device.utils.ExcelStyleUtil;
|
||||
import com.njcn.poi.excel.ExcelUtil;
|
||||
import com.njcn.poi.util.PoiUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -8,10 +8,11 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.device.line.mapper.LineMapper;
|
||||
import com.njcn.device.pq.enums.LineBaseEnum;
|
||||
import com.njcn.device.pq.enums.PvDeviceResponseEnum;
|
||||
import com.njcn.device.pq.mapper.LineMapper;
|
||||
import com.njcn.device.pq.mapper.PqsTflgassMapper;
|
||||
import com.njcn.device.pq.mapper.PqsTransformerMapper;
|
||||
import com.njcn.device.pq.pojo.dto.transformer.EntityLogicDTO;
|
||||
@@ -176,9 +177,9 @@ public class PqsTransformerServiceImpl extends ServiceImpl<PqsTransformerMapper,
|
||||
.eq(PqsTflgass::getLogicNext, param.getDownNode())
|
||||
)
|
||||
);
|
||||
if(ObjectUtil.isNotNull(tflgass)){
|
||||
if (ObjectUtil.isNotNull(tflgass)) {
|
||||
throw new BusinessException(PvDeviceResponseEnum.TRANSFORMER_NAME_REPEAT);
|
||||
}else{
|
||||
} else {
|
||||
fly = iPqsTflgassService.save(ass);
|
||||
}
|
||||
|
||||
@@ -198,59 +199,182 @@ public class PqsTransformerServiceImpl extends ServiceImpl<PqsTransformerMapper,
|
||||
PqsTflgass one = iPqsTflgassService.getOne(new LambdaQueryWrapper<PqsTflgass>()
|
||||
.eq(PqsTflgass::getTfIndex, id));
|
||||
|
||||
//1.获取当前变电站下,所拥有的母线条数
|
||||
List<TerminalTree> downVoltage = lineMapper.getvoltage(subId, 1);
|
||||
//获取母线id
|
||||
List<String> ids = downVoltage.stream().map(TerminalTree::getId).collect(Collectors.toList());
|
||||
//查询节点是否绑定
|
||||
List<PqsTflgass> pqsTflgasses = pqsTflgassMapper.selectFlgass(subId, ids);
|
||||
|
||||
|
||||
String[][] arr = new String[pqsTflgasses.size()][2];
|
||||
if (CollUtil.isNotEmpty(pqsTflgasses) && ids.size() > 2) {
|
||||
for (int i = 0; i < pqsTflgasses.size(); i++) {
|
||||
arr[i][0] = pqsTflgasses.get(i).getLogicBefore();
|
||||
arr[i][1] = pqsTflgasses.get(i).getLogicNext();
|
||||
}
|
||||
|
||||
List<String> arr = new ArrayList<>();
|
||||
if (Objects.nonNull(one)) {
|
||||
arr.add(one.getLogicBefore());
|
||||
arr.add(one.getLogicNext());
|
||||
}
|
||||
voltage.put("bind", arr);
|
||||
|
||||
Stream<String> beforeStream = pqsTflgasses.stream().map(PqsTflgass::getLogicBefore);
|
||||
Stream<String> nextStream = pqsTflgasses.stream().map(PqsTflgass::getLogicNext);
|
||||
//合并节点,要是母线都存在,说明是跨变电站,反之是本变电站
|
||||
List<String> merge = Stream.concat(beforeStream, nextStream)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
//查看已经绑定的母线
|
||||
List<String> bindList = merge.stream().filter(x -> ids.contains(x)).collect(Collectors.toList());
|
||||
|
||||
//绑定母线,如有绑定的母线下不存在这个母线,说明是有跨变电站数据,则新增母线节点,为最底层节点往后,拼接
|
||||
List<String> straddleList = merge.stream().filter(x -> !ids.contains(x)).collect(Collectors.toList());
|
||||
//判断当前母线下是否还存在,没绑定节点
|
||||
List<String> not = ids.stream().filter(x -> !bindList.contains(x)).collect(Collectors.toList());
|
||||
//1.获取当前变电站下,所拥有的母线条数
|
||||
List<TerminalTree> downVoltage = lineMapper.getvoltage(subId, 1);
|
||||
if(CollUtil.isNotEmpty(arr)) {
|
||||
downVoltage.forEach(item->{
|
||||
if(Objects.equals(item.getId(),arr.get(1))){
|
||||
item.setLevel(LineBaseEnum.SUB_V_LEVEL.getCode());
|
||||
}
|
||||
});
|
||||
}
|
||||
//获取所有母线层级
|
||||
List<Line> UpBusList = lineMapper.selectList(new LambdaQueryWrapper<Line>().eq(Line::getLevel, LineBaseEnum.SUB_V_LEVEL.getCode()).eq(Line::getState, DataStateEnum.ENABLE.getCode()).orderByAsc(Line::getSort));
|
||||
List<TerminalTree> upTreeList = UpBusList.stream().map(it -> {
|
||||
TerminalTree terminalTree = new TerminalTree();
|
||||
terminalTree.setId(it.getId());
|
||||
terminalTree.setName(it.getName());
|
||||
terminalTree.setPid(it.getPids().split(StrUtil.COMMA)[LineBaseEnum.SUB_LEVEL.getCode()]);
|
||||
terminalTree.setSort(it.getSort());
|
||||
if(CollUtil.isNotEmpty(arr)) {
|
||||
if (it.getId().equals(arr.get(0))) {
|
||||
terminalTree.setLevel(LineBaseEnum.SUB_V_LEVEL.getCode());
|
||||
}
|
||||
}
|
||||
return terminalTree;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
|
||||
//获取母线id
|
||||
//List<String> ids = downVoltage.stream().map(TerminalTree::getId).collect(Collectors.toList());
|
||||
|
||||
List<TerminalTree> upList = TreedChildren(upTreeList, "变压器上节点设备树", subId);
|
||||
voltage.put("upNode", upList);
|
||||
List<TerminalTree> downList = TreedChildren(downVoltage, "变压器下节点设备树", subId);
|
||||
voltage.put("downNode", downList);
|
||||
return voltage;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public Map<String, Object> getGeneratrixOld(String subId, String id) {
|
||||
Map<String, Object> voltage = new HashMap<>();
|
||||
//先判断当前,变电站是否已添加了节点
|
||||
PqsTflgass one = iPqsTflgassService.getOne(new LambdaQueryWrapper<PqsTflgass>()
|
||||
.eq(PqsTflgass::getTfIndex, id));
|
||||
|
||||
//1.获取当前变电站下,所拥有的母线条数
|
||||
List<TerminalTree> downVoltage = lineMapper.getvoltage(subId, 1);
|
||||
//获取母线id
|
||||
List<String> ids = downVoltage.stream().map(TerminalTree::getId).collect(Collectors.toList());
|
||||
//查询节点是否绑定
|
||||
List<PqsTflgass> pqsTflgasses = pqsTflgassMapper.selectFlgass(subId, ids);
|
||||
|
||||
|
||||
String[][] arr = new String[pqsTflgasses.size()][2];
|
||||
if (CollUtil.isNotEmpty(pqsTflgasses) && ids.size() > 2) {
|
||||
for (int i = 0; i < pqsTflgasses.size(); i++) {
|
||||
arr[i][0] = pqsTflgasses.get(i).getLogicBefore();
|
||||
arr[i][1] = pqsTflgasses.get(i).getLogicNext();
|
||||
}
|
||||
|
||||
}
|
||||
voltage.put("bind", arr);
|
||||
|
||||
Stream<String> beforeStream = pqsTflgasses.stream().map(PqsTflgass::getLogicBefore);
|
||||
Stream<String> nextStream = pqsTflgasses.stream().map(PqsTflgass::getLogicNext);
|
||||
//合并节点,要是母线都存在,说明是跨变电站,反之是本变电站
|
||||
List<String> merge = Stream.concat(beforeStream, nextStream)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
//查看已经绑定的母线
|
||||
List<String> bindList = merge.stream().filter(x -> ids.contains(x)).collect(Collectors.toList());
|
||||
|
||||
//绑定母线,如有绑定的母线下不存在这个母线,说明是有跨变电站数据,则新增母线节点,为最底层节点往后,拼接
|
||||
List<String> straddleList = merge.stream().filter(x -> !ids.contains(x)).collect(Collectors.toList());
|
||||
//判断当前母线下是否还存在,没绑定节点
|
||||
List<String> not = ids.stream().filter(x -> !bindList.contains(x)).collect(Collectors.toList());
|
||||
|
||||
|
||||
/**
|
||||
* 当母线节点+1等于去重之后的绑定节点说明,节点已经全部绑定了
|
||||
*
|
||||
* 跨变电站
|
||||
* 1.1当母线小于俩条时为跨
|
||||
* 1.2当都所有节点都绑定时,只有最起始节点为跨
|
||||
* 本变电站
|
||||
* 1.1当有俩条时或者大于俩条时时为本
|
||||
* 1.2当已绑定有跨变电站时,则上节点为最底层节点母线,下节点为没绑定的母线信息
|
||||
*/
|
||||
|
||||
|
||||
if (ObjectUtil.isNotNull(one)) {
|
||||
List<String> collect = ids.stream().filter(x -> x.equals(one.getLogicBefore())).collect(Collectors.toList());
|
||||
/**
|
||||
* 当母线节点+1等于去重之后的绑定节点说明,节点已经全部绑定了
|
||||
*
|
||||
* 跨变电站
|
||||
* 1.1当母线小于俩条时为跨
|
||||
* 1.2当都所有节点都绑定时,只有最起始节点为跨
|
||||
* 本变电站
|
||||
* 1.1当有俩条时或者大于俩条时时为本
|
||||
* 1.2当已绑定有跨变电站时,则上节点为最底层节点母线,下节点为没绑定的母线信息
|
||||
* 本
|
||||
* 1.当母线大于俩条
|
||||
* 2.当所有母线没有绑定是
|
||||
*/
|
||||
if (collect.size() > 0) {
|
||||
List<TerminalTree> upVOList;
|
||||
if (straddleList.size() > 0 && not.size() > 0) {
|
||||
String s = mostNext(pqsTflgasses);
|
||||
upVOList = downVoltage.stream().filter(x -> s.equals(x.getId())).collect(Collectors.toList());
|
||||
} else {
|
||||
//上节点id
|
||||
List<String> upIDs = pqsTflgasses.stream().map(PqsTflgass::getLogicBefore).collect(Collectors.toList());
|
||||
upVOList = downVoltage.stream().filter(x -> !upIDs.contains(x.getId())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
//下节点id
|
||||
List<String> downIDs = pqsTflgasses.stream().map(PqsTflgass::getLogicNext).collect(Collectors.toList());
|
||||
List<TerminalTree> downVOList = downVoltage.stream().filter(x -> !downIDs.contains(x.getId())).collect(Collectors.toList());
|
||||
|
||||
if (ObjectUtil.isNotNull(one)) {
|
||||
List<String> collect = ids.stream().filter(x -> x.equals(one.getLogicBefore())).collect(Collectors.toList());
|
||||
/**
|
||||
* 本
|
||||
* 1.当母线大于俩条
|
||||
* 2.当所有母线没有绑定是
|
||||
*/
|
||||
if (collect.size() > 0) {
|
||||
if (ObjectUtil.isNotNull(one)) {
|
||||
TerminalTree beforeTree = addTree(one.getLogicBefore());
|
||||
TerminalTree nextTree = addTree(one.getLogicNext());
|
||||
upVOList.add(beforeTree);
|
||||
downVOList.add(nextTree);
|
||||
}
|
||||
List<TerminalTree> upList = TreedChildren(upVOList, "变压器上节点设备树", subId);
|
||||
voltage.put("upNode", upList);
|
||||
List<TerminalTree> downList = TreedChildren(downVOList, "变压器下节点设备树", subId);
|
||||
voltage.put("downNode", downList);
|
||||
return voltage;
|
||||
} else {
|
||||
//查询所有变电站下母线信息
|
||||
List<TerminalTree> upVoltage = lineMapper.getvoltage(subId, 0);
|
||||
if (merge.size() == ids.size()) {
|
||||
String s = mostBefore(pqsTflgasses);
|
||||
downVoltage = downVoltage.stream().filter(x -> x.getId().equals(s)).collect(Collectors.toList());
|
||||
|
||||
}
|
||||
if (ObjectUtil.isNotNull(one)) {
|
||||
TerminalTree beforeTree = addTree(one.getLogicBefore());
|
||||
TerminalTree nextTree = addTree(one.getLogicNext());
|
||||
upVoltage = upVoltage.stream().filter(x -> !x.getId().equals(beforeTree.getId())).collect(Collectors.toList());
|
||||
upVoltage.add(beforeTree);
|
||||
|
||||
downVoltage.clear();
|
||||
downVoltage.add(nextTree);
|
||||
}
|
||||
List<TerminalTree> upList = TreedChildren(upVoltage, "变压器上节点设备树", null);
|
||||
voltage.put("upNode", upList);
|
||||
List<TerminalTree> downList = TreedChildren(downVoltage, "变压器下节点设备树", subId);
|
||||
voltage.put("downNode", downList);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
} else {
|
||||
//判断是否已经全部绑定
|
||||
String chain = chain(pqsTflgasses);
|
||||
String chain2 = chain2(pqsTflgasses);
|
||||
if (StrUtil.isNotBlank(chain) && not.size() == 0 && pqsTflgasses.size() + 1 != ids.size() && straddleList.size() == 0
|
||||
|| StrUtil.isNotBlank(chain2) && not.size() == 0 && pqsTflgasses.size() + 1 != ids.size() && straddleList.size() == 0) {
|
||||
List<String> logicBefore = pqsTflgasses.stream().map(PqsTflgass::getLogicBefore).collect(Collectors.toList());
|
||||
List<String> logicNext = pqsTflgasses.stream().map(PqsTflgass::getLogicNext).collect(Collectors.toList());
|
||||
List<TerminalTree> up = downVoltage.stream().filter(x -> !logicBefore.contains(x.getId())).collect(Collectors.toList());
|
||||
List<TerminalTree> upList = TreedChildren(up, "变压器上节点设备树", subId);
|
||||
voltage.put("upNode", upList);
|
||||
|
||||
List<TerminalTree> down = downVoltage.stream().filter(x -> !logicNext.contains(x.getId())).collect(Collectors.toList());
|
||||
List<TerminalTree> downList = TreedChildren(down, "变压器下节点设备树", subId);
|
||||
voltage.put("downNode", downList);
|
||||
return voltage;
|
||||
} else {
|
||||
if (downVoltage.size() > 1 && straddleList.size() == 0 && bindList.size() != ids.size()
|
||||
|| straddleList.size() > 0 && not.size() > 0
|
||||
|
||||
) {
|
||||
List<TerminalTree> upVOList;
|
||||
if (straddleList.size() > 0 && not.size() > 0) {
|
||||
String s = mostNext(pqsTflgasses);
|
||||
@@ -263,20 +387,24 @@ public class PqsTransformerServiceImpl extends ServiceImpl<PqsTransformerMapper,
|
||||
|
||||
//下节点id
|
||||
List<String> downIDs = pqsTflgasses.stream().map(PqsTflgass::getLogicNext).collect(Collectors.toList());
|
||||
List<TerminalTree> downVOList = downVoltage.stream().filter(x -> !downIDs.contains(x.getId())).collect(Collectors.toList());
|
||||
|
||||
if (ObjectUtil.isNotNull(one)) {
|
||||
TerminalTree beforeTree = addTree(one.getLogicBefore());
|
||||
TerminalTree nextTree = addTree(one.getLogicNext());
|
||||
upVOList.add(beforeTree);
|
||||
downVOList.add(nextTree);
|
||||
List<TerminalTree> downVOList = downVoltage.stream().filter(x -> !downIDs.contains(x.getId())).collect(Collectors.toList());
|
||||
if (not.size() == 1) {
|
||||
List<String> logicBefore = pqsTflgasses.stream().map(PqsTflgass::getLogicBefore).collect(Collectors.toList());
|
||||
downVOList = downVOList.stream().filter(x -> !logicBefore.contains(x.getId())).collect(Collectors.toList());
|
||||
}
|
||||
List<TerminalTree> upList = TreedChildren(upVOList, "变压器上节点设备树", subId);
|
||||
voltage.put("upNode", upList);
|
||||
List<TerminalTree> downList = TreedChildren(downVOList, "变压器下节点设备树", subId);
|
||||
voltage.put("downNode", downList);
|
||||
return voltage;
|
||||
} else {
|
||||
}
|
||||
|
||||
/**
|
||||
* 跨
|
||||
* 1.当母线小于2条跨
|
||||
* 2.当所有母线都绑定为跨
|
||||
*/
|
||||
else {
|
||||
//查询所有变电站下母线信息
|
||||
List<TerminalTree> upVoltage = lineMapper.getvoltage(subId, 0);
|
||||
if (merge.size() == ids.size()) {
|
||||
@@ -284,304 +412,231 @@ public class PqsTransformerServiceImpl extends ServiceImpl<PqsTransformerMapper,
|
||||
downVoltage = downVoltage.stream().filter(x -> x.getId().equals(s)).collect(Collectors.toList());
|
||||
|
||||
}
|
||||
if (ObjectUtil.isNotNull(one)) {
|
||||
TerminalTree beforeTree = addTree(one.getLogicBefore());
|
||||
TerminalTree nextTree = addTree(one.getLogicNext());
|
||||
upVoltage = upVoltage.stream().filter(x -> !x.getId().equals(beforeTree.getId())).collect(Collectors.toList());
|
||||
upVoltage.add(beforeTree);
|
||||
//下节点id
|
||||
List<String> downIDs = pqsTflgasses.stream().map(PqsTflgass::getLogicNext).collect(Collectors.toList());
|
||||
List<TerminalTree> downVOList = downVoltage.stream().filter(x -> !downIDs.contains(x.getId())).collect(Collectors.toList());
|
||||
|
||||
downVoltage.clear();
|
||||
downVoltage.add(nextTree);
|
||||
}
|
||||
List<TerminalTree> upList = TreedChildren(upVoltage, "变压器上节点设备树", null);
|
||||
voltage.put("upNode", upList);
|
||||
List<TerminalTree> downList = TreedChildren(downVoltage, "变压器下节点设备树", subId);
|
||||
List<TerminalTree> downList = TreedChildren(downVOList, "变压器下节点设备树", subId);
|
||||
voltage.put("downNode", downList);
|
||||
return voltage;
|
||||
}
|
||||
}
|
||||
}
|
||||
return voltage;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<TerminalTree> getTransformerTree() {
|
||||
List<TerminalTree> terminalTrees = this.baseMapper.listTransformer();
|
||||
return TreedChildren(terminalTrees, "变压器设备树", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntityLogicDTO> getLogic() {
|
||||
return pqsTflgassMapper.getLogic();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部子节点
|
||||
*
|
||||
* @author cdf
|
||||
* @date 2021/7/19
|
||||
*/
|
||||
public List<TerminalTree> getChildren(TerminalTree item, List<TerminalTree> all) {
|
||||
return all.stream().filter(allItem -> allItem.getPid().equals(item.getId())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化设备树
|
||||
*
|
||||
* @param children 子节点
|
||||
* @param name 节点名称
|
||||
* @param subId 不为空则只展示,当前变电站节点的信息,为空则展示所有信息
|
||||
* @return
|
||||
*/
|
||||
public List<TerminalTree> TreedChildren(List<TerminalTree> children, String name, String subId) {
|
||||
List<TerminalTree> taiZhang = new ArrayList<>();
|
||||
List<TerminalTree> allList = lineMapper.getAllList();
|
||||
|
||||
List<TerminalTree> gdList;
|
||||
List<TerminalTree> subList;
|
||||
List<TerminalTree> provinceList;
|
||||
if (StrUtil.isBlank(subId)) {
|
||||
subList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.SUB_LEVEL.getCode())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
gdList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.GD_LEVEL.getCode())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
provinceList = lineMapper.getProvinceList(null, 0);
|
||||
} else {
|
||||
subList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.SUB_LEVEL.getCode())
|
||||
&& item.getId().equals(subId)
|
||||
).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
gdList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.GD_LEVEL.getCode())
|
||||
&& item.getId().equals(subList.get(0).getPid())
|
||||
).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
provinceList = lineMapper.getProvinceList(Arrays.asList(gdList.get(0).getPid()), 1);
|
||||
}
|
||||
List<TerminalTree> terminal = children.stream().sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
|
||||
subList.forEach(sub -> sub.setChildren(getChildren(sub, terminal)));
|
||||
gdList.forEach(gd -> gd.setChildren(getChildren(gd, subList)));
|
||||
provinceList.forEach(province -> province.setChildren(getChildren(province, gdList)));
|
||||
|
||||
if (CollectionUtil.isNotEmpty(allList)) {
|
||||
TerminalTree terminalTree = new TerminalTree();
|
||||
terminalTree.setId("9999999");
|
||||
terminalTree.setLevel(0);
|
||||
terminalTree.setName(name);
|
||||
if (CollectionUtil.isNotEmpty(provinceList)) {
|
||||
terminalTree.setChildren(provinceList);
|
||||
}
|
||||
taiZhang.add(terminalTree);
|
||||
}
|
||||
return taiZhang;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找最顶层节点信息
|
||||
*
|
||||
* @param pqsTflgasses
|
||||
* @return
|
||||
*/
|
||||
private static String mostBefore(List<PqsTflgass> pqsTflgasses) {
|
||||
String logicBefore = null;
|
||||
for (PqsTflgass pqsTflgass : pqsTflgasses) {
|
||||
//根据获取的的上节点判断是否存在,这上节点是否是尾节点
|
||||
if (ObjectUtil.isNull(logicBefore)) {
|
||||
logicBefore = pqsTflgass.getLogicBefore();
|
||||
} else {
|
||||
//判断是否已经全部绑定
|
||||
String chain = chain(pqsTflgasses);
|
||||
String chain2 = chain2(pqsTflgasses);
|
||||
if (StrUtil.isNotBlank(chain) && not.size() == 0&& pqsTflgasses.size()+1!=ids.size()&&straddleList.size()==0
|
||||
|| StrUtil.isNotBlank(chain2) && not.size() == 0&& pqsTflgasses.size()+1!=ids.size()&&straddleList.size()==0) {
|
||||
List<String> logicBefore = pqsTflgasses.stream().map(PqsTflgass::getLogicBefore).collect(Collectors.toList());
|
||||
List<String> logicNext = pqsTflgasses.stream().map(PqsTflgass::getLogicNext).collect(Collectors.toList());
|
||||
List<TerminalTree> up = downVoltage.stream().filter(x -> !logicBefore.contains(x.getId())).collect(Collectors.toList());
|
||||
List<TerminalTree> upList = TreedChildren(up, "变压器上节点设备树", subId);
|
||||
voltage.put("upNode", upList);
|
||||
|
||||
List<TerminalTree> down = downVoltage.stream().filter(x -> !logicNext.contains(x.getId())).collect(Collectors.toList());
|
||||
List<TerminalTree> downList = TreedChildren(down, "变压器下节点设备树", subId);
|
||||
voltage.put("downNode", downList);
|
||||
return voltage;
|
||||
} else {
|
||||
if (downVoltage.size() > 1 && straddleList.size() == 0 && bindList.size() != ids.size()
|
||||
|| straddleList.size() > 0 && not.size() > 0
|
||||
|
||||
) {
|
||||
List<TerminalTree> upVOList;
|
||||
if (straddleList.size() > 0 && not.size() > 0) {
|
||||
String s = mostNext(pqsTflgasses);
|
||||
upVOList = downVoltage.stream().filter(x -> s.equals(x.getId())).collect(Collectors.toList());
|
||||
while (true) {
|
||||
for (int i1 = 0; i1 < pqsTflgasses.size(); i1++) {
|
||||
String logicNext = pqsTflgasses.get(i1).getLogicNext();
|
||||
if (logicBefore.equals(logicNext)) {
|
||||
logicBefore = pqsTflgasses.get(i1).getLogicBefore();
|
||||
break;
|
||||
} else {
|
||||
//上节点id
|
||||
List<String> upIDs = pqsTflgasses.stream().map(PqsTflgass::getLogicBefore).collect(Collectors.toList());
|
||||
upVOList = downVoltage.stream().filter(x -> !upIDs.contains(x.getId())).collect(Collectors.toList());
|
||||
if (i1 == pqsTflgasses.size()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//下节点id
|
||||
List<String> downIDs = pqsTflgasses.stream().map(PqsTflgass::getLogicNext).collect(Collectors.toList());
|
||||
|
||||
List<TerminalTree> downVOList = downVoltage.stream().filter(x -> !downIDs.contains(x.getId())).collect(Collectors.toList());
|
||||
if(not.size() ==1){
|
||||
List<String> logicBefore = pqsTflgasses.stream().map(PqsTflgass::getLogicBefore).collect(Collectors.toList());
|
||||
downVOList = downVOList.stream().filter(x -> !logicBefore.contains(x.getId())).collect(Collectors.toList());
|
||||
}
|
||||
List<TerminalTree> upList = TreedChildren(upVOList, "变压器上节点设备树", subId);
|
||||
voltage.put("upNode", upList);
|
||||
List<TerminalTree> downList = TreedChildren(downVOList, "变压器下节点设备树", subId);
|
||||
voltage.put("downNode", downList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 跨
|
||||
* 1.当母线小于2条跨
|
||||
* 2.当所有母线都绑定为跨
|
||||
*/
|
||||
else {
|
||||
//查询所有变电站下母线信息
|
||||
List<TerminalTree> upVoltage = lineMapper.getvoltage(subId, 0);
|
||||
if (merge.size() == ids.size()) {
|
||||
String s = mostBefore(pqsTflgasses);
|
||||
downVoltage = downVoltage.stream().filter(x -> x.getId().equals(s)).collect(Collectors.toList());
|
||||
|
||||
}
|
||||
//下节点id
|
||||
List<String> downIDs = pqsTflgasses.stream().map(PqsTflgass::getLogicNext).collect(Collectors.toList());
|
||||
List<TerminalTree> downVOList = downVoltage.stream().filter(x -> !downIDs.contains(x.getId())).collect(Collectors.toList());
|
||||
|
||||
List<TerminalTree> upList = TreedChildren(upVoltage, "变压器上节点设备树", null);
|
||||
voltage.put("upNode", upList);
|
||||
List<TerminalTree> downList = TreedChildren(downVOList, "变压器下节点设备树", subId);
|
||||
voltage.put("downNode", downList);
|
||||
return voltage;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return voltage;
|
||||
}
|
||||
return logicBefore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TerminalTree> getTransformerTree() {
|
||||
List<TerminalTree> terminalTrees = this.baseMapper.listTransformer();
|
||||
return TreedChildren(terminalTrees, "变压器设备树", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntityLogicDTO> getLogic() {
|
||||
return pqsTflgassMapper.getLogic();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部子节点
|
||||
*
|
||||
* @author cdf
|
||||
* @date 2021/7/19
|
||||
*/
|
||||
public List<TerminalTree> getChildren(TerminalTree item, List<TerminalTree> all) {
|
||||
return all.stream().filter(allItem -> allItem.getPid().equals(item.getId())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化设备树
|
||||
*
|
||||
* @param children 子节点
|
||||
* @param name 节点名称
|
||||
* @param subId 不为空则只展示,当前变电站节点的信息,为空则展示所有信息
|
||||
* @return
|
||||
*/
|
||||
public List<TerminalTree> TreedChildren(List<TerminalTree> children, String name, String subId) {
|
||||
List<TerminalTree> taiZhang = new ArrayList<>();
|
||||
List<TerminalTree> allList = lineMapper.getAllList();
|
||||
|
||||
List<TerminalTree> gdList;
|
||||
List<TerminalTree> subList;
|
||||
List<TerminalTree> provinceList;
|
||||
if (StrUtil.isBlank(subId)) {
|
||||
subList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.SUB_LEVEL.getCode())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
gdList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.GD_LEVEL.getCode())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
provinceList = lineMapper.getProvinceList(null, 0);
|
||||
/**
|
||||
* 查找最底层节点信息
|
||||
*
|
||||
* @param pqsTflgasses
|
||||
* @return
|
||||
*/
|
||||
private static String mostNext(List<PqsTflgass> pqsTflgasses) {
|
||||
String logicNext = null;
|
||||
for (PqsTflgass pqsTflgass : pqsTflgasses) {
|
||||
//根据获取的的上节点判断是否存在,这上节点是否是尾节点
|
||||
if (ObjectUtil.isNull(logicNext)) {
|
||||
logicNext = pqsTflgass.getLogicNext();
|
||||
} else {
|
||||
subList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.SUB_LEVEL.getCode())
|
||||
&& item.getId().equals(subId)
|
||||
).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
gdList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.GD_LEVEL.getCode())
|
||||
&& item.getId().equals(subList.get(0).getPid())
|
||||
).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
provinceList = lineMapper.getProvinceList(Arrays.asList(gdList.get(0).getPid()), 1);
|
||||
}
|
||||
List<TerminalTree> terminal = children.stream().sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
|
||||
subList.forEach(sub -> sub.setChildren(getChildren(sub, terminal)));
|
||||
gdList.forEach(gd -> gd.setChildren(getChildren(gd, subList)));
|
||||
provinceList.forEach(province -> province.setChildren(getChildren(province, gdList)));
|
||||
|
||||
if (CollectionUtil.isNotEmpty(allList)) {
|
||||
TerminalTree terminalTree = new TerminalTree();
|
||||
terminalTree.setId("9999999");
|
||||
terminalTree.setLevel(0);
|
||||
terminalTree.setName(name);
|
||||
if (CollectionUtil.isNotEmpty(provinceList)) {
|
||||
terminalTree.setChildren(provinceList);
|
||||
}
|
||||
taiZhang.add(terminalTree);
|
||||
}
|
||||
return taiZhang;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找最顶层节点信息
|
||||
*
|
||||
* @param pqsTflgasses
|
||||
* @return
|
||||
*/
|
||||
private static String mostBefore(List<PqsTflgass> pqsTflgasses) {
|
||||
String logicBefore = null;
|
||||
for (PqsTflgass pqsTflgass : pqsTflgasses) {
|
||||
//根据获取的的上节点判断是否存在,这上节点是否是尾节点
|
||||
if (ObjectUtil.isNull(logicBefore)) {
|
||||
logicBefore = pqsTflgass.getLogicBefore();
|
||||
} else {
|
||||
while (true) {
|
||||
for (int i1 = 0; i1 < pqsTflgasses.size(); i1++) {
|
||||
String logicNext = pqsTflgasses.get(i1).getLogicNext();
|
||||
if (logicBefore.equals(logicNext)) {
|
||||
logicBefore = pqsTflgasses.get(i1).getLogicBefore();
|
||||
while (true) {
|
||||
for (int i1 = 0; i1 < pqsTflgasses.size(); i1++) {
|
||||
String logicBefore = pqsTflgasses.get(i1).getLogicBefore();
|
||||
if (logicNext.equals(logicBefore)) {
|
||||
logicNext = pqsTflgasses.get(i1).getLogicNext();
|
||||
break;
|
||||
} else {
|
||||
if (i1 == pqsTflgasses.size()) {
|
||||
break;
|
||||
} else {
|
||||
if (i1 == pqsTflgasses.size()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return logicBefore;
|
||||
}
|
||||
return logicNext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找最底层节点信息
|
||||
*
|
||||
* @param pqsTflgasses
|
||||
* @return
|
||||
*/
|
||||
private static String mostNext(List<PqsTflgass> pqsTflgasses) {
|
||||
String logicNext = null;
|
||||
for (PqsTflgass pqsTflgass : pqsTflgasses) {
|
||||
//根据获取的的上节点判断是否存在,这上节点是否是尾节点
|
||||
if (ObjectUtil.isNull(logicNext)) {
|
||||
logicNext = pqsTflgass.getLogicNext();
|
||||
} else {
|
||||
while (true) {
|
||||
for (int i1 = 0; i1 < pqsTflgasses.size(); i1++) {
|
||||
String logicBefore = pqsTflgasses.get(i1).getLogicBefore();
|
||||
if (logicNext.equals(logicBefore)) {
|
||||
logicNext = pqsTflgasses.get(i1).getLogicNext();
|
||||
break;
|
||||
} else {
|
||||
if (i1 == pqsTflgasses.size()) {
|
||||
break;
|
||||
}
|
||||
/**
|
||||
* 判断是否已经成为链行
|
||||
*
|
||||
* @param pqsTflgasses
|
||||
* @return
|
||||
*/
|
||||
private static String chain(List<PqsTflgass> pqsTflgasses) {
|
||||
if (pqsTflgasses.size() < 2) {
|
||||
return null;
|
||||
}
|
||||
String logicNext = null;
|
||||
for (PqsTflgass pqsTflgass : pqsTflgasses) {
|
||||
//根据获取的的下节点判断是否存在,这下节点是否是首节点
|
||||
if (ObjectUtil.isNull(logicNext)) {
|
||||
logicNext = pqsTflgass.getLogicNext();
|
||||
} else {
|
||||
while (true) {
|
||||
for (int i1 = 0; i1 < pqsTflgasses.size(); i1++) {
|
||||
String logicBefore = pqsTflgasses.get(i1).getLogicBefore();
|
||||
if (logicNext.equals(logicBefore)) {
|
||||
logicNext = pqsTflgasses.get(i1).getLogicNext();
|
||||
break;
|
||||
} else {
|
||||
if (i1 == pqsTflgasses.size() - 1) {
|
||||
return logicNext;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return logicNext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否已经成为链行
|
||||
*
|
||||
* @param pqsTflgasses
|
||||
* @return
|
||||
*/
|
||||
private static String chain(List<PqsTflgass> pqsTflgasses) {
|
||||
if(pqsTflgasses.size()<2){
|
||||
return null;
|
||||
}
|
||||
String logicNext = null;
|
||||
for (PqsTflgass pqsTflgass : pqsTflgasses) {
|
||||
//根据获取的的下节点判断是否存在,这下节点是否是首节点
|
||||
if (ObjectUtil.isNull(logicNext)) {
|
||||
logicNext = pqsTflgass.getLogicNext();
|
||||
} else {
|
||||
while (true) {
|
||||
for (int i1 = 0; i1 < pqsTflgasses.size(); i1++) {
|
||||
String logicBefore = pqsTflgasses.get(i1).getLogicBefore();
|
||||
if (logicNext.equals(logicBefore)) {
|
||||
logicNext = pqsTflgasses.get(i1).getLogicNext();
|
||||
break;
|
||||
} else {
|
||||
if (i1 == pqsTflgasses.size() - 1) {
|
||||
return logicNext;
|
||||
}
|
||||
}
|
||||
return logicNext;
|
||||
}
|
||||
|
||||
private static String chain2(List<PqsTflgass> pqsTflgasses) {
|
||||
if (pqsTflgasses.size() < 2) {
|
||||
return null;
|
||||
}
|
||||
String logicBefore = null;
|
||||
for (PqsTflgass pqsTflgass : pqsTflgasses) {
|
||||
//根据获取的的下节点判断是否存在,这下节点是否是首节点
|
||||
if (ObjectUtil.isNull(logicBefore)) {
|
||||
logicBefore = pqsTflgass.getLogicBefore();
|
||||
} else {
|
||||
while (true) {
|
||||
for (int i1 = 0; i1 < pqsTflgasses.size(); i1++) {
|
||||
String logicNext = pqsTflgasses.get(i1).getLogicNext();
|
||||
if (logicBefore.equals(logicNext)) {
|
||||
logicBefore = pqsTflgasses.get(i1).getLogicBefore();
|
||||
break;
|
||||
} else {
|
||||
if (i1 == pqsTflgasses.size() - 1) {
|
||||
return logicBefore;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
return logicNext;
|
||||
}
|
||||
|
||||
private static String chain2(List<PqsTflgass> pqsTflgasses) {
|
||||
if(pqsTflgasses.size()<2){
|
||||
return null;
|
||||
}
|
||||
String logicBefore = null;
|
||||
for (PqsTflgass pqsTflgass : pqsTflgasses) {
|
||||
//根据获取的的下节点判断是否存在,这下节点是否是首节点
|
||||
if (ObjectUtil.isNull(logicBefore)) {
|
||||
logicBefore = pqsTflgass.getLogicBefore();
|
||||
} else {
|
||||
while (true) {
|
||||
for (int i1 = 0; i1 < pqsTflgasses.size(); i1++) {
|
||||
String logicNext = pqsTflgasses.get(i1).getLogicNext();
|
||||
if (logicBefore.equals(logicNext)) {
|
||||
logicBefore = pqsTflgasses.get(i1).getLogicBefore();
|
||||
break;
|
||||
} else {
|
||||
if (i1 == pqsTflgasses.size() - 1) {
|
||||
return logicBefore;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return logicBefore;
|
||||
}
|
||||
return logicBefore;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据母线获取信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public TerminalTree addTree(String id) {
|
||||
List<TerminalTree> getvoltage = lineMapper.getvoltage(id, 2);
|
||||
getvoltage.get(0).setLevel(5);
|
||||
return getvoltage.get(0);
|
||||
}
|
||||
/**
|
||||
* 根据母线获取信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public TerminalTree addTree(String id) {
|
||||
List<TerminalTree> getvoltage = lineMapper.getvoltage(id, 2);
|
||||
getvoltage.get(0).setLevel(5);
|
||||
return getvoltage.get(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,31 +1,41 @@
|
||||
package com.njcn.device.pq.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
|
||||
import com.njcn.device.pq.mapper.LineDetailMapper;
|
||||
import com.njcn.device.pq.mapper.LineMapper;
|
||||
import com.njcn.device.pq.mapper.RStatIntegrityDMapper;
|
||||
import com.njcn.device.common.service.GeneralDeviceService;
|
||||
import com.njcn.device.line.mapper.LineDetailMapper;
|
||||
import com.njcn.device.line.mapper.LineMapper;
|
||||
import com.njcn.device.line.service.LineService;
|
||||
import com.njcn.device.pq.enums.RunFlagEnum;
|
||||
import com.njcn.device.pq.mapper.RStatOnlinerateDMapper;
|
||||
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
|
||||
import com.njcn.device.pq.pojo.dto.LineDataQualityDTO;
|
||||
import com.njcn.device.pq.pojo.dto.MonitorIntegrityDTO;
|
||||
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
|
||||
import com.njcn.device.pq.pojo.param.LineBaseQueryParam;
|
||||
import com.njcn.device.pq.pojo.param.LineDataQualityParam;
|
||||
import com.njcn.device.pq.pojo.po.Line;
|
||||
import com.njcn.device.pq.pojo.po.RStatIntegrityD;
|
||||
import com.njcn.device.pq.pojo.po.RStatOnlinerateD;
|
||||
import com.njcn.device.pq.pojo.vo.LineDetailDataVO;
|
||||
import com.njcn.device.pq.pojo.vo.LineDetailVO;
|
||||
import com.njcn.device.pq.pojo.vo.RStatIntegrityVO;
|
||||
import com.njcn.device.pq.pojo.vo.common.DeviceOnlineRate;
|
||||
import com.njcn.device.pq.service.IRStatIntegrityDService;
|
||||
import com.njcn.device.rstatintegrity.mapper.RStatIntegrityDMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
@@ -44,11 +54,11 @@ import java.util.stream.Collectors;
|
||||
public class RStatIntegrityDServiceImpl extends MppServiceImpl<RStatIntegrityDMapper, RStatIntegrityD> implements IRStatIntegrityDService {
|
||||
|
||||
private final RStatOnlinerateDMapper onlineRateMapper;
|
||||
|
||||
private final RStatIntegrityDMapper rStatIntegrityDMapper;
|
||||
|
||||
private final LineMapper lineMapper;
|
||||
private final LineDetailMapper lineDetailMapper;
|
||||
private final GeneralDeviceService deviceService;
|
||||
private final LineService lineService;
|
||||
|
||||
@Override
|
||||
public Float getTotalIntegrityByLineIds(LineBaseQueryParam param) {
|
||||
@@ -125,4 +135,79 @@ public class RStatIntegrityDServiceImpl extends MppServiceImpl<RStatIntegrityDMa
|
||||
this.saveOrUpdateBatchByMultiId(collect1,200);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceOnlineRate getData(DeviceInfoParam.BusinessParam param) {
|
||||
DeviceOnlineRate rate = new DeviceOnlineRate();
|
||||
//获取终端台账类信息
|
||||
List<GeneralDeviceDTO> deviceInfo = deviceService.getDeviceInfo(param, null, Collections.singletonList(1));
|
||||
if (CollUtil.isNotEmpty(deviceInfo)) {
|
||||
List<String> lineIds = deviceInfo.stream()
|
||||
.flatMap(x -> x.getLineIndexes().stream()).collect(Collectors.toList())
|
||||
.stream()
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
rate.setTotalNum(lineIds.size());
|
||||
//获取所有监测点的数据完整性
|
||||
List<RStatIntegrityVO> lineIntegrityRateInfo = rStatIntegrityDMapper.getLineIntegrityRateInfo(lineIds,param.getSearchBeginTime(),param.getSearchEndTime());
|
||||
//获取所有监测点信息信息
|
||||
List<LineDetailVO.Detail> LineInfoByIds = lineService.getLineDetailByIds(lineIds);
|
||||
|
||||
rate.setBelowNum(CollUtil.isNotEmpty(lineIntegrityRateInfo)?calculateIntegrityRate(lineIntegrityRateInfo,90):lineIds.size());
|
||||
rate.setTotalOnlineRate(calculateIntegrityRate(lineIntegrityRateInfo,lineIds).toString());
|
||||
List<DeviceOnlineRate.CitDetail> citDetailList=new ArrayList<>();
|
||||
DeviceOnlineRate.CitDetail citDetail;
|
||||
DeviceOnlineRate.LineDetail detail;
|
||||
for (GeneralDeviceDTO dto : deviceInfo) {
|
||||
//获取部门终端集合
|
||||
List<RStatIntegrityVO> citDevOnRate = lineIntegrityRateInfo.stream().filter(x -> dto.getLineIndexes().contains(x.getLineIndex())).collect(Collectors.toList());
|
||||
Map<String, Double> onlineRateByDevMap = citDevOnRate.stream()
|
||||
.collect(Collectors.toMap(RStatIntegrityVO::getLineIndex, RStatIntegrityVO::getIntegrityRate));
|
||||
citDetail=new DeviceOnlineRate.CitDetail();
|
||||
citDetail.setCitName(dto.getName());
|
||||
citDetail.setCitTotalNum(dto.getLineIndexes().size());
|
||||
citDetail.setCitBelowNum(CollUtil.isNotEmpty(citDevOnRate)?calculateIntegrityRate(lineIntegrityRateInfo,90):dto.getLineIndexes().size());
|
||||
citDetail.setCitTotalOnlineRate(calculateIntegrityRate(lineIntegrityRateInfo,dto.getLineIndexes()).toString());
|
||||
List<DeviceOnlineRate.LineDetail> detailList = new ArrayList<>();
|
||||
List<LineDetailVO.Detail> lineDetail = LineInfoByIds.stream().filter(x -> dto.getLineIndexes().contains(x.getLineId())).collect(Collectors.toList());
|
||||
for (LineDetailVO.Detail line : lineDetail) {
|
||||
detail = new DeviceOnlineRate.LineDetail();
|
||||
detail.setCit(line.getDeptName());
|
||||
detail.setCompany(line.getGdName());
|
||||
detail.setSubStation(line.getSubName());
|
||||
detail.setDeviceId(line.getDevId());
|
||||
detail.setDeviceName(line.getDevName());
|
||||
detail.setManufacturer(line.getManufacturer());
|
||||
detail.setIp(line.getIp());
|
||||
detail.setRunFlag(RunFlagEnum.getRunFlagRemarkByStatus(Integer.valueOf(line.getLineRunType())));
|
||||
detail.setLineId(line.getLineId());
|
||||
detail.setLineName(line.getLineName());
|
||||
detail.setLatestTime(line.getTimeID());
|
||||
detail.setIntegrity(onlineRateByDevMap.getOrDefault(line.getLineId(), 0.0));
|
||||
detailList.add(detail);
|
||||
}
|
||||
citDetail.setDetailList(detailList);
|
||||
citDetailList.add(citDetail);
|
||||
}
|
||||
rate.setCitDetailList(citDetailList);
|
||||
}
|
||||
return rate;
|
||||
}
|
||||
|
||||
private Double calculateIntegrityRate(List<RStatIntegrityVO> lineIntegrityRateInfo ,List<String> deviceIds){
|
||||
List<RStatIntegrityVO> list = lineIntegrityRateInfo.stream().filter(x -> deviceIds.contains(x.getLineIndex())).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(list)){
|
||||
BigDecimal onlineMin = BigDecimal.valueOf(list.stream().mapToLong(RStatIntegrityVO::getDueTime).sum());
|
||||
BigDecimal offlineMin =BigDecimal.valueOf( list.stream().mapToLong(RStatIntegrityVO::getRealTime).sum());
|
||||
BigDecimal sumMin= onlineMin.add(offlineMin);
|
||||
return sumMin.doubleValue();
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
private Integer calculateIntegrityRate(List<RStatIntegrityVO> onlineRateByDev,Integer limit){
|
||||
return (int) onlineRateByDev.stream().filter(x -> x.getIntegrityRate() < limit).count();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,11 +8,13 @@ import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.dto.SimpleDTO;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.device.common.service.GeneralDeviceService;
|
||||
import com.njcn.device.common.service.TerminalBaseService;
|
||||
import com.njcn.device.device.mapper.DeviceMapper;
|
||||
import com.njcn.device.line.mapper.LineDetailMapper;
|
||||
import com.njcn.device.line.service.LineService;
|
||||
import com.njcn.device.pq.enums.LineBaseEnum;
|
||||
import com.njcn.device.pq.mapper.DeviceMapper;
|
||||
import com.njcn.device.pq.mapper.LineDetailMapper;
|
||||
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
|
||||
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
|
||||
import com.njcn.device.pq.pojo.param.RunManageParam;
|
||||
@@ -22,12 +24,9 @@ import com.njcn.device.pq.pojo.vo.LineInfluxDbOnlineVO;
|
||||
import com.njcn.device.pq.pojo.vo.RunManageVO;
|
||||
import com.njcn.device.pq.pojo.vo.RunTimeVO;
|
||||
import com.njcn.device.pq.pojo.vo.TerminalLedgerVO;
|
||||
import com.njcn.device.pq.service.LineService;
|
||||
import com.njcn.device.pq.service.RunManageService;
|
||||
import com.njcn.device.pq.service.TerminalBaseService;
|
||||
import com.njcn.supervision.api.UserLedgerFeignClient;
|
||||
import com.njcn.supervision.pojo.vo.user.NewUserReportVO;
|
||||
import com.njcn.supervision.pojo.vo.user.UserLedgerVO;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.enums.DicDataTypeEnum;
|
||||
import com.njcn.system.pojo.enums.StatisticsEnum;
|
||||
@@ -134,11 +133,6 @@ public class RunManageServiceImpl implements RunManageService {
|
||||
DeviceInfoParam deviceInfoParam = new DeviceInfoParam();
|
||||
BeanUtil.copyProperties(runManageParam, deviceInfoParam);
|
||||
deviceInfoParam.setServerName("pqs-common");
|
||||
if(CollUtil.isNotEmpty(runManageParam.getRunFlag())){
|
||||
if(runManageParam.getRunFlag().get(0)==0){
|
||||
deviceInfoParam.setLineRunFlag(0);
|
||||
}
|
||||
}
|
||||
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceService.getDeviceInfo(deviceInfoParam, runManageParam.getRunFlag(), Stream.of(1).collect(Collectors.toList()));
|
||||
if (CollectionUtils.isEmpty(generalDeviceDTOList)) {
|
||||
throw new BusinessException("当前部门没有装置台账");
|
||||
|
||||
@@ -4,13 +4,14 @@ package com.njcn.device.pq.service.impl;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.njcn.device.common.service.GeneralDeviceService;
|
||||
import com.njcn.device.common.service.TerminalBaseService;
|
||||
import com.njcn.device.pq.pojo.bo.DeviceType;
|
||||
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
|
||||
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
|
||||
import com.njcn.device.pq.pojo.vo.CommunicateVO;
|
||||
import com.njcn.device.pq.pojo.vo.TerminalBaseVO;
|
||||
import com.njcn.device.pq.service.ISubstationExpendService;
|
||||
import com.njcn.device.pq.service.TerminalBaseService;
|
||||
import com.njcn.influx.imapper.PqsCommunicateMapper;
|
||||
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
|
||||
import com.njcn.influx.pojo.po.PqsCommunicate;
|
||||
|
||||
@@ -5,22 +5,19 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.device.line.mapper.LineDetailMapper;
|
||||
import com.njcn.device.line.mapper.LineMapper;
|
||||
import com.njcn.device.pq.enums.LineBaseEnum;
|
||||
import com.njcn.device.pq.enums.PowerFlagEnum;
|
||||
import com.njcn.device.pq.mapper.LineDetailMapper;
|
||||
import com.njcn.device.pq.mapper.LineMapper;
|
||||
import com.njcn.device.pq.mapper.SubstationMapper;
|
||||
import com.njcn.device.pq.mapper.VoltageMapper;
|
||||
import com.njcn.device.pq.pojo.dto.SubstationDTO;
|
||||
import com.njcn.device.pq.pojo.po.Line;
|
||||
import com.njcn.device.pq.pojo.po.LineDetail;
|
||||
import com.njcn.device.pq.pojo.po.Substation;
|
||||
import com.njcn.device.pq.pojo.po.Voltage;
|
||||
import com.njcn.device.pq.pojo.vo.LedgerSelectVO;
|
||||
import com.njcn.device.pq.pojo.vo.LineDetailVO;
|
||||
import com.njcn.device.pq.service.ISubstationService;
|
||||
import com.njcn.device.substation.mapper.SubstationMapper;
|
||||
import com.njcn.device.subvoltage.mapper.VoltageMapper;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.enums.DicDataTypeEnum;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.njcn.common.config.GeneralInfo;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.device.common.service.GeneralDeviceService;
|
||||
import com.njcn.device.pq.api.AlarmClient;
|
||||
import com.njcn.device.biz.enums.DeviceResponseEnum;
|
||||
import com.njcn.device.pq.enums.LineBaseEnum;
|
||||
|
||||
@@ -3,16 +3,18 @@ package com.njcn.device.pq.service.impl;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.common.pojo.enums.common.ServerEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.device.biz.pojo.vo.TerminalSelectTreeVO;
|
||||
import com.njcn.device.common.service.GeneralDeviceService;
|
||||
import com.njcn.device.line.mapper.DeptLineMapper;
|
||||
import com.njcn.device.line.mapper.LineDetailMapper;
|
||||
import com.njcn.device.line.mapper.LineMapper;
|
||||
import com.njcn.device.pq.enums.LineBaseEnum;
|
||||
import com.njcn.device.pq.mapper.DeptLineMapper;
|
||||
import com.njcn.device.pq.mapper.LineDetailMapper;
|
||||
import com.njcn.device.pq.mapper.LineMapper;
|
||||
import com.njcn.device.pq.mapper.TreeMapper;
|
||||
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
|
||||
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
|
||||
@@ -25,7 +27,6 @@ import com.njcn.supervision.api.UserLedgerFeignClient;
|
||||
import com.njcn.supervision.pojo.param.user.UserReportParam;
|
||||
import com.njcn.supervision.pojo.vo.user.UserLedgerVO;
|
||||
import com.njcn.system.api.AreaFeignClient;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.pojo.enums.StatisticsEnum;
|
||||
import com.njcn.system.pojo.po.Area;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
@@ -138,7 +139,12 @@ public class TerminalTreeServiceImpl implements TerminalTreeService {
|
||||
|
||||
private List<TerminalTree> specialDealSubChildren(TerminalTree sub,List<TerminalTree> lineUserList,List<TerminalTree> devOtherList,List<TerminalTree> busBarList,List<TerminalTree> devAllList,List<UserLedgerVO> userReportPOList){
|
||||
List<TerminalTree> list = new ArrayList<>();
|
||||
|
||||
//电网侧
|
||||
List<TerminalTree> devTree = devOtherList.stream().filter(it->it.getPid().equals(sub.getId())).collect(Collectors.toList());
|
||||
if(CollectionUtil.isNotEmpty(devTree)){
|
||||
list.addAll(devTree);
|
||||
}
|
||||
//非电网侧
|
||||
if(CollUtil.isNotEmpty(userReportPOList)) {
|
||||
Map<String, UserLedgerVO> userLedgerVOMap = userReportPOList.stream().collect(Collectors.toMap(UserLedgerVO::getId, Function.identity()));
|
||||
|
||||
@@ -160,6 +166,7 @@ public class TerminalTreeServiceImpl implements TerminalTreeService {
|
||||
busCopy.setName(it.getName());
|
||||
busCopy.setId(it.getId());
|
||||
busCopy.setPid(it.getPid());
|
||||
busCopy.setSort(it.getSort());
|
||||
busCopy.setChildren(getChildren(it, lineList));
|
||||
busCopy.setPowerFlag(1);
|
||||
busCopy.setLevel(LineBaseEnum.SUB_V_LEVEL.getCode());
|
||||
@@ -175,6 +182,7 @@ public class TerminalTreeServiceImpl implements TerminalTreeService {
|
||||
devCopy.setName(it.getName());
|
||||
devCopy.setId(it.getId());
|
||||
devCopy.setPid(it.getPid());
|
||||
devCopy.setSort(it.getSort());
|
||||
devCopy.setChildren(getChildren(it, temBus));
|
||||
devCopy.setPowerFlag(1);
|
||||
devCopy.setLevel(LineBaseEnum.DEVICE_LEVEL.getCode());
|
||||
@@ -192,18 +200,11 @@ public class TerminalTreeServiceImpl implements TerminalTreeService {
|
||||
terminalTree.setPowerFlag(1);
|
||||
terminalTree.setLevel(LineBaseEnum.USER_LEVEL.getCode());
|
||||
terminalTree.setChildren(temDevList);
|
||||
terminalTree.setSort(0);
|
||||
list.add(terminalTree);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
List<TerminalTree> devTree = devOtherList.stream().filter(it->it.getPid().equals(sub.getId())).collect(Collectors.toList());
|
||||
if(CollectionUtil.isNotEmpty(devTree)){
|
||||
list.addAll(devTree);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -521,6 +522,7 @@ public class TerminalTreeServiceImpl implements TerminalTreeService {
|
||||
sub.setId(collect.get(0).getId());
|
||||
sub.setName(collect.get(0).getName());
|
||||
sub.setPid(collect.get(0).getPid());
|
||||
sub.setSort(0);
|
||||
sub.setChildren(valueList);
|
||||
|
||||
TerminalTree powerTree=new TerminalTree();
|
||||
@@ -551,7 +553,7 @@ public class TerminalTreeServiceImpl implements TerminalTreeService {
|
||||
sub.setId(child.getId());
|
||||
sub.setName(child.getName());
|
||||
sub.setPid(child.getPid());
|
||||
|
||||
sub.setSort(0);
|
||||
TerminalTree powerTree=new TerminalTree();
|
||||
powerTree.setName("电网侧");
|
||||
powerTree.setId(child.getId());
|
||||
@@ -581,7 +583,7 @@ public class TerminalTreeServiceImpl implements TerminalTreeService {
|
||||
sub.setId(child.getId());
|
||||
sub.setName(child.getName());
|
||||
sub.setPid(child.getPid());
|
||||
|
||||
sub.setSort(0);
|
||||
TerminalTree powerTree = new TerminalTree();
|
||||
powerTree.setName("电网侧");
|
||||
powerTree.setId(child.getId());
|
||||
@@ -620,7 +622,7 @@ public class TerminalTreeServiceImpl implements TerminalTreeService {
|
||||
sub.setId(notSub.getId());
|
||||
sub.setName(notSub.getName());
|
||||
sub.setPid(notSub.getPid());
|
||||
|
||||
sub.setSort(0);
|
||||
TerminalTree powerTree = new TerminalTree();
|
||||
powerTree.setId(notSub.getId());
|
||||
powerTree.setName("电网侧");
|
||||
@@ -655,6 +657,49 @@ public class TerminalTreeServiceImpl implements TerminalTreeService {
|
||||
return taiZhang;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TerminalTree> getJbNewTerminalTree() {
|
||||
List<TerminalTree> allList = lineMapper.getAllList();
|
||||
List<TerminalTree> projectList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.PROJECT_LEVEL.getCode())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
List<TerminalTree> provinceList = lineMapper.getProvinceList(null, 0);
|
||||
|
||||
List<TerminalTree> gdList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.GD_LEVEL.getCode())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
List<TerminalTree> subList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.SUB_LEVEL.getCode())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
List<TerminalTree> devList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.DEVICE_LEVEL.getCode())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
List<TerminalTree> subvList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.SUB_V_LEVEL.getCode())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
|
||||
List<TerminalTree> linepowerList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.LINE_LEVEL.getCode())&&item.getPowerFlag() != 1).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
List<TerminalTree> lineNotPowerList = allList.stream().filter(item -> item.getLevel().equals(LineBaseEnum.LINE_LEVEL.getCode())&&item.getPowerFlag() == 1).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
|
||||
|
||||
|
||||
subvList.forEach(subv ->{
|
||||
if(CollUtil.isEmpty(subv.getChildren())){
|
||||
subv.setChildren(getRecursionChildren(subv, linepowerList));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
subvList.forEach(subv -> {
|
||||
if(CollUtil.isEmpty(subv.getChildren())){
|
||||
subv.setChildren(getRecursionChildren(subv, lineNotPowerList));
|
||||
}
|
||||
}
|
||||
);
|
||||
subvList.stream().filter(x-> ObjUtil.isNull(x.getPowerFlag())).forEach(x->x.setPowerFlag(0));
|
||||
devList.forEach(dev -> dev.setChildren(getRecursionChildren(dev, subvList)));
|
||||
devList.stream().filter(x-> ObjUtil.isNull(x.getPowerFlag())).forEach(x->x.setPowerFlag(0));
|
||||
|
||||
|
||||
|
||||
subList.forEach(sub -> sub.setChildren(getRecursionChildrenCs(sub, devList)));
|
||||
gdList.forEach(gd -> gd.setChildren(getChildren(gd, subList)));
|
||||
provinceList.forEach(province -> province.setChildren(getChildren(province, gdList)));
|
||||
projectList.forEach(project -> project.setChildren(getChildren(project, provinceList)));
|
||||
|
||||
return projectList;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部子节点
|
||||
@@ -663,7 +708,40 @@ public class TerminalTreeServiceImpl implements TerminalTreeService {
|
||||
* @date 2021/7/19
|
||||
*/
|
||||
public List<TerminalTree> getChildren(TerminalTree item, List<TerminalTree> all) {
|
||||
return all.stream().filter(allItem -> allItem.getPid().equals(item.getId())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
List<TerminalTree> collect = all.stream().filter(allItem -> allItem.getPid().equals(item.getId())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(collect)){
|
||||
long sortSize = collect.stream().filter(x->ObjUtil.isNotNull(x.getSort())).filter(x -> x.getSort() == 0).count();
|
||||
if(collect.size()-sortSize/collect.size()>50){
|
||||
collect.sort(Comparator.comparing(x->x.getName()));
|
||||
}
|
||||
}
|
||||
return collect;
|
||||
}
|
||||
|
||||
public List<TerminalTree> getRecursionChildrenCs(TerminalTree item, List<TerminalTree> all){
|
||||
List<TerminalTree> collect = all.stream().filter(allItem -> allItem.getPid().equals(item.getId())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
List<TerminalTree> list=new ArrayList<>();
|
||||
TerminalTree power=new TerminalTree();
|
||||
power.setName("电网侧");
|
||||
power.setSort(0);
|
||||
power.setChildren(collect.stream().filter(x -> 1 != x.getPowerFlag()).collect(Collectors.toList()));
|
||||
list.add(power);
|
||||
|
||||
|
||||
|
||||
TerminalTree notPower=new TerminalTree();
|
||||
notPower.setName("非电网侧");
|
||||
notPower.setSort(1);
|
||||
notPower.setChildren(collect.stream().filter(x -> 1 == x.getPowerFlag()).collect(Collectors.toList()));
|
||||
list.add(notPower);
|
||||
return list;
|
||||
}
|
||||
public List<TerminalTree> getRecursionChildren(TerminalTree item, List<TerminalTree> all){
|
||||
List<TerminalTree> list = all.stream().filter(allItem -> allItem.getPid().equals(item.getId())).sorted(Comparator.comparing(TerminalTree::getSort)).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(list)){
|
||||
item.setPowerFlag(list.get(0).getPowerFlag());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,13 +5,13 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.device.biz.pojo.dto.SubGetBase;
|
||||
import com.njcn.device.biz.pojo.param.SubstationParam;
|
||||
import com.njcn.device.pq.mapper.SubstationMapper;
|
||||
import com.njcn.device.pq.mapper.YwZtSubstationMapper;
|
||||
import com.njcn.device.pq.pojo.po.Substation;
|
||||
import com.njcn.device.pq.pojo.po.YwZtSubstation;
|
||||
import com.njcn.device.pq.service.ISubstationService;
|
||||
import com.njcn.device.pq.service.IYwZtSubstationService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.device.substation.mapper.SubstationMapper;
|
||||
import com.njcn.user.api.DeptFeignClient;
|
||||
import com.njcn.user.pojo.dto.DeptDTO;
|
||||
import com.njcn.user.pojo.po.Dept;
|
||||
|
||||
53
pqs-device/pq-device/pq-device-com/pom.xml
Normal file
53
pqs-device/pq-device/pq-device-com/pom.xml
Normal file
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>pq-device</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pq-device-com</artifactId>
|
||||
<name>传统设备通用业务</name>
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>pq-device-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-web</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>supervision-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-oss</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn.platform</groupId>
|
||||
<artifactId>message-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user