refactor(data): 优化数据处理逻辑并修复设备数据查询

- 在CsEventPOServiceImpl中使用Optional处理pt2Ratio和ct2Ratio字段,避免空指针异常
- 修正waveDataDTO中PT和CT比率计算,使用ptRatio/pt2Ratio和ctRatio/ct2Ratio公式
- 修复StableDataServiceImpl中设备数据查询条件,将name字段检查改为otherName字段
- 重构StableDataServiceImpl中的数据映射逻辑,直接通过lineId获取对应数据列表
- 简化ThdDataVO转换过程,移除不必要的循环和条件判断
- 移除CsEventUserPOMapper.xml中多余的空行,保持代码整洁
This commit is contained in:
xy
2026-06-17 15:39:15 +08:00
parent 9438f75c01
commit 870ace35cb
3 changed files with 81 additions and 40 deletions

View File

@@ -277,7 +277,6 @@
<if test="csEventUserQueryPage!=null and csEventUserQueryPage.eventType != null and csEventUserQueryPage.eventType !=''">
AND b.tag = #{csEventUserQueryPage.eventType}
</if>
<if test="csEventUserQueryPage!=null and csEventUserQueryPage.location != null and csEventUserQueryPage.location !=''">
AND b.location = #{csEventUserQueryPage.location}
</if>

View File

@@ -884,8 +884,11 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
throw new BusinessException(AlgorithmResponseEnum.LINE_DATA_MISS);
}
waveDataDTO.setPtType(csLinePOList.get(0).getConType());
waveDataDTO.setPt(csLinePOList.get(0).getPtRatio());
waveDataDTO.setCt(csLinePOList.get(0).getCtRatio());
CsLinePO firstLine = csLinePOList.get(0);
double pt2Ratio = Optional.ofNullable(firstLine.getPt2Ratio()).orElse(1.0);
waveDataDTO.setPt(firstLine.getPtRatio() / pt2Ratio);
double ct2Ratio = Optional.ofNullable(firstLine.getCt2Ratio()).orElse(1.0);
waveDataDTO.setCt(firstLine.getCtRatio() / ct2Ratio);
waveDataDTO.setMonitorName(csLinePOList.get(0).getName());
return waveDataDTO;
}

View File

@@ -275,7 +275,7 @@ public class StableDataServiceImpl implements StableDataService {
CommonQueryParam commonQueryParam = new CommonQueryParam();
commonQueryParam.setLineId(temp.getLineId());
commonQueryParam.setTableName(influxDbParamUtil.getTableNameByClassId(epdPqd.getClassId()));
if (epdPqd.getName() == null || epdPqd.getName().isEmpty()) {
if (epdPqd.getOtherName() == null || epdPqd.getOtherName().isEmpty()) {
commonQueryParam.setColumnName(epdPqd.getName()+ finalFrequency1);
} else {
commonQueryParam.setColumnName(epdPqd.getOtherName()+ finalFrequency1);
@@ -292,42 +292,81 @@ public class StableDataServiceImpl implements StableDataService {
List<StatisticalDataDTO> deviceRtData = commonService.getDeviceRtDataByTime(commonQueryParams);
if (CollectionUtil.isNotEmpty(deviceRtData)) {
Map<String, List<StatisticalDataDTO> > map = deviceRtData.stream().collect(Collectors.groupingBy(StatisticalDataDTO::getLineId));
map.forEach((key, value) -> {
if (!Objects.isNull(loadSideLine) && Objects.equals(key, loadSideLine.getLineId())) {
List<ThdDataVO> collect1 = value.stream().map(temp -> {
ThdDataVO vo = new ThdDataVO();
vo.setLineId(temp.getLineId());
vo.setPhase(temp.getPhaseType());
vo.setPosition(loadSideLine.getPosition());
vo.setTime(temp.getTime());
vo.setStatMethod(temp.getValueType());
vo.setStatisticalData(Double.valueOf(df.format(temp.getValue())));
vo.setStatisticalIndex(epdPqd.getId());
vo.setUnit(epdPqd.getUnit());
vo.setStatisticalName(epdPqd.getName());
vo.setAnotherName("治理前");
return vo;
}).collect(Collectors.toList());
result.addAll(collect1);
}
if (!Objects.isNull(gridSideLine) && Objects.equals(key, gridSideLine.getLineId())) {
List<ThdDataVO> collect1 = value.stream().map(temp -> {
ThdDataVO vo = new ThdDataVO();
vo.setLineId(temp.getLineId());
vo.setPhase(temp.getPhaseType());
vo.setPosition(gridSideLine.getPosition());
vo.setTime(temp.getTime());
vo.setStatMethod(temp.getValueType());
vo.setStatisticalData(Double.valueOf(df.format(temp.getValue())));
vo.setStatisticalIndex(epdPqd.getId());
vo.setUnit(epdPqd.getUnit());
vo.setStatisticalName(epdPqd.getName());
vo.setAnotherName("治理后");
return vo;
}).collect(Collectors.toList());
result.addAll(collect1);
}
});
List<StatisticalDataDTO> loadSideData = map.get(loadSideLine.getLineId());
if (CollectionUtil.isNotEmpty(loadSideData)) {
List<ThdDataVO> collect1 = loadSideData.stream().map(temp -> {
ThdDataVO vo = new ThdDataVO();
vo.setLineId(temp.getLineId());
vo.setPhase(temp.getPhaseType());
vo.setPosition(loadSideLine.getPosition());
vo.setTime(temp.getTime());
vo.setStatMethod(temp.getValueType());
vo.setStatisticalData(Double.valueOf(df.format(temp.getValue())));
vo.setStatisticalIndex(epdPqd.getId());
vo.setUnit(epdPqd.getUnit());
vo.setStatisticalName(epdPqd.getName());
vo.setAnotherName("治理前");
return vo;
}).collect(Collectors.toList());
result.addAll(collect1);
}
List<StatisticalDataDTO> gridSideData = map.get(gridSideLine.getLineId());
if (CollectionUtil.isNotEmpty(gridSideData)) {
List<ThdDataVO> collect2 = gridSideData.stream().map(temp -> {
ThdDataVO vo = new ThdDataVO();
vo.setLineId(temp.getLineId());
vo.setPhase(temp.getPhaseType());
vo.setPosition(gridSideLine.getPosition());
vo.setTime(temp.getTime());
vo.setStatMethod(temp.getValueType());
vo.setStatisticalData(Double.valueOf(df.format(temp.getValue())));
vo.setStatisticalIndex(epdPqd.getId());
vo.setUnit(epdPqd.getUnit());
vo.setStatisticalName(epdPqd.getName());
vo.setAnotherName("治理后");
return vo;
}).collect(Collectors.toList());
result.addAll(collect2);
}
// map.forEach((key, value) -> {
// if (!Objects.isNull(loadSideLine) && Objects.equals(key, loadSideLine.getLineId())) {
// List<ThdDataVO> collect1 = value.stream().map(temp -> {
// ThdDataVO vo = new ThdDataVO();
// vo.setLineId(temp.getLineId());
// vo.setPhase(temp.getPhaseType());
// vo.setPosition(loadSideLine.getPosition());
// vo.setTime(temp.getTime());
// vo.setStatMethod(temp.getValueType());
// vo.setStatisticalData(Double.valueOf(df.format(temp.getValue())));
// vo.setStatisticalIndex(epdPqd.getId());
// vo.setUnit(epdPqd.getUnit());
// vo.setStatisticalName(epdPqd.getName());
// vo.setAnotherName("治理前");
// return vo;
// }).collect(Collectors.toList());
// result.addAll(collect1);
// }
// if (!Objects.isNull(gridSideLine) && Objects.equals(key, gridSideLine.getLineId())) {
// List<ThdDataVO> collect1 = value.stream().map(temp -> {
// ThdDataVO vo = new ThdDataVO();
// vo.setLineId(temp.getLineId());
// vo.setPhase(temp.getPhaseType());
// vo.setPosition(gridSideLine.getPosition());
// vo.setTime(temp.getTime());
// vo.setStatMethod(temp.getValueType());
// vo.setStatisticalData(Double.valueOf(df.format(temp.getValue())));
// vo.setStatisticalIndex(epdPqd.getId());
// vo.setUnit(epdPqd.getUnit());
// vo.setStatisticalName(epdPqd.getName());
// vo.setAnotherName("治理后");
// return vo;
// }).collect(Collectors.toList());
// result.addAll(collect1);
// }
// });
}
});
}