Selaa lähdekoodia

250321-1代码。

baoyubo 4 kuukautta sitten
vanhempi
commit
4e925c38d3

+ 62 - 0
jobs/hkvideo_job.py

@@ -117,6 +117,7 @@ def refresh_hkvideo_list(db: Session):
                             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'],
@@ -140,5 +141,66 @@ def refresh_hkvideo_list(db: Session):
                 print(f"Error occurred during database operations: {e}")
         else:
             print("Failed to fetch initial camera data")
+    else:
+        print("API response is not in the expected format")
+
+
+def refresh_hkvideo_region_list(db: Session):
+    api = hk_video_api.HikvisionAPI()
+    data = api.get_regions()
+
+    if isinstance(data, dict):
+        if data['code'] == '0':
+            total = data['data']['total']
+            page_size = 1000
+            total_pages = (total + page_size - 1) // page_size
+            infos = []
+
+            for page in range(total_pages):
+                print(f'视频条数{total_pages},正在获取视频信息第{page}页')
+                data = api.get_regions(page + 1, page_size)
+                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)
+                else:
+                    print(f"Failed to fetch cameras on page {page + 1}")
+                    return
+
+            try:
+                # 清空表
+                db.execute(text("TRUNCATE TABLE tp_video_region;"))
+                # 插入新数据
+                db.add_all(infos)
+                db.commit()
+            except Exception as e:
+                db.rollback()  # 回滚事务
+                print(f"Error occurred during database operations: {e}")
+        else:
+            print("Failed to fetch initial camera data")
     else:
         print("API response is not in the expected format")

+ 18 - 1
models/video_base.py

@@ -182,8 +182,25 @@ class TPVideoInfo(Base):
     cameraType = Column(String(50), comment="摄像头类型代码")
     cameraTypeName = Column(String(100), comment="摄像头类型名称")
     installPlace = Column(String(255), comment="安装位置")
+    unitIndexCode =  Column(String(255), 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="状态码")
     statusName = Column(String(250), comment="状态名称")
-    location = Column(String(255)) # 存储 POINT 类型的字符串表示
+    location = Column(String(255)) # 存储 POINT 类型的字符串表示
+
+class TPVideoRegion(Base):
+    __tablename__ = 'tp_video_region'  # 表名
+
+    # 字段定义
+    indexCode = Column(String(255),primary_key=True, nullable=False, comment='组织编号(长度1-255位)')
+    name = Column(String(255), nullable=False, comment='组织名称(长度1-255位)')
+    parentIndexCode = Column(String(255), comment='父组织编号(长度1-255位)')
+    treeCode = Column(String(255), comment='树编码')
+    externalIndexCode = Column(String(255), comment='国标编码')
+    sort = Column(Integer, 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="状态码")
+    available=Column(Integer, comment='是否显示')
+    leaf=Column(Integer, comment='是否叶')

+ 2 - 1
routers/api/videoResource/location/__init__.py

@@ -28,7 +28,7 @@ router = APIRouter()
 
 @router.get("/videos")
 async def get_videos(
-        zoom_level: int = Query(..., description="Zoom level for clustering"),
+        zoom_level: float = Query(..., description="Zoom level for clustering"),
         latitude_min: float = Query(..., description="Minimum latitude"),
         latitude_max: float = Query(..., description="Maximum latitude"),
         longitude_min: float = Query(..., description="Minimum longitude"),
@@ -62,6 +62,7 @@ async def get_videos(
                 TPVideoInfo.latitude,
                 TPVideoInfo.longitude,
                 TPVideoInfo.name,
+                TPVideoInfo.unitIndexCode,
                 func.ST_AsText(TPVideoInfo.location).label("location")
             )
             .select_from(TPVideoInfo).where(

+ 13 - 0
utils/hk_video_api.py

@@ -104,3 +104,16 @@ class HikvisionAPI:
             return response.json()
         else:
             raise Exception(f"Failed to get preview URL: {response.text}")
+    def get_regions(self,pageNo=1,pageSize=1):
+        path = "/api/resource/v1/regions"
+        url = f"{self.base_url}{path}"
+        body =  {
+            "pageNo": pageNo,"pageSize":pageSize,
+            "treeCode": "0"
+        }
+        headers =self._generate_signature(path)
+        response = requests.post(url, headers=headers, json=body, verify=False)
+        if response.status_code == 200:
+            return response.json()
+        else:
+            raise Exception(f"Failed to get preview URL: {response.text}")