项目集成华为obs查看波形文件

This commit is contained in:
2023-03-06 16:03:57 +08:00
parent 7dd90fbe0d
commit c2c3fd9fd6
32 changed files with 938 additions and 927 deletions

View File

@@ -72,6 +72,18 @@
<artifactId>pq-device-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>huawei-obs-springboot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
<build>

View File

@@ -3,7 +3,6 @@ package com.njcn.event.controller.majornetwork;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.dto.wave.WaveDataDTO;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
@@ -202,24 +201,6 @@ public class MonitorPointController extends BaseController {
/**
*监测点事件波形分析
* @author zbj
* @date 2022/7/27
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getMonitorEventAnalyseWave")
@ApiOperation("监测点事件波形分析")
@ApiImplicitParams({
@ApiImplicitParam(name = "timeId", value = "时间Id", required = true),
@ApiImplicitParam(name = "lineId", value = "监测点Id", required = true)
})
public HttpResult<WaveDataDTO> getMonitorEventAnalyseWave(@RequestParam("timeId") String timeId, @RequestParam("lineId") String lineId){
String methodDescribe = getMethodDescribe("getMonitorEventAnalyseWave");
WaveDataDTO wave = eventAnalysisService.getMonitorEventAnalyseWave(timeId, lineId);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, wave, methodDescribe);
}
/**
*监测点事件波形下载
* @author zbj

View File

@@ -3,11 +3,11 @@ package com.njcn.event.controller.majornetwork;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.dto.wave.WaveDataDTO;
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.event.pojo.dto.wave.WaveDataDTO;
import com.njcn.event.pojo.param.TransientParam;
import com.njcn.event.pojo.param.WaveFileParam;
import com.njcn.event.pojo.po.EventDetailNew;

View File

@@ -1,7 +1,7 @@
package com.njcn.event.service.majornetwork;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.dto.wave.WaveDataDTO;
import com.njcn.event.pojo.dto.wave.WaveDataDTO;
import com.njcn.event.pojo.param.*;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.vo.*;
@@ -82,12 +82,7 @@ public interface EventAnalysisService {
*/
Page<WaveTypeVO> getMonitorEventAnalyseQuery(EventBaseParam eventBaseParam);
/**
*监测点事件波形分析
* @author zbj
* @date 2022/7/27
*/
WaveDataDTO getMonitorEventAnalyseWave(String timeId, String lineId);
/**
*监测点事件波形下载

View File

@@ -4,16 +4,15 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.config.GeneralInfo;
import com.njcn.common.pojo.dto.wave.WaveDataDTO;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.PubUtils;
import com.njcn.common.utils.wave.AnalyWave;
import com.njcn.device.pq.api.LineFeignClient;
import com.njcn.device.pq.pojo.vo.AreaLineInfoVO;
import com.njcn.device.pq.pojo.vo.LineDetailDataVO;
import com.njcn.event.enums.EventResponseEnum;
import com.njcn.event.pojo.constant.Param;
import com.njcn.event.pojo.dto.wave.WaveDataDTO;
import com.njcn.event.pojo.param.*;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.po.EventDetailNew;
@@ -1627,55 +1626,6 @@ public class EventAnalysisServiceImpl implements EventAnalysisService {
}
/**
* 监测点事件波形分析
*
* @author zbj
* @date 2022/7/27
*/
@Override
public WaveDataDTO getMonitorEventAnalyseWave(String timeId, String lineId) {
WaveDataDTO waveDataDTO = new WaveDataDTO();
//根据监测点id获取监测点详情
LineDetailDataVO lineDetailData = lineFeignClient.getLineDetailData(lineId).getData();
EventDetail eventDetailByTime = eventDetailService.getEventDetailByTime(lineId, timeId);
//暂时没有进行拼接
String ip = lineDetailData.getIp();
String waveName = eventDetailByTime.getWaveName();
/* if(StrUtil.isBlank(waveName)){
throw new BusinessException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND);
}*/
AnalyWave analyWave = new AnalyWave();
/*WaveDataDTO comtrade = analyWave.getComtrade(generalInfo.getBusinessWavePath() + File.separator + ip + File.separator + waveName + ".CFG", 1);
if (Objects.isNull(comtrade.getComtradeCfgDTO())) {
throw new BusinessException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND);
}*/
//测试用的本地路径
WaveDataDTO comtrade = analyWave.getComtrade("C:\\Users\\CDF\\Desktop\\00-B7-8D-00-E7-15\\1_20220204_125513_383.cfg", 1);
waveDataDTO = analyWave.getValidData(comtrade);
waveDataDTO.setPtType(PubUtils.ptTypeName(lineDetailData.getPtType()));
double pt1 = Double.parseDouble(lineDetailData.getPt().split("/")[0]);
double pt2 = Double.parseDouble(lineDetailData.getPt().split("/")[1]);
double ct1 = Double.parseDouble(lineDetailData.getCt().split("/")[0]);
double ct2 = Double.parseDouble(lineDetailData.getCt().split("/")[1]);
waveDataDTO.setPt(pt1 / pt2);
waveDataDTO.setCt(ct1 / ct2);
return waveDataDTO;
}
/**

View File

@@ -118,7 +118,7 @@ public class EventDetailServiceImpl implements EventDetailService {
}
stringBuilder.append(") order by time desc");
int i = (pageNum - 1)*pageSize;
stringBuilder.append("LIMIT ").append(pageSize).append(" OFFSET ").append(i).append(" tz('Asia/Shanghai')");
stringBuilder.append(" LIMIT ").append(pageSize).append(" OFFSET ").append(i).append(" tz('Asia/Shanghai')");
//sql语句
String sql = "SELECT * FROM pqs_eventdetail WHERE " + stringBuilder;
System.out.println(sql);

View File

@@ -5,11 +5,11 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.config.GeneralInfo;
import com.njcn.common.pojo.dto.wave.WaveDataDTO;
import com.njcn.common.pojo.constant.GeneralConstant;
import com.njcn.common.pojo.constant.OssPath;
import com.njcn.common.pojo.enums.common.ServerEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.PubUtils;
import com.njcn.common.utils.wave.AnalyWave;
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
import com.njcn.device.pq.api.LineFeignClient;
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
@@ -17,6 +17,7 @@ import com.njcn.device.pq.pojo.vo.AreaLineInfoVO;
import com.njcn.device.pq.pojo.vo.LineDetailDataVO;
import com.njcn.event.enums.EventResponseEnum;
import com.njcn.event.mapper.majornetwork.TransientMapper;
import com.njcn.event.pojo.dto.wave.WaveDataDTO;
import com.njcn.event.pojo.param.TransientParam;
import com.njcn.event.pojo.param.WaveFileParam;
import com.njcn.event.pojo.po.EventDetail;
@@ -24,6 +25,8 @@ import com.njcn.event.pojo.po.EventDetailNew;
import com.njcn.event.pojo.vo.TransientVO;
import com.njcn.event.service.majornetwork.EventDetailService;
import com.njcn.event.service.majornetwork.TransientService;
import com.njcn.event.utils.WaveUtil;
import com.njcn.huawei.obs.util.OBSUtil;
import com.njcn.influxdb.mapper.InfluxDBResultMapperCn;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDBCommUtils;
@@ -75,6 +78,11 @@ public class TransientServiceImpl implements TransientService {
private final InfluxDbUtils influxDbUtils;
private final OBSUtil obsUtil;
private final WaveUtil waveUtil;
@Override
public Page<TransientVO> getTransientData(TransientParam transientParam) {
Page<TransientVO> page = new Page<>();
@@ -86,7 +94,7 @@ public class TransientServiceImpl implements TransientService {
List<GeneralDeviceDTO> deviceList = generalDeviceInfoClient.getPracticalRunDeviceInfo(transientParam).getData();
if (!CollectionUtils.isEmpty(deviceList)) {
//获取按终端分类的监测点索引集合
List<String> LineIndexes = deviceList.stream().flatMap(list->list.getLineIndexes().stream()).collect(Collectors.toList());
List<String> LineIndexes = deviceList.stream().flatMap(list -> list.getLineIndexes().stream()).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(LineIndexes)) {
//influxDB查询待分页数据总量
@@ -96,7 +104,7 @@ public class TransientServiceImpl implements TransientService {
int pages = (int) Math.ceil(data.size() * 1.0 / transientParam.getPageSize());
page.setPages(pages);*/
//influxDB分页查询
List<EventDetail> eventDetailData = eventDetailService.getEventDetailLimit(LineIndexes, transientParam.getSearchBeginTime(), transientParam.getSearchEndTime(), transientParam.getPageSize(), transientParam.getPageNum(),transientParam.getWaveType());
List<EventDetail> eventDetailData = eventDetailService.getEventDetailLimit(LineIndexes, transientParam.getSearchBeginTime(), transientParam.getSearchEndTime(), transientParam.getPageSize(), transientParam.getPageNum(), transientParam.getWaveType());
if (!CollectionUtils.isEmpty(eventDetailData)) {
List<String> lineIds = eventDetailData.stream().map(EventDetail::getLineId).collect(Collectors.toList());
@@ -168,23 +176,47 @@ public class TransientServiceImpl implements TransientService {
@Override
public WaveDataDTO getTransientAnalyseWave(String timeId, String lineId) {
WaveDataDTO waveDataDTO;
//原始数据
WaveDataDTO originalData;
//根据监测点id获取监测点详情
LineDetailDataVO lineDetailData = lineFeignClient.getLineDetailData(lineId).getData();
EventDetail eventDetailByTime = eventDetailService.getEventDetailByTime(lineId, timeId);
String ip = lineDetailData.getIp();
String waveName = eventDetailByTime.getWaveName();
AnalyWave analyWave = new AnalyWave();
// 从本地读取该事件的波形
WaveDataDTO comtrade = analyWave.getComtrade(generalInfo.getBusinessWavePath() + File.separator + ip + File.separator + waveName + ".CFG", 1);
if (Objects.isNull(comtrade.getComtradeCfgDTO())) {
throw new BusinessException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND);
String cfgPath, datPath;
if (generalInfo.getBusinessFileStorage() == 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;
InputStream cfgStream = waveUtil.getFileInputStreamByFilePath(cfgPath);
InputStream datStream = waveUtil.getFileInputStreamByFilePath(datPath);
if (Objects.isNull(cfgStream) || Objects.isNull(datStream)) {
throw new BusinessException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND);
}
originalData = waveUtil.getComtrade(cfgStream, datStream, 1);
// } else if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
} else {
ip = "192.168.1.190";
waveName = "PQMonitor_PQM1_002438_20210508_092859_938";
cfgPath = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.CFG;
datPath = OssPath.WAVE_DIR + ip + StrUtil.SLASH + waveName + GeneralConstant.DAT;
try (
InputStream cfgStream = obsUtil.fileDownload(cfgPath);
InputStream datStream = obsUtil.fileDownload(datPath)
) {
if (Objects.isNull(cfgStream) || Objects.isNull(datStream)) {
throw new BusinessException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND);
}
originalData = waveUtil.getComtrade(cfgStream, datStream, 1);
} catch (IOException e) {
throw new BusinessException(EventResponseEnum.WAVE_DATA_INVALID);
}
}
waveDataDTO = analyWave.getValidData(comtrade);
waveDataDTO = waveUtil.getValidData(originalData);
waveDataDTO.setPtType(PubUtils.ptTypeName(lineDetailData.getPtType()));
double pt1 = Double.parseDouble(lineDetailData.getPt().split("/")[0]);
double pt2 = Double.parseDouble(lineDetailData.getPt().split("/")[1]);
double ct1 = Double.parseDouble(lineDetailData.getCt().split("/")[0]);
double ct2 = Double.parseDouble(lineDetailData.getCt().split("/")[1]);
double pt1 = Double.parseDouble(lineDetailData.getPt().split(StrUtil.SLASH)[0]);
double pt2 = Double.parseDouble(lineDetailData.getPt().split(StrUtil.SLASH)[1]);
double ct1 = Double.parseDouble(lineDetailData.getCt().split(StrUtil.SLASH)[0]);
double ct2 = Double.parseDouble(lineDetailData.getCt().split(StrUtil.SLASH)[1]);
waveDataDTO.setPt(pt1 / pt2);
waveDataDTO.setCt(ct1 / ct2);
return waveDataDTO;
@@ -227,7 +259,7 @@ public class TransientServiceImpl implements TransientService {
}
@Override
public Page<EventDetailNew> getTransientValue(TransientParam transientParam){
public Page<EventDetailNew> getTransientValue(TransientParam transientParam) {
Page<EventDetailNew> page = new Page<>();
page.setSize(transientParam.getPageSize());
page.setCurrent(transientParam.getPageNum());
@@ -241,7 +273,7 @@ public class TransientServiceImpl implements TransientService {
if (!CollectionUtils.isEmpty(lineList)) {
StringBuilder stringBuilder = InfluxDBCommUtils.assToInfluxParam(lineList);
//influxDB查询待分页数据总量
Long total = getTransientDetail(stringBuilder,transientParam);
Long total = getTransientDetail(stringBuilder, transientParam);
page.setTotal(total);
//分页总页数
int pages = (int) Math.ceil(transientParam.getPageNum() * 1.0 / transientParam.getPageSize());
@@ -259,8 +291,8 @@ public class TransientServiceImpl implements TransientService {
for (EventDetailNew eventDetail : eventDetailData) {
for(AreaLineInfoVO areaLineInfoVO : r){
if(eventDetail.getLineId().equals(areaLineInfoVO.getLineId())){
for (AreaLineInfoVO areaLineInfoVO : r) {
if (eventDetail.getLineId().equals(areaLineInfoVO.getLineId())) {
eventDetail.setLineId(areaLineInfoVO.getLineId());
eventDetail.setLineName(areaLineInfoVO.getLineName());
eventDetail.setGdName(areaLineInfoVO.getGdName());
@@ -301,22 +333,22 @@ public class TransientServiceImpl implements TransientService {
/**
* 查询数据库
*/
private Long getTransientDetail(StringBuilder stringBuilder,TransientParam transientParam) {
private Long getTransientDetail(StringBuilder stringBuilder, TransientParam transientParam) {
Long total = 0L;
//组装sql语句
stringBuilder.append(" and time >= '").append(DateUtil.beginOfDay(DateUtil.parse(transientParam.getSearchBeginTime()))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(transientParam.getSearchEndTime()))).append("'").append(InfluxDBPublicParam.TIME_ZONE);
//sql语句
String sql = "SELECT count(wave_type) FROM pqs_eventdetail WHERE " + stringBuilder;
System.out.println("sql------------->>>"+sql);
System.out.println("sql------------->>>" + sql);
//结果集
QueryResult result = influxDbUtils.query(sql);
//结果集映射到对象中
List<QueryResult.Series> series = result.getResults().get(0).getSeries();
if(CollUtil.isNotEmpty(series)){
Double tem =(Double)series.get(0).getValues().get(0).get(1);
if (CollUtil.isNotEmpty(series)) {
Double tem = (Double) series.get(0).getValues().get(0).get(1);
total = tem.longValue();
}
return total;
return total;
}
/**
@@ -325,31 +357,31 @@ public class TransientServiceImpl implements TransientService {
private List<EventDetailNew> getTransientDetailLimit(List<String> lineIndexes, TransientParam transientParam) {
//查询数据是否为空不为空拼接sql语句
StringBuilder querySql = new StringBuilder();
if(Objects.nonNull(transientParam.getEventValueMin())){
if (Objects.nonNull(transientParam.getEventValueMin())) {
querySql.append(" and event_value >=").append(transientParam.getEventValueMin());
}
if(Objects.nonNull(transientParam.getEventValueMax())){
if (Objects.nonNull(transientParam.getEventValueMax())) {
querySql.append(" and event_value <=").append(transientParam.getEventValueMax());
}
if(Objects.nonNull(transientParam.getPersistMin())){
if (Objects.nonNull(transientParam.getPersistMin())) {
querySql.append(" and persist_time >=").append(transientParam.getPersistMin());
}
if(Objects.nonNull(transientParam.getEventValueMax())){
if (Objects.nonNull(transientParam.getEventValueMax())) {
querySql.append(" and persist_time <=").append(transientParam.getPersistMax());
}
if(Objects.nonNull(transientParam.getSeverityMin())){
if (Objects.nonNull(transientParam.getSeverityMin())) {
querySql.append(" and severity >=").append(transientParam.getSeverityMin());
}
if(Objects.nonNull(transientParam.getSeverityMax())){
if (Objects.nonNull(transientParam.getSeverityMax())) {
querySql.append(" and severity <=").append(transientParam.getSeverityMax());
}
if(Objects.nonNull(transientParam.getFileFlag())){
if (Objects.nonNull(transientParam.getFileFlag())) {
querySql.append(" and file_flag = ").append(transientParam.getFileFlag());
}
if(CollUtil.isNotEmpty(transientParam.getWaveType())) {
if (CollUtil.isNotEmpty(transientParam.getWaveType())) {
querySql.append(" and ( ");
for (int i = 0; i < transientParam.getWaveType().size(); i++) {
if (transientParam.getWaveType().size() - i != 1) {
@@ -359,7 +391,7 @@ public class TransientServiceImpl implements TransientService {
}
}
}
if(CollUtil.isNotEmpty(transientParam.getEventReason())) {
if (CollUtil.isNotEmpty(transientParam.getEventReason())) {
querySql.append(" and ( ");
for (int i = 0; i < transientParam.getEventReason().size(); i++) {
if (transientParam.getWaveType().size() - i != 1) {
@@ -369,7 +401,7 @@ public class TransientServiceImpl implements TransientService {
}
}
}
if(CollUtil.isNotEmpty(transientParam.getEventType())) {
if (CollUtil.isNotEmpty(transientParam.getEventType())) {
querySql.append(" and ( ");
for (int i = 0; i < transientParam.getEventType().size(); i++) {
if (transientParam.getEventType().size() - i != 1) {
@@ -393,8 +425,8 @@ public class TransientServiceImpl implements TransientService {
stringBuilder.append("line_id ='").append(lineIndexes.get(i)).append("') ");
}
}
int i = (transientParam.getPageNum() - 1)*transientParam.getPageSize();
stringBuilder.append("LIMIT ").append(transientParam.getPageSize()).append(" OFFSET ").append(i).append(" tz('Asia/Shanghai')");
int i = (transientParam.getPageNum() - 1) * transientParam.getPageSize();
stringBuilder.append(" LIMIT ").append(transientParam.getPageSize()).append(" OFFSET ").append(i).append(" tz('Asia/Shanghai')");
//sql语句
String sql = "SELECT * FROM pqs_eventdetail WHERE " + stringBuilder;

View File

@@ -1,7 +1,7 @@
package com.njcn.event.service.majornetwork;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.dto.wave.WaveDataDTO;
import com.njcn.event.pojo.dto.wave.WaveDataDTO;
import com.njcn.event.pojo.param.TransientParam;
import com.njcn.event.pojo.param.WaveFileParam;
import com.njcn.event.pojo.po.EventDetail;

View File

@@ -0,0 +1,81 @@
package com.njcn.event.utils;
public class BitConverter {
/**
* byte数组转换为无符号short整数
* @param bytes byte数组
* @param off 开始位置
* @return short整数
*/
public static short byte2ToUnsignedShort(byte[] bytes, int off) {
int low = bytes[off]& 0xFF;
int high = bytes[off + 1]& 0xFF;
return (short)(((high & 0x00FF) << 8) | (0x00FF & low));
}
/**
* 字节转换为浮点
*
* @param b 字节至少4个字节
* @param index 开始位置
* @return
*/
public static float byte4float(byte[] b, int index) {
/* b=new byte[4];
b[0]=-16;
b[1]=-1;
b[2]=117;
b[3]=66;*/
int l;
l = b[index + 0];
l &= 0xff;
l |= ((long) b[index + 1] << 8);
l &= 0xffff;
l |= ((long) b[index + 2] << 16);
l &= 0xffffff;
l |= ((long) b[index + 3] << 24);
return Float.intBitsToFloat(l);
}
/**
* byte数组转换为int32整数
* @param bytes byte数组
* @param off 开始位置
* @return int整数
*/
public static int byte4ToInt(byte[] bytes, int off) {
int b0 = bytes[off] & 0xFF;
int b1 = bytes[off + 1] & 0xFF;
int b2 = bytes[off + 2] & 0xFF;
int b3 = bytes[off + 3] & 0xFF;
return (b3 << 24) | (b2 << 16) | (b1 << 8) | b0;
}
/**
* byte数组转换为int16整数
* @param bytes byte数组
* @param off 开始位置
* @return int整数
*/
public static int byte2ToInt(byte[] bytes, int off) {
int b0 = bytes[off] & 0xFF;
int b1 = bytes[off + 1] & 0xFF;
return (b1 << 8) | b0;
}
/**
* byte数组转换为int16整数
* @param bytes byte数组
* @param off 开始位置
* @return int整数
*/
public static long byte4ToLong(byte[] bytes, int off) {
long b0 = bytes[off] & 0xFF;
long b1 = bytes[off + 1] & 0xFF;
long b2 = bytes[off + 2] & 0xFF;
long b3 = bytes[off + 3] & 0xFF;
return (b3 << 24) | (b2 << 16) | (b1 << 8) | b0;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -44,3 +44,4 @@ mybatis-plus:
type-aliases-package: com.njcn.event.pojo
mqtt:
client-id: @artifactId@${random.value}

View File

@@ -1,8 +1,14 @@
package com.njcn.event;
import com.njcn.common.pojo.constant.OssPath;
import com.njcn.event.enums.EventResponseEnum;
import com.njcn.event.pojo.PqsEventDetail;
import com.njcn.event.pojo.PqsOnlinerateAggregate;
import com.njcn.event.pojo.PqsEventDetailCount;
import com.njcn.event.pojo.dto.wave.EigenvalueDTO;
import com.njcn.event.pojo.dto.wave.WaveDataDTO;
import com.njcn.event.utils.WaveUtil;
import com.njcn.huawei.obs.util.OBSUtil;
import com.njcn.influxdb.config.InfluxDbConfig;
import com.njcn.influxdb.utils.InfluxDbUtils;
import org.influxdb.dto.QueryResult;
@@ -20,8 +26,14 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import static com.njcn.influxdb.param.InfluxDBPublicParam.PQS_EVENT_DETAIL;
@@ -39,79 +51,85 @@ public class EventBootApplicationTest {
@Autowired
private InfluxDbUtils influxDbUtils;
@Autowired
private WaveUtil waveUtil;
@Autowired
private OBSUtil obsUtil;
// TODO https://github.com/influxdata/influxdb-java/blob/master/QUERY_BUILDER.md
@Test
public void queryList() {
// or 条件数据
List<Clause> clauses = getClauses();
SelectQueryImpl selectQuery = select().column("line_id").column("eventass_index").from(influxDbConfig.getDatabase(), PQS_EVENT_DETAIL);
WhereQueryImpl<SelectQueryImpl> where = selectQuery.where();
// WHERE (line_id = '1' OR line_id = '2' OR line_id = '3') 加上前后()
whereAndNested(clauses, where);
// AND time >= '2022-05-01T00:00:00Z' AND time <= '2022-09-01T00:00:00Z' tz('Asia/Shanghai');
where.and(gte("time", "2022-05-01T00:00:00Z")).and(lte("time", "2022-09-01T00:00:00Z"));
where.tz("Asia/Shanghai");
QueryResult result = influxDbUtils.query(selectQuery.getCommand());
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<PqsEventDetail> re = influxDBResultMapper.toPOJO(result, PqsEventDetail.class);
Assert.assertTrue(re.size() > 0);
}
@Test
public void queryCount() {
// or 条件数据
List<Clause> clauses = getClauses();
SelectQueryImpl selectQuery = select().count("eventass_index").from(influxDbConfig.getDatabase(), PQS_EVENT_DETAIL);
WhereQueryImpl<SelectQueryImpl> where = selectQuery.where();
// WHERE (line_id = '1' OR line_id = '2' OR line_id = '3') 加上前后()
whereAndNested(clauses, where);
// AND time >= '2022-05-01T00:00:00Z' AND time <= '2022-09-01T00:00:00Z' tz('Asia/Shanghai');
where.and(gte("time", "2022-05-01T00:00:00Z")).and(lte("time", "2022-09-01T00:00:00Z"));
where.tz("Asia/Shanghai");
QueryResult result = influxDbUtils.query(selectQuery.getCommand());
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<PqsEventDetailCount> re = influxDBResultMapper.toPOJO(result, PqsEventDetailCount.class);
Assert.assertTrue(re.size() > 0);
}
@Test
public void queryAggregate() {
// SELECT (SUM(onlinemin) / (SUM(onlinemin) + SUM(offlinemin))) * 100 FROM pqs_onlinerate
SelectionQueryImpl select = select();
SelectionQueryImpl sum = select.op(op(sum("onlinemin"), "/", op(sum("onlinemin"), "+", sum("offlinemin"))), "*", 100)
.as("value");
SelectQueryImpl selectQuery = sum.from(influxDbConfig.getDatabase(), "pqs_onlinerate");
WhereQueryImpl<SelectQueryImpl> where = selectQuery.where();
// AND time >= '2022-05-01T00:00:00Z' AND time <= '2022-09-01T00:00:00Z' tz('Asia/Shanghai');
where.and(gte("time", "2022-05-01T00:00:00Z")).and(lte("time", "2022-09-01T00:00:00Z"));
where.tz("Asia/Shanghai");
QueryResult result = influxDbUtils.query(selectQuery.getCommand());
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<PqsOnlinerateAggregate> re = influxDBResultMapper.toPOJO(result, PqsOnlinerateAggregate.class);
Assert.assertTrue(re.size() > 0);
}
private List<Clause> getClauses() {
Clause c1 = eq("line_id", "5e467a40023b299070682eb21f2ec9a1");
Clause c2 = eq("line_id", "183245996f303ebfd80eeb3377cecdc2");
Clause c3 = eq("line_id", "0d46f54420246e999d5c68b3133f668c");
return Arrays.asList(c1, c2, c3);
}
private void whereAndNested(List<Clause> clauses, WhereQueryImpl<SelectQueryImpl> whereQuery) {
WhereNested<WhereQueryImpl<SelectQueryImpl>> andNested = whereQuery.andNested();
for (Clause clause : clauses) {
@@ -119,5 +137,29 @@ public class EventBootApplicationTest {
}
andNested.close();
}
@Test
public void testHuaweiOBS() throws FileNotFoundException {
String cfgPath = OssPath.WAVE_DIR+"192.168.1.190/PQMonitor_PQM1_002438_20210508_092859_938.CFG";
String datPath = OssPath.WAVE_DIR+"192.168.1.190/PQMonitor_PQM1_002438_20210508_092859_938.DAT";
InputStream cfgStream =obsUtil.fileDownload(cfgPath);
InputStream datStream =obsUtil.fileDownload(datPath);
if(Objects.isNull(cfgStream) || Objects.isNull(datStream)){
throw new FileNotFoundException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND.getMessage());
}
// 获取瞬时波形 //获取原始波形值
WaveDataDTO waveDataDTO = waveUtil.getComtrade(cfgStream,datStream, 1);
// 获取RMS波形
WaveDataDTO waveDataDTO1 = waveUtil.getValidData(waveDataDTO);
// 获取特征值
List<EigenvalueDTO> lstEigenvalueDTO = waveUtil.getEigenvalue(waveDataDTO, true);
System.out.println(1);
}
}