using Fake.Application; namespace Oms.Application.Shared; /// /// 开放接口件重尺单位换算为系统内部单位(kg / cm)。 /// public static class OpenApiMeasureUnitConverter { public static decimal ToKilograms(decimal weight, string? weightUnit) { var unit = string.IsNullOrWhiteSpace(weightUnit) ? "KG" : weightUnit.Trim().ToUpperInvariant(); return unit switch { "KG" or "KGS" or "KILOGRAM" or "KILOGRAMS" => weight, "G" or "GRAM" or "GRAMS" => weight / 1000m, "LB" or "LBS" or "POUND" or "POUNDS" => weight * 0.45359237m, _ => throw new BusinessException($"不支持的重量单位:{weightUnit}") }; } public static decimal ToCentimeters(decimal length, string? lengthUnit) { var unit = string.IsNullOrWhiteSpace(lengthUnit) ? "CM" : lengthUnit.Trim().ToUpperInvariant(); return unit switch { "CM" or "CMS" or "CENTIMETER" or "CENTIMETERS" => length, "MM" or "MILLIMETER" or "MILLIMETERS" => length / 10m, "M" or "METER" or "METERS" => length * 100m, "IN" or "INCH" or "INCHES" => length * 2.54m, _ => throw new BusinessException($"不支持的长度单位:{lengthUnit}") }; } }