This commit is contained in:
DingZQ
2025-03-19 22:21:53 +08:00
parent fb2f6aee80
commit e56e3e0078
2 changed files with 26 additions and 2 deletions

View File

@@ -1,10 +1,34 @@
import schedule
import time
import datetime
import shutil
import redis
import urllib.request
def query_all_records_by_date_with_type_flow(date: str):
try:
response = urllib.request.urlopen('localhost/queryallrecordbydatewithtype/?querydate={date}&querytype=flow')
html = response.read().decode('utf-8')
print(html)
except urllib.error.URLError as e:
print("Error")
def auto_cache_data():
redis_client = redis.redis(host='localhost', port=6379, db=0)
items = ['queryallrecordsbydatewithtype_[DATE]_flow']
today - datetime.date.today()
print(today)
for item in items:
prev_day = today.deltaday(-1)
str_prev_day = prev_day.strftime('%Y-%m-%d')
print(str_prev_day)
key = item.replace('[DATE]', str_prev_day)
if not redis_client.exists(key):
query_all_records_by_date_with_type_flow(str_prev_day)
if __name__ == "__main__":
auto_cache_data()

View File

@@ -2245,7 +2245,7 @@ async def fastapi_query_scada_data_by_device_id_and_date(ids: str, querydate: st
async def fastapi_query_all_scada_records_by_date(querydate: str):
# 缓存查询结果提高性能
global redis_client
cache_key = f"{querydate}"
cache_key = f"queryallscadarecordsbydate_{querydate}"
data = redis_client.get(cache_key)
if data:
# 使用自定义的反序列化函数