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] 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 "