提交 b7df7939 编写于 作者: L llis

Fixed equipment.py,gateway.py,point.py,rule.py,timezone.py,user.py file

上级 582bedd5
...@@ -51,13 +51,12 @@ class EquipmentCollection: ...@@ -51,13 +51,12 @@ class EquipmentCollection:
result = list() result = list()
if rows_equipments is not None and len(rows_equipments) > 0: if rows_equipments is not None and len(rows_equipments) > 0:
for row in rows_equipments: for row in rows_equipments:
cost_center = cost_center_dict.get(row[5], None)
meta_result = {"id": row[0], meta_result = {"id": row[0],
"name": row[1], "name": row[1],
"uuid": row[2], "uuid": row[2],
"is_input_counted": bool(row[3]), "is_input_counted": bool(row[3]),
"is_output_counted": bool(row[4]), "is_output_counted": bool(row[4]),
"cost_center": cost_center, "cost_center": cost_center_dict.get(row[5], None),
"svg": row[6], "svg": row[6],
"camera_url": row[7], "camera_url": row[7],
"description": row[8], "description": row[8],
...@@ -225,13 +224,12 @@ class EquipmentItem: ...@@ -225,13 +224,12 @@ class EquipmentItem:
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.EQUIPMENT_NOT_FOUND') description='API.EQUIPMENT_NOT_FOUND')
else: else:
cost_center = cost_center_dict.get(row[5], None)
meta_result = {"id": row[0], meta_result = {"id": row[0],
"name": row[1], "name": row[1],
"uuid": row[2], "uuid": row[2],
"is_input_counted": bool(row[3]), "is_input_counted": bool(row[3]),
"is_output_counted": bool(row[4]), "is_output_counted": bool(row[4]),
"cost_center": cost_center, "cost_center": cost_center_dict.get(row[5], None),
"svg": row[6], "svg": row[6],
"camera_url": row[7], "camera_url": row[7],
"description": row[8], "description": row[8],
...@@ -1332,9 +1330,10 @@ class EquipmentMeterCollection: ...@@ -1332,9 +1330,10 @@ class EquipmentMeterCollection:
result = list() result = list()
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
energy_category = energy_category_dict.get(row[3], None) meta_result = {"id": row[0],
meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "name": row[1],
"energy_category": energy_category, "uuid": row[2],
"energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])} "is_output": bool(row[4])}
result.append(meta_result) result.append(meta_result)
...@@ -1530,9 +1529,10 @@ class EquipmentOfflineMeterCollection: ...@@ -1530,9 +1529,10 @@ class EquipmentOfflineMeterCollection:
result = list() result = list()
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
energy_category = energy_category_dict.get(row[3], None) meta_result = {"id": row[0],
meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "name": row[1],
"energy_category": energy_category, "uuid": row[2],
"energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])} "is_output": bool(row[4])}
result.append(meta_result) result.append(meta_result)
...@@ -1729,9 +1729,10 @@ class EquipmentVirtualMeterCollection: ...@@ -1729,9 +1729,10 @@ class EquipmentVirtualMeterCollection:
result = list() result = list()
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
energy_category = energy_category_dict.get(row[3], None) meta_result = {"id": row[0],
meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "name": row[1],
"energy_category": energy_category, "uuid": row[2],
"energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])} "is_output": bool(row[4])}
result.append(meta_result) result.append(meta_result)
...@@ -1916,7 +1917,9 @@ class EquipmentCommandCollection: ...@@ -1916,7 +1917,9 @@ class EquipmentCommandCollection:
result = list() result = list()
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
meta_result = {"id": row[0], "name": row[1], "uuid": row[2]} meta_result = {"id": row[0],
"name": row[1],
"uuid": row[2]}
result.append(meta_result) result.append(meta_result)
resp.text = json.dumps(result) resp.text = json.dumps(result)
...@@ -2098,13 +2101,12 @@ class EquipmentExport: ...@@ -2098,13 +2101,12 @@ class EquipmentExport:
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.EQUIPMENT_NOT_FOUND') description='API.EQUIPMENT_NOT_FOUND')
else: else:
cost_center = cost_center_dict.get(row[5], None)
meta_result = {"id": row[0], meta_result = {"id": row[0],
"name": row[1], "name": row[1],
"uuid": row[2], "uuid": row[2],
"is_input_counted": bool(row[3]), "is_input_counted": bool(row[3]),
"is_output_counted": bool(row[4]), "is_output_counted": bool(row[4]),
"cost_center": cost_center, "cost_center": cost_center_dict.get(row[5], None),
"svg": row[6], "svg": row[6],
"camera_url": row[7], "camera_url": row[7],
"description": row[8], "description": row[8],
...@@ -2124,7 +2126,9 @@ class EquipmentExport: ...@@ -2124,7 +2126,9 @@ class EquipmentExport:
command_result = list() command_result = list()
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
result = {"id": row[0], "name": row[1], "uuid": row[2]} result = {"id": row[0],
"name": row[1],
"uuid": row[2]}
command_result.append(result) command_result.append(result)
meta_result['commands'] = command_result meta_result['commands'] = command_result
...@@ -2150,9 +2154,10 @@ class EquipmentExport: ...@@ -2150,9 +2154,10 @@ class EquipmentExport:
meter_result = list() meter_result = list()
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
energy_category = energy_category_dict.get(row[3], None) result = {"id": row[0],
result = {"id": row[0], "name": row[1], "uuid": row[2], "name": row[1],
"energy_category": energy_category, "uuid": row[2],
"energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])} "is_output": bool(row[4])}
meter_result.append(result) meter_result.append(result)
meta_result['meters'] = meter_result meta_result['meters'] = meter_result
...@@ -2166,9 +2171,10 @@ class EquipmentExport: ...@@ -2166,9 +2171,10 @@ class EquipmentExport:
offlinemeter_result = list() offlinemeter_result = list()
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
energy_category = energy_category_dict.get(row[3], None) result = {"id": row[0],
result = {"id": row[0], "name": row[1], "uuid": row[2], "name": row[1],
"energy_category": energy_category, "uuid": row[2],
"energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])} "is_output": bool(row[4])}
offlinemeter_result.append(result) offlinemeter_result.append(result)
meta_result['offline_meters'] = offlinemeter_result meta_result['offline_meters'] = offlinemeter_result
...@@ -2182,9 +2188,10 @@ class EquipmentExport: ...@@ -2182,9 +2188,10 @@ class EquipmentExport:
virtualmeter_result = list() virtualmeter_result = list()
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
energy_category = energy_category_dict.get(row[3], None) result = {"id": row[0],
result = {"id": row[0], "name": row[1], "uuid": row[2], "name": row[1],
"energy_category": energy_category, "uuid": row[2],
"energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])} "is_output": bool(row[4])}
virtualmeter_result.append(result) virtualmeter_result.append(result)
meta_result['virtual_meters'] = virtualmeter_result meta_result['virtual_meters'] = virtualmeter_result
...@@ -2686,13 +2693,12 @@ class EquipmentClone: ...@@ -2686,13 +2693,12 @@ class EquipmentClone:
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.EQUIPMENT_NOT_FOUND') description='API.EQUIPMENT_NOT_FOUND')
else: else:
cost_center = cost_center_dict.get(row[5], None)
meta_result = {"id": row[0], meta_result = {"id": row[0],
"name": row[1], "name": row[1],
"uuid": row[2], "uuid": row[2],
"is_input_counted": bool(row[3]), "is_input_counted": bool(row[3]),
"is_output_counted": bool(row[4]), "is_output_counted": bool(row[4]),
"cost_center": cost_center, "cost_center": cost_center_dict.get(row[5], None),
"svg": row[6], "svg": row[6],
"camera_url": row[7], "camera_url": row[7],
"description": row[8], "description": row[8],
...@@ -2712,7 +2718,9 @@ class EquipmentClone: ...@@ -2712,7 +2718,9 @@ class EquipmentClone:
command_result = list() command_result = list()
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
result = {"id": row[0], "name": row[1], "uuid": row[2]} result = {"id": row[0],
"name": row[1],
"uuid": row[2]}
command_result.append(result) command_result.append(result)
meta_result['commands'] = command_result meta_result['commands'] = command_result
...@@ -2738,9 +2746,10 @@ class EquipmentClone: ...@@ -2738,9 +2746,10 @@ class EquipmentClone:
meter_result = list() meter_result = list()
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
energy_category = energy_category_dict.get(row[3], None) result = {"id": row[0],
result = {"id": row[0], "name": row[1], "uuid": row[2], "name": row[1],
"energy_category": energy_category, "uuid": row[2],
"energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])} "is_output": bool(row[4])}
meter_result.append(result) meter_result.append(result)
meta_result['meters'] = meter_result meta_result['meters'] = meter_result
...@@ -2754,9 +2763,10 @@ class EquipmentClone: ...@@ -2754,9 +2763,10 @@ class EquipmentClone:
offlinemeter_result = list() offlinemeter_result = list()
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
energy_category = energy_category_dict.get(row[3], None) result = {"id": row[0],
result = {"id": row[0], "name": row[1], "uuid": row[2], "name": row[1],
"energy_category": energy_category, "uuid": row[2],
"energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])} "is_output": bool(row[4])}
offlinemeter_result.append(result) offlinemeter_result.append(result)
meta_result['offline_meters'] = offlinemeter_result meta_result['offline_meters'] = offlinemeter_result
...@@ -2770,9 +2780,10 @@ class EquipmentClone: ...@@ -2770,9 +2780,10 @@ class EquipmentClone:
virtualmeter_result = list() virtualmeter_result = list()
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
energy_category = energy_category_dict.get(row[3], None) result = {"id": row[0],
result = {"id": row[0], "name": row[1], "uuid": row[2], "name": row[1],
"energy_category": energy_category, "uuid": row[2],
"energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])} "is_output": bool(row[4])}
virtualmeter_result.append(result) virtualmeter_result.append(result)
meta_result['virtual_meters'] = virtualmeter_result meta_result['virtual_meters'] = virtualmeter_result
......
...@@ -43,7 +43,9 @@ class GatewayCollection: ...@@ -43,7 +43,9 @@ class GatewayCollection:
last_seen_datetime = last_seen_datetime_local.strftime('%Y-%m-%dT%H:%M:%S') last_seen_datetime = last_seen_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
else: else:
last_seen_datetime = None last_seen_datetime = None
meta_result = {"id": row[0], "name": row[1], "uuid": row[2], meta_result = {"id": row[0],
"name": row[1],
"uuid": row[2],
"token": row[3], "token": row[3],
"last_seen_datetime": last_seen_datetime, "last_seen_datetime": last_seen_datetime,
"description": row[5] "description": row[5]
......
...@@ -47,10 +47,9 @@ class PointCollection: ...@@ -47,10 +47,9 @@ class PointCollection:
result = list() result = list()
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
data_source = data_source_dict.get(row[2], None)
meta_result = {"id": row[0], meta_result = {"id": row[0],
"name": row[1], "name": row[1],
"data_source": data_source, "data_source": data_source_dict.get(row[2], None),
"object_type": row[3], "object_type": row[3],
"units": row[4], "units": row[4],
"high_limit": row[5], "high_limit": row[5],
...@@ -273,10 +272,9 @@ class PointItem: ...@@ -273,10 +272,9 @@ class PointItem:
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.POINT_NOT_FOUND') description='API.POINT_NOT_FOUND')
data_source = data_source_dict.get(row[2], None)
result = {"id": row[0], result = {"id": row[0],
"name": row[1], "name": row[1],
"data_source": data_source, "data_source": data_source_dict.get(row[2], None),
"object_type": row[3], "object_type": row[3],
"units": row[4], "units": row[4],
"high_limit": row[5], "high_limit": row[5],
...@@ -909,10 +907,9 @@ class PointExport: ...@@ -909,10 +907,9 @@ class PointExport:
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.POINT_NOT_FOUND') description='API.POINT_NOT_FOUND')
data_source = data_source_dict.get(row[2], None)
result = {"id": row[0], result = {"id": row[0],
"name": row[1], "name": row[1],
"data_source": data_source, "data_source": data_source_dict.get(row[2], None),
"object_type": row[3], "object_type": row[3],
"units": row[4], "units": row[4],
"high_limit": row[5], "high_limit": row[5],
...@@ -1143,10 +1140,9 @@ class PointClone: ...@@ -1143,10 +1140,9 @@ class PointClone:
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.POINT_NOT_FOUND') description='API.POINT_NOT_FOUND')
data_source = data_source_dict.get(row[2], None)
result = {"id": row[0], result = {"id": row[0],
"name": row[1], "name": row[1],
"data_source": data_source, "data_source": data_source_dict.get(row[2], None),
"object_type": row[3], "object_type": row[3],
"units": row[4], "units": row[4],
"high_limit": row[5], "high_limit": row[5],
......
...@@ -56,9 +56,14 @@ class RuleCollection: ...@@ -56,9 +56,14 @@ class RuleCollection:
else: else:
next_run_datetime = None next_run_datetime = None
meta_result = {"id": row[0], "name": row[1], "uuid": row[2], meta_result = {"id": row[0],
"category": row[3], "fdd_code": row[4], "priority": row[5], "name": row[1],
"channel": row[6], "expression": row[7], "uuid": row[2],
"category": row[3],
"fdd_code": row[4],
"priority": row[5],
"channel": row[6],
"expression": row[7],
"message_template": row[8].replace("<br>", ""), "message_template": row[8].replace("<br>", ""),
"is_enabled": bool(row[9]), "is_enabled": bool(row[9]),
"last_run_datetime": last_run_datetime, "last_run_datetime": last_run_datetime,
...@@ -248,9 +253,14 @@ class RuleItem: ...@@ -248,9 +253,14 @@ class RuleItem:
else: else:
next_run_datetime = None next_run_datetime = None
result = {"id": row[0], "name": row[1], "uuid": row[2], result = {"id": row[0],
"category": row[3], "fdd_code": row[4], "priority": row[5], "name": row[1],
"channel": row[6], "expression": row[7], "uuid": row[2],
"category": row[3],
"fdd_code": row[4],
"priority": row[5],
"channel": row[6],
"expression": row[7],
"message_template": row[8].replace("<br>", ""), "message_template": row[8].replace("<br>", ""),
"is_enabled": bool(row[9]), "is_enabled": bool(row[9]),
"last_run_datetime": last_run_datetime, "last_run_datetime": last_run_datetime,
...@@ -523,9 +533,14 @@ class RuleExport: ...@@ -523,9 +533,14 @@ class RuleExport:
else: else:
next_run_datetime = None next_run_datetime = None
result = {"id": row[0], "name": row[1], "uuid": row[2], result = {"id": row[0],
"category": row[3], "fdd_code": row[4], "priority": row[5], "name": row[1],
"channel": row[6], "expression": row[7], "uuid": row[2],
"category": row[3],
"fdd_code": row[4],
"priority": row[5],
"channel": row[6],
"expression": row[7],
"message_template": row[8].replace("<br>", ""), "message_template": row[8].replace("<br>", ""),
"is_enabled": bool(row[9]), "is_enabled": bool(row[9]),
"last_run_datetime": last_run_datetime, "last_run_datetime": last_run_datetime,
...@@ -722,9 +737,14 @@ class RuleClone: ...@@ -722,9 +737,14 @@ class RuleClone:
else: else:
next_run_datetime = None next_run_datetime = None
result = {"id": row[0], "name": row[1], "uuid": row[2], result = {"id": row[0],
"category": row[3], "fdd_code": row[4], "priority": row[5], "name": row[1],
"channel": row[6], "expression": row[7], "uuid": row[2],
"category": row[3],
"fdd_code": row[4],
"priority": row[5],
"channel": row[6],
"expression": row[7],
"message_template": row[8].replace("<br>", ""), "message_template": row[8].replace("<br>", ""),
"is_enabled": bool(row[9]), "is_enabled": bool(row[9]),
"last_run_datetime": last_run_datetime, "last_run_datetime": last_run_datetime,
......
...@@ -36,7 +36,10 @@ class TimezoneCollection: ...@@ -36,7 +36,10 @@ class TimezoneCollection:
result = list() result = list()
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
meta_result = {"id": row[0], "name": row[1], "description": row[2], "utc_offset": row[3]} meta_result = {"id": row[0],
"name": row[1],
"description": row[2],
"utc_offset": row[3]}
result.append(meta_result) result.append(meta_result)
resp.text = json.dumps(result) resp.text = json.dumps(result)
...@@ -78,7 +81,10 @@ class TimezoneItem: ...@@ -78,7 +81,10 @@ class TimezoneItem:
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.TIMEZONE_NOT_FOUND') description='API.TIMEZONE_NOT_FOUND')
result = {"id": row[0], "name": row[1], "description": row[2], "utc_offset": row[3]} result = {"id": row[0],
"name": row[1],
"description": row[2],
"utc_offset": row[3]}
cursor.close() cursor.close()
cnx.close() cnx.close()
......
...@@ -44,10 +44,6 @@ class UserCollection: ...@@ -44,10 +44,6 @@ class UserCollection:
result = list() result = list()
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
account_expiration_datetime_local = row[9].replace(tzinfo=timezone.utc) + \
timedelta(minutes=timezone_offset)
password_expiration_datetime_local = row[10].replace(tzinfo=timezone.utc) + \
timedelta(minutes=timezone_offset)
meta_result = {"id": row[0], meta_result = {"id": row[0],
"name": row[1], "name": row[1],
"display_name": row[2], "display_name": row[2],
...@@ -59,9 +55,9 @@ class UserCollection: ...@@ -59,9 +55,9 @@ class UserCollection:
"id": row[7], "id": row[7],
"name": row[8]} if row[7] is not None else None, "name": row[8]} if row[7] is not None else None,
"account_expiration_datetime": "account_expiration_datetime":
account_expiration_datetime_local.strftime('%Y-%m-%dT%H:%M:%S'), (row[9].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset)).strftime('%Y-%m-%dT%H:%M:%S'),
"password_expiration_datetime": "password_expiration_datetime":
password_expiration_datetime_local.strftime('%Y-%m-%dT%H:%M:%S'), (row[10].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset)).strftime('%Y-%m-%dT%H:%M:%S'),
"is_locked": True if row[11] >= config.maximum_failed_login_count else False} "is_locked": True if row[11] >= config.maximum_failed_login_count else False}
result.append(meta_result) result.append(meta_result)
...@@ -255,9 +251,6 @@ class UserItem: ...@@ -255,9 +251,6 @@ class UserItem:
if config.utc_offset[0] == '-': if config.utc_offset[0] == '-':
timezone_offset = -timezone_offset timezone_offset = -timezone_offset
account_expiration_datetime_local = row[9].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset)
password_expiration_datetime_local = row[10].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset)
result = {"id": row[0], result = {"id": row[0],
"name": row[1], "name": row[1],
"display_name": row[2], "display_name": row[2],
...@@ -269,9 +262,9 @@ class UserItem: ...@@ -269,9 +262,9 @@ class UserItem:
"id": row[7], "id": row[7],
"name": row[8]} if row[7] is not None else None, "name": row[8]} if row[7] is not None else None,
"account_expiration_datetime": "account_expiration_datetime":
account_expiration_datetime_local.strftime('%Y-%m-%dT%H:%M:%S'), (row[9].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset)).strftime('%Y-%m-%dT%H:%M:%S'),
"password_expiration_datetime": "password_expiration_datetime":
password_expiration_datetime_local.strftime('%Y-%m-%dT%H:%M:%S'), (row[10].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset)).strftime('%Y-%m-%dT%H:%M:%S'),
"is_locked": True if row[11] >= config.maximum_failed_login_count else False} "is_locked": True if row[11] >= config.maximum_failed_login_count else False}
resp.text = json.dumps(result) resp.text = json.dumps(result)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册