提交 15df0e6b authored 作者: zw.wang's avatar zw.wang

feat: 对接mysql查询摄像头信息

上级 0ecf7ced
......@@ -76,11 +76,34 @@ def query(cursor_dict=False):
return in_func
@query(cursor_dict=True)
def get_camera_info(cursor, conn):
sql = '''
select id as camera_id,
name as camera_name,
point_index_code,
'131331' as event_type,
concat('common_video_', mod(service_type, 2), '.',
'video_data_motion_', mod(biz_type, 8)) as 'db_table',
ai_config_support, device_code, service_type, biz_type
from camera_info
join camera_ai_config cac
on camera_info.id = cac.camera_info_id
where biz_type is not null
order by create_time;
'''
cursor.execute(sql)
cameras = cursor.fetchall()
if not cameras:
cameras = []
return cameras
@query()
def insert_video_info(cursor, conn, device_code, file_name, start_time, end_time,
def insert_video_info(cursor, conn, db_table, device_code, file_name, start_time, end_time,
recovered_time, date, video_url, video_resolution, status=0):
sql = '''
insert video_data_motion_test (
insert {} (
device_code, file_name, start_date, end_date,
recovered_time, date,
video_url, video_resolution,
......@@ -92,7 +115,7 @@ def insert_video_info(cursor, conn, device_code, file_name, start_time, end_time
1, 1,
date_add(now(),interval 31 day), %(status)s, now()
)
'''
'''.format(db_table)
cursor.execute(sql, {
'device_code': device_code,
'file_name': file_name,
......
......@@ -10,20 +10,11 @@ from intelab_python_sdk.logger import log
from hikvision_isc_client.db import rabbitmq_connect, redis_connect
from hikvision_isc_client.const import LAST_CHECK_TIME_KEY
from hikvision_isc_client.pre_event import PreEvent
from hikvision_isc_client.db.mysql import get_camera_info
tz = pytz.timezone('Asia/Shanghai')
def get_camera_info():
camera_info = {
'index_code': '9e6768059bd74f6085eec605b7658e8f',
'event_type': '131331',
'device_code': 'D86639983',
'db_table': 'video_0.video_data_motion_1'
}
return [camera_info]
class EventMergerJob:
def __init__(self):
......@@ -72,7 +63,7 @@ class EventMergerJob:
last_check_time.strftime('%Y-%m-%d %H:%M:%S'),
now.strftime('%Y-%m-%d %H:%M:%S')
)
alarm_list = list(pre_event.get_alarm_list(camera['index_code']))
alarm_list = list(pre_event.get_alarm_list(camera['point_index_code']))
log.info('time: {}-{}, alarm_list: {}'.format(last_check_time, now, len(alarm_list)))
connection = None
# if len(alarm_list) > 0:
......@@ -89,10 +80,10 @@ class EventMergerJob:
for event in events:
body = {
'camera_index': camera['index_code'],
'camera_index': camera['point_index_code'],
'start_time': event['start_time'].astimezone(pytz.utc).strftime('%Y-%m-%dT%H:%M:%S'),
'end_time': event['end_time'].astimezone(pytz.utc).strftime('%Y-%m-%dT%H:%M:%S'),
'event_type': '131331',
'event_type': camera['event_type'],
'camera_code': camera['device_code'],
'db_table': camera['db_table']
}
......
......@@ -104,13 +104,13 @@ class StreamRecorder:
record_result['file_name'])
os.remove(record_result['file_name'])
video_id = insert_video_info(body['camera_code'], file_name, body['start_time'],
video_id = insert_video_info(body['db_table'], body['camera_code'], file_name, body['start_time'],
body['end_time'],
recovered_time=record_result['recovered_time'].astimezone(pytz.utc),
date=body['start_time'].split('T')[0].replace('-', ''),
video_url=url, video_resolution=video_info['resolution'],
status=1 if record_result['is_completed'] else 2)
log.info('video_info: %s, url: %s, video_id: %s', video_info, url, video_id)
log.info('video_info: %s, url: %s, video_id: %s.%s', video_info, url, body['db_table'], video_id)
return True
@staticmethod
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论