db_area.py 820 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. from sqlalchemy.orm import Session
  4. from sqlalchemy import text, exists, and_, or_, not_
  5. from sqlalchemy.sql import func
  6. from database import get_db
  7. from models import *
  8. from extensions import logger
  9. from utils import *
  10. # 根据经纬度获取地区代码
  11. def get_region_code_by_gps(db: Session, lng: str, lat: str):
  12. return "4409"
  13. def id_get_area_info(db: Session,id):
  14. query = db.query(GovdataArea)
  15. query = query.filter(GovdataArea.id == id)
  16. return query.first()
  17. def id_get_area_parent_list(db: Session,id,li:list = []):
  18. area = id_get_area_info(db,id)
  19. # print({"id":id,'label':area.area_name})
  20. li.append({"id":id,'label':area.area_name})
  21. if area.parent_id<=1:
  22. return li[::-1]
  23. return id_get_area_parent_list(db,area.parent_id,li)