1
wankeda
2026-03-16 d5538af4a0bbc5511990aceb3431fb1caa9bbc65
ÏîÄ¿´úÂë/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)}不可为null", data);
                        if (string.IsNullOrEmpty(value.ToString())) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}不可为空字符串", data);
                        if (value == null) return (false, $"{propDesc}不可为null", 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)}不可为null", data);
                        if (value == null) return (false, $"{propDesc}不可为null", data);
                        // å…³é”®ï¼šå…ˆå°†å€¼è½¬æ¢ä¸ºdecimal(支持小数),避免直接转int报错
                        if (!decimal.TryParse(value.ToString(), out decimal valueDecimal))
                        {
                            return (false, $"{propDesc}的值【{value}】不是有效的数值格式(需为整数或小数)", data);
                        }
                        // å°†int类型的MinValue转为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)}不可为null", data);
                        if (value == null) return (false, $"{propDesc}不可为null", data);
                        // åŒæ ·å…ˆè½¬decimal
                        if (!decimal.TryParse(value.ToString(), out decimal valueDecimal))
                        {
                            return (false, $"{propDesc}的值【{value}】不是有效的数值格式(需为整数或小数)", data);
                        }
                        // int转decimal比较
                        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);
                        }
                    }