OA 评论选人列表改为请求 users/options 时按当前登录用户部门优先排序,Web 与移动 OA 共用后端稳定排序,便于先选到同部门同事。 Co-authored-by: Cursor <cursoragent@cursor.com>
20 lines
612 B
Python
20 lines
612 B
Python
"""用户下拉选项:同部门优先排序等轻量辅助。"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Dict, List, Sequence
|
|
|
|
|
|
def prioritize_caller_dept_options(
|
|
options: Sequence[Dict[str, Any]],
|
|
caller_dept_id: str,
|
|
) -> List[Dict[str, Any]]:
|
|
"""稳定排序:当前登录用户同部门在前,其余保持原相对顺序。"""
|
|
items = list(options)
|
|
dept = (caller_dept_id or "").strip()
|
|
if not dept or not items:
|
|
return items
|
|
return sorted(
|
|
items,
|
|
key=lambda item: 0 if str(item.get("deptId") or "").strip() == dept else 1,
|
|
)
|