后端更新

This commit is contained in:
BBIT-Kai
2026-03-26 17:48:20 +08:00
parent 4c2bcd7dce
commit 0c2859b0db
22 changed files with 1336 additions and 213 deletions
+7 -7
View File
@@ -1,14 +1,16 @@
import asyncio
import base64
from fastapi import APIRouter
from config.app import F8_SERVER_USER_ID
from db.postgres.sentinel import saveSentinelRecord
from models.BaseResponse import BaseResponse
from models.F8ImageRequest import F8ImageRequest
from models.F8ImageRequestV2 import F8ImageRequestV2
from models.SentinelRecordRequest import SentinelRecordRequest
from service.RabbitMQ import sentinel_new_analysis
from service.RabbitMQ import (
mq_client,
)
from service.vision import (
process_ticket_image,
process_license_image,
@@ -85,8 +87,6 @@ async def recognize_silkworm_cocoon(data: F8ImageRequest):
@publicRouter.post("/sentinel-record-analytics")
async def delete_sentinel_record(data: SentinelRecordRequest):
# 保存部分数据到数据库
data.Id = saveSentinelRecord(data)
# 发送请求给RabbitMQ
res = await sentinel_new_analysis(data)
return BaseResponse(data=res)
# 发送全盘分析请求给RabbitMQ
asyncio.create_task(mq_client.send_all_analysis(data))
return BaseResponse(data="submitted")
+73 -36
View File
@@ -107,22 +107,51 @@ async def get_sentinel_monitor_promotional_list(
):
if not user_id:
return {"error": "userId is required"}
# 图片过期时间:7天
expiration_time = 60 * 60 * 24 * 7
return BaseResponse(
data=[
{
"id": 1,
"remark": "人员公示及岗位职责",
"url": get_temp_url("sentinel", "promotional/promotional (2).jpg"),
"url": get_temp_url(
"sentinel", "promotional/promotional (2).jpg", expiration_time
),
},
{
"id": 2,
"remark": "入川动物监督检查工作流程图",
"url": get_temp_url("sentinel", "promotional/promotional (1).jpg"),
"url": get_temp_url(
"sentinel", "promotional/promotional (1).jpg", expiration_time
),
},
{
"id": 3,
"remark": "四川省人民政府关于设立川动物运输指定通道的通告",
"url": get_temp_url("sentinel", "promotional/promotional (3).jpg"),
"remark": "四川省人民政府关于设立川动物运输指定通道的通告",
"url": get_temp_url(
"sentinel", "promotional/promotional (3).jpg", expiration_time
),
},
{
"id": 4,
"remark": "四川省动物卫生监督检查站工作程序",
"url": get_temp_url(
"sentinel", "promotional/promotional (4).jpg", expiration_time
),
},
{
"id": 5,
"remark": "四川省动物卫生监督检查站无害化处理制度",
"url": get_temp_url(
"sentinel", "promotional/promotional (5).jpg", expiration_time
),
},
{
"id": 6,
"remark": "四川省动物卫生监督检查站工作人员行为规范",
"url": get_temp_url(
"sentinel", "promotional/promotional (6).jpg", expiration_time
),
},
]
)
@@ -153,40 +182,48 @@ async def get_sentinel_monitor_list(
)
url = "https://open.ys7.com/api/lapp/v2/live/address/get"
# device_serials = ["BG2493625"]
device_serials = ["BG2493625", "GH3713250", "GH3714496", "GH3714497"]
device_serials = {
# "GG9175589": [1, 2, 3, 4],
"GG9175589": [1, 3],
"GG9175555": [1, 2],
}
video_expire_time = 25 * 24 * 60 * 60 # 25 天
res = []
for device_serial in device_serials:
live_key = f"ys7:live:{device_serial}"
cached_live = redis_client.get_value(live_key)
for device_serial, channels in device_serials.items():
for channelNo in channels:
live_key = f"ys7:live:{device_serial}:{channelNo}"
cached_live = redis_client.get_value(live_key)
if cached_live:
video_id = cached_live.get("id")
video_url = cached_live.get("url")
else:
payload = {
"accessToken": access_token,
"deviceSerial": device_serial,
"channelNo": channelNo,
"protocol": 4,
"expireTime": video_expire_time,
"supportH265": 0,
"quality": 2,
}
result = await http_client.post(url, data=payload)
video_data = result.get("data")
if not video_data:
continue # 或者记录异常日志
video_id = video_data["id"]
video_url = video_data["url"]
redis_client.set_value(
live_key,
{"id": video_id, "url": video_url},
expire=video_expire_time,
)
res.append({"id": video_id, "url": video_url})
if cached_live:
video_id = cached_live.get("id")
video_url = cached_live.get("url")
else:
payload = {
"accessToken": access_token,
"deviceSerial": device_serial,
"protocol": 4, # 流播放协议,1-ezopen、2-hls、3-rtmp、4-flv,默认为1
"expireTime": video_expire_time, # 25天
"supportH265": 0,
"quality": 2,
}
result = await http_client.post(url, data=payload)
video_id = result["data"]["id"]
video_url = result["data"]["url"]
# 存到 Redis,自动序列化为 JSON,过期 25天
redis_client.set_value(
live_key,
{"id": video_id, "url": video_url},
expire=video_expire_time,
)
res.append(
{
"id": video_id,
"url": video_url,
}
)
return BaseResponse(data=res)