Browse Source

Merge branch 'master' of https://gogs.tjp.com.cn/maoming/python-fastapi-mm-zhcs-yj-api

libushang 1 tháng trước cách đây
mục cha
commit
03decd40fa
2 tập tin đã thay đổi với 128 bổ sung32 xóa
  1. 10 2
      routers/api/riskManagement/task.py
  2. 118 30
      routers/api/videoResource/videoinfo.py

+ 10 - 2
routers/api/riskManagement/task.py

@@ -133,6 +133,8 @@ async def get_inspection_task(
                 "task_number": task.task_number,
                 "business": task.inspection_business,
                 "task_time": '%s-%s'%(task.start_time.strftime('%Y/%m/%d'),task.end_time.strftime('%Y/%m/%d')),
+                "start_time":task.start_time.strftime('%Y-%m-%d'),
+                "end_time":task.end_time.strftime('%Y-%m-%d'),
                 "cycle": task.inspection_cycle,
                 "inspection_range": task.inspection_range,
                 "task_status": task_status,
@@ -178,10 +180,16 @@ async def create_inspection_task(
         else:
             corn=''
         # 创建新的预案记录
+        start_time = body['start_time']
+        if start_time =='':
+            start_time = datetime.now().strftime("%Y-%m-%d 00:00:00")
+        end_time = body['end_time']
+        if end_time =='':
+            end_time= '9999-12-31 00:00:00'
         new_task = RiskManagementInspectionTask(
             inspection_business=body['business'],
-            start_time = body['start_time'],
-            end_time = body['end_time'],
+            start_time = start_time,
+            end_time = end_time,
             inspection_cycle = cycle,
             corn_expression = corn,
             inspection_range = body['inspection_range'],

+ 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)}")