fix: дԤ¾¯ÉèÖÃÖÐãÐֵΪ null µ¼Öºó¶Ë 500 ±ÀÀ£µÄÎÊÌ⣬²¢Ôö¼Óǰºó¶˰²ȫУÑé
This commit is contained in:
@ -371,18 +371,21 @@ def batch_set_warning():
|
|||||||
# 更新现有记录
|
# 更新现有记录
|
||||||
if 'isEnabled' in item:
|
if 'isEnabled' in item:
|
||||||
warning.is_enabled = bool(item['isEnabled'])
|
warning.is_enabled = bool(item['isEnabled'])
|
||||||
if 'yellowThreshold' in item:
|
# 安全转换阈值,None 默认转为 0
|
||||||
warning.yellow_threshold = item['yellowThreshold']
|
yellow_val = item.get('yellowThreshold')
|
||||||
if 'redThreshold' in item:
|
red_val = item.get('redThreshold')
|
||||||
warning.red_threshold = item['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
|
updated_count += 1
|
||||||
else:
|
else:
|
||||||
# 创建新记录
|
# 创建新记录
|
||||||
|
yellow_val = item.get('yellowThreshold')
|
||||||
|
red_val = item.get('redThreshold')
|
||||||
warning = MaterialWarningSetting(
|
warning = MaterialWarningSetting(
|
||||||
base_id=base_id,
|
base_id=base_id,
|
||||||
is_enabled=item.get('isEnabled', False),
|
is_enabled=item.get('isEnabled', False),
|
||||||
yellow_threshold=item.get('yellowThreshold'),
|
yellow_threshold=float(yellow_val) if yellow_val is not None else 0,
|
||||||
red_threshold=item.get('redThreshold')
|
red_threshold=float(red_val) if red_val is not None else 0
|
||||||
)
|
)
|
||||||
db.session.add(warning)
|
db.session.add(warning)
|
||||||
created_count += 1
|
created_count += 1
|
||||||
|
|||||||
@ -1204,13 +1204,23 @@ const submitWarning = async () => {
|
|||||||
|
|
||||||
await warningFormRef.value.validate();
|
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;
|
warningLoading.value = true;
|
||||||
try {
|
try {
|
||||||
const data = warningDialog.selectedIds.map(baseId => ({
|
const data = warningDialog.selectedIds.map(baseId => ({
|
||||||
baseId,
|
baseId,
|
||||||
isEnabled: warningForm.isEnabled,
|
isEnabled: warningForm.isEnabled,
|
||||||
redThreshold: warningForm.redThreshold,
|
redThreshold: red,
|
||||||
yellowThreshold: warningForm.yellowThreshold
|
yellowThreshold: yellow
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await batchSetWarning(data);
|
await batchSetWarning(data);
|
||||||
|
|||||||
Reference in New Issue
Block a user