From 6b932f79a855cac6846a6a93fa2b388fd0b4470a Mon Sep 17 00:00:00 2001 From: DXC Date: Wed, 11 Mar 2026 17:06:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=C3=90=DE=B8=C2=B4=D4=A4=C2=BE=C2=AF?= =?UTF-8?q?=C3=89=C3=A8=C3=96=C3=83=C3=96=C3=90=C3=A3=C3=90=D6=B5=CE=AA=20?= =?UTF-8?q?null=20=C2=B5=C2=BC=C3=96=C2=BA=C3=B3=C2=B6=C3=8B=20500=20?= =?UTF-8?q?=C2=B1=C3=80=C3=80=C2=A3=C2=B5=C3=84=C3=8E=C3=8A=C3=8C=E2=A3=AC?= =?UTF-8?q?=C2=B2=C2=A2=C3=94=C3=B6=C2=BC=C3=93=C7=B0=C2=BA=C3=B3=C2=B6?= =?UTF-8?q?=CB=B0=C2=B2=C8=AB=D0=A3=C3=91=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inventory-backend/app/api/v1/inbound/base.py | 15 +++++++++------ inventory-web/src/views/material/list.vue | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/inventory-backend/app/api/v1/inbound/base.py b/inventory-backend/app/api/v1/inbound/base.py index 2960999..2660e0a 100644 --- a/inventory-backend/app/api/v1/inbound/base.py +++ b/inventory-backend/app/api/v1/inbound/base.py @@ -371,18 +371,21 @@ def batch_set_warning(): # 更新现有记录 if 'isEnabled' in item: warning.is_enabled = bool(item['isEnabled']) - if 'yellowThreshold' in item: - warning.yellow_threshold = item['yellowThreshold'] - if 'redThreshold' in item: - warning.red_threshold = item['redThreshold'] + # 安全转换阈值,None 默认转为 0 + yellow_val = item.get('yellowThreshold') + red_val = item.get('redThreshold') + warning.yellow_threshold = float(yellow_val) if yellow_val is not None else 0 + warning.red_threshold = float(red_val) if red_val is not None else 0 updated_count += 1 else: # 创建新记录 + yellow_val = item.get('yellowThreshold') + red_val = item.get('redThreshold') warning = MaterialWarningSetting( base_id=base_id, is_enabled=item.get('isEnabled', False), - yellow_threshold=item.get('yellowThreshold'), - red_threshold=item.get('redThreshold') + yellow_threshold=float(yellow_val) if yellow_val is not None else 0, + red_threshold=float(red_val) if red_val is not None else 0 ) db.session.add(warning) created_count += 1 diff --git a/inventory-web/src/views/material/list.vue b/inventory-web/src/views/material/list.vue index 8b50396..fb89180 100644 --- a/inventory-web/src/views/material/list.vue +++ b/inventory-web/src/views/material/list.vue @@ -1204,13 +1204,23 @@ const submitWarning = async () => { await warningFormRef.value.validate(); + // 安全转换数值,null/undefined 默认转为 0 + const yellow = Number(warningForm.yellowThreshold) || 0; + const red = Number(warningForm.redThreshold) || 0; + + // 逻辑校验:启用预警时,黄色阈值必须大于红色阈值 + if (warningForm.isEnabled && yellow !== 0 && red !== 0 && yellow <= red) { + ElMessage.warning('黄色阈值必须大于红色阈值'); + return; + } + warningLoading.value = true; try { const data = warningDialog.selectedIds.map(baseId => ({ baseId, isEnabled: warningForm.isEnabled, - redThreshold: warningForm.redThreshold, - yellowThreshold: warningForm.yellowThreshold + redThreshold: red, + yellowThreshold: yellow })); await batchSetWarning(data);