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 @@ + + +