using System.Collections.Generic;
using System.Linq;
namespace wms.service.Extensions.LayerPacking.model
{
///
/// 层配装箱约束条件
///
public class LayerPackingConstraints
{
///
/// 产品目标值
///
public decimal P { get; set; }
///
/// 产品偏差范围
///
public decimal P1 { get; set; }
///
/// 箱总扭转目标值
///
private decimal? _x;
///
/// 层总扭转目标值
///
private decimal? _c;
///
/// 箱总产品数
///
private int _productsPerBox;
///
/// 箱总产品数
///
public int ProductsPerBox
{
get => _productsPerBox;
set
{
_productsPerBox = value;
// 重新计算相关值
_x = null;
_c = null;
}
}
///
/// 层总产品数
///
private const int PRODUCTS_PER_LAYER = 12;
///
/// 层总产品数
///
public int ProductsPerLayer => PRODUCTS_PER_LAYER;
///
/// 箱总层数
///
public int LayersPerBox => ProductsPerBox / PRODUCTS_PER_LAYER;
///
/// 箱总扭转目标值
///
public decimal X
{
get => _x ?? P * ProductsPerBox;
set => _x = value;
}
///
/// 箱总扭转目标偏差范围
///
public decimal X1 { get; set; }
///
/// 层总扭转目标值
///
public decimal C
{
get => _c ?? P * PRODUCTS_PER_LAYER;
set => _c = value;
}
///
/// 层总扭转目标偏差范围
///
public decimal C1 { get; set; }
///
/// 最大焊点盘数
///
public int SolderMaxCount { get; set; }
///
/// 最大焊点数
///
public int PerSolderMaxCount { get; set; }
///
/// 最小产品扭转目标值
///
public decimal MinProductValue => P - P1;
///
/// 最大产品扭转目标值
///
public decimal MaxProductValue => P + P1;
///
/// 是产品最小扭转目标值
///
public bool IsAtMinTarget { get; private set; }
///
/// 是产品最大扭转目标值
///
public bool IsAtMaxTarget { get; private set; }
///
/// 最小箱总目标值
///
public decimal MinBoxTotal
{
get
{
if (X == P - P1 * ProductsPerBox)
return X;
if (X == P + P1 * ProductsPerBox)
return X - X1;
return X - X1;
}
}
///
/// 最大箱总目标值
///
public decimal MaxBoxTotal
{
get
{
if (X == P + P1 * ProductsPerBox)
return X;
if (X == P - P1 * ProductsPerBox)
return X + X1;
return X + X1;
}
}
///
/// 最小层总目标值
///
public decimal MinLayerTotal
{
get
{
if (C == P - P1 * PRODUCTS_PER_LAYER)
return C;
if (C == P + P1 * PRODUCTS_PER_LAYER)
return C - C1;
return C - C1;
}
}
///
/// 最大层总目标值
///
public decimal MaxLayerTotal
{
get
{
if (C == P + P1 * PRODUCTS_PER_LAYER)
return C;
if (C == P - P1 * PRODUCTS_PER_LAYER)
return C + C1;
return C + C1;
}
}
///
/// 更新箱层目标值
///
///
public void UpdateTargetValues(List products)
{
if (products == null || !products.Any()) return;
decimal avgValue = products.Average(p => p.TorsChkValue);
decimal effectiveProductTarget; // 有效产品目标值 --计算箱层目标值时使用的产品目标值
if (avgValue <= MinProductValue)
{
effectiveProductTarget = MinProductValue;
IsAtMinTarget = true;
IsAtMaxTarget = false;
}
else if (avgValue >= MaxProductValue)
{
effectiveProductTarget = MaxProductValue;
IsAtMinTarget = false;
IsAtMaxTarget = true;
}
else
{
effectiveProductTarget = avgValue;
IsAtMinTarget = false;
IsAtMaxTarget = false;
}
_x = effectiveProductTarget * ProductsPerBox;
_c = effectiveProductTarget * PRODUCTS_PER_LAYER;
X1 = P1 * ProductsPerBox;
C1 = P1 * PRODUCTS_PER_LAYER;
}
///
/// 获取焊点在装箱中的约束方案
///
///
public SolderConstraintType GetSolderConstraintType()
{
if (SolderMaxCount <= 0) return SolderConstraintType.NoConstraint;
else if (PerSolderMaxCount <= 0) return SolderConstraintType.OnlyProductCount;
else return SolderConstraintType.BothConstraints;
}
}
///
/// 焊点约束条件
///
public enum SolderConstraintType
{
///
/// 无约束条件
///
NoConstraint,
///
/// 仅产品数
///
OnlyProductCount,
///
/// 同时满足产品数和焊点数
///
BothConstraints
}
}