admin/src/Oms.Application/Shared/OpenApiMeasureUnitConverter.cs
zzh e85dfb80b5
All checks were successful
Build and Deploy / deploy (push) Successful in 1m1s
feat: 仓配开放 API 与后台用户启停
新增 warehouseOpenApi(Token/入库/件重尺/红外图),并在 fk_user 支持 IsEnabled 禁用登录。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-13 17:53:00 +08:00

35 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Fake.Application;
namespace Oms.Application.Shared;
/// <summary>
/// 开放接口件重尺单位换算为系统内部单位(kg / cm)。
/// </summary>
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}")
};
}
}