@ -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 )