From 2f4831bbd8744266e124f9910408d5d42e81e819 Mon Sep 17 00:00:00 2001 From: "13621160019@163.com" <13621160019@163.com> Date: Wed, 23 Feb 2022 14:02:48 +0800 Subject: [PATCH] added limit 1 to number of ENERGY_VALUE points of meter --- admin/app/translations.js | 3 +++ myems-api/core/meter.py | 17 ++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/admin/app/translations.js b/admin/app/translations.js index 79c9b8ea..4c2844e1 100644 --- a/admin/app/translations.js +++ b/admin/app/translations.js @@ -852,6 +852,7 @@ function config($translateProvider) { METER_NAME_IS_ALREADY_IN_USE: 'Meter Name Is Already In Use', METER_NOT_FOUND: 'Meter Not Found', METER_OF_VARIABLE_NOT_FOUND: 'Meter Of Variable Not Found', + METER_CANNOT_HAVE_MORE_THAN_ONE_ENERGY_VALUE_POINTS: 'Meter Cannot Have More Than One ENERGY_VALUE Points', METER_POINT_RELATION_EXISTS: 'Meter Point Relation Exists', METER_POINT_RELATION_NOT_FOUND: 'Meter Point Relation Not Found', NOT_FOUND: 'Not Found', @@ -1851,6 +1852,7 @@ function config($translateProvider) { METER_NAME_IS_ALREADY_IN_USE: 'Meter Name Is Already In Use', METER_NOT_FOUND: 'Meter Not Found', METER_OF_VARIABLE_NOT_FOUND: 'Meter Of Variable Not Found', + METER_CANNOT_HAVE_MORE_THAN_ONE_ENERGY_VALUE_POINTS: 'Meter Cannot Have More Than One ENERGY_VALUE Points', METER_POINT_RELATION_EXISTS: 'Meter Point Relation Exists', METER_POINT_RELATION_NOT_FOUND: 'Meter Point Relation Not Found', NOT_FOUND: 'Not Found', @@ -2848,6 +2850,7 @@ function config($translateProvider) { METER_NAME_IS_ALREADY_IN_USE: 'Meter Name Is Already In Use', METER_NOT_FOUND: 'Meter Not Found', METER_OF_VARIABLE_NOT_FOUND: 'Meter Of Variable Not Found', + METER_CANNOT_HAVE_MORE_THAN_ONE_ENERGY_VALUE_POINTS: 'Meter Cannot Have More Than One ENERGY_VALUE Points', METER_POINT_RELATION_EXISTS: 'Meter Point Relation Exists', METER_POINT_RELATION_NOT_FOUND: 'Meter Point Relation Not Found', NOT_FOUND: 'Not Found', diff --git a/myems-api/core/meter.py b/myems-api/core/meter.py index bffc74ce..17f4fbd2 100644 --- a/myems-api/core/meter.py +++ b/myems-api/core/meter.py @@ -933,18 +933,17 @@ class MeterPointCollection: cnx.disconnect() raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.POINT_NOT_FOUND') - if row[1] == 'ENERGY_VALUE': - query = (" SELECT tmp.id,tmp.meter_id,tmp.point_id,tp.object_type " - " FROM tbl_meters_points tmp " - " LEFT JOIN tbl_points tp ON tmp.point_id = tp.id" - " WHERE tmp.meter_id = %s AND tp.object_type = %s") - cursor.execute(query, (id_, 'ENERGY_VALUE',)) - rows = cursor.fetchall() - if rows is not None: + elif row[1] == 'ENERGY_VALUE': + query = (" SELECT p.id " + " FROM tbl_meters_points mp, tbl_points p " + " WHERE mp.meter_id = %s AND mp.point_id = p.id AND p.object_type = 'ENERGY_VALUE' ") + cursor.execute(query, (id_,)) + rows_points = cursor.fetchall() + if rows_points is not None and len(rows_points) > 0: cursor.close() cnx.disconnect() raise falcon.HTTPError(falcon.HTTP_404, title='API.BAD_REQUEST', - description='API.POINT_OBJECT_TYPE_IS_ALREADY_IN_USE') + description='API.METER_CANNOT_HAVE_MORE_THAN_ONE_ENERGY_VALUE_POINTS') query = (" SELECT id " " FROM tbl_meters_points "