浏览代码

250416-1代码。

baoyubo 1 月之前
父节点
当前提交
08dbdde9ac
共有 1 个文件被更改,包括 118 次插入30 次删除
  1. 118 30
      routers/api/videoResource/videoinfo.py

+ 118 - 30
routers/api/videoResource/videoinfo.py

@@ -538,10 +538,57 @@ async def get_dict_data_by_type(
 
         traceback.print_exc()
         raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
+def id_get_region_info(db, indexCode):
+    query = db.query(TPVideoRegion)
+    query = query.filter(TPVideoRegion.indexCode == indexCode)
+    return query.all()
+def parent_id_get_region_info(db, parent_id):
+    query = db.query(TPVideoRegion)
+    query = query.filter(TPVideoRegion.parentIndexCode == parent_id)
+    query = query.order_by(TPVideoRegion.sort.asc())
+    return query.all()
+def parent_id_get_video_info(db, unitIndexCode,status):
+    query = db.query(TPVideoInfo)
+    query = query.filter(TPVideoInfo.unitIndexCode == unitIndexCode)
+    query = query.order_by(TPVideoInfo.gbIndexCode.asc())
+    if status:
+        query = query.filter(TPVideoInfo.status == status)
+    return query.all()
+@router.get('/get_video_forest_fire_index_code')
+async def get_dict_data_by_type(
+    db: Session = Depends(get_db)
+):
+    try:
+        # 根据 dict_type 查询字典数据
+        # dict_data = db.query(SysDictData).filter_by(dict_type=dictType).all()
+        d = parent_id_get_region_info(db, '4409000000216202502')
+
+        dict_data_list = [{
+                "dictCode": data.indexCode,
+                "dictSort": data.sort,
+                "dictLabel": data.name,
+                "dictValue": data.indexCode,
+                "dictType": '',
+                "cssClass": '',
+                "listClass": ''
+            }for data in d]
+
+        # 构建返回结果
+        result = {
+            "data": dict_data_list,
+            "code": 200,
+            "msg": "查询成功"
+        }
+        return result
+
+    except Exception as e:
+        traceback.print_exc()
+        raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
 
 @router.get('/get_video_forest_fire_list')
 async def get_video_forest_fire_list(
-        radius:int = Query(None),
+        indexCode:str = Query('4409000000216202502'),
+        status:str = Query(None),
         db: Session = Depends(get_db),
         body=Depends(remove_xss_json),
         user_id=Depends(valid_access_token)):
@@ -553,42 +600,83 @@ async def get_video_forest_fire_list(
             :param paths: 包含层级路径的列表
             :return: 树形结构的字典
             """
-        video_code_list = [item[0] for item in db.query(TpVideoTag.video_code).filter(TpVideoTag.dict_value == 'slfh').all()]
-        # print(video_code_list)
-        video_list = db.query(TpVideoLog).filter(TpVideoLog.video_code.in_(video_code_list)).all()
-        root = {"label": "Root", "children": [],"online":0,"total":0}  # 创建根节点
+        "20ba3e565de64df9b29ff70a8056939a"
+
+
+        def build_video_tree(regions, parent_region,online,total,status):
+            video_tree = []
+            for region_info in regions:
+                region = {
+                    "label": region_info.name,
+                    "isLeaf": False,
+                    "status": region_info.status,
+                    "children":[]
+                }
+                # print(dept_info.dept_id)
+
+                videos = parent_id_get_video_info(db, region_info.indexCode,status)
+                if len(videos) > 0:
+                    for video_info in videos:
+                        region["children"].append({"label":video_info.name,"status":video_info.status,"video_code":video_info.gbIndexCode,"isLeaf":True})
+                        if video_info.status==1:
+                            online+=1
+                        total += 1
+                children = parent_id_get_region_info(db, region_info.indexCode)
+                if len(children) > 0:
+                    children_regions, online, total = build_video_tree(children, region, online, total,status)
+                    region["children"] = children_regions+region["children"]
+                video_tree.append(region)
+
+            return video_tree,online,total
+
+        result,online,total = build_video_tree(id_get_region_info(db, indexCode), None,0,0,status)
 
-        for video_info in video_list:
-            levels = video_info.area.split('/')
-            current_node = root
-            current_node['total']+=1
-            if video_info.status == '在线':
-                current_node['online']+=1
-            for level in levels:
-                # 查找当前层级是否已存在
-                existing_node = next((node for node in current_node["children"] if node["label"] == level), None)
-                if not existing_node:
-                    # 如果不存在,创建新节点
-                    new_node = {"label": level, "children": [],"online":0,"total":0}
-                    current_node["children"].append(new_node)
-                    existing_node = new_node
-
-                # 移动到子节点
-                current_node = existing_node
-                current_node['total']+=1
-                if video_info.status == '在线':
-                    current_node['online']+=1
-
-            current_node['children'].append({"label":video_info.name,"status":video_info.status,"video_code":video_info.video_code,"isLeaf":True})
 
         return {
             "code": 200,
             "msg": "成功",
-            "data": root['children'],
-            'online':root['online'],
-        'total':root['total']
+            "data": result,
+            'online':online,
+            'total':total
         }
 
+        #
+        # video_code_list = [item[0] for item in db.query(TpVideoTag.video_code).filter(TpVideoTag.dict_value == 'slfh').all()]
+        # # print(video_code_list)
+        # video_list = db.query(TpVideoLog).filter(TpVideoLog.video_code.in_(video_code_list)).all()
+        # root = {"label": "Root", "children": [],"online":0,"total":0}  # 创建根节点
+        #
+        # for video_info in video_list:
+        #     levels = video_info.area.split('/')
+        #     current_node = root
+        #     current_node['total']+=1
+        #     if video_info.status == '在线':
+        #         current_node['online']+=1
+        #     for level in levels:
+        #         # 查找当前层级是否已存在
+        #         existing_node = next((node for node in current_node["children"] if node["label"] == level), None)
+        #         if not existing_node:
+        #             # 如果不存在,创建新节点
+        #             new_node = {"label": level, "children": [],"online":0,"total":0}
+        #             current_node["children"].append(new_node)
+        #             existing_node = new_node
+        #
+        #         # 移动到子节点
+        #         current_node = existing_node
+        #         current_node['total']+=1
+        #         if video_info.status == '在线':
+        #             current_node['online']+=1
+        #
+        #     current_node['children'].append({"label":video_info.name,"status":video_info.status,"video_code":video_info.video_code,"isLeaf":True})
+        #
+        # return {
+        #     "code": 200,
+        #     "msg": "成功",
+        #     "data": root['children'],
+        #     'online':root['online'],
+        # 'total':root['total']
+        # }
+
     except Exception as e:
         traceback.print_exc()
         raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")