Files
zkxw/backend/app/crud/ethnic.py
T
2026-05-20 18:06:21 +08:00

35 lines
1012 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""民族码表 CRUD(全局 sys_ethnic)"""
from typing import Any, Dict, List, Optional
from sqlalchemy.orm import Session
from app.models.models import SysEthnic
def _row_to_dict(row: SysEthnic) -> Dict[str, Any]:
return {
"id": row.id,
"ethnicName": row.ethnic_name or "",
"ethnicCode": row.ethnic_code or "",
"orderNum": row.order_num,
}
def list_ethnics(
db: Session,
*,
keyword: Optional[str] = None,
limit: int = 200,
user_info=None,
) -> List[Dict[str, Any]]:
q = db.query(SysEthnic).filter(SysEthnic.del_flag == 0)
kw = (keyword or "").strip()
if kw:
like = f"%{kw}%"
q = q.filter(SysEthnic.ethnic_name.like(like))
if user_info:
from app.core.data_scope import apply_data_scope
q = apply_data_scope(q, SysEthnic, user_info, db)
rows = q.order_by(SysEthnic.order_num.asc(), SysEthnic.ethnic_code.asc()).limit(max(1, min(limit, 500))).all()
return [_row_to_dict(x) for x in rows]