From 30984aa908b69d0b04d2c0a7c0071a3c3865a481 Mon Sep 17 00:00:00 2001 From: xy <748613696@qq.com> Date: Wed, 8 Apr 2026 19:27:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E6=80=81=E4=BA=8B=E4=BB=B6=E6=B3=A2?= =?UTF-8?q?=E5=BD=A2=E8=A7=A3=E6=9E=90=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/EventWaveAnalysisServiceImpl.java | 4 + .../file/component/WaveFileComponent.java | 326 ++++++++++++++++-- 2 files changed, 307 insertions(+), 23 deletions(-) diff --git a/pqs-advance/advance-boot/src/main/java/com/njcn/advance/service/impl/EventWaveAnalysisServiceImpl.java b/pqs-advance/advance-boot/src/main/java/com/njcn/advance/service/impl/EventWaveAnalysisServiceImpl.java index dc9b453c0..d17774ec2 100644 --- a/pqs-advance/advance-boot/src/main/java/com/njcn/advance/service/impl/EventWaveAnalysisServiceImpl.java +++ b/pqs-advance/advance-boot/src/main/java/com/njcn/advance/service/impl/EventWaveAnalysisServiceImpl.java @@ -223,6 +223,10 @@ public class EventWaveAnalysisServiceImpl implements EventWaveAnalysisService { RmpEventDetailPO rmpEventDetailPO = rmpEventAdvanceMapper.selectById(eventIndex); EntityAdvancedData entityAdvancedData; + if (Objects.isNull(rmpEventDetailPO.getFileFlag())) { + throw new BusinessException("系统检测到波形文件未从装置招到本地,请联系管理员"); + } + if (rmpEventDetailPO.getFileFlag() == 1) { //获取所有暂态原因 List dicDataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.EVENT_TYPE.getCode()).getData(); diff --git a/pqs-common/common-event/src/main/java/com/njcn/event/file/component/WaveFileComponent.java b/pqs-common/common-event/src/main/java/com/njcn/event/file/component/WaveFileComponent.java index 012bf350e..b96ce7124 100644 --- a/pqs-common/common-event/src/main/java/com/njcn/event/file/component/WaveFileComponent.java +++ b/pqs-common/common-event/src/main/java/com/njcn/event/file/component/WaveFileComponent.java @@ -3,11 +3,9 @@ package com.njcn.event.file.component; import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.IoUtil; -import cn.hutool.core.text.StrPool; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.StrUtil; -import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.utils.wave.BitConverter; import com.njcn.event.file.pojo.dto.*; @@ -511,7 +509,6 @@ public class WaveFileComponent { //抽点后新的的采样率 List newLstRate = new ArrayList<>(); for (int iRate = 0; iRate < comtradeCfgDTO.getNRates(); iRate++) { -// if (comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() >= 32) { // 计算本段录波总共有多少波形 nWaveNum = comtradeCfgDTO.getLstRate().get(iRate).getNSampleNum() / comtradeCfgDTO.getLstRate().get(iRate).getNOneSample(); //设置总波形大小 @@ -547,12 +544,7 @@ public class WaveFileComponent { newLstRate.get(nnInd).setNSampleNum(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() * nWaveNum); } - // 正常的配置中采样率 - /* comtradeCfgDTO.getLstRate().get(nnInd).setNOneSample(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample()); - comtradeCfgDTO.getLstRate().get(nnInd).setNSampleNum(comtradeCfgDTO.getLstRate().get(iRate).getNSampleNum());*/ - nnInd++; -// } } // 偏移量,采样间隔 long nOffSet = 0, nWaveSpan; @@ -560,7 +552,6 @@ public class WaveFileComponent { float fValue, dfValue; // 计算不同块的采样率 int nIndex = 0; - // 将最低采样率替换到本段录波内 // .CFG中采样率 RateDTO tmpRateDTO; // nBlockNum 总循环次数 @@ -596,26 +587,17 @@ public class WaveFileComponent { long allWaveTemp = newLstRate.get(nIndex).getNSampleNum() / newLstRate.get(nIndex).getNOneSample(); // 本段需要补多少点 long allempSample = newLstRate.get(nIndex).getNOneSample(); - //int iStartWaveTemp = i ;// 开始补点的起点 + + int currentDataIndex = i; for (int iWaveTemp = 0; iWaveTemp < allWaveTemp; iWaveTemp++) { for (int mTempSample = 0; mTempSample < allempSample; mTempSample++) { - //最多只有半波有效值,也就是每周波是1个或者2个点,然后去补最少16个点 - if (mTempSample / nWaveSpan == 1 && mTempSample % nWaveSpan == 0) { - i++; - } - //存储局部数据集合,包含了时间,A,B,C三相 tmpWaveData = new ArrayList<>(); for (int j = 0; j < comtradeCfgDTO.getNAnalogNum(); j++) { - //数据只有电压ABC三相数据,不展示U0、I0等数据 YXB2020-10-09 去除相别为N相的数据 if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzPhasicName().equalsIgnoreCase("N")) { break; } 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; + fValue = BitConverter.byte2ToUnsignedShort(datArray, currentDataIndex * nBlockSize + 2 * 4 + j * 2) * fCoef; //WW 2019-11-14 /************************* * 1、接口返回的默认是二次值 @@ -668,7 +650,7 @@ public class WaveFileComponent { //xValue前移量,假如是第一次时候则需要前移 if (!blxValue && j == 0) { - xValueAll = (float) (i * 20) / tmpRateDTO.getNOneSample() - comtradeCfgDTO.getNPush(); + xValueAll = (float) (currentDataIndex * 20) / tmpRateDTO.getNOneSample() - comtradeCfgDTO.getNPush(); blxValue = true; //只增加一个xValue的值 //增加时间值 tmpWaveData.add((float) (Math.round(xValueAll * 100)) / 100); @@ -686,7 +668,7 @@ public class WaveFileComponent { } // 把每个单独的值赋予到整体里面去 if (iWaveTemp < (allWaveTemp - 1)) { - i++; + currentDataIndex++; } } } else { @@ -777,6 +759,304 @@ public class WaveFileComponent { return listWaveData; } +// private List> getComtradeDat(ComtradeCfgDTO comtradeCfgDTO, InputStream datStream, int iType) { +// //返回数据,如果仅仅做展示后期考虑换String类型,降低内存开销 +// List> listWaveData = new ArrayList<>(); +// //初始化xValue的值 +// float xValueAll = 0; +// //判断是否首次登陆 +// boolean blxValue = false; +// byte[] datArray; +// try { +// datArray = IoUtil.readBytes(datStream); +// if (ArrayUtil.isEmpty(datArray)) { +// throw new BusinessException(WaveFileResponseEnum.DAT_DATA_ERROR); +// } +// // 计算每个单独的数据块的大小 4个字节的序号 4个字节的时间 2个字节的值 +// // 示例中的排布是 4个字节的序号 4个字节的时间 UA(2字节) UB(2字节) UC(2字节) IA(2字节) IB(2字节) IC(2字节) +// 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 = (int)Math.floor(datArray.length / nBlockSize); +// +// // 获取采样率 +// int finalSampleRate = getFinalWaveSample(comtradeCfgDTO.getLstRate(), iType); +// if (finalSampleRate != -1) { +// //设置最终采样率 +// comtradeCfgDTO.setFinalSampleRate(finalSampleRate); +// // 计算转换后的采样率 +// int nnInd = 0; +// // 抽点后总共多少点数据 +// int nWaveNum; +// //抽点后新的的采样率 +// List newLstRate = new ArrayList<>(); +// for (int iRate = 0; iRate < comtradeCfgDTO.getNRates(); iRate++) { +//// if (comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() >= 32) { +// // 计算本段录波总共有多少波形 +// nWaveNum = comtradeCfgDTO.getLstRate().get(iRate).getNSampleNum() / comtradeCfgDTO.getLstRate().get(iRate).getNOneSample(); +// //设置总波形大小 +// comtradeCfgDTO.setNAllWaveNum(comtradeCfgDTO.getNAllWaveNum() + nWaveNum); +// // 将最低采样率替换到本段录波内 +// RateDTO tmpRateDTO = new RateDTO(); +// // 有效值标志,如果是有效值,那么就需要反向补点,而不是抽点 +// if (comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() >= 32) { +// //YXB 2025-08-27 +// tmpRateDTO.bRMSFlag = false; +// } +// //如果采样是全波有效值或者半波有效值,需要去补足周波点数 YXB 2025-08-27 +// else if (comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() <= 2) { +// //YXB 2025-08-27 +// tmpRateDTO.bRMSFlag = true; +// } +// newLstRate.add(tmpRateDTO); +// //iFlag =3 一定不进行抽点算法 +// if (iType != 3) { +// //true 抽点算法(当前采样率跟统一采样率不一样则是抽点,否则是未抽点) +// if (!Objects.equals(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample(), comtradeCfgDTO.getFinalSampleRate())) { +// newLstRate.get(nnInd).setNOneSample(comtradeCfgDTO.getFinalSampleRate()); +// // 计算本段录波按照最低采样点应该有多少录波 +// newLstRate.get(nnInd).setNSampleNum(comtradeCfgDTO.getFinalSampleRate() * nWaveNum); +// } else { +// newLstRate.get(nnInd).setNOneSample(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample()); +// // 计算本段录波按照最低采样点应该有多少录波 +// newLstRate.get(nnInd).setNSampleNum(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() * nWaveNum); +// } +// } else { +// newLstRate.get(nnInd).setNOneSample(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample()); +// // 计算本段录波按照最低采样点应该有多少录波 +// newLstRate.get(nnInd).setNSampleNum(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample() * nWaveNum); +// } +// +// // 正常的配置中采样率 +// /* comtradeCfgDTO.getLstRate().get(nnInd).setNOneSample(comtradeCfgDTO.getLstRate().get(iRate).getNOneSample()); +// comtradeCfgDTO.getLstRate().get(nnInd).setNSampleNum(comtradeCfgDTO.getLstRate().get(iRate).getNSampleNum());*/ +// +// nnInd++; +//// } +// } +// // 偏移量,采样间隔 +// long nOffSet = 0, nWaveSpan; +// //两个点之间的时间差 +// float fValue, dfValue; +// // 计算不同块的采样率 +// int nIndex = 0; +// // 将最低采样率替换到本段录波内 +// // .CFG中采样率 +// RateDTO tmpRateDTO; +// // nBlockNum 总循环次数 +// for (int i = 0; i < nBlockNum; i++) { +// tmpRateDTO = comtradeCfgDTO.getLstRate().get(nIndex); +// // 判断是否进入下一段 +// if (i == tmpRateDTO.getNSampleNum() + nOffSet) { +// nOffSet += tmpRateDTO.getNSampleNum(); +// nIndex++; +// if (nIndex == nnInd) { +// break; +// } +// } +// tmpRateDTO = comtradeCfgDTO.getLstRate().get(nIndex); +// //YXB 2025-08-27 如果是有效值,那么需要去补点,而不是抽点 +// if (newLstRate.get(nIndex).bRMSFlag == true) { +// //计算本段补点采样间隔 +// nWaveSpan = newLstRate.get(nIndex).getNOneSample() / tmpRateDTO.getNOneSample(); +// } else { +// // 计算本段抽点采样间隔 +// nWaveSpan = tmpRateDTO.getNOneSample() / newLstRate.get(nIndex).getNOneSample(); +// } +// +// dfValue = (float) 20 / tmpRateDTO.getNOneSample(); +// // 判断是否到了需要抽的采样点 +// if (i % nWaveSpan == 0) { +// // 计算每个通道的值 +// //存储局部数据集合,包含了时间,A,B,C三相 +// List tmpWaveData = new ArrayList<>(); +// //YXB 2025-08-27 如果是有效值,那么需要去补点,而不是抽点 +// if (newLstRate.get(nIndex).bRMSFlag == true) { +// // 计算有多少个周波 +// long allWaveTemp = newLstRate.get(nIndex).getNSampleNum() / newLstRate.get(nIndex).getNOneSample(); +// // 本段需要补多少点 +// long allempSample = newLstRate.get(nIndex).getNOneSample(); +// //int iStartWaveTemp = i ;// 开始补点的起点 +// for (int iWaveTemp = 0; iWaveTemp < allWaveTemp; iWaveTemp++) { +// for (int mTempSample = 0; mTempSample < allempSample; mTempSample++) { +// //最多只有半波有效值,也就是每周波是1个或者2个点,然后去补最少16个点 +// if (mTempSample / nWaveSpan == 1 && mTempSample % nWaveSpan == 0) { +// i++; +// } +// //存储局部数据集合,包含了时间,A,B,C三相 +// tmpWaveData = new ArrayList<>(); +// for (int j = 0; j < comtradeCfgDTO.getNAnalogNum(); j++) { +// //数据只有电压ABC三相数据,不展示U0、I0等数据 YXB2020-10-09 去除相别为N相的数据 +// if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzPhasicName().equalsIgnoreCase("N")) { +// break; +// } +// 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 +// /************************* +// * 1、接口返回的默认是二次值 +// * 2、P是一次值 S是二次值 +// * 3、S(二次值)情况下: +// * ①、单位为"V"时候则直接等于; +// * ②、单位为"kV"时候需要乘以1000 +// * 4、P(一次值)情况下: +// * ①、单位为"V"时候则直接等于; +// * ②、单位为"kV"时候需要乘以1000 +// *************************/ +// //P是一次值 S是二次值 +// if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzValueType().equalsIgnoreCase("S")) { +// //判断单位是V还是kV +// if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("KV")) { +// fValue = fValue * 1000.0f; +// } else { +// fValue = fValue; +// } +// } +// //P是一次值 S是二次值 +// else if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzValueType().equalsIgnoreCase("P")) { +// //判断单位是V还是kV +// if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("V")) { +// //根据cfg内的变比,将一次值转换成二次值 +// if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) { +// fValue = fValue * comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary(); +// } else { +// fValue = fValue; +// } +// } +// //判断单位是V还是kV +// else if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("KV")) { +// //根据cfg内的变比,将一次值转换成二次值 +// if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) { +// fValue = fValue * 1000.0f * comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary(); +// } else { +// fValue = fValue; +// } +// } else //还有可能是 电流,单位是A +// { +// //根据cfg内的变比,将一次值转换成二次值 +// if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) { +// fValue = comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary(); +// } else { +// fValue = fValue; +// } +// } +// } +// +// //xValue前移量,假如是第一次时候则需要前移 +// if (!blxValue && j == 0) { +// xValueAll = (float) (i * 20) / tmpRateDTO.getNOneSample() - comtradeCfgDTO.getNPush(); +// blxValue = true; +// //只增加一个xValue的值 //增加时间值 +// tmpWaveData.add((float) (Math.round(xValueAll * 100)) / 100); +// } else if (j == 0) { +// xValueAll += (float) dfValue / nWaveSpan; +// //只增加一个xValue的值 //增加时间值 +// tmpWaveData.add((float) (Math.round(xValueAll * 100)) / 100); +// } +// +// //不同通道yValue的值都需要增加,最终成ABC三相 //每个通道的值 +// tmpWaveData.add((float) (Math.round(fValue * 100)) / 100); +// } +// //把每个单独的值赋予到整体里面去 +// listWaveData.add(tmpWaveData); +// } +// // 把每个单独的值赋予到整体里面去 +// if (iWaveTemp < (allWaveTemp - 1)) { +// i++; +// } +// } +// } else { +// for (int j = 0; j < comtradeCfgDTO.getNAnalogNum(); j++) { +// //数据只有电压ABC三相数据,不展示U0、I0等数据 YXB2020-10-09 去除相别为N相的数据 +// if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzPhasicName().equalsIgnoreCase("N")) { +// break; +// } +// +// float fCoef = comtradeCfgDTO.getLstAnalogDTO().get(j).getFCoefficent(); +// fValue = BitConverter.byte2ToUnsignedShort(datArray, i * nBlockSize + 2 * 4 + j * 2) * fCoef; +// +// //WW 2019-11-14 +// /************************** +// * 1、接口返回的默认是二次值 +// * 2、P是一次值 S是二次值 +// * 3、S(二次值)情况下: +// * ①、单位为"V"时候则直接等于; +// * ②、单位为"kV"时候需要乘以1000 +// * 4、P(一次值)情况下: +// * ①、单位为"V"时候则直接等于; +// * ②、单位为"kV"时候需要乘以1000 +// **************************/ +// //P是一次值 S是二次值 +// if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzValueType().equalsIgnoreCase("S")) { +// //判断单位是V还是kV +// if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("KV")) { +// fValue = fValue * 1000.0f; +// } else { +// fValue = fValue; +// } +// } +// //P是一次值 S是二次值 +// else if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzValueType().equalsIgnoreCase("P")) { +// //判断单位是V还是kV +// if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("V")) { +// //根据cfg内的变比,将一次值转换成二次值 +// if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) { +// fValue = fValue * comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary(); +// } else { +// fValue = fValue; +// } +// } +// //判断单位是V还是kV +// else if (comtradeCfgDTO.getLstAnalogDTO().get(j).getSzUnitName().equalsIgnoreCase("KV")) { +// //根据cfg内的变比,将一次值转换成二次值 +// if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) { +// fValue = fValue * 1000.0f * comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary(); +// } else { +// fValue = fValue; +// } +// } else //还有可能是 电流,单位是A +// { +// //根据cfg内的变比,将一次值转换成二次值 +// if (comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary() != 0.0f) { +// fValue = comtradeCfgDTO.getLstAnalogDTO().get(j).getFSecondary() / comtradeCfgDTO.getLstAnalogDTO().get(j).getFPrimary(); +// } else { +// fValue = fValue; +// } +// } +// } +// //xValue前移量,假如是第一次时候则需要前移 +// if (!blxValue && j == 0) { +// xValueAll = (float) (i * 20) / tmpRateDTO.getNOneSample() - comtradeCfgDTO.getNPush(); +// blxValue = true; +// //只增加一个xValue的值 //增加时间值 +// tmpWaveData.add((float) (Math.round(xValueAll * 100)) / 100); +// } else if (j == 0) { +// xValueAll += (float) nWaveSpan * dfValue; +// //只增加一个xValue的值 //增加时间值 +// tmpWaveData.add((float) (Math.round(xValueAll * 100)) / 100); +// } +// +// //不同通道yValue的值都需要增加,最终成ABC三相 //每个通道的值 +// tmpWaveData.add((float) (Math.round(fValue * 100)) / 100); +// } +// //把每个单独的值赋予到整体里面去 +// listWaveData.add(tmpWaveData); +// } +// } +// } +// } +// } catch (Exception e) { +// e.printStackTrace(); +// throw new BusinessException(WaveFileResponseEnum.DAT_DATA_ERROR); +// } +// +// return listWaveData; +// } + /********************************* * 获取最小(最终)采样率方法