feat(oa): 评论@人员优先展示同部门用户 (#117) #132
No files matched your search
@@ -29,6 +29,7 @@ from app.crud import user as user_svc
|
||||
from app.crud.collection_protocol import _lookup_attachment_by_url
|
||||
from app.models.models import BizAttachment, SysDept, SysRole, SysUser, SysMenu, SysPost
|
||||
from app.services.permission_administration import validate_tenant_references
|
||||
from app.services.user_select_options import prioritize_caller_dept_options
|
||||
from app.services.web_auth_roles import (
|
||||
_map_role_name_to_web,
|
||||
list_user_ids_with_effective_role_name,
|
||||
@@ -77,12 +78,15 @@ async def list_roles_for_select(
|
||||
@router.get("/users/options")
|
||||
async def list_users_for_select(
|
||||
roleName: Optional[str] = Query(None, alias="roleName"),
|
||||
prioritizeCallerDept: bool = Query(False, alias="prioritizeCallerDept"),
|
||||
_user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""返回用户下拉选项(label=昵称,value=用户ID),供流程设计器审批人选择使用。
|
||||
"""返回用户下拉选项(label=昵称,value=用户ID,deptId=部门ID)。
|
||||
|
||||
供流程设计器审批人选择、OA 评论 @ 人员等使用。
|
||||
可选 roleName:按有效角色(直接绑定 ∪ 职位继承)精确过滤。
|
||||
可选 prioritizeCallerDept:当前登录用户同部门人员排在前面(组内仍按创建时间倒序)。
|
||||
"""
|
||||
tenant_no = _user.get("tenant_no", "")
|
||||
q = db.query(SysUser).filter(SysUser.del_flag == 0, SysUser.status == "1")
|
||||
@@ -97,7 +101,16 @@ async def list_users_for_select(
|
||||
return success_response([])
|
||||
q = q.filter(SysUser.id.in_(matched_ids))
|
||||
rows = q.order_by(SysUser.create_time.desc()).distinct().all()
|
||||
out = [{"label": (r.nick_name or r.user_no or ""), "value": r.id} for r in rows]
|
||||
out = [
|
||||
{
|
||||
"label": (r.nick_name or r.user_no or ""),
|
||||
"value": r.id,
|
||||
"deptId": (r.dept_id or ""),
|
||||
}
|
||||
for r in rows
|
||||
]
|
||||
if prioritizeCallerDept:
|
||||
out = prioritize_caller_dept_options(out, _user.get("region_id") or "")
|
||||
return success_response(out)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
"""用户下拉选项:同部门优先排序等轻量辅助。"""
|
||||
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,
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
"""用户下拉选项:同部门优先排序。"""
|
||||
from app.services.user_select_options import prioritize_caller_dept_options
|
||||
|
||||
|
||||
def test_prioritize_caller_dept_keeps_relative_order():
|
||||
options = [
|
||||
{"label": "外1", "value": "a", "deptId": "d2"},
|
||||
{"label": "同1", "value": "b", "deptId": "d1"},
|
||||
{"label": "外2", "value": "c", "deptId": "d3"},
|
||||
{"label": "同2", "value": "d", "deptId": "d1"},
|
||||
{"label": "无部门", "value": "e", "deptId": ""},
|
||||
]
|
||||
out = prioritize_caller_dept_options(options, "d1")
|
||||
assert [x["value"] for x in out] == ["b", "d", "a", "c", "e"]
|
||||
|
||||
|
||||
def test_prioritize_caller_dept_noop_without_caller_dept():
|
||||
options = [
|
||||
{"label": "a", "value": "a", "deptId": "d1"},
|
||||
{"label": "b", "value": "b", "deptId": "d2"},
|
||||
]
|
||||
assert prioritize_caller_dept_options(options, "") == options
|
||||
assert prioritize_caller_dept_options(options, " ") == options
|
||||
|
||||
|
||||
def test_prioritize_caller_dept_empty_list():
|
||||
assert prioritize_caller_dept_options([], "d1") == []
|
||||
@@ -216,7 +216,8 @@ async function ensureUserCache() {
|
||||
if (userCachePromise) return userCachePromise
|
||||
userCachePromise = (async () => {
|
||||
try {
|
||||
const res = await fetchUserOptions()
|
||||
// 同部门优先:由后端按当前登录用户部门排序
|
||||
const res = await fetchUserOptions({ prioritizeCallerDept: true })
|
||||
const list = Array.isArray(res) ? res : res?.list || []
|
||||
const next = []
|
||||
const seen = new Set()
|
||||
|
||||
@@ -22,9 +22,12 @@ export function fetchGetRoleList() {
|
||||
})
|
||||
}
|
||||
|
||||
/** 流程设计器:用户下拉选项(label=昵称,value=用户ID) */
|
||||
export function fetchUserOptions(params?: { roleName?: string }) {
|
||||
return request.get<Array<{ label: string; value: string }>>({
|
||||
/** 用户下拉选项(label=昵称,value=用户ID;可选 deptId / prioritizeCallerDept) */
|
||||
export function fetchUserOptions(params?: {
|
||||
roleName?: string
|
||||
prioritizeCallerDept?: boolean
|
||||
}) {
|
||||
return request.get<Array<{ label: string; value: string; deptId?: string }>>({
|
||||
url: '/web/admin/users/options',
|
||||
params
|
||||
})
|
||||
|
||||
@@ -255,7 +255,8 @@
|
||||
if (userCachePromise) return userCachePromise
|
||||
userCachePromise = (async () => {
|
||||
try {
|
||||
const res = await fetchUserOptions()
|
||||
// 同部门优先:由后端按当前登录用户部门排序
|
||||
const res = await fetchUserOptions({ prioritizeCallerDept: true })
|
||||
const list = Array.isArray(res) ? res : []
|
||||
const next: MentionUser[] = []
|
||||
const seen = new Set<string>()
|
||||
|
||||
Reference in new issue
Block a user