| 123456789101112131415161718192021222324252627282930313233 |
- """民族码表 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))
- # 民族码表为全局主数据,不做数据范围过滤
- _ = user_info
- 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]
|