소스 검색

250325-3代码。

baoyubo 1 개월 전
부모
커밋
ff532e9570
3개의 변경된 파일40개의 추가작업 그리고 27개의 파일을 삭제
  1. 32 26
      jobs/hkvideo_job.py
  2. 2 0
      models/video_base.py
  3. 6 1
      utils/video_util.py

+ 32 - 26
jobs/hkvideo_job.py

@@ -4,6 +4,7 @@ from datetime import datetime
 from sqlalchemy.orm import Session
 from sqlalchemy import text
 from utils import *
+from utils.video_util import unitIndexCode_get_video_region_info
 from utils.redis_util import *
 from models import *
 from exceptions import *
@@ -21,6 +22,7 @@ def proc():
         db = get_db_local()
 
         refresh_hkvideo(db)
+        refresh_hkvideo_region_list(db)
         refresh_hkvideo_list(db)
 
         db.close()
@@ -108,6 +110,10 @@ def refresh_hkvideo_list(db: Session):
                             longitude = 0.0
                         if latitude=='':
                             latitude = 0.0
+                        regionPath = ''
+                        region = unitIndexCode_get_video_region_info(db,camera_info['unitIndexCode'])
+                        if region is not None:
+                            regionPath = region.regionPath
                         info = TPVideoInfo(
                             cameraIndexCode=camera_info['cameraIndexCode'],
                             gbIndexCode=camera_info['gbIndexCode'],
@@ -118,6 +124,7 @@ def refresh_hkvideo_list(db: Session):
                             pixel=camera_info['pixel'],
                             cameraType=camera_info['cameraType'],
                             unitIndexCode = camera_info['unitIndexCode'],
+                            regionPath = regionPath,
                             cameraTypeName=camera_info['cameraTypeName'],
                             installPlace=camera_info['installPlace'],
                             updateTime=camera_info['updateTime'],
@@ -162,31 +169,30 @@ def refresh_hkvideo_region_list(db: Session):
                 if data['code'] == '0':
                     region_list = data['data']['list']
                     for cregion_info in region_list:
-                        pass
-                        # longitude= camera_info['longitude']
-                        # latitude = camera_info['latitude']
-                        # if longitude=='':
-                        #     longitude = 0.0
-                        # if latitude=='':
-                        #     latitude = 0.0
-                        # info = TPVideoInfo(
-                        #     cameraIndexCode=camera_info['cameraIndexCode'],
-                        #     gbIndexCode=camera_info['gbIndexCode'],
-                        #     name=camera_info['name'],
-                        #     longitude=longitude,
-                        #     latitude=latitude,
-                        #     altitude=camera_info['altitude'],
-                        #     pixel=camera_info['pixel'],
-                        #     cameraType=camera_info['cameraType'],
-                        #     unitIndexCode = camera_info['unitIndexCode'],
-                        #     cameraTypeName=camera_info['cameraTypeName'],
-                        #     installPlace=camera_info['installPlace'],
-                        #     updateTime=camera_info['updateTime'],
-                        #     createTime=camera_info['createTime'],
-                        #     status=camera_info['status'],
-                        #     statusName=camera_info['statusName']
-                        # )
-                        # infos.append(info)
+                        if cregion_info['leaf']:
+                            leaf='1'
+                        else:
+                            leaf='0'
+                        if cregion_info['available']:
+                            available ='1'
+                        else:
+                            available = '0'
+                        info = TPVideoRegion(
+                                    indexCode = cregion_info['indexCode'],
+                                    regionPath = cregion_info['regionPath'],
+                                    name = cregion_info['name'],
+                                    parentIndexCode = cregion_info['parentIndexCode'],
+                                    treeCode = cregion_info['treeCode'],
+                                    externalIndexCode = cregion_info['externalIndexCode'],
+                                    sort = cregion_info['sort'],
+                                    updateTime = cregion_info['updateTime'],
+                                    createTime = cregion_info['createTime'],
+                                    status = cregion_info['status'],
+                                    available=available,
+                                    leaf=leaf
+                        )
+                        infos.append(info)
+
                 else:
                     print(f"Failed to fetch cameras on page {page + 1}")
                     return
@@ -203,4 +209,4 @@ def refresh_hkvideo_region_list(db: Session):
         else:
             print("Failed to fetch initial camera data")
     else:
-        print("API response is not in the expected format")
+        print("API response is not in the expected format")

+ 2 - 0
models/video_base.py

@@ -183,6 +183,7 @@ class TPVideoInfo(Base):
     cameraTypeName = Column(String(100), comment="摄像头类型名称")
     installPlace = Column(String(255), comment="安装位置")
     unitIndexCode =  Column(String(255), comment="所属组织编号")
+    regionPath = Column(Text, comment='机构路径')
     updateTime = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment="更新时间")
     createTime = Column(DateTime, server_default=func.now(), comment="创建时间")
     status = Column(String(255), comment="状态码")
@@ -195,6 +196,7 @@ class TPVideoRegion(Base):
     # 字段定义
     indexCode = Column(String(255),primary_key=True, nullable=False, comment='组织编号(长度1-255位)')
     name = Column(String(255), nullable=False, comment='组织名称(长度1-255位)')
+    regionPath = Column(Text, comment='机构路径')
     parentIndexCode = Column(String(255), comment='父组织编号(长度1-255位)')
     treeCode = Column(String(255), comment='树编码')
     externalIndexCode = Column(String(255), comment='国标编码')

+ 6 - 1
utils/video_util.py

@@ -12,4 +12,9 @@ def tag_get_video_tag_list(db,dict_value:str):
     query = query.filter(TpVideoTag.del_flag != '2')
     query = query.filter(TpVideoTag.dict_value == dict_value)
     query = query.order_by(TpVideoTag.video_code)
-    return query.all()
+    return query.all()
+
+def unitIndexCode_get_video_region_info(db,unitIndexCode:str):
+    query = db.query(TPVideoRegion)
+    query = query.filter(TPVideoRegion.indexCode == unitIndexCode)
+    return query.first()