App稳态、暂态报告功能支持

This commit is contained in:
xy
2026-03-25 13:28:46 +08:00
parent fcddc064f6
commit 7b9fb1628b
25 changed files with 850 additions and 62 deletions

View File

@@ -2,8 +2,14 @@ package com.njcn.advance.api;
import com.njcn.advance.api.fallback.EventWaveAnalysisFeignClientFallbackFactory;
import com.njcn.advance.pojo.dto.waveAnalysis.EntityAdvancedData;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.ServerInfo;
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 io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -27,4 +33,7 @@ public interface EventWaveAnalysisFeignClient {
*/
@PostMapping("analysis")
HttpResult<EntityAdvancedData> analysis(@RequestParam("eventIndex") String eventIndex);
@PostMapping("analysisWlEvent")
HttpResult<EntityAdvancedData> analysisWlEvent(@RequestParam("eventIndex") String eventIndex);
}

View File

@@ -32,6 +32,12 @@ public class EventWaveAnalysisFeignClientFallbackFactory implements FallbackFact
log.error("{}异常,降级处理,异常为:{}", "波形高级分析", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<EntityAdvancedData> analysisWlEvent(String eventIndex) {
log.error("{}异常,降级处理,异常为:{}", "物联测点波形高级分析异常", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -73,4 +73,10 @@ public class EventAnalysisDTO {
* 1 正常计算
*/
private Integer typeFlag = 1;
/**
* 文件全路径
* 适配物联的暂态事件解析 物联那边事件的路径是全路径,不需要拼接,这个参数可为空
*/
private String wlFilePath;
}

View File

@@ -23,8 +23,13 @@ public class CauseStruct extends Structure {
public static class ByValue extends CauseStruct implements Structure.ByValue {
}
// @Override
// protected List<String> getFieldOrder() { // 返回值填入的顺序
// return Arrays.asList(new String[] { "cause", "no_cal" });
// }
@Override
protected List<String> getFieldOrder() { // 返回值填入的顺序
return Arrays.asList(new String[] { "cause", "no_cal" });
protected List<String> getFieldOrder() {
return Arrays.asList("smp_va", "smp_vb", "smp_vc", "smp_rate", "smp_len", "threshold", "cause", "no_cal");
}
}

View File

@@ -35,8 +35,13 @@ public class Rect extends Structure {
}
// @Override
// protected List<String> getFieldOrder() {
// return Arrays.asList(new String[] { "evt_num","evt_buf" });
// }
@Override
protected List<String> getFieldOrder() {
return Arrays.asList(new String[] { "evt_num","evt_buf" });
return Arrays.asList("smp_va", "smp_vb", "smp_vc", "smp_rate", "smp_len", "evt_num", "evt_buf");
}
}

View File

@@ -34,7 +34,6 @@ public class EventWaveAnalysisController extends BaseController {
private final EventWaveAnalysisService eventWaveAnalysisService;
@PostMapping("analysis")
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("波形高级分析")
@@ -43,6 +42,15 @@ public class EventWaveAnalysisController extends BaseController {
String methodDescribe = getMethodDescribe("analysis");
EntityAdvancedData entityAdvancedData = eventWaveAnalysisService.analysis(eventIndex);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, entityAdvancedData, methodDescribe);
}
@PostMapping("analysisWlEvent")
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("物联事件波形高级分析")
@ApiImplicitParam(name = "eventIndex", value = "暂降事件id", required = true)
public HttpResult<EntityAdvancedData> analysisWlEvent(@RequestParam("eventIndex") String eventIndex) {
String methodDescribe = getMethodDescribe("analysisWlEvent");
EntityAdvancedData entityAdvancedData = eventWaveAnalysisService.analysisWlEvent(eventIndex);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, entityAdvancedData, methodDescribe);
}
}

View File

@@ -48,11 +48,12 @@ public class EventAdvanceServiceImpl implements IEventAdvanceService {
public EventAnalysisDTO analysisCauseAndType(EventAnalysisDTO eventAnalysis) {
WaveDataDTO waveDataDTO;
String waveName = eventAnalysis.getWaveName();
String wlFilePath = eventAnalysis.getWlFilePath();
String cfgPath, datPath, cfgPath2, datPath2;
String ip = eventAnalysis.getIp();
if (generalInfo.getBusinessWaveFileStorage() == GeneralConstant.LOCAL_DISK) {
cfgPath = generalInfo.getBusinessWavePath() + File.separator + ip + File.separator + waveName + GeneralConstant.CFG;
datPath = generalInfo.getBusinessWavePath() + File.separator + ip + File.separator + waveName + GeneralConstant.DAT;
cfgPath = Objects.isNull(wlFilePath) ? generalInfo.getBusinessWavePath() + File.separator + ip + File.separator + waveName + GeneralConstant.CFG : wlFilePath + GeneralConstant.CFG;
datPath = Objects.isNull(wlFilePath) ? generalInfo.getBusinessWavePath() + File.separator + ip + File.separator + waveName + GeneralConstant.DAT : wlFilePath + GeneralConstant.DAT;
log.info("本地磁盘波形文件路径----" + cfgPath);
InputStream cfgStream = waveFileComponent.getFileInputStreamByFilePath(cfgPath);
InputStream datStream = waveFileComponent.getFileInputStreamByFilePath(datPath);
@@ -61,11 +62,11 @@ public class EventAdvanceServiceImpl implements IEventAdvanceService {
}
waveDataDTO = waveFileComponent.getComtrade(cfgStream, datStream, 0);
} else {
cfgPath = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.CFG;
datPath = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.DAT;
cfgPath = Objects.isNull(wlFilePath) ? OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.CFG : wlFilePath + GeneralConstant.CFG;
datPath = Objects.isNull(wlFilePath) ? OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.DAT : wlFilePath + GeneralConstant.DAT;
//适配文件后缀小写
cfgPath2 = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.CFG.toLowerCase();
datPath2 = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.DAT.toLowerCase();
cfgPath2 = Objects.isNull(wlFilePath) ? OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.CFG.toLowerCase() : wlFilePath + GeneralConstant.CFG.toLowerCase();
datPath2 = Objects.isNull(wlFilePath) ? OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.DAT.toLowerCase() : wlFilePath + GeneralConstant.DAT.toLowerCase();
log.info("文件服务器波形文件路径----" + cfgPath);
try (
InputStream cfgStream = fileStorageUtil.getFileStream(cfgPath);
@@ -127,9 +128,19 @@ public class EventAdvanceServiceImpl implements IEventAdvanceService {
}
}
String str = WriteData2File(typeDataStruct);
String hdrPath = OssPath.WAVE_DIR + ip+StrUtil.SLASH ;
String hdrName = waveName + GeneralConstant.HDR_LOWER;
fileStorageUtil.uploadStreamSpecifyName(new ByteArrayInputStream(str.getBytes()),hdrPath,hdrName);
if (Objects.isNull(wlFilePath)) {
String hdrPath = OssPath.WAVE_DIR + ip+StrUtil.SLASH;
String hdrName = waveName + GeneralConstant.HDR_LOWER;
fileStorageUtil.uploadStreamSpecifyName(new ByteArrayInputStream(str.getBytes()),hdrPath,hdrName);
} else {
// comtrade/00:B7:8D:00:A8:7A/PQMonitor_PQM1_00100_20260204_162453_071_WAV.hdr
String fullPath = wlFilePath + GeneralConstant.HDR_LOWER;
int lastSlashIndex = fullPath.lastIndexOf('/');
String hdrPath = fullPath.substring(0, lastSlashIndex + 1);
String hdrName = fullPath.substring(lastSlashIndex + 1);
fileStorageUtil.uploadStreamSpecifyName(new ByteArrayInputStream(str.getBytes()),hdrPath,hdrName);
}
//上传HR
eventAnalysis.setType(globalFaultType);
} else {

View File

@@ -11,4 +11,6 @@ import com.njcn.advance.pojo.dto.waveAnalysis.EntityAdvancedData;
public interface EventWaveAnalysisService {
EntityAdvancedData analysis(String eventIndex);
EntityAdvancedData analysisWlEvent(String eventIndex);
}

View File

@@ -6,9 +6,11 @@ import cn.hutool.core.util.StrUtil;
import com.njcn.advance.enums.EnumEvt;
import com.njcn.advance.mapper.RmpEventAdvanceMapper;
import com.njcn.advance.pojo.dto.waveAnalysis.*;
import com.njcn.advance.service.EventWaveAnalysisService;
import com.njcn.advance.utils.*;
import com.njcn.advance.utils.JnaCallBalance;
import com.njcn.advance.utils.JnaCallDllOrSo;
import com.njcn.advance.utils.Utils;
import com.njcn.advance.utils.WaveUtils;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.PubUtils;
import com.njcn.device.pq.api.LineFeignClient;
@@ -26,7 +28,10 @@ import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -170,17 +175,13 @@ public class EventWaveAnalysisServiceImpl implements EventWaveAnalysisService {
causeStruct.smp_len = pitchList.size();
causeStruct.smp_rate = (int) wavePitchData.getnOneWaveNum();
String hdrStr = waveUtils.getFile(OssPath.WAVE_DIR + lineDetailDataVO.getIp() + StrUtil.SLASH + rmpEventDetailPO.getWavePath() + GeneralConstant.HDR);
JSONObject jsonObject = JSONObject.fromObject(hdrStr);
translateData(jsonObject, rmpEventDetailPO.getStartTime(), entityAdvancedData);
if (rmpEventDetailPO.getDealFlag() != 1) {
//如果存在三个文件但是没有调用dll/so计算
getDataFromDLL(rmpEventDetailPO, waveOriginalData, rect, entityAdvancedData, causeStruct);
}
@@ -214,6 +215,159 @@ public class EventWaveAnalysisServiceImpl implements EventWaveAnalysisService {
return entityAdvancedData;
}
@Override
public EntityAdvancedData analysisWlEvent(String eventIndex) {
TimeInterval timeInterval = new TimeInterval();
//调用方法获取暂降事件详情
RmpEventDetailPO rmpEventDetailPO = rmpEventAdvanceMapper.selectById(eventIndex);
EntityAdvancedData entityAdvancedData;
if (rmpEventDetailPO.getFileFlag() == 1) {
//获取所有暂态原因
List<DictData> dicDataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.EVENT_TYPE.getCode()).getData();
Map<Integer, DictData> eventTypeMap = dicDataList.stream().collect(Collectors.toMap(DictData::getAlgoDescribe, Function.identity()));
InputStream inputStreamCfg;
InputStream inputStreamDat;
try {
inputStreamCfg = fileStorageUtil.getFileStream(rmpEventDetailPO.getWavePath()+ GeneralConstant.CFG);
inputStreamDat = fileStorageUtil.getFileStream(rmpEventDetailPO.getWavePath() + GeneralConstant.DAT);
} catch (Exception e) {
try {
inputStreamCfg = fileStorageUtil.getFileStream(rmpEventDetailPO.getWavePath() + GeneralConstant.CFG.toLowerCase());
inputStreamDat = fileStorageUtil.getFileStream(rmpEventDetailPO.getWavePath() + GeneralConstant.DAT.toLowerCase());
} catch (Exception e1) {
throw new BusinessException("暂降cfg,dat文件缺失,请联系管理员");
}
}
//读取
BufferedReader bufferedReader;
InputStreamReader read = null;
String strFileLine;
byte[] array = {};
List<String> temCfgList = new ArrayList<>();
try {
// 判断文件是否存在
array = IoUtil.readBytes(inputStreamDat);
// 考虑到编码格式
read = new InputStreamReader(inputStreamCfg, StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(read);
while ((strFileLine = bufferedReader.readLine()) != null) {
temCfgList.add(strFileLine);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (read != null) {
read.close();
}
if (inputStreamDat != null) {
inputStreamDat.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
//原始波形
WaveData waveOriginalData = getWavedata(rmpEventDetailPO, temCfgList, array, 3);
List<List<Float>> originalList = waveOriginalData.getSunData();
entityAdvancedData = new EntityAdvancedData(originalList.size());
for (int i = 0; i < originalList.size(); i++) {
//坐标轴
entityAdvancedData.smp_x[i] = originalList.get(i).get(0);
entityAdvancedData.smp_a[i] = originalList.get(i).get(1);
entityAdvancedData.smp_b[i] = originalList.get(i).get(2);
entityAdvancedData.smp_c[i] = originalList.get(i).get(3);
}
entityAdvancedData.smp_len = originalList.size();
//抽点方法计算波形
WaveData wavePitchData = getWavedata(rmpEventDetailPO, temCfgList, array, 0);
List<List<Float>> pitchList = wavePitchData.getSunData();
// 将获取到的数据填充到结构体内
Rect rect = new Rect();
CauseStruct causeStruct = new CauseStruct();
for (int i = 0; i < pitchList.size(); i++) {
rect.smp_va[i] = pitchList.get(i).get(1);
causeStruct.smp_va[i] = pitchList.get(i).get(1);
rect.smp_vb[i] = pitchList.get(i).get(2);
causeStruct.smp_vb[i] = pitchList.get(i).get(2);
rect.smp_vc[i] = pitchList.get(i).get(3);
causeStruct.smp_vc[i] = pitchList.get(i).get(3);
}
rect.smp_len = pitchList.size();
//超过60s的波形直接抛异常给上面处理
/*
* 波形最大值计算
*/
int MAX_LENGTH = 128 * 3000;
if (rect.smp_len >= MAX_LENGTH) {
throw new BusinessException("波形超过60S");
}
rect.smp_rate = (int) wavePitchData.getnOneWaveNum();
causeStruct.smp_len = pitchList.size();
causeStruct.smp_rate = (int) wavePitchData.getnOneWaveNum();
if (rmpEventDetailPO.getDealFlag() != 1) {
//如果存在三个文件但是没有调用dll/so计算
getDataFromDLL(rmpEventDetailPO, waveOriginalData, rect, entityAdvancedData, causeStruct);
}
String hdrStr = null;
try {
hdrStr = waveUtils.getFile(rmpEventDetailPO.getWavePath() + GeneralConstant.HDR.toLowerCase());
} catch (Exception e) {
log.error("读取文件服务器波形数据异常:{}",e.getMessage());
}
if (hdrStr != null) {
JSONObject jsonObject = JSONObject.fromObject(hdrStr);
translateData(jsonObject, rmpEventDetailPO.getStartTime(), entityAdvancedData);
}
// if (rmpEventDetailPO.getDealFlag() != 1) {
// //如果存在三个文件但是没有调用dll/so计算
// getDataFromDLL(rmpEventDetailPO, waveOriginalData, rect, entityAdvancedData, causeStruct);
// }
/****************************************************************
* 根据返回的结果计算,获取暂降类型描述
****************************************************************/
if (entityAdvancedData.backNumber > 0) {
for (int i = 0; i < entityAdvancedData.backNumber; i++) {
entityAdvancedData.sagType[i] = eventTypeMap.get(entityAdvancedData.evt_buf[i].qvvr_cata_type[0]).getName();
switch (entityAdvancedData.evt_buf[i].qvvr_phasetype[0]) {
case 1:
entityAdvancedData.sagPhaseType[i] = "单相";
break;
case 2:
entityAdvancedData.sagPhaseType[i] = "两相";
break;
case 3:
entityAdvancedData.sagPhaseType[i] = "三相";
break;
default:
break;
}
}
}
} else {
throw new BusinessException("暂降cfg,dat文件缺失,请联系管理员");
}
log.info("高级算法波形计算" + timeInterval.interval());
return entityAdvancedData;
}
/**
* 事件未进行高级算法处理系统调用dll处理并保存结果
@@ -358,7 +512,7 @@ public class EventWaveAnalysisServiceImpl implements EventWaveAnalysisService {
if (StrUtil.isBlank(rmpEventDetailPOQuery.getAdvanceReason())) {
//暂降原因计算
JnaCallDllOrSo jnaCallDllReason = new JnaCallBalance("qvvr_dll_cause");
JnaCallDllOrSo jnaCallDllReason = new JnaCallBalance("qvvr_cause_dll");
jnaCallDllReason.setPath();
JnaCallBalance.Balancelibrary CAUSE = JnaCallBalance.Balancelibrary.INSTANTCE;