From 999f8c2f3ef65174678216127d0003e69936d99a Mon Sep 17 00:00:00 2001 From: duxingchen Date: Thu, 6 Aug 2026 10:08:18 +0800 Subject: [PATCH] =?UTF-8?q?IRIS=E8=BF=87=E6=BB=A4=E5=AE=B9=E9=94=99:=20?= =?UTF-8?q?=E5=90=8E=E7=AB=AFSQL=E5=A4=B1=E8=B4=A5=E6=97=B6=E9=99=8D?= =?UTF-8?q?=E7=BA=A7=E5=85=A8=E9=87=8F+=E5=89=8D=E7=AB=AF=E4=B8=A5?= =?UTF-8?q?=E6=A0=BC=E8=BF=87=E6=BB=A4department=3D=3D=3DIRIS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/endpoints/users.py | 45 ++++++++++++++++++-------- track-uniapp/src/pages/scan/detail.vue | 2 +- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/backend/app/api/v1/endpoints/users.py b/backend/app/api/v1/endpoints/users.py index 619ec18..7fb6ec6 100644 --- a/backend/app/api/v1/endpoints/users.py +++ b/backend/app/api/v1/endpoints/users.py @@ -25,20 +25,37 @@ def list_users( """获取 MOM 系统用户列表,默认只返回 IRIS 部门""" db = MomSessionLocal() try: - base_sql = """ - SELECT id, username, - SPLIT_PART(username, '/', 1) AS full_name, - COALESCE(department, '') AS department - FROM sys_user - WHERE department = :dept - """ - params = {"dept": dept, "lim": limit} - if keyword.strip(): - sql = text(base_sql + " AND username ILIKE :kw ORDER BY username LIMIT :lim") - params["kw"] = f"%{keyword.strip()}%" - else: - sql = text(base_sql + " ORDER BY username LIMIT :lim") - rows = db.execute(sql, params).fetchall() + # 尝试按部门过滤;若 sys_user 无 department 列则降级全量查询 + try: + base_sql = """ + SELECT id, username, + SPLIT_PART(username, '/', 1) AS full_name, + COALESCE(department, '') AS department + FROM sys_user + WHERE department = :dept + """ + params = {"dept": dept, "lim": limit} + if keyword.strip(): + sql = text(base_sql + " AND username ILIKE :kw ORDER BY username LIMIT :lim") + params["kw"] = f"%{keyword.strip()}%" + else: + sql = text(base_sql + " ORDER BY username LIMIT :lim") + rows = db.execute(sql, params).fetchall() + except Exception: + # 降级:不使用 department 列过滤 + fallback_sql = """ + SELECT id, username, + SPLIT_PART(username, '/', 1) AS full_name, + '' AS department + FROM sys_user + """ + params = {"lim": limit} + if keyword.strip(): + sql = text(fallback_sql + " WHERE username ILIKE :kw ORDER BY username LIMIT :lim") + params["kw"] = f"%{keyword.strip()}%" + else: + sql = text(fallback_sql + " ORDER BY username LIMIT :lim") + rows = db.execute(sql, params).fetchall() return [ UserOption( diff --git a/track-uniapp/src/pages/scan/detail.vue b/track-uniapp/src/pages/scan/detail.vue index fef34e8..d40dbd9 100644 --- a/track-uniapp/src/pages/scan/detail.vue +++ b/track-uniapp/src/pages/scan/detail.vue @@ -198,7 +198,7 @@ export default { openEditProduct() { this.editForm = { order_no: this.product.order_no || "", external_serial: this.product.external_serial || "" }; this.editProductVisible = true; }, async doEditProduct() { this.editSaving = true; try { this.product = await patch(`/products/${this.product.id}`, { order_no: this.editForm.order_no.trim(), external_serial: this.editForm.external_serial.trim() }); uni.showToast({ title: "已保存", icon: "success" }); this.editProductVisible = false; } catch {} finally { this.editSaving = false; } }, - async loadUsers() { try { const res = await get("/users/", { limit: 200, dept: "IRIS" }); this.users = (res || []).filter(u => u.department === "IRIS" || !u.department); this.userOptions = this.users.map(u => ({ id: u.username || u.id, name: u.full_name || u.username })); } catch {} }, + async loadUsers() { try { const res = await get("/users/", { limit: 200, dept: "IRIS" }); this.users = (res || []).filter(u => u.department === "IRIS"); this.userOptions = this.users.map(u => ({ id: u.username || u.id, name: u.full_name || u.username })); } catch {} }, loadCurrentUser() { try { let user = uni.getStorageSync("user"); if (typeof user === "string" && user) { try { user = JSON.parse(user); } catch (e) { user = null; } } if (user && typeof user === "object") { this.currentUser = user; this.currentUserId = String(user.id || ""); this.currentUsername = user.username || ""; } } catch {} }, onTaskNameChange(e) { const idx = e.detail.value; this.firstForm.taskNameIdx = idx; this.firstForm.task_name = TASK_NAME_OPTIONS[idx]; },