feat(warning): 库存预警邮件支持顺延发送,前端物料列表新增预警状态展示列
This commit is contained in:
@ -101,6 +101,8 @@ class InventoryWarningService:
|
|||||||
|
|
||||||
total_red = 0
|
total_red = 0
|
||||||
total_yellow = 0
|
total_yellow = 0
|
||||||
|
total_red_cascaded = 0 # 红色顺延到黄色
|
||||||
|
total_yellow_cascaded = 0 # 黄色顺延到红色
|
||||||
sent_red = False
|
sent_red = False
|
||||||
sent_yellow = False
|
sent_yellow = False
|
||||||
processed_settings = []
|
processed_settings = []
|
||||||
@ -121,7 +123,18 @@ class InventoryWarningService:
|
|||||||
if red_th is not None and inv <= red_th:
|
if red_th is not None and inv <= red_th:
|
||||||
total_red += 1
|
total_red += 1
|
||||||
red_emails = InventoryWarningService._parse_emails(setting.red_emails)
|
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)
|
processed_settings.append(setting)
|
||||||
row = {
|
row = {
|
||||||
'name': name,
|
'name': name,
|
||||||
@ -129,10 +142,14 @@ class InventoryWarningService:
|
|||||||
'qty': round(inv, 2),
|
'qty': round(inv, 2),
|
||||||
'threshold': round(red_th, 2),
|
'threshold': round(red_th, 2),
|
||||||
}
|
}
|
||||||
for email in red_emails:
|
if use_yellow_channel:
|
||||||
red_rows_by_email[email].append(row)
|
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:
|
else:
|
||||||
print(f"[InventoryWarning] 物料「{name}」红单跳过:无 red_emails 配置")
|
print(f"[InventoryWarning] 物料「{name}」红单跳过:无 red_emails 且 yellow_emails 也为空")
|
||||||
|
|
||||||
# ★ 黄色预警:red_threshold < 库存 <= yellow_threshold,走 setting.yellow_emails ★
|
# ★ 黄色预警:red_threshold < 库存 <= yellow_threshold,走 setting.yellow_emails ★
|
||||||
elif (
|
elif (
|
||||||
@ -141,7 +158,18 @@ class InventoryWarningService:
|
|||||||
):
|
):
|
||||||
total_yellow += 1
|
total_yellow += 1
|
||||||
yellow_emails = InventoryWarningService._parse_emails(setting.yellow_emails)
|
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)
|
processed_settings.append(setting)
|
||||||
row = {
|
row = {
|
||||||
'name': name,
|
'name': name,
|
||||||
@ -149,10 +177,14 @@ class InventoryWarningService:
|
|||||||
'qty': round(inv, 2),
|
'qty': round(inv, 2),
|
||||||
'threshold': round(yellow_th, 2),
|
'threshold': round(yellow_th, 2),
|
||||||
}
|
}
|
||||||
for email in yellow_emails:
|
if use_red_channel:
|
||||||
yellow_rows_by_email[email].append(row)
|
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:
|
else:
|
||||||
print(f"[InventoryWarning] 物料「{name}」黄单跳过:无 yellow_emails 配置")
|
print(f"[InventoryWarning] 物料「{name}」黄单跳过:无 yellow_emails 且 red_emails 也为空")
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -193,6 +225,8 @@ class InventoryWarningService:
|
|||||||
return {
|
return {
|
||||||
'red_count': total_red,
|
'red_count': total_red,
|
||||||
'yellow_count': total_yellow,
|
'yellow_count': total_yellow,
|
||||||
|
'red_cascaded_count': total_red_cascaded,
|
||||||
|
'yellow_cascaded_count': total_yellow_cascaded,
|
||||||
'red_sent': sent_red,
|
'red_sent': sent_red,
|
||||||
'yellow_sent': sent_yellow,
|
'yellow_sent': sent_yellow,
|
||||||
'timestamp': now.strftime('%Y-%m-%d %H:%M:%S')
|
'timestamp': now.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|||||||
@ -302,6 +302,22 @@
|
|||||||
</el-tag>
|
</el-tag>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
<el-table-column v-if="userStore.hasPermission('material_list:view_warning')" label="预警状态" width="120" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<template v-if="row.warningStatus === 2">
|
||||||
|
<el-tag type="danger" size="small">红色预警</el-tag>
|
||||||
|
<div style="font-size: 11px; color: #999;">阈值: {{ row.warningRed }}</div>
|
||||||
|
</template>
|
||||||
|
<template v-else-if="row.warningStatus === 1">
|
||||||
|
<el-tag type="warning" size="small">黄色预警</el-tag>
|
||||||
|
<div style="font-size: 11px; color: #999;">阈值: {{ row.warningYellow }}</div>
|
||||||
|
</template>
|
||||||
|
<template v-else-if="row.warningEnabled">
|
||||||
|
<el-tag type="success" size="small">已配置</el-tag>
|
||||||
|
</template>
|
||||||
|
<span v-else style="color: #c0c4cc;">-</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column v-if="userStore.hasPermission('material_list:operation')" label="操作" width="280" fixed="right" align="center">
|
<el-table-column v-if="userStore.hasPermission('material_list:operation')" label="操作" width="280" fixed="right" align="center">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button v-if="userStore.hasPermission('material_list:operation')" link type="primary" size="small" @click="handleEdit(scope.row)">编辑</el-button>
|
<el-button v-if="userStore.hasPermission('material_list:operation')" link type="primary" size="small" @click="handleEdit(scope.row)">编辑</el-button>
|
||||||
|
|||||||
Reference in New Issue
Block a user