From 368e3003b865f847cc8af4efaf6d6bc08a6a26aa Mon Sep 17 00:00:00 2001 From: "apan_youxiang@163.com" Date: Thu, 11 Aug 2022 09:05:11 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=AF=E5=A2=83=E7=9B=91=E6=B5=8B=E5=B0=8F?= =?UTF-8?q?=E6=95=B0=E7=82=B9=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/Utils.py | 9 --------- apps/monitor/views.py | 6 ++---- config/server.py | 3 +++ db_logic/humiture_record.py | 16 +++++++++------- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/Common/Utils.py b/Common/Utils.py index 3c60824..b0bdd1b 100644 --- a/Common/Utils.py +++ b/Common/Utils.py @@ -35,15 +35,6 @@ class Utils(object): def get_str_datetime(): return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") - def data_float_type_convent(data_list): - new_list = [] - for i in data_list: - new_dic = {} - for k,v in i.items(): - new_dic[k]= v if not isinstance(v, Decimal) else float(v) - new_list.append(new_dic) - return new_list - def sql_paging_assemble(sql_all, page_param): sql_all += ' limit ' + str((page_param.curPage - 1) * page_param.pageRows) + ',' + str(page_param.pageRows) return sql_all diff --git a/apps/monitor/views.py b/apps/monitor/views.py index 4949c93..b4f8313 100644 --- a/apps/monitor/views.py +++ b/apps/monitor/views.py @@ -34,8 +34,7 @@ def get_day_monitor(): client_id=client_id, start_time=start_time, end_time=end_time, page_param=page_param ) - data_list = Utils.msyql_table_model(data_list) - return jsonify(Utils.true_return(data={"data_list": Utils.data_float_type_convent(data_list), "total_count": page_param.totalRecords})) + return jsonify(Utils.true_return(data={"data_list": Utils.msyql_table_model(data_list), "total_count": page_param.totalRecords})) # 获取每日记录详情 @@ -54,5 +53,4 @@ def get_day_monitor_info(): end_time=end_time, page_param=page_param ) - data_list = Utils.msyql_table_model(data_list) - return jsonify(Utils.true_return(data={"data_list": Utils.data_float_type_convent(data_list), "total_count": page_param.totalRecords})) + return jsonify(Utils.true_return(data={"data_list": Utils.msyql_table_model(data_list), "total_count": page_param.totalRecords})) diff --git a/config/server.py b/config/server.py index da929fa..a342eeb 100644 --- a/config/server.py +++ b/config/server.py @@ -71,6 +71,7 @@ def register_blueprints(app: New_flask): from apps.report.views import report_router from apps.client.views import client_router from apps.power.views import power_router + from apps.monitor.views import monitor_router # 主概览相关 app.register_blueprint(home_router, url_prefix="/api/home") @@ -88,6 +89,8 @@ def register_blueprints(app: New_flask): # 获取用户权限 app.register_blueprint(power_router, url_prefix="/api/power") + # 获取温湿度监控 + app.register_blueprint(monitor_router, url_prefix="/api/monitor") def create_app(): diff --git a/db_logic/humiture_record.py b/db_logic/humiture_record.py index 478f46b..3430a41 100644 --- a/db_logic/humiture_record.py +++ b/db_logic/humiture_record.py @@ -55,7 +55,7 @@ class BllHumitureRecord(Repository): def get_client_day_log(self, client_id, start_time, end_time, page_param): filter_base = "" if client_id: - filter_base += f" clint_id='{client_id}'" + filter_base += f" client_id='{client_id}'" if start_time and end_time: if filter_base: filter_base += " and " @@ -68,8 +68,9 @@ class BllHumitureRecord(Repository): from ( select client_id, client_name, DATE_FORMAT(record_date,'%Y-%m-%d') day_date, - avg(temperature) avg_wd, avg(humidity) avg_sd, - avg(voc_content) avg_voc + round(avg(temperature),2) avg_wd, + round(avg(humidity),2) avg_sd, + round(avg(voc_content),2) avg_voc from rms_humiture_record {filter_base} GROUP BY client_id, DATE_FORMAT(record_date,'%Y-%m-%d') ) a LEFT JOIN rms_client as b on a.client_id=b.client_id ORDER BY day_date desc """ @@ -90,13 +91,14 @@ class BllHumitureRecord(Repository): if filter_base: filter_base += " and " filter_base += f" record_date>= '{start_time}' and record_date<= '{end_time}' " - + if filter_base: + filter_base = f" where {filter_base}" sql_all = f""" select DATE_FORMAT(record_date,'%H:%i:%s') day_date, - FORMAT(temperature,2) as wd, - FORMAT(humidity,2) as sd, - FORMAT(voc_content,2) as voc + round(temperature,2) as wd, + round(humidity,2) as sd, + round(voc_content,2) as voc from rms_humiture_record {filter_base} ORDER BY record_date """ try: