综合查询优化
This commit is contained in:
@ -271,7 +271,7 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
|
|||||||
private Stats clacStats(List<GeneralQueryDataVo> deviceDataList) {
|
private Stats clacStats(List<GeneralQueryDataVo> deviceDataList) {
|
||||||
// 提取有效数值(过滤null)
|
// 提取有效数值(过滤null)
|
||||||
List<BigDecimal> values = deviceDataList.stream()
|
List<BigDecimal> values = deviceDataList.stream()
|
||||||
.map(vo -> (BigDecimal) vo.getPointValue())
|
.map(vo -> convertToBigDecimal(vo.getPointValue()))
|
||||||
.filter(value -> value != null) // 过滤null值
|
.filter(value -> value != null) // 过滤null值
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (values.isEmpty()) {
|
if (values.isEmpty()) {
|
||||||
@ -290,6 +290,27 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
|
|||||||
return new Stats(maxValue,minValue,avgValue,diff);
|
return new Stats(maxValue,minValue,avgValue,diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BigDecimal convertToBigDecimal(Object pointValue) {
|
||||||
|
if (pointValue == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// 根据实际存储的数值类型,依次判断并转换
|
||||||
|
if (pointValue instanceof BigDecimal) {
|
||||||
|
return (BigDecimal) pointValue;
|
||||||
|
} else if (pointValue instanceof Integer) {
|
||||||
|
return new BigDecimal ((Integer) pointValue);
|
||||||
|
} else if (pointValue instanceof Long) {
|
||||||
|
return new BigDecimal ((Long) pointValue);
|
||||||
|
} else if (pointValue instanceof Double) {
|
||||||
|
return BigDecimal.valueOf ((Double) pointValue); // 避免 Double 精度丢失
|
||||||
|
} else if (pointValue instanceof Float) {
|
||||||
|
return BigDecimal.valueOf ((Float) pointValue);
|
||||||
|
} else {
|
||||||
|
// 非数值类型(如 String),可根据业务需求处理(此处返回 null)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void dealDataTime(PointNameRequest request) {
|
private void dealDataTime(PointNameRequest request) {
|
||||||
String startDate = request.getStartDate();
|
String startDate = request.getStartDate();
|
||||||
String endDate = request.getEndDate();
|
String endDate = request.getEndDate();
|
||||||
@ -354,7 +375,7 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
|
|||||||
data.setValueDate(minute);
|
data.setValueDate(minute);
|
||||||
data.setSiteId(siteId);
|
data.setSiteId(siteId);
|
||||||
data.setDeviceId(deviceId);
|
data.setDeviceId(deviceId);
|
||||||
data.setPointValue(lastValue==null? 0 : lastValue); // 用上一分钟值填充
|
data.setPointValue(lastValue==null? BigDecimal.ZERO : lastValue); // 用上一分钟值填充
|
||||||
} else {
|
} else {
|
||||||
lastValue = data.getPointValue(); // 更新最新值
|
lastValue = data.getPointValue(); // 更新最新值
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user