浏览代码

250707-2代码。

baoyubo 1 月之前
父节点
当前提交
cd14aacffe
共有 1 个文件被更改,包括 50 次插入0 次删除
  1. 50 0
      routers/api/dutyManagement/contact.py

+ 50 - 0
routers/api/dutyManagement/contact.py

@@ -26,6 +26,10 @@ def parent_id_get_contact_dept_list(db,parent_id):
     query = query.filter(EmergencyContactDepartment.del_flag != '2')
     query = query.filter(EmergencyContactDepartment.parent_department_id == parent_id)
     return query.all()
+def yzy_parent_id_get_contact_dept_list(db,parent_id):
+    query = db.query(YzyOrgUnitEntity)
+    query = query.filter(YzyOrgUnitEntity.parentunitid == parent_id)
+    return query.all()
 def id_get_contact_dept_info(db,id):
     query = db.query(EmergencyContactDepartment)
     query = query.filter(EmergencyContactDepartment.del_flag != '2')
@@ -77,6 +81,52 @@ async def get_dict_data_by_type(
             'msg': str(e)
         })
 
+@router.get('/yzy/department/data')
+async def get_dict_data_by_type(
+    db: Session = Depends(get_db),
+    user_id = Depends(valid_access_token)
+):
+
+    try:
+
+        data = yzy_parent_id_get_contact_dept_list(db,'0')
+
+        def build_dept_tree(depts, parent_dept):
+            dept_tree = []  # 初始化一个列表来存储菜单树结构
+            for dept in depts:
+                dept_data = {
+                    "id": dept.id,
+                    "isShowSelect": False,
+                    "label": dept.department_name,
+                    "regionPath": dept.regionPath,
+                    "yzy_unitid": dept.yzy_unitid,
+                }
+                children_depts =  yzy_parent_id_get_contact_dept_list(db,dept.id)
+                if len(children_depts) > 0:
+                    dept_data['children'] = build_dept_tree(children_depts, dept)
+                    dept_data['isShowSelect'] = True
+                dept_tree.append(dept_data)  # 将当前菜单数据添加到菜单树列表
+            return dept_tree
+
+        routers = build_dept_tree(data, None)
+
+        # 构建返回结果
+        result = {
+            "data": routers,
+            "code": 200,
+            "msg": "查询成功"
+        }
+        return result
+
+    except Exception as e:
+        # 处理异常
+        traceback.print_exc()
+        return JSONResponse(status_code=404, content={
+            'code': 404,
+            'msg': str(e)
+        })
+
+
 @router.post('/department/create')
 async def create_dict_data(
     db: Session = Depends(get_db),