From d01658c63cd541fe4ea5cec5c4bd7f23b9408cdb Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期六, 18 十月 2025 15:04:56 +0800
Subject: [PATCH] 前端,pda,后端接口更改,新增,优化
---
WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/ModelValidate.cs | 44 ++++++++++++++++++++++++++++++++++++--------
1 files changed, 36 insertions(+), 8 deletions(-)
diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/ModelValidate.cs b/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/ModelValidate.cs
index 9440915..52a9e11 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/ModelValidate.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/ModelValidate.cs
@@ -99,35 +99,63 @@
if (propertyAttribute == null) continue;
object? value = propertyInfo.GetValue(data, null);
+ // 鎻愬彇鎻忚堪锛堝噺灏戦噸澶嶄唬鐮侊級
+ string propDesc = string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description;
+
+ // 闈炵┖楠岃瘉锛堜繚鎸佷笉鍙橈級
if (propertyAttribute.NotNullAndEmpty)
{
- if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}涓嶅彲涓簄ull", data);
- if (string.IsNullOrEmpty(value.ToString())) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}涓嶅彲涓虹┖瀛楃涓�", data);
+ if (value == null) return (false, $"{propDesc}涓嶅彲涓簄ull", data);
+ if (string.IsNullOrEmpty(value.ToString())) return (false, $"{propDesc}涓嶅彲涓虹┖瀛楃涓�", data);
}
+ // 鏈�灏忓�奸獙璇侊紙鏍稿績淇敼锛氬吋瀹瑰皬鏁帮級
if (propertyAttribute.MinValue > int.MinValue)
{
- if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}涓嶅彲涓簄ull", data);
+ if (value == null) return (false, $"{propDesc}涓嶅彲涓簄ull", data);
+
+ // 鍏抽敭锛氬厛灏嗗�艰浆鎹负decimal锛堟敮鎸佸皬鏁帮級锛岄伩鍏嶇洿鎺ヨ浆int鎶ラ敊
+ if (!decimal.TryParse(value.ToString(), out decimal valueDecimal))
+ {
+ return (false, $"{propDesc}鐨勫�笺�恵value}銆戜笉鏄湁鏁堢殑鏁板�兼牸寮忥紙闇�涓烘暣鏁版垨灏忔暟锛�", data);
+ }
+
+ // 灏唅nt绫诲瀷鐨凪inValue杞负decimal鍐嶆瘮杈冿紙int鍙殣寮忚浆decimal锛�
+ decimal minValue = propertyAttribute.MinValue;
if (propertyAttribute.IsContainMinValue)
{
- if (Convert.ToInt32(value.ToString()) < propertyAttribute.MinValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}鐨勫�笺�恵value}銆戜笉鍙皬浜庛�恵propertyAttribute.MinValue}銆�", data);
+ if (valueDecimal < minValue)
+ return (false, $"{propDesc}鐨勫�笺�恵value}銆戜笉鍙皬浜庛�恵minValue}銆�", data);
}
else
{
- if (Convert.ToInt32(value.ToString()) <= propertyAttribute.MinValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}鐨勫�笺�恵value}銆戣澶т簬銆恵propertyAttribute.MinValue}銆�", data);
+ if (valueDecimal <= minValue)
+ return (false, $"{propDesc}鐨勫�笺�恵value}銆戣澶т簬銆恵minValue}銆�", data);
}
}
+ // 鏈�澶у�奸獙璇侊紙鏍稿績淇敼锛氬吋瀹瑰皬鏁帮級
if (propertyAttribute.MaxValue < int.MaxValue)
{
- if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}涓嶅彲涓簄ull", data);
+ if (value == null) return (false, $"{propDesc}涓嶅彲涓簄ull", data);
+
+ // 鍚屾牱鍏堣浆decimal
+ if (!decimal.TryParse(value.ToString(), out decimal valueDecimal))
+ {
+ return (false, $"{propDesc}鐨勫�笺�恵value}銆戜笉鏄湁鏁堢殑鏁板�兼牸寮忥紙闇�涓烘暣鏁版垨灏忔暟锛�", data);
+ }
+
+ // int杞琩ecimal姣旇緝
+ decimal maxValue = propertyAttribute.MaxValue;
if (propertyAttribute.IsContainMaxValue)
{
- if (Convert.ToInt32(value.ToString()) >= propertyAttribute.MaxValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}鐨勫�笺�恵value}銆戜笉鍙ぇ浜庛�恵propertyAttribute.MaxValue}銆�", data);
+ if (valueDecimal > maxValue)
+ return (false, $"{propDesc}鐨勫�笺�恵value}銆戜笉鍙ぇ浜庛�恵maxValue}銆�", data);
}
else
{
- if (Convert.ToInt32(value.ToString()) > propertyAttribute.MaxValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}鐨勫�笺�恵value}銆戣灏忎簬銆恵propertyAttribute.MaxValue}銆�", data);
+ if (valueDecimal >= maxValue)
+ return (false, $"{propDesc}鐨勫�笺�恵value}銆戣灏忎簬銆恵maxValue}銆�", data);
}
}
--
Gitblit v1.9.3