|
@@ -0,0 +1,53 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+
|
|
|
+from fastapi import APIRouter, Request, Depends,Query,HTTPException
|
|
|
+from database import get_db
|
|
|
+from sqlalchemy.orm import Session
|
|
|
+from fastapi.responses import JSONResponse
|
|
|
+from models import *
|
|
|
+from utils import *
|
|
|
+from utils.ry_system_util import *
|
|
|
+from common.security import valid_access_token
|
|
|
+import traceback
|
|
|
+
|
|
|
+router = APIRouter()
|
|
|
+
|
|
|
+@router.get("/tree/{parent_id}")
|
|
|
+def read_all_areas(parent_id:int = 1,db: Session = Depends(get_db)):
|
|
|
+ def parent_id_get_area_info(parent_id):
|
|
|
+ query = db.query(GovdataArea)
|
|
|
+ query = query.filter(GovdataArea.parent_id == parent_id)
|
|
|
+ return query.all()
|
|
|
+ def id_get_area_info(id):
|
|
|
+ query = db.query(GovdataArea)
|
|
|
+ query = query.filter(GovdataArea.id == id)
|
|
|
+ return query.first()
|
|
|
+ try:
|
|
|
+ area_info = id_get_area_info(parent_id)
|
|
|
+ area_list = parent_id_get_area_info(parent_id)
|
|
|
+ data = []
|
|
|
+ if parent_id>1:
|
|
|
+ data.append({'id': area_info.id,
|
|
|
+ 'label': f"{area_info.area_name}本级",
|
|
|
+ 'personSum': 0,
|
|
|
+ 'isShowSelect': False,
|
|
|
+ # 'parentLabel': area_info.area_name
|
|
|
+ })
|
|
|
+ for info in area_list:
|
|
|
+ isShowSelect = True
|
|
|
+ if parent_id_get_area_info(info.id):
|
|
|
+ isShowSelect=False
|
|
|
+ data.append({'id': info.id,
|
|
|
+ 'label': info.area_name,
|
|
|
+ 'personSum': 0,
|
|
|
+ 'isShowSelect': isShowSelect,
|
|
|
+ 'parentLabel': area_info.area_name})
|
|
|
+ return {
|
|
|
+ "code": 200,
|
|
|
+ "msg": "成功",
|
|
|
+ "data": data
|
|
|
+ }
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|