添加环境监控数据;

添加试剂使用率接口数据
duizhaopin
apan 3 years ago
parent 4c7aa7483b
commit 10593d079f

@ -4,6 +4,7 @@
@Date:2022/07/18 16:19:33
'''
from flask import jsonify, request, g
from db_logic.humiture_record import BllHumitureRecord
from db_logic.medicament import BllMedicament
from models.warning_models import EntityWarning
@ -120,3 +121,17 @@ def update_warning_type():
# 获取环境控图
@home_router.route("/get_monitoring_info", methods=["GET", "POST"])
def get_monitoring_info():
client_id = request.values.get("client_id")
time_type = request.values.get("time_type")
obj_type = request.values.get("obj_type")
data_list = BllHumitureRecord().get_data_info_list(
client_id=client_id,
time_type=time_type,
obj_type=obj_type
)
return jsonify(Utils.true_return(data=Utils.msyql_table_model(data_list)))

@ -5,9 +5,11 @@
'''
from operator import index
import sys
from db_logic.user import BllUser
sys.path.append('.')
from flask import Blueprint, request, g
from flask import Blueprint, jsonify, request, g
from db_logic.module_relation import BllModuleRelation
from Common.Utils import Utils
power_router = Blueprint('power', __name__)
@ -15,13 +17,16 @@ power_router = Blueprint('power', __name__)
@power_router.route("/user_power", methods=["GET", "POST"])
def get_user_power_list():
user_info = g.current_user
# user_info = g.current_user
user_id = '4cea74ee-0d8b-11ed-943e-f47b094925e1'
user_info = BllUser().findEntity(user_id)
module_list = BllModuleRelation().get_user_module_list(user_id=user_info.user_id, role_id=user_info.role_id)
module_list = Utils.msyql_table_model(module_list)
if len(module_list) > 6:
for module in module_list:
if module["module_code"] == "DataReport":
if module_list.index(module) in [1,2,4]:
module_list.pop(module_list.index(module))
module_list.insert(5, module)
data = module_list
return jsonify(Utils.true_return(data=module_list))
# if len(module_list) > 6:
# for module in module_list:
# if module["module_code"] == "DataReport":
# if module_list.index(module) in [1,2,4]:
# module_list.pop(module_list.index(module))
# module_list.insert(5, module)
# data = module_list

@ -45,6 +45,7 @@ report_router = Blueprint("report", __name__)
def report_home_show():
resp_data = {
"drug_use_type_data": "",
"use_avg_info":{},
"drug_stock_expend": {"count_number":0, "data":""},
"drug_use_expend":"",
"user_use_expend": ""
@ -53,7 +54,7 @@ def report_home_show():
try:
obj_data = BllMedicamentRecord()
# 试剂使用统计
drug_use_type_data = obj_data.get_drug_record_count()
drug_use_type_data, avg_use_dic = obj_data.get_drug_record_count()
# 消耗统计部分
drug_stock_expend, num_all = BllMedicament().get_drug_stock_use_classify()
# 试剂用量消耗
@ -61,6 +62,7 @@ def report_home_show():
# 用户试剂消耗
user_use_expend = obj_data.report_home_user_use_info()
resp_data["drug_use_type_data"] = drug_use_type_data
resp_data["use_avg_info"] = avg_use_dic
resp_data["drug_stock_expend"] = {
"count_number": num_all,
"data": drug_stock_expend

@ -70,6 +70,7 @@ def register_blueprints(app: New_flask):
from apps.user.views import user_router
from apps.report.views import report_router
from apps.client.views import client_router
from apps.power.views import power_router
# 主概览相关
app.register_blueprint(home_router, url_prefix="/api/home")
@ -84,6 +85,9 @@ def register_blueprints(app: New_flask):
# 客户端相关
app.register_blueprint(client_router, url_prefix="/api/client")
# 获取用户权限
app.register_blueprint(power_router, url_prefix="/api/power")
def create_app():

@ -24,22 +24,85 @@ class BllHumitureRecord(Repository):
def __init__(self, entityType=EntityHumitureRecord):
return super().__init__(entityType)
def get_data_info_list(self, client_id, time_type="1", obj_type="1"):
# 1.24小时2近七天3.近一个月
time_dic = {
"1": "record_date >=(NOW() - interval 24 hour)",
"2": "DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= DATE(record_date)",
"3": "DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= DATE(record_date)"
}
time_str = time_dic.get(time_type)
# 1湿度2温度3voc
obj_type_dict = {
"1": "temperature",
"2": "humidity",
"3": "voc_content",
}
obj_type_str = obj_type_dict.get(obj_type)
filter_base = ""
if client_id:
filter_base += f" and client_id='{client_id}'"
sql_all = f"""
select {obj_type_str}, record_date from rms_humiture_record where {time_str} {filter_base} order by record_date
"""
return self.execute(sql_all).fetchall()
# 获取温湿度列表
# def getHumitureList(self, customerId, pageParam):
# queryStr = 'select * from ((select * from rms_humiture_record where client_id=:client_id) '
# queryStr += ' union all (select * from rms_humiture_record where client_id!=:client_id order by client_name ASC ) )t order by t.record_date DESC '
def getHumitureList(self, customerId, pageParam):
queryStr = 'select * from ((select * from rms_humiture_record where client_id=:client_id) '
queryStr += ' union all (select * from rms_humiture_record where client_id!=:client_id order by client_name ASC ) )t order by t.record_date DESC '
queryCountStr = 'select COUNT(*) from ((select * from rms_humiture_record where client_id=:client_id) '
queryCountStr += ' union all (select * from rms_humiture_record where client_id!=:client_id order by client_name ASC ) )t order by t.record_date DESC '
# queryParams = {"clientId": CurrentInfo.ClientInfo.client_id}
queryParams = {"client_id": customerId}
templateList = self.execute(queryStr + ' limit ' + str((pageParam.curPage - 1)
* pageParam.pageRows) + ',' + str(pageParam.pageRows), queryParams).fetchall()
pageParam.totalRecords = self.execute(
queryCountStr, queryParams).fetchone()[0]
jsonData = Utils.mysqlTable2Model(templateList)
return jsonData
# queryCountStr = 'select COUNT(*) from ((select * from rms_humiture_record where client_id=:client_id) '
# queryCountStr += ' union all (select * from rms_humiture_record where client_id!=:client_id order by client_name ASC ) )t order by t.record_date DESC '
# # queryParams = {"clientId": CurrentInfo.ClientInfo.client_id}
# queryParams = {"client_id": customerId}
# templateList = self.execute(queryStr + ' limit ' + str((pageParam.curPage - 1)
# * pageParam.pageRows) + ',' + str(pageParam.pageRows), queryParams).fetchall()
# pageParam.totalRecords = self.execute(
# queryCountStr, queryParams).fetchone()[0]
# jsonData = Utils.mysqlTable2Model(templateList)
# return jsonData
def insert_one(self, entity):
self.insert(entity)
# def get_month(self, num):
# import arrow
# month_list = []
# a = arrow.now() # 当前本地时间
# for i in range(0, num + 1):
# yearmonth = a.shift(hours=-i).format("YYYY-MM-DD HH:mm:ss")
# month_list.append(yearmonth)
# month_list.sort()
# return month_list
# def inster_log_info_list(self):
# import random
# date_list = self.get_month(100)
# data_list = []
# for i in date_list:
# obj = EntityHumitureRecord(
# client_id='1c39cb24-07f8-11ed-abd4-f47b094925e1',
# client_name='测试机器',
# temperature=round(random.uniform(-1, 1),2),
# humidity=round(random.uniform(-1, 1),2),
# record_date=i,
# voc_content=round(random.uniform(-1, 1),2)
# )
# data_list.append(obj)
# self.insert_many(data_list)
if __name__ == '__main__':
data = BllHumitureRecord().get_data_info_list('')
print(data)
for i in data:
print(i)

@ -121,6 +121,27 @@ class BllMedicamentRecord(Repository):
# print(sql_all)
return self.execute(sql_all).fetchall()
# 获取报表统计主页,使用频率
def get_use_avg_number(self):
sql_all = """
select a.`name`, IFNULL(b.count_number ,0) count_number from (
select medicament_id, purity, `name`, speci from rms_medicament
) a LEFT JOIN(
select medicament_id, count(record_id) count_number from rms_medicament_record where record_type=2 GROUP BY medicament_id
) b
on a.medicament_id=b.medicament_id GROUP BY a.purity, a.`name`, a.speci ORDER BY count_number desc
"""
sql_data = self.execute(sql_all).fetchall()
use_number = sum([float(i[1]) for i in sql_data])
drug_num = len(sql_data)
resp_data = {
"avg_use_number": round(use_number / drug_num),
"max_name": sql_data[0][0],
"max_number": sql_data[0][1]
}
return resp_data
# 获取报表统计主页入库记录信息
def get_drug_record_count(self):
sql_all = """
@ -144,7 +165,7 @@ class BllMedicamentRecord(Repository):
}
new_dic.update(**i)
data_list.append(new_dic)
return data_list
return data_list, self.get_use_avg_number()
# 获取报表统计主页试剂用量消耗
def report_home_drug_useing_classify(self):
@ -431,7 +452,7 @@ class BllMedicamentRecord(Repository):
# return result
if __name__ == '__main__':
aaa = BllMedicamentRecord().getTodayDrugRecordCount('', '')
aaa = BllMedicamentRecord().get_use_avg_number()
print(aaa)
# import random
# from db_logic.medicament_record import BllMedicamentRecord

@ -308,3 +308,14 @@ object_type=1 查询权限id
def get_month(num):
import arrow
month_list = []
a = arrow.now() # 当前本地时间
for i in range(0, num + 1):
yearmonth = a.shift(hours=-i).format("YYYY-MM-DD HH:mm:ss")
month_list.append(yearmonth)
month_list.sort()
return month_list
print(get_month(48))

@ -23,5 +23,6 @@ class EntityHumitureRecord(Base):
customer_id = Column(String(50), comment='客户id') # 客户ID
temperature = Column(Float, comment='温度值') # 温度值
humidity = Column(Float, comment='湿度值') # 湿度值
voc_content = Column(Float, comment='voc含量') # voc含量
record_date = Column(String(50), comment='记录日期') # 记录日期
is_add = Column(Integer, comment='是否添加', default=1)

Loading…
Cancel
Save