From 51b9e43a04aacdf66359345e811615a49f32a1a3 Mon Sep 17 00:00:00 2001 From: tianlinzhong <673359306@qq.com> Date: Mon, 21 Feb 2022 14:39:53 +0800 Subject: [PATCH 1/4] fixed issues 199 --- myems-api/core/meter.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/myems-api/core/meter.py b/myems-api/core/meter.py index a57ce560..ec0f25f8 100644 --- a/myems-api/core/meter.py +++ b/myems-api/core/meter.py @@ -913,7 +913,6 @@ class MeterPointCollection: description='API.INVALID_METER_ID') new_values = json.loads(raw_json) - cnx = mysql.connector.connect(**config.myems_system_db) cursor = cnx.cursor() @@ -925,15 +924,33 @@ class MeterPointCollection: cnx.disconnect() raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND') - - cursor.execute(" SELECT name " + cursor.execute(" SELECT name, object_type " " FROM tbl_points " " WHERE id = %s ", (new_values['data']['point_id'],)) - if cursor.fetchone() is None: + row = cursor.fetchone() + if row is None: cursor.close() cnx.disconnect() raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.POINT_NOT_FOUND') + if row[1] == 'ENERGY_VALUE': + query = (" SELECT point_id " + " FROM tbl_meters_points " + " WHERE meter_id = %s") + cursor.execute(query, (id_,)) + rows = cursor.fetchall() + if rows is not None: + for row1 in rows: + cursor.execute(" SELECT object_type " + " FROM tbl_points " + " WHERE id = %s ", (row1[0],)) + row = cursor.fetchone() + if row is not None: + if row[0] == 'ENERGY_VALUE': + cursor.close() + cnx.disconnect() + raise falcon.HTTPError(falcon.HTTP_404, title='API.BAD_REQUEST', + description='API.POINT_OBJECT_TYPE_IS_ALREADY_IN_USE') query = (" SELECT id " " FROM tbl_meters_points " From 25a9713e23a4b375d8241e97a5ea605d33156d46 Mon Sep 17 00:00:00 2001 From: tianlinzhong <673359306@qq.com> Date: Mon, 21 Feb 2022 23:38:49 +0800 Subject: [PATCH 2/4] fixed issues 199 -2 --- myems-api/core/meter.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/myems-api/core/meter.py b/myems-api/core/meter.py index ec0f25f8..ddc4200a 100644 --- a/myems-api/core/meter.py +++ b/myems-api/core/meter.py @@ -939,18 +939,19 @@ class MeterPointCollection: " WHERE meter_id = %s") cursor.execute(query, (id_,)) rows = cursor.fetchall() + + cursor.execute(" SELECT id " + " FROM tbl_points " + " WHERE object_type = %s ", ('ENERGY_VALUE',)) + ponit_ids = cursor.fetchall() + if rows is not None: for row1 in rows: - cursor.execute(" SELECT object_type " - " FROM tbl_points " - " WHERE id = %s ", (row1[0],)) - row = cursor.fetchone() - if row is not None: - if row[0] == 'ENERGY_VALUE': - cursor.close() - cnx.disconnect() - raise falcon.HTTPError(falcon.HTTP_404, title='API.BAD_REQUEST', - description='API.POINT_OBJECT_TYPE_IS_ALREADY_IN_USE') + if row1 in ponit_ids: + cursor.close() + cnx.disconnect() + raise falcon.HTTPError(falcon.HTTP_404, title='API.BAD_REQUEST', + description='API.POINT_OBJECT_TYPE_IS_ALREADY_IN_USE') query = (" SELECT id " " FROM tbl_meters_points " From c2f427e354a2e9e8095769a7d4952cabf2bcc6e0 Mon Sep 17 00:00:00 2001 From: tianlinzhong <673359306@qq.com> Date: Mon, 21 Feb 2022 23:49:41 +0800 Subject: [PATCH 3/4] fixed issues 199 -2 --- myems-api/core/meter.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/myems-api/core/meter.py b/myems-api/core/meter.py index ddc4200a..423b64e1 100644 --- a/myems-api/core/meter.py +++ b/myems-api/core/meter.py @@ -946,12 +946,13 @@ class MeterPointCollection: ponit_ids = cursor.fetchall() if rows is not None: - for row1 in rows: - if row1 in ponit_ids: - cursor.close() - cnx.disconnect() - raise falcon.HTTPError(falcon.HTTP_404, title='API.BAD_REQUEST', - description='API.POINT_OBJECT_TYPE_IS_ALREADY_IN_USE') + if ponit_ids is not None: + for row1 in rows: + if row1 in ponit_ids: + cursor.close() + cnx.disconnect() + raise falcon.HTTPError(falcon.HTTP_404, title='API.BAD_REQUEST', + description='API.POINT_OBJECT_TYPE_IS_ALREADY_IN_USE') query = (" SELECT id " " FROM tbl_meters_points " From d19838fd3223f62c1d3039154da42fe2a9c60773 Mon Sep 17 00:00:00 2001 From: tianlinzhong <673359306@qq.com> Date: Wed, 23 Feb 2022 11:07:21 +0800 Subject: [PATCH 4/4] fixed issues 199 -3 --- myems-api/core/meter.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/myems-api/core/meter.py b/myems-api/core/meter.py index 423b64e1..bffc74ce 100644 --- a/myems-api/core/meter.py +++ b/myems-api/core/meter.py @@ -934,25 +934,17 @@ class MeterPointCollection: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.POINT_NOT_FOUND') if row[1] == 'ENERGY_VALUE': - query = (" SELECT point_id " - " FROM tbl_meters_points " - " WHERE meter_id = %s") - cursor.execute(query, (id_,)) + 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() - - cursor.execute(" SELECT id " - " FROM tbl_points " - " WHERE object_type = %s ", ('ENERGY_VALUE',)) - ponit_ids = cursor.fetchall() - if rows is not None: - if ponit_ids is not None: - for row1 in rows: - if row1 in ponit_ids: - cursor.close() - cnx.disconnect() - raise falcon.HTTPError(falcon.HTTP_404, title='API.BAD_REQUEST', - description='API.POINT_OBJECT_TYPE_IS_ALREADY_IN_USE') + cursor.close() + cnx.disconnect() + raise falcon.HTTPError(falcon.HTTP_404, title='API.BAD_REQUEST', + description='API.POINT_OBJECT_TYPE_IS_ALREADY_IN_USE') query = (" SELECT id " " FROM tbl_meters_points "