IRIS过滤容错: 后端SQL失败时降级全量+前端严格过滤department===IRIS
This commit is contained in:
@ -25,20 +25,37 @@ def list_users(
|
|||||||
"""获取 MOM 系统用户列表,默认只返回 IRIS 部门"""
|
"""获取 MOM 系统用户列表,默认只返回 IRIS 部门"""
|
||||||
db = MomSessionLocal()
|
db = MomSessionLocal()
|
||||||
try:
|
try:
|
||||||
base_sql = """
|
# 尝试按部门过滤;若 sys_user 无 department 列则降级全量查询
|
||||||
SELECT id, username,
|
try:
|
||||||
SPLIT_PART(username, '/', 1) AS full_name,
|
base_sql = """
|
||||||
COALESCE(department, '') AS department
|
SELECT id, username,
|
||||||
FROM sys_user
|
SPLIT_PART(username, '/', 1) AS full_name,
|
||||||
WHERE department = :dept
|
COALESCE(department, '') AS department
|
||||||
"""
|
FROM sys_user
|
||||||
params = {"dept": dept, "lim": limit}
|
WHERE department = :dept
|
||||||
if keyword.strip():
|
"""
|
||||||
sql = text(base_sql + " AND username ILIKE :kw ORDER BY username LIMIT :lim")
|
params = {"dept": dept, "lim": limit}
|
||||||
params["kw"] = f"%{keyword.strip()}%"
|
if keyword.strip():
|
||||||
else:
|
sql = text(base_sql + " AND username ILIKE :kw ORDER BY username LIMIT :lim")
|
||||||
sql = text(base_sql + " ORDER BY username LIMIT :lim")
|
params["kw"] = f"%{keyword.strip()}%"
|
||||||
rows = db.execute(sql, params).fetchall()
|
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 [
|
return [
|
||||||
UserOption(
|
UserOption(
|
||||||
|
|||||||
@ -198,7 +198,7 @@ export default {
|
|||||||
openEditProduct() { this.editForm = { order_no: this.product.order_no || "", external_serial: this.product.external_serial || "" }; this.editProductVisible = true; },
|
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 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 {} },
|
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]; },
|
onTaskNameChange(e) { const idx = e.detail.value; this.firstForm.taskNameIdx = idx; this.firstForm.task_name = TASK_NAME_OPTIONS[idx]; },
|
||||||
|
|||||||
Reference in New Issue
Block a user