admin/src/Oms.Application/Services/Orders/PriceCheckInputProfile.cs
zzh 3d5eaa223a feat: 小包全链路加固、待排货与运单号 IDE 前缀
查价/下单/入库/出库统一校验与计费上下文;待排货状态及可选入库排货;运单号改为 IDE+yyMMddHHmmss;补充迁移 SQL 与测试修复。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-22 19:00:55 +08:00

94 lines
2.7 KiB
C#

namespace Oms.Application.Services.Orders;
using Oms.Application.Dtos.Orders;
/// <summary>
/// 查价入参完整度(用于估算逻辑与对客提示)。
/// </summary>
internal sealed class PriceCheckInputProfile
{
public bool HasDimensions { get; init; }
public bool HasPostalCode { get; init; }
public bool HasProvince { get; init; }
public bool HasCargoTypeFilter { get; init; }
public bool HasWarehouseFilter { get; init; }
public bool HasShippingMethodFilter { get; init; }
public IReadOnlyList<string> MissingFieldCodes { get; init; } = [];
public static PriceCheckInputProfile FromInput(OrderPriceCheckInput input)
{
var hasDimensions = input.Length is > 0 && input.Width is > 0 && input.Height is > 0;
var hasPostal = !string.IsNullOrWhiteSpace(input.PostalCode);
var hasProvince = !string.IsNullOrWhiteSpace(input.DestinationProvince);
var cargoCodes = (input.CargoTypes ?? [])
.Where(x => !string.IsNullOrWhiteSpace(x))
.ToList();
if (cargoCodes.Count == 0 && !string.IsNullOrWhiteSpace(input.CargoType))
{
cargoCodes.Add(input.CargoType.Trim());
}
var hasCargoFilter = cargoCodes.Count > 0;
var hasWarehouseFilter = (input.WarehouseIds ?? []).Any(x => x > 0);
var hasShippingFilter = !string.IsNullOrWhiteSpace(input.ShippingMethod);
var missing = new List<string>();
if (!hasDimensions)
{
missing.Add(PriceCheckMissingFieldCodes.Dimensions);
}
if (!hasPostal)
{
missing.Add(PriceCheckMissingFieldCodes.PostalCode);
}
if (!hasProvince)
{
missing.Add(PriceCheckMissingFieldCodes.Province);
}
if (!hasCargoFilter)
{
missing.Add(PriceCheckMissingFieldCodes.CargoType);
}
if (!hasWarehouseFilter)
{
missing.Add(PriceCheckMissingFieldCodes.Warehouse);
}
return new PriceCheckInputProfile
{
HasDimensions = hasDimensions,
HasPostalCode = hasPostal,
HasProvince = hasProvince,
HasCargoTypeFilter = hasCargoFilter,
HasWarehouseFilter = hasWarehouseFilter,
HasShippingMethodFilter = hasShippingFilter,
MissingFieldCodes = missing
};
}
public bool IsQueryEstimated => MissingFieldCodes.Count > 0;
}
internal static class PriceCheckMissingFieldCodes
{
public const string Dimensions = "dimensions";
public const string PostalCode = "postalCode";
public const string Province = "province";
public const string CargoType = "cargoType";
public const string Warehouse = "warehouse";
}