past_seven_days
This commit is contained in:
parent
6b7b44a1af
commit
4ba135f885
8
xumu.py
8
xumu.py
|
@ -24,7 +24,7 @@ class BaseResponse(BaseModel):
|
||||||
async def video_query(username):
|
async def video_query(username):
|
||||||
return BaseResponse(data=get_video_url(username))
|
return BaseResponse(data=get_video_url(username))
|
||||||
|
|
||||||
|
# 报警数据接口
|
||||||
@app.get("/api/xumu/warning")
|
@app.get("/api/xumu/warning")
|
||||||
async def get_warning(deviceId):
|
async def get_warning(deviceId):
|
||||||
try:
|
try:
|
||||||
|
@ -34,6 +34,8 @@ async def get_warning(deviceId):
|
||||||
"sql": sql
|
"sql": sql
|
||||||
}
|
}
|
||||||
r = requests.post(baseHost + queryUri, headers=headers, json=send_json)
|
r = requests.post(baseHost + queryUri, headers=headers, json=send_json)
|
||||||
|
data = r.json()
|
||||||
|
|
||||||
return BaseResponse(data=r.json())
|
return BaseResponse(data=r.json())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return BaseResponse(code=500, msg=str(e))
|
return BaseResponse(code=500, msg=str(e))
|
||||||
|
@ -327,14 +329,14 @@ async def process_data(request: Request):
|
||||||
|
|
||||||
|
|
||||||
# 监测数据最近7天的数据
|
# 监测数据最近7天的数据
|
||||||
@app.get("/api/xumu/data/past_seven_days")
|
@app.get("/api/xumu/warning/past_seven_days")
|
||||||
async def past_seven_days(deviceId):
|
async def past_seven_days(deviceId):
|
||||||
try:
|
try:
|
||||||
current_date = datetime.now().date()
|
current_date = datetime.now().date()
|
||||||
past_7_days_date = current_date - timedelta(days=7)
|
past_7_days_date = current_date - timedelta(days=7)
|
||||||
if deviceId is None or deviceId == "" or len(deviceId) != 4:
|
if deviceId is None or deviceId == "" or len(deviceId) != 4:
|
||||||
return BaseResponse(code=500, msg="参数错误")
|
return BaseResponse(code=500, msg="参数错误")
|
||||||
sql = f"select * from root.farm.{deviceId} where time >= {past_7_days_date} and time <= {current_date}"
|
sql = f"select * from root.warning.{deviceId} where time >= {past_7_days_date} and time <= {current_date}"
|
||||||
send_json = {
|
send_json = {
|
||||||
"sql": sql
|
"sql": sql
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue