From ea322c50e35cde1bb56b662c0e2bc1d4cf7d3d19 Mon Sep 17 00:00:00 2001 From: Kamil Date: Mon, 8 Jan 2024 17:46:20 +0100 Subject: [PATCH] #2770 Fixed minimum/maximum calculate in Meta Data Point script - corrected performance --- .../dao/pointvalues/PointValueDAO.java | 26 ++++++++++++++++++- .../mango/service/PointValueService.java | 18 +++---------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/org/scada_lts/dao/pointvalues/PointValueDAO.java b/src/org/scada_lts/dao/pointvalues/PointValueDAO.java index 16fc28528a..14731a8f4f 100644 --- a/src/org/scada_lts/dao/pointvalues/PointValueDAO.java +++ b/src/org/scada_lts/dao/pointvalues/PointValueDAO.java @@ -209,7 +209,7 @@ public class PointValueDAO implements GenericDaoCR { public static final String POINT_VALUE_FILTER_BEFORE_TIME_STAMP_BASE_ON_DATA_POINT_ID = " " + "pv."+COLUMN_NAME_DATA_POINT_ID+"=? and " + "pv."+COLUMN_NAME_TIME_STAMP+" pointValues = DAO.getInstance().getJdbcTemp().query(POINT_VALUE_SELECT + " where pv.dataPointId=? and pv.ts=?", + new Object[]{dataPointId, time}, new PointValueRowMapper()); + if(pointValues.isEmpty()) + return null; + long maxId = pointValues.stream().mapToLong(PointValue::getId).max().orElse(-1); + PointValue pointValue = pointValues.stream().filter(a -> a.getId() == maxId).findAny().orElse(null); + if(pointValue == null) + return null; + return pointValue.getPointValue(); + } } \ No newline at end of file diff --git a/src/org/scada_lts/mango/service/PointValueService.java b/src/org/scada_lts/mango/service/PointValueService.java index 276854d2d7..b2f3c654cc 100644 --- a/src/org/scada_lts/mango/service/PointValueService.java +++ b/src/org/scada_lts/mango/service/PointValueService.java @@ -370,23 +370,13 @@ public PointValueTime getLatestPointValue(int dataPointId) { } public PointValueTime getPointValueBefore(int dataPointId, long time) { - List lst = PointValueDAO.getInstance().filtered( - PointValueDAO.POINT_VALUE_FILTER_BEFORE_TIME_STAMP_BASE_ON_DATA_POINT_ID, - new Object[]{dataPointId, time}, 1); - if (lst != null && lst.size() > 0) { - return lst.get(0).getPointValue(); - } else { - return null; - } + return PointValueDAO.getInstance().getPointValueBefore(dataPointId, time); } public PointValueTime getPointValueAt(int dataPointId, long time) { - List lst = PointValueDAO.getInstance().filtered( - PointValueDAO.POINT_VALUE_FILTER_AT_TIME_STAMP_BASE_ON_DATA_POINT_ID, - new Object[]{dataPointId, time}, 1); - if (lst != null && lst.size() > 0) { - return lst.get(0).getPointValue(); - } else { + try { + return PointValueDAO.getInstance().getPointValueAt(dataPointId, time); + } catch (Exception ex) { return null; } }