From 8356774a8affd9cbd45ecc115606f1f399f3a67d Mon Sep 17 00:00:00 2001 From: DXC Date: Tue, 12 May 2026 14:44:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(warning):=20=E5=BA=93=E5=AD=98=E9=A2=84?= =?UTF-8?q?=E8=AD=A6=E9=82=AE=E4=BB=B6=E6=94=AF=E6=8C=81=E9=A1=BA=E5=BB=B6?= =?UTF-8?q?=E5=8F=91=E9=80=81=EF=BC=8C=E5=89=8D=E7=AB=AF=E7=89=A9=E6=96=99?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=96=B0=E5=A2=9E=E9=A2=84=E8=AD=A6=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=B1=95=E7=A4=BA=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/services/inventory_task.py | 50 ++++++++++++++++--- inventory-web/src/views/material/list.vue | 16 ++++++ 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/inventory-backend/app/services/inventory_task.py b/inventory-backend/app/services/inventory_task.py index c2544bc..ee9c400 100644 --- a/inventory-backend/app/services/inventory_task.py +++ b/inventory-backend/app/services/inventory_task.py @@ -101,6 +101,8 @@ class InventoryWarningService: total_red = 0 total_yellow = 0 + total_red_cascaded = 0 # 红色顺延到黄色 + total_yellow_cascaded = 0 # 黄色顺延到红色 sent_red = False sent_yellow = False processed_settings = [] @@ -121,7 +123,18 @@ class InventoryWarningService: if red_th is not None and inv <= red_th: total_red += 1 red_emails = InventoryWarningService._parse_emails(setting.red_emails) - if red_emails: + emails_to_use = red_emails + use_yellow_channel = False # 是否走黄色通道(顺延时为 True) + if not emails_to_use: + # ★ 红色预警但无 red_emails,顺延使用 yellow_emails ★ + emails_to_use = InventoryWarningService._parse_emails(setting.yellow_emails) + if emails_to_use: + total_yellow += 1 + total_red_cascaded += 1 + use_yellow_channel = True + print(f"[InventoryWarning] 物料「{name}」红色预警触发,但 red_emails 为空,顺延使用 yellow_emails 发黄色预警") + + if emails_to_use: processed_settings.append(setting) row = { 'name': name, @@ -129,10 +142,14 @@ class InventoryWarningService: 'qty': round(inv, 2), 'threshold': round(red_th, 2), } - for email in red_emails: - red_rows_by_email[email].append(row) + if use_yellow_channel: + for email in emails_to_use: + yellow_rows_by_email[email].append(row) + else: + for email in emails_to_use: + red_rows_by_email[email].append(row) else: - print(f"[InventoryWarning] 物料「{name}」红单跳过:无 red_emails 配置") + print(f"[InventoryWarning] 物料「{name}」红单跳过:无 red_emails 且 yellow_emails 也为空") # ★ 黄色预警:red_threshold < 库存 <= yellow_threshold,走 setting.yellow_emails ★ elif ( @@ -141,7 +158,18 @@ class InventoryWarningService: ): total_yellow += 1 yellow_emails = InventoryWarningService._parse_emails(setting.yellow_emails) - if yellow_emails: + emails_to_use = yellow_emails + use_red_channel = False # 是否走红色通道(顺延时为 True) + if not emails_to_use: + # ★ 黄色预警但无 yellow_emails,顺延使用 red_emails ★ + emails_to_use = InventoryWarningService._parse_emails(setting.red_emails) + if emails_to_use: + total_red += 1 + total_yellow_cascaded += 1 + use_red_channel = True + print(f"[InventoryWarning] 物料「{name}」黄色预警触发,但 yellow_emails 为空,顺延使用 red_emails 发红色预警") + + if emails_to_use: processed_settings.append(setting) row = { 'name': name, @@ -149,10 +177,14 @@ class InventoryWarningService: 'qty': round(inv, 2), 'threshold': round(yellow_th, 2), } - for email in yellow_emails: - yellow_rows_by_email[email].append(row) + if use_red_channel: + for email in emails_to_use: + red_rows_by_email[email].append(row) + else: + for email in emails_to_use: + yellow_rows_by_email[email].append(row) else: - print(f"[InventoryWarning] 物料「{name}」黄单跳过:无 yellow_emails 配置") + print(f"[InventoryWarning] 物料「{name}」黄单跳过:无 yellow_emails 且 red_emails 也为空") else: continue @@ -193,6 +225,8 @@ class InventoryWarningService: return { 'red_count': total_red, 'yellow_count': total_yellow, + 'red_cascaded_count': total_red_cascaded, + 'yellow_cascaded_count': total_yellow_cascaded, 'red_sent': sent_red, 'yellow_sent': sent_yellow, 'timestamp': now.strftime('%Y-%m-%d %H:%M:%S') diff --git a/inventory-web/src/views/material/list.vue b/inventory-web/src/views/material/list.vue index 02b5c5b..65d80fb 100644 --- a/inventory-web/src/views/material/list.vue +++ b/inventory-web/src/views/material/list.vue @@ -302,6 +302,22 @@ + + +